lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQLozKuSPMe4qUDxCV6pCSQ=rQNKy524K7R=uM5yTpLV0Q@mail.gmail.com>
Date: Wed, 1 Oct 2025 18:37:33 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: "Paul E. McKenney" <paulmck@...nel.org>
Cc: rcu@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>, 
	Kernel Team <kernel-team@...a.com>, Steven Rostedt <rostedt@...dmis.org>, 
	Andrii Nakryiko <andrii@...nel.org>, Alexei Starovoitov <ast@...nel.org>, 
	Peter Zijlstra <peterz@...radead.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH v2 08/21] rcu: Add noinstr-fast rcu_read_{,un}lock_tasks_trace()
 APIs

On Wed, Oct 1, 2025 at 7:48 AM Paul E. McKenney <paulmck@...nel.org> 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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ