PR_SCHED_CORE_GET converts the internal core scheduling cookie to an
opaque userspace value with ptr_to_hashval().
When the pointer hash key is not initialized yet, ptr_to_hashval()
returns -EBUSY without storing a hash. PR_SCHED_CORE_GET currently
ignores this error and returns the zero-initialized id instead. Since
cookie 0 denotes the default core scheduling cookie, this reports
incorrect state to userspace.
Propagate the hashing error and make the scheduler selftest retry the
transient EBUSY. Do not wait for RNG initialization in
PR_SCHED_CORE_GET; ptr_to_hashval() already reports an unavailable
pointer hash key as -EBUSY, so propagate that condition through the
prctl interface.
Testing on x86_64:
- An entropy-starved early-boot QEMU reproducer observed on the
unfixed kernel:
CREATE ret=0 errno=0 (Success)
GET ret=0 errno=0 (Success) cookie=0x0000000000000000
With patch 1, the same probe returned:
GET ret=-1 errno=16 (Device or resource busy)
- The selftest built successfully with:
make -C tools/testing/selftests/sched -j12
- With PR_SCHED_CORE_GET fault-injected to return EBUSY, the v1
selftest continued evaluating cookie assertions using the error
sentinel and finished with 5 failures. The v2 selftest instead
aborted without evaluating cookie assertions after the failed GET.
- The v2 selftest passed with normal random initialization:
SUCCESS !!!
Changes since v1:
- Patch 1 is unchanged.
- Keep the PR_SCHED_CORE_GET status separate from the returned cookie.
- Abort after an unrecoverable or timed-out GET instead of comparing an
error sentinel as a valid cookie.
- Return cookie values directly from the fatal error helper to keep the
selftest comparisons compact.
- Avoid sleeping after the final retry.
- Rebased onto 2f0c1cf72f46.
v1: https://lore.kernel.org/all/[email protected]/
Hui Su (2):
sched/core: Propagate pointer hash errors from PR_SCHED_CORE_GET
selftests/sched: Retry PR_SCHED_CORE_GET on EBUSY
kernel/sched/core_sched.c | 5 +-
tools/testing/selftests/sched/cs_prctl_test.c | 93 +++++++++++++------
2 files changed, 66 insertions(+), 32 deletions(-)
base-commit: 2f0c1cf72f4682178506f513bbf015e591b1aa4a
--
2.55.0