From nobody Sun Oct 5 16:20:37 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 996ACBA4A; Fri, 1 Aug 2025 00:12:38 +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=1754007158; cv=none; b=P1TeIz46DWV5Vh+SHyUPU6fWtJtJgEHA23FzR89PAZ8ZjkCYtPvBgC/AcY1dgFquLm8dTvfKilskeWEccA24YJ7X/S0hP+AOW0Q494zFtD0bmGEZMzsolrSMCzFeJmulCWdmLKcdeUFNJQCRYTQkSmSAD8RifmiFPZo8wvA0zGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007158; c=relaxed/simple; bh=bLAjkr0rM9XAbo8UHtiwK4eJ6EnmjrJMGttjy+b6bi8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mmH3/APilnnL1aDEdrPhHJd8xLdBwv/zwjZXN2i1KChRoFP65KEIgL0LzMQSSh4Po9pFcyDpjXIq+EF44NL9IfgIFIOZnhKfUy4QQ2We0hmMadiJm+nj6jqTOhQc58Kbq8U7lpfF2sv9/u4EMXe5PblfGkMU/G6tQGl4yfPbYA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pkbOXKNu; 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="pkbOXKNu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EBBCC4CEEF; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=bLAjkr0rM9XAbo8UHtiwK4eJ6EnmjrJMGttjy+b6bi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pkbOXKNuvnDWTQKF4c7jLuX6Tch5m1OIWPf9pK0N6XicmokAnjqXuCz1m+CVAAk10 53I6mB0UkbaxezMjpAope/oHo/5IC53irHycZWbtLfpZJlnw8qVhhdZT0TfTlZ0aTY iMMNr2zAsXTOHRFhj/FX9PnYcNOqhFLaxm7MUxeV+tXfG+pESZJjEVg6ByBG5y7XWF /zYKBt4DRXkLAkL3GDqGjsRRj2e/JTGhvjcWRTGFhJO2lLTnki59HOTjtXsNJ1ittk Se6ZIuYbm4DGOvLN2nO8nm9u/RK/s2INL1RWqKhEB17NkIpxM6h3Csu5gGITsZfO2/ 3B0/lQzJDoAuA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 24731CE0A73; Thu, 31 Jul 2025 17:12:38 -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 v5 1/6] srcu: Move rcu_is_watching() checks to srcu_read_{,un}lock_fast() Date: Thu, 31 Jul 2025 17:12:31 -0700 Message-Id: <20250801001236.4091760-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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 Sun Oct 5 16:20:37 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 E7E4C1C27; Fri, 1 Aug 2025 00:12:38 +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=1754007159; cv=none; b=IZ56bdhmXmG5N6P109Ns2R9sHBTrUibXm4QwmfPDG4Yn8aXRrCvXbxHEZ/axhq/twM0cHzKcWUMrzfki0r1iosc+Rh/P/xcjdVXSxTMU8hm8AulOjZq3N666s1JbK4cq20Lp+SlS+xc27IQuPGxa7VhNRRqwWeb+YjJyV/ROTW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007159; c=relaxed/simple; bh=7M9V2tC56HNHwcS8Ht17nxHyMNl+pCEND+1MV1Qec3I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DjkRUNdncR6+G2bDXSUA/w7FeGn3eg7TorayoAZTTMOzE4gEKFjPigAlzv0scB+/v/z/Da7lmQBdxRJuw3Aq2/sn3FTF6x6fFDhj+sikGmdwQWRzYLWrYeCQBmuzpxpGLRTCrmj1AHzdBSjb5fFpUdYaq1iAy0h12UGH5FsKRIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=scqq5e+L; 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="scqq5e+L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B8D6C4CEF4; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=7M9V2tC56HNHwcS8Ht17nxHyMNl+pCEND+1MV1Qec3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=scqq5e+LDxhJy1UFGqRBUcUfnGYVbXU77BPa+rRJiS4vhBWOl1ha+miDwMI3kp3IY 9MBHYsKeHZBAAFB1e67SGKR0FaCYBoy/xcQGgiDw4mCALVVLHU1vAQpyRB6NGxcM2O 3I9/qXRYuSKmK86tOx/psuni64loHU6DTmOY04Nd6pZ7WNF+rNhkbopvP9zhunxwer B3gpN+ILsDeI95u2PYx8cLq30u1wOHrTFRhzhv4skKOfeTkX14EiKqghlecwRXz9lX XE77k4qW+WxSrjBNzOfZ04CvTcpDzhioN4qtnOJ3wpVPIh1V0MbWlK0YUOizaVeGeZ PExxb9PVygc6A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 28983CE0ADA; Thu, 31 Jul 2025 17:12:38 -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 v5 2/6] srcu: Add srcu_read_lock_fast_notrace() and srcu_read_unlock_fast_notrace() Date: Thu, 31 Jul 2025 17:12:32 -0700 Message-Id: <20250801001236.4091760-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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. ] [ paulmck: Apply excess-notrace feedback from Boqun Feng. ] 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 | 25 +++++++++++++++++++++++++ include/linux/srcutree.h | 5 +++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 478c73d067f7d..7a692bf8f99b9 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -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. @@ -394,6 +408,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 Sun Oct 5 16:20:37 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 E933623AD; Fri, 1 Aug 2025 00:12:38 +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=1754007159; cv=none; b=T4tPNC5bXZeL7zJ4KPfXybA1G+JbLrDPAvokkcDKQA29a1RxE1m1dw1M5DaNwZiC62oOMk2yFlMr5XTrwlfPIMtu+/xfOxOx5U3Sm80SmrF9Mv+SGBuccyV6NxVkhv2Js+ysCvUGl3wyuFmEBSCLC9JCJk7IqPmhO8OA3NcuqNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007159; c=relaxed/simple; bh=MJ5bAfE9Srk8OX6f3Xl/KDXvlfaoSrdv9K67Uthyu4c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=POhfH3lzYLP0sEI86FGUF/QZPPg/exbDzAsv0g2riag7nNhc6EC6JoKhwZjO5IuGn0sp16TAeJSaP1eKY+eCxZbAIh21l6N3bFpj/2u5vN+teziEwwT7Hlny6JQffOOelXVSuviE40c2veIDQOSMdDbjxAVkGb6Lv2jx7abaIGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HWgl+S9v; 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="HWgl+S9v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82100C4CEF7; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=MJ5bAfE9Srk8OX6f3Xl/KDXvlfaoSrdv9K67Uthyu4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HWgl+S9vzmpUr3PRe/9zMBRIhYjco/mdhRVDOU2M+3ZfXzPGMyaQm+tHBTX8RZOM/ Oe6FNaWPfAXEpOODP4gwU9PBKi0v/IU9QjTfkogNupsbqaASHIXY4W8oOvuQmT19rH JBDYGr1O+O1xMtd2SSzq4j963ozDkD3ZwGjRlyRG5H1+vCRqnrWu0/tTFOWS3JCa1u 3zJ+qeHmUB8DLihBk2NeYzdYXiV0jnDJkJGO46CIMmCbMR4TuaJZ6VhSb5hA+l9oxf oCNNqRFeIdNGzOMf1TxynrSllKw4G4WhCMHukeJmmIKqt93V9RcXZ8chfn8t5Sdm2b VKXbd4DBBWE0Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2B728CE0BB1; Thu, 31 Jul 2025 17:12:38 -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 v5 3/6] srcu: Add guards for notrace variants of SRCU-fast readers Date: Thu, 31 Jul 2025 17:12:33 -0700 Message-Id: <20250801001236.4091760-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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 7a692bf8f99b9..ada65b58bc4c5 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -515,4 +515,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 Sun Oct 5 16:20:37 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 EBE122581; Fri, 1 Aug 2025 00:12:38 +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=1754007159; cv=none; b=I1R/l0hL9o2550zpTJHBX67tyZsfzLzrQdCehew4eIF/7Q1RM//w1Nnm+2+CPfNm3xiuL9Tjdt9OUMM9iFBsJp63TiDIp7ZxguWKhEUPwsSZBcFgPZDQb2lo4XULok7NI3MpYQHVorHAXFYYv4VcSEVNHP/3wZdRJDkw1nBtOPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007159; c=relaxed/simple; bh=KM0pcPI/pYjych/Wp0FAUKf1zUs9854rfr3spHZiqvE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BP1Ehc/OfTFqbCQjD7lHZ4V61mRgT38CfPqWawmlBm7KH3cm44R4VwMdcBbgf/x4Olro3Z/lvlc4N1QLY0LO1zid9nOIMhxbFdhZKrWwxAbcBe7mOOD1nJB5EDriDsDaoVt7nTvoB/Wai2NeuvYzPVpWuOmxtHie34DMSPIVt5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CU1nlMgT; 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="CU1nlMgT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8910EC4CEF8; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=KM0pcPI/pYjych/Wp0FAUKf1zUs9854rfr3spHZiqvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CU1nlMgT6Uh0a877JgcE1NveM3vI+deSsYwCBGxVakUaUsfXUGiI2whCg7BF1LY/D kgykKa+/n0YJyhjsQiPmzgtVtkwWchSgw5lWjAWgdRSN77buD15na8ITkY7YpPh+xg zD3x3Kj4rFgtqbe7GZObdZcuoB31dGrgj4IOb3Z2zcQnObJGl8BVYobMtLfDdn4Qio xYeSVml5/ovK0KiRmYiBcmrP8mePVJQ/OJ/eFL4tRV9pNNXGXlm9NFnbUB6m1WsrY3 vgyjxBaR3sEaHh5UPykAQa1O9JU0yEQ0VBf/kQ/WryW21MfOXM58FfR6O/hDCJRWVZ S2npQIg5Pw8pA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2F136CE0C3E; Thu, 31 Jul 2025 17:12:38 -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 v5 4/6] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast Date: Thu, 31 Jul 2025 17:12:34 -0700 Message-Id: <20250801001236.4091760-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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, with some compensating additions of preemption disabling pointed out by Steven Rostedt (thank you, Steven!). [ Apply kernel test robot feedback. ] 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 ++++-- include/trace/perf.h | 2 ++ include/trace/trace_events.h | 2 ++ kernel/tracepoint.c | 21 ++++++++++++++++++++- 4 files changed, 28 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/include/trace/perf.h b/include/trace/perf.h index a1754b73a8f55..1b7925a859665 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -71,7 +71,9 @@ perf_trace_##call(void *__data, proto) \ u64 __count __attribute__((unused)); \ struct task_struct *__task __attribute__((unused)); \ \ + preempt_disable_notrace(); \ do_perf_trace_##call(__data, args); \ + preempt_enable_notrace(); \ } =20 #undef DECLARE_EVENT_SYSCALL_CLASS diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 4f22136fd4656..0504a423ca253 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -436,7 +436,9 @@ __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args)= , PARAMS(tstruct), \ static notrace void \ trace_event_raw_event_##call(void *__data, proto) \ { \ + preempt_disable_notrace(); \ do_trace_event_raw_event_##call(__data, args); \ + preempt_enable_notrace(); \ } =20 #undef DECLARE_EVENT_SYSCALL_CLASS 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 Sun Oct 5 16:20:37 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 E7EEB23A6; Fri, 1 Aug 2025 00:12:38 +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=1754007159; cv=none; b=kr6Vtqp7cez/+L5gZAceL31SDT1Vx9FrRkH3bPs6RvGPWbQCatB9FoBpYghdGAm8X+28dEKQrykr0VLmztE8/61jTbrvwgIHjc2OpOuUi6tpN1D539S8EhftiWH5Nb+mTgOalaqMFyAKp7qhaQU+h0DZ/T0GcrZi8K3CpqoLnB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007159; c=relaxed/simple; bh=k8g0jWBk9ohluDjiSN174RWil2KT7b5UhHLGA4f02YM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VoilRF1ASRj/1qN4EbKhLI6CbS7uheW3QHrU/21TnKRt7kouij4HeIBpc5UrR+H6guZZC9QriiVVF8zXgy2lBitfip579RrlEVELyTU3cRcP1OQY69RQEQ7Lu0VGxqYxZ41B7lX6mkoxjOxA5fKmoD0K3qHzvLnRQlkwSfLEWAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mg2P+aE+; 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="mg2P+aE+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F664C4CEFC; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=k8g0jWBk9ohluDjiSN174RWil2KT7b5UhHLGA4f02YM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mg2P+aE+FGTBXGrbSHz9MzOLoLby/pSRE+3TSegB6TWRiMegsqqqeSfSRGfRfv2O9 CGhzJRTlqn+FOteCyw/DPI6kkKq2zrJfn08powAYzs/FchOaldUD+VsA4XxpFadrv5 VgDZbmdjxIL1j1lEYsI9S8S53GxrkXTwzijaQmntwtokeRK9Rrc8qFM0yz1WW+GzYM 7rqKerguTiFwzh7vp571KuBAbYcDKaY8Euywq7p8n+Qc0d1Ri4ZyMrUooqR4aSf6jI W0LzXe5qO0RZhVHoDzq07Qup04qeYMSz+g5bwa8FVH0a4d+nPsnM1rnIE0Y0vx65DW 0mRrqkvHm5yig== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 31B9ECE0DEC; Thu, 31 Jul 2025 17:12:38 -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 v5 5/6] srcu: Document __srcu_read_{,un}lock_fast() implicit RCU readers Date: Thu, 31 Jul 2025 17:12:35 -0700 Message-Id: <20250801001236.4091760-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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 Sun Oct 5 16:20:37 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 5741F6ADD; Fri, 1 Aug 2025 00:12:38 +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=1754007159; cv=none; b=NzCofY3OrkOyLXEcGyuuP2SYSiIx3vVsHD3cuduNTDC6t+OuqXxXL57zxHfv+/in7aSFTKsnMFsnvlTimvnSi1zMGaJhjFPSt2bR2MfBp25Qg/BIe/HI/0i9yj2rlAE2AWurU3TwcP1QuNPFBhz9DgPrMlErUqx1cgKvyyHnFR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007159; c=relaxed/simple; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DfvVc7eN+7SXZ353r88Z6wWXqLbYkQVQVPDUBm43cDf3Uganfm2q/RxEM6uzZ64TwP8YIQsfFqPL5N+YA6S+/n/Lmb7S7tI/H0b6eBlvfC8kL3HzF6m1CL4+F43lLmAJY6BFrjicZP2gyr7Xb0diUrJm0zMlPI/+QIysnaYcmLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e9Wd0Zh/; 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="e9Wd0Zh/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE668C4CEFE; Fri, 1 Aug 2025 00:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754007158; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e9Wd0Zh/rpN0NXSOrDFbcJP1LqG4u1wvT0C8i/3/aBTS/rbNeAqHGgg/sxljtT9Tu DBJwMT+gPkLvpH92r6mG4+J4+qjen6EXc1ogDh5II93D5NP/73YamwbeWAS9QjUGle tHQYz1hdx89vSrVZCNAe85Fwl2iWh9PiHXiSyarpTStqXZpZsHHYDJToR4BDDLpTfA u5J1oeJ1gKHvHm3eAZyrt+B4XMJW4C1KX20LyQDz0thhHuN06Wj82con/U4IB1O9EN ArDHcQKjA/+lqTGrHVmXaHmUggw3WL2+onv2h8eYINXwySlu4iO8qzj3ekru1gES3/ ntcTCI7FyBIfA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 34851CE0E88; Thu, 31 Jul 2025 17:12:38 -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 v5 6/6] srcu: Document srcu_flip() memory-barrier D relation to SRCU-fast Date: Thu, 31 Jul 2025 17:12:36 -0700 Message-Id: <20250801001236.4091760-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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