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=1796148532; b=i/RcNuuUG/ABYxIgnhwQAKD3xGipMAK4y1NaDBiy78o+/y8CMn0C7MdQ789VFbA2ikKs LUsMjamaeVrIxm1UE4BzH027pu9wiV2peUOcWE4U0fkiM6e4ZEK16Wv9p4bLR/NSrl6d5 KK6XNCO3dbGSeOB0o9pyDtZsJ5N5rSMP2nLgOez0e4ZzdQETNSaOn77MtIubpmv5hYCKq lLN/lpRkUfY4nwKAkW9hTwKF3YT8wMC/v007TI+a9p5ySwUyY6y7lELMOPOP1TsmpX+aB i0yyi0Ae2NHREmpR9SbzIm896LirCZyaFELB0+UlFolOLEd8XTWd/wQUVSnhdiGPD1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148532; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ap4vsyHwYResMB8JBXm8k/A3pb97AwMI3oGi0iqp0ec=; b=Do2Eml35ZZjI90CPwFl/vqwruady9ROlalGlKh9DhuLruo+6shQwzhGB2p/NttO01Kzx YAIIByMZPl48NZcSyPZDxpNhd40ktJ56OEPzfUjJAna8sJeVj5pBw12NLuqOs/bESf811 jDi3NerCeu5CeE+OybrtrAbNH+GaCd0XOTzFdfPtNMXUTK5BG7+rW+CPABsyTKjWy9w6C VwiIEolenc2qgIAHfOyeKoTYVAjlrI7GlxL6B04rqNWhJCIr1ykaUux15/i/76BXRztlX k4qtDPfcong7+oAzZvcBqLAKY/1ZCfyttUSoGQZyfLmqWekJf+gLgPgvXuDfxw4gwiA== 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=g4ucmS2y; 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 3C766606A31A for ; Tue, 1 Dec 2026 18:08:51 +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=g4ucmS2y Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA8191F000C1; Tue, 1 Dec 2026 18:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796148531; bh=ap4vsyHwYResMB8JBXm8k/A3pb97AwMI3oGi0iqp0ec=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=g4ucmS2yICQdlXUsHxKHRLNM8FRMOuZnRzLAfgBJ3FzRy/9Q3te+ChYDk078iNgUt RJ2Z3U1wS6iYv0hl/Qx6Oub6rj95vnwuB6JVazq+Y5Mo/4Lflh/nP9oZp8IdIv1Jjv s2r7ST4ny/qs7AwcSDWE7CNtsYlleNkc+T2f+J0cXuSMwTlNebNG3BkY+g0u4TxAS0 nN6JKI8ynMqzyftz/wZONIQ/7jWw3aiU+qasAMrZZUmLkPOtyefi0nFBNfycPfxQft /5OmDBejnZijwlhgZ47G88cD8eMTBgDmg9WF3C1IZPI6IqP3/aYLv7YBrpX88teHug ORjZmfn4bVRPg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] srcu: Make srcu_barrier() wait for nested deferred callbacks Reply-To: sashiko-reviews@lists.linux.dev To: "Andrea Parri" Cc: bpf@vger.kernel.org In-Reply-To: <20261201175532.72556-1-parri.andrea@gmail.com> References: <20261201175532.72556-1-parri.andrea@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 18:08:51 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] srcu: callback list corruption on duplicate deferred __call_srcu() [1] -- commit 44be3f7a05942ce31e28c2b995f0b59469ca7b2d Author: Andrea Parri srcu: Make srcu_barrier() wait for nested deferred callbacks This commit updates srcu_barrier() to wait for an IPI to any CPU that still has callbacks on ->defer_cbs after srcu_defer_flush() and drain them again, ensuring callbacks from nested deferred call_srcu() invocations are not missed. > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c > index 2b0e2b2d2c187..157a4d94f2589 100644 > --- a/kernel/rcu/srcutree.c > +++ b/kernel/rcu/srcutree.c > @@ -112,6 +112,63 @@ static void srcu_defer_flush(void) > __srcu_defer_drain(&per_cpu(srcu_defer, cpu)); > } > =20 > +static void srcu_defer_ipi(void *unused) > +{ > +} > + > +/* > + * Does @sdp have deferred callbacks? A drainer takes them off ->defer_= cbs and > + * re-issues them under ->lock, so an empty list seen under ->lock means= none > + * is left mid-drain. > + */ > +static bool srcu_defer_pending(struct srcu_defer *sndp, struct srcu_data= *sdp) > +{ > + unsigned long flags; > + bool ret; > + > + raw_spin_lock_irqsave(&sndp->lock, flags); > + ret =3D !llist_empty(&sdp->defer_cbs); > + raw_spin_unlock_irqrestore(&sndp->lock, flags); > + return ret; > +} > + > +/* > + * Wait for @ssp's deferred callbacks whose staging was still in progres= s when > + * srcu_defer_flush() ran. __call_srcu() stages with interrupts disable= d, in > + * two steps: it adds the callback to ->defer_cbs, then chains the srcu_= data > + * onto the per-CPU list. A call_srcu() nested between the steps, from = an NMI > + * or a kprobe, returns before the srcu_data is chained, so the flush mi= sses its > + * callback and leaves ->defer_cbs non-empty. An IPI to that CPU return= s only > + * after the interrupted staging has finished, and a second drain then p= icks > + * the callback up. > + * > + * A CPU going offline leaves cpu_online_mask in take_cpu_down() but run= s until > + * it reports itself dead from the idle loop, and the IPI fails without = waiting > + * for it. Drain and sleep until its ->defer_cbs is empty instead. Tha= t ends: > + * a dead CPU cannot be part-way through staging, so all it staged is ch= ained. > + */ > +static void srcu_defer_wait_staging(struct srcu_struct *ssp) > +{ > + int cpu; > + > + if (!IS_ENABLED(CONFIG_RCU_DEFER)) > + return; > + > + for_each_possible_cpu(cpu) { > + struct srcu_data *sdp =3D per_cpu_ptr(ssp->sda, cpu); > + struct srcu_defer *sndp =3D &per_cpu(srcu_defer, cpu); > + > + while (srcu_defer_pending(sndp, sdp)) { > + int ret =3D smp_call_function_single(cpu, srcu_defer_ipi, NULL, 1); > + > + __srcu_defer_drain(sndp); > + if (!ret) > + break; > + schedule_timeout_uninterruptible(1); > + } > + } > +} [Severity: High] This problem wasn't introduced by this patch, but can a duplicate deferred call_srcu() truncate sdp->defer_cbs before __srcu_defer_drain() runs [1]? When should_rcu_defer() is true (such as during rcutorture's rcu_test_debug_objects() runs with interrupts disabled), __call_srcu() adds rhp directly to sdp->defer_cbs via llist_add() before srcu_do_enqueue() can check debug_rcu_head_queue(): kernel/rcu/srcutree.c:__call_srcu() { if (should_rcu_defer()) { ... sdp =3D this_cpu_ptr(ssp->sda); rhp->func =3D func; if (llist_add((struct llist_node *)rhp, &sdp->defer_cbs)) { sdp->ssp =3D ssp; if (llist_add(&sdp->defer_link, &sndp->list)) irq_work_queue(&sndp->iw); } return; } } If call_srcu() is called a second time on the same rhp before __srcu_defer_drain() runs, the second llist_add() overwrites rhp->next to point to itself (or to an intermediate node). When __srcu_defer_drain() clears rhp->next to bound the cycle, any earlier valid callbacks queued on sdp->defer_cbs behind the duplicate are detached and permanently lost, hanging waiters such as synchronize_srcu(). [1] https://sashiko.dev/#/bug/linux-426c730e-bf31-4178-bd44-460b2a8e5ae3 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201175532.7255= 6-1-parri.andrea@gmail.com?part=3D1