From nobody Tue Nov 26 22:25:30 2024 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 7A4DE13B284; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=ad1ebIscDXQHb73Eu0PfM2zFofYo0sB4gftK+EI64b25+frYDKUJkUlZVJF8bjJkG4pjdjhZ1Ofy7utfS5R0872jbBPV6B2LO28qr/JyVvNc1OB/W2s/qGK4FGRLDDTTcF7al8ySLUE0TJrhx2yaV8kVVZfV3Ca+wCUjE0QdiZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=YtrJn4vc+Mgz9wgw7+EugcgaEZCddJzBtXAuSeGGRxU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cvubs8C2ZpfMhTgQsiky77H86/QqZAhdKctqdAirgEol/NHMmJ2S+B7BVsA6jBgM60OKrHwbgWWVNwulox5eyqAijYFxFsqqlsqrj7ke4Q4nXKAG2ugUi2aJou3eN4RIiHvRtRvpOPvwJib21Xdkl/NxK9sQatfV0H/6KkbDtU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rjWuaejM; 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="rjWuaejM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 102FBC4CEC6; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=YtrJn4vc+Mgz9wgw7+EugcgaEZCddJzBtXAuSeGGRxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjWuaejMz3s2kw0x85c0BKmvxqsG68srpL0BWdgw5AbFisGdZpWkE88Lx8rFTSHA8 2VSsfnTjowFQzl7SIbV2FhnAWREHbhdxERR6dwrvif+bomJo3QZ5eI08901VU8byHO 6kqnhcWrYQuVeC/PIZclBNHNz5llVCAfSFXJ8fflzdV7Zfo6wVmv9FDH+6Au0ZIY+Q oOXOdYwmvw2zCFb/cpHli8WSDJVmnd3vslEhRdCAAjlUEa/FVk3V5Jnz+0JkHz5h7L YjONZx3hl9Stfqqfi84e9Lu/VF6yVMow50/k6fimHFOIubWyAFQDkTfLMRl4DtXpP3 P0AcGDYJLUg6Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B34EECE0971; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 01/15] srcu: Rename srcu_might_be_idle() to srcu_should_expedite() Date: Tue, 15 Oct 2024 09:10:58 -0700 Message-Id: <20241015161112.442758-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" SRCU auto-expedites grace periods that follow a sufficiently long idle period, and the srcu_might_be_idle() function is used to make this decision. However, the upcoming light-weight SRCU readers will not do auto-expediting because doing so would cause the grace-period machinery to invoke synchronize_rcu_expedited() twice, with IPIs all around. However, software-engineering considerations force this determination to remain in srcu_might_be_idle(). This commit therefore changes the name of srcu_might_be_idle() to srcu_should_expedite(), thus moving from what it currently does to why it does it, this latter being more future-proof. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/srcutree.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 31706e3293bce..9ff4ded609ba5 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1139,7 +1139,8 @@ static void srcu_flip(struct srcu_struct *ssp) } =20 /* - * If SRCU is likely idle, return true, otherwise return false. + * If SRCU is likely idle, in other words, the next SRCU grace period + * should be expedited, return true, otherwise return false. * * Note that it is OK for several current from-idle requests for a new * grace period from idle to specify expediting because they will all end @@ -1159,7 +1160,7 @@ static void srcu_flip(struct srcu_struct *ssp) * negligible when amortized over that time period, and the extra latency * of a needlessly non-expedited grace period is similarly negligible. */ -static bool srcu_might_be_idle(struct srcu_struct *ssp) +static bool srcu_should_expedite(struct srcu_struct *ssp) { unsigned long curseq; unsigned long flags; @@ -1469,14 +1470,15 @@ EXPORT_SYMBOL_GPL(synchronize_srcu_expedited); * Implementation of these memory-ordering guarantees is similar to * that of synchronize_rcu(). * - * If SRCU is likely idle, expedite the first request. This semantic - * was provided by Classic SRCU, and is relied upon by its users, so TREE - * SRCU must also provide it. Note that detecting idleness is heuristic - * and subject to both false positives and negatives. + * If SRCU is likely idle as determined by srcu_should_expedite(), + * expedite the first request. This semantic was provided by Classic SRCU, + * and is relied upon by its users, so TREE SRCU must also provide it. + * Note that detecting idleness is heuristic and subject to both false + * positives and negatives. */ void synchronize_srcu(struct srcu_struct *ssp) { - if (srcu_might_be_idle(ssp) || rcu_gp_is_expedited()) + if (srcu_should_expedite(ssp) || rcu_gp_is_expedited()) synchronize_srcu_expedited(ssp); else __synchronize_srcu(ssp, true); --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 7A5B71EBA09; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=sLbNrm4h/ICLlpbJukR0QAQlUAaX64A0lK8UJNhlOoGXh4wLab+BU8tJKofgcCnN+A4Co+twzr4O80gd4SypqlX/sJhaM5M5rLOmLf1YdgNf7/RtGDx2Bl3FjPPdLFwcm/vHONMBIMAriHzp5+UIjz/eJLrj9y3wxqgJv+7Pm70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=wmL8nD35K+D183HPbTxmWpox+7fCqVw7eRDQh/aakYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jbf6kNgtrWxEvUBA5LIcnz3N3C205x2LK4NKLIPHH9cMwEfMj72sJh2hxu4q878sM+lxztZmvjIVndzdqBPJUdnRN7uRfqJKy0aMESAJY2Mzj9+uFCYCvlVSuf41xTGof3bKf7kumrF9jUU2yBst6e+UYoQi2HtzHhpxzN9Sruo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YbaBVhq6; 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="YbaBVhq6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 170CFC4CECF; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=wmL8nD35K+D183HPbTxmWpox+7fCqVw7eRDQh/aakYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YbaBVhq6aLfC7VY51sLTggV8RlajgDfmAPWDy+4TnP/4MjDAqGv71VgfzruJoHkQq zyTw0yiWXvxGgMDAcAAxXsvxb3WOZm8Kw46nXEWWPiTYbqIUOMB3nmyl4NFWUIlD5w w38FOrsyEmju+lfK0LZyksc0YEmm9aYn+1dVTyJqxJqZOYCAR+Zaj1IHG9P5+v0v2v ZHmmCUFpmOq3bm39Jbv6542bzOB6s2tCHBDy2lviwGrX9Xq44c9VOC6HIhskVtXpKi HaMG3MfaTVU2BUhHMNc+HtlKjdIDDequkBQAM0vUxmKJiNSfSLzxR31m0zz1fUajNF KsNFHVLKnfV2Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B63C8CE098E; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 02/15] srcu: Introduce srcu_gp_is_expedited() helper function Date: Tue, 15 Oct 2024 09:10:59 -0700 Message-Id: <20241015161112.442758-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" Even though the open-coded expressions usually fit on one line, this commit replaces them with a call to a new srcu_gp_is_expedited() helper function in order to improve readability. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/srcutree.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 9ff4ded609ba5..e29c6cbffbcb0 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -418,6 +418,16 @@ static void check_init_srcu_struct(struct srcu_struct = *ssp) spin_unlock_irqrestore_rcu_node(ssp->srcu_sup, flags); } =20 +/* + * Is the current or any upcoming grace period to be expedited? + */ +static bool srcu_gp_is_expedited(struct srcu_struct *ssp) +{ + struct srcu_usage *sup =3D ssp->srcu_sup; + + return ULONG_CMP_LT(READ_ONCE(sup->srcu_gp_seq), READ_ONCE(sup->srcu_gp_s= eq_needed_exp)); +} + /* * Returns approximate total of the readers' ->srcu_lock_count[] values * for the rank of per-CPU counters specified by idx. @@ -622,7 +632,7 @@ static unsigned long srcu_get_delay(struct srcu_struct = *ssp) unsigned long jbase =3D SRCU_INTERVAL; struct srcu_usage *sup =3D ssp->srcu_sup; =20 - if (ULONG_CMP_LT(READ_ONCE(sup->srcu_gp_seq), READ_ONCE(sup->srcu_gp_seq_= needed_exp))) + if (srcu_gp_is_expedited(ssp)) jbase =3D 0; if (rcu_seq_state(READ_ONCE(sup->srcu_gp_seq))) { j =3D jiffies - 1; @@ -867,7 +877,7 @@ static void srcu_gp_end(struct srcu_struct *ssp) spin_lock_irq_rcu_node(sup); idx =3D rcu_seq_state(sup->srcu_gp_seq); WARN_ON_ONCE(idx !=3D SRCU_STATE_SCAN2); - if (ULONG_CMP_LT(READ_ONCE(sup->srcu_gp_seq), READ_ONCE(sup->srcu_gp_seq_= needed_exp))) + if (srcu_gp_is_expedited(ssp)) cbdelay =3D 0; =20 WRITE_ONCE(sup->srcu_last_gp_end, ktime_get_mono_fast_ns()); --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 7A5491DD0FD; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=AqMYtCmB4RD7UzId5nZqjw6Jjj+7+RL/tNwlHaE/rKIEiNu8sbxq7sixyUrQqXpKZXIkEUFYFVhFzL/9vTEozNT9cqQMt8+/yri1SL2+7SIIiaOpV/mmefHDG38X1b/vBuScl9b/zyIonndjrGXvBnjzUyLDgt5QgLIKBKCBS9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=Zx5VaivUvDu8VT1tnLqC/VtTV/C14Gn+/PcOHscidtA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fef4SG/CuLuV6vEpGjRKel/q7POivJuIlcRx1aaF4MX8j4PQYWhkrcV1OwOBJbG70epPRAklUD6aZrxk2YQGW4bv5tZ9d8QD4jspWgwGf/nqdTYD0dBRkznBiWzjwPOjeWUfzOyRkekkkWb0qorhE76f5RXmMwphWHU7rtNi1GI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b63025r7; 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="b63025r7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21031C4CECD; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=Zx5VaivUvDu8VT1tnLqC/VtTV/C14Gn+/PcOHscidtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b63025r74M2Ul9heC0OxSAl6gcYAiFcCZnrZG0XQUkb3Ge3zqb+GSMlvqOUULmI2u tI4KynSfkOeatysqXOCPL7HaFEtrFViHdcXxkNLuQk8BWLoCRYmN0fz00vil9RRZYa 9Sxq9I12Hj53QVqCdajvYJQApViPc7bAadYU6SvmYe++4/gWfygdRgY8wWFwouNFOV 0JjO79vsX3Nw8e+6S+oIYYzXXNuAULHDBkxDf1o2u+EzceraFjFOdHAReK5UUE+PLL iB3L9pYEq5Cv8BD5JuMiACEdSYfU24Qi0iMAUYwWNvzjCaPOHGAuy8vhtBrc67Nsr5 J1Tm/L40mkcOQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B9206CE09E9; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 03/15] srcu: Renaming in preparation for additional reader flavor Date: Tue, 15 Oct 2024 09:11:00 -0700 Message-Id: <20241015161112.442758-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" Currently, there are only two flavors of readers, normal and NMI-safe. A number of fields, functions, and types reflect this restriction. This renaming-only commit prepares for the addition of light-weight (as in memory-barrier-free) readers. OK, OK, there is also a drive-by white-space fixeup! Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- include/linux/srcu.h | 21 ++++++++++----------- include/linux/srcutree.h | 2 +- kernel/rcu/srcutree.c | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 835bbb2d1f88a..06728ef6f32a4 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -181,10 +181,9 @@ static inline int srcu_read_lock_held(const struct src= u_struct *ssp) #define SRCU_NMI_SAFE 0x2 =20 #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_TREE_SRCU) -void srcu_check_nmi_safety(struct srcu_struct *ssp, bool nmi_safe); +void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); #else -static inline void srcu_check_nmi_safety(struct srcu_struct *ssp, - bool nmi_safe) { } +static inline void srcu_check_read_flavor(struct srcu_struct *ssp, int rea= d_flavor) { } #endif =20 =20 @@ -245,7 +244,7 @@ static inline int srcu_read_lock(struct srcu_struct *ss= p) __acquires(ssp) { int retval; =20 - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); retval =3D __srcu_read_lock(ssp); srcu_lock_acquire(&ssp->dep_map); return retval; @@ -262,7 +261,7 @@ static inline int srcu_read_lock_nmisafe(struct srcu_st= ruct *ssp) __acquires(ssp { int retval; =20 - srcu_check_nmi_safety(ssp, true); + srcu_check_read_flavor(ssp, true); retval =3D __srcu_read_lock_nmisafe(ssp); rcu_try_lock_acquire(&ssp->dep_map); return retval; @@ -274,7 +273,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acqui= res(ssp) { int retval; =20 - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); retval =3D __srcu_read_lock(ssp); return retval; } @@ -303,7 +302,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acqui= res(ssp) static inline int srcu_down_read(struct srcu_struct *ssp) __acquires(ssp) { WARN_ON_ONCE(in_nmi()); - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); return __srcu_read_lock(ssp); } =20 @@ -318,7 +317,7 @@ static inline void srcu_read_unlock(struct srcu_struct = *ssp, int idx) __releases(ssp) { WARN_ON_ONCE(idx & ~0x1); - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); srcu_lock_release(&ssp->dep_map); __srcu_read_unlock(ssp, idx); } @@ -334,7 +333,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu= _struct *ssp, int idx) __releases(ssp) { WARN_ON_ONCE(idx & ~0x1); - srcu_check_nmi_safety(ssp, true); + srcu_check_read_flavor(ssp, true); rcu_lock_release(&ssp->dep_map); __srcu_read_unlock_nmisafe(ssp, idx); } @@ -343,7 +342,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu= _struct *ssp, int idx) static inline notrace void srcu_read_unlock_notrace(struct srcu_struct *ssp, int idx) __releases(ssp) { - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); __srcu_read_unlock(ssp, idx); } =20 @@ -360,7 +359,7 @@ static inline void srcu_up_read(struct srcu_struct *ssp= , int idx) { WARN_ON_ONCE(idx & ~0x1); WARN_ON_ONCE(in_nmi()); - srcu_check_nmi_safety(ssp, false); + srcu_check_read_flavor(ssp, false); __srcu_read_unlock(ssp, idx); } =20 diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index ed57598394de3..ab7d8d215b84b 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -25,7 +25,7 @@ struct srcu_data { /* Read-side state. */ atomic_long_t srcu_lock_count[2]; /* Locks per CPU. */ atomic_long_t srcu_unlock_count[2]; /* Unlocks per CPU. */ - int srcu_nmi_safety; /* NMI-safe srcu_struct structure? */ + int srcu_reader_flavor; /* Reader flavor for srcu_struct structure? */ =20 /* Update-side state. */ spinlock_t __private lock ____cacheline_internodealigned_in_smp; diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index e29c6cbffbcb0..18f2eae5e14bd 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -460,7 +460,7 @@ static unsigned long srcu_readers_unlock_idx(struct src= u_struct *ssp, int idx) =20 sum +=3D atomic_long_read(&cpuc->srcu_unlock_count[idx]); if (IS_ENABLED(CONFIG_PROVE_RCU)) - mask =3D mask | READ_ONCE(cpuc->srcu_nmi_safety); + mask =3D mask | READ_ONCE(cpuc->srcu_reader_flavor); } WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask >> 1)), "Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp); @@ -699,25 +699,25 @@ EXPORT_SYMBOL_GPL(cleanup_srcu_struct); =20 #ifdef CONFIG_PROVE_RCU /* - * Check for consistent NMI safety. + * Check for consistent reader flavor. */ -void srcu_check_nmi_safety(struct srcu_struct *ssp, bool nmi_safe) +void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor) { - int nmi_safe_mask =3D 1 << nmi_safe; - int old_nmi_safe_mask; + int reader_flavor_mask =3D 1 << read_flavor; + int old_reader_flavor_mask; struct srcu_data *sdp; =20 /* NMI-unsafe use in NMI is a bad sign */ - WARN_ON_ONCE(!nmi_safe && in_nmi()); + WARN_ON_ONCE(!read_flavor && in_nmi()); sdp =3D raw_cpu_ptr(ssp->sda); - old_nmi_safe_mask =3D READ_ONCE(sdp->srcu_nmi_safety); - if (!old_nmi_safe_mask) { - WRITE_ONCE(sdp->srcu_nmi_safety, nmi_safe_mask); + old_reader_flavor_mask =3D READ_ONCE(sdp->srcu_reader_flavor); + if (!old_reader_flavor_mask) { + WRITE_ONCE(sdp->srcu_reader_flavor, reader_flavor_mask); return; } - WARN_ONCE(old_nmi_safe_mask !=3D nmi_safe_mask, "CPU %d old state %d new = state %d\n", sdp->cpu, old_nmi_safe_mask, nmi_safe_mask); + WARN_ONCE(old_reader_flavor_mask !=3D reader_flavor_mask, "CPU %d old sta= te %d new state %d\n", sdp->cpu, old_reader_flavor_mask, reader_flavor_mask= ); } -EXPORT_SYMBOL_GPL(srcu_check_nmi_safety); +EXPORT_SYMBOL_GPL(srcu_check_read_flavor); #endif /* CONFIG_PROVE_RCU */ =20 /* --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 5A0E11CB9E2; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=qrsIqPUqkBKajWnQ8dlZ24YsLbsg2clZwhfXayl4TWy+DlfomLM4DBOz3sGU8dZhvPZp79AhXb2QDK6t9uRFarWmceuYdUfaxPREzzbhNkQ6RctW5IJM7ocg9ecwyKPLHpnbf8RKwbOewjKilVY6bd7+OIE0hCRNj8a82D7rD38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=HtkA9wBw7Sojuw5HhHk7JjMMtDq6tne9Y9iMOe1hFF4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KOyEPZXWwx+6agripVQX0BeCUrfZMVbt1i4UNZ8XRyVjsrlkJfzAsKzD8Kgj1cC+ft9JWqn0g4ra9letBrxuheEq2EE5mYxEUiemS94r27+H/i0JzVYCbK1gk8fwZyuWvUfhbtUocFcKmcEge/M3HN+u2iHzjBryrs56OxMaDEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BgLXKw6N; 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="BgLXKw6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E766C4CED1; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=HtkA9wBw7Sojuw5HhHk7JjMMtDq6tne9Y9iMOe1hFF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgLXKw6N3AW+UE0XMhLDqSIskVLB+HpYigMBdbsRUvuki4N7849L9Qsef8x0PCOuW sVKIg7vmnpeAmr4apZ0rwwbgih3UMRxEGxm32fXVw8nxp8dZKFLGANx//Y4SJRHBDE 4oD7Q6CUrBGrbVavbSKqXTi1I6v0DXk/2RZmeBy/T9zLtg0SLGXPik28l9fEKAduBm SYdgy3BCwcbvD4pui/epYistnTi7xQxmUyRXFVMDnzF/lce7Wdu5mxL0gl0hXoiz0N 33f0I0KfDui+jzdbhJXWmjHbP2rt7xVHU6lGOPpExt9h0DDU87ACcalCaaz7kTQhQ7 fBlLYRICxSdBA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BC0B7CE0F9A; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 04/15] srcu: Bit manipulation changes for additional reader flavor Date: Tue, 15 Oct 2024 09:11:01 -0700 Message-Id: <20241015161112.442758-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" Currently, there are only two flavors of readers, normal and NMI-safe. Very straightforward state updates suffice to check for erroneous mixing of reader flavors on a given srcu_struct structure. This commit upgrades the checking in preparation for the addition of light-weight (as in memory-barrier-free) readers. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/srcutree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 18f2eae5e14bd..abe55777c4335 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -462,7 +462,7 @@ static unsigned long srcu_readers_unlock_idx(struct src= u_struct *ssp, int idx) if (IS_ENABLED(CONFIG_PROVE_RCU)) mask =3D mask | READ_ONCE(cpuc->srcu_reader_flavor); } - WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask >> 1)), + WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)), "Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp); return sum; } @@ -712,8 +712,9 @@ void srcu_check_read_flavor(struct srcu_struct *ssp, in= t read_flavor) sdp =3D raw_cpu_ptr(ssp->sda); old_reader_flavor_mask =3D READ_ONCE(sdp->srcu_reader_flavor); if (!old_reader_flavor_mask) { - WRITE_ONCE(sdp->srcu_reader_flavor, reader_flavor_mask); - return; + old_reader_flavor_mask =3D cmpxchg(&sdp->srcu_reader_flavor, 0, reader_f= lavor_mask); + if (!old_reader_flavor_mask) + return; } WARN_ONCE(old_reader_flavor_mask !=3D reader_flavor_mask, "CPU %d old sta= te %d new state %d\n", sdp->cpu, old_reader_flavor_mask, reader_flavor_mask= ); } --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 9C86F1F6669; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=DCSW7UKaSmSFBCVj2ctOGoXewqQEuqHbahwkzXaDDLqhOvUa1nOOptSUBBjMW1xdaWKuKNavERIRN+PSLwkee1hG7prrU0qyau72AUgl8tYhrhR0ome5Mr8l3UNIRMu8mYIhovK44W23K6xRm4RKdxMd8vi9No6xc9g1SUYBakM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=Z/WQbE3a+ONF2RNiITyp4EEPiF50o0VFDZsBDE5/WuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cGuYcTlCwx8ngaoUKoPb8KoIyUqNODq3BBzW8fqozuwt0BxhJJBbrcz7IO4ZmN/GsxMpB+lFvMDBiR1MORr/R/Ec5d6np4F4XYeVo4We7G7QVpHRkaGfUSGHwDmB5h+M6t7u2Qp7J0eeceZfgWSjixCav7DjvjL9TOXW5p0h1dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a3+axXn8; 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="a3+axXn8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3380EC4CED3; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=Z/WQbE3a+ONF2RNiITyp4EEPiF50o0VFDZsBDE5/WuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3+axXn8xZbsDAU/0tCSbP0XWS+pig7dbTb/J7BJ5mBb5X4TnbB/qCAgEj+tFQWUC G0cjmvub+tfkwxceKo7nrBT/AAAnqOy20DFGAithOjS7h292xNJUyp20croHhzOmWn xaIL2BmFwfw27HPXvQ/SEjq47VjzRpd1mdenl9UZ/QMlHRidh/XsoViVwyKnb/I2we JPRiAT2Muu2Mcz/+QdwsgZ7+mMpArMVSD089PDbXLOfyydpQ8EzaAC5ME7J6CeYcqK fakIQ9cJI4I4tRFusceq3yeBbcpalD+NJF3jX16yZNSxXwJ4aEFSLTBR0R+UekJW8K hCPY85EHn4Upw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BEA68CE0FAB; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 05/15] srcu: Standardize srcu_data pointers to "sdp" and similar Date: Tue, 15 Oct 2024 09:11:02 -0700 Message-Id: <20241015161112.442758-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 changes a few "cpuc" variables to "sdp" to align with usage elsewhere. [ paulmck: Apply Neeraj Upadhyay feedback. ] Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/srcutree.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index abe55777c4335..1e6abdf22c881 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -438,9 +438,9 @@ static unsigned long srcu_readers_lock_idx(struct srcu_= struct *ssp, int idx) unsigned long sum =3D 0; =20 for_each_possible_cpu(cpu) { - struct srcu_data *cpuc =3D per_cpu_ptr(ssp->sda, cpu); + struct srcu_data *sdp =3D per_cpu_ptr(ssp->sda, cpu); =20 - sum +=3D atomic_long_read(&cpuc->srcu_lock_count[idx]); + sum +=3D atomic_long_read(&sdp->srcu_lock_count[idx]); } return sum; } @@ -456,11 +456,11 @@ static unsigned long srcu_readers_unlock_idx(struct s= rcu_struct *ssp, int idx) unsigned long sum =3D 0; =20 for_each_possible_cpu(cpu) { - struct srcu_data *cpuc =3D per_cpu_ptr(ssp->sda, cpu); + struct srcu_data *sdp =3D per_cpu_ptr(ssp->sda, cpu); =20 - sum +=3D atomic_long_read(&cpuc->srcu_unlock_count[idx]); + sum +=3D atomic_long_read(&sdp->srcu_unlock_count[idx]); if (IS_ENABLED(CONFIG_PROVE_RCU)) - mask =3D mask | READ_ONCE(cpuc->srcu_reader_flavor); + mask =3D mask | READ_ONCE(sdp->srcu_reader_flavor); } WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)), "Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp); @@ -564,12 +564,12 @@ static bool srcu_readers_active(struct srcu_struct *s= sp) unsigned long sum =3D 0; =20 for_each_possible_cpu(cpu) { - struct srcu_data *cpuc =3D per_cpu_ptr(ssp->sda, cpu); + struct srcu_data *sdp =3D per_cpu_ptr(ssp->sda, cpu); =20 - sum +=3D atomic_long_read(&cpuc->srcu_lock_count[0]); - sum +=3D atomic_long_read(&cpuc->srcu_lock_count[1]); - sum -=3D atomic_long_read(&cpuc->srcu_unlock_count[0]); - sum -=3D atomic_long_read(&cpuc->srcu_unlock_count[1]); + sum +=3D atomic_long_read(&sdp->srcu_lock_count[0]); + sum +=3D atomic_long_read(&sdp->srcu_lock_count[1]); + sum -=3D atomic_long_read(&sdp->srcu_unlock_count[0]); + sum -=3D atomic_long_read(&sdp->srcu_unlock_count[1]); } return sum; } --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 C88BB1F76C4; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=eNxgkuW1uB+q3GiDnXN6hSjvLTf0WUTGfR5FuVqcE37yHjOgCwfgQxFW9w6x7d5hNN4aL6VCO6yQxY5C4I9yah6CtNzgVmsi2alubD+KWnF3fRB5ssxyn6YUicF/d6zIalP2PcZOH3FoT6CKs4vz8KvnxThI2gh0FleM0h1FPcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=lRHusLBwQ9jaA1f95XVTfeSH3venFIrcNJmEhKbZEYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uxGhfFT0COLOD/YI+95piPmR9I93srkg9BJGrBGylgyVlaqtXmCTVPSUNcrL0O0Ezo8dAYiCdCdRIKsgqjwf099ZsGE6CdBjmt4yAu6ZB8ol9LllL/ONbj64PTPdyEzBj9OIlhctE3tAoy+IGcPCQE0/gimgDmm01WmqvLojzHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RM9ZN+DD; 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="RM9ZN+DD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67DCDC4CED6; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=lRHusLBwQ9jaA1f95XVTfeSH3venFIrcNJmEhKbZEYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RM9ZN+DD25G0DydGoVq9zu4brJs3JId72UOn3lOcOpg51/XD1DPm2dioYoLN4qdSM uDAk5+L7X3Ine1KLa/d+zs3HnOTeLzrJQsougq5niRR5y2VfJa+v0m8ySPY67JecNs FQquRCKdgiWlPp9XPy1MwAMEoru8IyWHOUA2acmaOWEoeEy8Pnbmjska6h9JPRGa+V qOjoW33u/KwbtNvDSlvh/pTRYI1gk678srFU2KuUZcWwPbWB2R24+Uc8IkraxQPGZh glWpOOS6GV//xM7b2SpMTu56krMa0lMTmyaDhYD3DkONmxZvnEFaP6v5EkFG+osFai wYw0N76bLbbLQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C1510CE1038; Tue, 15 Oct 2024 09:11:13 -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" , Andrii Nakryiko Subject: [PATCH rcu 06/15] srcu: Improve srcu_read_lock{,_nmisafe}() comments Date: Tue, 15 Oct 2024 09:11:03 -0700 Message-Id: <20241015161112.442758-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" This commit adds some additional usage constraints to the kernel-doc headers of srcu_read_lock() and srcu_read_lock_nmi_safe(). Suggested-by: Andrii Nakryiko Signed-off-by: Paul E. McKenney Reviewed-by: Neeraj Upadhyay --- include/linux/srcu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 06728ef6f32a4..46fd06b212baa 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -235,10 +235,13 @@ static inline void srcu_check_read_flavor(struct srcu= _struct *ssp, int read_flav * a mutex that is held elsewhere while calling synchronize_srcu() or * synchronize_srcu_expedited(). * - * Note that srcu_read_lock() and the matching srcu_read_unlock() must - * occur in the same context, for example, it is illegal to invoke - * srcu_read_unlock() in an irq handler if the matching srcu_read_lock() - * was invoked in process context. + * The return value from srcu_read_lock() must be passed unaltered + * to the matching srcu_read_unlock(). Note that srcu_read_lock() and + * the matching srcu_read_unlock() must occur in the same context, for + * example, it is illegal to invoke srcu_read_unlock() in an irq handler + * if the matching srcu_read_lock() was invoked in process context. Or, + * for that matter to invoke srcu_read_unlock() from one task and the + * matching srcu_read_lock() from another. */ static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp) { @@ -256,6 +259,10 @@ static inline int srcu_read_lock(struct srcu_struct *s= sp) __acquires(ssp) * * Enter an SRCU read-side critical section, but in an NMI-safe manner. * See srcu_read_lock() for more information. + * + * If srcu_read_lock_nmisafe() is ever used on an srcu_struct structure, + * then none of the other flavors may be used, whether before, during, + * or after. */ static inline int srcu_read_lock_nmisafe(struct srcu_struct *ssp) __acquir= es(ssp) { --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 CA4851F76C6; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=IvY6f3NWJuatMD0OLLlB3B7JDeRmzaRFG04/dixJwXnqIllSRqmCm91TkitwM/WfkOlq4nPlveQF/vCBJ4z811uH5/WGHNUygyRaGdkK+5BQy6yiUmV9Q4WFq/dWOqkjdCziWrw4nlpk65jaC933F82Rz5gy9DZrOWCyejJqO3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=26EP0pZI8PBKRVZdpQWBFbg5cAeS6s6sKXo9twbwLTs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OWAi1l/uIHmPnZQkNGmzDLbKPtjFUwaBe5YEgSxg01uUb3Cuz2Bmks3OjI1uaGTt0YXwueDKhMuH9IFC8Ye9pBuv+gW8/YqgPmgJdB4YjHcCBUD89W/nStaf++p4DRbpcMEuua61gJq1qppxnWlqrALZmziOXqEi0FU6cmAofhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a5vjrp7n; 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="a5vjrp7n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C059C4CEDE; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=26EP0pZI8PBKRVZdpQWBFbg5cAeS6s6sKXo9twbwLTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5vjrp7na9XP5kDbyfjxoYa+3p6xYTWVq8N/+8pbCSRuxmqqXKwMs3QvBxHBTA57u ulJB1TLF1HcRI6s209q4yxaUryB9m5yB8D6f+4SyEtAWM0jUGXt9yV3UVRHBM6IwtW L9yJo4/0+E2DvJ9ViRIZIm+fuDVJcivQo8z1Ge2r4P8iHy+7IqvId+CBpfnqQLBsmA biLKkGevQd6tUCX2g2wb46QUr9/Zdc4IFS4h1K/0kUPdswky5QpWIbg5yD//rHAL4C t+OqSRsHxPhVxFA9juT8uZCy3fArP9N71JM9vY5BAyGk61lyi1bdUAjv9wTAkSFtAd /EE0HzewLCNEA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C4179CE1189; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 07/15] srcu: Create CPP macros for normal and NMI-safe SRCU readers Date: Tue, 15 Oct 2024 09:11:04 -0700 Message-Id: <20241015161112.442758-7-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 creates SRCU_READ_FLAVOR_NORMAL and SRCU_READ_FLAVOR_NMI C-preprocessor macros for srcu_read_lock() and srcu_read_lock_nmisafe(), respectively. These replace the old true/false values that were previously passed to srcu_check_read_flavor(). In addition, the srcu_check_read_flavor() function itself requires a bit of rework to handle bitmasks instead of true/false values. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Signed-off-by: Paul E. McKenney Reviewed-by: Neeraj Upadhyay --- include/linux/srcu.h | 20 ++++++++------------ include/linux/srcutree.h | 4 ++++ kernel/rcu/srcutree.c | 21 +++++++++++---------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 46fd06b212baa..84daaa33ea0ab 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -176,10 +176,6 @@ static inline int srcu_read_lock_held(const struct src= u_struct *ssp) =20 #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ =20 -#define SRCU_NMI_UNKNOWN 0x0 -#define SRCU_NMI_UNSAFE 0x1 -#define SRCU_NMI_SAFE 0x2 - #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_TREE_SRCU) void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); #else @@ -247,7 +243,7 @@ static inline int srcu_read_lock(struct srcu_struct *ss= p) __acquires(ssp) { int retval; =20 - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); retval =3D __srcu_read_lock(ssp); srcu_lock_acquire(&ssp->dep_map); return retval; @@ -268,7 +264,7 @@ static inline int srcu_read_lock_nmisafe(struct srcu_st= ruct *ssp) __acquires(ssp { int retval; =20 - srcu_check_read_flavor(ssp, true); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NMI); retval =3D __srcu_read_lock_nmisafe(ssp); rcu_try_lock_acquire(&ssp->dep_map); return retval; @@ -280,7 +276,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acqui= res(ssp) { int retval; =20 - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); retval =3D __srcu_read_lock(ssp); return retval; } @@ -309,7 +305,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acqui= res(ssp) static inline int srcu_down_read(struct srcu_struct *ssp) __acquires(ssp) { WARN_ON_ONCE(in_nmi()); - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); return __srcu_read_lock(ssp); } =20 @@ -324,7 +320,7 @@ static inline void srcu_read_unlock(struct srcu_struct = *ssp, int idx) __releases(ssp) { WARN_ON_ONCE(idx & ~0x1); - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); srcu_lock_release(&ssp->dep_map); __srcu_read_unlock(ssp, idx); } @@ -340,7 +336,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu= _struct *ssp, int idx) __releases(ssp) { WARN_ON_ONCE(idx & ~0x1); - srcu_check_read_flavor(ssp, true); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NMI); rcu_lock_release(&ssp->dep_map); __srcu_read_unlock_nmisafe(ssp, idx); } @@ -349,7 +345,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu= _struct *ssp, int idx) static inline notrace void srcu_read_unlock_notrace(struct srcu_struct *ssp, int idx) __releases(ssp) { - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); __srcu_read_unlock(ssp, idx); } =20 @@ -366,7 +362,7 @@ static inline void srcu_up_read(struct srcu_struct *ssp= , int idx) { WARN_ON_ONCE(idx & ~0x1); WARN_ON_ONCE(in_nmi()); - srcu_check_read_flavor(ssp, false); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_NORMAL); __srcu_read_unlock(ssp, idx); } =20 diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index ab7d8d215b84b..79ad809c7f035 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -43,6 +43,10 @@ struct srcu_data { struct srcu_struct *ssp; }; =20 +/* Values for ->srcu_reader_flavor. */ +#define SRCU_READ_FLAVOR_NORMAL 0x1 // srcu_read_lock(). +#define SRCU_READ_FLAVOR_NMI 0x2 // srcu_read_lock_nmisafe(). + /* * Node in SRCU combining tree, similar in function to rcu_data. */ diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 1e6abdf22c881..4c51be484b48a 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -463,7 +463,7 @@ static unsigned long srcu_readers_unlock_idx(struct src= u_struct *ssp, int idx) mask =3D mask | READ_ONCE(sdp->srcu_reader_flavor); } WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)), - "Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp); + "Mixed reader flavors for srcu_struct at %ps.\n", ssp); return sum; } =20 @@ -703,20 +703,21 @@ EXPORT_SYMBOL_GPL(cleanup_srcu_struct); */ void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor) { - int reader_flavor_mask =3D 1 << read_flavor; - int old_reader_flavor_mask; + int old_read_flavor; struct srcu_data *sdp; =20 - /* NMI-unsafe use in NMI is a bad sign */ - WARN_ON_ONCE(!read_flavor && in_nmi()); + /* NMI-unsafe use in NMI is a bad sign, as is multi-bit read_flavor value= s. */ + WARN_ON_ONCE((read_flavor !=3D SRCU_READ_FLAVOR_NMI) && in_nmi()); + WARN_ON_ONCE(read_flavor & (read_flavor - 1)); + sdp =3D raw_cpu_ptr(ssp->sda); - old_reader_flavor_mask =3D READ_ONCE(sdp->srcu_reader_flavor); - if (!old_reader_flavor_mask) { - old_reader_flavor_mask =3D cmpxchg(&sdp->srcu_reader_flavor, 0, reader_f= lavor_mask); - if (!old_reader_flavor_mask) + old_read_flavor =3D READ_ONCE(sdp->srcu_reader_flavor); + if (!old_read_flavor) { + old_read_flavor =3D cmpxchg(&sdp->srcu_reader_flavor, 0, read_flavor); + if (!old_read_flavor) return; } - WARN_ONCE(old_reader_flavor_mask !=3D reader_flavor_mask, "CPU %d old sta= te %d new state %d\n", sdp->cpu, old_reader_flavor_mask, reader_flavor_mask= ); + WARN_ONCE(old_read_flavor !=3D read_flavor, "CPU %d old state %d new stat= e %d\n", sdp->cpu, old_read_flavor, read_flavor); } EXPORT_SYMBOL_GPL(srcu_check_read_flavor); #endif /* CONFIG_PROVE_RCU */ --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 AC3EB1F76A2; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=Qo2L4Fy/LCGg7jGyXg0dwqlIS7hhpxrSOH1IIFsnQ7hriE4gOAxTZKbdSk9NUol2Sg5S9FDAIvaI2bCYUSi2aV5RO6OMDCIZkDLRGcbQ3zTzSVaF2Xay98m3On69SKzUklKpu/rPbeR5aLSamthQ5S5Sk7AEUBLnu3EKLmYY36M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=LFRisZMxRbIMr0KIalT12nZOMI5l1WeI4c/6S81vXZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U4RLBxlJeZDKd9scjNAb2O0Hn2e7CjlAbl1ToMkMKA77fgAQuICOQAwlrqHX3uB4+TOe3APFsTzMh6nnSxiy1YPKAD8HezI3blBLyKPp6HNJDdG/cnTAmzVVQqVzsqSsS95Tnn6XJbnqwapB0Vv6aGHwQSolUkpO7N1CU1aH+a4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xk8q/x1s; 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="Xk8q/x1s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D0BEC4CEDF; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=LFRisZMxRbIMr0KIalT12nZOMI5l1WeI4c/6S81vXZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xk8q/x1sAek4IeABu0A+hRcMPj2+RWlSTixnPVI4eMNhjwTI++y8JfO7PlInQV+QV w95Su8hJnV75pHc2NgkDSz/aplgYZJCL5EQbkTkLOkte9iA3KKcg3O4RwPxolfTTrt YtpySRR1OF8ou0jBtb5WxM2dRjsUk/cosZXfyvj05uCcqzDjwtAlY3U2NbcJgJ6AJy t0UHoVuET7vpuRbCMqWMtEE1u+lOPXejHR+3DjUh5e4BSAluuWfn3myhNhM7ATUh4k 44jyubPmnpenV3XIHDMZF+yam86Hkx/Cv/TJ6hMnL51ZsEH3ioLBraIQhv7kHN5xSO SLANQsah9fbVQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C6E16CE1388; Tue, 15 Oct 2024 09:11:13 -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" , kernel test robot , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 08/15] srcu: Add srcu_read_lock_lite() and srcu_read_unlock_lite() Date: Tue, 15 Oct 2024 09:11:05 -0700 Message-Id: <20241015161112.442758-8-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 patch adds srcu_read_lock_lite() and srcu_read_unlock_lite(), which dispense with the read-side smp_mb() but also are restricted to code regions that RCU is watching. If a given srcu_struct structure uses srcu_read_lock_lite() and srcu_read_unlock_lite(), it is not permitted to use any other SRCU read-side marker, before, during, or after. Another price of light-weight readers is heavier weight grace periods. Such readers mean that SRCU grace periods on srcu_struct structures used by light-weight readers will incur at least two calls to synchronize_rcu(). In addition, normal SRCU grace periods for light-weight-reader srcu_struct structures never auto-expedite. Note that expedited SRCU grace periods for light-weight-reader srcu_struct structures still invoke synchronize_rcu(), not synchronize_srcu_expedited(). Something about wishing to keep the IPIs down to a dull roar. The srcu_read_lock_lite() and srcu_read_unlock_lite() functions may not (repeat, *not*) be used from NMI handlers, but if this is needed, an additional flavor of SRCU reader can be added by some future commit. [ paulmck: Apply Alexei Starovoitov expediting feedback. ] [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney Tested-by: kernel test robot Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- include/linux/srcu.h | 51 ++++++++++++++++++++++++- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 82 ++++++++++++++++++++++++++++++++++------ 3 files changed, 122 insertions(+), 12 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 84daaa33ea0ab..4ba96e2cfa405 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -56,6 +56,13 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head = *head, void cleanup_srcu_struct(struct srcu_struct *ssp); int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp); void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp); +#ifdef CONFIG_TINY_SRCU +#define __srcu_read_lock_lite __srcu_read_lock +#define __srcu_read_unlock_lite __srcu_read_unlock +#else // #ifdef CONFIG_TINY_SRCU +int __srcu_read_lock_lite(struct srcu_struct *ssp) __acquires(ssp); +void __srcu_read_unlock_lite(struct srcu_struct *ssp, int idx) __releases(= ssp); +#endif // #else // #ifdef CONFIG_TINY_SRCU void synchronize_srcu(struct srcu_struct *ssp); =20 #define SRCU_GET_STATE_COMPLETED 0x1 @@ -179,7 +186,7 @@ static inline int srcu_read_lock_held(const struct srcu= _struct *ssp) #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_TREE_SRCU) void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); #else -static inline void srcu_check_read_flavor(struct srcu_struct *ssp, int rea= d_flavor) { } +#define srcu_check_read_flavor(ssp, read_flavor) do { } while (0) #endif =20 =20 @@ -249,6 +256,32 @@ static inline int srcu_read_lock(struct srcu_struct *s= sp) __acquires(ssp) return retval; } =20 +/** + * srcu_read_lock_lite - register a new reader for an SRCU-protected struc= ture. + * @ssp: srcu_struct in which to register the new reader. + * + * Enter an SRCU read-side critical section, but for a light-weight + * smp_mb()-free reader. See srcu_read_lock() for more information. + * + * If srcu_read_lock_lite() is ever used on an srcu_struct structure, + * then none of the other flavors may be used, whether before, during, + * or after. Note that grace-period auto-expediting is disabled for _lite + * srcu_struct structures because auto-expedited grace periods invoke + * synchronize_rcu_expedited(), IPIs and all. + * + * Note that srcu_read_lock_lite() can be invoked only from those contexts + * where RCU is watching. Otherwise, lockdep will complain. + */ +static inline int srcu_read_lock_lite(struct srcu_struct *ssp) __acquires(= ssp) +{ + int retval; + + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_LITE); + retval =3D __srcu_read_lock_lite(ssp); + rcu_try_lock_acquire(&ssp->dep_map); + return retval; +} + /** * srcu_read_lock_nmisafe - register a new reader for an SRCU-protected st= ructure. * @ssp: srcu_struct in which to register the new reader. @@ -325,6 +358,22 @@ static inline void srcu_read_unlock(struct srcu_struct= *ssp, int idx) __srcu_read_unlock(ssp, idx); } =20 +/** + * srcu_read_unlock_lite - unregister a old reader from an SRCU-protected = structure. + * @ssp: srcu_struct in which to unregister the old reader. + * @idx: return value from corresponding srcu_read_lock(). + * + * Exit a light-weight SRCU read-side critical section. + */ +static inline void srcu_read_unlock_lite(struct srcu_struct *ssp, int idx) + __releases(ssp) +{ + WARN_ON_ONCE(idx & ~0x1); + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_LITE); + srcu_lock_release(&ssp->dep_map); + __srcu_read_unlock(ssp, idx); +} + /** * srcu_read_unlock_nmisafe - unregister a old reader from an SRCU-protect= ed structure. * @ssp: srcu_struct in which to unregister the old reader. diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 79ad809c7f035..8074138cbd624 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -46,6 +46,7 @@ struct srcu_data { /* Values for ->srcu_reader_flavor. */ #define SRCU_READ_FLAVOR_NORMAL 0x1 // srcu_read_lock(). #define SRCU_READ_FLAVOR_NMI 0x2 // srcu_read_lock_nmisafe(). +#define SRCU_READ_FLAVOR_LITE 0x4 // srcu_read_lock_lite(). =20 /* * Node in SRCU combining tree, similar in function to rcu_data. diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 4c51be484b48a..bf51758cf4a64 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -429,20 +429,29 @@ static bool srcu_gp_is_expedited(struct srcu_struct *= ssp) } =20 /* - * Returns approximate total of the readers' ->srcu_lock_count[] values - * for the rank of per-CPU counters specified by idx. + * Computes approximate total of the readers' ->srcu_lock_count[] values + * for the rank of per-CPU counters specified by idx, and returns true if + * the caller did the proper barrier (gp), and if the count of the locks + * matches that of the unlocks passed in. */ -static unsigned long srcu_readers_lock_idx(struct srcu_struct *ssp, int id= x) +static bool srcu_readers_lock_idx(struct srcu_struct *ssp, int idx, bool g= p, unsigned long unlocks) { int cpu; + unsigned long mask =3D 0; unsigned long sum =3D 0; =20 for_each_possible_cpu(cpu) { struct srcu_data *sdp =3D per_cpu_ptr(ssp->sda, cpu); =20 sum +=3D atomic_long_read(&sdp->srcu_lock_count[idx]); + if (IS_ENABLED(CONFIG_PROVE_RCU)) + mask =3D mask | READ_ONCE(sdp->srcu_reader_flavor); } - return sum; + WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)), + "Mixed reader flavors for srcu_struct at %ps.\n", ssp); + if (mask & SRCU_READ_FLAVOR_LITE && !gp) + return false; + return sum =3D=3D unlocks; } =20 /* @@ -473,6 +482,7 @@ static unsigned long srcu_readers_unlock_idx(struct src= u_struct *ssp, int idx) */ static bool srcu_readers_active_idx_check(struct srcu_struct *ssp, int idx) { + bool did_gp =3D !!(raw_cpu_read(ssp->sda->srcu_reader_flavor) & SRCU_READ= _FLAVOR_LITE); unsigned long unlocks; =20 unlocks =3D srcu_readers_unlock_idx(ssp, idx); @@ -482,13 +492,16 @@ static bool srcu_readers_active_idx_check(struct srcu= _struct *ssp, int idx) * unlock is counted. Needs to be a smp_mb() as the read side may * contain a read from a variable that is written to before the * synchronize_srcu() in the write side. In this case smp_mb()s - * A and B act like the store buffering pattern. + * A and B (or X and Y) act like the store buffering pattern. * - * This smp_mb() also pairs with smp_mb() C to prevent accesses - * after the synchronize_srcu() from being executed before the - * grace period ends. + * This smp_mb() also pairs with smp_mb() C (or, in the case of X, + * Z) to prevent accesses after the synchronize_srcu() from being + * executed before the grace period ends. */ - smp_mb(); /* A */ + if (!did_gp) + smp_mb(); /* A */ + else + synchronize_rcu(); /* X */ =20 /* * If the locks are the same as the unlocks, then there must have @@ -546,7 +559,7 @@ static bool srcu_readers_active_idx_check(struct srcu_s= truct *ssp, int idx) * which are unlikely to be configured with an address space fully * populated with memory, at least not anytime soon. */ - return srcu_readers_lock_idx(ssp, idx) =3D=3D unlocks; + return srcu_readers_lock_idx(ssp, idx, did_gp, unlocks); } =20 /** @@ -750,6 +763,47 @@ void __srcu_read_unlock(struct srcu_struct *ssp, int i= dx) } EXPORT_SYMBOL_GPL(__srcu_read_unlock); =20 +/* + * Counts the new reader in the appropriate per-CPU element of the + * srcu_struct. Returns an index that must be passed to the matching + * srcu_read_unlock_lite(). + * + * Note that this_cpu_inc() is an RCU read-side critical section either + * because it disables interrupts, because it is a single instruction, + * or because it is a read-modify-write atomic operation, depending on + * the whims of the architecture. + */ +int __srcu_read_lock_lite(struct srcu_struct *ssp) +{ + int idx; + + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock= _lite()."); + idx =3D READ_ONCE(ssp->srcu_idx) & 0x1; + this_cpu_inc(ssp->sda->srcu_lock_count[idx].counter); /* Y */ + barrier(); /* Avoid leaking the critical section. */ + return idx; +} +EXPORT_SYMBOL_GPL(__srcu_read_lock_lite); + +/* + * Removes the count for the old reader from the appropriate + * per-CPU element of the srcu_struct. Note that this may well be a + * different CPU than that which was incremented by the corresponding + * srcu_read_lock_lite(), but it must be within the same task. + * + * Note that this_cpu_inc() is an RCU read-side critical section either + * because it disables interrupts, because it is a single instruction, + * or because it is a read-modify-write atomic operation, depending on + * the whims of the architecture. + */ +void __srcu_read_unlock_lite(struct srcu_struct *ssp, int idx) +{ + barrier(); /* Avoid leaking the critical section. */ + this_cpu_inc(ssp->sda->srcu_unlock_count[idx].counter); /* Z */ + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_lite()."); +} +EXPORT_SYMBOL_GPL(__srcu_read_unlock_lite); + #ifdef CONFIG_NEED_SRCU_NMI_SAFE =20 /* @@ -1134,6 +1188,8 @@ static void srcu_flip(struct srcu_struct *ssp) * it stays until either (1) Compilers learn about this sort of * control dependency or (2) Some production workload running on * a production system is unduly delayed by this slowpath smp_mb(). + * Except for _lite() readers, where it is inoperative, which + * means that it is a good thing that it is redundant. */ smp_mb(); /* E */ /* Pairs with B and C. */ =20 @@ -1152,7 +1208,8 @@ static void srcu_flip(struct srcu_struct *ssp) =20 /* * If SRCU is likely idle, in other words, the next SRCU grace period - * should be expedited, return true, otherwise return false. + * should be expedited, return true, otherwise return false. Except that + * in the presence of _lite() readers, always return false. * * Note that it is OK for several current from-idle requests for a new * grace period from idle to specify expediting because they will all end @@ -1181,6 +1238,9 @@ static bool srcu_should_expedite(struct srcu_struct *= ssp) unsigned long tlast; =20 check_init_srcu_struct(ssp); + /* If _lite() readers, don't do unsolicited expediting. */ + if (this_cpu_read(ssp->sda->srcu_reader_flavor) & SRCU_READ_FLAVOR_LITE) + return false; /* If the local srcu_data structure has callbacks, not idle. */ sdp =3D raw_cpu_ptr(ssp->sda); spin_lock_irqsave_rcu_node(sdp, flags); --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 CB19C1F76C7; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=Qmo1/ZTTYwqWxXHf0smlrpNlqbz6Zi/+D0lCeIi8wUuR8/+cLtlQ0dkcevckY9U8BmmpLjTmX9lYOPSHNboouRuVkqsW4j5u+J21nRtMLjne8CwZJRdHdGtvvNTK9uvLoMYX7k5lh4eVz04HQLB9xr5QJ+iUcuCAeUZWF90VkvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=MCTM0QcTKx5V+XLmwCnRaQM2SyFIPw4fWJwP26eLAXM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pP2LdcEHQxAnOJTwfOlp3kR9bCQ+Dsmw4fwRlOljZ0XX3nK+jAAfHtcV0+r8CybNvmlqPkDLC7VPagt+l9strVitjdKvEuBR1WnZ03UIG5203OV3eNPnIkPz6agW4/sO5HHbbgK6jvcpNFkpKzUnX3/GYzSfXbSErpq+9ID50aU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ra5QECD3; 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="ra5QECD3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A209C4CEDD; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=MCTM0QcTKx5V+XLmwCnRaQM2SyFIPw4fWJwP26eLAXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ra5QECD3QJxWPaa32Olv7ALvD8WaHYOESDtwfwVpFNCLGi5UelTFTH7vC+X7TgmHv tdHVAt2CSY5nB/4aBW+ELG94HXe6z9fdqbv1mXTtbgV3tOZ+yfKRwyUtGU2QC/95ls 4hj+TnYv4EstDFP8jdQ+4TXqnkiXxPBV/oM9MK+nK4OZwvWM3bKL6OSeh+jSM2gc8W 3SN0DGUuH6anwYHG4H9zwM5h1DWcBDKZBbkpmNsd58hF0Intcrko5eCUagiENwHBtq NZIT5Kc4S6DZB3Ks3pIVYVMBsKLtThc8U1joWpwjIWLnTDqXoPxGcv0EvMO27k3rVZ y1bsOFXkGDElQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C9DC2CE13D2; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 09/15] srcu: Allow inlining of __srcu_read_{,un}lock_lite() Date: Tue, 15 Oct 2024 09:11:06 -0700 Message-Id: <20241015161112.442758-9-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 moves __srcu_read_lock_lite() and __srcu_read_unlock_lite() into include/linux/srcu.h and marks them "static inline" so that they can be inlined into srcu_read_lock_lite() and srcu_read_unlock_lite(), respectively. They are not hand-inlined due to Tree SRCU and Tiny SRCU having different implementations. The earlier removal of smp_mb() combined with the inlining produce significant single-percentage performance wins. Link: https://lore.kernel.org/all/CAEf4BzYgiNmSb=3DZKQ65tm6nJDi1UX2Gq26cdHS= H1mPwXJYZj5g@mail.gmail.com/ Reported-by: Alexei Starovoitov Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- include/linux/srcutree.h | 39 ++++++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 41 ---------------------------------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 8074138cbd624..778eb61542e18 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -209,4 +209,43 @@ void synchronize_srcu_expedited(struct srcu_struct *ss= p); void srcu_barrier(struct srcu_struct *ssp); void srcu_torture_stats_print(struct srcu_struct *ssp, char *tt, char *tf); =20 +/* + * Counts the new reader in the appropriate per-CPU element of the + * srcu_struct. Returns an index that must be passed to the matching + * srcu_read_unlock_lite(). + * + * Note that this_cpu_inc() is an RCU read-side critical section either + * because it disables interrupts, because it is a single instruction, + * or because it is a read-modify-write atomic operation, depending on + * the whims of the architecture. + */ +static inline int __srcu_read_lock_lite(struct srcu_struct *ssp) +{ + int idx; + + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock= _lite()."); + idx =3D READ_ONCE(ssp->srcu_idx) & 0x1; + this_cpu_inc(ssp->sda->srcu_lock_count[idx].counter); /* Y */ + barrier(); /* Avoid leaking the critical section. */ + return idx; +} + +/* + * Removes the count for the old reader from the appropriate + * per-CPU element of the srcu_struct. Note that this may well be a + * different CPU than that which was incremented by the corresponding + * srcu_read_lock_lite(), but it must be within the same task. + * + * Note that this_cpu_inc() is an RCU read-side critical section either + * because it disables interrupts, because it is a single instruction, + * or because it is a read-modify-write atomic operation, depending on + * the whims of the architecture. + */ +static inline void __srcu_read_unlock_lite(struct srcu_struct *ssp, int id= x) +{ + barrier(); /* Avoid leaking the critical section. */ + this_cpu_inc(ssp->sda->srcu_unlock_count[idx].counter); /* Z */ + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_lite()."); +} + #endif diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index bf51758cf4a64..07147efcb64d3 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -763,47 +763,6 @@ void __srcu_read_unlock(struct srcu_struct *ssp, int i= dx) } EXPORT_SYMBOL_GPL(__srcu_read_unlock); =20 -/* - * Counts the new reader in the appropriate per-CPU element of the - * srcu_struct. Returns an index that must be passed to the matching - * srcu_read_unlock_lite(). - * - * Note that this_cpu_inc() is an RCU read-side critical section either - * because it disables interrupts, because it is a single instruction, - * or because it is a read-modify-write atomic operation, depending on - * the whims of the architecture. - */ -int __srcu_read_lock_lite(struct srcu_struct *ssp) -{ - int idx; - - RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock= _lite()."); - idx =3D READ_ONCE(ssp->srcu_idx) & 0x1; - this_cpu_inc(ssp->sda->srcu_lock_count[idx].counter); /* Y */ - barrier(); /* Avoid leaking the critical section. */ - return idx; -} -EXPORT_SYMBOL_GPL(__srcu_read_lock_lite); - -/* - * Removes the count for the old reader from the appropriate - * per-CPU element of the srcu_struct. Note that this may well be a - * different CPU than that which was incremented by the corresponding - * srcu_read_lock_lite(), but it must be within the same task. - * - * Note that this_cpu_inc() is an RCU read-side critical section either - * because it disables interrupts, because it is a single instruction, - * or because it is a read-modify-write atomic operation, depending on - * the whims of the architecture. - */ -void __srcu_read_unlock_lite(struct srcu_struct *ssp, int idx) -{ - barrier(); /* Avoid leaking the critical section. */ - this_cpu_inc(ssp->sda->srcu_unlock_count[idx].counter); /* Z */ - RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlo= ck_lite()."); -} -EXPORT_SYMBOL_GPL(__srcu_read_unlock_lite); - #ifdef CONFIG_NEED_SRCU_NMI_SAFE =20 /* --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 CBD9E1F76C8; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=Ujjz2UznQsCHE64HqP70tbNk+vjnf7YZ4qJCWew2FI0IzmIP+rtukRwJSkyCxFLuMqKwQ9AjyYt78kG4SjN1hmI08wQibzxOc1xa4vcYB5COY5DL6j5loCRe/1qfP9hkeRGSBLafdy8sEGe0ksbkcopue982nXTo4AX73uL1LYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=455xAJUPKkl1YHsvTg2vxb9TRAoSDc2shVSbJO8e+tM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CeTyWw2s2Qf7mTiawIKo9CFNrNhyJ9rug6VeofpNudpNFOo2l/C+GMhKwhyJS7IMvqEKmnCY3qjQNepuWIEBLEh/pX+c1jRxyT6EKtwRX1AQVAIBTVmeKzzIn26IZPLefXk4M1x+Xvn27jDhqCApvtChFCejasDamyW3XVbEsrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g53+DCaY; 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="g53+DCaY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CB5DC4CEE0; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=455xAJUPKkl1YHsvTg2vxb9TRAoSDc2shVSbJO8e+tM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g53+DCaYtXNr3LB/5c24f8gsm5/pr3vCPBGvUlasCxPyKawrgCNRlXmGKVz5adxyw imbbqGmd2udmTpIRKK3euVfXxgKsQDGCFkGcP66MdzeBqse/ifG55yLtzMIc69ll0q FzbJY+caaNE2/5g3fF7/GeFzBoXY+O4BbSK1eFweGeOIVpHO+tsdTcCUrZzZtvCD+3 o5zt0rfCtR7hbg3fvGxVwD79PjBgkb5IyoGlCutwpJV4MXVxEy0anc4ZIHy4clOq/F ZDqHEnP4s5caGfSzH35FjhYSGPygHo03PYna9UeYcSexNZZGbP4P7SMGOkK+HuDMka oiqo3D73rD1pA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CC702CE15C3; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 10/15] rcutorture: Expand RCUTORTURE_RDR_MASK_[12] to eight bits Date: Tue, 15 Oct 2024 09:11:07 -0700 Message-Id: <20241015161112.442758-10-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 prepares for testing of multiple SRCU reader flavors by expanding RCUTORTURE_RDR_MASK_1 and RCUTORTURE_RDR_MASK_2 from a single bit to eight bits, allowing them to accommodate the return values from multiple calls to srcu_read_lock*(). This will in turn permit better testing coverage for these SRCU reader flavors, including testing of the diagnostics for inproper use of mixed reader flavors. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/rcutorture.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index bb75dbf5c800c..f96ab98f8182f 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -57,9 +57,9 @@ MODULE_AUTHOR("Paul E. McKenney a= nd Josh Triplett extendables field, extendables param, and related definition= s. */ #define RCUTORTURE_RDR_SHIFT_1 8 /* Put SRCU index in upper bits. */ -#define RCUTORTURE_RDR_MASK_1 (1 << RCUTORTURE_RDR_SHIFT_1) -#define RCUTORTURE_RDR_SHIFT_2 9 /* Put SRCU index in upper bits. */ -#define RCUTORTURE_RDR_MASK_2 (1 << RCUTORTURE_RDR_SHIFT_2) +#define RCUTORTURE_RDR_MASK_1 (0xff << RCUTORTURE_RDR_SHIFT_1) +#define RCUTORTURE_RDR_SHIFT_2 16 /* Put SRCU index in upper bits. */ +#define RCUTORTURE_RDR_MASK_2 (0xff << RCUTORTURE_RDR_SHIFT_2) #define RCUTORTURE_RDR_BH 0x01 /* Extend readers by disabling bh. */ #define RCUTORTURE_RDR_IRQ 0x02 /* ... disabling interrupts. */ #define RCUTORTURE_RDR_PREEMPT 0x04 /* ... disabling preemption. */ @@ -71,6 +71,9 @@ MODULE_AUTHOR("Paul E. McKenney a= nd Josh Triplett > RCUTORTURE_RDR_SHIFT_2) > 1); + WARN_ON_ONCE(idxold2 & ~RCUTORTURE_RDR_ALLBITS); rtrsp->rt_readstate =3D newstate; =20 /* First, put new protection in place to avoid critical-section gap. */ @@ -1835,9 +1838,9 @@ static void rcutorture_one_extend(int *readstate, int= newstate, if (statesnew & RCUTORTURE_RDR_SCHED) rcu_read_lock_sched(); if (statesnew & RCUTORTURE_RDR_RCU_1) - idxnew1 =3D (cur_ops->readlock() & 0x1) << RCUTORTURE_RDR_SHIFT_1; + idxnew1 =3D (cur_ops->readlock() << RCUTORTURE_RDR_SHIFT_1) & RCUTORTURE= _RDR_MASK_1; if (statesnew & RCUTORTURE_RDR_RCU_2) - idxnew2 =3D (cur_ops->readlock() & 0x1) << RCUTORTURE_RDR_SHIFT_2; + idxnew2 =3D (cur_ops->readlock() << RCUTORTURE_RDR_SHIFT_2) & RCUTORTURE= _RDR_MASK_2; =20 /* * Next, remove old protection, in decreasing order of strength @@ -1857,7 +1860,7 @@ static void rcutorture_one_extend(int *readstate, int= newstate, if (statesold & RCUTORTURE_RDR_RBH) rcu_read_unlock_bh(); if (statesold & RCUTORTURE_RDR_RCU_2) { - cur_ops->readunlock((idxold2 >> RCUTORTURE_RDR_SHIFT_2) & 0x1); + cur_ops->readunlock((idxold2 & RCUTORTURE_RDR_MASK_2) >> RCUTORTURE_RDR_= SHIFT_2); WARN_ON_ONCE(idxnew2 !=3D -1); idxold2 =3D 0; } @@ -1867,7 +1870,7 @@ static void rcutorture_one_extend(int *readstate, int= newstate, lockit =3D !cur_ops->no_pi_lock && !statesnew && !(torture_random(trsp) = & 0xffff); if (lockit) raw_spin_lock_irqsave(¤t->pi_lock, flags); - cur_ops->readunlock((idxold1 >> RCUTORTURE_RDR_SHIFT_1) & 0x1); + cur_ops->readunlock((idxold1 & RCUTORTURE_RDR_MASK_1) >> RCUTORTURE_RDR_= SHIFT_1); WARN_ON_ONCE(idxnew1 !=3D -1); idxold1 =3D 0; if (lockit) @@ -1882,16 +1885,13 @@ static void rcutorture_one_extend(int *readstate, i= nt newstate, if (idxnew1 =3D=3D -1) idxnew1 =3D idxold1 & RCUTORTURE_RDR_MASK_1; WARN_ON_ONCE(idxnew1 < 0); - if (WARN_ON_ONCE((idxnew1 >> RCUTORTURE_RDR_SHIFT_1) > 1)) - pr_info("Unexpected idxnew1 value of %#x\n", idxnew1); if (idxnew2 =3D=3D -1) idxnew2 =3D idxold2 & RCUTORTURE_RDR_MASK_2; WARN_ON_ONCE(idxnew2 < 0); - WARN_ON_ONCE((idxnew2 >> RCUTORTURE_RDR_SHIFT_2) > 1); *readstate =3D idxnew1 | idxnew2 | newstate; WARN_ON_ONCE(*readstate < 0); - if (WARN_ON_ONCE((*readstate >> RCUTORTURE_RDR_SHIFT_2) > 1)) - pr_info("Unexpected idxnew2 value of %#x\n", idxnew2); + if (WARN_ON_ONCE(*readstate & ~RCUTORTURE_RDR_ALLBITS)) + pr_info("Unexpected readstate value of %#x\n", *readstate); } =20 /* Return the biggest extendables mask given current RCU and boot paramete= rs. */ @@ -1916,7 +1916,7 @@ rcutorture_extend_mask(int oldmask, struct torture_ra= ndom_state *trsp) unsigned long preempts_irq =3D preempts | RCUTORTURE_RDR_IRQ; unsigned long bhs =3D RCUTORTURE_RDR_BH | RCUTORTURE_RDR_RBH; =20 - WARN_ON_ONCE(mask >> RCUTORTURE_RDR_SHIFT_1); + WARN_ON_ONCE(mask >> RCUTORTURE_RDR_SHIFT_1); // Can't have reader idx b= its. /* Mostly only one bit (need preemption!), sometimes lots of bits. */ if (!(randmask1 & 0x7)) mask =3D mask & randmask2; --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 E94491F76D9; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008675; cv=none; b=oWd1GegFrMEitlPMFmfNom/67P3sAiWAetkAQvAleXQNJbs62q9p8a7vZYeTuM9NwaKXIK6SmstkJureM+qQEoLe0StAb96zD/8JjCu+BlitDPxER70swJlL+PHwpjld0DIeWAtDKHovc06O0Z6AwthMBF1S+EyzeSoE4G71m7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008675; c=relaxed/simple; bh=USWy1f2+MRE4E6Ag+HiaCUvOKEVnE9SJTDypoSyYrTo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t8zmlbRPLWDW94Ci6OuDHBoiuFEjVeOJT1dso/IK5x1TkWYw8JxfCRkLrFUqK8UWJigpWy3LJAm1vgJyu7gCHcqMhgyiCXnQqOfUM27vTqOp9P0EJLqUK5Tb8IPdvPd8R4Bq8pFaG3hoYt9It39T2rQ+HCZdX83PligwSMgP1iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VluLbv0D; 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="VluLbv0D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85DAFC4CEE4; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=USWy1f2+MRE4E6Ag+HiaCUvOKEVnE9SJTDypoSyYrTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VluLbv0DeB/aePpRB2If4lR9PZW2xAiiLjEKlpvhbZYRhtKBvek4K8DIwRWS7DVKv wNQidWf2fSt5/42jtGoFKqZCWU6JHqAWBx6eB+jmwMLHIWjlD6K/zy0wonIGVBA3Rc SJVSamA/SawXue+wuT8PGVj5w1yyDZDiAUfKraWI9ElF4SDWQQXtRyH0ckXL+9B/Zl uzCKheq7oTkLWOiwo/PdDCvuNZhEpPCAIzpaXxi393dPJ7DxDgX3DI1LggSxyTbpHO m/B14GCYJwLH/3dh9/kfExnjwz/lQQ/AYq+TBS3v/aKzQmyO7263Cn1wwq++it6bQ1 sNHIDtV1kX26A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CF578CE16F0; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 11/15] rcutorture: Add reader_flavor parameter for SRCU readers Date: Tue, 15 Oct 2024 09:11:08 -0700 Message-Id: <20241015161112.442758-11-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 an rcutorture.reader_flavor parameter whose bits correspond to reader flavors. For example, SRCU's readers are 0x1 for normal and 0x2 for NMI-safe. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- .../admin-guide/kernel-parameters.txt | 8 +++++ kernel/rcu/rcutorture.c | 30 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 1518343bbe223..52922727006fc 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5426,6 +5426,14 @@ The delay, in seconds, between successive read-then-exit testing episodes. =20 + rcutorture.reader_flavor=3D [KNL] + A bit mask indicating which readers to use. + If there is more than one bit set, the readers + are entered from low-order bit up, and are + exited in the opposite order. For SRCU, the + 0x1 bit is normal readers and the 0x2 bit is + for NMI-safe readers. + rcutorture.shuffle_interval=3D [KNL] Set task-shuffle interval (s). Shuffling tasks allows some CPUs to go into dyntick-idle mode diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index f96ab98f8182f..405decec33677 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -111,6 +111,7 @@ torture_param(int, nocbs_nthreads, 0, "Number of NOCB t= oggle threads, 0 to disab torture_param(int, nocbs_toggle, 1000, "Time between toggling nocb state (= ms)"); torture_param(int, read_exit_delay, 13, "Delay between read-then-exit epis= odes (s)"); torture_param(int, read_exit_burst, 16, "# of read-then-exit bursts per ep= isode, zero to disable"); +torture_param(int, reader_flavor, 0x1, "Reader flavors to use, one per bit= ."); torture_param(int, shuffle_interval, 3, "Number of seconds between shuffle= s"); torture_param(int, shutdown_secs, 0, "Shutdown time (s), <=3D zero to disa= ble."); torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable."); @@ -644,10 +645,20 @@ static void srcu_get_gp_data(int *flags, unsigned lon= g *gp_seq) =20 static int srcu_torture_read_lock(void) { - if (cur_ops =3D=3D &srcud_ops) - return srcu_read_lock_nmisafe(srcu_ctlp); - else - return srcu_read_lock(srcu_ctlp); + int idx; + int ret =3D 0; + + if ((reader_flavor & 0x1) || !(reader_flavor & 0x7)) { + idx =3D srcu_read_lock(srcu_ctlp); + WARN_ON_ONCE(idx & ~0x1); + ret +=3D idx; + } + if (reader_flavor & 0x2) { + idx =3D srcu_read_lock_nmisafe(srcu_ctlp); + WARN_ON_ONCE(idx & ~0x1); + ret +=3D idx << 1; + } + return ret; } =20 static void @@ -671,10 +682,11 @@ srcu_read_delay(struct torture_random_state *rrsp, st= ruct rt_read_seg *rtrsp) =20 static void srcu_torture_read_unlock(int idx) { - if (cur_ops =3D=3D &srcud_ops) - srcu_read_unlock_nmisafe(srcu_ctlp, idx); - else - srcu_read_unlock(srcu_ctlp, idx); + WARN_ON_ONCE((reader_flavor && (idx & ~reader_flavor)) || (!reader_flavor= && (idx & ~0x1))); + if (reader_flavor & 0x2) + srcu_read_unlock_nmisafe(srcu_ctlp, (idx & 0x2) >> 1); + if ((reader_flavor & 0x1) || !(reader_flavor & 0x7)) + srcu_read_unlock(srcu_ctlp, idx & 0x1); } =20 static int torture_srcu_read_lock_held(void) @@ -2389,6 +2401,7 @@ rcu_torture_print_module_parms(struct rcu_torture_ops= *cur_ops, const char *tag) "n_barrier_cbs=3D%d " "onoff_interval=3D%d onoff_holdoff=3D%d " "read_exit_delay=3D%d read_exit_burst=3D%d " + "reader_flavor=3D%x " "nocbs_nthreads=3D%d nocbs_toggle=3D%d " "test_nmis=3D%d\n", torture_type, tag, nrealreaders, nfakewriters, @@ -2401,6 +2414,7 @@ rcu_torture_print_module_parms(struct rcu_torture_ops= *cur_ops, const char *tag) n_barrier_cbs, onoff_interval, onoff_holdoff, read_exit_delay, read_exit_burst, + reader_flavor, nocbs_nthreads, nocbs_toggle, test_nmis); } --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 D811D1F76D2; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=QcCzN6vm4fNlhFh2JljHx5jxh8dI9Cin0uZXAZle2iNl9TiBB/GIEsjhJpeHc/nef87jH2dOM21QA9wA894LRMHBBXe0U+FfMTD99UlPUkxCrl1gOEVQF1/ecLv6LAjCnoPF+25qjGmh36L3XTb1EZmTURuIQgy2XiYSVE2+pIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=2/hu6Yi0XsmLS7jmPPcP2qqf4oo1mhmwzrHcI6b4xBA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TEXNULrtbZJfni1wrlEahi2MfG0Oi+b+5yclxf4I2pyMcEn+UnjFrFKBXePZc/OO4kyMioEICRSBqbv+1LsnGbOGECC9xSJphmAQ5jxPtWOkrdxEPgqd/QgLKmes0NiCbd43WpQDRFM67D+i+eOagwpy4vZmewtv5/LbUhNKW0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eikvUaAA; 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="eikvUaAA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84EBDC4CEE3; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=2/hu6Yi0XsmLS7jmPPcP2qqf4oo1mhmwzrHcI6b4xBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eikvUaAAAV+LFBGasGXysFYWlnzo6ep0sjM6lJ+EOa0ujRPxyeBHVnLdKCwhCg+zu gPsrpkMBFlWeEzNbUPK08SevdPC+tRQynJnAW7uLFw9I5qTtFr81pk8kLe8H0NnZF3 lh/QmqnCf3emspdPnHccaYisFqUE48OqoW/ngm9+E1AxJd4+Akpa06QD5ezS7AxahQ aXMNe/gzffcug8gUaTpuMd1YByQ7qLKCUtCb6zNEiKGYKIMG5oPdn6Xfb9bLnMP9FG LWSKEjc8MEDuQqbPbgGKvy+83kregsyfoZnSBLbHsQbPaDhAJHmDy25Yu/mMIilI4X ijiC2cvzYr1UQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D1EA8CE1D59; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 12/15] rcutorture: Add srcu_read_lock_lite() support to rcutorture.reader_flavor Date: Tue, 15 Oct 2024 09:11:09 -0700 Message-Id: <20241015161112.442758-12-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 causes bit 0x4 of rcutorture.reader_flavor to select the new srcu_read_lock_lite() and srcu_read_unlock_lite() functions. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- Documentation/admin-guide/kernel-parameters.txt | 4 ++-- kernel/rcu/rcutorture.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 52922727006fc..203ec51e41d48 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5431,8 +5431,8 @@ If there is more than one bit set, the readers are entered from low-order bit up, and are exited in the opposite order. For SRCU, the - 0x1 bit is normal readers and the 0x2 bit is - for NMI-safe readers. + 0x1 bit is normal readers, 0x2 NMI-safe readers, + and 0x4 light-weight readers. =20 rcutorture.shuffle_interval=3D [KNL] Set task-shuffle interval (s). Shuffling tasks diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index 405decec33677..a313cdcb0960f 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -658,6 +658,11 @@ static int srcu_torture_read_lock(void) WARN_ON_ONCE(idx & ~0x1); ret +=3D idx << 1; } + if (reader_flavor & 0x4) { + idx =3D srcu_read_lock_lite(srcu_ctlp); + WARN_ON_ONCE(idx & ~0x1); + ret +=3D idx << 2; + } return ret; } =20 @@ -683,6 +688,8 @@ srcu_read_delay(struct torture_random_state *rrsp, stru= ct rt_read_seg *rtrsp) static void srcu_torture_read_unlock(int idx) { WARN_ON_ONCE((reader_flavor && (idx & ~reader_flavor)) || (!reader_flavor= && (idx & ~0x1))); + if (reader_flavor & 0x4) + srcu_read_unlock_lite(srcu_ctlp, (idx & 0x4) >> 2); if (reader_flavor & 0x2) srcu_read_unlock_nmisafe(srcu_ctlp, (idx & 0x2) >> 1); if ((reader_flavor & 0x1) || !(reader_flavor & 0x7)) --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 D089B1F76CB; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=XIV49JsGuDjGWPtVMFTma2ZB+yy5YKcqU89iE95xJbVyr1q+rrYOYNMf8QUwqEJ+nsvPsHN+znZO+OHY34GGekyM0Hwn0v6XRCcUe6v/X2qoDFgvB8whgwX3k7XsFhVE25HlYmHQy1YMSKBptFTjs+weaLy+ojWBrBZ7XA1T4Lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=aRxkj03S73hF0jV8gryZajtKN0A7DA6aTKR8Jq/1sgk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qlXi+Th+NM4k5p+lNJ/F5FbnL0NX5UpWawyc/OEZrwA50kJdJDwWnLFgZQChXdg6pHVSvErELAkGa2GjAfBzjrPZNjl2J79y6+fwPj4CmaLVxP5Ye5HNdtTaGAmIvjz2S86RUt6/qs95/TefNn6ry9XGnI6vB3ZQs+Bk2NucXx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A9aengoc; 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="A9aengoc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FEEBC4CEEA; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=aRxkj03S73hF0jV8gryZajtKN0A7DA6aTKR8Jq/1sgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9aengocjrOEp06JhtZ7EDKxhhEbbEJWPJt5kIWlCOu6SeFdTfUT68yFtT9Bm1WSm DWqw/2zF4G4HaT/JcV/VDfWWQIjRZINlsFlflqzlE4k3dNq9ELaF6bS5siJXKvXSXJ AxQ/jXkMamJAHktKdBcFFFEVoUYElKshmFe9OAPwdXQ78ypcMGB6y6mkxsdc9Utq3T swlx3XYeVEzwkxV6JdxTARGjDfTKJXlKzyk2xPSbeBbWnrW9KpFCfkK/PMd6iHIqDe 5wsmH/pi28YEEK8WrCGrQgWdS4l3PhqPWrWa5gjiT+eByI7KanmBYrazv1QSmb8wT4 6eQskVSS087Qg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D4755CE1FD0; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 13/15] rcutorture: Add light-weight SRCU scenario Date: Tue, 15 Oct 2024 09:11:10 -0700 Message-Id: <20241015161112.442758-13-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 an rcutorture scenario that tests light-weight SRCU readers. While in the area, it adjusts the size of the TREE10 scenario. Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- tools/testing/selftests/rcutorture/configs/rcu/CFLIST | 1 + tools/testing/selftests/rcutorture/configs/rcu/SRCU-L | 10 ++++++++++ .../selftests/rcutorture/configs/rcu/SRCU-L.boot | 3 +++ .../selftests/rcutorture/configs/rcu/SRCU-N.boot | 1 + tools/testing/selftests/rcutorture/configs/rcu/TREE10 | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-L create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-L.b= oot diff --git a/tools/testing/selftests/rcutorture/configs/rcu/CFLIST b/tools/= testing/selftests/rcutorture/configs/rcu/CFLIST index 98b6175e5aa09..45f572570a8c3 100644 --- a/tools/testing/selftests/rcutorture/configs/rcu/CFLIST +++ b/tools/testing/selftests/rcutorture/configs/rcu/CFLIST @@ -5,6 +5,7 @@ TREE04 TREE05 TREE07 TREE09 +SRCU-L SRCU-N SRCU-P SRCU-T diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-L b/tools/= testing/selftests/rcutorture/configs/rcu/SRCU-L new file mode 100644 index 0000000000000..3b4fa8dbef8a9 --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-L @@ -0,0 +1,10 @@ +CONFIG_RCU_TRACE=3Dn +CONFIG_SMP=3Dy +CONFIG_NR_CPUS=3D6 +CONFIG_HOTPLUG_CPU=3Dy +CONFIG_PREEMPT_NONE=3Dy +CONFIG_PREEMPT_VOLUNTARY=3Dn +CONFIG_PREEMPT=3Dn +#CHECK#CONFIG_RCU_EXPERT=3Dn +CONFIG_KPROBES=3Dn +CONFIG_FTRACE=3Dn diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-L.boot b/t= ools/testing/selftests/rcutorture/configs/rcu/SRCU-L.boot new file mode 100644 index 0000000000000..0207b3138c5be --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-L.boot @@ -0,0 +1,3 @@ +rcutorture.torture_type=3Dsrcu +rcutorture.reader_flavor=3D0x4 +rcutorture.fwd_progress=3D3 diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot b/t= ools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot index ce0694fd9b929..b54cf87dc1103 100644 --- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot +++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot @@ -1,2 +1,3 @@ rcutorture.torture_type=3Dsrcu +rcutorture.reader_flavor=3D0x2 rcutorture.fwd_progress=3D3 diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE10 b/tools/= testing/selftests/rcutorture/configs/rcu/TREE10 index a323d8948b7cf..759ee51d3ddc6 100644 --- a/tools/testing/selftests/rcutorture/configs/rcu/TREE10 +++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE10 @@ -1,5 +1,5 @@ CONFIG_SMP=3Dy -CONFIG_NR_CPUS=3D56 +CONFIG_NR_CPUS=3D74 CONFIG_PREEMPT_NONE=3Dy CONFIG_PREEMPT_VOLUNTARY=3Dn CONFIG_PREEMPT=3Dn --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 EF88B1F76DD; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008675; cv=none; b=laFi3NAhqex4qZrQmPlCHD5vJs50+D8wcf/ailyez20TSKd5rb+ihtnJhG6sKvDGZxHN2PukdJAbFSDH60xX6jEM+y5efm+iTyE0gGO/rAFxIgQPbGT5tvWv7Ru2s0YiizIVtvHaWaKf5jFdVON00f0qNzxTdttH3/5sS92rpnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008675; c=relaxed/simple; bh=ShAY23PXWJnTwN9m3aELbGSryO452AQIXFVffiHUjJ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=edC1hSAa87U7INZi/fDo6Y9MX5TrkcdP2PGXdisj5iI/ePQW4TQqoXUFPjrL8l8nKT8prwzQqDkivl9A+xg8tsjOYYNS94t6LPJ8vex1jAfngaIbqGYS8vDH4fYqbdpKELKdGCzRstfvB8gWo2bCUAI8ISSZj5wji92m4NLPIPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JLTU9ovS; 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="JLTU9ovS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4B44C4CEF3; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=ShAY23PXWJnTwN9m3aELbGSryO452AQIXFVffiHUjJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JLTU9ovS7V5DQluJGRKqzRlmP20klBZWltdZIpdgvfxcg0+/eG4Cwaj0xEwHOUAtP /Ji4tT90mMEUhTGub0zGqCrKbSRtoU0ZcEkTlBPiwEUgJT3i7k+Q1uQK5hUmjME8AW a9+f43D+BOtWUeqpm3NgeL/Mj50NU6YTTGCwmXq4mz/vgAkDmNJvMlxQlNS60Rlg8k kW9uwTlFFSMXAy6/Xgx+GouyhP3baIHbf5FP6BUawXwrvTg+Q4AEwjLtCPi4H3evOx bjnrCixHk3GLKz0Si3mNEHHxCIswE1nf1dBxbRZ5TjMyKmSDrgDdce5q+4CCqW91Rg gVitZYy3/GhFA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D7376CE1FD6; Tue, 15 Oct 2024 09:11:13 -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" , Alexei Starovoitov , Andrii Nakryiko , Peter Zijlstra , Kent Overstreet , bpf@vger.kernel.org Subject: [PATCH rcu 14/15] refscale: Add srcu_read_lock_lite() support using "srcu-lite" Date: Tue, 15 Oct 2024 09:11:11 -0700 Message-Id: <20241015161112.442758-14-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 creates a new srcu-lite option for the refscale.scale_type module parameter that selects srcu_read_lock_lite() and srcu_read_unlock_lite(). Signed-off-by: Paul E. McKenney Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Kent Overstreet Cc: Reviewed-by: Neeraj Upadhyay --- kernel/rcu/refscale.c | 51 +++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index 0db9db73f57f2..09ee27ced2a78 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -212,6 +212,36 @@ static const struct ref_scale_ops srcu_ops =3D { .name =3D "srcu" }; =20 +static void srcu_lite_ref_scale_read_section(const int nloops) +{ + int i; + int idx; + + for (i =3D nloops; i >=3D 0; i--) { + idx =3D srcu_read_lock_lite(srcu_ctlp); + srcu_read_unlock_lite(srcu_ctlp, idx); + } +} + +static void srcu_lite_ref_scale_delay_section(const int nloops, const int = udl, const int ndl) +{ + int i; + int idx; + + for (i =3D nloops; i >=3D 0; i--) { + idx =3D srcu_read_lock_lite(srcu_ctlp); + un_delay(udl, ndl); + srcu_read_unlock_lite(srcu_ctlp, idx); + } +} + +static const struct ref_scale_ops srcu_lite_ops =3D { + .init =3D rcu_sync_scale_init, + .readsection =3D srcu_lite_ref_scale_read_section, + .delaysection =3D srcu_lite_ref_scale_delay_section, + .name =3D "srcu-lite" +}; + #ifdef CONFIG_TASKS_RCU =20 // Definitions for RCU Tasks ref scale testing: Empty read markers. @@ -1082,27 +1112,26 @@ ref_scale_init(void) long i; int firsterr =3D 0; static const struct ref_scale_ops *scale_ops[] =3D { - &rcu_ops, &srcu_ops, RCU_TRACE_OPS RCU_TASKS_OPS &refcnt_ops, &rwlock_op= s, - &rwsem_ops, &lock_ops, &lock_irq_ops, &acqrel_ops, &clock_ops, &jiffies_= ops, - &typesafe_ref_ops, &typesafe_lock_ops, &typesafe_seqlock_ops, + &rcu_ops, &srcu_ops, &srcu_lite_ops, RCU_TRACE_OPS RCU_TASKS_OPS + &refcnt_ops, &rwlock_ops, &rwsem_ops, &lock_ops, &lock_irq_ops, &acqrel_= ops, + &clock_ops, &jiffies_ops, &typesafe_ref_ops, &typesafe_lock_ops, + &typesafe_seqlock_ops, }; =20 if (!torture_init_begin(scale_type, verbose)) return -EBUSY; =20 for (i =3D 0; i < ARRAY_SIZE(scale_ops); i++) { - cur_ops =3D scale_ops[i]; - if (strcmp(scale_type, cur_ops->name) =3D=3D 0) + cur_ops =3D scale_ops[i]; if (strcmp(scale_type, + cur_ops->name) =3D=3D 0) break; } if (i =3D=3D ARRAY_SIZE(scale_ops)) { - pr_alert("rcu-scale: invalid scale type: \"%s\"\n", scale_type); - pr_alert("rcu-scale types:"); - for (i =3D 0; i < ARRAY_SIZE(scale_ops); i++) + pr_alert("rcu-scale: invalid scale type: \"%s\"\n", + scale_type); pr_alert("rcu-scale types:"); for (i =3D 0; + i < ARRAY_SIZE(scale_ops); i++) pr_cont(" %s", scale_ops[i]->name); - pr_cont("\n"); - firsterr =3D -EINVAL; - cur_ops =3D NULL; + pr_cont("\n"); firsterr =3D -EINVAL; cur_ops =3D NULL; goto unwind; } if (cur_ops->init) --=20 2.40.1 From nobody Tue Nov 26 22:25:30 2024 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 DBEBE1F76D4; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; cv=none; b=G7GHlnKUNu98+DqSfK+BXphz90nJRleJBSS1AC5vYPnVhTPpLLE8wJLVMkycpaKQ2sYqeTOMRJEEJoHTdZklIIgNaPuAEJDVRidNm/mkr9RGVNoi7ImGgn8jcqSyjwvuWtmYM2i+aE90Rm8ta9G+H0EiVqQZ+QSRuZJ90OJ5HqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729008674; c=relaxed/simple; bh=8e+zGyoW+Tm4spVSvH4fyTbGnotsozeYt2gapdOvycA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bTUzznG7Y2N70gaD+GEUqIUnLMG1Qu/tDVS6c6ApQ8D65iBxfhWFICJzHttCF8uZ+5Hk7QhooI4cxggNUZrgVBYT1e6AEChgyp52nEUeGUN1zRHWxNtG4btu/EgMuFF7iepQvDXrNBV9ZY2nygcPfPujtV3hox8/U+yVnBOHFBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZRM6b5VE; 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="ZRM6b5VE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4FA4C4CEF5; Tue, 15 Oct 2024 16:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729008674; bh=8e+zGyoW+Tm4spVSvH4fyTbGnotsozeYt2gapdOvycA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZRM6b5VE41ITBDvTkYCmQMVXY9O2L3EaJDoraUdCMbsxr75935KbL5NUm4YaAcdaL NtTXITYelbjm9+BgDAFQh37dC3zBcmoaFUWxpMClP2TFB49ySXqURLza1yTrcqF70I zkTIH9Z2TtdTpdOPLI13eFEF59lYJpP0azd6i9lF9iZZqYM2jjLwPdDLRMX5Br+61f n56YycBAU0rWwwkk6p+kVw++dvwMCM8p1m6f9DoPHvFzC/GkDH009ks7F1jbptIHvQ Mu+zsIOsZw4RAzvRJvB+yku4tLy3paGGnC8Ldz7aza9wjUAui+77chUtMraLUkkT9i 5H3+Ap5L3qEsg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D9AA9CE20E2; Tue, 15 Oct 2024 09:11:13 -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" , Andrii Nakryiko Subject: [PATCH rcu 15/15] srcu: Improve srcu_read_lock_lite() kernel-doc comment Date: Tue, 15 Oct 2024 09:11:12 -0700 Message-Id: <20241015161112.442758-15-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" Where RCU is watching is where it is OK to invoke rcu_read_lock(). Reported-by: Andrii Nakryiko Signed-off-by: Paul E. McKenney Acked-by: Andrii Nakryiko Reviewed-by: Neeraj Upadhyay --- include/linux/srcu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 4ba96e2cfa405..bab1dae3f69e6 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -270,7 +270,8 @@ static inline int srcu_read_lock(struct srcu_struct *ss= p) __acquires(ssp) * synchronize_rcu_expedited(), IPIs and all. * * Note that srcu_read_lock_lite() can be invoked only from those contexts - * where RCU is watching. Otherwise, lockdep will complain. + * where RCU is watching, that is, from contexts where it would be legal + * to invoke rcu_read_lock(). Otherwise, lockdep will complain. */ static inline int srcu_read_lock_lite(struct srcu_struct *ssp) __acquires(= ssp) { --=20 2.40.1