From nobody Mon Oct 6 06:32:12 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 AC34E230BEE; Wed, 23 Jul 2025 20:28:04 +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=1753302484; cv=none; b=SAeRWxpkwpo6SB5r7zGldi400iSAewFmBPBqTgO2739BlcWGEc0gBD08Lxlfh5BTB2i/Cc+l6xovJZQOxrrfP94IvkrI/0LqKiB8jeBfi7nY3UkujtTFeNxfxf8sjo0eaqH6ROzGq0RUnsyPN8FqDb74H13ffEBZMJ94n0HA83g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302484; c=relaxed/simple; bh=bLAjkr0rM9XAbo8UHtiwK4eJ6EnmjrJMGttjy+b6bi8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nbRF2UhUFThtLQo9Mjpz2p2L3jdGMbqhwoGaldBha2c6y8Vy0fRsHRqX5QEmbzxSGGr7WISDToM3kew/iDlBOqVb6DE0xUXHREJr2f3MCpeq0d3TrmI9Mmxo7teDaRWjnv5Sjy5ICfVZxW/mfsxzOTnmhxXFFIM+WZbkwhD1nqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DHLoX8Wa; 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="DHLoX8Wa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50C8BC4CEE7; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=bLAjkr0rM9XAbo8UHtiwK4eJ6EnmjrJMGttjy+b6bi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DHLoX8WaSr8rGPNBsi/CR4rvQbKi79eO2QNAIQxa//G3uQz6Cc0seeeZo+YhUqvWn X9EPzvAwn3wfZCEXCOytFxekbTunm3elUGhlNzd8AVzk1mf/2iX9Ley7vU4X+qkwDP kwoDEsYgXv3/42e7EXuFzreErA38xfyTVi3O6Kk3qvfvZvmWJ9dLUiHVj9gD15IO4r fTzNPviaLWhzubYbVKMmN7TUdm8dGPKm9grhl2a1fm3Nj4mYs+VYYJXX69X39R8LKh K77safqG4BOEHDhTpmlBVIDYoar0wPp+3PUYUHB7WZbmkyOYCqXr3r1HltN2jPwXly AdNDx0rxs2S/Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 04E89CE08DF; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Joel Fernandes , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 1/6] srcu: Move rcu_is_watching() checks to srcu_read_{,un}lock_fast() Date: Wed, 23 Jul 2025 13:27:55 -0700 Message-Id: <20250723202800.2094614-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" The rcu_is_watching() warnings are currently in the SRCU-tree implementations of __srcu_read_lock_fast() and __srcu_read_unlock_fast(). However, this makes it difficult to create _notrace variants of srcu_read_lock_fast() and srcu_read_unlock_fast(). This commit therefore moves these checks to srcu_read_lock_fast(), srcu_read_unlock_fast(), srcu_down_read_fast(), and srcu_up_read_fast(). Signed-off-by: Paul E. McKenney Reviewed-by: Joel Fernandes Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- include/linux/srcu.h | 4 ++++ include/linux/srcutree.h | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index f179700fecafb..478c73d067f7d 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -275,6 +275,7 @@ static inline struct srcu_ctr __percpu *srcu_read_lock_= fast(struct srcu_struct * { struct srcu_ctr __percpu *retval; =20 + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock= _fast()."); srcu_check_read_flavor_force(ssp, SRCU_READ_FLAVOR_FAST); retval =3D __srcu_read_lock_fast(ssp); rcu_try_lock_acquire(&ssp->dep_map); @@ -295,6 +296,7 @@ static inline struct srcu_ctr __percpu *srcu_read_lock_= fast(struct srcu_struct * static inline struct srcu_ctr __percpu *srcu_down_read_fast(struct srcu_st= ruct *ssp) __acquires(ssp) { WARN_ON_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && in_nmi()); + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_down_read= _fast()."); srcu_check_read_flavor_force(ssp, SRCU_READ_FLAVOR_FAST); return __srcu_read_lock_fast(ssp); } @@ -389,6 +391,7 @@ static inline void srcu_read_unlock_fast(struct srcu_st= ruct *ssp, struct srcu_ct srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_FAST); srcu_lock_release(&ssp->dep_map); __srcu_read_unlock_fast(ssp, scp); + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_fast()."); } =20 /** @@ -405,6 +408,7 @@ static inline void srcu_up_read_fast(struct srcu_struct= *ssp, struct srcu_ctr __ WARN_ON_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && in_nmi()); srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_FAST); __srcu_read_unlock_fast(ssp, scp); + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_up_read_f= ast()."); } =20 /** diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index bf44d8d1e69ea..043b5a67ef71e 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -244,7 +244,6 @@ static inline struct srcu_ctr __percpu *__srcu_read_loc= k_fast(struct srcu_struct { struct srcu_ctr __percpu *scp =3D READ_ONCE(ssp->srcu_ctrp); =20 - RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock= _fast()."); if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE)) this_cpu_inc(scp->srcu_locks.counter); /* Y */ else @@ -275,7 +274,6 @@ static inline void __srcu_read_unlock_fast(struct srcu_= struct *ssp, struct srcu_ this_cpu_inc(scp->srcu_unlocks.counter); /* Z */ else atomic_long_inc(raw_cpu_ptr(&scp->srcu_unlocks)); /* Z */ - RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_fast()."); } =20 void __srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); --=20 2.40.1 From nobody Mon Oct 6 06:32:12 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 AC2F2230270; Wed, 23 Jul 2025 20:28:04 +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=1753302484; cv=none; b=Hs1HilbWcEjDA0ADOT0tDHE0YdSQQrPD0piuf0glCT+Uqdume09oMRfVTnNaPHj7EJawBLOMq0mz7tOJ/1xca/eJQRYNzsnnwP9EDXQNDvuQk9T5dvRYTu02C9Sxrnp6f9XJEBh8G6fLw5j2Dyhdkca+4yHL4NyKpgXIm6pOJms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302484; c=relaxed/simple; bh=lzk8+M42krZ085WSr7goKl4MCdBBd1jt58dCcDBT3cQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c1UXzYtmmz4EqEJnO9CiPEGiykbw8mWGf0SeFP4w6K9XWJW7qh3hKKGHWKP9ac/Y7lNuYe1/MmZ3aKIcUlN+iQeMAhydWVETAKX82TB3HPSy0eSna63/sKEWvV2adNuZkutiQEa58rEUiA/s0rhuZaw5Tq+7XtDhNIXrNbvha54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JpiNV+af; 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="JpiNV+af" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6450FC4CEF5; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=lzk8+M42krZ085WSr7goKl4MCdBBd1jt58dCcDBT3cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpiNV+afh1sv0cYlij3GUzzM9e7igMaXxFL73qtxfaAmQjt5lJMSUcJj25FhmzQSN vXJL9JgAMeojE4CgTSOi/DPfAEk79MeB7X1/zvV/NYbdgmEd0yBHguQ6b+MnZuI03H dpg1UM8QTYjMeWle+bHxHv74Ug8zx023cOOSTF808PRBTDcZW+ROwTISTXGGesDPd9 TpwF9mGCpRz9+zOk6sEDLE11TZIWmM+9h392R+Snll9PO63Y75gGHRIhhSkudlbC5C GB+n2O7AR8GEMMhN2spWvXd5xcvS4CDJON3+zhQclrVlchRDYg8O1N4uxlLE5jlC0W kWn+atHdK4k/w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 084F6CE0928; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Joel Fernandes , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 2/6] srcu: Add srcu_read_lock_fast_notrace() and srcu_read_unlock_fast_notrace() Date: Wed, 23 Jul 2025 13:27:56 -0700 Message-Id: <20250723202800.2094614-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" This commit adds no-trace variants of the srcu_read_lock_fast() and srcu_read_unlock_fast() functions for tracing use. [ paulmck: Apply notrace feedback from Joel Fernandes, Steven Rostedt, and = Mathieu Desnoyers. ] Link: https://lore.kernel.org/all/20250721162433.10454-1-paulmck@kernel.org Signed-off-by: Paul E. McKenney Reviewed-by: Joel Fernandes Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- include/linux/srcu.h | 30 ++++++++++++++++++++++++++++-- include/linux/srcutree.h | 5 +++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 478c73d067f7d..ec3b8e27d6c5a 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -271,7 +271,7 @@ static inline int srcu_read_lock(struct srcu_struct *ss= p) __acquires(ssp) * where RCU is watching, that is, from contexts where it would be legal * to invoke rcu_read_lock(). Otherwise, lockdep will complain. */ -static inline struct srcu_ctr __percpu *srcu_read_lock_fast(struct srcu_st= ruct *ssp) __acquires(ssp) +static inline struct srcu_ctr __percpu notrace *srcu_read_lock_fast(struct= srcu_struct *ssp) __acquires(ssp) { struct srcu_ctr __percpu *retval; =20 @@ -282,6 +282,20 @@ static inline struct srcu_ctr __percpu *srcu_read_lock= _fast(struct srcu_struct * return retval; } =20 +/* + * Used by tracing, cannot be traced and cannot call lockdep. + * See srcu_read_lock_fast() for more information. + */ +static inline struct srcu_ctr __percpu *srcu_read_lock_fast_notrace(struct= srcu_struct *ssp) + __acquires(ssp) +{ + struct srcu_ctr __percpu *retval; + + srcu_check_read_flavor_force(ssp, SRCU_READ_FLAVOR_FAST); + retval =3D __srcu_read_lock_fast(ssp); + return retval; +} + /** * srcu_down_read_fast - register a new reader for an SRCU-protected struc= ture. * @ssp: srcu_struct in which to register the new reader. @@ -385,7 +399,8 @@ static inline void srcu_read_unlock(struct srcu_struct = *ssp, int idx) * * Exit a light-weight SRCU read-side critical section. */ -static inline void srcu_read_unlock_fast(struct srcu_struct *ssp, struct s= rcu_ctr __percpu *scp) +static inline void notrace +srcu_read_unlock_fast(struct srcu_struct *ssp, struct srcu_ctr __percpu *s= cp) __releases(ssp) { srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_FAST); @@ -394,6 +409,17 @@ static inline void srcu_read_unlock_fast(struct srcu_s= truct *ssp, struct srcu_ct RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_fast()."); } =20 +/* + * Used by tracing, cannot be traced and cannot call lockdep. + * See srcu_read_unlock_fast() for more information. + */ +static inline void srcu_read_unlock_fast_notrace(struct srcu_struct *ssp, + struct srcu_ctr __percpu *scp) __releases(ssp) +{ + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_FAST); + __srcu_read_unlock_fast(ssp, scp); +} + /** * srcu_up_read_fast - unregister a old reader from an SRCU-protected stru= cture. * @ssp: srcu_struct in which to unregister the old reader. diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 043b5a67ef71e..4d2fee4d38289 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -240,7 +240,7 @@ static inline struct srcu_ctr __percpu *__srcu_ctr_to_p= tr(struct srcu_struct *ss * on architectures that support NMIs but do not supply NMI-safe * implementations of this_cpu_inc(). */ -static inline struct srcu_ctr __percpu *__srcu_read_lock_fast(struct srcu_= struct *ssp) +static inline struct srcu_ctr __percpu notrace *__srcu_read_lock_fast(stru= ct srcu_struct *ssp) { struct srcu_ctr __percpu *scp =3D READ_ONCE(ssp->srcu_ctrp); =20 @@ -267,7 +267,8 @@ static inline struct srcu_ctr __percpu *__srcu_read_loc= k_fast(struct srcu_struct * on architectures that support NMIs but do not supply NMI-safe * implementations of this_cpu_inc(). */ -static inline void __srcu_read_unlock_fast(struct srcu_struct *ssp, struct= srcu_ctr __percpu *scp) +static inline void notrace +__srcu_read_unlock_fast(struct srcu_struct *ssp, struct srcu_ctr __percpu = *scp) { barrier(); /* Avoid leaking the critical section. */ if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE)) --=20 2.40.1 From nobody Mon Oct 6 06:32:12 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 AC28F1EEA5F; Wed, 23 Jul 2025 20:28:04 +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=1753302484; cv=none; b=fHV1GUSLM5RsB+O+GNxk46pFB1rcoDlGH6pYpd8BsyK72aTnhucDFVn92L9QOB6k90qOib2cgwYX1XW6vZWosfQ8WMSDg8wGewf8QBDWyKBeSYSGj+5VTJAxGrLv87TP6UF1L4ERKLewkCKydSJejkjNJDlH10yAaC6lsY5DvgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302484; c=relaxed/simple; bh=Ta9aIor4BQit4OnpAbqvXNX0/P6L2jwLAeMWjUv0sC4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bfTHId27DAcS9MBkMFpMfVVf/TEc1tBmluD/m3LRmJX0aig6/Psl1zacIBzVngu+8dK0PeeJWtMOYkSjcmv3H7kNlfp2zch5K9muMa7WkiCrhyR3qnb/4pRkZ5oXDZO3EQCpFKc5wGxoSwINYk0JkD+IP5BMV9747doEZ5hNpls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ihYGrKPM; 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="ihYGrKPM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61674C4CEF4; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=Ta9aIor4BQit4OnpAbqvXNX0/P6L2jwLAeMWjUv0sC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ihYGrKPMCy5cws+s+fpf18WAvJTd9r/nB9FO7xBwudYl6By+Of5NlBdDmvZUB6Fbk 5ado4AxIN1gcnCG/kweyRmJKz5y3825rIXXMEY+PRtiTdltzHrJsAkzJG2bZZKjG1z nHfVtF/eWbEa3ZLrTZEQAEPWa8fWVbNW4BIvGz1YmEuiqdgV4Xwsujk9bzo3utXWLB gYOVpqcZSZsYFXOUumaaosiUVMkphO+K/rg8F3c48V21Si/uTI3r+OgEsWFUQsdDbe N5VuhCJsSbUAALPh3QcNp1J/3blr4woLIfyRbEryvufNQ0ypMU3Zez3gc7VfDYvhAI k/jSxgPkar45Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0B5F2CE0AD7; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Joel Fernandes , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 3/6] srcu: Add guards for notrace variants of SRCU-fast readers Date: Wed, 23 Jul 2025 13:27:57 -0700 Message-Id: <20250723202800.2094614-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" This adds the usual scoped_guard(srcu_fast_notrace, &my_srcu) and guard(srcu_fast_notrace)(&my_srcu). Signed-off-by: Paul E. McKenney Reviewed-by: Joel Fernandes Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- include/linux/srcu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index ec3b8e27d6c5a..1dc677bc9abca 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -516,4 +516,9 @@ DEFINE_LOCK_GUARD_1(srcu_fast, struct srcu_struct, srcu_read_unlock_fast(_T->lock, _T->scp), struct srcu_ctr __percpu *scp) =20 +DEFINE_LOCK_GUARD_1(srcu_fast_notrace, struct srcu_struct, + _T->scp =3D srcu_read_lock_fast_notrace(_T->lock), + srcu_read_unlock_fast_notrace(_T->lock, _T->scp), + struct srcu_ctr __percpu *scp) + #endif --=20 2.40.1 From nobody Mon Oct 6 06:32:12 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 B9DD7230D1E; Wed, 23 Jul 2025 20:28:04 +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=1753302484; cv=none; b=VXRgaFmTJboK7SBXYUSFsyZkcE2aBEI+okrTpJwhiuDFM3TDiVNJuV9pADNae7vaFG0NgWg8drwTzHQaA1PbZ/3+QXEIYNGDead9zM5c9q5J04/f3fJMFfscMZgT06U+AhCP2ZyKNPgGHVUup9di6D/k6yE/sTcA/f0cY/JeQCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302484; c=relaxed/simple; bh=B72QdzJwtONRhRvW5/jVEQT6uL4Kvid6Z1j8Kvnv3hk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GGEkeC8+Vjt4zjYVyolPUb7O/S++l8p3rTzU7Ux2FIJrF68ZhYNcZKCUD4oOd+aER15zuOk0DZFz32dkrBC7HKFVN4s0wb3brR0bnEL+05PisjFG6Wp3s7UYSO2Ejy+y8C6sAVrPNaW6cp9qTBqj/LokTZnYtqAbdrKpcFmi8i8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OKOJ7H/J; 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="OKOJ7H/J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F867C4CEF8; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=B72QdzJwtONRhRvW5/jVEQT6uL4Kvid6Z1j8Kvnv3hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OKOJ7H/JnDJLonx5BHAgJYDxOj5fegWwXnFRbwweKT/BVqa7PWX49o8AbuU6mMfL8 VaklSQ+iAFTI3k9p2sMgaSjxKEDD0sl89cLIhCeJ7QDMEqUS3Pz66wIGXJ5eDjo9Ns YEpkrM1awkhdgHOQEBtvDI10aoPKV0L1jqWaMcGUr+o/hAsHkvhZFDN59rJ4PS5Oxv NZzlRVsaV1sUgaMHJsk+mFS6tqenzpSaNVXjTV2wbmIZdiAxY6UvvR0h2c0gj2DCR9 lQ5P+XXm8R7Ho+9SgEyBhOWgCgyseUKl91oJXNjKTCl0IQ0JcEaJkftba3OwgiC1TF KRzqmPrguvL6w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0E077CE0B66; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 4/6] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast Date: Wed, 23 Jul 2025 13:27:58 -0700 Message-Id: <20250723202800.2094614-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" The current use of guard(preempt_notrace)() within __DECLARE_TRACE() to protect invocation of __DO_TRACE_CALL() means that BPF programs attached to tracepoints are non-preemptible. This is unhelpful in real-time systems, whose users apparently wish to use BPF while also achieving low latencies. (Who knew?) One option would be to use preemptible RCU, but this introduces many opportunities for infinite recursion, which many consider to be counterproductive, especially given the relatively small stacks provided by the Linux kernel. These opportunities could be shut down by sufficiently energetic duplication of code, but this sort of thing is considered impolite in some circles. Therefore, use the shiny new SRCU-fast API, which provides somewhat faster readers than those of preemptible RCU, at least on my laptop, where task_struct access is more expensive than access to per-CPU variables. And SRCU fast provides way faster readers than does SRCU, courtesy of being able to avoid the read-side use of smp_mb(). Also, it is quite straightforward to create srcu_read_{,un}lock_fast_notrace() functions. While in the area, SRCU now supports early boot call_srcu(). Therefore, remove the checks that used to avoid such use from rcu_free_old_probes() before this commit was applied: e53244e2c893 ("tracepoint: Remove SRCU protection") The current commit can be thought of as an approximate revert of that commit. Link: https://lore.kernel.org/all/20250613152218.1924093-1-bigeasy@linutron= ix.de/ Signed-off-by: Paul E. McKenney Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- include/linux/tracepoint.h | 6 ++++-- kernel/tracepoint.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 826ce3f8e1f85..a22c1ab88560b 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -33,6 +33,8 @@ struct trace_eval_map { =20 #define TRACEPOINT_DEFAULT_PRIO 10 =20 +extern struct srcu_struct tracepoint_srcu; + extern int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data); extern int @@ -115,7 +117,7 @@ void for_each_tracepoint_in_module(struct module *mod, static inline void tracepoint_synchronize_unregister(void) { synchronize_rcu_tasks_trace(); - synchronize_rcu(); + synchronize_srcu(&tracepoint_srcu); } static inline bool tracepoint_is_faultable(struct tracepoint *tp) { @@ -271,7 +273,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) static inline void __do_trace_##name(proto) \ { \ if (cond) { \ - guard(preempt_notrace)(); \ + guard(srcu_fast_notrace)(&tracepoint_srcu); \ __DO_TRACE_CALL(name, TP_ARGS(args)); \ } \ } \ diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 62719d2941c90..e19973015cbd7 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -25,6 +25,9 @@ enum tp_func_state { extern tracepoint_ptr_t __start___tracepoints_ptrs[]; extern tracepoint_ptr_t __stop___tracepoints_ptrs[]; =20 +DEFINE_SRCU(tracepoint_srcu); +EXPORT_SYMBOL_GPL(tracepoint_srcu); + enum tp_transition_sync { TP_TRANSITION_SYNC_1_0_1, TP_TRANSITION_SYNC_N_2_1, @@ -34,6 +37,7 @@ enum tp_transition_sync { =20 struct tp_transition_snapshot { unsigned long rcu; + unsigned long srcu_gp; bool ongoing; }; =20 @@ -46,6 +50,7 @@ static void tp_rcu_get_state(enum tp_transition_sync sync) =20 /* Keep the latest get_state snapshot. */ snapshot->rcu =3D get_state_synchronize_rcu(); + snapshot->srcu_gp =3D start_poll_synchronize_srcu(&tracepoint_srcu); snapshot->ongoing =3D true; } =20 @@ -56,6 +61,8 @@ static void tp_rcu_cond_sync(enum tp_transition_sync sync) if (!snapshot->ongoing) return; cond_synchronize_rcu(snapshot->rcu); + if (!poll_state_synchronize_srcu(&tracepoint_srcu, snapshot->srcu_gp)) + synchronize_srcu(&tracepoint_srcu); snapshot->ongoing =3D false; } =20 @@ -101,17 +108,29 @@ static inline void *allocate_probes(int count) return p =3D=3D NULL ? NULL : p->probes; } =20 -static void rcu_free_old_probes(struct rcu_head *head) +static void srcu_free_old_probes(struct rcu_head *head) { kfree(container_of(head, struct tp_probes, rcu)); } =20 +static void rcu_free_old_probes(struct rcu_head *head) +{ + call_srcu(&tracepoint_srcu, head, srcu_free_old_probes); +} + static inline void release_probes(struct tracepoint *tp, struct tracepoint= _func *old) { if (old) { struct tp_probes *tp_probes =3D container_of(old, struct tp_probes, probes[0]); =20 + /* + * Tracepoint probes are protected by either RCU or + * Tasks Trace RCU and also by SRCU. By calling the SRCU + * callback in the [Tasks Trace] RCU callback we cover + * both cases. So let us chain the SRCU and [Tasks Trace] + * RCU callbacks to wait for both grace periods. + */ if (tracepoint_is_faultable(tp)) call_rcu_tasks_trace(&tp_probes->rcu, rcu_free_old_probes); else --=20 2.40.1 From nobody Mon Oct 6 06:32:12 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 D8969235364; Wed, 23 Jul 2025 20:28:04 +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=1753302485; cv=none; b=PgeQ5IU9Y07kq6siSf2yPsSaWWMH8CIHOLN0DossCXzH6LvUE845FKwcoIb2J4lhG6tRQaSjI3moSo/N9qbaZNOI1xvRUs3B+DW9JzDo7BPWF70E3YO9scMk3plZi2QDCiyb/EoQ/3rWJ4QGVTby/GpRcoGg0COPy/O3gnN7HAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302485; c=relaxed/simple; bh=k8g0jWBk9ohluDjiSN174RWil2KT7b5UhHLGA4f02YM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cgNB0Eef0pai4jjPteiIrg4bYXkN95cDk2405NmsEjvFLot59RwUdohsn0DrgGtzx11pkM9a3AX/uwz9hdFWA1+YsAT+QGWzE8bpyjbyb1k+NGG7OSIXyWM1NVPj8qpPP4dN8vzaTMSH9qdWXQjrDuaR8tA4m6RP/D/k45G9hO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cwWC9rrb; 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="cwWC9rrb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C41EC4CEF7; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=k8g0jWBk9ohluDjiSN174RWil2KT7b5UhHLGA4f02YM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cwWC9rrb8U72UlBt9C4A/3Iy3aRM3G8rMuTvFchM3/mrj1qG8F2JgpQF5Ve5Gr0E5 +AVUan7jwZ58RXZA2nCbCHWcc6e3QD36WKWzA8/hrKGYuVBw/04Zo7bdeuBUhbsyXD cnz0JjOIWptLRrfhDi2FVFQx158tw4FIbN4+ui5MpKBblt3U4N3MN2HwA9yhMCCMyB 7cUB9Om/EY9HTe1sb6W4fKsIDREcyG0ynALaxMNeITbItJy1bh+6Mv4Wu0PfPcPpkP g1+hIfvHJqIgDH9XNgUmZax47Up71yTZI5Vvq5dIRIN8g36eYa8L6xAFvYFqhRNY38 wkbv7bvuOz1pg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 10DDBCE0CCE; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 5/6] srcu: Document __srcu_read_{,un}lock_fast() implicit RCU readers Date: Wed, 23 Jul 2025 13:27:59 -0700 Message-Id: <20250723202800.2094614-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" This commit documents the implicit RCU readers that are implied by the this_cpu_inc() and atomic_long_inc() operations in __srcu_read_lock_fast() and __srcu_read_unlock_fast(). While in the area, fix the documentation of the memory pairing of atomic_long_inc() in __srcu_read_lock_fast(). [ paulmck: Apply Joel Fernandes feedback. ] Signed-off-by: Paul E. McKenney Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- include/linux/srcutree.h | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 4d2fee4d38289..42098e0fa0b7d 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -232,9 +232,27 @@ static inline struct srcu_ctr __percpu *__srcu_ctr_to_= ptr(struct srcu_struct *ss * srcu_read_unlock_fast(). * * Note that both this_cpu_inc() and atomic_long_inc() are RCU read-side - * critical sections either because they disables interrupts, because they - * are a single instruction, or because they are a read-modify-write atomic - * operation, depending on the whims of the architecture. + * critical sections either because they disables interrupts, because + * they are a single instruction, or because they are read-modify-write + * atomic operations, depending on the whims of the architecture. + * This matters because the SRCU-fast grace-period mechanism uses either + * synchronize_rcu() or synchronize_rcu_expedited(), that is, RCU, + * *not* SRCU, in order to eliminate the need for the read-side smp_mb() + * invocations that are used by srcu_read_lock() and srcu_read_unlock(). + * The __srcu_read_unlock_fast() function also relies on this same RCU + * (again, *not* SRCU) trick to eliminate the need for smp_mb(). + * + * The key point behind this RCU trick is that if any part of a given + * RCU reader precedes the beginning of a given RCU grace period, then + * the entirety of that RCU reader and everything preceding it happens + * before the end of that same RCU grace period. Similarly, if any part + * of a given RCU reader follows the end of a given RCU grace period, + * then the entirety of that RCU reader and everything following it + * happens after the beginning of that same RCU grace period. Therefore, + * the operations labeled Y in __srcu_read_lock_fast() and those labeled Z + * in __srcu_read_unlock_fast() are ordered against the corresponding SRCU + * read-side critical section from the viewpoint of the SRCU grace period. + * This is all the ordering that is required, hence no calls to smp_mb(). * * This means that __srcu_read_lock_fast() is not all that fast * on architectures that support NMIs but do not supply NMI-safe @@ -245,9 +263,9 @@ static inline struct srcu_ctr __percpu notrace *__srcu_= read_lock_fast(struct src struct srcu_ctr __percpu *scp =3D READ_ONCE(ssp->srcu_ctrp); =20 if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE)) - this_cpu_inc(scp->srcu_locks.counter); /* Y */ + this_cpu_inc(scp->srcu_locks.counter); // Y, and implicit RCU reader. else - atomic_long_inc(raw_cpu_ptr(&scp->srcu_locks)); /* Z */ + atomic_long_inc(raw_cpu_ptr(&scp->srcu_locks)); // Y, and implicit RCU = reader. barrier(); /* Avoid leaking the critical section. */ return scp; } @@ -258,23 +276,17 @@ static inline struct srcu_ctr __percpu notrace *__src= u_read_lock_fast(struct src * different CPU than that which was incremented by the corresponding * srcu_read_lock_fast(), but it must be within the same task. * - * Note that both this_cpu_inc() and atomic_long_inc() are RCU read-side - * critical sections either because they disables interrupts, because they - * are a single instruction, or because they are a read-modify-write atomic - * operation, depending on the whims of the architecture. - * - * This means that __srcu_read_unlock_fast() is not all that fast - * on architectures that support NMIs but do not supply NMI-safe - * implementations of this_cpu_inc(). + * Please see the __srcu_read_lock_fast() function's header comment for + * information on implicit RCU readers and NMI safety. */ static inline void notrace __srcu_read_unlock_fast(struct srcu_struct *ssp, struct srcu_ctr __percpu = *scp) { barrier(); /* Avoid leaking the critical section. */ if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE)) - this_cpu_inc(scp->srcu_unlocks.counter); /* Z */ + this_cpu_inc(scp->srcu_unlocks.counter); // Z, and implicit RCU reader. else - atomic_long_inc(raw_cpu_ptr(&scp->srcu_unlocks)); /* Z */ + atomic_long_inc(raw_cpu_ptr(&scp->srcu_unlocks)); // Z, and implicit RC= U reader. } =20 void __srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); --=20 2.40.1 From nobody Mon Oct 6 06:32:12 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 353C12376E6; Wed, 23 Jul 2025 20:28:04 +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=1753302485; cv=none; b=HgQ88ihMzpZNVW6IAn7xzGM0aRSIDPqslxLnF7hLC6GAkEJsjrec1kKAjoC6aUjOMWGrvXENr3W8PL4EJ7w9hIj6U/xTtRRfU9dc9nHxtg2nDz4IG2YzbML3Tdt7MY6qvTORK7w/ok6PjiiGgYM71gL35eQuNRsBwQzQmWqAV0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302485; c=relaxed/simple; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VuF+DTXzsqjEw+mYKicDIXt4kAMSbyRLccpm/sT7a5wOsPj0yC1OSYJQiZ3Lx0gvhkkB77vvUXj33Eb6195uWoP7ZeS8nPAaHl8oKa5epcDoJlNrQEB4Su5+7OocJdfSAwvUlw83QFtJD6OQSko5gD1DggSJ8uiKF5lyOS6LfUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ULy0KYa/; 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="ULy0KYa/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC959C4CEFD; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ULy0KYa/FimCMc+aEg4Xwoo6O80VGJfim2xYMZdinFvpInetq1E2+AhMUVE3wd1u6 aIfYo+7B+pzrgyaCyTONE6y9GMreTgO54rzFRPmeseKJB5Vn/tRUPYPPFJEWokioNL vtXp4eyCGxVKQKj8GuRAviUaKL0gjYqK2FUXgS+jxNN71XRr1k51yspLV2Fd7nRnrQ 4+GAr9cAq8Q+4m8WGgcvxU/M+yrkpp/aEOR/3dgbW6GYlmKFsmk3hw3MBARSbLE98N hZk5/7qjUh+SlPWC6BTJ99WB4k3d1qcm9xLOUD2TD59IxX5dFc09n5gW5wDCGN//SH f6ZkVxZe1iAtw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 13651CE0F52; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 6/6] srcu: Document srcu_flip() memory-barrier D relation to SRCU-fast Date: Wed, 23 Jul 2025 13:28:00 -0700 Message-Id: <20250723202800.2094614-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> 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" The smp_mb() memory barrier at the end of srcu_flip() has a comment, but that comment does not make it clear that this memory barrier is an optimization, as opposed to being needed for correctness. This commit therefore adds this information and points out that it is omitted for SRCU-fast, where a much heavier weight synchronize_srcu() would be required. Signed-off-by: Paul E. McKenney Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- kernel/rcu/srcutree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index c5e8ebc493d5e..1ff94b76d91f1 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1168,6 +1168,16 @@ static void srcu_flip(struct srcu_struct *ssp) * counter update. Note that both this memory barrier and the * one in srcu_readers_active_idx_check() provide the guarantee * for __srcu_read_lock(). + * + * Note that this is a performance optimization, in which we spend + * an otherwise unnecessary smp_mb() in order to reduce the number + * of full per-CPU-variable scans in srcu_readers_lock_idx() and + * srcu_readers_unlock_idx(). But this performance optimization + * is not so optimal for SRCU-fast, where we would be spending + * not smp_mb(), but rather synchronize_rcu(). At the same time, + * the overhead of the smp_mb() is in the noise, so there is no + * point in omitting it in the SRCU-fast case. So the same code + * is executed either way. */ smp_mb(); /* D */ /* Pairs with C. */ } --=20 2.40.1