Re: [PATCH] perf callchain: Fix suspicious RCU usage in get_callchain_entry()

From: Andrii Nakryiko
Date: Thu Jul 18 2024 - 13:41:44 EST


On Mon, Jul 15, 2024 at 3:47 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Mon, Jul 15, 2024 at 12:23:27PM +0200, Radoslaw Zielonek wrote:
> > The rcu_dereference() is using rcu_read_lock_held() as a checker, but
> > BPF in bpf_prog_test_run_syscall() is using rcu_read_lock_trace() locker.
> > To fix this issue the proper checker has been used
> > (rcu_read_lock_trace_held() || rcu_read_lock_held())
>
> How does that fix it? release_callchain_buffers() does call_rcu(), not
> call_rcu_tracing().
>
> Does a normal RCU grace period fully imply an RCU-tracing grace period?

I don't think so, they are completely independent. So this change
doesn't seem correct. I think we should just ensure
rcu_read_lock()/rcu_read_unlock() before calling into perf_callchain
functionality.

Which is what I'm doing in [0]. Radoslaw, can you please help
validating if those changes are enough to fix this issue or we need to
do some more?

[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240709204245.3847811-10-andrii@xxxxxxxxxx/

>
> > ---
> > kernel/events/callchain.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >

[...]