2023-01-12 21:52:25

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH 8/8] perf/core: Call perf_prepare_sample() before running BPF

As BPF can access sample data, it needs to populate the data. Also
remove the logic to get the callchain specifically as it's covered by
the perf_prepare_sample() now.

Cc: Song Liu <[email protected]>
Cc: [email protected]
Signed-off-by: Namhyung Kim <[email protected]>
---
kernel/events/core.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5c4f3fa3d2b7..af8365fb639a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10363,13 +10363,7 @@ static void bpf_overflow_handler(struct perf_event *event,
rcu_read_lock();
prog = READ_ONCE(event->prog);
if (prog) {
- if (prog->call_get_stack &&
- (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) &&
- !(data->sample_flags & PERF_SAMPLE_CALLCHAIN)) {
- data->callchain = perf_callchain(event, regs);
- data->sample_flags |= PERF_SAMPLE_CALLCHAIN;
- }
-
+ perf_prepare_sample(data, event, regs);
ret = bpf_prog_run(prog, &ctx);
}
rcu_read_unlock();
--
2.39.0.314.g84b9a713c41-goog


2023-01-13 21:11:46

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH 8/8] perf/core: Call perf_prepare_sample() before running BPF

On Thu, Jan 12, 2023 at 1:40 PM Namhyung Kim <[email protected]> wrote:
>
> As BPF can access sample data, it needs to populate the data. Also
> remove the logic to get the callchain specifically as it's covered by
> the perf_prepare_sample() now.
>
> Cc: Song Liu <[email protected]>
> Cc: [email protected]
> Signed-off-by: Namhyung Kim <[email protected]>

Acked-by: Song Liu <[email protected]>

> ---
> kernel/events/core.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 5c4f3fa3d2b7..af8365fb639a 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -10363,13 +10363,7 @@ static void bpf_overflow_handler(struct perf_event *event,
> rcu_read_lock();
> prog = READ_ONCE(event->prog);
> if (prog) {
> - if (prog->call_get_stack &&
> - (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) &&
> - !(data->sample_flags & PERF_SAMPLE_CALLCHAIN)) {
> - data->callchain = perf_callchain(event, regs);
> - data->sample_flags |= PERF_SAMPLE_CALLCHAIN;
> - }
> -
> + perf_prepare_sample(data, event, regs);
> ret = bpf_prog_run(prog, &ctx);
> }
> rcu_read_unlock();
> --
> 2.39.0.314.g84b9a713c41-goog
>