1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ 3 4 #include <vmlinux.h> 5 #include <bpf/bpf_tracing.h> 6 #include "bpf_misc.h" 7 #include "../test_kmods/bpf_testmod.h" 8 #include "../test_kmods/bpf_testmod_kfunc.h" 9 10 char _license[] SEC("license") = "GPL"; 11 __kfunc_btf_root(void)12void __kfunc_btf_root(void) 13 { 14 bpf_kfunc_st_ops_inc10(NULL); 15 } 16 subprog(struct st_ops_args * args)17static __noinline __used int subprog(struct st_ops_args *args) 18 { 19 args->a += 1; 20 return args->a; 21 } 22 23 __success 24 /* prologue */ 25 __xlated("0: r8 = r1") 26 __xlated("1: r1 = 0") 27 __xlated("2: call kernel-function") 28 __xlated("3: if r0 != 0x0 goto pc+5") 29 __xlated("4: r6 = *(u64 *)(r8 +0)") 30 __xlated("5: r7 = *(u64 *)(r6 +0)") 31 __xlated("6: r7 += 1000") 32 __xlated("7: *(u64 *)(r6 +0) = r7") 33 __xlated("8: goto pc+2") 34 __xlated("9: r1 = r0") 35 __xlated("10: call kernel-function") 36 __xlated("11: r1 = r8") 37 /* save __u64 *ctx to stack */ 38 __xlated("12: *(u64 *)(r10 -8) = r1") 39 /* main prog */ 40 __xlated("13: r1 = *(u64 *)(r1 +0)") 41 __xlated("14: r6 = r1") 42 __xlated("15: call kernel-function") 43 __xlated("16: r1 = r6") 44 __xlated("17: call pc+") 45 /* epilogue */ 46 __xlated("18: r1 = 0") 47 __xlated("19: r6 = 0") 48 __xlated("20: call kernel-function") 49 __xlated("21: if r0 != 0x0 goto pc+6") 50 __xlated("22: r1 = *(u64 *)(r10 -8)") 51 __xlated("23: r1 = *(u64 *)(r1 +0)") 52 __xlated("24: r6 = *(u64 *)(r1 +0)") 53 __xlated("25: r6 += 10000") 54 __xlated("26: *(u64 *)(r1 +0) = r6") 55 __xlated("27: goto pc+2") 56 __xlated("28: r1 = r0") 57 __xlated("29: call kernel-function") 58 __xlated("30: r0 = r6") 59 __xlated("31: r0 *= 2") 60 __xlated("32: exit") 61 SEC("struct_ops/test_pro_epilogue") test_kfunc_pro_epilogue(void)62__naked int test_kfunc_pro_epilogue(void) 63 { 64 asm volatile ( 65 "r1 = *(u64 *)(r1 +0);" 66 "r6 = r1;" 67 "call %[bpf_kfunc_st_ops_inc10];" 68 "r1 = r6;" 69 "call subprog;" 70 "exit;" 71 : 72 : __imm(bpf_kfunc_st_ops_inc10) 73 : __clobber_all); 74 } 75 76 SEC("syscall") 77 __retval(22022) /* (PROLOGUE_A [1000] + KFUNC_INC10 + SUBPROG_A [1] + EPILOGUE_A [10000]) * 2 */ syscall_pro_epilogue(void * ctx)78int syscall_pro_epilogue(void *ctx) 79 { 80 struct st_ops_args args = {}; 81 82 return bpf_kfunc_st_ops_test_pro_epilogue(&args); 83 } 84 85 SEC(".struct_ops.link") 86 struct bpf_testmod_st_ops pro_epilogue_with_kfunc = { 87 .test_pro_epilogue = (void *)test_kfunc_pro_epilogue, 88 }; 89