feat(libkernel): return ESRCH and EINVAL for unsupported cpuset affinity targets #4585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4585"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T16:13:53Z.
What
Return
ESRCH(3) for thread or process IDs other than the caller, andEINVAL(22) for invalid level/which arguments incpuset_getaffinityandcpuset_setaffinity. Also support querying and setting affinity when the calling thread passes its own thread ID (scePthreadGetthreadid()/self->tid), matching FreeBSD 11.4 cpuset semantics instead of throwingNotImplemented.Tested
tools/check_conventions.py --base origin/main
Unit test assertions in core/libs/tests/GuestAvailableCpumask.cpp
Checklist
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:42:44Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Checked against FreeBSD 11.4
kern_cpuset_getaffinity/kern_cpuset_setaffinity(sys/kern/kern_cpuset.c); build andguest_available_cpumaskpass, but a few things don't match it:Thread.cpp(newlevel != LevelWhich || (which != WhichThread && which != WhichProcess)check, both functions):CPU_LEVEL_ROOT(1) andCPU_LEVEL_CPUSET(2) are valid levels, andCPU_WHICH_CPUSET/CPU_WHICH_JAILare valid scopes; only levels outside 1..3 hit thedefault: EINVAL. ReturningEINVALfor the valid combinations is a plausible-but-wrong result wheremainthrew. ReturnEINVALonly for levels outside 1..3 and keep throwing for valid combinations that aren't modelled.cpuset_which(which, id, ...)before the level switch, so an unknown id givesESRCHeven when the level is bad. Check the id first.id != self->tid→ESRCH: another live thread of the process is a valid target in FreeBSD (cpuset_whichfinds it by tid). Either handle other guest threads (we know their tids) or keep throwing for them;ESRCHis only right for tids that don't exist.docs/dev/debt/libkernel.mdconflicts withmain(the two cpuset lines moved); rebase and update the lines to say what is still unmodelled (other levels/scopes, other threads).EINVALonce handled, or must throw), and a bad level with an unknown id (ESRCH).Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-13T01:03:14Z.
@adriadam10 Thanks for the detailed review against FreeBSD 11.4
kern_cpuset.c! Updated as requested:origin/mainresolving the debt doc conflict.ESRCHfor unknown IDs even when the level is invalid (e.g. level 99 with unknown ID returnsESRCH).EINVALfor levels outside 1..3 (level < 1 || level > 3); valid levels 1 (CPU_LEVEL_ROOT) and 2 (CPU_LEVEL_CPUSET) as well as valid scopes 3..6 throwNotImplemented_nid_no_patchas unmodelled rather than returningEINVAL.LiveGuestThreadExists(id)and throw as unmodelled rather than returningESRCH;ESRCHis only returned for tids that do not exist.ESRCH), and live secondary thread throwing as unmodelled.docs/dev/debt/libkernel.mdto document the exact unmodelled levels, scopes, and secondary threads.ctest -R guest_available_cpumask(passed) andtools/check_conventions.py --base origin/main.Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:36:13Z.
Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto
main7e181fcc3together with #4725, #4719, #4585 and #4582 (no conflicts):guest_available_cpumaskpasses. With this PR's source change reverted (test kept), it fails on Linux, so the check guards the change on Linux too.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:32:55Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL128-130Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:46:28Z.
Review: APPROVED
Re-checked against FreeBSD 11.4
kern_cpuset_{get,set}affinity: target ID is validated before the level, valid levels 1..3 and scopes 3..6 throw as unmodelled, unknown IDs returnESRCH, invalid levels/scopesEINVAL.guest_available_cpumaskpasses and fails without the source change; debt lines updated. Merging once the full build is green.