Skip to content

Commit c4fcc7d

Browse files
khueyingomolnar
authored andcommitted
perf/bpf: Allow a BPF program to suppress all sample side effects
Returning zero from a BPF program attached to a perf event already suppresses any data output. Return early from __perf_event_overflow() in this case so it will also suppress event_limit accounting, SIGTRAP generation, and F_ASYNC signalling. Signed-off-by: Kyle Huey <khuey@kylehuey.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Song Liu <song@kernel.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20240412015019.7060-7-khuey@kylehuey.com
1 parent 76f6d58 commit c4fcc7d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

kernel/events/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9677,6 +9677,9 @@ static int __perf_event_overflow(struct perf_event *event,
96779677

96789678
ret = __perf_event_account_interrupt(event, throttle);
96799679

9680+
if (event->prog && !bpf_overflow_handler(event, data, regs))
9681+
return ret;
9682+
96809683
/*
96819684
* XXX event_limit might not quite work as expected on inherited
96829685
* events
@@ -9726,8 +9729,7 @@ static int __perf_event_overflow(struct perf_event *event,
97269729
irq_work_queue(&event->pending_irq);
97279730
}
97289731

9729-
if (!(event->prog && !bpf_overflow_handler(event, data, regs)))
9730-
READ_ONCE(event->overflow_handler)(event, data, regs);
9732+
READ_ONCE(event->overflow_handler)(event, data, regs);
97319733

97329734
if (*perf_event_fasync(event) && event->pending_kill) {
97339735
event->pending_wakeup = 1;

0 commit comments

Comments
 (0)