1 // SPDX-License-Identifier: GPL-2.0
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
6 #include "bpf_experimental.h"
9 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
10 int preempt_lock_missing_1(struct __sk_buff *ctx)
12 bpf_preempt_disable();
17 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
18 int preempt_lock_missing_2(struct __sk_buff *ctx)
20 bpf_preempt_disable();
21 bpf_preempt_disable();
26 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
27 int preempt_lock_missing_3(struct __sk_buff *ctx)
29 bpf_preempt_disable();
30 bpf_preempt_disable();
31 bpf_preempt_disable();
36 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
37 int preempt_lock_missing_3_minus_2(struct __sk_buff *ctx)
39 bpf_preempt_disable();
40 bpf_preempt_disable();
41 bpf_preempt_disable();
47 static __noinline void preempt_disable(void)
49 bpf_preempt_disable();
52 static __noinline void preempt_enable(void)
58 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
59 int preempt_lock_missing_1_subprog(struct __sk_buff *ctx)
66 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
67 int preempt_lock_missing_2_subprog(struct __sk_buff *ctx)
75 __failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
76 int preempt_lock_missing_2_minus_1_subprog(struct __sk_buff *ctx)
84 static __noinline void preempt_balance_subprog(void)
91 __success int preempt_balance(struct __sk_buff *ctx)
98 __success int preempt_balance_subprog_test(struct __sk_buff *ctx)
100 preempt_balance_subprog();
104 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
105 __failure __msg("sleepable helper bpf_copy_from_user#")
106 int preempt_sleepable_helper(void *ctx)
110 bpf_preempt_disable();
111 bpf_copy_from_user(&data, sizeof(data), NULL);
112 bpf_preempt_enable();
116 int __noinline preempt_global_subprog(void)
118 preempt_balance_subprog();
123 __failure __msg("global function calls are not allowed with preemption disabled")
124 int preempt_global_subprog_test(struct __sk_buff *ctx)
127 preempt_global_subprog();
132 char _license[] SEC("license") = "GPL";