public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, rostedt@goodmis.org,
	kernel test robot <oliver.sang@intel.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	bpf@vger.kernel.org
Subject: Re: [PATCH v2 02/21] rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast
Date: Thu, 2 Oct 2025 17:46:10 +0200	[thread overview]
Message-ID: <aN6eQuTbdwAAhxIj@localhost.localdomain> (raw)
In-Reply-To: <20251001144832.631770-2-paulmck@kernel.org>

Le Wed, Oct 01, 2025 at 07:48:13AM -0700, Paul E. McKenney a écrit :
> This commit saves more than 500 lines of RCU code by re-implementing
> RCU Tasks Trace in terms of SRCU-fast.  Follow-up work will remove
> more code that does not cause problems by its presence, but that is no
> longer required.
> 
> This variant places smp_mb() in rcu_read_{,un}lock_trace(), which will
> be removed on common-case architectures in a later commit.

The changelog doesn't mention what this is ordering :-)

> 
> [ paulmck: Apply kernel test robot, Boqun Feng, and Zqiang feedback. ]
> [ paulmck: Split out Tiny SRCU fixes per Andrii Nakryiko feedback. ]
> 
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Tested-by: kernel test robot <oliver.sang@intel.com>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: <bpf@vger.kernel.org>
> ---
[...]
> @@ -50,12 +50,14 @@ static inline void rcu_read_lock_trace(void)
>  {
>  	struct task_struct *t = current;
>  
> -	WRITE_ONCE(t->trc_reader_nesting, READ_ONCE(t->trc_reader_nesting) + 1);
> -	barrier();
> -	if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) &&
> -	    t->trc_reader_special.b.need_mb)
> -		smp_mb(); // Pairs with update-side barriers
> -	rcu_lock_acquire(&rcu_trace_lock_map);
> +	if (t->trc_reader_nesting++) {
> +		// In case we interrupted a Tasks Trace RCU reader.
> +		rcu_try_lock_acquire(&rcu_tasks_trace_srcu_struct.dep_map);
> +		return;
> +	}
> +	barrier();  // nesting before scp to protect against interrupt handler.
> +	t->trc_reader_scp = srcu_read_lock_fast(&rcu_tasks_trace_srcu_struct);
> +	smp_mb(); // Placeholder for more selective ordering

Mysterious :-)

>  }
>  
>  /**
> @@ -69,26 +71,75 @@ static inline void rcu_read_lock_trace(void)
>   */
>  static inline void rcu_read_unlock_trace(void)
>  {
> -	int nesting;
> +	struct srcu_ctr __percpu *scp;
>  	struct task_struct *t = current;
>  
> -	rcu_lock_release(&rcu_trace_lock_map);
> -	nesting = READ_ONCE(t->trc_reader_nesting) - 1;
> -	barrier(); // Critical section before disabling.
> -	// Disable IPI-based setting of .need_qs.
> -	WRITE_ONCE(t->trc_reader_nesting, INT_MIN + nesting);
> -	if (likely(!READ_ONCE(t->trc_reader_special.s)) || nesting) {
> -		WRITE_ONCE(t->trc_reader_nesting, nesting);
> -		return;  // We assume shallow reader nesting.
> -	}
> -	WARN_ON_ONCE(nesting != 0);
> -	rcu_read_unlock_trace_special(t);
> +	smp_mb(); // Placeholder for more selective ordering

Bizarre :-)

> +	scp = t->trc_reader_scp;
> +	barrier();  // scp before nesting to protect against interrupt handler.

What is it protecting against interrupt?

> +	if (!--t->trc_reader_nesting)
> +		srcu_read_unlock_fast(&rcu_tasks_trace_srcu_struct, scp);
> +	else
> +		srcu_lock_release(&rcu_tasks_trace_srcu_struct.dep_map);
> +}

Thanks (very happy to see all the rest of the code going away!)

-- 
Frederic Weisbecker
SUSE Labs

  reply	other threads:[~2025-10-02 15:46 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01 14:48 [PATCH v2 0/21] Implement RCU Tasks Trace in terms of SRCU-fast and optimize Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 01/21] srcu: Permit Tiny SRCU srcu_read_unlock() with interrupts disabled Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 02/21] rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast Paul E. McKenney
2025-10-02 15:46   ` Frederic Weisbecker [this message]
2025-10-04  9:47     ` Paul E. McKenney
2025-10-07 12:10       ` Frederic Weisbecker
2025-10-07 13:47         ` Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 03/21] context_tracking: Remove rcu_task_trace_heavyweight_{enter,exit}() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 04/21] rcu: Clean up after the SRCU-fastification of RCU Tasks Trace Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 05/21] rcu: Move rcu_tasks_trace_srcu_struct out of #ifdef CONFIG_TASKS_RCU_GENERIC Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 06/21] srcu: Create an srcu_expedite_current() function Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 07/21] rcutorture: Test srcu_expedite_current() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 08/21] rcu: Add noinstr-fast rcu_read_{,un}lock_tasks_trace() APIs Paul E. McKenney
2025-10-02  1:37   ` Alexei Starovoitov
2025-10-02 13:38     ` Paul E. McKenney
2025-10-02 15:56       ` Alexei Starovoitov
2025-10-03  8:07         ` Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 09/21] rcu: Update Requirements.rst for RCU Tasks Trace Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 10/21] checkpatch: Deprecate rcu_read_{,un}lock_trace() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 11/21] srcu: Create a DEFINE_SRCU_FAST() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 12/21] srcu: Create an rcu_tasks_trace_expedite_current() function Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 13/21] rcutorture: Test rcu_tasks_trace_expedite_current() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 14/21] srcu: Make grace-period determination use ssp->srcu_reader_flavor Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 15/21] rcutorture: Exercise DEFINE_STATIC_SRCU_FAST() and init_srcu_struct_fast() Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 16/21] refscale: " Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 17/21] srcu: Require special srcu_struct define/init for SRCU-fast readers Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 18/21] srcu: Make SRCU-fast readers enforce use of SRCU-fast definition/init Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 19/21] doc: Update for SRCU-fast definitions and initialization Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 20/21] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast Paul E. McKenney
2025-10-01 14:48 ` [PATCH v2 21/21] rcu: Mark diagnostic functions as notrace Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aN6eQuTbdwAAhxIj@localhost.localdomain \
    --to=frederic@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.sang@intel.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox