On Wed, Oct 1, 2025 at 7:48 AM Paul E. McKenney <[email protected]> wrote:
>
> +static inline struct srcu_ctr __percpu *rcu_read_lock_tasks_trace(void)
> +{
> +       struct srcu_ctr __percpu *ret = 
> __srcu_read_lock_fast(&rcu_tasks_trace_srcu_struct);
> +
> +       rcu_try_lock_acquire(&rcu_tasks_trace_srcu_struct.dep_map);
> +       if (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))
> +               smp_mb(); // Provide ordering on noinstr-incomplete 
> architectures.
> +       return ret;
> +}

...

> @@ -50,14 +97,15 @@ static inline void rcu_read_lock_trace(void)
>  {
>         struct task_struct *t = current;
>
> +       rcu_try_lock_acquire(&rcu_tasks_trace_srcu_struct.dep_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
> +       t->trc_reader_scp = 
> __srcu_read_lock_fast(&rcu_tasks_trace_srcu_struct);
> +       if (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))
> +               smp_mb(); // Placeholder for more selective ordering
>  }

Since srcu_fast() __percpu pointers must be incremented/decremented
within the same task, should we expose "raw" rcu_read_lock_tasks_trace()
at all?
rcu_read_lock_trace() stashes that pointer within a task,
so implementation guarantees that unlock will happen within the same task,
while _tasks_trace() requires the user not to do stupid things.

I guess it's fine to have both versions and the amount of copy paste
seems justified, but I keep wondering.
Especially since _tasks_trace() needs more work on bpf trampoline
side to pass this pointer around from lock to unlock.
We can add extra 8 bytes to struct bpf_tramp_run_ctx and save it there,
but set/reset run_ctx operates on current anyway, so it's not clear
which version will be faster. I suspect _trace() will be good enough.
Especially since trc_reader_nesting is kinda an optimization.

Reply via email to