Created attachment 186278 [details] patch to check that mask is actually too small, not just smaller than the kernel compiled type As mentioned in Bug 200802, increasing MAXCPUS breaks compatibility for software setting cpu affinity compiled on earlier versions of FreeBSD. With this patch, the calls will only fail with ERANGE if the mask size is actually too small. In case of running old binaries on new systems with more cpus than fit in the mask, that's still not going to work with this patch. In response to a comment on that bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200802#c4 > Shouldn't cpuset users be querying the cpuset size from sysctl and using that as their allocation base? Possibly, but then the calling code wouldn't be able to use cpuset_t types, or CPU_SET macros. Some updates of documentation would be required too, as the documentation currently says when using a too small mask, get returns an error, and set runs without error (which doesn't appear to be correct).
Believe addressed by f35093f8d6d8155ab2e56c11ee03d474688b16a2 and subsequent commits commit f35093f8d6d8155ab2e56c11ee03d474688b16a2 Author: Dmitry Chagin <dchagin@FreeBSD.org> Date: Wed May 11 10:36:01 2022 +0300 Use Linux semantics for the thread affinity syscalls. Linux has more tolerant checks of the user supplied cpuset_t's. Minimum cpuset_t size that the Linux kernel permits in case of getaffinity() is the maximum CPU id, present in the system / NBBY, the maximum size is not limited. For setaffinity(), Linux does not limit the size of the user-provided cpuset_t, internally using only the meaningful part of the set, where the upper bound is the maximum CPU id, present in the system, no larger than the size of the kernel cpuset_t. Unlike FreeBSD, Linux ignores high bits if set in the setaffinity(), so clear it in the sched_setaffinity() and Linuxulator itself. Reviewed by: Pau Amma (man pages) In collaboration with: jhb Differential revision: https://reviews.freebsd.org/D34849 MFC after: 2 weeks commit 01f74ccd5a0d1a444703e931339709c7de5296b5 Author: Dmitry Chagin <dchagin@FreeBSD.org> AuthorDate: 2023-01-29 12:35:18 +0000 Commit: Dmitry Chagin <dchagin@FreeBSD.org> CommitDate: 2023-01-29 12:35:18 +0000 libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel. Since f35093f8 semantics of a thread affinity functions is changed to be a compatible with Linux: In case of getaffinity(), the minimum cpuset_t size that the kernel permits is the maximum CPU id, present in the system, / NBBY bytes, the maximum size is not limited. In case of setaffinity(), the kernel does not limit the size of the user-provided cpuset_t, internally using only the meaningful part of the set, where the upper bound is the maximum CPU id, present in the system, no larger than the size of the kernel cpuset_t. To match pthread_attr_[g|s]etaffinity_np checks of the user-provided cpusets to the kernel behavior export the minimum cpuset_t size allowed by running kernel via new sysctl kern.sched.cpusetsizemin and use it in checks. Reviewed by: Differential Revision: https://reviews.freebsd.org/D38112 MFC after: 1 week
Thank you for your submission. It appears that this was solved in a different way in the interim. Please do let us know if you encounter any additional issues.