Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add light skeleton test for kfunc detection.

Add light skeleton test for kfunc detection and denylist it for s390.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230321203854.3035-5-alexei.starovoitov@gmail.com

authored by

Alexei Starovoitov and committed by
Andrii Nakryiko
3b2ec214 708cdc57

+16
+1
tools/testing/selftests/bpf/DENYLIST.s390x
··· 11 11 iters/testmod_seq* # s390x doesn't support kfuncs in modules yet 12 12 kprobe_multi_bench_attach # bpf_program__attach_kprobe_multi_opts unexpected error: -95 13 13 kprobe_multi_test # relies on fentry 14 + ksyms_btf/weak_ksyms* # test_ksyms_weak__open_and_load unexpected error: -22 (kfunc) 14 15 ksyms_module # test_ksyms_module__open_and_load unexpected error: -9 (?) 15 16 ksyms_module_libbpf # JIT does not support calling kernel function (kfunc) 16 17 ksyms_module_lskel # test_ksyms_module_lskel__open_and_load unexpected error: -9 (?)
+15
tools/testing/selftests/bpf/progs/test_ksyms_weak.c
··· 20 20 /* test existing weak symbols can be resolved. */ 21 21 extern const struct rq runqueues __ksym __weak; /* typed */ 22 22 extern const void bpf_prog_active __ksym __weak; /* typeless */ 23 + struct task_struct *bpf_task_acquire(struct task_struct *p) __ksym __weak; 24 + void bpf_testmod_test_mod_kfunc(int i) __ksym __weak; 23 25 24 26 25 27 /* non-existent weak symbols. */ ··· 31 29 32 30 /* typed symbols, default to zero. */ 33 31 extern const int bpf_link_fops2 __ksym __weak; 32 + void invalid_kfunc(void) __ksym __weak; 34 33 35 34 SEC("raw_tp/sys_enter") 36 35 int pass_handler(const void *ctx) ··· 52 49 53 50 if (&bpf_link_fops2) /* can't happen */ 54 51 out__non_existent_typed = (__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0); 52 + 53 + if (!bpf_ksym_exists(bpf_task_acquire)) 54 + /* dead code won't be seen by the verifier */ 55 + bpf_task_acquire(0); 56 + 57 + if (!bpf_ksym_exists(bpf_testmod_test_mod_kfunc)) 58 + /* dead code won't be seen by the verifier */ 59 + bpf_testmod_test_mod_kfunc(0); 60 + 61 + if (bpf_ksym_exists(invalid_kfunc)) 62 + /* dead code won't be seen by the verifier */ 63 + invalid_kfunc(); 55 64 56 65 return 0; 57 66 }