From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796536804; b=zRwPWVgrh1WqIc5l3rshZm650uPgyzUHw9IKMcIdZmknlFzqpBoyQPY3gbkuOMmfVo4S 4lzMrgpjBxROEVfDkVk9Zd3GvRGokSkuVb8tSRMKxJ2iIrlm7LvdLHJYOA0hkdyY3QAHz 15iHVGOismOTLPfNb+LNF67x1XOGYwuDlh++LsK3kZXO9weoHvhMenHh0SAANN/rYowSs aNRJYwH8yjaHAaZmJ3Pa1j8PKMOS/BG94b0VtVW64DJb8KYJMXeeiS6gvr+HbXMm3y2iu BnN1xHftWPbCctk6HXy1mr9Iyl9i9daFW+XFfMGBz9zfJ4nfWdP0Ke2j3G1ckEvf7lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536804; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=oJFMUfYvVuWCjvdqepcIHz/p0VfMDIMgI8JHnqjDeXU=; b=Qro8+rrFDWBGWdS62xwaSBymMYwWqczjUoLGlsPC9A3P+GGzfAGwx30qKd++JZ6uCxmP gX0pjLArvzFJQw6wSNboaogL/u78ZKQa40xfdvsY7d117e44S62smEdcjq8vWhUaKQdNe dyp7EtPoYyX5YPj5Ob8uP7HZ3fymQsX7vPFhgQV/ODFaxVYjKMhMQioYqR/nSLBC1442I d80LTytrBhRMYW/jc8ugPlvObehw8PqzWyXM2yFHARVibhh0olodJn+eI/Y6NID2txDhM i81wi6xOBUN4i+p2GZn9+DkWSeSmuZvMp/rKSajg/Dw22SAU2xrbNkIfd6KNntFCNFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JSBPYsGf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12B1E606A322 for ; Sun, 6 Dec 2026 06:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JSBPYsGf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C56B1F0093B; Sun, 6 Dec 2026 06:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796536803; bh=oJFMUfYvVuWCjvdqepcIHz/p0VfMDIMgI8JHnqjDeXU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JSBPYsGf7BgTD9eCpb84RtteGX2iT1dyuuvsjJWRzAcDMpV3YVnGUESCg92xug81S lq5AeNKe0SsC3S0VmuqNvPT1jjmtxNuosSlGV3Nkjb7kM5dYzdiqy4mln1oTr17fok gU+ewRcw8+1Fi3n+pV+ZB0CrYOnOAW7q5ImNIbVfWukialepBI0ytriOhyVicuYXDM t3UhhGhtiFDeJbOTR5D4C+kgu3WvpMVWKUY54nbWspnz3qWR4aoCZ82lcIDtg1h4XN Ivlkj50fbCmEnOKnffnTTe0yfQA6fO1Kg5n3fgq/a26D2uHuSqh4mlSI21EMqHsixA GAbelEFmJ/2ng== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 3/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Reply-To: sashiko-reviews@lists.linux.dev To: "Changwoo Min" Cc: sched-ext@lists.linux.dev In-Reply-To: <20261206053728.2026272-4-changwoo@igalia.com> References: <20261206053728.2026272-1-changwoo@igalia.com> <20261206053728.2026272-4-changwoo@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 06:00:03 +0000 X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] sched_ext: scx_bpf_task_set_priv() missing from scx_kfunc_ids_no_sub_caps - [Low] sched_ext: scx_bpf_task_priv() takes non-const task_struct pointer - [Low] sched_ext: 64-bit p->scx.bpf_priv accesses can tear on 32-bit x86 SMP -- commit d733d17a1b2f82be9f9d84dff228752ded0286a8 Author: Changwoo Min sched_ext: Add p->scx.bpf_priv for O(1) task context lookup This commit adds an opaque u64 field p->scx.bpf_priv, a kfunc scx_bpf_task_set_priv() to update it while the calling scheduler owns the task, and a compat.bpf.h helper scx_bpf_task_priv() to read it locklessly. > diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h > index f3564581c317c..a1793ab5f0c32 100644 > --- a/include/linux/sched/ext.h > +++ b/include/linux/sched/ext.h > @@ -277,6 +277,17 @@ struct sched_ext_entity { > */ > atomic64_t slice_oob; > =20 > + /* > + * Opaque value owned by the task's scheduler, typically an arena > + * pointer to its per-task context. The kernel never dereferences it. > + * Set with scx_bpf_task_set_priv() while @p is on the scheduler, > + * from after ops.init_task() until ops.exit_task(), and cleared > + * after ops.exit_task(). Any BPF program can read it, so a tracing > + * program can reach the context of the current task with a single > + * load. > + */ > + u64 bpf_priv; > + [Severity: Low] Can 64-bit accesses to p->scx.bpf_priv tear on 32-bit x86 SMP? Both scx_bpf_task_set_priv() and __scx_disable_and_exit_task() update p->scx.bpf_priv with WRITE_ONCE(), which splits a 64-bit store into two 32-bit stores on CONFIG_X86_32. On the reader side, do_jit() in arch/x86/net/bpf_jit_comp32.c compiles the 64-bit BPF_LDX load from scx_bpf_task_priv() into two 32-bit mov loads. CPU0 (writer) CPU1 (lockless BPF reader) __scx_disable_and_exit_task() WRITE_ONCE(p->scx.bpf_priv, 0) store low 32 bits =3D 0 scx_bpf_task_priv() load low 32 bits (0) load high 32 bits (old tag) <-- torn read store high 32 bits =3D 0 On CONFIG_X86_32 SMP, bpf_jit_supports_kfunc_call() is enabled and a callback-less root scheduler can attach without trampoline support, allowing a BPF_PROG_TYPE_SYSCALL program to write via scx_bpf_task_set_priv() while another CPU reads concurrently. A torn load can pair a matching scheduler = ID tag with a zeroed or stale payload, breaking the documented tagged-ID lockless read contract. > diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c > index 343d82f328efc..4f575a19df761 100644 > --- a/kernel/sched/ext/ext.c > +++ b/kernel/sched/ext/ext.c [ ... ] > @@ -12347,6 +12435,7 @@ static const struct btf_kfunc_id_set scx_kfunc_se= t_any =3D { > BTF_KFUNCS_START(scx_kfunc_ids_no_tracing) > BTF_ID_FLAGS(func, scx_bpf_cpuperf_set, KF_IMPLICIT_ARGS) > BTF_ID_FLAGS(func, scx_bpf_cidperf_set, KF_IMPLICIT_ARGS) > +BTF_ID_FLAGS(func, scx_bpf_task_set_priv, KF_IMPLICIT_ARGS | KF_RCU) > BTF_ID_FLAGS(func, scx_bpf_sub_grant, KF_IMPLICIT_ARGS) > BTF_ID_FLAGS(func, scx_bpf_sub_revoke, KF_IMPLICIT_ARGS) > BTF_ID_FLAGS(func, scx_bpf_destroy_dsq, KF_IMPLICIT_ARGS) [Severity: Medium] Should scx_bpf_task_set_priv also be added to scx_kfunc_ids_no_sub_caps? Because scx_bpf_task_set_priv is in scx_kfunc_ids_any and absent from scx_kfunc_ids_no_sub_caps, scx_kfunc_context_filter() allows ops.sub_caps_updated() to call it. caps_updated_deliver() invokes ops.sub_caps_updated() synchronously with locked_rq =3D NULL under guard(irqsave)(), inheriting whatever scx_locked_rq() and kf_tasks[] state the parent scheduler holds. Calling scx_bpf_task_set_priv() there therefore depends on the parent's locking context, either silently returning false when the parent holds an rq lock or taking task_rq_lock() inside caps_updated_deliver() when called unlocked. Adding it to scx_kfunc_ids_no_sub_caps would match how scx_bpf_cidperf_set() is restricted. > diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/i= nclude/scx/compat.bpf.h > index 4d2298bd7ac55..e8cb5f35eed08 100644 > --- a/tools/sched_ext/include/scx/compat.bpf.h > +++ b/tools/sched_ext/include/scx/compat.bpf.h [ ... ] > +/* p->scx.bpf_priv, or 0 on kernels without it */ > +static __always_inline u64 scx_bpf_task_priv(struct task_struct *p) > +{ > + struct sched_ext_entity___bpf_priv *scx =3D (void *)&p->scx; > + > + if (bpf_core_field_exists(scx->bpf_priv)) > + return READ_ONCE(scx->bpf_priv); > + return 0; > +} [Severity: Low] Should scx_bpf_task_priv() take a const struct task_struct *p? It only performs a read-only load of p->scx.bpf_priv, while its companion scx_task_sched_id() immediately below and the other task inspection helpers in common.bpf.h all accept const struct task_struct *p. Taking a non-const pointer prevents callers with a const task pointer from using it without a cast. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206053728.2026= 272-1-changwoo@igalia.com?part=3D3