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=1796537024; b=hLJ2ha+T5BIfehd/S8sSa/4StSvpNkd3DVgSS+391iqY31s3Mngq1z3Nc5HxbdCYcrAC 2T+4cXiwwzGOcvKf+3WY1RWrQLuAlGvP0QHpDzZ7BFIbFsfOLQVkKnLT2bJAOdsT+VHU1 CnGbI92jD7xfWpfn74VM9r/cf8+WIk1FSo0qmciXF/mKi3aeTk5v+PoKuwtiXyV4+6D/q cBku9s4fKGbGGmRJnFpXt1im/DvCriP38CzoqHAnrqGm0gEvAP3ckKI73+r0P4sadzOLD FRy32U1sR+eb9YIXTwJeiOq7zc6WTbi4GJ+o7aytO0x8JyjOti12lgKered5UgJipdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796537024; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=b8KyQILh5Jvj6tsjaYzpScibOBO+sHXMVyuncHG5MO4=; b=u9C0SwkvAYcmEu9GdFQs3lQa8fSpEunKS3ZahvTKhMI57sXcejUnBDs/1ZXd5Nnzbdoo P8ncRnqhP92sqjYDoAO9RmTtuMx7k1eJba9Dnz4T7iCTlgDAhpELUmQguNRZ2ARveEmVL 6ZBL7+JrbNCXfuk7rGlaVpjULoUGWZP5kVSpnih9bIG90jnqu9rVjgZ2efFBMteyfHF1+ kQqLyYL3hTTqGZtrImojvMedR029l+40GbzBdWMu5aC7jLR91VyDX0cKXNbAJgSW2lkTj ndsCq5yFaIWEbu5I2bW3WPnm5rmNh9JDnyCrfoy2qTtsDQi2OybmAkg+wKzr5luLTjg== 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="QX5Vcy/K"; 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 4CA19606A31F for ; Sun, 6 Dec 2026 06:03:44 +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=QX5Vcy/K Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11CD81F0092B; Sun, 6 Dec 2026 06:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796537024; bh=b8KyQILh5Jvj6tsjaYzpScibOBO+sHXMVyuncHG5MO4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QX5Vcy/KU5+T6xhTyzeF68Up6tEZZ3lOQCPSmXeJaBp1Kwsv/Om1b7WsHn3mgUWVc VmT1Axt/WWgDl18Z3KucO2GYXXKrrn5u6vOWTeWN3VkI5BHA+Jh62QybWlJ4k9PrHt obsE7cZTukXVn4O5kseFF6iCf0SwmpmjjIXqZ7DaonF0JWy7w5GxXoBUK6oyVLdDCt oOin/Lj4rfW2N3RMS8/6pPTfaalItqEroj1kgYA/6nVmECBzBFevTLSqqCyx7nnHFy 89NtG8cYlcBG63o3z1U8kmVTL+j5fRKY3NF3VxWhC52v4MQv0Hnfqe9h1ymij6YvUu vKPqXBxvHcu4A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 1/6] sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id() Reply-To: sashiko-reviews@lists.linux.dev To: "Changwoo Min" Cc: sched-ext@lists.linux.dev In-Reply-To: <20261206053728.2026272-2-changwoo@igalia.com> References: <20261206053728.2026272-1-changwoo@igalia.com> <20261206053728.2026272-2-changwoo@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 06:03:43 +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 1 potential issue to consider: - [Low] sched_ext: TOCTOU race between flags and sched loads in scx_task_sched_id() -- commit e70589ddaf2c9dcb29ade05fb3583c3b7983b075 Author: Changwoo Min sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id() This commit adds the scx_bpf_sched_id() kfunc to return the calling scheduler's instance id and the scx_task_sched_id() BPF helper to return the id of the scheduler owning a task. It also updates scx_set_task_state() to publish task state bits with a single WRITE_ONCE(). > diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/i= nclude/scx/compat.bpf.h > index 3520a749f8ce6..4d2298bd7ac55 100644 > --- a/tools/sched_ext/include/scx/compat.bpf.h > +++ b/tools/sched_ext/include/scx/compat.bpf.h > @@ -487,6 +487,67 @@ static inline void scx_bpf_task_set_lazy_resched(str= uct task_struct *p, bool laz [ ... ] > +static __always_inline u64 scx_task_sched_id(const struct task_struct *p) > +{ > + struct sched_ext_entity___task_id *scx =3D (void *)&p->scx; > + struct scx_sched___task_id *sch; > + u32 state; > + u64 id; > + > + if (!bpf_ksym_exists(scx_bpf_sched_id___new)) > + return 0; > + > + /* A sched owns @p only after ops.init_task() */ > + state =3D READ_ONCE(scx->flags) & > + bpf_core_enum_value(enum scx_ent_flags, SCX_TASK_STATE_MASK); > + if (state =3D=3D bpf_core_enum_value(enum scx_ent_flags, SCX_TASK_NONE)= || > + state =3D=3D bpf_core_enum_value(enum scx_ent_flags, SCX_TASK_INIT_= BEGIN) || > + state =3D=3D bpf_core_enum_value(enum scx_ent_flags, SCX_TASK_DEAD)) > + return 0; > + > + /* > + * Without CONFIG_EXT_SUB_SCHED, which @cgrp comes with, the kernel > + * doesn't set p->scx.sched, and the root is the only scheduler. > + */ > + if (!bpf_core_field_exists(struct scx_sched___task_id, cgrp)) > + return scx_bpf_sched_id(); > + > + /* Sleepable programs aren't in an RCU read section */ > + bpf_rcu_read_lock(); > + sch =3D scx->sched; > + id =3D sch ? sch->id : 0; > + bpf_rcu_read_unlock(); > + return id; > +} [Severity: Low] Can scx_task_sched_id() return a scheduler id for a task whose ops.init_task() never ran on that scheduler? Without CONFIG_EXT_SUB_SCHED, scx_task_sched_id() reads scx->flags and calls scx_bpf_sched_id() outside RCU. A sleepable BPF caller can read an active state under root scheduler S1, get preempted across S1 teardown and S2 startup, and return S2's id before S2 initializes p: CPU0 (sleepable BPF) CPU1 scx_task_sched_id(p) READ_ONCE(scx->flags) /* sees SCX_TASK_ENABLED */ scx_disable_workfn() /* S1 */ scx_set_task_state(p, SCX_TASK_NONE) synchronize_rcu() scx_enable() /* S2 */ rcu_assign_pointer(scx_root, S2) scx_bpf_sched_id() <-- returns S2->id before S2 ops.init_task(p) Because CPU0 is not inside bpf_rcu_read_lock(), synchronize_rcu() in scx_disable_workfn() does not wait for it. Wrapping the state check and scx_bpf_sched_id() in bpf_rcu_read_lock() prevents this straddle. With CONFIG_EXT_SUB_SCHED, an unlocked caller has a similar race with scx_punt_task(), which sets p to SCX_TASK_NONE and then assigns p->scx.sched without running ops.init_task(), letting scx_task_sched_id() pair the pre-punt active state with the new scx->sched pointer. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206053728.2026= 272-1-changwoo@igalia.com?part=3D1