mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hui Su <sh_def@163.com>
To: peterz@infradead.org
Cc: mingo@redhat.com, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	shuah@kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, Hui Su <sh_def@163.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 1/2] sched/core: Propagate pointer hash errors from PR_SCHED_CORE_GET
Date: Sun, 13 Sep 2026 23:10:39 +0900	[thread overview]
Message-ID: <20260913141040.2338964-2-sh_def@163.com> (raw)
In-Reply-To: <20260913141040.2338964-1-sh_def@163.com>

PR_SCHED_CORE_GET hashes the internal core scheduling cookie before
returning an opaque identifier to userspace.

ptr_to_hashval() returns -EBUSY until the random key used for pointer
hashing has been initialized. However, PR_SCHED_CORE_GET currently
ignores that return value.

Since id is initialized to zero, a failed hash is therefore reported
as a successful GET with cookie 0. Cookie 0 represents the default
core scheduling cookie, so a task which already has a core scheduling
cookie can temporarily appear to have the default cookie during early
boot.

Propagate errors from ptr_to_hashval() instead. In particular, this
allows userspace to retry PR_SCHED_CORE_GET when pointer hashing is
temporarily unavailable.

An early-boot x86_64 QEMU reproducer observed the following before the
fix:

  CREATE ret=0 errno=0 (Success)
  GET ret=0 errno=0 (Success) cookie=0x0000000000000000

With this fix, the same GET correctly returned:

  GET ret=-1 errno=16 (Device or resource busy)

The full cs_prctl_test also failed seven cookie assertions on the
unfixed kernel after PR_SCHED_CORE_CREATE succeeded but subsequent GETs
continued to report cookie 0.

Fixes: 7ac592aa35a6 ("sched: prctl() core-scheduling interface")
Cc: stable@vger.kernel.org
Signed-off-by: Hui Su <sh_def@163.com>
---
v2:
- No changes.

 kernel/sched/core_sched.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index 43e0bde3038e..f119a2973ca8 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -177,8 +177,9 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
 		}
 		cookie = sched_core_clone_cookie(task);
 		if (cookie) {
-			/* XXX improve ? */
-			ptr_to_hashval((void *)cookie, &id);
+			err = ptr_to_hashval((void *)cookie, &id);
+			if (err)
+				goto out;
 		}
 		err = put_user(id, (u64 __user *)uaddr);
 		goto out;
-- 
2.55.0


  reply	other threads:[~2026-09-13 14:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13 14:10 [PATCH v2 0/2] sched/core: Handle unavailable pointer hash in PR_SCHED_CORE_GET Hui Su
2026-09-13 14:10 ` Hui Su [this message]
2026-09-13 14:10 ` [PATCH v2 2/2] selftests/sched: Retry PR_SCHED_CORE_GET on EBUSY Hui Su

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260913141040.2338964-2-sh_def@163.com \
    --to=sh_def@163.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®