From patchwork Fri Mar 14 14:36:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 14016971 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 F0F65201021; Fri, 14 Mar 2025 14:36:51 +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=1741963012; cv=none; b=eXHCErsV5gQPmuBP6sFAy4ZptWb5S/w/zJVqqAX6ykv1bVWKv2YszMYvPx+3siPBa16wQDiQcMqKXKl4qkQjg8Py7kWQB7jdhS1Ms/AeYyJLoEhbCQ2S8hswORU4SqXPnnzZMYdSo/v/Wh4NYWBSj63xsSBJFof46xra+lwwJjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741963012; c=relaxed/simple; bh=r4H1oNViAr0LsHslsArziKgc+eWkFq12mA5EIJBu1F0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzycK9qytNHTLXgIiAZLGXPOQf1kUSqOKeBjbC30mHUpKEw/vde3gvVtSIqqir1Qti9zygEjoWFVdQKkuTU7sQ2EZakpwQvs7IKE5F9xSRXINqVCKi9o/EZMfZe1x45+7UKz5kmCaI8yzNGOTWlou9OKr+EMDgG14eu9OSUh9n0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=psn9jN8h; 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="psn9jN8h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 746FDC4CEE9; Fri, 14 Mar 2025 14:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741963011; bh=r4H1oNViAr0LsHslsArziKgc+eWkFq12mA5EIJBu1F0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psn9jN8hLNZmAN6LNQxR4/t9EEpqIOH6j5LCGlTFfSn1k++hnnoBBCCmg2YFCHqlo lphbKNYybpg9MKpet9xoE3txtMLP8RJc2NkcdAJI4qkMbYpsHFC0IGckgWc4j5tLPv 9lkHJLE5Duez9Q0pD88V4gEBiqdjnXik++oW8OvqaFwJ//l8/VvraHlSnXL1wiyrjf RvX41QD0MD3JJF4LLS7/5OjXR/9tOEoueUQ1DdaLFRNwj9rbfQxsEjyZR0GYMCRXo0 eT0SH2cUrFU0sp/toxrKCEv6LLKm8a8HV5tbas844afXI4CLjLFkqOYcXHHciu9inr V0Gf6XYsq2x4g== 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: Fri, 14 Mar 2025 15:36:38 +0100 Message-ID: <20250314143642.72554-2-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314143642.72554-1-frederic@kernel.org> References: <20250314143642.72554-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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 = rnp->expmask & ~mask_ofl_test; - /* - * 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); /* IPI the remaining CPUs for expedited quiescent state. */ From patchwork Fri Mar 14 14:36:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 14016972 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 E2C85201253; Fri, 14 Mar 2025 14:36:53 +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=1741963014; cv=none; b=HRMjjKWhlLGPEoGRMrVwWW/2r2eDO1reFm1wFbcBUgkmuK7WAmX5dE8SQ1rJArtoCyFMQHWkwHKSd629qWPPbVvwWE/ZOx3AZ4QL5GzU5Ijo8Mh2SiOudtsBQnnL6LdU/bdyTiqKb0zVRxOIddHAXczeuxRf3ow6ofyqqyPhBeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741963014; c=relaxed/simple; bh=Gf/HgxO4bwQVxa3pjudIyS3sTp30xi2+m/NxVQa/R4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t84N331Ig9pxfqN2A49vmv7CHuRTJrviROQYlPA+xyhpm2zCEiDS7DstxxAxWYpLQRSA3f2pXwn/IPvEEtyLRN/BDaIcGnbq686teMwmBNQOmE/Bty4nN3fFCOJbKyU3PhdfLSwIz3lXvmV6FBakivbXTsHrI6K6LLMkIPEGFIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NlIj3U4d; 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="NlIj3U4d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA729C4CEE3; Fri, 14 Mar 2025 14:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741963013; bh=Gf/HgxO4bwQVxa3pjudIyS3sTp30xi2+m/NxVQa/R4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NlIj3U4dBsROonRiYS38mlEIrrS02+tvr3XxU8VA5wvjOD+WdariVZOWpGXVNr7sn ybf0lYXSL/UT+wM4inllgpnsjkINEIawIQJ1g/VlR4b9tZmnqlZ6mqUmFSLNKCGl8G S1RrDxkMg3N2LHDH7ItOo/kQblE6JadPL4wcoElVOH+X9/7vH39AmEbOGHQfIA6pOx E0tbh6iR9HMSx3lJw6/GS+eKx4ACt+bqUpSzJ53QZVPgpVNWHHsyLcJjCzVODlNrpc fzU0KVZYDwO0LPnF/t7SfcB1+tmydAhh20/EQifcZIVnSoxgDf9Tii6aavybMg324w 5riEP/pcFeYtg== 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: Fri, 14 Mar 2025 15:36:39 +0100 Message-ID: <20250314143642.72554-3-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314143642.72554-1-frederic@kernel.org> References: <20250314143642.72554-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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 == rnp->gp_seq && (!empty_norm || rnp->qsmask)); empty_exp = sync_rcu_exp_done(rnp); - smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */ np = rcu_next_node_entry(t, rnp); list_del_init(&t->rcu_node_entry); t->rcu_blocked_node = NULL; From patchwork Fri Mar 14 14:36:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 14016973 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 56FE5202977; Fri, 14 Mar 2025 14:36:56 +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=1741963016; cv=none; b=Nw3xt6SEmU3Csb0PYgQxDoYdRvStl2fcuY/rtQG2FRT8bovGpk/XOnu4KsZhDloLSoKG4uoiepBO2kN7/F9sD13bpnyQHIM6rsZebjayEAhHKgs//WcM8oTEAgCK3aX2apLXIhdU2K7dvQxcx7BfWhMwzy0d6dQvgVQ4nPudjPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741963016; c=relaxed/simple; bh=5g0p1dHt9TAlfslQ3oGdsjlv0P14+kzYtg92uqqsHQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gYHsJD4hAHBRfXJ0xzT7H8LT6RZ5hw4FSj+EMoxoWHL8S9L+O8y8c4i67zQeUCBqhPVb0ROB3L8O7JqEO+tA+i3j+Pa/eu7SVZ4tRdN8YRnfnHPyMlYhPHdb6GdHPiULMdUKWYjlEeCDiiyJPdUJRGNwlv1aUEqwyJJ3IicaFXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G2H9y9MA; 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="G2H9y9MA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C8F4C4CEE9; Fri, 14 Mar 2025 14:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741963016; bh=5g0p1dHt9TAlfslQ3oGdsjlv0P14+kzYtg92uqqsHQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G2H9y9MABoHzvwF5Rsz25B66yItclucq82Sg1kpPEkpb64p7mdjePazI7CHmKcL/0 Ix8kNyGEM5hAVtCGhacxzarha9tmJ2czyR8fCXEpq2fAAsfUqx+GcfjNghgDkIu43r t2hbZz6EZ0Gf6x+fiKJKvGzFeCJQZVrIvv0MV3GAR8Q2sKREz31eM1Zw8y93AWIDrU nKDcbITZYeSGsTi0XFTrYZVVxi32S+jokHIcPW6Ckcau4XaIcYX/fWs3Wz8SIT2gL3 C9hUR8v4/lXWP33Skf2MrmZnfEYk+bpIMg+OYp930BoCH9ArVNjuHonRK5d1j5bSdO AGzNEdrJlc2WQ== 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: Fri, 14 Mar 2025 15:36:40 +0100 Message-ID: <20250314143642.72554-4-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314143642.72554-1-frederic@kernel.org> References: <20250314143642.72554-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 d7f3800c7c8e..3fe68057d8b4 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -151,7 +151,6 @@ static void rcu_report_qs_rnp(unsigned long mask, struct 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 *rnp); static bool rcu_rdp_is_offloaded(struct rcu_data *rdp); static bool rcu_rdp_cpu_online(struct rcu_data *rdp); @@ -4233,7 +4232,6 @@ int rcutree_online_cpu(unsigned int cpu) raw_spin_unlock_irqrestore_rcu_node(rnp, flags); if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE) return 0; /* Too early in boot for scheduler work. */ - sync_sched_exp_online_cleanup(cpu); // 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 = current; /* - * 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); } -/* PREEMPTION=y, so no PREEMPTION=n 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(); } -/* Send IPI for expedited cleanup if needed at end of CPU-hotplug operation. */ -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 = per_cpu_ptr(&rcu_data, cpu); - rnp = rdp->mynode; - my_cpu = 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 == 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 = 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 From patchwork Fri Mar 14 14:36:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 14016974 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 2267E202C39; Fri, 14 Mar 2025 14:36:58 +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=1741963019; cv=none; b=C+BAFMAy7DIDPgU0vu3d8gZmsIyqmOyJZhWa0LdEV9tk80+8kx5IzkqlP0FWSzD0UhR7YhrlgyH/fRiUmUgBDh2V3L6sLh3EoVsVwPRiTu5jB07KNPgj8xF8Q9mOPSZNns8FCUK2C3toMx1AFKdLeyEacrI+MmUFq6K1EhBpeaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741963019; c=relaxed/simple; bh=2ceJ30Ucuu3ZC70dVdSYC3nnStxus6Nf7//XhyNn4Us=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qxK0zyu3KASDR9o+a/q3tg/iok4liLqd/Lpzk0ZuSvn2/mTqLZ5gYkBOR1y37BBUFnaFfkaaLrxVR29K7yqBHnzU7+OGVK7dwzBykPoNJm1jkb2gZmN8dt5MGu+rjli+eydYlhcCxNLOfiUMZfBiL9Jjs61uoV6ZTY+PRKfA0V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FWtqe7zt; 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="FWtqe7zt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E7B4C4CEE3; Fri, 14 Mar 2025 14:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741963018; bh=2ceJ30Ucuu3ZC70dVdSYC3nnStxus6Nf7//XhyNn4Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FWtqe7zt+TPZpSTxH32/i2bCY2dI0v/Af0iJyYd6LxWsiwwQi95ebYjvjKHIAN9zs 3IR4p1FLOfqPO0oEAX0ZsJVx8uBEz1wYVN6vroXW7cMk/qppLTTazTIcJpMqOLgNRi pNZhggIjVI1HffilAmypbqfGwGC7flXrQr3SrG4V7fpRBFkR23qIijjyjreWVS3ds6 b+Q4p4DfsQWoT1n69KCrn3mUL44BS4zk4t8uM5qDpEX5SfnFFPG5jIpvRWXVMaPQ44 PBDrqACIX5JEMrE3roCfH4RNwb5ep0qc8KDVs0H1ae7ee0yptp+mmLK8qFBbppLvtm V4lYk/tyUzr3Q== 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: Fri, 14 Mar 2025 15:36:41 +0100 Message-ID: <20250314143642.72554-5-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314143642.72554-1-frederic@kernel.org> References: <20250314143642.72554-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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 3fe68057d8b4..79dced5fb72e 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4321,6 +4321,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() execution. + * 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); From patchwork Fri Mar 14 14:36:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 14016975 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 0E9CA202C34; Fri, 14 Mar 2025 14:37:01 +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=1741963021; cv=none; b=VHtpMbr3HyjnWmCH1zllClda5JgfhnaFnCfwlTh6fQvyP6tdOi0TL7AhIFfShouLBrqv4gqHfUXcCB25nhXkdcu8fn1dUnmOXvUVHaptKahFhBLNQsZI+xaaXl2YbdEFYD5fMXlZ/GPxZYZTidwmP4vrm3Ai7voCkwHWP3Tp3GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741963021; c=relaxed/simple; bh=JA73+M7TZ+VjBe+WGmCS+fPRTyG1hrOlK32h7qOdmBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6srBFGiO2uS6+4Onb/RZpwfIdGOUkCeyu67yMcP5g8h0U9OiTyBkJxLnl/WPOHkSq+6W6YESjf789z+3v0ySmVkUoT6qMWHXqXYRB3whk3MtFwXYEK+VrCuNJthLL+x59Ftl6HOuHxYqSFlSjxUJyJaWwtem1ayA/tcP08lbJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E9+FVapb; 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="E9+FVapb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FAC5C4AF09; Fri, 14 Mar 2025 14:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741963020; bh=JA73+M7TZ+VjBe+WGmCS+fPRTyG1hrOlK32h7qOdmBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E9+FVapbWNejlNlU/9D+likKIEzU/gRhun9WJGpIxYVOL4oApNgcIxuzyiejYdCgO QmqzreRIcvLn8tF04rCv1Od++bmxKzTYJZbNfgrrNOFZ/L3sa7KP45oWZxXDZ0W+HQ XX1HoS96oNjBQASM1BCg/pdL4J2e53f9svDX+yMyl2i66DL0ZQkVdwi4o9StS7QZAY gw1ymmCtt96/4QiPL59VcoTf4WptsYJ7xraPriiic4i3xUijFXaG6QBzA81Qsv4wxr ePfmCe+QQeDhM7aabcL2DIZQE4P9wQEVgn9l8pgSB5WgdJ7m2VvCFtaDdPIhQ4dzGq gSw6OSMKTHnXQ== 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: Fri, 14 Mar 2025 15:36:42 +0100 Message-ID: <20250314143642.72554-6-frederic@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314143642.72554-1-frederic@kernel.org> References: <20250314143642.72554-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 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 = per_cpu_ptr(&rcu_data, cpu); unsigned long mask = rdp->grpmask; + int nr_retries = 0; 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 |= mask; continue;