* Re: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
From: kernel test robot @ 2026-02-21 3:00 UTC (permalink / raw)
To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: oe-kbuild-all, bpf, linux-trace-kernel, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, Menglong Dong,
Steven Rostedt
In-Reply-To: <20260220100649.628307-5-jolsa@kernel.org>
Hi Jiri,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiri-Olsa/ftrace-Add-ftrace_hash_count-function/20260220-181324
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20260220100649.628307-5-jolsa%40kernel.org
patch subject: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
config: riscv-randconfig-001-20260221 (https://download.01.org/0day-ci/archive/20260221/202602211023.EiuS4wkF-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260221/202602211023.EiuS4wkF-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602211023.EiuS4wkF-lkp@intel.com/
All errors (new ones prefixed by >>):
arch/riscv/net/bpf_jit_comp64.c: In function 'invoke_bpf_prog':
>> arch/riscv/net/bpf_jit_comp64.c:944:7: error: 'struct bpf_tramp_link' has no member named 'cookie'
if (l->cookie)
^~
arch/riscv/net/bpf_jit_comp64.c:945:65: error: 'struct bpf_tramp_link' has no member named 'cookie'
emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
^~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:999:30: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function 'invoke_bpf':
>> arch/riscv/net/bpf_jit_comp64.c:1005:20: error: dereferencing pointer to incomplete type 'struct bpf_tramp_links'
for (i = 0; i < tl->nr_links; i++) {
^~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:1024:14: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
struct bpf_tramp_links *tlinks,
^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function '__arch_prepare_bpf_trampoline':
>> arch/riscv/net/bpf_jit_comp64.c:1033:42: error: invalid use of undefined type 'struct bpf_tramp_links'
struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY];
^
arch/riscv/net/bpf_jit_comp64.c:1033:42: error: dereferencing pointer to incomplete type 'struct bpf_tramp_links'
arch/riscv/net/bpf_jit_comp64.c:1034:41: error: invalid use of undefined type 'struct bpf_tramp_links'
struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT];
^
arch/riscv/net/bpf_jit_comp64.c:1035:44: error: invalid use of undefined type 'struct bpf_tramp_links'
struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
^
arch/riscv/net/bpf_jit_comp64.c:1118:39: error: passing argument 1 of 'bpf_fsession_cookie_cnt' from incompatible pointer type [-Werror=incompatible-pointer-types]
cookie_cnt = bpf_fsession_cookie_cnt(tlinks);
^~~~~~
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
include/linux/bpf.h:2207:67: note: expected 'struct bpf_tramp_nodes *' but argument is of type 'struct bpf_tramp_links *'
static inline int bpf_fsession_cookie_cnt(struct bpf_tramp_nodes *nodes)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
arch/riscv/net/bpf_jit_comp64.c:1175:23: error: passing argument 1 of 'bpf_fsession_cnt' from incompatible pointer type [-Werror=incompatible-pointer-types]
if (bpf_fsession_cnt(tlinks)) {
^~~~~~
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
include/linux/bpf.h:2189:60: note: expected 'struct bpf_tramp_nodes *' but argument is of type 'struct bpf_tramp_links *'
static inline int bpf_fsession_cnt(struct bpf_tramp_nodes *nodes)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
arch/riscv/net/bpf_jit_comp64.c:1191:20: error: passing argument 1 of 'invoke_bpf' from incompatible pointer type [-Werror=incompatible-pointer-types]
ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
^~~~~~
arch/riscv/net/bpf_jit_comp64.c:999:47: note: expected 'struct bpf_tramp_links *' but argument is of type 'struct bpf_tramp_links *'
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
~~~~~~~~~~~~~~~~~~~~~~~~^~
arch/riscv/net/bpf_jit_comp64.c:1198:16: warning: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
^
arch/riscv/net/bpf_jit_comp64.c:1241:23: error: passing argument 1 of 'bpf_fsession_cnt' from incompatible pointer type [-Werror=incompatible-pointer-types]
if (bpf_fsession_cnt(tlinks))
^~~~~~
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
include/linux/bpf.h:2189:60: note: expected 'struct bpf_tramp_nodes *' but argument is of type 'struct bpf_tramp_links *'
static inline int bpf_fsession_cnt(struct bpf_tramp_nodes *nodes)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
arch/riscv/net/bpf_jit_comp64.c:1245:20: error: passing argument 1 of 'invoke_bpf' from incompatible pointer type [-Werror=incompatible-pointer-types]
ret = invoke_bpf(fexit, args_off, retval_off, run_ctx_off, func_meta_off,
^~~~~
arch/riscv/net/bpf_jit_comp64.c:999:47: note: expected 'struct bpf_tramp_links *' but argument is of type 'struct bpf_tramp_links *'
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
~~~~~~~~~~~~~~~~~~~~~~~~^~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:1308:16: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
struct bpf_tramp_links *tlinks, void *func_addr)
^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1307:5: error: conflicting types for 'arch_bpf_trampoline_size'
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
include/linux/bpf.h:1271:5: note: previous declaration of 'arch_bpf_trampoline_size' was here
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
^~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function 'arch_bpf_trampoline_size':
arch/riscv/net/bpf_jit_comp64.c:1317:46: error: passing argument 3 of '__arch_prepare_bpf_trampoline' from incompatible pointer type [-Werror=incompatible-pointer-types]
ret = __arch_prepare_bpf_trampoline(&im, m, tlinks, func_addr, flags, &ctx);
^~~~~~
arch/riscv/net/bpf_jit_comp64.c:1024:31: note: expected 'struct bpf_tramp_links *' but argument is of type 'struct bpf_tramp_links *'
struct bpf_tramp_links *tlinks,
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:1334:23: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
u32 flags, struct bpf_tramp_links *tlinks,
^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1332:5: error: conflicting types for 'arch_prepare_bpf_trampoline'
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
include/linux/bpf.h:1264:5: note: previous declaration of 'arch_prepare_bpf_trampoline' was here
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *image_end,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function 'arch_prepare_bpf_trampoline':
arch/riscv/net/bpf_jit_comp64.c:1349:45: error: passing argument 3 of '__arch_prepare_bpf_trampoline' from incompatible pointer type [-Werror=incompatible-pointer-types]
ret = __arch_prepare_bpf_trampoline(im, m, tlinks, func_addr, flags, &ctx);
^~~~~~
arch/riscv/net/bpf_jit_comp64.c:1024:31: note: expected 'struct bpf_tramp_links *' but argument is of type 'struct bpf_tramp_links *'
struct bpf_tramp_links *tlinks,
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
cc1: some warnings being treated as errors
vim +944 arch/riscv/net/bpf_jit_comp64.c
93fd420d71beed5 Menglong Dong 2026-02-08 936
49b5e77ae3e214a Pu Lehui 2023-02-15 937 static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_off,
49b5e77ae3e214a Pu Lehui 2023-02-15 938 int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
49b5e77ae3e214a Pu Lehui 2023-02-15 939 {
49b5e77ae3e214a Pu Lehui 2023-02-15 940 int ret, branch_off;
49b5e77ae3e214a Pu Lehui 2023-02-15 941 struct bpf_prog *p = l->link.prog;
49b5e77ae3e214a Pu Lehui 2023-02-15 942 int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
49b5e77ae3e214a Pu Lehui 2023-02-15 943
93fd420d71beed5 Menglong Dong 2026-02-08 @944 if (l->cookie)
93fd420d71beed5 Menglong Dong 2026-02-08 945 emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
93fd420d71beed5 Menglong Dong 2026-02-08 946 else
49b5e77ae3e214a Pu Lehui 2023-02-15 947 emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 948
49b5e77ae3e214a Pu Lehui 2023-02-15 949 /* arg1: prog */
49b5e77ae3e214a Pu Lehui 2023-02-15 950 emit_imm(RV_REG_A0, (const s64)p, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 951 /* arg2: &run_ctx */
49b5e77ae3e214a Pu Lehui 2023-02-15 952 emit_addi(RV_REG_A1, RV_REG_FP, -run_ctx_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 953 ret = emit_call((const u64)bpf_trampoline_enter(p), true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 954 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 955 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 956
10541b374aa05c8 Xu Kuohai 2024-04-16 957 /* store prog start time */
10541b374aa05c8 Xu Kuohai 2024-04-16 958 emit_mv(RV_REG_S1, RV_REG_A0, ctx);
10541b374aa05c8 Xu Kuohai 2024-04-16 959
49b5e77ae3e214a Pu Lehui 2023-02-15 960 /* if (__bpf_prog_enter(prog) == 0)
49b5e77ae3e214a Pu Lehui 2023-02-15 961 * goto skip_exec_of_prog;
49b5e77ae3e214a Pu Lehui 2023-02-15 962 */
49b5e77ae3e214a Pu Lehui 2023-02-15 963 branch_off = ctx->ninsns;
49b5e77ae3e214a Pu Lehui 2023-02-15 964 /* nop reserved for conditional jump */
49b5e77ae3e214a Pu Lehui 2023-02-15 965 emit(rv_nop(), ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 966
49b5e77ae3e214a Pu Lehui 2023-02-15 967 /* arg1: &args_off */
49b5e77ae3e214a Pu Lehui 2023-02-15 968 emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 969 if (!p->jited)
49b5e77ae3e214a Pu Lehui 2023-02-15 970 /* arg2: progs[i]->insnsi for interpreter */
49b5e77ae3e214a Pu Lehui 2023-02-15 971 emit_imm(RV_REG_A1, (const s64)p->insnsi, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 972 ret = emit_call((const u64)p->bpf_func, true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 973 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 974 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 975
7112cd26e606c7b Björn Töpel 2023-10-04 976 if (save_ret) {
7112cd26e606c7b Björn Töpel 2023-10-04 977 emit_sd(RV_REG_FP, -retval_off, RV_REG_A0, ctx);
7112cd26e606c7b Björn Töpel 2023-10-04 978 emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx);
7112cd26e606c7b Björn Töpel 2023-10-04 979 }
49b5e77ae3e214a Pu Lehui 2023-02-15 980
49b5e77ae3e214a Pu Lehui 2023-02-15 981 /* update branch with beqz */
49b5e77ae3e214a Pu Lehui 2023-02-15 982 if (ctx->insns) {
49b5e77ae3e214a Pu Lehui 2023-02-15 983 int offset = ninsns_rvoff(ctx->ninsns - branch_off);
49b5e77ae3e214a Pu Lehui 2023-02-15 984 u32 insn = rv_beq(RV_REG_A0, RV_REG_ZERO, offset >> 1);
49b5e77ae3e214a Pu Lehui 2023-02-15 985 *(u32 *)(ctx->insns + branch_off) = insn;
49b5e77ae3e214a Pu Lehui 2023-02-15 986 }
49b5e77ae3e214a Pu Lehui 2023-02-15 987
49b5e77ae3e214a Pu Lehui 2023-02-15 988 /* arg1: prog */
49b5e77ae3e214a Pu Lehui 2023-02-15 989 emit_imm(RV_REG_A0, (const s64)p, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 990 /* arg2: prog start time */
49b5e77ae3e214a Pu Lehui 2023-02-15 991 emit_mv(RV_REG_A1, RV_REG_S1, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 992 /* arg3: &run_ctx */
49b5e77ae3e214a Pu Lehui 2023-02-15 993 emit_addi(RV_REG_A2, RV_REG_FP, -run_ctx_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 994 ret = emit_call((const u64)bpf_trampoline_exit(p), true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 995
49b5e77ae3e214a Pu Lehui 2023-02-15 996 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 997 }
49b5e77ae3e214a Pu Lehui 2023-02-15 998
35b3515be0ecb9d Menglong Dong 2026-02-08 999 static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
35b3515be0ecb9d Menglong Dong 2026-02-08 1000 int run_ctx_off, int func_meta_off, bool save_ret, u64 func_meta,
35b3515be0ecb9d Menglong Dong 2026-02-08 1001 int cookie_off, struct rv_jit_context *ctx)
35b3515be0ecb9d Menglong Dong 2026-02-08 1002 {
35b3515be0ecb9d Menglong Dong 2026-02-08 1003 int i, cur_cookie = (cookie_off - args_off) / 8;
35b3515be0ecb9d Menglong Dong 2026-02-08 1004
35b3515be0ecb9d Menglong Dong 2026-02-08 @1005 for (i = 0; i < tl->nr_links; i++) {
35b3515be0ecb9d Menglong Dong 2026-02-08 1006 int err;
35b3515be0ecb9d Menglong Dong 2026-02-08 1007
35b3515be0ecb9d Menglong Dong 2026-02-08 1008 if (bpf_prog_calls_session_cookie(tl->links[i])) {
35b3515be0ecb9d Menglong Dong 2026-02-08 1009 u64 meta = func_meta | ((u64)cur_cookie << BPF_TRAMP_COOKIE_INDEX_SHIFT);
35b3515be0ecb9d Menglong Dong 2026-02-08 1010
35b3515be0ecb9d Menglong Dong 2026-02-08 1011 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, meta, ctx);
35b3515be0ecb9d Menglong Dong 2026-02-08 1012 cur_cookie--;
35b3515be0ecb9d Menglong Dong 2026-02-08 1013 }
35b3515be0ecb9d Menglong Dong 2026-02-08 1014 err = invoke_bpf_prog(tl->links[i], args_off, retval_off, run_ctx_off,
35b3515be0ecb9d Menglong Dong 2026-02-08 1015 save_ret, ctx);
35b3515be0ecb9d Menglong Dong 2026-02-08 1016 if (err)
35b3515be0ecb9d Menglong Dong 2026-02-08 1017 return err;
35b3515be0ecb9d Menglong Dong 2026-02-08 1018 }
35b3515be0ecb9d Menglong Dong 2026-02-08 1019 return 0;
35b3515be0ecb9d Menglong Dong 2026-02-08 1020 }
35b3515be0ecb9d Menglong Dong 2026-02-08 1021
49b5e77ae3e214a Pu Lehui 2023-02-15 1022 static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
49b5e77ae3e214a Pu Lehui 2023-02-15 1023 const struct btf_func_model *m,
49b5e77ae3e214a Pu Lehui 2023-02-15 1024 struct bpf_tramp_links *tlinks,
49b5e77ae3e214a Pu Lehui 2023-02-15 1025 void *func_addr, u32 flags,
49b5e77ae3e214a Pu Lehui 2023-02-15 1026 struct rv_jit_context *ctx)
49b5e77ae3e214a Pu Lehui 2023-02-15 1027 {
49b5e77ae3e214a Pu Lehui 2023-02-15 1028 int i, ret, offset;
49b5e77ae3e214a Pu Lehui 2023-02-15 1029 int *branches_off = NULL;
6801b0aef79db47 Pu Lehui 2024-07-02 1030 int stack_size = 0, nr_arg_slots = 0;
35b3515be0ecb9d Menglong Dong 2026-02-08 1031 int retval_off, args_off, func_meta_off, ip_off, run_ctx_off, sreg_off, stk_arg_off;
35b3515be0ecb9d Menglong Dong 2026-02-08 1032 int cookie_off, cookie_cnt;
49b5e77ae3e214a Pu Lehui 2023-02-15 @1033 struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY];
49b5e77ae3e214a Pu Lehui 2023-02-15 1034 struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT];
49b5e77ae3e214a Pu Lehui 2023-02-15 1035 struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
1732ebc4a26181c Pu Lehui 2024-01-23 1036 bool is_struct_ops = flags & BPF_TRAMP_F_INDIRECT;
49b5e77ae3e214a Pu Lehui 2023-02-15 1037 void *orig_call = func_addr;
49b5e77ae3e214a Pu Lehui 2023-02-15 1038 bool save_ret;
35b3515be0ecb9d Menglong Dong 2026-02-08 1039 u64 func_meta;
49b5e77ae3e214a Pu Lehui 2023-02-15 1040 u32 insn;
49b5e77ae3e214a Pu Lehui 2023-02-15 1041
25ad10658dc1068 Pu Lehui 2023-07-21 1042 /* Two types of generated trampoline stack layout:
25ad10658dc1068 Pu Lehui 2023-07-21 1043 *
25ad10658dc1068 Pu Lehui 2023-07-21 1044 * 1. trampoline called from function entry
25ad10658dc1068 Pu Lehui 2023-07-21 1045 * --------------------------------------
25ad10658dc1068 Pu Lehui 2023-07-21 1046 * FP + 8 [ RA to parent func ] return address to parent
25ad10658dc1068 Pu Lehui 2023-07-21 1047 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1048 * FP + 0 [ FP of parent func ] frame pointer of parent
25ad10658dc1068 Pu Lehui 2023-07-21 1049 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1050 * FP - 8 [ T0 to traced func ] return address of traced
25ad10658dc1068 Pu Lehui 2023-07-21 1051 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1052 * FP - 16 [ FP of traced func ] frame pointer of traced
25ad10658dc1068 Pu Lehui 2023-07-21 1053 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1054 * --------------------------------------
49b5e77ae3e214a Pu Lehui 2023-02-15 1055 *
25ad10658dc1068 Pu Lehui 2023-07-21 1056 * 2. trampoline called directly
25ad10658dc1068 Pu Lehui 2023-07-21 1057 * --------------------------------------
25ad10658dc1068 Pu Lehui 2023-07-21 1058 * FP - 8 [ RA to caller func ] return address to caller
49b5e77ae3e214a Pu Lehui 2023-02-15 1059 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1060 * FP - 16 [ FP of caller func ] frame pointer of caller
49b5e77ae3e214a Pu Lehui 2023-02-15 1061 * function
25ad10658dc1068 Pu Lehui 2023-07-21 1062 * --------------------------------------
49b5e77ae3e214a Pu Lehui 2023-02-15 1063 *
49b5e77ae3e214a Pu Lehui 2023-02-15 1064 * FP - retval_off [ return value ] BPF_TRAMP_F_CALL_ORIG or
49b5e77ae3e214a Pu Lehui 2023-02-15 1065 * BPF_TRAMP_F_RET_FENTRY_RET
49b5e77ae3e214a Pu Lehui 2023-02-15 1066 * [ argN ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1067 * [ ... ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1068 * FP - args_off [ arg1 ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1069 *
35b3515be0ecb9d Menglong Dong 2026-02-08 1070 * FP - func_meta_off [ regs count, etc ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1071 *
49b5e77ae3e214a Pu Lehui 2023-02-15 1072 * FP - ip_off [ traced func ] BPF_TRAMP_F_IP_ARG
49b5e77ae3e214a Pu Lehui 2023-02-15 1073 *
35b3515be0ecb9d Menglong Dong 2026-02-08 1074 * [ stack cookie N ]
35b3515be0ecb9d Menglong Dong 2026-02-08 1075 * [ ... ]
35b3515be0ecb9d Menglong Dong 2026-02-08 1076 * FP - cookie_off [ stack cookie 1 ]
35b3515be0ecb9d Menglong Dong 2026-02-08 1077 *
49b5e77ae3e214a Pu Lehui 2023-02-15 1078 * FP - run_ctx_off [ bpf_tramp_run_ctx ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1079 *
49b5e77ae3e214a Pu Lehui 2023-02-15 1080 * FP - sreg_off [ callee saved reg ]
49b5e77ae3e214a Pu Lehui 2023-02-15 1081 *
49b5e77ae3e214a Pu Lehui 2023-02-15 1082 * [ pads ] pads for 16 bytes alignment
6801b0aef79db47 Pu Lehui 2024-07-02 1083 *
6801b0aef79db47 Pu Lehui 2024-07-02 1084 * [ stack_argN ]
6801b0aef79db47 Pu Lehui 2024-07-02 1085 * [ ... ]
6801b0aef79db47 Pu Lehui 2024-07-02 1086 * FP - stk_arg_off [ stack_arg1 ] BPF_TRAMP_F_CALL_ORIG
49b5e77ae3e214a Pu Lehui 2023-02-15 1087 */
49b5e77ae3e214a Pu Lehui 2023-02-15 1088
49b5e77ae3e214a Pu Lehui 2023-02-15 1089 if (flags & (BPF_TRAMP_F_ORIG_STACK | BPF_TRAMP_F_SHARE_IPMODIFY))
49b5e77ae3e214a Pu Lehui 2023-02-15 1090 return -ENOTSUPP;
49b5e77ae3e214a Pu Lehui 2023-02-15 1091
6801b0aef79db47 Pu Lehui 2024-07-02 1092 if (m->nr_args > MAX_BPF_FUNC_ARGS)
49b5e77ae3e214a Pu Lehui 2023-02-15 1093 return -ENOTSUPP;
49b5e77ae3e214a Pu Lehui 2023-02-15 1094
6801b0aef79db47 Pu Lehui 2024-07-02 1095 for (i = 0; i < m->nr_args; i++)
6801b0aef79db47 Pu Lehui 2024-07-02 1096 nr_arg_slots += round_up(m->arg_size[i], 8) / 8;
6801b0aef79db47 Pu Lehui 2024-07-02 1097
25ad10658dc1068 Pu Lehui 2023-07-21 1098 /* room of trampoline frame to store return address and frame pointer */
25ad10658dc1068 Pu Lehui 2023-07-21 1099 stack_size += 16;
49b5e77ae3e214a Pu Lehui 2023-02-15 1100
49b5e77ae3e214a Pu Lehui 2023-02-15 1101 save_ret = flags & (BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_RET_FENTRY_RET);
d0bf7cd5df18466 Chenghao Duan 2025-09-22 1102 if (save_ret)
7112cd26e606c7b Björn Töpel 2023-10-04 1103 stack_size += 16; /* Save both A5 (BPF R0) and A0 */
49b5e77ae3e214a Pu Lehui 2023-02-15 1104 retval_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1105
6801b0aef79db47 Pu Lehui 2024-07-02 1106 stack_size += nr_arg_slots * 8;
49b5e77ae3e214a Pu Lehui 2023-02-15 1107 args_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1108
35b3515be0ecb9d Menglong Dong 2026-02-08 1109 /* function metadata, such as regs count */
49b5e77ae3e214a Pu Lehui 2023-02-15 1110 stack_size += 8;
35b3515be0ecb9d Menglong Dong 2026-02-08 1111 func_meta_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1112
49b5e77ae3e214a Pu Lehui 2023-02-15 1113 if (flags & BPF_TRAMP_F_IP_ARG) {
49b5e77ae3e214a Pu Lehui 2023-02-15 1114 stack_size += 8;
49b5e77ae3e214a Pu Lehui 2023-02-15 1115 ip_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1116 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1117
35b3515be0ecb9d Menglong Dong 2026-02-08 1118 cookie_cnt = bpf_fsession_cookie_cnt(tlinks);
35b3515be0ecb9d Menglong Dong 2026-02-08 1119 /* room for session cookies */
35b3515be0ecb9d Menglong Dong 2026-02-08 1120 stack_size += cookie_cnt * 8;
35b3515be0ecb9d Menglong Dong 2026-02-08 1121 cookie_off = stack_size;
35b3515be0ecb9d Menglong Dong 2026-02-08 1122
49b5e77ae3e214a Pu Lehui 2023-02-15 1123 stack_size += round_up(sizeof(struct bpf_tramp_run_ctx), 8);
49b5e77ae3e214a Pu Lehui 2023-02-15 1124 run_ctx_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1125
49b5e77ae3e214a Pu Lehui 2023-02-15 1126 stack_size += 8;
49b5e77ae3e214a Pu Lehui 2023-02-15 1127 sreg_off = stack_size;
49b5e77ae3e214a Pu Lehui 2023-02-15 1128
a5912c37faf723c Puranjay Mohan 2024-07-08 1129 if ((flags & BPF_TRAMP_F_CALL_ORIG) && (nr_arg_slots - RV_MAX_REG_ARGS > 0))
6801b0aef79db47 Pu Lehui 2024-07-02 1130 stack_size += (nr_arg_slots - RV_MAX_REG_ARGS) * 8;
6801b0aef79db47 Pu Lehui 2024-07-02 1131
e944fc8152744a4 Xiao Wang 2024-05-23 1132 stack_size = round_up(stack_size, STACK_ALIGN);
49b5e77ae3e214a Pu Lehui 2023-02-15 1133
6801b0aef79db47 Pu Lehui 2024-07-02 1134 /* room for args on stack must be at the top of stack */
6801b0aef79db47 Pu Lehui 2024-07-02 1135 stk_arg_off = stack_size;
6801b0aef79db47 Pu Lehui 2024-07-02 1136
1732ebc4a26181c Pu Lehui 2024-01-23 1137 if (!is_struct_ops) {
25ad10658dc1068 Pu Lehui 2023-07-21 1138 /* For the trampoline called from function entry,
25ad10658dc1068 Pu Lehui 2023-07-21 1139 * the frame of traced function and the frame of
25ad10658dc1068 Pu Lehui 2023-07-21 1140 * trampoline need to be considered.
25ad10658dc1068 Pu Lehui 2023-07-21 1141 */
25ad10658dc1068 Pu Lehui 2023-07-21 1142 emit_addi(RV_REG_SP, RV_REG_SP, -16, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1143 emit_sd(RV_REG_SP, 8, RV_REG_RA, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1144 emit_sd(RV_REG_SP, 0, RV_REG_FP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1145 emit_addi(RV_REG_FP, RV_REG_SP, 16, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1146
25ad10658dc1068 Pu Lehui 2023-07-21 1147 emit_addi(RV_REG_SP, RV_REG_SP, -stack_size, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1148 emit_sd(RV_REG_SP, stack_size - 8, RV_REG_T0, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1149 emit_sd(RV_REG_SP, stack_size - 16, RV_REG_FP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1150 emit_addi(RV_REG_FP, RV_REG_SP, stack_size, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1151 } else {
e63985ecd22681c Puranjay Mohan 2024-03-03 1152 /* emit kcfi hash */
e63985ecd22681c Puranjay Mohan 2024-03-03 1153 emit_kcfi(cfi_get_func_hash(func_addr), ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1154 /* For the trampoline called directly, just handle
25ad10658dc1068 Pu Lehui 2023-07-21 1155 * the frame of trampoline.
25ad10658dc1068 Pu Lehui 2023-07-21 1156 */
25ad10658dc1068 Pu Lehui 2023-07-21 1157 emit_addi(RV_REG_SP, RV_REG_SP, -stack_size, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1158 emit_sd(RV_REG_SP, stack_size - 8, RV_REG_RA, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1159 emit_sd(RV_REG_SP, stack_size - 16, RV_REG_FP, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1160 emit_addi(RV_REG_FP, RV_REG_SP, stack_size, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1161 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1162
49b5e77ae3e214a Pu Lehui 2023-02-15 1163 /* callee saved register S1 to pass start time */
49b5e77ae3e214a Pu Lehui 2023-02-15 1164 emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1165
49b5e77ae3e214a Pu Lehui 2023-02-15 1166 /* store ip address of the traced function */
93fd420d71beed5 Menglong Dong 2026-02-08 1167 if (flags & BPF_TRAMP_F_IP_ARG)
93fd420d71beed5 Menglong Dong 2026-02-08 1168 emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1169
35b3515be0ecb9d Menglong Dong 2026-02-08 1170 func_meta = nr_arg_slots;
35b3515be0ecb9d Menglong Dong 2026-02-08 1171 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1172
6801b0aef79db47 Pu Lehui 2024-07-02 1173 store_args(nr_arg_slots, args_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1174
35b3515be0ecb9d Menglong Dong 2026-02-08 1175 if (bpf_fsession_cnt(tlinks)) {
35b3515be0ecb9d Menglong Dong 2026-02-08 1176 /* clear all session cookies' value */
35b3515be0ecb9d Menglong Dong 2026-02-08 1177 for (i = 0; i < cookie_cnt; i++)
35b3515be0ecb9d Menglong Dong 2026-02-08 1178 emit_sd(RV_REG_FP, -cookie_off + 8 * i, RV_REG_ZERO, ctx);
35b3515be0ecb9d Menglong Dong 2026-02-08 1179 /* clear return value to make sure fentry always get 0 */
35b3515be0ecb9d Menglong Dong 2026-02-08 1180 emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx);
35b3515be0ecb9d Menglong Dong 2026-02-08 1181 }
35b3515be0ecb9d Menglong Dong 2026-02-08 1182
49b5e77ae3e214a Pu Lehui 2023-02-15 1183 if (flags & BPF_TRAMP_F_CALL_ORIG) {
9f1e16fb1fc9826 Pu Lehui 2024-06-22 1184 emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1185 ret = emit_call((const u64)__bpf_tramp_enter, true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1186 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1187 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 1188 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1189
35b3515be0ecb9d Menglong Dong 2026-02-08 1190 if (fentry->nr_links) {
35b3515be0ecb9d Menglong Dong 2026-02-08 1191 ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
35b3515be0ecb9d Menglong Dong 2026-02-08 1192 flags & BPF_TRAMP_F_RET_FENTRY_RET, func_meta, cookie_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1193 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1194 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 1195 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1196
49b5e77ae3e214a Pu Lehui 2023-02-15 1197 if (fmod_ret->nr_links) {
49b5e77ae3e214a Pu Lehui 2023-02-15 1198 branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
49b5e77ae3e214a Pu Lehui 2023-02-15 1199 if (!branches_off)
49b5e77ae3e214a Pu Lehui 2023-02-15 1200 return -ENOMEM;
49b5e77ae3e214a Pu Lehui 2023-02-15 1201
49b5e77ae3e214a Pu Lehui 2023-02-15 1202 /* cleanup to avoid garbage return value confusion */
49b5e77ae3e214a Pu Lehui 2023-02-15 1203 emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1204 for (i = 0; i < fmod_ret->nr_links; i++) {
49b5e77ae3e214a Pu Lehui 2023-02-15 1205 ret = invoke_bpf_prog(fmod_ret->links[i], args_off, retval_off,
49b5e77ae3e214a Pu Lehui 2023-02-15 1206 run_ctx_off, true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1207 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1208 goto out;
49b5e77ae3e214a Pu Lehui 2023-02-15 1209 emit_ld(RV_REG_T1, -retval_off, RV_REG_FP, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1210 branches_off[i] = ctx->ninsns;
49b5e77ae3e214a Pu Lehui 2023-02-15 1211 /* nop reserved for conditional jump */
49b5e77ae3e214a Pu Lehui 2023-02-15 1212 emit(rv_nop(), ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1213 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1214 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1215
49b5e77ae3e214a Pu Lehui 2023-02-15 1216 if (flags & BPF_TRAMP_F_CALL_ORIG) {
8f3e00af8e52c0d Menglong Dong 2025-12-19 1217 /* skip to actual body of traced function */
8f3e00af8e52c0d Menglong Dong 2025-12-19 1218 orig_call += RV_FENTRY_NINSNS * 4;
6801b0aef79db47 Pu Lehui 2024-07-02 1219 restore_args(min_t(int, nr_arg_slots, RV_MAX_REG_ARGS), args_off, ctx);
6801b0aef79db47 Pu Lehui 2024-07-02 1220 restore_stack_args(nr_arg_slots - RV_MAX_REG_ARGS, args_off, stk_arg_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1221 ret = emit_call((const u64)orig_call, true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1222 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1223 goto out;
49b5e77ae3e214a Pu Lehui 2023-02-15 1224 emit_sd(RV_REG_FP, -retval_off, RV_REG_A0, ctx);
7112cd26e606c7b Björn Töpel 2023-10-04 1225 emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx);
2382a405c581ae8 Pu Lehui 2024-06-22 1226 im->ip_after_call = ctx->ro_insns + ctx->ninsns;
49b5e77ae3e214a Pu Lehui 2023-02-15 1227 /* 2 nops reserved for auipc+jalr pair */
49b5e77ae3e214a Pu Lehui 2023-02-15 1228 emit(rv_nop(), ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1229 emit(rv_nop(), ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1230 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1231
49b5e77ae3e214a Pu Lehui 2023-02-15 1232 /* update branches saved in invoke_bpf_mod_ret with bnez */
49b5e77ae3e214a Pu Lehui 2023-02-15 1233 for (i = 0; ctx->insns && i < fmod_ret->nr_links; i++) {
49b5e77ae3e214a Pu Lehui 2023-02-15 1234 offset = ninsns_rvoff(ctx->ninsns - branches_off[i]);
49b5e77ae3e214a Pu Lehui 2023-02-15 1235 insn = rv_bne(RV_REG_T1, RV_REG_ZERO, offset >> 1);
49b5e77ae3e214a Pu Lehui 2023-02-15 1236 *(u32 *)(ctx->insns + branches_off[i]) = insn;
49b5e77ae3e214a Pu Lehui 2023-02-15 1237 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1238
35b3515be0ecb9d Menglong Dong 2026-02-08 1239 /* set "is_return" flag for fsession */
35b3515be0ecb9d Menglong Dong 2026-02-08 1240 func_meta |= (1ULL << BPF_TRAMP_IS_RETURN_SHIFT);
35b3515be0ecb9d Menglong Dong 2026-02-08 1241 if (bpf_fsession_cnt(tlinks))
35b3515be0ecb9d Menglong Dong 2026-02-08 1242 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
35b3515be0ecb9d Menglong Dong 2026-02-08 1243
35b3515be0ecb9d Menglong Dong 2026-02-08 1244 if (fexit->nr_links) {
35b3515be0ecb9d Menglong Dong 2026-02-08 1245 ret = invoke_bpf(fexit, args_off, retval_off, run_ctx_off, func_meta_off,
35b3515be0ecb9d Menglong Dong 2026-02-08 1246 false, func_meta, cookie_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1247 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1248 goto out;
49b5e77ae3e214a Pu Lehui 2023-02-15 1249 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1250
49b5e77ae3e214a Pu Lehui 2023-02-15 1251 if (flags & BPF_TRAMP_F_CALL_ORIG) {
2382a405c581ae8 Pu Lehui 2024-06-22 1252 im->ip_epilogue = ctx->ro_insns + ctx->ninsns;
9f1e16fb1fc9826 Pu Lehui 2024-06-22 1253 emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1254 ret = emit_call((const u64)__bpf_tramp_exit, true, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1255 if (ret)
49b5e77ae3e214a Pu Lehui 2023-02-15 1256 goto out;
49b5e77ae3e214a Pu Lehui 2023-02-15 1257 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1258
49b5e77ae3e214a Pu Lehui 2023-02-15 1259 if (flags & BPF_TRAMP_F_RESTORE_REGS)
6801b0aef79db47 Pu Lehui 2024-07-02 1260 restore_args(min_t(int, nr_arg_slots, RV_MAX_REG_ARGS), args_off, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1261
7112cd26e606c7b Björn Töpel 2023-10-04 1262 if (save_ret) {
7112cd26e606c7b Björn Töpel 2023-10-04 1263 emit_ld(regmap[BPF_REG_0], -(retval_off - 8), RV_REG_FP, ctx);
fd2e08128944a76 Hengqi Chen 2025-09-08 1264 if (is_struct_ops) {
fd2e08128944a76 Hengqi Chen 2025-09-08 1265 ret = sign_extend(RV_REG_A0, regmap[BPF_REG_0], m->ret_size,
fd2e08128944a76 Hengqi Chen 2025-09-08 1266 m->ret_flags & BTF_FMODEL_SIGNED_ARG, ctx);
fd2e08128944a76 Hengqi Chen 2025-09-08 1267 if (ret)
fd2e08128944a76 Hengqi Chen 2025-09-08 1268 goto out;
fd2e08128944a76 Hengqi Chen 2025-09-08 1269 } else {
fd2e08128944a76 Hengqi Chen 2025-09-08 1270 emit_ld(RV_REG_A0, -retval_off, RV_REG_FP, ctx);
fd2e08128944a76 Hengqi Chen 2025-09-08 1271 }
7112cd26e606c7b Björn Töpel 2023-10-04 1272 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1273
49b5e77ae3e214a Pu Lehui 2023-02-15 1274 emit_ld(RV_REG_S1, -sreg_off, RV_REG_FP, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1275
1732ebc4a26181c Pu Lehui 2024-01-23 1276 if (!is_struct_ops) {
25ad10658dc1068 Pu Lehui 2023-07-21 1277 /* trampoline called from function entry */
25ad10658dc1068 Pu Lehui 2023-07-21 1278 emit_ld(RV_REG_T0, stack_size - 8, RV_REG_SP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1279 emit_ld(RV_REG_FP, stack_size - 16, RV_REG_SP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1280 emit_addi(RV_REG_SP, RV_REG_SP, stack_size, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1281
25ad10658dc1068 Pu Lehui 2023-07-21 1282 emit_ld(RV_REG_RA, 8, RV_REG_SP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1283 emit_ld(RV_REG_FP, 0, RV_REG_SP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1284 emit_addi(RV_REG_SP, RV_REG_SP, 16, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1285
49b5e77ae3e214a Pu Lehui 2023-02-15 1286 if (flags & BPF_TRAMP_F_SKIP_FRAME)
25ad10658dc1068 Pu Lehui 2023-07-21 1287 /* return to parent function */
25ad10658dc1068 Pu Lehui 2023-07-21 1288 emit_jalr(RV_REG_ZERO, RV_REG_RA, 0, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1289 else
25ad10658dc1068 Pu Lehui 2023-07-21 1290 /* return to traced function */
25ad10658dc1068 Pu Lehui 2023-07-21 1291 emit_jalr(RV_REG_ZERO, RV_REG_T0, 0, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1292 } else {
25ad10658dc1068 Pu Lehui 2023-07-21 1293 /* trampoline called directly */
25ad10658dc1068 Pu Lehui 2023-07-21 1294 emit_ld(RV_REG_RA, stack_size - 8, RV_REG_SP, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1295 emit_ld(RV_REG_FP, stack_size - 16, RV_REG_SP, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1296 emit_addi(RV_REG_SP, RV_REG_SP, stack_size, ctx);
49b5e77ae3e214a Pu Lehui 2023-02-15 1297
49b5e77ae3e214a Pu Lehui 2023-02-15 1298 emit_jalr(RV_REG_ZERO, RV_REG_RA, 0, ctx);
25ad10658dc1068 Pu Lehui 2023-07-21 1299 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1300
49b5e77ae3e214a Pu Lehui 2023-02-15 1301 ret = ctx->ninsns;
49b5e77ae3e214a Pu Lehui 2023-02-15 1302 out:
49b5e77ae3e214a Pu Lehui 2023-02-15 1303 kfree(branches_off);
49b5e77ae3e214a Pu Lehui 2023-02-15 1304 return ret;
49b5e77ae3e214a Pu Lehui 2023-02-15 1305 }
49b5e77ae3e214a Pu Lehui 2023-02-15 1306
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH 0/4] mm: zone lock tracepoint instrumentation
From: Shakeel Butt @ 2026-02-20 22:36 UTC (permalink / raw)
To: Cheatham, Benjamin
Cc: Dmitry Ilvokhin, linux-kernel, linux-mm, linux-trace-kernel,
linux-cxl, kernel-team, Andrew Morton, David Hildenbrand,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Brendan Jackman,
Johannes Weiner, Zi Yan, Oscar Salvador, Qi Zheng, Axel Rasmussen,
Yuanchu Xie, Wei Xu
In-Reply-To: <06b2a2b6-d5c8-4522-8e22-10616f887846@amd.com>
On Fri, Feb 20, 2026 at 01:09:59PM -0600, Cheatham, Benjamin wrote:
> On 2/11/2026 9:22 AM, Dmitry Ilvokhin wrote:
> > Zone lock contention can significantly impact allocation and
> > reclaim latency, as it is a central synchronization point in
> > the page allocator and reclaim paths. Improved visibility into
> > its behavior is therefore important for diagnosing performance
> > issues in memory-intensive workloads.
> >
> > On some production workloads at Meta, we have observed noticeable
> > zone lock contention. Deeper analysis of lock holders and waiters
> > is currently difficult with existing instrumentation.
> >
> > While generic lock contention_begin/contention_end tracepoints
> > cover the slow path, they do not provide sufficient visibility
> > into lock hold times. In particular, the lack of a release-side
> > event makes it difficult to identify long lock holders and
> > correlate them with waiters. As a result, distinguishing between
> > short bursts of contention and pathological long hold times
> > requires additional instrumentation.
> >
> > This patch series adds dedicated tracepoint instrumentation to
> > zone lock, following the existing mmap_lock tracing model.
> >
> > The goal is to enable detailed holder/waiter analysis and lock
> > hold time measurements without affecting the fast path when
> > tracing is disabled.
> >
> > The series is structured as follows:
> >
> > 1. Introduce zone lock wrappers.
> > 2. Mechanically convert zone lock users to the wrappers.
> > 3. Convert compaction to use the wrappers (requires minor
> > restructuring of compact_lock_irqsave()).
> > 4. Add zone lock tracepoints.
>
> I think you can improve the flow of this series if reorder as follows:
> 1. Introduce zone lock wrappers
> 4. Add zone lock tracepoints
> 2. Mechanically convert zone lock users to the wrappers
> 3. Convert compaction to use the wrappers...
>
> and possibly squash 1 & 4 (though that might be too big of a patch). It's better to introduce the
> wrappers and their tracepoints together before the reviewer (i.e. me) forgets what was added in
> patch 1 by the time they get to patch 4.
I don't think this suggestion will make anything better. This just seems like a
different taste. If I make a suggestion, I would request to squash (1) and (2)
i.e. patch containing wrappers and their use together but that is just my taste
and would be a nit. The series ordering is good as is.
^ permalink raw reply
* Re: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
From: kernel test robot @ 2026-02-20 21:05 UTC (permalink / raw)
To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: oe-kbuild-all, bpf, linux-trace-kernel, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, Menglong Dong,
Steven Rostedt
In-Reply-To: <20260220100649.628307-5-jolsa@kernel.org>
Hi Jiri,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiri-Olsa/ftrace-Add-ftrace_hash_count-function/20260220-181324
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20260220100649.628307-5-jolsa%40kernel.org
patch subject: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
config: riscv-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260220/202602202212.yC5wLunx-lkp@intel.com/config)
compiler: riscv64-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260220/202602202212.yC5wLunx-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602202212.yC5wLunx-lkp@intel.com/
All errors (new ones prefixed by >>):
arch/riscv/net/bpf_jit_comp64.c: In function 'invoke_bpf_prog':
>> arch/riscv/net/bpf_jit_comp64.c:944:14: error: 'struct bpf_tramp_link' has no member named 'cookie'
944 | if (l->cookie)
| ^~
arch/riscv/net/bpf_jit_comp64.c:945:79: error: 'struct bpf_tramp_link' has no member named 'cookie'
945 | emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
| ^~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:999:30: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
999 | static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
| ^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function 'invoke_bpf':
>> arch/riscv/net/bpf_jit_comp64.c:1005:27: error: invalid use of undefined type 'struct bpf_tramp_links'
1005 | for (i = 0; i < tl->nr_links; i++) {
| ^~
arch/riscv/net/bpf_jit_comp64.c:1008:53: error: invalid use of undefined type 'struct bpf_tramp_links'
1008 | if (bpf_prog_calls_session_cookie(tl->links[i])) {
| ^~
arch/riscv/net/bpf_jit_comp64.c:1014:41: error: invalid use of undefined type 'struct bpf_tramp_links'
1014 | err = invoke_bpf_prog(tl->links[i], args_off, retval_off, run_ctx_off,
| ^~
arch/riscv/net/bpf_jit_comp64.c: At top level:
arch/riscv/net/bpf_jit_comp64.c:1024:49: warning: 'struct bpf_tramp_links' declared inside parameter list will not be visible outside of this definition or declaration
1024 | struct bpf_tramp_links *tlinks,
| ^~~~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c: In function '__arch_prepare_bpf_trampoline':
arch/riscv/net/bpf_jit_comp64.c:1033:49: error: invalid use of undefined type 'struct bpf_tramp_links'
1033 | struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY];
| ^
arch/riscv/net/bpf_jit_comp64.c:1034:48: error: invalid use of undefined type 'struct bpf_tramp_links'
1034 | struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT];
| ^
arch/riscv/net/bpf_jit_comp64.c:1035:51: error: invalid use of undefined type 'struct bpf_tramp_links'
1035 | struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
| ^
arch/riscv/net/bpf_jit_comp64.c:1118:46: error: passing argument 1 of 'bpf_fsession_cookie_cnt' from incompatible pointer type [-Wincompatible-pointer-types]
1118 | cookie_cnt = bpf_fsession_cookie_cnt(tlinks);
| ^~~~~~
| |
| struct bpf_tramp_links *
In file included from arch/riscv/net/bpf_jit_comp64.c:9:
./include/linux/bpf.h:2207:67: note: expected 'struct bpf_tramp_nodes *' but argument is of type 'struct bpf_tramp_links *'
2207 | static inline int bpf_fsession_cookie_cnt(struct bpf_tramp_nodes *nodes)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
arch/riscv/net/bpf_jit_comp64.c:1175:30: error: passing argument 1 of 'bpf_fsession_cnt' from incompatible pointer type [-Wincompatible-pointer-types]
1175 | if (bpf_fsession_cnt(tlinks)) {
| ^~~~~~
| |
| struct bpf_tramp_links *
./include/linux/bpf.h:2189:60: note: expected 'struct bpf_tramp_nodes *' but argument is of type 'struct bpf_tramp_links *'
2189 | static inline int bpf_fsession_cnt(struct bpf_tramp_nodes *nodes)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
arch/riscv/net/bpf_jit_comp64.c:1190:19: error: invalid use of undefined type 'struct bpf_tramp_links'
1190 | if (fentry->nr_links) {
| ^~
arch/riscv/net/bpf_jit_comp64.c:1191:34: error: passing argument 1 of 'invoke_bpf' from incompatible pointer type [-Wincompatible-pointer-types]
1191 | ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
| ^~~~~~
| |
| struct bpf_tramp_links *
arch/riscv/net/bpf_jit_comp64.c:999:47: note: expected 'struct bpf_tramp_links *' but argument is of type 'struct bpf_tramp_links *'
999 | static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
| ~~~~~~~~~~~~~~~~~~~~~~~~^~
arch/riscv/net/bpf_jit_comp64.c:1197:21: error: invalid use of undefined type 'struct bpf_tramp_links'
1197 | if (fmod_ret->nr_links) {
| ^~
In file included from ./include/linux/workqueue.h:9,
from ./include/linux/bpf.h:11:
arch/riscv/net/bpf_jit_comp64.c:1198:48: error: invalid use of undefined type 'struct bpf_tramp_links'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~
./include/linux/alloc_tag.h:251:16: note: in definition of macro 'alloc_hooks_tag'
251 | typeof(_do_alloc) _res; \
| ^~~~~~~~~
./include/linux/slab.h:1115:49: note: in expansion of macro 'alloc_hooks'
1115 | #define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
| ^~~~~~~~~~~
./include/linux/slab.h:1154:41: note: in expansion of macro 'kmalloc_array'
1154 | #define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
| ^~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1198:32: note: in expansion of macro 'kcalloc'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1198:48: error: invalid use of undefined type 'struct bpf_tramp_links'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~
./include/linux/alloc_tag.h:255:24: note: in definition of macro 'alloc_hooks_tag'
255 | _res = _do_alloc; \
| ^~~~~~~~~
./include/linux/slab.h:1115:49: note: in expansion of macro 'alloc_hooks'
1115 | #define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
| ^~~~~~~~~~~
./include/linux/slab.h:1154:41: note: in expansion of macro 'kmalloc_array'
1154 | #define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
| ^~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1198:32: note: in expansion of macro 'kcalloc'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1198:48: error: invalid use of undefined type 'struct bpf_tramp_links'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~
./include/linux/alloc_tag.h:258:24: note: in definition of macro 'alloc_hooks_tag'
258 | _res = _do_alloc; \
| ^~~~~~~~~
./include/linux/slab.h:1115:49: note: in expansion of macro 'alloc_hooks'
1115 | #define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
| ^~~~~~~~~~~
./include/linux/slab.h:1154:41: note: in expansion of macro 'kmalloc_array'
1154 | #define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
| ^~~~~~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1198:32: note: in expansion of macro 'kcalloc'
1198 | branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
| ^~~~~~~
vim +944 arch/riscv/net/bpf_jit_comp64.c
93fd420d71beed Menglong Dong 2026-02-08 936
49b5e77ae3e214 Pu Lehui 2023-02-15 937 static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_off,
49b5e77ae3e214 Pu Lehui 2023-02-15 938 int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
49b5e77ae3e214 Pu Lehui 2023-02-15 939 {
49b5e77ae3e214 Pu Lehui 2023-02-15 940 int ret, branch_off;
49b5e77ae3e214 Pu Lehui 2023-02-15 941 struct bpf_prog *p = l->link.prog;
49b5e77ae3e214 Pu Lehui 2023-02-15 942 int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
49b5e77ae3e214 Pu Lehui 2023-02-15 943
93fd420d71beed Menglong Dong 2026-02-08 @944 if (l->cookie)
93fd420d71beed Menglong Dong 2026-02-08 945 emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
93fd420d71beed Menglong Dong 2026-02-08 946 else
49b5e77ae3e214 Pu Lehui 2023-02-15 947 emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 948
49b5e77ae3e214 Pu Lehui 2023-02-15 949 /* arg1: prog */
49b5e77ae3e214 Pu Lehui 2023-02-15 950 emit_imm(RV_REG_A0, (const s64)p, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 951 /* arg2: &run_ctx */
49b5e77ae3e214 Pu Lehui 2023-02-15 952 emit_addi(RV_REG_A1, RV_REG_FP, -run_ctx_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 953 ret = emit_call((const u64)bpf_trampoline_enter(p), true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 954 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 955 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 956
10541b374aa05c Xu Kuohai 2024-04-16 957 /* store prog start time */
10541b374aa05c Xu Kuohai 2024-04-16 958 emit_mv(RV_REG_S1, RV_REG_A0, ctx);
10541b374aa05c Xu Kuohai 2024-04-16 959
49b5e77ae3e214 Pu Lehui 2023-02-15 960 /* if (__bpf_prog_enter(prog) == 0)
49b5e77ae3e214 Pu Lehui 2023-02-15 961 * goto skip_exec_of_prog;
49b5e77ae3e214 Pu Lehui 2023-02-15 962 */
49b5e77ae3e214 Pu Lehui 2023-02-15 963 branch_off = ctx->ninsns;
49b5e77ae3e214 Pu Lehui 2023-02-15 964 /* nop reserved for conditional jump */
49b5e77ae3e214 Pu Lehui 2023-02-15 965 emit(rv_nop(), ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 966
49b5e77ae3e214 Pu Lehui 2023-02-15 967 /* arg1: &args_off */
49b5e77ae3e214 Pu Lehui 2023-02-15 968 emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 969 if (!p->jited)
49b5e77ae3e214 Pu Lehui 2023-02-15 970 /* arg2: progs[i]->insnsi for interpreter */
49b5e77ae3e214 Pu Lehui 2023-02-15 971 emit_imm(RV_REG_A1, (const s64)p->insnsi, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 972 ret = emit_call((const u64)p->bpf_func, true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 973 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 974 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 975
7112cd26e606c7 Björn Töpel 2023-10-04 976 if (save_ret) {
7112cd26e606c7 Björn Töpel 2023-10-04 977 emit_sd(RV_REG_FP, -retval_off, RV_REG_A0, ctx);
7112cd26e606c7 Björn Töpel 2023-10-04 978 emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx);
7112cd26e606c7 Björn Töpel 2023-10-04 979 }
49b5e77ae3e214 Pu Lehui 2023-02-15 980
49b5e77ae3e214 Pu Lehui 2023-02-15 981 /* update branch with beqz */
49b5e77ae3e214 Pu Lehui 2023-02-15 982 if (ctx->insns) {
49b5e77ae3e214 Pu Lehui 2023-02-15 983 int offset = ninsns_rvoff(ctx->ninsns - branch_off);
49b5e77ae3e214 Pu Lehui 2023-02-15 984 u32 insn = rv_beq(RV_REG_A0, RV_REG_ZERO, offset >> 1);
49b5e77ae3e214 Pu Lehui 2023-02-15 985 *(u32 *)(ctx->insns + branch_off) = insn;
49b5e77ae3e214 Pu Lehui 2023-02-15 986 }
49b5e77ae3e214 Pu Lehui 2023-02-15 987
49b5e77ae3e214 Pu Lehui 2023-02-15 988 /* arg1: prog */
49b5e77ae3e214 Pu Lehui 2023-02-15 989 emit_imm(RV_REG_A0, (const s64)p, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 990 /* arg2: prog start time */
49b5e77ae3e214 Pu Lehui 2023-02-15 991 emit_mv(RV_REG_A1, RV_REG_S1, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 992 /* arg3: &run_ctx */
49b5e77ae3e214 Pu Lehui 2023-02-15 993 emit_addi(RV_REG_A2, RV_REG_FP, -run_ctx_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 994 ret = emit_call((const u64)bpf_trampoline_exit(p), true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 995
49b5e77ae3e214 Pu Lehui 2023-02-15 996 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 997 }
49b5e77ae3e214 Pu Lehui 2023-02-15 998
35b3515be0ecb9 Menglong Dong 2026-02-08 999 static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
35b3515be0ecb9 Menglong Dong 2026-02-08 1000 int run_ctx_off, int func_meta_off, bool save_ret, u64 func_meta,
35b3515be0ecb9 Menglong Dong 2026-02-08 1001 int cookie_off, struct rv_jit_context *ctx)
35b3515be0ecb9 Menglong Dong 2026-02-08 1002 {
35b3515be0ecb9 Menglong Dong 2026-02-08 1003 int i, cur_cookie = (cookie_off - args_off) / 8;
35b3515be0ecb9 Menglong Dong 2026-02-08 1004
35b3515be0ecb9 Menglong Dong 2026-02-08 @1005 for (i = 0; i < tl->nr_links; i++) {
35b3515be0ecb9 Menglong Dong 2026-02-08 1006 int err;
35b3515be0ecb9 Menglong Dong 2026-02-08 1007
35b3515be0ecb9 Menglong Dong 2026-02-08 1008 if (bpf_prog_calls_session_cookie(tl->links[i])) {
35b3515be0ecb9 Menglong Dong 2026-02-08 1009 u64 meta = func_meta | ((u64)cur_cookie << BPF_TRAMP_COOKIE_INDEX_SHIFT);
35b3515be0ecb9 Menglong Dong 2026-02-08 1010
35b3515be0ecb9 Menglong Dong 2026-02-08 1011 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, meta, ctx);
35b3515be0ecb9 Menglong Dong 2026-02-08 1012 cur_cookie--;
35b3515be0ecb9 Menglong Dong 2026-02-08 1013 }
35b3515be0ecb9 Menglong Dong 2026-02-08 1014 err = invoke_bpf_prog(tl->links[i], args_off, retval_off, run_ctx_off,
35b3515be0ecb9 Menglong Dong 2026-02-08 1015 save_ret, ctx);
35b3515be0ecb9 Menglong Dong 2026-02-08 1016 if (err)
35b3515be0ecb9 Menglong Dong 2026-02-08 1017 return err;
35b3515be0ecb9 Menglong Dong 2026-02-08 1018 }
35b3515be0ecb9 Menglong Dong 2026-02-08 1019 return 0;
35b3515be0ecb9 Menglong Dong 2026-02-08 1020 }
35b3515be0ecb9 Menglong Dong 2026-02-08 1021
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH v2 4/4] ring-buffer: Record invalid buffer event
From: Steven Rostedt @ 2026-02-20 19:59 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel
In-Reply-To: <177140968338.1537493.3298484599734677165.stgit@mhiramat.tok.corp.google.com>
On Wed, 18 Feb 2026 19:14:43 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> Record an invalid buffer event on the invalidated sub buffer
> so that user can notice how much data is skipped.
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
As I showed in patch 3, just mark it as having missed events. We could add
a pr_warn() that says the buffer was corrupted, but we don't need a
"invalid" event.
-- Steve
^ permalink raw reply
* Re: [PATCH bpf-next 02/17] bpf: Use mutex lock pool for bpf trampolines
From: Alexei Starovoitov @ 2026-02-20 19:58 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-3-jolsa@kernel.org>
On Fri, Feb 20, 2026 at 2:07 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Adding mutex lock pool that replaces bpf trampolines mutex.
>
> For tracing_multi link coming in following changes we need to lock all
> the involved trampolines during the attachment. This could mean thousands
> of mutex locks, which is not convenient.
>
> As suggested by Andrii we can replace bpf trampolines mutex with mutex
> pool, where each trampoline is hash-ed to one of the locks from the pool.
>
> It's better to lock all the pool mutexes (64 at the moment) than
> thousands of them.
>
> Removing the mutex_is_locked in bpf_trampoline_put, because we removed
> the mutex from bpf_trampoline.
>
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> include/linux/bpf.h | 2 --
> kernel/bpf/trampoline.c | 74 +++++++++++++++++++++++++++++++----------
> 2 files changed, 56 insertions(+), 20 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index cd9b96434904..46bf3d86bdb2 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1335,8 +1335,6 @@ struct bpf_trampoline {
> /* hlist for trampoline_ip_table */
> struct hlist_node hlist_ip;
> struct ftrace_ops *fops;
> - /* serializes access to fields of this trampoline */
> - struct mutex mutex;
> refcount_t refcnt;
> u32 flags;
> u64 key;
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 952cd7932461..05dc0358654d 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -30,6 +30,45 @@ static struct hlist_head trampoline_ip_table[TRAMPOLINE_TABLE_SIZE];
> /* serializes access to trampoline tables */
> static DEFINE_MUTEX(trampoline_mutex);
>
> +#define TRAMPOLINE_LOCKS_BITS 6
> +#define TRAMPOLINE_LOCKS_TABLE_SIZE (1 << TRAMPOLINE_LOCKS_BITS)
> +
> +static struct {
> + struct mutex mutex;
> + struct lock_class_key key;
> +} *trampoline_locks;
> +
> +static struct mutex *trampoline_locks_lookup(struct bpf_trampoline *tr)
select_trampoline_lock() ?
> +{
> + return &trampoline_locks[hash_64((u64) tr, TRAMPOLINE_LOCKS_BITS)].mutex;
> +}
> +
> +static void trampoline_lock(struct bpf_trampoline *tr)
> +{
> + mutex_lock(trampoline_locks_lookup(tr));
> +}
> +
> +static void trampoline_unlock(struct bpf_trampoline *tr)
> +{
> + mutex_unlock(trampoline_locks_lookup(tr));
> +}
> +
> +static int __init trampoline_locks_init(void)
> +{
> + int i;
> +
> + trampoline_locks = kmalloc_array(TRAMPOLINE_LOCKS_TABLE_SIZE,
> + sizeof(trampoline_locks[0]), GFP_KERNEL);
why bother with memory allocation? This is just 64 mutexes.
> + if (!trampoline_locks)
> + return -ENOMEM;
> +
> + for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++) {
> + lockdep_register_key(&trampoline_locks[i].key);
why special key?
^ permalink raw reply
* Re: [PATCH v2 3/4] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer
From: Steven Rostedt @ 2026-02-20 19:56 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel
In-Reply-To: <177140967567.1537493.7265236420134382381.stgit@mhiramat.tok.corp.google.com>
On Wed, 18 Feb 2026 19:14:35 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> Skip invalid sub-buffers when validating the persistent ring buffer
> instead of invalidate all ring buffers.
instead of discarding the entire ring buffer.
>
> If the cache data in memory fails to be synchronized during a reboot,
> the persistent ring buffer may become partially corrupted, but other
> sub-buffers may still contain readable event data, allowing usersto
> recover data from the corrupted ring buffer.
... contain readable event data. Only discard the
subbuffers that are found to be corrupted.
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> kernel/trace/ring_buffer.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index d2b69221a94c..0ae2a5ad8c3e 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -2045,17 +2045,19 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
> if (ret < 0) {
> pr_info("Ring buffer meta [%d] invalid buffer page\n",
> cpu_buffer->cpu);
> - goto invalid;
> - }
> -
> - /* If the buffer has content, update pages_touched */
> - if (ret)
> - local_inc(&cpu_buffer->pages_touched);
> -
> - entries += ret;
> - entry_bytes += local_read(&head_page->page->commit);
> - local_set(&cpu_buffer->head_page->entries, ret);
> + /* Instead of invalidate whole ring buffer, just clear this subbuffer. */
> + local_set(&head_page->entries, 0);
> + local_set(&head_page->page->commit, 0);
> + /* TODO: commit an event to mark this is broken. */
Here's how to fix the TODO:
local_set(&head_page->page->commit, RB_MISSED_EVENTS);
-- Steve
> + } else {
> + /* If the buffer has content, update pages_touched */
> + if (ret)
> + local_inc(&cpu_buffer->pages_touched);
>
> + entries += ret;
> + entry_bytes += local_read(&head_page->page->commit);
> + local_set(&cpu_buffer->head_page->entries, ret);
> + }
> if (head_page == cpu_buffer->commit_page)
> break;
> }
^ permalink raw reply
* Re: [PATCH v2 2/4] ring-buffer: Flush and stop persistent ring buffer on panic
From: Steven Rostedt @ 2026-02-20 19:53 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel
In-Reply-To: <177140966801.1537493.7352910810257662003.stgit@mhiramat.tok.corp.google.com>
On Wed, 18 Feb 2026 19:14:28 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> On a real hardware, since panic and reboot the machine will not
> flush hardware cache to the persistent ring buffer, the events
> written right before the panic can be lost. Moreover, since
> there will be an inconsistency between the commit counter (which
> is written atomically via local_set()) and the data, validation
> will fail and all data in the persistent ring buffer will be lost.
Here's a bit of a fix up on the text:
On real hardware, panic and machine reboot may not flush hardware cache
to memory. This means the persistent ring buffer, which relies on a
coherent state of memory, may not have its events written to the buffer
and they may be lost. Moreover, there may be inconsistency with the
counters which are used for validation of the integrity of the
persistent ring buffer which may cause all data to be discarded.
>
> To avoid this issue, this will stop recording on the ring buffer
> and flush cache at the reserved memory on panic.
To avoid this issue, stop recording of the ring buffer on panic and
flush the cache of the ring buffer's memory.
-- Steve
^ permalink raw reply
* Re: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
From: kernel test robot @ 2026-02-20 19:52 UTC (permalink / raw)
To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: llvm, oe-kbuild-all, bpf, linux-trace-kernel, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, Menglong Dong,
Steven Rostedt
In-Reply-To: <20260220100649.628307-5-jolsa@kernel.org>
Hi Jiri,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiri-Olsa/ftrace-Add-ftrace_hash_count-function/20260220-181324
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20260220100649.628307-5-jolsa%40kernel.org
patch subject: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20260221/202602210330.ukNZdClO-lkp@intel.com/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260221/202602210330.ukNZdClO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602210330.ukNZdClO-lkp@intel.com/
All errors (new ones prefixed by >>):
arch/riscv/net/bpf_jit_comp64.c:944:9: error: no member named 'cookie' in 'struct bpf_tramp_link'
if (l->cookie)
~ ^
arch/riscv/net/bpf_jit_comp64.c:945:67: error: no member named 'cookie' in 'struct bpf_tramp_link'
emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
~ ^
arch/riscv/net/bpf_jit_comp64.c:999:30: warning: declaration of 'struct bpf_tramp_links' will not be visible outside of this function [-Wvisibility]
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^
arch/riscv/net/bpf_jit_comp64.c:1005:20: error: incomplete definition of type 'struct bpf_tramp_links'
for (i = 0; i < tl->nr_links; i++) {
~~^
arch/riscv/net/bpf_jit_comp64.c:999:30: note: forward declaration of 'struct bpf_tramp_links'
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^
arch/riscv/net/bpf_jit_comp64.c:1008:39: error: incomplete definition of type 'struct bpf_tramp_links'
if (bpf_prog_calls_session_cookie(tl->links[i])) {
~~^
arch/riscv/net/bpf_jit_comp64.c:999:30: note: forward declaration of 'struct bpf_tramp_links'
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^
arch/riscv/net/bpf_jit_comp64.c:1014:27: error: incomplete definition of type 'struct bpf_tramp_links'
err = invoke_bpf_prog(tl->links[i], args_off, retval_off, run_ctx_off,
~~^
arch/riscv/net/bpf_jit_comp64.c:999:30: note: forward declaration of 'struct bpf_tramp_links'
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^
arch/riscv/net/bpf_jit_comp64.c:1024:14: warning: declaration of 'struct bpf_tramp_links' will not be visible outside of this function [-Wvisibility]
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1033:42: error: subscript of pointer to incomplete type 'struct bpf_tramp_links'
struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY];
~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1034:41: error: subscript of pointer to incomplete type 'struct bpf_tramp_links'
struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT];
~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1035:44: error: subscript of pointer to incomplete type 'struct bpf_tramp_links'
struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
>> arch/riscv/net/bpf_jit_comp64.c:1118:39: error: incompatible pointer types passing 'struct bpf_tramp_links *' to parameter of type 'struct bpf_tramp_nodes *' [-Werror,-Wincompatible-pointer-types]
cookie_cnt = bpf_fsession_cookie_cnt(tlinks);
^~~~~~
include/linux/bpf.h:2207:67: note: passing argument to parameter 'nodes' here
static inline int bpf_fsession_cookie_cnt(struct bpf_tramp_nodes *nodes)
^
arch/riscv/net/bpf_jit_comp64.c:1175:23: error: incompatible pointer types passing 'struct bpf_tramp_links *' to parameter of type 'struct bpf_tramp_nodes *' [-Werror,-Wincompatible-pointer-types]
if (bpf_fsession_cnt(tlinks)) {
^~~~~~
include/linux/bpf.h:2189:60: note: passing argument to parameter 'nodes' here
static inline int bpf_fsession_cnt(struct bpf_tramp_nodes *nodes)
^
arch/riscv/net/bpf_jit_comp64.c:1190:12: error: incomplete definition of type 'struct bpf_tramp_links'
if (fentry->nr_links) {
~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1191:20: error: incompatible pointer types passing 'struct bpf_tramp_links *' to parameter of type 'struct bpf_tramp_links *' [-Werror,-Wincompatible-pointer-types]
ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
^~~~~~
arch/riscv/net/bpf_jit_comp64.c:999:47: note: passing argument to parameter 'tl' here
static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval_off,
^
arch/riscv/net/bpf_jit_comp64.c:1197:14: error: incomplete definition of type 'struct bpf_tramp_links'
if (fmod_ret->nr_links) {
~~~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1198:34: error: incomplete definition of type 'struct bpf_tramp_links'
branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
~~~~~~~~^
include/linux/slab.h:1154:48: note: expanded from macro 'kcalloc'
#define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
^
include/linux/slab.h:1115:63: note: expanded from macro 'kmalloc_array'
#define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
^~~~~~~~~~~
include/linux/alloc_tag.h:265:31: note: expanded from macro 'alloc_hooks'
alloc_hooks_tag(&_alloc_tag, _do_alloc); \
^~~~~~~~~
include/linux/alloc_tag.h:251:9: note: expanded from macro 'alloc_hooks_tag'
typeof(_do_alloc) _res; \
^~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1198:34: error: incomplete definition of type 'struct bpf_tramp_links'
branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
~~~~~~~~^
include/linux/slab.h:1154:48: note: expanded from macro 'kcalloc'
#define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
^
include/linux/slab.h:1115:63: note: expanded from macro 'kmalloc_array'
#define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
^~~~~~~~~~~
include/linux/alloc_tag.h:265:31: note: expanded from macro 'alloc_hooks'
alloc_hooks_tag(&_alloc_tag, _do_alloc); \
^~~~~~~~~
include/linux/alloc_tag.h:255:10: note: expanded from macro 'alloc_hooks_tag'
_res = _do_alloc; \
^~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1198:34: error: incomplete definition of type 'struct bpf_tramp_links'
branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
~~~~~~~~^
include/linux/slab.h:1154:48: note: expanded from macro 'kcalloc'
#define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
^
include/linux/slab.h:1115:63: note: expanded from macro 'kmalloc_array'
#define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
^~~~~~~~~~~
include/linux/alloc_tag.h:265:31: note: expanded from macro 'alloc_hooks'
alloc_hooks_tag(&_alloc_tag, _do_alloc); \
^~~~~~~~~
include/linux/alloc_tag.h:258:10: note: expanded from macro 'alloc_hooks_tag'
_res = _do_alloc; \
^~~~~~~~~
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1204:27: error: incomplete definition of type 'struct bpf_tramp_links'
for (i = 0; i < fmod_ret->nr_links; i++) {
~~~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1205:34: error: incomplete definition of type 'struct bpf_tramp_links'
ret = invoke_bpf_prog(fmod_ret->links[i], args_off, retval_off,
~~~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
^
arch/riscv/net/bpf_jit_comp64.c:1233:40: error: incomplete definition of type 'struct bpf_tramp_links'
for (i = 0; ctx->insns && i < fmod_ret->nr_links; i++) {
~~~~~~~~^
arch/riscv/net/bpf_jit_comp64.c:1024:14: note: forward declaration of 'struct bpf_tramp_links'
struct bpf_tramp_links *tlinks,
vim +1118 arch/riscv/net/bpf_jit_comp64.c
35b3515be0ecb9 Menglong Dong 2026-02-08 1021
49b5e77ae3e214 Pu Lehui 2023-02-15 1022 static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
49b5e77ae3e214 Pu Lehui 2023-02-15 1023 const struct btf_func_model *m,
49b5e77ae3e214 Pu Lehui 2023-02-15 1024 struct bpf_tramp_links *tlinks,
49b5e77ae3e214 Pu Lehui 2023-02-15 1025 void *func_addr, u32 flags,
49b5e77ae3e214 Pu Lehui 2023-02-15 1026 struct rv_jit_context *ctx)
49b5e77ae3e214 Pu Lehui 2023-02-15 1027 {
49b5e77ae3e214 Pu Lehui 2023-02-15 1028 int i, ret, offset;
49b5e77ae3e214 Pu Lehui 2023-02-15 1029 int *branches_off = NULL;
6801b0aef79db4 Pu Lehui 2024-07-02 1030 int stack_size = 0, nr_arg_slots = 0;
35b3515be0ecb9 Menglong Dong 2026-02-08 1031 int retval_off, args_off, func_meta_off, ip_off, run_ctx_off, sreg_off, stk_arg_off;
35b3515be0ecb9 Menglong Dong 2026-02-08 1032 int cookie_off, cookie_cnt;
49b5e77ae3e214 Pu Lehui 2023-02-15 1033 struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY];
49b5e77ae3e214 Pu Lehui 2023-02-15 1034 struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT];
49b5e77ae3e214 Pu Lehui 2023-02-15 1035 struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
1732ebc4a26181 Pu Lehui 2024-01-23 1036 bool is_struct_ops = flags & BPF_TRAMP_F_INDIRECT;
49b5e77ae3e214 Pu Lehui 2023-02-15 1037 void *orig_call = func_addr;
49b5e77ae3e214 Pu Lehui 2023-02-15 1038 bool save_ret;
35b3515be0ecb9 Menglong Dong 2026-02-08 1039 u64 func_meta;
49b5e77ae3e214 Pu Lehui 2023-02-15 1040 u32 insn;
49b5e77ae3e214 Pu Lehui 2023-02-15 1041
25ad10658dc106 Pu Lehui 2023-07-21 1042 /* Two types of generated trampoline stack layout:
25ad10658dc106 Pu Lehui 2023-07-21 1043 *
25ad10658dc106 Pu Lehui 2023-07-21 1044 * 1. trampoline called from function entry
25ad10658dc106 Pu Lehui 2023-07-21 1045 * --------------------------------------
25ad10658dc106 Pu Lehui 2023-07-21 1046 * FP + 8 [ RA to parent func ] return address to parent
25ad10658dc106 Pu Lehui 2023-07-21 1047 * function
25ad10658dc106 Pu Lehui 2023-07-21 1048 * FP + 0 [ FP of parent func ] frame pointer of parent
25ad10658dc106 Pu Lehui 2023-07-21 1049 * function
25ad10658dc106 Pu Lehui 2023-07-21 1050 * FP - 8 [ T0 to traced func ] return address of traced
25ad10658dc106 Pu Lehui 2023-07-21 1051 * function
25ad10658dc106 Pu Lehui 2023-07-21 1052 * FP - 16 [ FP of traced func ] frame pointer of traced
25ad10658dc106 Pu Lehui 2023-07-21 1053 * function
25ad10658dc106 Pu Lehui 2023-07-21 1054 * --------------------------------------
49b5e77ae3e214 Pu Lehui 2023-02-15 1055 *
25ad10658dc106 Pu Lehui 2023-07-21 1056 * 2. trampoline called directly
25ad10658dc106 Pu Lehui 2023-07-21 1057 * --------------------------------------
25ad10658dc106 Pu Lehui 2023-07-21 1058 * FP - 8 [ RA to caller func ] return address to caller
49b5e77ae3e214 Pu Lehui 2023-02-15 1059 * function
25ad10658dc106 Pu Lehui 2023-07-21 1060 * FP - 16 [ FP of caller func ] frame pointer of caller
49b5e77ae3e214 Pu Lehui 2023-02-15 1061 * function
25ad10658dc106 Pu Lehui 2023-07-21 1062 * --------------------------------------
49b5e77ae3e214 Pu Lehui 2023-02-15 1063 *
49b5e77ae3e214 Pu Lehui 2023-02-15 1064 * FP - retval_off [ return value ] BPF_TRAMP_F_CALL_ORIG or
49b5e77ae3e214 Pu Lehui 2023-02-15 1065 * BPF_TRAMP_F_RET_FENTRY_RET
49b5e77ae3e214 Pu Lehui 2023-02-15 1066 * [ argN ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1067 * [ ... ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1068 * FP - args_off [ arg1 ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1069 *
35b3515be0ecb9 Menglong Dong 2026-02-08 1070 * FP - func_meta_off [ regs count, etc ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1071 *
49b5e77ae3e214 Pu Lehui 2023-02-15 1072 * FP - ip_off [ traced func ] BPF_TRAMP_F_IP_ARG
49b5e77ae3e214 Pu Lehui 2023-02-15 1073 *
35b3515be0ecb9 Menglong Dong 2026-02-08 1074 * [ stack cookie N ]
35b3515be0ecb9 Menglong Dong 2026-02-08 1075 * [ ... ]
35b3515be0ecb9 Menglong Dong 2026-02-08 1076 * FP - cookie_off [ stack cookie 1 ]
35b3515be0ecb9 Menglong Dong 2026-02-08 1077 *
49b5e77ae3e214 Pu Lehui 2023-02-15 1078 * FP - run_ctx_off [ bpf_tramp_run_ctx ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1079 *
49b5e77ae3e214 Pu Lehui 2023-02-15 1080 * FP - sreg_off [ callee saved reg ]
49b5e77ae3e214 Pu Lehui 2023-02-15 1081 *
49b5e77ae3e214 Pu Lehui 2023-02-15 1082 * [ pads ] pads for 16 bytes alignment
6801b0aef79db4 Pu Lehui 2024-07-02 1083 *
6801b0aef79db4 Pu Lehui 2024-07-02 1084 * [ stack_argN ]
6801b0aef79db4 Pu Lehui 2024-07-02 1085 * [ ... ]
6801b0aef79db4 Pu Lehui 2024-07-02 1086 * FP - stk_arg_off [ stack_arg1 ] BPF_TRAMP_F_CALL_ORIG
49b5e77ae3e214 Pu Lehui 2023-02-15 1087 */
49b5e77ae3e214 Pu Lehui 2023-02-15 1088
49b5e77ae3e214 Pu Lehui 2023-02-15 1089 if (flags & (BPF_TRAMP_F_ORIG_STACK | BPF_TRAMP_F_SHARE_IPMODIFY))
49b5e77ae3e214 Pu Lehui 2023-02-15 1090 return -ENOTSUPP;
49b5e77ae3e214 Pu Lehui 2023-02-15 1091
6801b0aef79db4 Pu Lehui 2024-07-02 1092 if (m->nr_args > MAX_BPF_FUNC_ARGS)
49b5e77ae3e214 Pu Lehui 2023-02-15 1093 return -ENOTSUPP;
49b5e77ae3e214 Pu Lehui 2023-02-15 1094
6801b0aef79db4 Pu Lehui 2024-07-02 1095 for (i = 0; i < m->nr_args; i++)
6801b0aef79db4 Pu Lehui 2024-07-02 1096 nr_arg_slots += round_up(m->arg_size[i], 8) / 8;
6801b0aef79db4 Pu Lehui 2024-07-02 1097
25ad10658dc106 Pu Lehui 2023-07-21 1098 /* room of trampoline frame to store return address and frame pointer */
25ad10658dc106 Pu Lehui 2023-07-21 1099 stack_size += 16;
49b5e77ae3e214 Pu Lehui 2023-02-15 1100
49b5e77ae3e214 Pu Lehui 2023-02-15 1101 save_ret = flags & (BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_RET_FENTRY_RET);
d0bf7cd5df1846 Chenghao Duan 2025-09-22 1102 if (save_ret)
7112cd26e606c7 Björn Töpel 2023-10-04 1103 stack_size += 16; /* Save both A5 (BPF R0) and A0 */
49b5e77ae3e214 Pu Lehui 2023-02-15 1104 retval_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1105
6801b0aef79db4 Pu Lehui 2024-07-02 1106 stack_size += nr_arg_slots * 8;
49b5e77ae3e214 Pu Lehui 2023-02-15 1107 args_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1108
35b3515be0ecb9 Menglong Dong 2026-02-08 1109 /* function metadata, such as regs count */
49b5e77ae3e214 Pu Lehui 2023-02-15 1110 stack_size += 8;
35b3515be0ecb9 Menglong Dong 2026-02-08 1111 func_meta_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1112
49b5e77ae3e214 Pu Lehui 2023-02-15 1113 if (flags & BPF_TRAMP_F_IP_ARG) {
49b5e77ae3e214 Pu Lehui 2023-02-15 1114 stack_size += 8;
49b5e77ae3e214 Pu Lehui 2023-02-15 1115 ip_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1116 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1117
35b3515be0ecb9 Menglong Dong 2026-02-08 @1118 cookie_cnt = bpf_fsession_cookie_cnt(tlinks);
35b3515be0ecb9 Menglong Dong 2026-02-08 1119 /* room for session cookies */
35b3515be0ecb9 Menglong Dong 2026-02-08 1120 stack_size += cookie_cnt * 8;
35b3515be0ecb9 Menglong Dong 2026-02-08 1121 cookie_off = stack_size;
35b3515be0ecb9 Menglong Dong 2026-02-08 1122
49b5e77ae3e214 Pu Lehui 2023-02-15 1123 stack_size += round_up(sizeof(struct bpf_tramp_run_ctx), 8);
49b5e77ae3e214 Pu Lehui 2023-02-15 1124 run_ctx_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1125
49b5e77ae3e214 Pu Lehui 2023-02-15 1126 stack_size += 8;
49b5e77ae3e214 Pu Lehui 2023-02-15 1127 sreg_off = stack_size;
49b5e77ae3e214 Pu Lehui 2023-02-15 1128
a5912c37faf723 Puranjay Mohan 2024-07-08 1129 if ((flags & BPF_TRAMP_F_CALL_ORIG) && (nr_arg_slots - RV_MAX_REG_ARGS > 0))
6801b0aef79db4 Pu Lehui 2024-07-02 1130 stack_size += (nr_arg_slots - RV_MAX_REG_ARGS) * 8;
6801b0aef79db4 Pu Lehui 2024-07-02 1131
e944fc8152744a Xiao Wang 2024-05-23 1132 stack_size = round_up(stack_size, STACK_ALIGN);
49b5e77ae3e214 Pu Lehui 2023-02-15 1133
6801b0aef79db4 Pu Lehui 2024-07-02 1134 /* room for args on stack must be at the top of stack */
6801b0aef79db4 Pu Lehui 2024-07-02 1135 stk_arg_off = stack_size;
6801b0aef79db4 Pu Lehui 2024-07-02 1136
1732ebc4a26181 Pu Lehui 2024-01-23 1137 if (!is_struct_ops) {
25ad10658dc106 Pu Lehui 2023-07-21 1138 /* For the trampoline called from function entry,
25ad10658dc106 Pu Lehui 2023-07-21 1139 * the frame of traced function and the frame of
25ad10658dc106 Pu Lehui 2023-07-21 1140 * trampoline need to be considered.
25ad10658dc106 Pu Lehui 2023-07-21 1141 */
25ad10658dc106 Pu Lehui 2023-07-21 1142 emit_addi(RV_REG_SP, RV_REG_SP, -16, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1143 emit_sd(RV_REG_SP, 8, RV_REG_RA, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1144 emit_sd(RV_REG_SP, 0, RV_REG_FP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1145 emit_addi(RV_REG_FP, RV_REG_SP, 16, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1146
25ad10658dc106 Pu Lehui 2023-07-21 1147 emit_addi(RV_REG_SP, RV_REG_SP, -stack_size, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1148 emit_sd(RV_REG_SP, stack_size - 8, RV_REG_T0, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1149 emit_sd(RV_REG_SP, stack_size - 16, RV_REG_FP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1150 emit_addi(RV_REG_FP, RV_REG_SP, stack_size, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1151 } else {
e63985ecd22681 Puranjay Mohan 2024-03-03 1152 /* emit kcfi hash */
e63985ecd22681 Puranjay Mohan 2024-03-03 1153 emit_kcfi(cfi_get_func_hash(func_addr), ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1154 /* For the trampoline called directly, just handle
25ad10658dc106 Pu Lehui 2023-07-21 1155 * the frame of trampoline.
25ad10658dc106 Pu Lehui 2023-07-21 1156 */
25ad10658dc106 Pu Lehui 2023-07-21 1157 emit_addi(RV_REG_SP, RV_REG_SP, -stack_size, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1158 emit_sd(RV_REG_SP, stack_size - 8, RV_REG_RA, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1159 emit_sd(RV_REG_SP, stack_size - 16, RV_REG_FP, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1160 emit_addi(RV_REG_FP, RV_REG_SP, stack_size, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1161 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1162
49b5e77ae3e214 Pu Lehui 2023-02-15 1163 /* callee saved register S1 to pass start time */
49b5e77ae3e214 Pu Lehui 2023-02-15 1164 emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1165
49b5e77ae3e214 Pu Lehui 2023-02-15 1166 /* store ip address of the traced function */
93fd420d71beed Menglong Dong 2026-02-08 1167 if (flags & BPF_TRAMP_F_IP_ARG)
93fd420d71beed Menglong Dong 2026-02-08 1168 emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1169
35b3515be0ecb9 Menglong Dong 2026-02-08 1170 func_meta = nr_arg_slots;
35b3515be0ecb9 Menglong Dong 2026-02-08 1171 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1172
6801b0aef79db4 Pu Lehui 2024-07-02 1173 store_args(nr_arg_slots, args_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1174
35b3515be0ecb9 Menglong Dong 2026-02-08 1175 if (bpf_fsession_cnt(tlinks)) {
35b3515be0ecb9 Menglong Dong 2026-02-08 1176 /* clear all session cookies' value */
35b3515be0ecb9 Menglong Dong 2026-02-08 1177 for (i = 0; i < cookie_cnt; i++)
35b3515be0ecb9 Menglong Dong 2026-02-08 1178 emit_sd(RV_REG_FP, -cookie_off + 8 * i, RV_REG_ZERO, ctx);
35b3515be0ecb9 Menglong Dong 2026-02-08 1179 /* clear return value to make sure fentry always get 0 */
35b3515be0ecb9 Menglong Dong 2026-02-08 1180 emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx);
35b3515be0ecb9 Menglong Dong 2026-02-08 1181 }
35b3515be0ecb9 Menglong Dong 2026-02-08 1182
49b5e77ae3e214 Pu Lehui 2023-02-15 1183 if (flags & BPF_TRAMP_F_CALL_ORIG) {
9f1e16fb1fc982 Pu Lehui 2024-06-22 1184 emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1185 ret = emit_call((const u64)__bpf_tramp_enter, true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1186 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1187 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 1188 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1189
35b3515be0ecb9 Menglong Dong 2026-02-08 1190 if (fentry->nr_links) {
35b3515be0ecb9 Menglong Dong 2026-02-08 1191 ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
35b3515be0ecb9 Menglong Dong 2026-02-08 1192 flags & BPF_TRAMP_F_RET_FENTRY_RET, func_meta, cookie_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1193 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1194 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 1195 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1196
49b5e77ae3e214 Pu Lehui 2023-02-15 1197 if (fmod_ret->nr_links) {
49b5e77ae3e214 Pu Lehui 2023-02-15 1198 branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
49b5e77ae3e214 Pu Lehui 2023-02-15 1199 if (!branches_off)
49b5e77ae3e214 Pu Lehui 2023-02-15 1200 return -ENOMEM;
49b5e77ae3e214 Pu Lehui 2023-02-15 1201
49b5e77ae3e214 Pu Lehui 2023-02-15 1202 /* cleanup to avoid garbage return value confusion */
49b5e77ae3e214 Pu Lehui 2023-02-15 1203 emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1204 for (i = 0; i < fmod_ret->nr_links; i++) {
49b5e77ae3e214 Pu Lehui 2023-02-15 1205 ret = invoke_bpf_prog(fmod_ret->links[i], args_off, retval_off,
49b5e77ae3e214 Pu Lehui 2023-02-15 1206 run_ctx_off, true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1207 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1208 goto out;
49b5e77ae3e214 Pu Lehui 2023-02-15 1209 emit_ld(RV_REG_T1, -retval_off, RV_REG_FP, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1210 branches_off[i] = ctx->ninsns;
49b5e77ae3e214 Pu Lehui 2023-02-15 1211 /* nop reserved for conditional jump */
49b5e77ae3e214 Pu Lehui 2023-02-15 1212 emit(rv_nop(), ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1213 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1214 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1215
49b5e77ae3e214 Pu Lehui 2023-02-15 1216 if (flags & BPF_TRAMP_F_CALL_ORIG) {
8f3e00af8e52c0 Menglong Dong 2025-12-19 1217 /* skip to actual body of traced function */
8f3e00af8e52c0 Menglong Dong 2025-12-19 1218 orig_call += RV_FENTRY_NINSNS * 4;
6801b0aef79db4 Pu Lehui 2024-07-02 1219 restore_args(min_t(int, nr_arg_slots, RV_MAX_REG_ARGS), args_off, ctx);
6801b0aef79db4 Pu Lehui 2024-07-02 1220 restore_stack_args(nr_arg_slots - RV_MAX_REG_ARGS, args_off, stk_arg_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1221 ret = emit_call((const u64)orig_call, true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1222 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1223 goto out;
49b5e77ae3e214 Pu Lehui 2023-02-15 1224 emit_sd(RV_REG_FP, -retval_off, RV_REG_A0, ctx);
7112cd26e606c7 Björn Töpel 2023-10-04 1225 emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx);
2382a405c581ae Pu Lehui 2024-06-22 1226 im->ip_after_call = ctx->ro_insns + ctx->ninsns;
49b5e77ae3e214 Pu Lehui 2023-02-15 1227 /* 2 nops reserved for auipc+jalr pair */
49b5e77ae3e214 Pu Lehui 2023-02-15 1228 emit(rv_nop(), ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1229 emit(rv_nop(), ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1230 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1231
49b5e77ae3e214 Pu Lehui 2023-02-15 1232 /* update branches saved in invoke_bpf_mod_ret with bnez */
49b5e77ae3e214 Pu Lehui 2023-02-15 1233 for (i = 0; ctx->insns && i < fmod_ret->nr_links; i++) {
49b5e77ae3e214 Pu Lehui 2023-02-15 1234 offset = ninsns_rvoff(ctx->ninsns - branches_off[i]);
49b5e77ae3e214 Pu Lehui 2023-02-15 1235 insn = rv_bne(RV_REG_T1, RV_REG_ZERO, offset >> 1);
49b5e77ae3e214 Pu Lehui 2023-02-15 1236 *(u32 *)(ctx->insns + branches_off[i]) = insn;
49b5e77ae3e214 Pu Lehui 2023-02-15 1237 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1238
35b3515be0ecb9 Menglong Dong 2026-02-08 1239 /* set "is_return" flag for fsession */
35b3515be0ecb9 Menglong Dong 2026-02-08 1240 func_meta |= (1ULL << BPF_TRAMP_IS_RETURN_SHIFT);
35b3515be0ecb9 Menglong Dong 2026-02-08 1241 if (bpf_fsession_cnt(tlinks))
35b3515be0ecb9 Menglong Dong 2026-02-08 1242 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
35b3515be0ecb9 Menglong Dong 2026-02-08 1243
35b3515be0ecb9 Menglong Dong 2026-02-08 1244 if (fexit->nr_links) {
35b3515be0ecb9 Menglong Dong 2026-02-08 1245 ret = invoke_bpf(fexit, args_off, retval_off, run_ctx_off, func_meta_off,
35b3515be0ecb9 Menglong Dong 2026-02-08 1246 false, func_meta, cookie_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1247 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1248 goto out;
49b5e77ae3e214 Pu Lehui 2023-02-15 1249 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1250
49b5e77ae3e214 Pu Lehui 2023-02-15 1251 if (flags & BPF_TRAMP_F_CALL_ORIG) {
2382a405c581ae Pu Lehui 2024-06-22 1252 im->ip_epilogue = ctx->ro_insns + ctx->ninsns;
9f1e16fb1fc982 Pu Lehui 2024-06-22 1253 emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1254 ret = emit_call((const u64)__bpf_tramp_exit, true, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1255 if (ret)
49b5e77ae3e214 Pu Lehui 2023-02-15 1256 goto out;
49b5e77ae3e214 Pu Lehui 2023-02-15 1257 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1258
49b5e77ae3e214 Pu Lehui 2023-02-15 1259 if (flags & BPF_TRAMP_F_RESTORE_REGS)
6801b0aef79db4 Pu Lehui 2024-07-02 1260 restore_args(min_t(int, nr_arg_slots, RV_MAX_REG_ARGS), args_off, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1261
7112cd26e606c7 Björn Töpel 2023-10-04 1262 if (save_ret) {
7112cd26e606c7 Björn Töpel 2023-10-04 1263 emit_ld(regmap[BPF_REG_0], -(retval_off - 8), RV_REG_FP, ctx);
fd2e08128944a7 Hengqi Chen 2025-09-08 1264 if (is_struct_ops) {
fd2e08128944a7 Hengqi Chen 2025-09-08 1265 ret = sign_extend(RV_REG_A0, regmap[BPF_REG_0], m->ret_size,
fd2e08128944a7 Hengqi Chen 2025-09-08 1266 m->ret_flags & BTF_FMODEL_SIGNED_ARG, ctx);
fd2e08128944a7 Hengqi Chen 2025-09-08 1267 if (ret)
fd2e08128944a7 Hengqi Chen 2025-09-08 1268 goto out;
fd2e08128944a7 Hengqi Chen 2025-09-08 1269 } else {
fd2e08128944a7 Hengqi Chen 2025-09-08 1270 emit_ld(RV_REG_A0, -retval_off, RV_REG_FP, ctx);
fd2e08128944a7 Hengqi Chen 2025-09-08 1271 }
7112cd26e606c7 Björn Töpel 2023-10-04 1272 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1273
49b5e77ae3e214 Pu Lehui 2023-02-15 1274 emit_ld(RV_REG_S1, -sreg_off, RV_REG_FP, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1275
1732ebc4a26181 Pu Lehui 2024-01-23 1276 if (!is_struct_ops) {
25ad10658dc106 Pu Lehui 2023-07-21 1277 /* trampoline called from function entry */
25ad10658dc106 Pu Lehui 2023-07-21 1278 emit_ld(RV_REG_T0, stack_size - 8, RV_REG_SP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1279 emit_ld(RV_REG_FP, stack_size - 16, RV_REG_SP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1280 emit_addi(RV_REG_SP, RV_REG_SP, stack_size, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1281
25ad10658dc106 Pu Lehui 2023-07-21 1282 emit_ld(RV_REG_RA, 8, RV_REG_SP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1283 emit_ld(RV_REG_FP, 0, RV_REG_SP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1284 emit_addi(RV_REG_SP, RV_REG_SP, 16, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1285
49b5e77ae3e214 Pu Lehui 2023-02-15 1286 if (flags & BPF_TRAMP_F_SKIP_FRAME)
25ad10658dc106 Pu Lehui 2023-07-21 1287 /* return to parent function */
25ad10658dc106 Pu Lehui 2023-07-21 1288 emit_jalr(RV_REG_ZERO, RV_REG_RA, 0, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1289 else
25ad10658dc106 Pu Lehui 2023-07-21 1290 /* return to traced function */
25ad10658dc106 Pu Lehui 2023-07-21 1291 emit_jalr(RV_REG_ZERO, RV_REG_T0, 0, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1292 } else {
25ad10658dc106 Pu Lehui 2023-07-21 1293 /* trampoline called directly */
25ad10658dc106 Pu Lehui 2023-07-21 1294 emit_ld(RV_REG_RA, stack_size - 8, RV_REG_SP, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1295 emit_ld(RV_REG_FP, stack_size - 16, RV_REG_SP, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1296 emit_addi(RV_REG_SP, RV_REG_SP, stack_size, ctx);
49b5e77ae3e214 Pu Lehui 2023-02-15 1297
49b5e77ae3e214 Pu Lehui 2023-02-15 1298 emit_jalr(RV_REG_ZERO, RV_REG_RA, 0, ctx);
25ad10658dc106 Pu Lehui 2023-07-21 1299 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1300
49b5e77ae3e214 Pu Lehui 2023-02-15 1301 ret = ctx->ninsns;
49b5e77ae3e214 Pu Lehui 2023-02-15 1302 out:
49b5e77ae3e214 Pu Lehui 2023-02-15 1303 kfree(branches_off);
49b5e77ae3e214 Pu Lehui 2023-02-15 1304 return ret;
49b5e77ae3e214 Pu Lehui 2023-02-15 1305 }
49b5e77ae3e214 Pu Lehui 2023-02-15 1306
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH 3/4] mm: convert compaction to zone lock wrappers
From: Cheatham, Benjamin @ 2026-02-20 19:10 UTC (permalink / raw)
To: Dmitry Ilvokhin
Cc: linux-kernel, linux-mm, linux-trace-kernel, linux-cxl,
kernel-team, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Brendan Jackman,
Johannes Weiner, Zi Yan, Oscar Salvador, Qi Zheng, Shakeel Butt,
Axel Rasmussen, Yuanchu Xie, Wei Xu
In-Reply-To: <3462b7fd26123c69ccdd121a894da14bbfafdd9d.1770821420.git.d@ilvokhin.com>
On 2/11/2026 9:22 AM, Dmitry Ilvokhin wrote:
> Compaction uses compact_lock_irqsave(), which currently operates
> on a raw spinlock_t pointer so that it can be used for both
> zone->lock and lru_lock. Since zone lock operations are now wrapped,
> compact_lock_irqsave() can no longer operate directly on a spinlock_t
> when the lock belongs to a zone.
>
> Introduce struct compact_lock to abstract the underlying lock type. The
> structure carries a lock type enum and a union holding either a zone
> pointer or a raw spinlock_t pointer, and dispatches to the appropriate
> lock/unlock helper.
>
> No functional change intended.
>
> Signed-off-by: Dmitry Ilvokhin <d@ilvokhin.com>
> ---
> mm/compaction.c | 108 +++++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 89 insertions(+), 19 deletions(-)
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 1e8f8eca318c..1b000d2b95b2 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -24,6 +24,7 @@
> #include <linux/page_owner.h>
> #include <linux/psi.h>
> #include <linux/cpuset.h>
> +#include <linux/zone_lock.h>
> #include "internal.h"
>
> #ifdef CONFIG_COMPACTION
> @@ -493,6 +494,65 @@ static bool test_and_set_skip(struct compact_control *cc, struct page *page)
> }
> #endif /* CONFIG_COMPACTION */
>
> +enum compact_lock_type {
> + COMPACT_LOCK_ZONE,
> + COMPACT_LOCK_RAW_SPINLOCK,
> +};
> +
> +struct compact_lock {
> + enum compact_lock_type type;
> + union {
> + struct zone *zone;
> + spinlock_t *lock; /* Reference to lru lock */
> + };
> +};
> +
> +static bool compact_do_zone_trylock_irqsave(struct zone *zone,
> + unsigned long *flags)
> +{
> + return zone_trylock_irqsave(zone, *flags);
> +}
> +
> +static bool compact_do_raw_trylock_irqsave(spinlock_t *lock,
> + unsigned long *flags)
> +{
> + return spin_trylock_irqsave(lock, *flags);
> +}
> +
> +static bool compact_do_trylock_irqsave(struct compact_lock lock,
> + unsigned long *flags)
> +{
> + if (lock.type == COMPACT_LOCK_ZONE)
> + return compact_do_zone_trylock_irqsave(lock.zone, flags);
> +
> + return compact_do_raw_trylock_irqsave(lock.lock, flags);
> +}
Nit: You could remove the helpers above and just do the calls directly in this function, though
it would remove the parity with the compact helpers. compact_do_lock_irqsave() helpers can stay
since they have the __acquires() annotations.
> +
> +static void compact_do_zone_lock_irqsave(struct zone *zone,
> + unsigned long *flags)
> +__acquires(zone->lock)
> +{
> + zone_lock_irqsave(zone, *flags);
> +}
> +
> +static void compact_do_raw_lock_irqsave(spinlock_t *lock,
> + unsigned long *flags)
> +__acquires(lock)
> +{
> + spin_lock_irqsave(lock, *flags);
> +}
> +
> +static void compact_do_lock_irqsave(struct compact_lock lock,
> + unsigned long *flags)
> +{
> + if (lock.type == COMPACT_LOCK_ZONE) {
> + compact_do_zone_lock_irqsave(lock.zone, flags);
> + return;
> + }
> +
> + return compact_do_raw_lock_irqsave(lock.lock, flags);
You don't need the return statement here (and you shouldn't be returning a value at all).
It may be cleaner to just do an if-else statement here instead.
> +}
> +
> /*
> * Compaction requires the taking of some coarse locks that are potentially
> * very heavily contended. For async compaction, trylock and record if the
> @@ -502,19 +562,19 @@ static bool test_and_set_skip(struct compact_control *cc, struct page *page)
> *
> * Always returns true which makes it easier to track lock state in callers.
> */
> -static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
> - struct compact_control *cc)
> - __acquires(lock)
> +static bool compact_lock_irqsave(struct compact_lock lock,
> + unsigned long *flags,
> + struct compact_control *cc)
> {
> /* Track if the lock is contended in async mode */
> if (cc->mode == MIGRATE_ASYNC && !cc->contended) {
> - if (spin_trylock_irqsave(lock, *flags))
> + if (compact_do_trylock_irqsave(lock, flags))
> return true;
>
> cc->contended = true;
> }
>
> - spin_lock_irqsave(lock, *flags);
> + compact_do_lock_irqsave(lock, flags);
> return true;
> }
>
> @@ -530,11 +590,13 @@ static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
> * Returns true if compaction should abort due to fatal signal pending.
> * Returns false when compaction can continue.
> */
> -static bool compact_unlock_should_abort(spinlock_t *lock,
> - unsigned long flags, bool *locked, struct compact_control *cc)
> +static bool compact_unlock_should_abort(struct zone *zone,
> + unsigned long flags,
> + bool *locked,
> + struct compact_control *cc)
> {
> if (*locked) {
> - spin_unlock_irqrestore(lock, flags);
> + zone_unlock_irqrestore(zone, flags);
I would move this (and other wrapper changes below that don't use compact_*) to the last patch. I understand you
didn't change it due to location but I would argue it isn't really relevant to what's being added in this patch
and fits better in the last.
> *locked = false;
> }
>
> @@ -582,9 +644,8 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
> * contention, to give chance to IRQs. Abort if fatal signal
> * pending.
> */
> - if (!(blockpfn % COMPACT_CLUSTER_MAX)
> - && compact_unlock_should_abort(&cc->zone->lock, flags,
> - &locked, cc))
> + if (!(blockpfn % COMPACT_CLUSTER_MAX) &&
> + compact_unlock_should_abort(cc->zone, flags, &locked, cc))
> break;
>
> nr_scanned++;
> @@ -613,8 +674,12 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
>
> /* If we already hold the lock, we can skip some rechecking. */
> if (!locked) {
> - locked = compact_lock_irqsave(&cc->zone->lock,
> - &flags, cc);
> + struct compact_lock zol = {
> + .type = COMPACT_LOCK_ZONE,
> + .zone = cc->zone,
> + };
> +
> + locked = compact_lock_irqsave(zol, &flags, cc);
>
> /* Recheck this is a buddy page under lock */
> if (!PageBuddy(page))
> @@ -649,7 +714,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
> }
>
> if (locked)
> - spin_unlock_irqrestore(&cc->zone->lock, flags);
> + zone_unlock_irqrestore(cc->zone, flags);
>
> /*
> * Be careful to not go outside of the pageblock.
> @@ -1157,10 +1222,15 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>
> /* If we already hold the lock, we can skip some rechecking */
> if (lruvec != locked) {
> + struct compact_lock zol = {
> + .type = COMPACT_LOCK_RAW_SPINLOCK,
> + .lock = &lruvec->lru_lock,
> + };
> +
> if (locked)
> unlock_page_lruvec_irqrestore(locked, flags);
>
> - compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
> + compact_lock_irqsave(zol, &flags, cc);
> locked = lruvec;
>
> lruvec_memcg_debug(lruvec, folio);
> @@ -1555,7 +1625,7 @@ static void fast_isolate_freepages(struct compact_control *cc)
> if (!area->nr_free)
> continue;
>
> - spin_lock_irqsave(&cc->zone->lock, flags);
> + zone_lock_irqsave(cc->zone, flags);
> freelist = &area->free_list[MIGRATE_MOVABLE];
> list_for_each_entry_reverse(freepage, freelist, buddy_list) {
> unsigned long pfn;
> @@ -1614,7 +1684,7 @@ static void fast_isolate_freepages(struct compact_control *cc)
> }
> }
>
> - spin_unlock_irqrestore(&cc->zone->lock, flags);
> + zone_unlock_irqrestore(cc->zone, flags);
>
> /* Skip fast search if enough freepages isolated */
> if (cc->nr_freepages >= cc->nr_migratepages)
> @@ -1988,7 +2058,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
> if (!area->nr_free)
> continue;
>
> - spin_lock_irqsave(&cc->zone->lock, flags);
> + zone_lock_irqsave(cc->zone, flags);
> freelist = &area->free_list[MIGRATE_MOVABLE];
> list_for_each_entry(freepage, freelist, buddy_list) {
> unsigned long free_pfn;
> @@ -2021,7 +2091,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
> break;
> }
> }
> - spin_unlock_irqrestore(&cc->zone->lock, flags);
> + zone_unlock_irqrestore(cc->zone, flags);
> }
>
> cc->total_migrate_scanned += nr_scanned;
^ permalink raw reply
* Re: [PATCH 0/4] mm: zone lock tracepoint instrumentation
From: Cheatham, Benjamin @ 2026-02-20 19:09 UTC (permalink / raw)
To: Dmitry Ilvokhin
Cc: linux-kernel, linux-mm, linux-trace-kernel, linux-cxl,
kernel-team, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Brendan Jackman,
Johannes Weiner, Zi Yan, Oscar Salvador, Qi Zheng, Shakeel Butt,
Axel Rasmussen, Yuanchu Xie, Wei Xu
In-Reply-To: <cover.1770821420.git.d@ilvokhin.com>
On 2/11/2026 9:22 AM, Dmitry Ilvokhin wrote:
> Zone lock contention can significantly impact allocation and
> reclaim latency, as it is a central synchronization point in
> the page allocator and reclaim paths. Improved visibility into
> its behavior is therefore important for diagnosing performance
> issues in memory-intensive workloads.
>
> On some production workloads at Meta, we have observed noticeable
> zone lock contention. Deeper analysis of lock holders and waiters
> is currently difficult with existing instrumentation.
>
> While generic lock contention_begin/contention_end tracepoints
> cover the slow path, they do not provide sufficient visibility
> into lock hold times. In particular, the lack of a release-side
> event makes it difficult to identify long lock holders and
> correlate them with waiters. As a result, distinguishing between
> short bursts of contention and pathological long hold times
> requires additional instrumentation.
>
> This patch series adds dedicated tracepoint instrumentation to
> zone lock, following the existing mmap_lock tracing model.
>
> The goal is to enable detailed holder/waiter analysis and lock
> hold time measurements without affecting the fast path when
> tracing is disabled.
>
> The series is structured as follows:
>
> 1. Introduce zone lock wrappers.
> 2. Mechanically convert zone lock users to the wrappers.
> 3. Convert compaction to use the wrappers (requires minor
> restructuring of compact_lock_irqsave()).
> 4. Add zone lock tracepoints.
I think you can improve the flow of this series if reorder as follows:
1. Introduce zone lock wrappers
4. Add zone lock tracepoints
2. Mechanically convert zone lock users to the wrappers
3. Convert compaction to use the wrappers...
and possibly squash 1 & 4 (though that might be too big of a patch). It's better to introduce the
wrappers and their tracepoints together before the reviewer (i.e. me) forgets what was added in
patch 1 by the time they get to patch 4.
Thanks,
Ben
^ permalink raw reply
* Re: [PATCH 1/2] x86: Prevent syscall hooking
From: Steven Rostedt @ 2026-02-20 17:12 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Masami Hiramatsu, Kees Cook, Dave Hansen, Elly I. Esparza,
linux-kernel, luto, tglx, mingo, bp, dave.hansen, x86, hpa,
Naveen N Rao, David S. Miller, linux-trace-kernel
In-Reply-To: <aZiUJ--WJygUU6QP@infradead.org>
On Fri, 20 Feb 2026 09:04:39 -0800
Christoph Hellwig <hch@infradead.org> wrote:
> > Agreed. The blacklist (or blocklist) of kprobes is designed for preventing
> > nesting software breakpoint handling, not for security.
>
> It still can be useful. As mention in the other thread, we just need
> to make it clear. I.e. add something like "noprobe_for_security".
> And if we really, really care it could be conditional on a config
> option.
As I already mentioned, we have the LOCKDOWN infrastructure for that. If
you care about security of kprobes, use lockdown to disable it. As
previously stated, there's 1000 other ways kprobes can get this same
information. Adding a "noprobe_for_security" will lead to a false sense of
security. Basically the same as leaving your car unlocked and hiding the
keys in the visor and thinking nobody will steal your car.
-- Steve
^ permalink raw reply
* Re: [PATCH 1/2] x86: Prevent syscall hooking
From: Christoph Hellwig @ 2026-02-20 17:04 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Kees Cook, Steven Rostedt, Dave Hansen, Elly I. Esparza,
linux-kernel, luto, tglx, mingo, bp, dave.hansen, x86, hpa,
Naveen N Rao, David S. Miller, linux-trace-kernel
In-Reply-To: <20260220114540.fbee78a9a8b8097ec729451c@kernel.org>
On Fri, Feb 20, 2026 at 11:45:40AM +0900, Masami Hiramatsu wrote:
> On Thu, 19 Feb 2026 10:45:02 -0800
> Kees Cook <kees@kernel.org> wrote:
>
> > On Wed, Feb 18, 2026 at 10:52:04AM -0500, Steven Rostedt wrote:
> > > Honesty, if you are worried about this, just run LOCKDOWN on tracing, and
> > > prevent *ALL* kprobes. Because yes, there's a 1000 ways to get this
> > > information once you have kprobes enabled and have root access. This patch
> > > is hurting legitimate debugging of running systems more than it is limiting
> > > rootkits from hacking the kernel.
> >
> > Yeah, I agree. If kprobes is available, there is a lot of harm an
> > attacker can already do. If a bright line between root/ring-0 is
> > desired, a system needs to be configured to be using lockdown or similar
> > things to turn off the interfaces that let root write to kernel state.
>
> Agreed. The blacklist (or blocklist) of kprobes is designed for preventing
> nesting software breakpoint handling, not for security.
It still can be useful. As mention in the other thread, we just need
to make it clear. I.e. add something like "noprobe_for_security".
And if we really, really care it could be conditional on a config
option.
^ permalink raw reply
* Re: [PATCH] mm/tracing: rss_stat: Ensure curr is false from kthread context
From: Pedro Falcato @ 2026-02-20 11:07 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, rostedt, joel, kernel-team, android-mm,
David Hildenbrand (Arm), Lorenzo Stoakes, Minchan Kim,
Suren Baghdasaryan, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Masami Hiramatsu, Mathieu Desnoyers,
Jann Horn, Martin Liu, David Rientjes, Zi Yan,
Wander Lairson Costa, Petr Mladek, linux-mm, linux-kernel,
linux-trace-kernel
In-Reply-To: <20260219233708.1971199-1-kaleshsingh@google.com>
On Thu, Feb 19, 2026 at 03:36:56PM -0800, Kalesh Singh wrote:
> The rss_stat trace event allows userspace tools, like Perfetto [1],
> to inspect per-process RSS metric changes over time.
>
> The curr field was introduced to rss_stat in commit e4dcad204d3a
> ("rss_stat: add support to detect RSS updates of external mm").
> It's intent is to indicate whether the RSS update is for the
> mm_struct of the current execution context; and is set to false
> when operating on a remote mm_struct (e.g., via kswapd or a
> direct reclaimer).
>
> However, an issue arises when a kernel thread temporarily adopts
> a user process's mm_struct. Kernel threads do not have their own
> mm_struct and normally have current->mm set to NULL. To operate
> on user memory, they can "borrow" a memory context using
> kthread_use_mm(), which sets current->mm to the user process's mm.
>
> This can be observed, for example, in the USB Function Filesystem
> (FFS) driver. The ffs_user_copy_worker() handles AIO completions
> and uses kthread_use_mm() to copy data to a user-space buffer.
> If a page fault occurs during this copy, the fault handler executes
> in the kthread's context.
>
> At this point, current is the kthread, but current->mm points to the
> user process's mm. Since the rss_stat event (from the page fault)
> is for that same mm, the condition current->mm == mm becomes true,
> causing curr to be incorrectly set to true when the trace event is
> emitted.
>
> This is misleading because it suggests the mm belongs to the kthread,
> confusing userspace tools that track per-process RSS changes and
> corrupting their mm_id-to-process association.
>
> Fix this by ensuring curr is always false when the trace event is
> emitted from a kthread context by checking for the PF_KTHREAD flag.
>
> [1] https://perfetto.dev/
>
> Fixes: e4dcad204d3a ("rss_stat: add support to detect RSS updates of external mm")
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: "David Hildenbrand (Arm)" <david@kernel.org>
> Cc: Joel Fernandes <joel@joelfernandes.org>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Looks cromulent, thanks :)
--
Pedro
^ permalink raw reply
* Re: [PATCH bpf-next 04/17] bpf: Add struct bpf_tramp_node object
From: bot+bpf-ci @ 2026-02-20 10:58 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-5-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
[ ... ]
> +struct bpf_tramp_node {
> + struct bpf_link *link;
> + struct hlist_node tramp_hlist;
> + u64 cookie;
> +};
During the RFC review, Andrii Nakryiko suggested that instead of
co-locating a prog/link pointer in bpf_tramp_node, the JIT functions
like invoke_bpf_prog() could accept the prog pointer as a separate
argument, keeping bpf_tramp_node to just {tramp_hlist, cookie}:
https://lore.kernel.org/bpf/CAEf4BzY=vqpnjrDNtLVvC3_nU5=Z7iROU_He=xbkEJDuGCoqug@mail.gmail.com/
The RFC had `struct bpf_prog *prog` in bpf_tramp_node and this v1
changed it to `struct bpf_link *link`, which still co-locates the
path to the program inside the node. Was the refactoring to pass
prog separately to invoke_bpf_prog() considered and ruled out, or
is that planned for a follow-up?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Mechanical refactoring with lore history dating back to 2021, consistent with the author's known kernel development style and iterative review process.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Unaddressed RFC review comment from maintainer about struct design; not a code bug but a design concern about co-locating link pointer in bpf_tramp_node.
^ permalink raw reply
* Re: [PATCH bpf-next 08/17] bpf: Add support for tracing multi link
From: bot+bpf-ci @ 2026-02-20 10:57 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-9-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2573 bytes --]
> diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
> --- a/include/linux/bpf_types.h
> +++ b/include/linux/bpf_types.h
[ ... ]
> +BPF_LINK_TYPE(BPF_LINK_TYPE_TRACING_MULTI, tracing)
The existing BPF_LINK_TYPE_TRACING also uses "tracing" as its name
argument:
BPF_LINK_TYPE(BPF_LINK_TYPE_TRACING, tracing)
This means bpf_link_type_strs[] will contain "tracing" for both
BPF_LINK_TYPE_TRACING and BPF_LINK_TYPE_TRACING_MULTI, making them
indistinguishable in fdinfo output via bpf_link_show_fdinfo().
The libbpf side correctly uses "tracing_multi":
[BPF_LINK_TYPE_TRACING_MULTI] = "tracing_multi",
Should this be BPF_LINK_TYPE(BPF_LINK_TYPE_TRACING_MULTI, tracing_multi)
to match?
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
[ ... ]
> +int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
> +{
[ ... ]
> + ids = kvmalloc_array(cnt, sizeof(*ids), GFP_KERNEL);
[ ... ]
> + link = kzalloc(struct_size(link, nodes, cnt), GFP_KERNEL);
^^^^^^
The ids array above uses kvmalloc_array() to handle large allocations,
but the link struct uses kzalloc(). With MAX_TRACING_MULTI_CNT at 1M
and each bpf_tracing_multi_node being roughly 40 bytes,
struct_size() can request up to ~40MB of contiguous memory. kzalloc()
is limited to KMALLOC_MAX_SIZE (~4MB on x86_64), so this will fail
for cnt values above roughly 100K.
Would kvzalloc() work here instead? bpf_tracing_multi_link_dealloc()
would need to use kvfree() accordingly:
> +static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
> +{
> + struct bpf_tracing_multi_link *tr_link =
> + container_of(link, struct bpf_tracing_multi_link, link);
> +
> + kfree(tr_link);
^^^^^
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Code follows established BPF subsystem patterns and Jiri Olsa's terse kernel commit style, with no AI-characteristic verbosity or over-documentation.
issues-found: 2
issue-severity-score: low
issue-severity-explanation: BPF_LINK_TYPE naming collision makes fdinfo output ambiguous between tracing and tracing_multi link types, and kzalloc limits the flex-array link allocation well below the advertised MAX_TRACING_MULTI_CNT; neither causes crashes or data corruption.
^ permalink raw reply
* Re: [PATCH bpf-next 10/17] bpf: Add support for tracing_multi link session
From: bot+bpf-ci @ 2026-02-20 10:57 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-11-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2732 bytes --]
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 5892dca20b7e..1cd6c1457bd3 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -3611,6 +3611,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
> if (prog->expected_attach_type != BPF_TRACE_FENTRY &&
> prog->expected_attach_type != BPF_TRACE_FEXIT &&
> prog->expected_attach_type != BPF_TRACE_FSESSION &&
> + prog->expected_attach_type != BPF_TRACE_FSESSION_MULTI &&
> prog->expected_attach_type != BPF_TRACE_FENTRY_MULTI &&
> prog->expected_attach_type != BPF_TRACE_FEXIT_MULTI &&
> prog->expected_attach_type != BPF_MODIFY_RETURN) {
BPF_TRACE_FSESSION_MULTI is now accepted here, which means
a program with this type can enter bpf_tracing_prog_attach()
via BPF_RAW_TRACEPOINT_OPEN:
bpf_raw_tracepoint_open()
bpf_raw_tp_link_attach() /* name == NULL */
bpf_tracing_prog_attach() /* BPF_TRACE_FSESSION_MULTI */
Further down in bpf_tracing_prog_attach(), the fexit node
initialization only checks for BPF_TRACE_FSESSION:
kernel/bpf/syscall.c:bpf_tracing_prog_attach() {
...
if (prog->expected_attach_type == BPF_TRACE_FSESSION) {
link->fexit.link = &link->link.link;
link->fexit.cookie = bpf_cookie;
}
...
}
So for BPF_TRACE_FSESSION_MULTI, link->fexit.link stays NULL
(from kzalloc). When __bpf_trampoline_link_prog() later calls
fsession_exit(), it returns &link->fexit with a NULL link
field. This node gets added to the trampoline FEXIT list, and
bpf_trampoline_get_progs() then dereferences it:
kernel/bpf/trampoline.c:bpf_trampoline_get_progs() {
...
hlist_for_each_entry(node, &tr->progs_hlist[kind], tramp_hlist) {
*ip_arg |= node->link->prog->call_get_func_ip;
^^^^^^^^^^
...
}
Would it make sense to either add BPF_TRACE_FSESSION_MULTI to
the fexit initialization, or reject this type in
bpf_tracing_prog_attach() since it should only be used through
bpf_tracing_multi_attach()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Code follows established kernel BPF patterns for adding new attach types, written by a well-known BPF maintainer with terse, practical commit message style.
issues-found: 1
issue-severity-score: high
issue-severity-explanation: NULL pointer dereference reachable from BPF_RAW_TRACEPOINT_OPEN syscall when BPF_TRACE_FSESSION_MULTI enters bpf_tracing_prog_attach without fexit initialization, leading to kernel crash.
^ permalink raw reply
* Re: [PATCH bpf-next 07/17] bpf: Add bpf_trampoline_multi_attach/detach functions
From: bot+bpf-ci @ 2026-02-20 10:57 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-8-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 4511 bytes --]
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 2d701bc6e1a5..c32205adfebe 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
[ ... ]
> +static int unregister_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, void *old_addr,
> + void *ptr)
> +{
> + unsigned long addr = (unsigned long) old_addr;
> + unsigned long ip = ftrace_location(tr->ip);
> + struct fentry_multi_data *data = ptr;
> +
> + if (bpf_trampoline_use_jmp(tr->flags))
> + addr = ftrace_jmp_set(addr);
> + return add_ftrace_hash_entry_direct(data->unreg, ip, addr) ? 0 : -ENOMEM;
> +}
[ ... ]
> +int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
> + struct bpf_tracing_multi_link *link)
> +{
> + struct bpf_attach_target_info tgt_info = {};
> + struct bpf_tracing_multi_node *mnode;
> + int j, i, err, cnt = link->nodes_cnt;
> + struct fentry_multi_data data = {};
> + struct bpf_trampoline *tr;
> + u64 key;
> +
> + data.reg = alloc_ftrace_hash(FTRACE_HASH_DEFAULT_BITS);
> + if (!data.reg)
> + return -ENOMEM;
> +
> + data.modify = alloc_ftrace_hash(FTRACE_HASH_DEFAULT_BITS);
> + if (!data.modify) {
> + free_ftrace_hash(data.reg);
> + return -ENOMEM;
> + }
data.unreg is left as NULL here. In the forward path this is
fine since only data.reg and data.modify are used, but the
rollback path can reach unregister_fentry_multi() which calls
add_ftrace_hash_entry_direct(data->unreg, ...) with a NULL hash.
This happens when rollback_unlink calls
__bpf_trampoline_unlink_prog() on a trampoline that had no
other BPF programs before this attach. Removing the only
program brings total to 0, so bpf_trampoline_update_ops()
calls ops->unregister_fentry, reaching:
unregister_fentry_multi()
add_ftrace_hash_entry_direct(data->unreg, ip, addr)
__add_hash_entry(hash, entry)
ftrace_hash_key(hash, ...) <-- NULL dereference
Should data.unreg also be allocated here to cover the rollback
path?
> +
> + for (i = 0; i < cnt; i++) {
> + mnode = &link->nodes[i];
> + err = bpf_check_attach_target(NULL, prog, NULL, ids[i], &tgt_info);
> + if (err)
> + goto rollback_put;
> +
> + key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, ids[i]);
> +
> + tr = bpf_trampoline_get(key, &tgt_info);
> + if (!tr) {
> + err = -ENOMEM;
> + goto rollback_put;
> + }
> +
> + mnode->trampoline = tr;
> + mnode->node.link = &link->link;
> + }
After this loop completes, all cnt trampolines have been
obtained via bpf_trampoline_get() with refcounts incremented.
> +
> + trampoline_lock_all();
> +
> + for (i = 0; i < cnt; i++) {
> + mnode = &link->nodes[i];
> + err = __bpf_trampoline_link_prog(&mnode->node, mnode->trampoline, NULL,
> + &trampoline_multi_ops, &data);
> + if (err)
> + goto rollback_unlink;
> + }
[ ... ]
> +rollback_unlink:
> + for (j = 0; j < i; j++) {
> + mnode = &link->nodes[j];
> + WARN_ON_ONCE(__bpf_trampoline_unlink_prog(&mnode->node, mnode->trampoline,
> + NULL, &trampoline_multi_ops, &data));
> + }
> + trampoline_unlock_all();
> +
> +rollback_put:
> + for (j = 0; j < i; j++)
> + bpf_trampoline_put(link->nodes[j].trampoline);
When __bpf_trampoline_link_prog() fails at index i in the
second loop, this falls through from rollback_unlink to
rollback_put with i still set to the failing index. But all
cnt trampolines were obtained in the first loop above.
The rollback_put loop only puts trampolines 0..i-1, leaving
trampolines i..cnt-1 with elevated refcounts that are never
released.
When rollback_put is reached directly from the first loop
(bpf_trampoline_get or bpf_check_attach_target failure), the
j < i bound is correct since only 0..i-1 were obtained.
Could the rollback_unlink path set i = cnt before falling
through, or use a separate loop bound for the put?
> +
> + free_fentry_multi_data(&data);
> + return err;
> +}
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Natural kernel development style from a known BPF maintainer, with human-typical error handling oversights in batch operation code.
issues-found: 2
issue-severity-score: high
issue-severity-explanation: NULL pointer dereference in error rollback path causes kernel crash, combined with trampoline refcount leak preventing resource cleanup.
^ permalink raw reply
* Re: [PATCH bpf-next 11/17] libbpf: Add support to create tracing multi link
From: bot+bpf-ci @ 2026-02-20 10:57 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-12-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 5176 bytes --]
> The provided <pattern> is used as 'pattern' argument in
> bpf_program__attach_kprobe_multi_opts function.
This isn't a bug, but the commit message references
bpf_program__attach_kprobe_multi_opts when the code actually calls
bpf_program__attach_tracing_multi. Looks like a leftover from
the kprobe_multi code this was modeled after.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> +struct bpf_link *
> +bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pattern,
> + const struct bpf_tracing_multi_opts *opts)
> +{
> + LIBBPF_OPTS(bpf_link_create_opts, lopts);
> + __u32 *ids, cnt, *free_ids = NULL;
cnt is declared as __u32 here, but collect_btf_func_ids_by_glob()
returns int. When that function returns a negative error such as
-ENOMEM, the value wraps to a large unsigned number.
> + __u64 *cookies;
> + int prog_fd, link_fd, err;
> + struct bpf_link *link;
[ ... ]
> + if (pattern) {
> + err = bpf_object__load_vmlinux_btf(prog->obj, true);
> + if (err)
> + return libbpf_err_ptr(err);
> +
> + cnt = collect_btf_func_ids_by_glob(prog->obj->btf_vmlinux, pattern, &ids);
> + if (cnt < 0)
> + return libbpf_err_ptr(cnt);
Since cnt is __u32, this comparison is always false. On an allocation
failure inside collect_btf_func_ids_by_glob(), the error is silently
ignored. That function also does free(*ids) before returning -ENOMEM,
so ids becomes a dangling pointer. The code then continues with a
freed ids pointer and a garbage cnt, and eventually double-frees ids
through the error label via free_ids.
Should cnt be declared as int instead of __u32?
> + if (cnt == 0)
> + return libbpf_err_ptr(-EINVAL);
> + free_ids = ids;
> + }
[ ... ]
> +error:
> + free(link);
> + free(free_ids);
> + return libbpf_err_ptr(err);
> +}
> +
> +static int attach_tracing_multi(const struct bpf_program *prog, long cookie, struct bpf_link **link)
> +{
> + bool is_fexit, is_fsession;
> + const char *spec;
> + char *pattern;
> + int n;
> +
> + /* Do not allow auto attach if there's no function pattern. */
> + if (strcmp(prog->sec_name, "fentry.multi") == 0 ||
> + strcmp(prog->sec_name, "fexit.multi") == 0 ||
> + strcmp(prog->sec_name, "fsession.multi") == 0 ||
> + strcmp(prog->sec_name, "fentry.multi.s") == 0 ||
> + strcmp(prog->sec_name, "fexit.multi.s") == 0 ||
> + strcmp(prog->sec_name, "fsession.multi.s") == 0)
> + return 0;
> +
> + is_fexit = str_has_pfx(prog->sec_name, "fexit.multi/");
> + is_fsession = str_has_pfx(prog->sec_name, "fsession.multi/");
> +
> + if (is_fsession)
> + spec = prog->sec_name + sizeof("fsession.multi/") - 1;
> + else if (is_fexit)
> + spec = prog->sec_name + sizeof("fexit.multi/") - 1;
> + else
> + spec = prog->sec_name + sizeof("fentry.multi/") - 1;
The sleepable variants with patterns don't seem to be handled here.
For a section name like "fentry.multi.s/my_func", none of the
str_has_pfx checks match because "fexit.multi/" and "fsession.multi/"
are not prefixes of "fentry.multi.s/..." (the character at position
11 or 14 is '.' not '/').
The else branch then computes spec using sizeof("fentry.multi/") - 1
which gives an offset of 13, pointing into "s/my_func" instead of
"my_func". The sscanf then extracts "s" as the pattern, and the
program attaches to any function matching the glob "s" rather than
"my_func".
Similarly for "fexit.multi.s/X" and "fsession.multi.s/X", the
offsets are wrong and produce either error returns or incorrect
patterns.
The SEC_DEF entries register all six sleepable variants, and
sec_def_matches() correctly distinguishes "fentry.multi.s+" from
"fentry.multi+" using the '/' separator check, so the matching
works but the pattern extraction here does not.
Would it work to also check for the ".s/" variants, for example:
is_fexit = str_has_pfx(prog->sec_name, "fexit.multi/") ||
str_has_pfx(prog->sec_name, "fexit.multi.s/");
with the corresponding sizeof adjustments for the spec offset?
> +
> + n = sscanf(spec, "%m[a-zA-Z0-9_.*?]", &pattern);
> + if (n < 1) {
> + pr_warn("tracing multi pattern is invalid: %s\n", spec);
> + return -EINVAL;
> + }
> +
> + *link = bpf_program__attach_tracing_multi(prog, pattern, NULL);
> + free(pattern);
> + return libbpf_get_error(*link);
> +}
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Written by a well-known BPF maintainer with long contribution history; bugs are typical human copy-paste errors from modeling after existing kprobe_multi code, and the patch evolved through multiple RFC revisions on LKML.
issues-found: 3
issue-severity-score: medium
issue-severity-explanation: The __u32 cnt type bug creates dead error handling that can lead to a double-free under memory pressure, and the sleepable section parsing bug causes wrong functions to be attached silently; both affect correctness of a new public API.
^ permalink raw reply
* Re: [PATCH bpf-next 02/17] bpf: Use mutex lock pool for bpf trampolines
From: bot+bpf-ci @ 2026-02-20 10:57 UTC (permalink / raw)
To: jolsa, ast, daniel, andrii
Cc: bpf, linux-trace-kernel, kafai, eddyz87, songliubraving, yhs,
menglong8.dong, rostedt, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
In-Reply-To: <20260220100649.628307-3-jolsa@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2986 bytes --]
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
[ ... ]
> @@ -71,7 +110,7 @@ static int bpf_tramp_ftrace_ops_func(struct ftrace_ops *ops, unsigned long ip,
> /* This is called inside register_ftrace_direct_multi(), so
> * tr->mutex is already locked.
> */
> - lockdep_assert_held_once(&tr->mutex);
> + lockdep_assert_held_once(trampoline_locks_lookup(tr));
This comment still references tr->mutex, but the field was removed from
struct bpf_trampoline by this patch. Should the comment say the
trampoline pool lock is already held instead?
[ ... ]
> @@ -102,7 +141,7 @@ static int bpf_tramp_ftrace_ops_func(struct ftrace_ops *ops, unsigned long ip,
> /* The normal locking order is
> * tr->mutex => direct_mutex (ftrace.c) => ftrace_lock (ftrace.c)
> *
> * The following two commands are called from
> *
> * prepare_direct_functions_for_ipmodify
> * cleanup_direct_functions_after_ipmodify
> *
> * In both cases, direct_mutex is already locked. Use
> * mutex_trylock(&tr->mutex) to avoid deadlock in race condition
> * (something else is making changes to this same trampoline).
> */
> - if (!mutex_trylock(&tr->mutex)) {
> + if (!mutex_trylock(trampoline_locks_lookup(tr))) {
> /* sleep 1 ms to make sure whatever holding tr->mutex makes
> * some progress.
> */
The locking order comment and the two references to tr->mutex in this
block also appear to need updating. The locking order is now pool lock
rather than tr->mutex, and the trylock and sleep comments still name the
removed field.
[ ... ]
> @@ -1026,11 +1065,11 @@ struct bpf_attach_target_info tgt_info = {};
> /* note, we're still holding tr refcnt from above */
>
> - mutex_unlock(&tr->mutex);
> + trampoline_unlock(tr);
>
> return 0;
> err:
> - mutex_unlock(&tr->mutex);
> + trampoline_unlock(tr);
>
> if (shim_link)
> bpf_link_put(&shim_link->link.link);
>
> /* have to release tr while _not_ holding its mutex */
> bpf_trampoline_put(tr); /* bpf_trampoline_get above */
Similarly, this comment in bpf_trampoline_link_cgroup_shim() references
"its mutex" which no longer exists as a per-trampoline field.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22220470181
AI-authorship-score: low
AI-authorship-explanation: Well-motivated infrastructure patch by known BPF maintainer with collaborative development history (Suggested-by tag) and idiomatic kernel coding patterns; stale comments are a typical human oversight.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Stale comments in bpf_tramp_ftrace_ops_func reference the removed tr->mutex field in locking order documentation, which could mislead future developers but has no runtime impact.
^ permalink raw reply
* [PATCH bpf-next 17/17] selftests/bpf: Add tracing multi attach benchmark test
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding benchmark test that attaches to (almost) all allowed tracing
functions and display attach/detach times.
# ./test_progs -t tracing_multi_bench_attach -v
bpf_testmod.ko is already unloaded.
Loading bpf_testmod.ko...
Successfully loaded bpf_testmod.ko.
serial_test_tracing_multi_bench_attach:PASS:btf__load_vmlinux_btf 0 nsec
serial_test_tracing_multi_bench_attach:PASS:tracing_multi_bench__open_and_load 0 nsec
serial_test_tracing_multi_bench_attach:PASS:get_syms 0 nsec
serial_test_tracing_multi_bench_attach:PASS:bpf_program__attach_tracing_multi 0 nsec
serial_test_tracing_multi_bench_attach: found 51186 functions
serial_test_tracing_multi_bench_attach: attached in 1.295s
serial_test_tracing_multi_bench_attach: detached in 0.243s
#507 tracing_multi_bench_attach:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Successfully unloaded bpf_testmod.ko.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/tracing_multi.c | 177 ++++++++++++++++++
.../selftests/bpf/progs/tracing_multi_bench.c | 13 ++
2 files changed, 190 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_bench.c
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index ba86a88844e6..ac8ef41586f0 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -7,6 +7,7 @@
#include "tracing_multi.skel.h"
#include "tracing_multi_intersect.skel.h"
#include "tracing_multi_session.skel.h"
+#include "tracing_multi_bench.skel.h"
#include "trace_helpers.h"
static __u64 bpf_fentry_test_cookies[] = {
@@ -394,6 +395,182 @@ static void test_attach_api_fails(void)
tracing_multi__destroy(skel);
}
+/*
+ * Skip several kernel symbols that might not be safe or could cause delays.
+ */
+static bool skip_symbol(char *name)
+{
+ if (!strcmp(name, "arch_cpu_idle"))
+ return true;
+ if (!strcmp(name, "default_idle"))
+ return true;
+ if (!strncmp(name, "rcu_", 4))
+ return true;
+ if (!strcmp(name, "bpf_dispatcher_xdp_func"))
+ return true;
+ if (strstr(name, "rcu"))
+ return true;
+ if (strstr(name, "trace"))
+ return true;
+ if (strstr(name, "irq"))
+ return true;
+ if (strstr(name, "bpf_lsm_"))
+ return true;
+ if (!strcmp(name, "migrate_enable"))
+ return true;
+ if (!strcmp(name, "migrate_disable"))
+ return true;
+ if (!strcmp(name, "preempt_count_sub"))
+ return true;
+ if (!strcmp(name, "preempt_count_add"))
+ return true;
+ return false;
+}
+
+#define MAX_BPF_FUNC_ARGS 12
+
+static bool btf_type_is_modifier(const struct btf_type *t)
+{
+ switch (BTF_INFO_KIND(t->info)) {
+ case BTF_KIND_TYPEDEF:
+ case BTF_KIND_VOLATILE:
+ case BTF_KIND_CONST:
+ case BTF_KIND_RESTRICT:
+ case BTF_KIND_TYPE_TAG:
+ return true;
+ }
+ return false;
+}
+
+static bool is_allowed_func(const struct btf *btf, const struct btf_type *t)
+{
+ const struct btf_type *proto;
+ const struct btf_param *args;
+ __u32 i, nargs;
+ __s64 ret;
+
+ proto = btf_type_by_id(btf, t->type);
+ if (BTF_INFO_KIND(proto->info) != BTF_KIND_FUNC_PROTO)
+ return false;
+
+ args = (const struct btf_param *)(proto + 1);
+ nargs = btf_vlen(proto);
+ if (nargs > MAX_BPF_FUNC_ARGS)
+ return false;
+
+ t = btf__type_by_id(btf, proto->type);
+ while (t && btf_type_is_modifier(t))
+ t = btf__type_by_id(btf, t->type);
+
+ if (btf_is_struct(t) || btf_is_union(t))
+ return false;
+
+ for (i = 0; i < nargs; i++) {
+ /* No support for variable args */
+ if (i == nargs - 1 && args[i].type == 0)
+ return false;
+
+ /* No support of struct argument size greater than 16 bytes */
+ ret = btf__resolve_size(btf, args[i].type);
+ if (ret < 0 || ret > 16)
+ return false;
+ }
+
+ return true;
+}
+
+void serial_test_tracing_multi_bench_attach(void)
+{
+ LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+ struct tracing_multi_bench *skel = NULL;
+ size_t i, syms_cnt, cap = 0, cnt = 0;
+ long attach_start_ns, attach_end_ns;
+ long detach_start_ns, detach_end_ns;
+ double attach_delta, detach_delta;
+ struct bpf_link *link = NULL;
+ void *root = NULL;
+ __u32 *ids = NULL;
+ __u32 nr, type_id;
+ struct btf *btf;
+ char **syms;
+ int err;
+
+#ifndef __x86_64__
+ test__skip();
+ return;
+#endif
+
+ btf = btf__load_vmlinux_btf();
+ if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
+ return;
+
+ skel = tracing_multi_bench__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi_bench__open_and_load"))
+ goto cleanup;
+
+ if (!ASSERT_OK(bpf_get_ksyms(&syms, &syms_cnt, true), "get_syms"))
+ goto cleanup;
+
+ for (i = 0; i < syms_cnt; i++) {
+ if (skip_symbol(syms[i]))
+ continue;
+ tsearch(&syms[i], &root, compare);
+ }
+
+ nr = btf__type_cnt(btf);
+ for (type_id = 1; type_id < nr; type_id++) {
+ const struct btf_type *type;
+ const char *str;
+
+ type = btf__type_by_id(btf, type_id);
+ if (!type)
+ break;
+
+ if (BTF_INFO_KIND(type->info) != BTF_KIND_FUNC)
+ continue;
+
+ str = btf__name_by_offset(btf, type->name_off);
+ if (!str)
+ break;
+
+ if (!tfind(&str, &root, compare))
+ continue;
+
+ if (!is_allowed_func(btf, type))
+ continue;
+
+ err = libbpf_ensure_mem((void **) &ids, &cap, sizeof(*ids), cnt + 1);
+ if (err)
+ break;
+
+ ids[cnt++] = type_id;
+ }
+
+ opts.ids = ids;
+ opts.cnt = cnt;
+
+ attach_start_ns = get_time_ns();
+ link = bpf_program__attach_tracing_multi(skel->progs.bench, NULL, &opts);
+ attach_end_ns = get_time_ns();
+
+ if (!ASSERT_OK_PTR(link, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ detach_start_ns = get_time_ns();
+ bpf_link__destroy(link);
+ detach_end_ns = get_time_ns();
+
+ attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
+ detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
+
+ printf("%s: found %lu functions\n", __func__, cnt);
+ printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
+ printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
+
+cleanup:
+ tracing_multi_bench__destroy(skel);
+}
+
void test_tracing_multi_test(void)
{
#ifndef __x86_64__
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_bench.c b/tools/testing/selftests/bpf/progs/tracing_multi_bench.c
new file mode 100644
index 000000000000..067ba668489b
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_bench.c
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("fentry.multi")
+int BPF_PROG(bench)
+{
+ return 0;
+}
--
2.52.0
^ permalink raw reply related
* [PATCH bpf-next 16/17] selftests/bpf: Add tracing multi attach fails test
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding tests for attach fails on tracing multi link.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/tracing_multi.c | 56 +++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index 3d9327b80e88..ba86a88844e6 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -340,6 +340,60 @@ static void test_session(void)
tracing_multi_session__destroy(skel);
}
+static void test_attach_api_fails(void)
+{
+ LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+ struct tracing_multi *skel = NULL;
+ __u64 cookies[2];
+ __u32 ids[2];
+
+ skel = tracing_multi__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi__open_and_load"))
+ return;
+
+ /* fail#1 pattern and opts NULL */
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ NULL, NULL);
+ if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ /* fail#2 pattern and ids */
+ opts.ids = ids;
+ opts.cnt = 2;
+
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ "bpf_fentry_test*", &opts);
+ if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ /* fail#3 pattern and cookies */
+ opts.ids = NULL;
+ opts.cnt = 2;
+ opts.cookies = cookies;
+
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ "bpf_fentry_test*", &opts);
+ if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ /* fail#4 bogus pattern */
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ "bpf_not_really_a_function*", NULL);
+ if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ /* fail#5 abnormal cnt */
+ opts.ids = ids;
+ opts.cnt = INT_MAX;
+
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ NULL, &opts);
+ ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi");
+
+cleanup:
+ tracing_multi__destroy(skel);
+}
+
void test_tracing_multi_test(void)
{
#ifndef __x86_64__
@@ -359,4 +413,6 @@ void test_tracing_multi_test(void)
test_link_api_ids(true);
if (test__start_subtest("session"))
test_session();
+ if (test__start_subtest("attach_api_fails"))
+ test_attach_api_fails();
}
--
2.52.0
^ permalink raw reply related
* [PATCH bpf-next 15/17] selftests/bpf: Add tracing multi session test
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding tests for tracing multi link session.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 4 ++-
.../selftests/bpf/prog_tests/tracing_multi.c | 31 +++++++++++++++++++
.../bpf/progs/tracing_multi_session_attach.c | 27 ++++++++++++++++
3 files changed, 61 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_session_attach.c
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 0cbc9bcb9a2e..b415d64bf0d1 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -482,7 +482,8 @@ LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \
linked_vars.skel.h linked_maps.skel.h \
test_subskeleton.skel.h test_subskeleton_lib.skel.h \
test_usdt.skel.h tracing_multi.skel.h \
- tracing_multi_intersect.skel.h
+ tracing_multi_intersect.skel.h \
+ tracing_multi_session.skel.h
LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c \
core_kern.c core_kern_overflow.c test_ringbuf.c \
@@ -510,6 +511,7 @@ xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
xdp_features.skel.h-deps := xdp_features.bpf.o
tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o
tracing_multi_intersect.skel.h-deps := tracing_multi_intersect_attach.bpf.o tracing_multi_check.bpf.o
+tracing_multi_session.skel.h-deps := tracing_multi_session_attach.bpf.o tracing_multi_check.bpf.o
LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index 1bab4c3ea808..3d9327b80e88 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -6,6 +6,7 @@
#include "bpf/libbpf_internal.h"
#include "tracing_multi.skel.h"
#include "tracing_multi_intersect.skel.h"
+#include "tracing_multi_session.skel.h"
#include "trace_helpers.h"
static __u64 bpf_fentry_test_cookies[] = {
@@ -311,6 +312,34 @@ static void test_intersect(void)
tracing_multi_intersect__destroy(skel);
}
+static void test_session(void)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ struct tracing_multi_session *skel;
+ int err, prog_fd;
+
+ skel = tracing_multi_session__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi_session__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ err = tracing_multi_session__attach(skel);
+ if (!ASSERT_OK(err, "tracing_multi_session__attach"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.test_session);
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ ASSERT_OK(err, "test_run");
+
+ ASSERT_EQ(skel->bss->test_result_fentry, 10, "test_result_fentry");
+ /* extra count for test_result_fexit cookie */
+ ASSERT_EQ(skel->bss->test_result_fexit, 20, "test_result_fexit");
+
+cleanup:
+ tracing_multi_session__destroy(skel);
+}
+
void test_tracing_multi_test(void)
{
#ifndef __x86_64__
@@ -328,4 +357,6 @@ void test_tracing_multi_test(void)
test_intersect();
if (test__start_subtest("cookies"))
test_link_api_ids(true);
+ if (test__start_subtest("session"))
+ test_session();
}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_session_attach.c b/tools/testing/selftests/bpf/progs/tracing_multi_session_attach.c
new file mode 100644
index 000000000000..9d717018a00f
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_session_attach.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+__hidden extern int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return);
+
+__u64 test_result_fentry = 0;
+__u64 test_result_fexit = 0;
+
+SEC("fsession.multi/bpf_fentry_test*")
+int BPF_PROG(test_session)
+{
+ volatile __u64 *cookie = bpf_session_cookie(ctx);
+
+ if (bpf_session_is_return(ctx)) {
+ tracing_multi_arg_check(ctx, &test_result_fexit, true);
+ /* extra count for test_result_fexit cookie */
+ test_result_fexit += *cookie == 0xbeafbeafbeafbeaf;
+ } else {
+ tracing_multi_arg_check(ctx, &test_result_fentry, false);
+ *cookie = 0xbeafbeafbeafbeaf;
+ }
+ return 0;
+}
--
2.52.0
^ permalink raw reply related
* [PATCH bpf-next 14/17] selftests/bpf: Add tracing multi cookies test
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding tests for using cookies on tracing multi link.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/tracing_multi.c | 23 +++++++++++++++++--
.../selftests/bpf/progs/tracing_multi_check.c | 15 +++++++++++-
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index f6ff1668d88f..1bab4c3ea808 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -8,6 +8,19 @@
#include "tracing_multi_intersect.skel.h"
#include "trace_helpers.h"
+static __u64 bpf_fentry_test_cookies[] = {
+ 8, /* bpf_fentry_test1 */
+ 9, /* bpf_fentry_test2 */
+ 7, /* bpf_fentry_test3 */
+ 5, /* bpf_fentry_test4 */
+ 4, /* bpf_fentry_test5 */
+ 2, /* bpf_fentry_test6 */
+ 3, /* bpf_fentry_test7 */
+ 1, /* bpf_fentry_test8 */
+ 10, /* bpf_fentry_test9 */
+ 6, /* bpf_fentry_test10 */
+};
+
static const char * const bpf_fentry_test[] = {
"bpf_fentry_test1",
"bpf_fentry_test2",
@@ -176,7 +189,7 @@ static void test_link_api_pattern(void)
tracing_multi__destroy(skel);
}
-static void test_link_api_ids(void)
+static void test_link_api_ids(bool test_cookies)
{
LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
struct tracing_multi *skel = NULL;
@@ -188,6 +201,7 @@ static void test_link_api_ids(void)
return;
skel->bss->pid = getpid();
+ skel->bss->test_cookies = test_cookies;
ids = get_ids(bpf_fentry_test, cnt);
if (!ASSERT_OK_PTR(ids, "get_ids"))
@@ -196,6 +210,9 @@ static void test_link_api_ids(void)
opts.ids = ids;
opts.cnt = cnt;
+ if (test_cookies)
+ opts.cookies = bpf_fentry_test_cookies;
+
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
NULL, &opts);
if (!ASSERT_OK_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
@@ -306,7 +323,9 @@ void test_tracing_multi_test(void)
if (test__start_subtest("link_api_pattern"))
test_link_api_pattern();
if (test__start_subtest("link_api_ids"))
- test_link_api_ids();
+ test_link_api_ids(false);
if (test__start_subtest("intersect"))
test_intersect();
+ if (test__start_subtest("cookies"))
+ test_link_api_ids(true);
}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_check.c b/tools/testing/selftests/bpf/progs/tracing_multi_check.c
index fe7d1708cda5..c800e537b6b5 100644
--- a/tools/testing/selftests/bpf/progs/tracing_multi_check.c
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_check.c
@@ -7,6 +7,7 @@
char _license[] SEC("license") = "GPL";
int pid = 0;
+bool test_cookies = false;
extern const void bpf_fentry_test1 __ksym;
extern const void bpf_fentry_test2 __ksym;
@@ -22,7 +23,7 @@ extern const void bpf_fentry_test10 __ksym;
int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
{
void *ip = (void *) bpf_get_func_ip(ctx);
- __u64 value = 0, ret = 0;
+ __u64 value = 0, ret = 0, cookie = 0;
long err = 0;
if (bpf_get_current_pid_tgid() >> 32 != pid)
@@ -30,6 +31,8 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
if (is_return)
err |= bpf_get_func_ret(ctx, &ret);
+ if (test_cookies)
+ cookie = test_cookies ? bpf_get_attach_cookie(ctx) : 0;
if (ip == &bpf_fentry_test1) {
int a;
@@ -38,6 +41,7 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
a = (int) value;
err |= is_return ? ret != 2 : 0;
+ err |= test_cookies ? cookie != 8 : 0;
*test_result += err == 0 && a == 1;
} else if (ip == &bpf_fentry_test2) {
@@ -50,6 +54,7 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
b = value;
err |= is_return ? ret != 5 : 0;
+ err |= test_cookies ? cookie != 9 : 0;
*test_result += err == 0 && a == 2 && b == 3;
} else if (ip == &bpf_fentry_test3) {
@@ -65,6 +70,7 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
c = value;
err |= is_return ? ret != 15 : 0;
+ err |= test_cookies ? cookie != 7 : 0;
*test_result += err == 0 && a == 4 && b == 5 && c == 6;
} else if (ip == &bpf_fentry_test4) {
@@ -83,6 +89,7 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
d = value;
err |= is_return ? ret != 34 : 0;
+ err |= test_cookies ? cookie != 5 : 0;
*test_result += err == 0 && a == (void *) 7 && b == 8 && c == 9 && d == 10;
} else if (ip == &bpf_fentry_test5) {
@@ -104,6 +111,7 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
e = value;
err |= is_return ? ret != 65 : 0;
+ err |= test_cookies ? cookie != 4 : 0;
*test_result += err == 0 && a == 11 && b == (void *) 12 && c == 13 && d == 14 && e == 15;
} else if (ip == &bpf_fentry_test6) {
@@ -128,22 +136,27 @@ int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
f = value;
err |= is_return ? ret != 111 : 0;
+ err |= test_cookies ? cookie != 2 : 0;
*test_result += err == 0 && a == 16 && b == (void *) 17 && c == 18 && d == 19 && e == (void *) 20 && f == 21;
} else if (ip == &bpf_fentry_test7) {
err |= is_return ? ret != 0 : 0;
+ err |= test_cookies ? cookie != 3 : 0;
*test_result += err == 0 ? 1 : 0;
} else if (ip == &bpf_fentry_test8) {
err |= is_return ? ret != 0 : 0;
+ err |= test_cookies ? cookie != 1 : 0;
*test_result += err == 0 ? 1 : 0;
} else if (ip == &bpf_fentry_test9) {
err |= is_return ? ret != 0 : 0;
+ err |= test_cookies ? cookie != 10 : 0;
*test_result += err == 0 ? 1 : 0;
} else if (ip == &bpf_fentry_test10) {
err |= is_return ? ret != 0 : 0;
+ err |= test_cookies ? cookie != 6 : 0;
*test_result += err == 0 ? 1 : 0;
}
--
2.52.0
^ permalink raw reply related
* [PATCH bpf-next 13/17] selftests/bpf: Add tracing multi intersect tests
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding tracing multi tests for intersecting attached functions.
Using bits from (from 1 to 16 values) to specify (up to 4) attached
programs, and randomly choosing bpf_fentry_test* functions they are
attached to.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 4 +-
.../selftests/bpf/prog_tests/tracing_multi.c | 99 +++++++++++++++++++
.../progs/tracing_multi_intersect_attach.c | 42 ++++++++
3 files changed, 144 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 849c585fc2a1..0cbc9bcb9a2e 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -481,7 +481,8 @@ SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \
linked_vars.skel.h linked_maps.skel.h \
test_subskeleton.skel.h test_subskeleton_lib.skel.h \
- test_usdt.skel.h tracing_multi.skel.h
+ test_usdt.skel.h tracing_multi.skel.h \
+ tracing_multi_intersect.skel.h
LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c \
core_kern.c core_kern_overflow.c test_ringbuf.c \
@@ -508,6 +509,7 @@ xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
xdp_features.skel.h-deps := xdp_features.bpf.o
tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o
+tracing_multi_intersect.skel.h-deps := tracing_multi_intersect_attach.bpf.o tracing_multi_check.bpf.o
LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index 79b84701d38f..f6ff1668d88f 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -5,6 +5,7 @@
#include <search.h>
#include "bpf/libbpf_internal.h"
#include "tracing_multi.skel.h"
+#include "tracing_multi_intersect.skel.h"
#include "trace_helpers.h"
static const char * const bpf_fentry_test[] = {
@@ -22,6 +23,20 @@ static const char * const bpf_fentry_test[] = {
#define FUNCS_CNT (ARRAY_SIZE(bpf_fentry_test))
+static int get_random_funcs(const char **funcs)
+{
+ int i, cnt = 0;
+
+ for (i = 0; i < FUNCS_CNT; i++) {
+ if (rand() % 2)
+ funcs[cnt++] = bpf_fentry_test[i];
+ }
+ /* we always need at least one.. */
+ if (!cnt)
+ funcs[cnt++] = bpf_fentry_test[rand() % FUNCS_CNT];
+ return cnt;
+}
+
static int compare(const void *ppa, const void *ppb)
{
const char *pa = *(const char **) ppa;
@@ -197,6 +212,88 @@ static void test_link_api_ids(void)
tracing_multi__destroy(skel);
}
+static bool is_set(__u32 mask, __u32 bit)
+{
+ return (1 << bit) & mask;
+}
+
+static void __test_intersect(__u32 mask, const struct bpf_program *progs[4], __u64 *test_results[4])
+{
+ LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ struct bpf_link *links[4] = { NULL };
+ const char *funcs[FUNCS_CNT];
+ __u64 expected[4];
+ __u32 *ids, i;
+ int err, cnt;
+
+ /*
+ * We have 4 programs in progs and the mask bits pick which
+ * of them gets attached to randomly chosen functions.
+ */
+ for (i = 0; i < 4; i++) {
+ if (!is_set(mask, i))
+ continue;
+
+ cnt = get_random_funcs(funcs);
+ ids = get_ids(funcs, cnt);
+ if (!ASSERT_OK_PTR(ids, "get_ids"))
+ goto cleanup;
+
+ opts.ids = ids;
+ opts.cnt = cnt;
+ links[i] = bpf_program__attach_tracing_multi(progs[i], NULL, &opts);
+ free(ids);
+
+ if (!ASSERT_OK_PTR(links[i], "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ expected[i] = *test_results[i] + cnt;
+ }
+
+ err = bpf_prog_test_run_opts(bpf_program__fd(progs[0]), &topts);
+ ASSERT_OK(err, "test_run");
+
+ for (i = 0; i < 4; i++) {
+ if (!is_set(mask, i))
+ continue;
+ ASSERT_EQ(*test_results[i], expected[i], "test_results");
+ }
+
+cleanup:
+ for (i = 0; i < 4; i++)
+ bpf_link__destroy(links[i]);
+}
+
+static void test_intersect(void)
+{
+ const struct bpf_program *progs[4];
+ struct tracing_multi_intersect *skel;
+ __u64 *test_results[4];
+ __u32 i;
+
+ skel = tracing_multi_intersect__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi_intersect__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ progs[0] = skel->progs.fentry_1;
+ progs[1] = skel->progs.fexit_1;
+ progs[2] = skel->progs.fentry_2;
+ progs[3] = skel->progs.fexit_2;
+
+ test_results[0] = &skel->bss->test_result_fentry_1;
+ test_results[1] = &skel->bss->test_result_fexit_1;
+ test_results[2] = &skel->bss->test_result_fentry_2;
+ test_results[3] = &skel->bss->test_result_fexit_2;
+
+ for (i = 1; i < 16; i++)
+ __test_intersect(i, progs, test_results);
+
+ tracing_multi_intersect__destroy(skel);
+}
+
void test_tracing_multi_test(void)
{
#ifndef __x86_64__
@@ -210,4 +307,6 @@ void test_tracing_multi_test(void)
test_link_api_pattern();
if (test__start_subtest("link_api_ids"))
test_link_api_ids();
+ if (test__start_subtest("intersect"))
+ test_intersect();
}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c
new file mode 100644
index 000000000000..bbd052b02559
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+__hidden extern int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return);
+
+__u64 test_result_fentry_1 = 0;
+__u64 test_result_fentry_2 = 0;
+__u64 test_result_fexit_1 = 0;
+__u64 test_result_fexit_2 = 0;
+
+SEC("fentry.multi")
+int BPF_PROG(fentry_1)
+{
+ tracing_multi_arg_check(ctx, &test_result_fentry_1, false);
+ return 0;
+}
+
+SEC("fentry.multi")
+int BPF_PROG(fentry_2)
+{
+ tracing_multi_arg_check(ctx, &test_result_fentry_2, false);
+ return 0;
+}
+
+SEC("fexit.multi")
+int BPF_PROG(fexit_1)
+{
+ tracing_multi_arg_check(ctx, &test_result_fexit_1, true);
+ return 0;
+}
+
+SEC("fexit.multi")
+int BPF_PROG(fexit_2)
+{
+ tracing_multi_arg_check(ctx, &test_result_fexit_2, true);
+ return 0;
+}
--
2.52.0
^ permalink raw reply related
* [PATCH bpf-next 12/17] selftests/bpf: Add tracing multi skel/pattern/ids attach tests
From: Jiri Olsa @ 2026-02-20 10:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, linux-trace-kernel, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Menglong Dong, Steven Rostedt
In-Reply-To: <20260220100649.628307-1-jolsa@kernel.org>
Adding tests for tracing_multi link attachment via all possible
libbpf apis - skeleton, function pattern and btf ids.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 3 +-
.../selftests/bpf/prog_tests/tracing_multi.c | 213 ++++++++++++++++++
.../bpf/progs/tracing_multi_attach.c | 26 +++
.../selftests/bpf/progs/tracing_multi_check.c | 152 +++++++++++++
4 files changed, 393 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_multi.c
create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_attach.c
create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_check.c
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 6776158f1f3e..849c585fc2a1 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -481,7 +481,7 @@ SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \
linked_vars.skel.h linked_maps.skel.h \
test_subskeleton.skel.h test_subskeleton_lib.skel.h \
- test_usdt.skel.h
+ test_usdt.skel.h tracing_multi.skel.h
LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c \
core_kern.c core_kern_overflow.c test_ringbuf.c \
@@ -507,6 +507,7 @@ test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o
xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
xdp_features.skel.h-deps := xdp_features.bpf.o
+tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o
LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
new file mode 100644
index 000000000000..79b84701d38f
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include <bpf/btf.h>
+#include <search.h>
+#include "bpf/libbpf_internal.h"
+#include "tracing_multi.skel.h"
+#include "trace_helpers.h"
+
+static const char * const bpf_fentry_test[] = {
+ "bpf_fentry_test1",
+ "bpf_fentry_test2",
+ "bpf_fentry_test3",
+ "bpf_fentry_test4",
+ "bpf_fentry_test5",
+ "bpf_fentry_test6",
+ "bpf_fentry_test7",
+ "bpf_fentry_test8",
+ "bpf_fentry_test9",
+ "bpf_fentry_test10",
+};
+
+#define FUNCS_CNT (ARRAY_SIZE(bpf_fentry_test))
+
+static int compare(const void *ppa, const void *ppb)
+{
+ const char *pa = *(const char **) ppa;
+ const char *pb = *(const char **) ppb;
+
+ return strcmp(pa, pb);
+}
+
+static __u32 *get_ids(const char * const funcs[], int funcs_cnt)
+{
+ __u32 nr, type_id, cnt = 0;
+ void *root = NULL;
+ __u32 *ids = NULL;
+ struct btf *btf;
+ int i, err = 0;
+
+ btf = btf__load_vmlinux_btf();
+ if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
+ return NULL;
+
+ ids = calloc(funcs_cnt, sizeof(ids[0]));
+ if (!ids)
+ goto out;
+
+ /*
+ * We sort function names by name and search them
+ * below for each function.
+ */
+ for (i = 0; i < funcs_cnt; i++)
+ tsearch(&funcs[i], &root, compare);
+
+ nr = btf__type_cnt(btf);
+ for (type_id = 1; type_id < nr && cnt < funcs_cnt; type_id++) {
+ const struct btf_type *type;
+ const char *str, ***val;
+ unsigned int idx;
+
+ type = btf__type_by_id(btf, type_id);
+ if (!type) {
+ err = -1;
+ break;
+ }
+
+ if (BTF_INFO_KIND(type->info) != BTF_KIND_FUNC)
+ continue;
+
+ str = btf__name_by_offset(btf, type->name_off);
+ if (!str) {
+ err = -1;
+ break;
+ }
+
+ val = tfind(&str, &root, compare);
+ if (!val)
+ continue;
+
+ /*
+ * We keep pointer for each function name so we can get the original
+ * array index and have the resulting ids array matching the original
+ * function array.
+ *
+ * Doing it this way allow us to easily test the cookies support,
+ * because each cookie is attach to particular function/id.
+ */
+ idx = *val - funcs;
+ ids[idx] = type_id;
+ cnt++;
+ }
+
+ if (err) {
+ free(ids);
+ ids = NULL;
+ }
+
+out:
+ btf__free(btf);
+ return ids;
+}
+
+static void tracing_multi_test_run(struct tracing_multi *skel)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ int err, prog_fd;
+
+ prog_fd = bpf_program__fd(skel->progs.test_fentry);
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ ASSERT_OK(err, "test_run");
+
+ ASSERT_EQ(skel->bss->test_result_fentry, FUNCS_CNT, "test_result_fentry");
+ ASSERT_EQ(skel->bss->test_result_fexit, FUNCS_CNT, "test_result_fexit");
+}
+
+static void test_skel_api(void)
+{
+ struct tracing_multi *skel = NULL;
+ int err;
+
+ skel = tracing_multi__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ err = tracing_multi__attach(skel);
+ if (!ASSERT_OK(err, "tracing_multi__attach"))
+ goto cleanup;
+
+ tracing_multi_test_run(skel);
+
+cleanup:
+ tracing_multi__destroy(skel);
+}
+
+static void test_link_api_pattern(void)
+{
+ struct tracing_multi *skel = NULL;
+
+ skel = tracing_multi__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ "bpf_fentry_test*", NULL);
+ if (!ASSERT_OK_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ skel->links.test_fexit = bpf_program__attach_tracing_multi(skel->progs.test_fexit,
+ "bpf_fentry_test*", NULL);
+ if (!ASSERT_OK_PTR(skel->links.test_fexit, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ tracing_multi_test_run(skel);
+
+cleanup:
+ tracing_multi__destroy(skel);
+}
+
+static void test_link_api_ids(void)
+{
+ LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+ struct tracing_multi *skel = NULL;
+ size_t cnt = FUNCS_CNT;
+ __u32 *ids;
+
+ skel = tracing_multi__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ ids = get_ids(bpf_fentry_test, cnt);
+ if (!ASSERT_OK_PTR(ids, "get_ids"))
+ goto cleanup;
+
+ opts.ids = ids;
+ opts.cnt = cnt;
+
+ skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ skel->links.test_fexit = bpf_program__attach_tracing_multi(skel->progs.test_fexit,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_fexit, "bpf_program__attach_tracing_multi"))
+ goto cleanup;
+
+ tracing_multi_test_run(skel);
+
+cleanup:
+ tracing_multi__destroy(skel);
+}
+
+void test_tracing_multi_test(void)
+{
+#ifndef __x86_64__
+ test__skip();
+ return;
+#endif
+
+ if (test__start_subtest("skel_api"))
+ test_skel_api();
+ if (test__start_subtest("link_api_pattern"))
+ test_link_api_pattern();
+ if (test__start_subtest("link_api_ids"))
+ test_link_api_ids();
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_attach.c b/tools/testing/selftests/bpf/progs/tracing_multi_attach.c
new file mode 100644
index 000000000000..65b96a0d6915
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_attach.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+__hidden extern int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return);
+
+__u64 test_result_fentry = 0;
+__u64 test_result_fexit = 0;
+
+SEC("fentry.multi/bpf_fentry_test*")
+int BPF_PROG(test_fentry)
+{
+ tracing_multi_arg_check(ctx, &test_result_fentry, false);
+ return 0;
+}
+
+SEC("fexit.multi/bpf_fentry_test*")
+int BPF_PROG(test_fexit)
+{
+ tracing_multi_arg_check(ctx, &test_result_fexit, true);
+ return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_check.c b/tools/testing/selftests/bpf/progs/tracing_multi_check.c
new file mode 100644
index 000000000000..fe7d1708cda5
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_check.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+int pid = 0;
+
+extern const void bpf_fentry_test1 __ksym;
+extern const void bpf_fentry_test2 __ksym;
+extern const void bpf_fentry_test3 __ksym;
+extern const void bpf_fentry_test4 __ksym;
+extern const void bpf_fentry_test5 __ksym;
+extern const void bpf_fentry_test6 __ksym;
+extern const void bpf_fentry_test7 __ksym;
+extern const void bpf_fentry_test8 __ksym;
+extern const void bpf_fentry_test9 __ksym;
+extern const void bpf_fentry_test10 __ksym;
+
+int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
+{
+ void *ip = (void *) bpf_get_func_ip(ctx);
+ __u64 value = 0, ret = 0;
+ long err = 0;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ if (is_return)
+ err |= bpf_get_func_ret(ctx, &ret);
+
+ if (ip == &bpf_fentry_test1) {
+ int a;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = (int) value;
+
+ err |= is_return ? ret != 2 : 0;
+
+ *test_result += err == 0 && a == 1;
+ } else if (ip == &bpf_fentry_test2) {
+ __u64 b;
+ int a;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = (int) value;
+ err |= bpf_get_func_arg(ctx, 1, &value);
+ b = value;
+
+ err |= is_return ? ret != 5 : 0;
+
+ *test_result += err == 0 && a == 2 && b == 3;
+ } else if (ip == &bpf_fentry_test3) {
+ __u64 c;
+ char a;
+ int b;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = (char) value;
+ err |= bpf_get_func_arg(ctx, 1, &value);
+ b = (int) value;
+ err |= bpf_get_func_arg(ctx, 2, &value);
+ c = value;
+
+ err |= is_return ? ret != 15 : 0;
+
+ *test_result += err == 0 && a == 4 && b == 5 && c == 6;
+ } else if (ip == &bpf_fentry_test4) {
+ void *a;
+ char b;
+ int c;
+ __u64 d;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = (void *) value;
+ err |= bpf_get_func_arg(ctx, 1, &value);
+ b = (char) value;
+ err |= bpf_get_func_arg(ctx, 2, &value);
+ c = (int) value;
+ err |= bpf_get_func_arg(ctx, 3, &value);
+ d = value;
+
+ err |= is_return ? ret != 34 : 0;
+
+ *test_result += err == 0 && a == (void *) 7 && b == 8 && c == 9 && d == 10;
+ } else if (ip == &bpf_fentry_test5) {
+ __u64 a;
+ void *b;
+ short c;
+ int d;
+ __u64 e;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = value;
+ err |= bpf_get_func_arg(ctx, 1, &value);
+ b = (void *) value;
+ err |= bpf_get_func_arg(ctx, 2, &value);
+ c = (short) value;
+ err |= bpf_get_func_arg(ctx, 3, &value);
+ d = (int) value;
+ err |= bpf_get_func_arg(ctx, 4, &value);
+ e = value;
+
+ err |= is_return ? ret != 65 : 0;
+
+ *test_result += err == 0 && a == 11 && b == (void *) 12 && c == 13 && d == 14 && e == 15;
+ } else if (ip == &bpf_fentry_test6) {
+ __u64 a;
+ void *b;
+ short c;
+ int d;
+ void *e;
+ __u64 f;
+
+ err |= bpf_get_func_arg(ctx, 0, &value);
+ a = value;
+ err |= bpf_get_func_arg(ctx, 1, &value);
+ b = (void *) value;
+ err |= bpf_get_func_arg(ctx, 2, &value);
+ c = (short) value;
+ err |= bpf_get_func_arg(ctx, 3, &value);
+ d = (int) value;
+ err |= bpf_get_func_arg(ctx, 4, &value);
+ e = (void *) value;
+ err |= bpf_get_func_arg(ctx, 5, &value);
+ f = value;
+
+ err |= is_return ? ret != 111 : 0;
+
+ *test_result += err == 0 && a == 16 && b == (void *) 17 && c == 18 && d == 19 && e == (void *) 20 && f == 21;
+ } else if (ip == &bpf_fentry_test7) {
+ err |= is_return ? ret != 0 : 0;
+
+ *test_result += err == 0 ? 1 : 0;
+ } else if (ip == &bpf_fentry_test8) {
+ err |= is_return ? ret != 0 : 0;
+
+ *test_result += err == 0 ? 1 : 0;
+ } else if (ip == &bpf_fentry_test9) {
+ err |= is_return ? ret != 0 : 0;
+
+ *test_result += err == 0 ? 1 : 0;
+ } else if (ip == &bpf_fentry_test10) {
+ err |= is_return ? ret != 0 : 0;
+
+ *test_result += err == 0 ? 1 : 0;
+ }
+
+ return 0;
+}
--
2.52.0
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox