From nobody Fri Sep 25 11:08:00 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 D00CA34A79D; Sun, 13 Sep 2026 14:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789308715; cv=none; b=iCe+RUfiBb3WLquvwtGv767FBsYZAhNBuooVtmXIcwzas/9KjHVL0tXunS6/wtnq4uazgmjMHOmgRXHEdDoCeO0mt2Nmf5g+8TcXpHroJFR3+GhvbC1LJwXR8kOStN1x/+RKAv33mnKjLs0JijcvH9MWz4ONw8MBmpDPs+0+uRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789308715; c=relaxed/simple; bh=mJnOZtn5cuGbI2017nzUjEmKRHaxUcFGidgrANxD3uY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A2JyEKxw/ql5bxHiuA952VaLCBNfwisaffRI6CjpahTtoYpgl69qXdGrBQveotOFfWJVJlgU3o4FNkGwX7xkhqpN99DNY97nrkhj9e5TrjXVDrhHe7RsnHlqftWFabN102ZAao1jz++7OMouDTNOT3R57SlMwCTrpjRcd34FCYc= 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=Tvfjnhzs; arc=none smtp.client-ip=220.197.31.2 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="Tvfjnhzs" 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=MK a+Yb5kJ73XpCnhjg1Ux1w8fUhPw2uP6nQz6HAv/h0=; b=TvfjnhzsoECyoYtzLU jY7Zy/4G5uhlnOGDG40g8AzYx5rLn7KZnpApQ+IuIfsojhvIWJQNaaH5vjIaeQMX kOgucVmVODkTphpSjUB+8G7pT92XQQyuiuk4ZeYxbCS/qkNAx1BWfLe0/LtTsQQK yib9td4CJNUtp97NchPIw7ufM= Received: from localhost (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD3d7DirqZq7EjeAQ--.56354S2; Sun, 13 Sep 2026 22:10:43 +0800 (CST) From: Hui Su 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 , 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 Message-ID: <20260913141040.2338964-2-sh_def@163.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913141040.2338964-1-sh_def@163.com> References: <20260913141040.2338964-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: _____wD3d7DirqZq7EjeAQ--.56354S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFWkJrWkKr1kKFWDGF4xCrg_yoW8ZF18pr s8W3yxKrs7Kay8KF18Aw48JFyrGr12kFW3Wr4kJ34fKr4FvryaqryFyryaqF4UKrW0kFW0 yr129asIvryqy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piNJ55UUUUU= X-CM-SenderInfo: xvkbvvri6rljoofrz/xtbCwgMoh2qmruNQpQAA3a 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 --- 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, 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 11:08:00 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (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 E50953E9C12; Sun, 13 Sep 2026 14:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789308720; cv=none; b=oLLwFPo7y0AzkySAQUa6Gr9e6SKdIw7CZ/6GCJeIo4PnBOq0hiu/SGLMQkS9KZLUMRaLVacnJQcbCoYCYyOiIrpp+lQ3obLuM9KknFhn5+NB0kKAwh/tHN5BshDtnZjHlrmnWtOip/2GrUWawBWjDjx+7Q5Bw4Ydo+hsooWtm3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789308720; c=relaxed/simple; bh=5jEcgfzuFG9WzNTEsPant0FzwTi4FP0cWe2BNrm61y0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gWMEoZ6OwAWAZ1IDgQJ/tz3ARKEhCMtjYBJJH1a9WT4P5MlnRWzU0PWVbJnlOu8Xc+oWRErvziblVKfOIt83kqVran3vhvVicwz3yA5ahF3YNDJLYx5d2O6P3pZYdJvmJHjSZcal3MOEL7uCUkC3X30BtkY48OcXXISxyn2Myng= 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=e+Ssimcp; arc=none smtp.client-ip=220.197.31.4 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="e+Ssimcp" 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=hb 5u1gF4u/r+OYROsvy452ERxXcsq25RRWiIzysw9Bw=; b=e+SsimcpYFo/Zo4JmX qVtg1iW7lxEEV1cNyKJw95BlgikGqoH7a3oHb1kLpVdSpPuqCNQp3qr/3ovH2Otn kUBwZuU6KHa/e1MD7Ds2Pgrc4vGhUa8eoxm82PWppO21mYQNhWDluSqoz+PMP7oQ ccg+ezLn5sW1eF25WjHxlehNk= Received: from localhost (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3HwbjrqZqlLvuPw--.46190S2; Sun, 13 Sep 2026 22:10:44 +0800 (CST) From: Hui Su 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 Subject: [PATCH v2 2/2] selftests/sched: Retry PR_SCHED_CORE_GET on EBUSY Date: Sun, 13 Sep 2026 23:10:40 +0900 Message-ID: <20260913141040.2338964-3-sh_def@163.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260913141040.2338964-1-sh_def@163.com> References: <20260913141040.2338964-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: PSgvCgD3HwbjrqZqlLvuPw--.46190S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3Aw1UZFW7Cw4DCrW8WryUWrg_yoW3Gw1UpF W3tw1DtFW8WFW3Jr4kJr4kXFyrGrn8tF47Krsak34Iyw4UGr1UGryIy34aqry7Jr40qw45 ua1qy3ZFyFy7X3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JU1pBsUUUUU= X-CM-SenderInfo: xvkbvvri6rljoofrz/xtbCwgQpiGqmruRQswAA3C 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. Keep the syscall status separate from the returned cookie and abort the test if the GET still fails, so an error value cannot be compared as a valid cookie. Report other errors immediately instead of describing every failed GET as an unsupported core scheduling system. cs_prctl_test passes on x86_64 with normal random initialization. Signed-off-by: Hui Su --- v2: - Return cookie values directly from the fatal error helper to keep the selftest comparisons compact. - Avoid sleeping after the final retry. tools/testing/selftests/sched/cs_prctl_test.c | 93 +++++++++++++------ 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/= selftests/sched/cs_prctl_test.c index 52d97fae4dbd..7bd0bc262a6b 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" @@ -109,19 +111,43 @@ static void handle_usage(int rc, char *msg) exit(rc); } =20 -static unsigned long get_cs_cookie(int pid) +static int get_cs_cookie(int pid, unsigned long long *cookie) { - unsigned long long cookie; - int ret; + int i, ret, err =3D 0; =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; + 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 0; + + err =3D errno; + if (err !=3D EBUSY || i =3D=3D CORE_COOKIE_RETRIES - 1) + break; + + 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 err; +} + +static unsigned long long get_cs_cookie_or_die(int pid) +{ + unsigned long long cookie; + int err; + + err =3D get_cs_cookie(pid, &cookie); + if (!err) + return cookie; + + errno =3D err; + handle_error("get core sched cookie"); + __builtin_unreachable(); } =20 static int child_func_thread(void __attribute__((unused))*arg) @@ -202,15 +228,16 @@ void disp_processes(int num_processes, struct child_a= rgs proc[]) { int i, j; =20 - printf("tid=3D%d, / tgid=3D%d / pgid=3D%d: %lx\n", gettid(), getpid(), ge= tpgid(0), - get_cs_cookie(getpid())); + printf("tid=3D%d, / tgid=3D%d / pgid=3D%d: %llx\n", gettid(), getpid(), g= etpgid(0), + get_cs_cookie_or_die(getpid())); =20 for (i =3D 0; i < num_processes; ++i) { - printf(" tid=3D%d, / tgid=3D%d / pgid=3D%d: %lx\n", proc[i].cpid, pro= c[i].cpid, - getpgid(proc[i].cpid), get_cs_cookie(proc[i].cpid)); + printf(" tid=3D%d, / tgid=3D%d / pgid=3D%d: %llx\n", proc[i].cpid, pr= oc[i].cpid, + getpgid(proc[i].cpid), get_cs_cookie_or_die(proc[i].cpid)); for (j =3D 0; j < proc[i].num_threads; ++j) { - printf(" tid=3D%d, / tgid=3D%d / pgid=3D%d: %lx\n", proc[i].thr_= tids[j], - proc[i].cpid, getpgid(0), get_cs_cookie(proc[i].thr_tids[j])); + printf(" tid=3D%d, / tgid=3D%d / pgid=3D%d: %llx\n", proc[i].thr= _tids[j], + proc[i].cpid, getpgid(0), + get_cs_cookie_or_die(proc[i].thr_tids[j])); } } puts("\n"); @@ -280,30 +307,32 @@ int main(int argc, char *argv[]) create_processes(num_processes, num_threads, procs); need_cleanup =3D 1; disp_processes(num_processes, procs); - validate(get_cs_cookie(0) =3D=3D 0); + validate(get_cs_cookie_or_die(0) =3D=3D 0); =20 printf("\n## Set a cookie on entire process group\n"); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, PIDTYPE_PGID, 0) < 0) handle_error("core_sched create failed -- PGID"); disp_processes(num_processes, procs); =20 - validate(get_cs_cookie(0) !=3D 0); + validate(get_cs_cookie_or_die(0) !=3D 0); =20 /* get a random process pid */ pidx =3D rand() % num_processes; pid =3D procs[pidx].cpid; =20 - validate(get_cs_cookie(0) =3D=3D get_cs_cookie(pid)); - validate(get_cs_cookie(0) =3D=3D get_cs_cookie(procs[pidx].thr_tids[0])); + validate(get_cs_cookie_or_die(0) =3D=3D get_cs_cookie_or_die(pid)); + validate(get_cs_cookie_or_die(0) =3D=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); =20 printf("\n## Set a new cookie on entire process/TGID [%d]\n", pid); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, pid, PIDTYPE_TGID, 0) < 0) handle_error("core_sched create failed -- TGID"); disp_processes(num_processes, procs); =20 - validate(get_cs_cookie(0) !=3D get_cs_cookie(pid)); - validate(get_cs_cookie(pid) !=3D 0); - validate(get_cs_cookie(pid) =3D=3D get_cs_cookie(procs[pidx].thr_tids[0])= ); + validate(get_cs_cookie_or_die(0) !=3D get_cs_cookie_or_die(pid)); + validate(get_cs_cookie_or_die(pid) !=3D 0); + validate(get_cs_cookie_or_die(pid) =3D=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); =20 printf("\n## Copy the cookie of current/PGID[%d], to pid [%d] as PIDTYPE_= PID\n", getpid(), pid); @@ -311,9 +340,10 @@ int main(int argc, char *argv[]) handle_error("core_sched share to itself failed -- PID"); disp_processes(num_processes, procs); =20 - validate(get_cs_cookie(0) =3D=3D get_cs_cookie(pid)); - validate(get_cs_cookie(pid) !=3D 0); - validate(get_cs_cookie(pid) !=3D get_cs_cookie(procs[pidx].thr_tids[0])); + validate(get_cs_cookie_or_die(0) =3D=3D get_cs_cookie_or_die(pid)); + validate(get_cs_cookie_or_die(pid) !=3D 0); + validate(get_cs_cookie_or_die(pid) !=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); =20 printf("\n## Copy cookie from a thread [%d] to current/PGID [%d] as PIDTY= PE_PID\n", procs[pidx].thr_tids[0], getpid()); @@ -322,17 +352,20 @@ int main(int argc, char *argv[]) handle_error("core_sched share from thread failed -- PID"); disp_processes(num_processes, procs); =20 - validate(get_cs_cookie(0) =3D=3D get_cs_cookie(procs[pidx].thr_tids[0])); - validate(get_cs_cookie(pid) !=3D get_cs_cookie(procs[pidx].thr_tids[0])); + validate(get_cs_cookie_or_die(0) =3D=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); + validate(get_cs_cookie_or_die(pid) !=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); =20 printf("\n## Copy cookie from current [%d] to current as pidtype PGID\n",= getpid()); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, 0, PIDTYPE_PGID, 0) < 0) handle_error("core_sched share to self failed -- PGID"); disp_processes(num_processes, procs); =20 - validate(get_cs_cookie(0) =3D=3D get_cs_cookie(pid)); - validate(get_cs_cookie(pid) !=3D 0); - validate(get_cs_cookie(pid) =3D=3D get_cs_cookie(procs[pidx].thr_tids[0])= ); + validate(get_cs_cookie_or_die(0) =3D=3D get_cs_cookie_or_die(pid)); + validate(get_cs_cookie_or_die(pid) !=3D 0); + validate(get_cs_cookie_or_die(pid) =3D=3D + get_cs_cookie_or_die(procs[pidx].thr_tids[0])); =20 validate(_prctl(PR_SCHED_CORE, PR_SCHED_CORE_MAX, 0, PIDTYPE_PGID, 0) < 0 && errno =3D=3D EINVAL); --=20 2.55.0