Skip to contentSkip to conversation

bpf,perf: Fix perf_event_detach_bpf_prog error handling

PATCH Applied Jiri Olsa 2 participants 2 messages Oct 23, 2024

Subsystems (4)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH v2 1/1 bpf,perf: Fix perf_event_detach_bpf_prog error handling

Peter reported that perf_event_detach_bpf_prog might skip to release the bpf program for -ENOENT error from bpf_prog_array_copy.

This can't happen because bpf program is stored in perf event and is detached and released only when perf event is freed.

Let's drop the -ENOENT check and make sure the bpf program is released in any case.

Cc Sean Young <[email protected]>
Fixes 170a7e3ea070 ("bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not found")

---
v2 changes:
- drop the WARN_ON_ONCE check (Andrii, Sean)

 kernel/trace/bpf_trace.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/bpf_trace.c +0 -2
index 95b6b3b16bac..630b763e5240 100644
@@ -2216,8 +2216,6 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
 
 	old_array = bpf_event_rcu_dereference(event->tp_event->prog_array);
 	ret = bpf_prog_array_copy(old_array, event->prog, NULL, 0, &new_array);
-	if (ret == -ENOENT)
-		goto unlock;
 	if (ret < 0) {
 		bpf_prog_array_delete_safe(old_array, event->prog);
 	} else {
Signature · 1 line
2.46.2
#1 lore raw
This patch was applied to bpf/bpf.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Andrii Nakryiko <[email protected]>:

Quoted 10 lines · On Wed, 23 Oct 2024 22:03:52 +0200 you wrote:

Peter reported that perf_event_detach_bpf_prog might skip to release the bpf program for -ENOENT error from bpf_prog_array_copy.

This can't happen because bpf program is stored in perf event and is detached and released only when perf event is freed.

Let's drop the -ENOENT check and make sure the bpf program is released in any case.

[...]

Here is the summary with links:
- [PATCHv2,bpf] bpf,perf: Fix perf_event_detach_bpf_prog error handling

    https://git.kernel.org/bpf/bpf/c/0ee288e69d03

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html