linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events
@ 2024-08-13 15:17 Joe Damato
  2024-08-13 17:07 ` Andrii Nakryiko
  2024-08-13 17:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Joe Damato @ 2024-08-13 15:17 UTC (permalink / raw)
  To: linux-perf-users, linux-kernel, bpf
  Cc: peterz, andrii, mhiramat, olsajiri, me, Kyle Huey,
	Andrii Nakryiko, Joe Damato, stable

From: Kyle Huey <me@kylehuey.com>

The regressing commit is new in 6.10. It assumed that anytime event->prog
is set bpf_overflow_handler() should be invoked to execute the attached bpf
program. This assumption is false for tracing events, and as a result the
regressing commit broke bpftrace by invoking the bpf handler with garbage
inputs on overflow.

Prior to the regression the overflow handlers formed a chain (of length 0,
1, or 2) and perf_event_set_bpf_handler() (the !tracing case) added
bpf_overflow_handler() to that chain, while perf_event_attach_bpf_prog()
(the tracing case) did not. Both set event->prog. The chain of overflow
handlers was replaced by a single overflow handler slot and a fixed call to
bpf_overflow_handler() when appropriate. This modifies the condition there
to check event->prog->type == BPF_PROG_TYPE_PERF_EVENT, restoring the
previous behavior and fixing bpftrace.

Signed-off-by: Kyle Huey <khuey@kylehuey.com>
Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Reported-by: Joe Damato <jdamato@fastly.com>
Closes: https://lore.kernel.org/lkml/ZpFfocvyF3KHaSzF@LQ3V64L9R2/
Fixes: f11f10bfa1ca ("perf/bpf: Call BPF handler directly, not through overflow machinery")
Cc: stable@vger.kernel.org
Tested-by: Joe Damato <jdamato@fastly.com> # bpftrace
---
v2:
  - Update patch based on Andrii's suggestion
  - Update commit message

 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index aa3450bdc227..c973e3c11e03 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -9706,7 +9706,8 @@ static int __perf_event_overflow(struct perf_event *event,
 
 	ret = __perf_event_account_interrupt(event, throttle);
 
-	if (event->prog && !bpf_overflow_handler(event, data, regs))
+	if (event->prog && event->prog->type == BPF_PROG_TYPE_PERF_EVENT &&
+	    !bpf_overflow_handler(event, data, regs))
 		return ret;
 
 	/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events
  2024-08-13 15:17 [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events Joe Damato
@ 2024-08-13 17:07 ` Andrii Nakryiko
  2024-08-13 17:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2024-08-13 17:07 UTC (permalink / raw)
  To: Joe Damato
  Cc: linux-perf-users, linux-kernel, bpf, peterz, andrii, mhiramat,
	olsajiri, me, Kyle Huey, stable

On Tue, Aug 13, 2024 at 8:17 AM Joe Damato <jdamato@fastly.com> wrote:
>
> From: Kyle Huey <me@kylehuey.com>
>
> The regressing commit is new in 6.10. It assumed that anytime event->prog
> is set bpf_overflow_handler() should be invoked to execute the attached bpf
> program. This assumption is false for tracing events, and as a result the
> regressing commit broke bpftrace by invoking the bpf handler with garbage
> inputs on overflow.
>
> Prior to the regression the overflow handlers formed a chain (of length 0,
> 1, or 2) and perf_event_set_bpf_handler() (the !tracing case) added
> bpf_overflow_handler() to that chain, while perf_event_attach_bpf_prog()
> (the tracing case) did not. Both set event->prog. The chain of overflow
> handlers was replaced by a single overflow handler slot and a fixed call to
> bpf_overflow_handler() when appropriate. This modifies the condition there
> to check event->prog->type == BPF_PROG_TYPE_PERF_EVENT, restoring the
> previous behavior and fixing bpftrace.
>
> Signed-off-by: Kyle Huey <khuey@kylehuey.com>
> Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Reported-by: Joe Damato <jdamato@fastly.com>
> Closes: https://lore.kernel.org/lkml/ZpFfocvyF3KHaSzF@LQ3V64L9R2/
> Fixes: f11f10bfa1ca ("perf/bpf: Call BPF handler directly, not through overflow machinery")
> Cc: stable@vger.kernel.org
> Tested-by: Joe Damato <jdamato@fastly.com> # bpftrace
> ---
> v2:
>   - Update patch based on Andrii's suggestion
>   - Update commit message
>

LGTM, thanks.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  kernel/events/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index aa3450bdc227..c973e3c11e03 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -9706,7 +9706,8 @@ static int __perf_event_overflow(struct perf_event *event,
>
>         ret = __perf_event_account_interrupt(event, throttle);
>
> -       if (event->prog && !bpf_overflow_handler(event, data, regs))
> +       if (event->prog && event->prog->type == BPF_PROG_TYPE_PERF_EVENT &&
> +           !bpf_overflow_handler(event, data, regs))
>                 return ret;
>
>         /*
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events
  2024-08-13 15:17 [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events Joe Damato
  2024-08-13 17:07 ` Andrii Nakryiko
@ 2024-08-13 17:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-13 17:30 UTC (permalink / raw)
  To: Joe Damato
  Cc: linux-perf-users, linux-kernel, bpf, peterz, andrii, mhiramat,
	olsajiri, me, khuey, andrii.nakryiko, stable

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue, 13 Aug 2024 15:17:27 +0000 you wrote:
> From: Kyle Huey <me@kylehuey.com>
> 
> The regressing commit is new in 6.10. It assumed that anytime event->prog
> is set bpf_overflow_handler() should be invoked to execute the attached bpf
> program. This assumption is false for tracing events, and as a result the
> regressing commit broke bpftrace by invoking the bpf handler with garbage
> inputs on overflow.
> 
> [...]

Here is the summary with links:
  - [v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events
    https://git.kernel.org/bpf/bpf/c/100bff23818e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-13 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 15:17 [PATCH v2] perf/bpf: Don't call bpf_overflow_handler() for tracing events Joe Damato
2024-08-13 17:07 ` Andrii Nakryiko
2024-08-13 17:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).