From nobody Fri Sep 25 12:04:11 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 749743C1D53; Sun, 13 Sep 2026 06:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789281359; cv=none; b=QqCGdo1aphsM487pVL1aZpuJnzGTQ/hLe8R4JTn8MR++4wHygwR/aZseCDBMLcEUydHpY9A8fw0yW6/3u22bgO1lsSMj3q9OgRL001BhcJAvszFTSUMXq2ufq+ky9XUTM4WTVnE4dTltEFEIc6vJLNuz03wvxORWxgJPDwspMpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789281359; c=relaxed/simple; bh=K7fPKCJ+Xx+ataxj1VxJwzwRhB9AfyKsvQNjgHLN2qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fjazpo8A4Wy85hfedfuRmW6W8mu95LBbykYxZeWMUafsDCxw7fTZ1C0JyiismIxZ7qD7mTP073AfQOOEcdPlUnw0rYY+YwGCi+C7+hpcu9AA1FcGdXSl2/ZeRMo3nDvseY9XOEYu939lZiySdqyUiwmB4YWfhde/tSqTf9sco0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=QIVUTa90; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="QIVUTa90" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=7C flEv2FrrwTLg4pOvkoWVb1FkOEdZ9mWjEaIhtJj4c=; b=QIVUTa90da21RC7Tgi qL+Jr19Jzcpqgne87ZMrzTmHLokEaZdKnx4FlezKWgQQbWB7/BT4YQYG+Ie/IaZp mXJsxFt4vQXKf/8OcvroTYP4+S+A7KB+Np6aoXbnCaaiDAVnlTHg4I0uOgzb5vfm WSddPwbEhbuo6hQP40CQTvwTY= Received: from localhost (unknown []) by gzga-smtp-mtada-g0-3 (Coremail) with SMTP id _____wAnd4cARKZqCcuWAQ--.26522S2; Sun, 13 Sep 2026 14:34:41 +0800 (CST) From: Hui Su To: mingo@redhat.com, peterz@infradead.org Cc: juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, shuah@kernel.org, chris.hyser@oracle.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, sh_def@163.com, stable@vger.kernel.org Subject: [PATCH v1 1/2] sched/core: Propagate pointer hash errors from PR_SCHED_CORE_GET Date: Sun, 13 Sep 2026 15:34:38 +0900 Message-ID: <20260913063439.1513107-2-sh_def@163.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913063439.1513107-1-sh_def@163.com> References: <20260913063439.1513107-1-sh_def@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAnd4cARKZqCcuWAQ--.26522S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFWkJrWkKr1kKFWDGF4xCrg_yoW8Zryfpr sxW3yxKrs7Kay8KF18Aw48AFyrWr12kFW3Wr4kJrySkr4Fv34aqryFkryaqF4UKrW0kFW0 kr129asIv34qy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrR6wUUUUU= X-CM-SenderInfo: xvkbvvri6rljoofrz/xtbC6QFVtGqmRAFu4AAA3O Content-Type: text/plain; charset="utf-8" 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=3D0 errno=3D0 (Success) GET ret=3D0 errno=3D0 (Success) cookie=3D0x0000000000000000 With this fix, the same GET correctly returned: GET ret=3D-1 errno=3D16 (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 --- 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, e= num pid_type type, } cookie =3D sched_core_clone_cookie(task); if (cookie) { - /* XXX improve ? */ - ptr_to_hashval((void *)cookie, &id); + err =3D ptr_to_hashval((void *)cookie, &id); + if (err) + goto out; } err =3D put_user(id, (u64 __user *)uaddr); goto out; --=20 2.55.0 From nobody Fri Sep 25 12:04:11 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2DE6374745; Sun, 13 Sep 2026 06:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789281359; cv=none; b=YFbxYIdt0Iwb+mwJoJF/Kd30alYOEFYVFLgxUDfDeGeK1mQWFG7AG1aJpyQtYfYOFrdVuHUBYqxs8bHSG2xrMdg6BusdREPcoRFJJ92g572DjMTn92fYVhbeEkLS0VorZrzZMGADLrEl2cKSjMawOYq3jlcwJ59Oy7+r1NMYY3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789281359; c=relaxed/simple; bh=ONiEDh5RCxcG+d5MzmF6pFw2I9pINv/Sb5S7kG8toDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mRLxAWk4bSGUPEizPbXX6+jrovRiVSnFPpPp5AMoYZhluxd5FCm/GlkuufoepjO6etn3YQMZ0XUkj5DMHRXj0zK+9/eWFEKtdl/2tKDCYToYRfosTOUA6/6rQ6uveXSxnhFVAa28Eptj6MLAQ9QMEtiBVdIq2+gEUFKkytJJLwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=T1nXMjx+; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="T1nXMjx+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Uy dHFPlT/LvY4TGP582dBZaNlxC8hCkdi8SuWa1765Q=; b=T1nXMjx+/J/TFiLjFu f6FHOP6asrmaE0XFiQPajqVkOvtnPzwaTqr7pu9D2VWOy2CAo//rqRJl+iCntWIm 72VSyu4iKX3r+g9+JEQ1UTjEyQ4UVAo4az4Rh81fVuC3gueRfeCOMtCObmZEx89L OonKSwdoTJnXKKviyhtEA5xdE= Received: from localhost (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD3z+gBRKZq3wuLAQ--.45906S2; Sun, 13 Sep 2026 14:34:42 +0800 (CST) From: Hui Su To: mingo@redhat.com, peterz@infradead.org Cc: juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, shuah@kernel.org, chris.hyser@oracle.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, sh_def@163.com Subject: [PATCH v1 2/2] selftests/sched: Retry PR_SCHED_CORE_GET on EBUSY Date: Sun, 13 Sep 2026 15:34:39 +0900 Message-ID: <20260913063439.1513107-3-sh_def@163.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913063439.1513107-1-sh_def@163.com> References: <20260913063439.1513107-1-sh_def@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3z+gBRKZq3wuLAQ--.45906S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww1DGr45Xw4kWFWruw1DGFg_yoW8uFWrpr WfX34DtF4YgF9xtrn3JrWvgryrZrnFqFWUGw4fJryxAw48t3WUtr1xtF4agF17CFWFv3yS yr4ava4YkayDJ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUjjg7UUUUU= X-CM-SenderInfo: xvkbvvri6rljoofrz/xtbCwQJVtGqmRALRZgAA3f Content-Type: text/plain; charset="utf-8" During early boot, the pointer hash key may not be initialized when PR_SCHED_CORE_GET is called. With the preceding kernel fix, GET reports EBUSY until the pointer hash key becomes available. Retry the operation for up to one second when it returns EBUSY. Report other errors immediately, instead of describing every failed GET as an unsupported core scheduling system. cs_prctl_test passes on x86_64 QEMU with normal random initialization. A targeted early-boot probe also confirmed that the fixed kernel returns EBUSY while pointer hashing is unavailable. Signed-off-by: Hui Su --- tools/testing/selftests/sched/cs_prctl_test.c | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/= selftests/sched/cs_prctl_test.c index 52d97fae4dbd..dcb661cace5e 100644 --- a/tools/testing/selftests/sched/cs_prctl_test.c +++ b/tools/testing/selftests/sched/cs_prctl_test.c @@ -51,6 +51,8 @@ static pid_t gettid(void) =20 #define MAX_PROCESSES 128 #define MAX_THREADS 128 +#define CORE_COOKIE_RETRIES 100 +#define CORE_COOKIE_RETRY_US 10000 =20 static const char USAGE[] =3D "cs_prctl_test [options]\n" " options:\n" @@ -112,16 +114,27 @@ static void handle_usage(int rc, char *msg) static unsigned long get_cs_cookie(int pid) { unsigned long long cookie; - int ret; + int i, ret, err =3D 0; + + for (i =3D 0; i < CORE_COOKIE_RETRIES; i++) { + ret =3D prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, + (unsigned long)&cookie); + if (!ret) + return cookie; + + err =3D errno; + if (err !=3D EBUSY) + break; =20 - ret =3D prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, - (unsigned long)&cookie); - if (ret) { - printf("Not a core sched system\n"); - return -1UL; + usleep(CORE_COOKIE_RETRY_US); } =20 - return cookie; + if (err =3D=3D EBUSY) + printf("Timed out waiting for core sched cookie\n"); + else + printf("Failed to get core sched cookie: %s\n", strerror(err)); + + return -1UL; } =20 static int child_func_thread(void __attribute__((unused))*arg) --=20 2.55.0