From nobody Wed Dec 17 20:40:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3192E2D1F68; Tue, 29 Apr 2025 13:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934194; cv=none; b=EoNhznKHMiWL+JOr9JdNgzIqoS0plwJi2QPyVXiiRTED9KI9ZWbOi+6ACliNswDcLsTy3u4FKyYbJBaLGcXbqVHJFrd27tGVdQU8+JUjuvuHI49MnMjTMGxsKDh1pSVN3rw7EO7xikQa81tjF1FDnBHdnmiQSNnzfi5HTA23M6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934194; c=relaxed/simple; bh=tNR7OxZ4D8Xc5LSW0eegi8c20pJ6DRwVBXL2pcIjr2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rMlbvFDrentb6Tcyx1s5XpqmpRNeoBCp+R+dGZtJnzUzxrpa5ToU24s0KpQwNh7nwFUGJCyDj65F8pbtAmeYazaNlJiTnzNNBeRPPrhuohHHdx4gKhL7f4G29BT/FbRyXmFpQR3i9DJJ3J0La3pXkaD+ma50//ROfG8pNRLTxNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=htQ9SkSS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="htQ9SkSS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1495DC4CEED; Tue, 29 Apr 2025 13:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745934194; bh=tNR7OxZ4D8Xc5LSW0eegi8c20pJ6DRwVBXL2pcIjr2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=htQ9SkSSYp6CDrTeHCN9tTubzgDe2taTnQbqBgLymRB2OpeKCCv4CZhQ4eWEOJ2e9 9EQEp+j3L3YMxwJIqsxUcwrZn0cW0WnlPI2i2PsJr19jZhk4VTd9cQE/DvbWx9xPQT cIWKFe/30a4cmMsPMYxl7f6fNvdGv4kp4GO9ND3XGFAdvG6sHz2mO6pIWsbv598K68 tnejouFYMi1ibzRd3D4ZX0NkuFL+JrhYd4Hg4MIEyFhFv9MLHnN66D6+jOD7u9QTsb Yj6otiy5MKS3Gyz+YAl8gSjL4ASZmTIDNmFME+joe3WuSssBGI8LnmvUermNaiSmjZ 9p2MWqB0X6n0g== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , "Paul E . McKenney" , Uladzislau Rezki , Zqiang , rcu Subject: [PATCH 1/5] rcu/exp: Protect against early QS report Date: Tue, 29 Apr 2025 15:43:00 +0200 Message-ID: <20250429134304.3824863-2-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429134304.3824863-1-frederic@kernel.org> References: <20250429134304.3824863-1-frederic@kernel.org> 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 Content-Type: text/plain; charset="utf-8" When a grace period is started, the ->expmask of each node is set up from sync_exp_reset_tree(). Then later on each leaf node also initialize its ->exp_tasks pointer. This means that the initialization of the quiescent state of a node and the initialization of its blocking tasks happen with an unlocked node gap in-between. It happens to be fine because nothing is expected to report an exp quiescent state within this gap, since no IPI have been issued yet and every rdp's ->cpu_no_qs.b.exp should be false. However if it were to happen by accident, the quiescent state could be reported and propagated while ignoring tasks that blocked _before_ the start of the grace period. Prevent such trouble to happen in the future and initialize both the quiescent states mask to report and the blocked tasks head from the same node locked block. If a task blocks within an RCU read side critical section before sync_exp_reset_tree() is called and is then unblocked between sync_exp_reset_tree() and __sync_rcu_exp_select_node_cpus(), the QS won't be reported because no RCU exp IPI had been issued to request it through the setting of srdp->cpu_no_qs.b.exp. Reviewed-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree_exp.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index c36c7d5575ca..2fa7aa9155bd 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -141,6 +141,13 @@ static void __maybe_unused sync_exp_reset_tree(void) raw_spin_lock_irqsave_rcu_node(rnp, flags); WARN_ON_ONCE(rnp->expmask); WRITE_ONCE(rnp->expmask, rnp->expmaskinit); + /* + * Need to wait for any blocked tasks as well. Note that + * additional blocking tasks will also block the expedited GP + * until such time as the ->expmask bits are cleared. + */ + if (rcu_is_leaf_node(rnp) && rcu_preempt_has_tasks(rnp)) + WRITE_ONCE(rnp->exp_tasks, rnp->blkd_tasks.next); raw_spin_unlock_irqrestore_rcu_node(rnp, flags); } } @@ -393,13 +400,6 @@ static void __sync_rcu_exp_select_node_cpus(struct rcu= _exp_work *rewp) } mask_ofl_ipi =3D rnp->expmask & ~mask_ofl_test; =20 - /* - * Need to wait for any blocked tasks as well. Note that - * additional blocking tasks will also block the expedited GP - * until such time as the ->expmask bits are cleared. - */ - if (rcu_preempt_has_tasks(rnp)) - WRITE_ONCE(rnp->exp_tasks, rnp->blkd_tasks.next); raw_spin_unlock_irqrestore_rcu_node(rnp, flags); =20 /* IPI the remaining CPUs for expedited quiescent state. */ --=20 2.48.1 From nobody Wed Dec 17 20:40:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DA0222D29B9; Tue, 29 Apr 2025 13:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934196; cv=none; b=WPAlT2eUPc/wcgHtcMzbsZvCytezBqiyRH16VAqCHmZ/mHU9mew5TkE8AAmGRwHuYhurqosjp3uPqIbI1/Gqr9jzxgbBJTHhDqqTsqktydFJtI1Jbt0q2hHoB9YCW1RtHnaEXy1MdCx4XNUZ4KLztvMlKRUlYbnr9VLUsnnAw1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934196; c=relaxed/simple; bh=jT+JCug3rY6Eclx9wz6YCHHOuZE/75MafzqB5rX/F6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F3zHbyi/hNo3C2+U8V06XMoCgn8k0U8UUWebd7Bzb6/WUDteqhU7wCsL7f7buu1H5SYHxFzrychVfA+z+QDm16PYt2ycMHgzcMaCoLqq23flP+s+kDzjSs8cCpF/DReryNARcYwT1ZHi3xKeMMpn/65g3c2LtJHns3NCGEqQ/OA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TGs5eYE/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TGs5eYE/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CDC8C4CEEB; Tue, 29 Apr 2025 13:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745934196; bh=jT+JCug3rY6Eclx9wz6YCHHOuZE/75MafzqB5rX/F6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGs5eYE/zJt3gO/xiEsdExNC96ap/UtpBhYV2Lncl2gYiQwpU2O596rQembt2CkNm Sgtsti/vvGMGpeIek4lNmGLmgmoxpCT+sCS6szayOKcrFo+/KWnzlf9iDGV7AyLgu5 3TfXaQLU3jk355dSne9r3QrqXv+ZyeaFX/MO+rdxjPX18H9HTzfNj/D8/XSZ0MxmK0 VhZPW0KJQuSppDcsbz0t6doBNQrz071nKP6PxOrP75TioeGG8Lo1N5vEgJRBVxAlpb HKbkfkPDIRKNK/Op30A5Va2vlVnfLqbiwt8xcbvsbUBvzDmFF0ZNckeJP065aoYjwn CeytYZsKGojCw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , "Paul E . McKenney" , Uladzislau Rezki , Zqiang , rcu Subject: [PATCH 2/5] rcu/exp: Remove confusing needless full barrier on task unblock Date: Tue, 29 Apr 2025 15:43:01 +0200 Message-ID: <20250429134304.3824863-3-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429134304.3824863-1-frederic@kernel.org> References: <20250429134304.3824863-1-frederic@kernel.org> 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 Content-Type: text/plain; charset="utf-8" A full memory barrier in the RCU-PREEMPT task unblock path advertizes to order the context switch (or rather the accesses prior to rcu_read_unlock()) with the expedited grace period fastpath. However the grace period can not complete without the rnp calling into rcu_report_exp_rnp() with the node locked. This reports the quiescent state in a fully ordered fashion against updater's accesses thanks to: 1) The READ-SIDE smp_mb__after_unlock_lock() barrier accross nodes locking while propagating QS up to the root. 2) The UPDATE-SIDE smp_mb__after_unlock_lock() barrier while holding the the root rnp to wait/check for the GP completion. 3) The (perhaps redundant given step 1) and 2)) smp_mb() in rcu_seq_end() before the grace period completes. This makes the explicit barrier in this place superflous. Therefore remove it as it is confusing. Acked-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree_plugin.h | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 3c0bbbbb686f..d51cc7a5dfc7 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -534,7 +534,6 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *= t, unsigned long flags) WARN_ON_ONCE(rnp->completedqs =3D=3D rnp->gp_seq && (!empty_norm || rnp->qsmask)); empty_exp =3D sync_rcu_exp_done(rnp); - smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */ np =3D rcu_next_node_entry(t, rnp); list_del_init(&t->rcu_node_entry); t->rcu_blocked_node =3D NULL; --=20 2.48.1 From nobody Wed Dec 17 20:40:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2902F2D29CE; Tue, 29 Apr 2025 13:43:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934199; cv=none; b=XYxB5UkMu9LDDWjW19j9s9KrldZdRVEumgauODphsgpwHDdJq/IBaCsBjZkOaFGUacwTjoziIW2DTq6CYuOluJe9ghCNNXdUpCknxaC1+1Pv7oDPKBCElZpSWW1988XAXRdSVBFreaK6Wr/dYD/CTeyQ1TEqgb4ZYsECEXnI9og= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934199; c=relaxed/simple; bh=LvEdS+axYlVyjNN2L87xRki9bE4HGFdIFlgLzqRz9hI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fbsCTy2QQbCCMuEjE4KXammipsyqjwbFzTX+h6Jzl3v8cvLLBG7CAnj550HnaTfvYXCkESpAWqeTK1xd8Dt6mJRDRAvAUTCm1ldxDPZYt9kkaFz+1cJ6WTHRQO6pmd3y34VXnPYFAOEZQo9QoxagF75L8sobkEbIlU200ivePWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZOIJScua; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZOIJScua" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD579C4CEEF; Tue, 29 Apr 2025 13:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745934198; bh=LvEdS+axYlVyjNN2L87xRki9bE4HGFdIFlgLzqRz9hI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOIJScuaU9C52Q+ifn1DYPpGcsSA1pgol9svBU+GOhXoe9pDPk0S0y/DBF7nd4+WX tGQOiCAfDQzep1JPJ7Im70eujuh2QAgXrp6vVomDUR58P/2NuaMg8lKipAh0pOQVi7 hxDYKVXXzFm/QN/o3416NULWAT2fFgpKqZWz4gP/hN6ivBvN5Rvsan2lYmmQp4jlCb cGwCBrZzmMR+3l3AVs47C9ckEnNbKpKkPOmHmMN6VXcqYGg0/7oFZspQC417L758IR YvT1Ux3jQkaBk5x7sJ+MA685GdNkjdgAf5uz9a4ES789iOcWioocahdeAJQITEAer1 arkvvdo4U0AdQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , "Paul E . McKenney" , Uladzislau Rezki , Zqiang , rcu Subject: [PATCH 3/5] rcu/exp: Remove needless CPU up quiescent state report Date: Tue, 29 Apr 2025 15:43:02 +0200 Message-ID: <20250429134304.3824863-4-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429134304.3824863-1-frederic@kernel.org> References: <20250429134304.3824863-1-frederic@kernel.org> 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 Content-Type: text/plain; charset="utf-8" A CPU coming online checks for an ongoing grace period and reports a quiescent state accordingly if needed. This special treatment that shortcuts the expedited IPI finds its origin as an optimization purpose on the following commit: 338b0f760e84 (rcu: Better hotplug handling for synchronize_sched_expedited= () The point is to avoid an IPI while waiting for a CPU to become online or failing to become offline. However this is pointless and even error prone for several reasons: * If the CPU has been seen offline in the first round scanning offline and idle CPUs, no IPI is even tried and the quiescent state is reported on behalf of the CPU. * This means that if the IPI fails, the CPU just became offline. So it's unlikely to become online right away, unless the cpu hotplug operation failed and rolled back, which is a rare event that can wait a jiffy for a new IPI to be issued. * But then the "optimization" applying on failing CPU hotplug down only applies to !PREEMPT_RCU. * This force reports a quiescent state even if ->cpu_no_qs.b.exp is not set. As a result it can race with remote QS reports on the same rdp. Fortunately it happens to be OK but an accident is waiting to happen. For all those reasons, remove this optimization that doesn't look worthy to keep around. Reported-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker Reviewed-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree.c | 2 -- kernel/rcu/tree_exp.h | 45 ++----------------------------------------- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 90d0214c05c7..5be292667385 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -160,7 +160,6 @@ static void rcu_report_qs_rnp(unsigned long mask, struc= t rcu_node *rnp, unsigned long gps, unsigned long flags); static void invoke_rcu_core(void); static void rcu_report_exp_rdp(struct rcu_data *rdp); -static void sync_sched_exp_online_cleanup(int cpu); static void check_cb_ovld_locked(struct rcu_data *rdp, struct rcu_node *rn= p); static bool rcu_rdp_is_offloaded(struct rcu_data *rdp); static bool rcu_rdp_cpu_online(struct rcu_data *rdp); @@ -4264,7 +4263,6 @@ int rcutree_online_cpu(unsigned int cpu) raw_spin_unlock_irqrestore_rcu_node(rnp, flags); if (rcu_scheduler_active =3D=3D RCU_SCHEDULER_INACTIVE) return 0; /* Too early in boot for scheduler work. */ - sync_sched_exp_online_cleanup(cpu); =20 // Stop-machine done, so allow nohz_full to disable tick. tick_dep_clear(TICK_DEP_BIT_RCU); diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 2fa7aa9155bd..6058a734090c 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -751,12 +751,8 @@ static void rcu_exp_handler(void *unused) struct task_struct *t =3D current; =20 /* - * First, is there no need for a quiescent state from this CPU, - * or is this CPU already looking for a quiescent state for the - * current grace period? If either is the case, just leave. - * However, this should not happen due to the preemptible - * sync_sched_exp_online_cleanup() implementation being a no-op, - * so warn if this does happen. + * WARN if the CPU is unexpectedly already looking for a + * QS or has already reported one. */ ASSERT_EXCLUSIVE_WRITER_SCOPED(rdp->cpu_no_qs.b.exp); if (WARN_ON_ONCE(!(READ_ONCE(rnp->expmask) & rdp->grpmask) || @@ -803,11 +799,6 @@ static void rcu_exp_handler(void *unused) WARN_ON_ONCE(1); } =20 -/* PREEMPTION=3Dy, so no PREEMPTION=3Dn expedited grace period to clean up= after. */ -static void sync_sched_exp_online_cleanup(int cpu) -{ -} - /* * Scan the current list of tasks blocked within RCU read-side critical * sections, printing out the tid of each that is blocking the current @@ -885,38 +876,6 @@ static void rcu_exp_handler(void *unused) rcu_exp_need_qs(); } =20 -/* Send IPI for expedited cleanup if needed at end of CPU-hotplug operatio= n. */ -static void sync_sched_exp_online_cleanup(int cpu) -{ - unsigned long flags; - int my_cpu; - struct rcu_data *rdp; - int ret; - struct rcu_node *rnp; - - rdp =3D per_cpu_ptr(&rcu_data, cpu); - rnp =3D rdp->mynode; - my_cpu =3D get_cpu(); - /* Quiescent state either not needed or already requested, leave. */ - if (!(READ_ONCE(rnp->expmask) & rdp->grpmask) || - READ_ONCE(rdp->cpu_no_qs.b.exp)) { - put_cpu(); - return; - } - /* Quiescent state needed on current CPU, so set it up locally. */ - if (my_cpu =3D=3D cpu) { - local_irq_save(flags); - rcu_exp_need_qs(); - local_irq_restore(flags); - put_cpu(); - return; - } - /* Quiescent state needed on some other CPU, send IPI. */ - ret =3D smp_call_function_single(cpu, rcu_exp_handler, NULL, 0); - put_cpu(); - WARN_ON_ONCE(ret); -} - /* * Because preemptible RCU does not exist, we never have to check for * tasks blocked within RCU read-side critical sections that are --=20 2.48.1 From nobody Wed Dec 17 20:40:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 62A882D3208; Tue, 29 Apr 2025 13:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934201; cv=none; b=iylOWEAhUh79CH8ATe/kc44V6y9kWjtX9ffAGu8Jr2gaGb3TMBKd/J5FVWYPbvrBg4MPtptubJNQUunkRpiSoRLu0JWZhrsAhMqKcaa5mshGI2sUL83Gf7c/ghvn3RSEZXHi709d1VshLVAFIixPdQS5dGk95g38e9EhIEacbSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934201; c=relaxed/simple; bh=JzScvX4/KWOWu92ElQeUAb8SA6xsSgfyRoCjWHokjL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SrBOcO7EhdMX5Vju8ZMfnbp/mcTQcSr65xNjN6NCW1TA3uGgedN6XfveVBAKW9tSO3BRhA2BGDI/56LnOjYu01JMtKA8v83e0QokvFyNlosWdKcRKV7y4c0PImySw4yzTyl4lmeLeLfq3jEjpnegSryjlFfAgJ2O1RdB002KwGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YzgYMth1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YzgYMth1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0596FC4CEED; Tue, 29 Apr 2025 13:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745934200; bh=JzScvX4/KWOWu92ElQeUAb8SA6xsSgfyRoCjWHokjL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YzgYMth1C/+Nvv5cWeKgVT03KJsVXSiWqXRFuHzdclSVY6CdjJMGA+TLSQhiw2vZ3 qjfXS0t7Bm/OpQ9ApTVzt0Cygdt1SHlLOEBTOvofDc8VC3Oth8NQ/keEu5y2m86dZh 9M7FMmR7mxO0+ZKcEJJHjU5PtZcvqLRdUejQC3EY4NCac/oSW82oprtlAsaMbcqXeB +xcO++7KJotcWdE3bdgXwpAI4a1l/xYKlm1c8pyoTl31lEwKqfCIL1LUuBdmfJZRyK 1ui4AV+G59vDqIfDsIopcbyASPE8P3yhOI/6Ewe+7aUkuJLjXoOXf/t+STsr0ePp4w uai3F1M6QQt1Q== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , "Paul E . McKenney" , Uladzislau Rezki , Zqiang , rcu Subject: [PATCH 4/5] rcu/exp: Warn on QS requested on dying CPU Date: Tue, 29 Apr 2025 15:43:03 +0200 Message-ID: <20250429134304.3824863-5-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429134304.3824863-1-frederic@kernel.org> References: <20250429134304.3824863-1-frederic@kernel.org> 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 Content-Type: text/plain; charset="utf-8" It is not possible to send an IPI to a dying CPU that has passed the CPUHP_TEARDOWN_CPU stage. Remaining unhandled IPIs are handled later at CPUHP_AP_SMPCFD_DYING stage by stop machine. This is the last opportunity for RCU exp handler to request an expedited quiescent state. And the upcoming final context switch between stop machine and idle must have reported the requested context switch. Therefore, it should not be possible to observe a pending requested expedited quiescent state when RCU finally stops watching the outgoing CPU. Once IPIs aren't possible anymore, the QS for the target CPU will be reported on its behalf by the RCU exp kworker. Provide an assertion to verify those expectations. Reviewed-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 5be292667385..e14bdbb658a9 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4352,6 +4352,12 @@ void rcutree_report_cpu_dead(void) * may introduce a new READ-side while it is actually off the QS masks. */ lockdep_assert_irqs_disabled(); + /* + * CPUHP_AP_SMPCFD_DYING was the last call for rcu_exp_handler() executio= n. + * The requested QS must have been reported on the last context switch + * from stop machine to idle. + */ + WARN_ON_ONCE(rdp->cpu_no_qs.b.exp); // Do any dangling deferred wakeups. do_nocb_deferred_wakeup(rdp); =20 --=20 2.48.1 From nobody Wed Dec 17 20:40:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F0EBB2D3230; Tue, 29 Apr 2025 13:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934204; cv=none; b=ILdqEO2TVNTQhpPDtBtF6R4qfUiUvPAsyqhr/42dgyh67r4KFBUKFuw90Vd1yslK5H9rbvv+cjBVP0n46CshTTkXxRyhhA5D7NyX95b81hcPSNjj9NRDLdPSVl8AK+CMVYumGOMm9foh4oKISMg+1AS5JmRVzBoQbCbVbsu3Zbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745934204; c=relaxed/simple; bh=yGWkKy/tKQerFkmSW04s+UTgCO9enQW5oW0EdLwrtek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XiNyiuH9F4glzG4ZMgCpKGY5Oy1g7uVoxk9X7xTjOro8hDErbcLixEZb+DYTDYbzc3SGF+ZX8AOVtpCMOesjSO//GQP0oSrCHy13ACgDnzTqm8a/sHkB9TinO+Q4i9A91ea4R1ulO7KQKOLXtCymgVDoeZ3z+6R+pn8KkKOH9/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G7CRtGTv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G7CRtGTv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 612E7C4CEEB; Tue, 29 Apr 2025 13:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745934203; bh=yGWkKy/tKQerFkmSW04s+UTgCO9enQW5oW0EdLwrtek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7CRtGTvHO5PXI7/0xm2Dlb9UqieemyNO1L+QxPZC88h+YxCNFanYgAvRDZM7PE91 ebRCdv6+Z7yWgORKPR/cDpXk8/gPqp99uonvSIIO8+MMQ0ChnTLrp1YqslU5Mzeyw6 paclvxCYKmJUWSisz2s90hxATsGnAVnpvyr30clWITre9JcwkrTjY+ej0CKN2t0aab kxZEve0hkaB8qdy5VLuN4bvEX3wuLw4u4oOLMzNPK8IvuZKJ42uZILVuBEV2Rg1HJG 9uKBzTDuk18p3ZWAOwkgz/tGPXK0QWjBxlcZfgIWameCh7spXPWTdR92u+SHuljhJI PY4IufoBDXKOQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , "Paul E . McKenney" , Uladzislau Rezki , Zqiang , rcu Subject: [PATCH 5/5] rcu/exp: Warn on CPU lagging for too long within hotplug IPI's blindspot Date: Tue, 29 Apr 2025 15:43:04 +0200 Message-ID: <20250429134304.3824863-6-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429134304.3824863-1-frederic@kernel.org> References: <20250429134304.3824863-1-frederic@kernel.org> 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 Content-Type: text/plain; charset="utf-8" A CPU within hotplug operations can make the RCU exp kworker lagging if: * The dying CPU is running after CPUHP_TEARDOWN_CPU but before rcutree_report_cpu_dead(). It is too late to send an IPI but RCU is still watching the CPU. Therefore the exp kworker can only wait for the target to reach rcutree_report_cpu_dead(). * The booting CPU is running after rcutree_report_cpu_starting() but before set_cpu_online(). RCU is watching the CPU but it is too early to be able to send an IPI. Therefore the exp kworker can only wait until it observes the CPU as officially online. Such a lag is expected to be very short. However #VMEXIT and other hazards can stay on the way. Report long delays, 10 jiffies is considered a high threshold already. Reported-by: Paul E. McKenney Reviewed-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree_exp.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 6058a734090c..87a44423927d 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -406,8 +406,18 @@ static void __sync_rcu_exp_select_node_cpus(struct rcu= _exp_work *rewp) for_each_leaf_node_cpu_mask(rnp, cpu, mask_ofl_ipi) { struct rcu_data *rdp =3D per_cpu_ptr(&rcu_data, cpu); unsigned long mask =3D rdp->grpmask; + int nr_retries =3D 0; =20 retry_ipi: + /* + * In case of retrying, CPU either is lagging: + * + * - between CPUHP_TEARDOWN_CPU and rcutree_report_cpu_dead() + * or: + * - between rcutree_report_cpu_starting() and set_cpu_online() + */ + WARN_ON_ONCE(nr_retries++ > 10); + if (rcu_watching_snap_stopped_since(rdp, rdp->exp_watching_snap)) { mask_ofl_test |=3D mask; continue; --=20 2.48.1