1430d97a8SAndrii Nakryiko // SPDX-License-Identifier: GPL-2.0 2430d97a8SAndrii Nakryiko /* Copyright (c) 2021 Facebook */ 3430d97a8SAndrii Nakryiko 4430d97a8SAndrii Nakryiko #include "vmlinux.h" 5430d97a8SAndrii Nakryiko #include <bpf/bpf_helpers.h> 6430d97a8SAndrii Nakryiko 7*c48e51c8SKumar Kartikeya Dwivedi #define X_0(x) 8*c48e51c8SKumar Kartikeya Dwivedi #define X_1(x) x X_0(x) 9*c48e51c8SKumar Kartikeya Dwivedi #define X_2(x) x X_1(x) 10*c48e51c8SKumar Kartikeya Dwivedi #define X_3(x) x X_2(x) 11*c48e51c8SKumar Kartikeya Dwivedi #define X_4(x) x X_3(x) 12*c48e51c8SKumar Kartikeya Dwivedi #define X_5(x) x X_4(x) 13*c48e51c8SKumar Kartikeya Dwivedi #define X_6(x) x X_5(x) 14*c48e51c8SKumar Kartikeya Dwivedi #define X_7(x) x X_6(x) 15*c48e51c8SKumar Kartikeya Dwivedi #define X_8(x) x X_7(x) 16*c48e51c8SKumar Kartikeya Dwivedi #define X_9(x) x X_8(x) 17*c48e51c8SKumar Kartikeya Dwivedi #define X_10(x) x X_9(x) 18*c48e51c8SKumar Kartikeya Dwivedi #define REPEAT_256(Y) X_2(X_10(X_10(Y))) X_5(X_10(Y)) X_6(Y) 19*c48e51c8SKumar Kartikeya Dwivedi 20430d97a8SAndrii Nakryiko extern const int bpf_testmod_ksym_percpu __ksym; 21*c48e51c8SKumar Kartikeya Dwivedi extern void bpf_testmod_test_mod_kfunc(int i) __ksym; 22*c48e51c8SKumar Kartikeya Dwivedi extern void bpf_testmod_invalid_mod_kfunc(void) __ksym __weak; 23430d97a8SAndrii Nakryiko 24*c48e51c8SKumar Kartikeya Dwivedi int out_bpf_testmod_ksym = 0; 25*c48e51c8SKumar Kartikeya Dwivedi const volatile int x = 0; 26430d97a8SAndrii Nakryiko 27*c48e51c8SKumar Kartikeya Dwivedi SEC("tc") load(struct __sk_buff * skb)28*c48e51c8SKumar Kartikeya Dwivediint load(struct __sk_buff *skb) 29430d97a8SAndrii Nakryiko { 30*c48e51c8SKumar Kartikeya Dwivedi /* This will be kept by clang, but removed by verifier. Since it is 31*c48e51c8SKumar Kartikeya Dwivedi * marked as __weak, libbpf and gen_loader don't error out if BTF ID 32*c48e51c8SKumar Kartikeya Dwivedi * is not found for it, instead imm and off is set to 0 for it. 33*c48e51c8SKumar Kartikeya Dwivedi */ 34*c48e51c8SKumar Kartikeya Dwivedi if (x) 35*c48e51c8SKumar Kartikeya Dwivedi bpf_testmod_invalid_mod_kfunc(); 36*c48e51c8SKumar Kartikeya Dwivedi bpf_testmod_test_mod_kfunc(42); 37*c48e51c8SKumar Kartikeya Dwivedi out_bpf_testmod_ksym = *(int *)bpf_this_cpu_ptr(&bpf_testmod_ksym_percpu); 38*c48e51c8SKumar Kartikeya Dwivedi return 0; 39*c48e51c8SKumar Kartikeya Dwivedi } 40430d97a8SAndrii Nakryiko 41*c48e51c8SKumar Kartikeya Dwivedi SEC("tc") load_256(struct __sk_buff * skb)42*c48e51c8SKumar Kartikeya Dwivediint load_256(struct __sk_buff *skb) 43*c48e51c8SKumar Kartikeya Dwivedi { 44*c48e51c8SKumar Kartikeya Dwivedi /* this will fail if kfunc doesn't reuse its own btf fd index */ 45*c48e51c8SKumar Kartikeya Dwivedi REPEAT_256(bpf_testmod_test_mod_kfunc(42);); 46*c48e51c8SKumar Kartikeya Dwivedi bpf_testmod_test_mod_kfunc(42); 47430d97a8SAndrii Nakryiko return 0; 48430d97a8SAndrii Nakryiko } 49430d97a8SAndrii Nakryiko 50430d97a8SAndrii Nakryiko char LICENSE[] SEC("license") = "GPL"; 51