From: Peter Zijlstra <peterz@infradead.org>
To: Radoslaw Zielonek <radoslaw.zielonek@gmail.com>
Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org,
syzbot+72a43cdb78469f7fbad1@syzkaller.appspotmail.com
Subject: Re: [PATCH] perf callchain: Fix suspicious RCU usage in get_callchain_entry()
Date: Mon, 15 Jul 2024 12:47:19 +0200 [thread overview]
Message-ID: <20240715104719.GA14400@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240715102326.1910790-2-radoslaw.zielonek@gmail.com>
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?
> ---
> kernel/events/callchain.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> index 1273be84392c..a8af7cd50626 100644
> --- a/kernel/events/callchain.c
> +++ b/kernel/events/callchain.c
> @@ -11,6 +11,7 @@
> #include <linux/perf_event.h>
> #include <linux/slab.h>
> #include <linux/sched/task_stack.h>
> +#include <linux/rcupdate_trace.h>
>
> #include "internal.h"
>
> @@ -32,7 +33,7 @@ static inline size_t perf_callchain_entry__sizeof(void)
> static DEFINE_PER_CPU(int, callchain_recursion[PERF_NR_CONTEXTS]);
> static atomic_t nr_callchain_events;
> static DEFINE_MUTEX(callchain_mutex);
> -static struct callchain_cpus_entries *callchain_cpus_entries;
> +static struct callchain_cpus_entries __rcu *callchain_cpus_entries;
>
>
> __weak void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
> @@ -158,7 +159,13 @@ struct perf_callchain_entry *get_callchain_entry(int *rctx)
> if (*rctx == -1)
> return NULL;
>
> - entries = rcu_dereference(callchain_cpus_entries);
> + /*
> + * BPF locked rcu using rcu_read_lock_trace() in
> + * bpf_prog_test_run_syscall()
> + */
> + entries = rcu_dereference_check(callchain_cpus_entries,
> + rcu_read_lock_trace_held() ||
> + rcu_read_lock_held());
> if (!entries) {
> put_recursion_context(this_cpu_ptr(callchain_recursion), *rctx);
> return NULL;
> --
> 2.43.0
>
next prev parent reply other threads:[~2024-07-15 10:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 10:23 [PATCH] perf callchain: Fix suspicious RCU usage in get_callchain_entry() Radoslaw Zielonek
2024-07-15 10:47 ` Peter Zijlstra [this message]
2024-07-18 17:41 ` Andrii Nakryiko
2026-01-28 6:26 ` Qing Wang
2026-01-28 8:19 ` Tao Chen
2026-01-28 8:45 ` Qing Wang
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=20240715104719.GA14400@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=radoslaw.zielonek@gmail.com \
--cc=syzbot+72a43cdb78469f7fbad1@syzkaller.appspotmail.com \
/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