Skip to content

Commit 24507ce

Browse files
anakryikorostedt
authored andcommitted
bpf: ensure RCU Tasks Trace GP for sleepable raw tracepoint BPF links
Now that kernel supports sleepable tracepoints, the fact that bpf_probe_unregister() is asynchronous, i.e., that it doesn't wait for any in-flight tracepoints to conclude before returning, we now need to delay BPF raw tp link's deallocation and bpf_prog_put() of its underlying BPF program (regardless of program's own sleepable semantics) until after full RCU Tasks Trace GP. With that GP over, we'll have a guarantee that no tracepoint can reach BPF link and thus its BPF program. We use newly added tracepoint_is_faultable() check to know when this RCU Tasks Trace GP is necessary and utilize BPF link's own sleepable flag passed through bpf_link_init_sleepable() initializer. Link: https://lore.kernel.org/20241101181754.782341-3-andrii@kernel.org Tested-by: Jordan Rife <jrife@google.com> Reported-by: Jordan Rife <jrife@google.com> Fixes: a363d27 ("tracing: Allow system call tracepoints to handle page faults") Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 61c6fef commit 24507ce

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kernel/bpf/syscall.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/rcupdate_trace.h>
3636
#include <linux/memcontrol.h>
3737
#include <linux/trace_events.h>
38+
#include <linux/tracepoint.h>
3839

3940
#include <net/netfilter/nf_bpf_link.h>
4041
#include <net/netkit.h>
@@ -3845,8 +3846,9 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog,
38453846
err = -ENOMEM;
38463847
goto out_put_btp;
38473848
}
3848-
bpf_link_init(&link->link, BPF_LINK_TYPE_RAW_TRACEPOINT,
3849-
&bpf_raw_tp_link_lops, prog);
3849+
bpf_link_init_sleepable(&link->link, BPF_LINK_TYPE_RAW_TRACEPOINT,
3850+
&bpf_raw_tp_link_lops, prog,
3851+
tracepoint_is_faultable(btp->tp));
38503852
link->btp = btp;
38513853
link->cookie = cookie;
38523854

0 commit comments

Comments
 (0)