| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/08/13 20:50 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"aarch64_insn_gen_add_sub_extended_reg",
"bpf_jit_supports_arena_args",
"arch_prepare_bpf_trampoline"
],
"KMSANReasoning": "The patch extends the arm64 BPF JIT compiler to support BPF arena arguments. It introduces new instruction encoding functions for arm64 (e.g., `aarch64_insn_gen_add_sub_extended_reg`) and modifies the JIT compiler (`arch/arm64/net/bpf_jit_comp.c`) to emit instructions that rebase arena pointers. The changes are strictly related to JIT compilation logic and instruction emission. They do not introduce any new kernel structures copied to user space, nor do they allocate complex data structures that could be left uninitialized. Any bugs in the JIT compiler would likely result in invalid instruction generation, crashes, or out-of-bounds memory accesses in the JITed code, which are adequately covered by KASAN and standard kernel testing. There is no risk of uninitialized memory exposure that would require KMSAN.",
"NeedsKMSAN": false,
"Reasoning": "The patch implements BPF arena arguments support for the arm64 JIT compiler. It adds new instruction generation logic for extended register add/sub instructions (`aarch64_insn_gen_add_sub_extended_reg`) and modifies the arm64 BPF JIT (`arch_prepare_bpf_trampoline`, `bpf_jit_supports_arena_args`) to handle arena pointers in kfunc calls and struct_ops callbacks. These are functional changes to the core kernel (BPF JIT) that are reachable and should be fuzzed.",
"WorthFuzzing": true
} |
| 1/1 | 2026/08/13 20:50 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 9fd38225c23e8a95eaf388f273dc33871b224ebf\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Aug 13 20:50:11 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst\nindex 10e725cbe64cd..85f73e0bbd0ff 100644\n--- a/Documentation/bpf/kfuncs.rst\n+++ b/Documentation/bpf/kfuncs.rst\n@@ -301,9 +301,9 @@ An example is given below::\n }\n \n Calling such a kfunc requires the program to use an arena map and a JIT with\n-arena argument support (currently x86-64); verification fails otherwise. The\n-program can pass any value without compromising the kernel. A value that does\n-not point into the arena is a program bug.\n+arena argument support (currently x86-64 and arm64); verification fails\n+otherwise. The program can pass any value without compromising the kernel. A\n+value that does not point into the arena is a program bug.\n \n The suffixes have the same meaning on the arguments of struct_ops stub\n functions, with the conversion running in the opposite direction. The\ndiff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h\nindex cc0702fa64a79..1ce75a4426387 100644\n--- a/arch/arm64/include/asm/insn.h\n+++ b/arch/arm64/include/asm/insn.h\n@@ -205,6 +205,18 @@ enum aarch64_insn_adsb_type {\n \tAARCH64_INSN_ADSB_SUB_SETFLAGS\n };\n \n+/* option field of add/sub (extended register) */\n+enum aarch64_insn_extend_type {\n+\tAARCH64_INSN_EXTEND_UXTB,\n+\tAARCH64_INSN_EXTEND_UXTH,\n+\tAARCH64_INSN_EXTEND_UXTW,\n+\tAARCH64_INSN_EXTEND_UXTX,\n+\tAARCH64_INSN_EXTEND_SXTB,\n+\tAARCH64_INSN_EXTEND_SXTH,\n+\tAARCH64_INSN_EXTEND_SXTW,\n+\tAARCH64_INSN_EXTEND_SXTX,\n+};\n+\n enum aarch64_insn_movewide_type {\n \tAARCH64_INSN_MOVEWIDE_ZERO,\n \tAARCH64_INSN_MOVEWIDE_KEEP,\n@@ -378,6 +390,10 @@ __AARCH64_INSN_FUNCS(add,\t0x7F200000, 0x0B000000)\n __AARCH64_INSN_FUNCS(adds,\t0x7F200000, 0x2B000000)\n __AARCH64_INSN_FUNCS(sub,\t0x7F200000, 0x4B000000)\n __AARCH64_INSN_FUNCS(subs,\t0x7F200000, 0x6B000000)\n+__AARCH64_INSN_FUNCS(add_ext,\t0x7FE00000, 0x0B200000)\n+__AARCH64_INSN_FUNCS(adds_ext,\t0x7FE00000, 0x2B200000)\n+__AARCH64_INSN_FUNCS(sub_ext,\t0x7FE00000, 0x4B200000)\n+__AARCH64_INSN_FUNCS(subs_ext,\t0x7FE00000, 0x6B200000)\n __AARCH64_INSN_FUNCS(madd,\t0x7FE08000, 0x1B000000)\n __AARCH64_INSN_FUNCS(msub,\t0x7FE08000, 0x1B008000)\n __AARCH64_INSN_FUNCS(udiv,\t0x7FE0FC00, 0x1AC00800)\n@@ -637,6 +653,13 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n \t\t\t\t\t int shift,\n \t\t\t\t\t enum aarch64_insn_variant variant,\n \t\t\t\t\t enum aarch64_insn_adsb_type type);\n+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\n+\t\t\t\t\t enum aarch64_insn_register src,\n+\t\t\t\t\t enum aarch64_insn_register reg,\n+\t\t\t\t\t enum aarch64_insn_extend_type extend,\n+\t\t\t\t\t int shift,\n+\t\t\t\t\t enum aarch64_insn_variant variant,\n+\t\t\t\t\t enum aarch64_insn_adsb_type type);\n u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,\n \t\t\t enum aarch64_insn_register src,\n \t\t\t enum aarch64_insn_variant variant,\ndiff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c\nindex 37ce75f7f1f08..e70ac02385153 100644\n--- a/arch/arm64/lib/insn.c\n+++ b/arch/arm64/lib/insn.c\n@@ -986,6 +986,66 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n \treturn aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn, shift);\n }\n \n+/*\n+ * Unlike the shifted-register form, register 31 is not XZR everywhere here:\n+ * it encodes SP for @src, and for @dst too unless @type sets the flags. Only\n+ * @reg keeps the XZR meaning.\n+ */\n+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\n+\t\t\t\t\t enum aarch64_insn_register src,\n+\t\t\t\t\t enum aarch64_insn_register reg,\n+\t\t\t\t\t enum aarch64_insn_extend_type extend,\n+\t\t\t\t\t int shift,\n+\t\t\t\t\t enum aarch64_insn_variant variant,\n+\t\t\t\t\t enum aarch64_insn_adsb_type type)\n+{\n+\tu32 insn;\n+\n+\tswitch (type) {\n+\tcase AARCH64_INSN_ADSB_ADD:\n+\t\tinsn = aarch64_insn_get_add_ext_value();\n+\t\tbreak;\n+\tcase AARCH64_INSN_ADSB_SUB:\n+\t\tinsn = aarch64_insn_get_sub_ext_value();\n+\t\tbreak;\n+\tcase AARCH64_INSN_ADSB_ADD_SETFLAGS:\n+\t\tinsn = aarch64_insn_get_adds_ext_value();\n+\t\tbreak;\n+\tcase AARCH64_INSN_ADSB_SUB_SETFLAGS:\n+\t\tinsn = aarch64_insn_get_subs_ext_value();\n+\t\tbreak;\n+\tdefault:\n+\t\tpr_err(\"%s: unknown add/sub encoding %d\\n\", __func__, type);\n+\t\treturn AARCH64_BREAK_FAULT;\n+\t}\n+\n+\tswitch (variant) {\n+\tcase AARCH64_INSN_VARIANT_32BIT:\n+\t\tbreak;\n+\tcase AARCH64_INSN_VARIANT_64BIT:\n+\t\tinsn |= AARCH64_INSN_SF_BIT;\n+\t\tbreak;\n+\tdefault:\n+\t\tpr_err(\"%s: unknown variant encoding %d\\n\", __func__, variant);\n+\t\treturn AARCH64_BREAK_FAULT;\n+\t}\n+\n+\tif (shift \u003c 0 || shift \u003e 4) {\n+\t\tpr_err(\"%s: invalid shift encoding %d\\n\", __func__, shift);\n+\t\treturn AARCH64_BREAK_FAULT;\n+\t}\n+\n+\tinsn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RD, insn, dst);\n+\n+\tinsn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RN, insn, src);\n+\n+\tinsn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RM, insn, reg);\n+\n+\t/* option in bits [15:13] and imm3 in [12:10] together fill IMM_6 */\n+\treturn aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn,\n+\t\t\t\t\t (extend \u003c\u003c 3) | shift);\n+}\n+\n u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,\n \t\t\t enum aarch64_insn_register src,\n \t\t\t enum aarch64_insn_variant variant,\ndiff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h\nindex d13de4222cfb7..b2fe6e6dcf447 100644\n--- a/arch/arm64/net/bpf_jit.h\n+++ b/arch/arm64/net/bpf_jit.h\n@@ -243,6 +243,17 @@\n /* Rn - Rm; set condition flags */\n #define A64_CMP(sf, Rn, Rm) A64_SUBS(sf, A64_ZR, Rn, Rm)\n \n+/* Add/subtract (extended register) */\n+#define A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, type) \\\n+\taarch64_insn_gen_add_sub_extended_reg(Rd, Rn, Rm, \\\n+\t\tAARCH64_INSN_EXTEND_##ext, shift, A64_VARIANT(sf), \\\n+\t\tAARCH64_INSN_ADSB_##type)\n+/* Rd = Rn + (EXT(Rm) \u003c\u003c shift) */\n+#define A64_ADD_EXT(sf, Rd, Rn, Rm, ext, shift) \\\n+\tA64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, ADD)\n+/* Rd = Rn + (u32)Rm */\n+#define A64_ADD_UXTW(Rd, Rn, Rm) A64_ADD_EXT(1, Rd, Rn, Rm, UXTW, 0)\n+\n /* Data-processing (1 source) */\n #define A64_DATA1(sf, Rd, Rn, type) aarch64_insn_gen_data1(Rd, Rn, \\\n \tA64_VARIANT(sf), AARCH64_INSN_DATA1_##type)\ndiff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c\nindex 74b4083791da3..c18e005a41dbe 100644\n--- a/arch/arm64/net/bpf_jit_comp.c\n+++ b/arch/arm64/net/bpf_jit_comp.c\n@@ -1256,6 +1256,43 @@ static void emit_stack_arg_store_imm(s32 imm, s16 bpf_off, const u8 tmp, struct\n \t}\n }\n \n+/*\n+ * Rebase the __arena args of a kfunc call to arena kernel addresses,\n+ * xN = kern_vm_start + (u32)xN, with the arena base register holding\n+ * kern_vm_start. A nullable arg preserves NULL by skipping the add, tested\n+ * on the truncated value as arena NULL is offset 0.\n+ */\n+static int emit_kfunc_arena_args(struct jit_ctx *ctx, const struct bpf_insn *insn)\n+{\n+\tconst u8 arena_vm_base = bpf2a64[ARENA_VM_START];\n+\tconst struct btf_func_model *fm;\n+\tint i;\n+\n+\tfm = bpf_jit_find_kfunc_model(ctx-\u003eprog, insn);\n+\tif (!fm)\n+\t\treturn -EINVAL;\n+\n+\tfor (i = 0; i \u003c min_t(int, fm-\u003enr_args, MAX_BPF_FUNC_REG_ARGS); i++) {\n+\t\tconst u8 reg = bpf2a64[BPF_REG_1 + i];\n+\t\tu8 flags = fm-\u003earg_flags[i];\n+\n+\t\tif (!(flags \u0026 BTF_FMODEL_ARENA_ARG))\n+\t\t\tcontinue;\n+\t\tif (WARN_ON_ONCE(!ctx-\u003earena_vm_start))\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (flags \u0026 BTF_FMODEL_NULLABLE_ARG) {\n+\t\t\t/* 32-bit mov clears the upper 32 bits */\n+\t\t\temit(A64_MOV(0, reg, reg), ctx);\n+\t\t\t/* skip the add so that NULL stays NULL */\n+\t\t\temit(A64_CBZ(0, reg, 2), ctx);\n+\t\t}\n+\t\temit(A64_ADD_UXTW(reg, arena_vm_base, reg), ctx);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /* JITs an eBPF instruction.\n * Returns:\n * 0 - successfully JITed an 8-byte eBPF instruction.\n@@ -1678,6 +1715,11 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \t\t\t\t\t \u0026func_addr, \u0026func_addr_fixed);\n \t\tif (ret \u003c 0)\n \t\t\treturn ret;\n+\t\tif (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL) {\n+\t\t\tret = emit_kfunc_arena_args(ctx, insn);\n+\t\t\tif (ret \u003c 0)\n+\t\t\t\treturn ret;\n+\t\t}\n \t\temit_call(func_addr, ctx);\n \t\t/*\n \t\t * Call to arch_bpf_timed_may_goto() is emitted by the\n@@ -2351,6 +2393,11 @@ bool bpf_jit_supports_stack_args(void)\n \treturn true;\n }\n \n+bool bpf_jit_supports_arena_args(void)\n+{\n+\treturn true;\n+}\n+\n void *bpf_arch_text_copy(void *dst, void *src, size_t len)\n {\n \tif (!aarch64_insn_copy(dst, src, len))\n@@ -2524,34 +2571,76 @@ static void clear_garbage(struct jit_ctx *ctx, int reg, int effective_bytes)\n \t}\n }\n \n+/*\n+ * Convert an arena kernel address into the arena pointer form on its way into\n+ * the BPF ctx, dst = (u32)(src - kern_vm_start), with @base_lo holding the low\n+ * 32 bits of kern_vm_start. A nullable arg preserves NULL, tested on the full\n+ * 64-bit kernel pointer. The 32-bit subtraction both truncates and clears the\n+ * upper half, so the stored value satisfies the JIT invariant for arena\n+ * pointer registers.\n+ */\n+static void emit_arena_arg_conv(struct jit_ctx *ctx, u8 dst, u8 src, bool nullable, u8 base_lo)\n+{\n+\tif (nullable) {\n+\t\tif (dst != src)\n+\t\t\temit(A64_MOV(1, dst, src), ctx);\n+\t\t/* skip the subtraction so that NULL stays NULL */\n+\t\temit(A64_CBZ(1, dst, 2), ctx);\n+\t\tsrc = dst;\n+\t}\n+\temit(A64_SUB(0, dst, src, base_lo), ctx);\n+}\n+\n static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,\n-\t\t const struct btf_func_model *m,\n-\t\t const struct arg_aux *a,\n-\t\t bool for_call_origin)\n+\t\t const struct btf_func_model *m, const struct arg_aux *a,\n+\t\t bool for_call_origin, bool is_struct_ops, u64 arena_base)\n {\n-\tint i;\n-\tint reg;\n-\tint doff;\n-\tint soff;\n-\tint slots;\n \tu8 tmp = bpf2a64[TMP_REG_1];\n+\tu8 base_lo = bpf2a64[TMP_REG_2];\n+\tint i, reg, doff, soff, slots;\n+\n+\t/* only the low 32 bits of the base take part in the subtraction */\n+\tif (arena_base)\n+\t\temit_a64_mov_i(0, base_lo, (s32)(u32)arena_base, ctx);\n \n \t/* store arguments to the stack for the bpf program, or restore\n \t * arguments from stack for the original function\n \t */\n-\tfor (reg = 0; reg \u003c a-\u003eregs_for_args; reg++) {\n-\t\temit(for_call_origin ?\n-\t\t A64_LDR64I(reg, A64_SP, bargs_off) :\n-\t\t A64_STR64I(reg, A64_SP, bargs_off),\n-\t\t ctx);\n-\t\tbargs_off += 8;\n+\tfor (i = 0, reg = 0; i \u003c a-\u003eargs_in_regs; i++) {\n+\t\tbool arena_arg = arena_base \u0026\u0026 (m-\u003earg_flags[i] \u0026 BTF_FMODEL_ARENA_ARG);\n+\t\tbool nullable = m-\u003earg_flags[i] \u0026 BTF_FMODEL_NULLABLE_ARG;\n+\n+\t\tslots = (m-\u003earg_size[i] + 7) / 8;\n+\t\twhile (slots-- \u003e 0) {\n+\t\t\tif (for_call_origin) {\n+\t\t\t\temit(A64_LDR64I(reg, A64_SP, bargs_off), ctx);\n+\t\t\t} else if (arena_arg) {\n+\t\t\t\temit_arena_arg_conv(ctx, tmp, reg, nullable, base_lo);\n+\t\t\t\temit(A64_STR64I(tmp, A64_SP, bargs_off), ctx);\n+\t\t\t} else {\n+\t\t\t\temit(A64_STR64I(reg, A64_SP, bargs_off), ctx);\n+\t\t\t}\n+\t\t\treg++;\n+\t\t\tbargs_off += 8;\n+\t\t}\n \t}\n \n-\tsoff = 32; /* on stack arguments start from FP + 32 */\n+\t/*\n+\t * On-stack arguments start above the frame(s) pushed by the trampoline\n+\t * prologue. Entered through the fentry call from a traced function, the\n+\t * prologue saves both the parent (FP/x9) and the traced function\n+\t * (FP/LR) frames, so the arguments start at FP + 32. A struct_ops\n+\t * callback is called indirectly and only the FP/LR frame is saved, so\n+\t * they start at FP + 16.\n+\t */\n+\tsoff = is_struct_ops ? 16 : 32;\n \tdoff = (for_call_origin ? oargs_off : bargs_off);\n \n \t/* save on stack arguments */\n \tfor (i = a-\u003eargs_in_regs; i \u003c m-\u003enr_args; i++) {\n+\t\tbool arena_arg = arena_base \u0026\u0026 (m-\u003earg_flags[i] \u0026 BTF_FMODEL_ARENA_ARG);\n+\t\tbool nullable = m-\u003earg_flags[i] \u0026 BTF_FMODEL_NULLABLE_ARG;\n+\n \t\tslots = (m-\u003earg_size[i] + 7) / 8;\n \t\t/* verifier ensures arg_size \u003c= 16, so slots equals 1 or 2 */\n \t\twhile (slots-- \u003e 0) {\n@@ -2561,6 +2650,15 @@ static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,\n \t\t\t */\n \t\t\tif (slots == 0 \u0026\u0026 !for_call_origin)\n \t\t\t\tclear_garbage(ctx, tmp, m-\u003earg_size[i] % 8);\n+\t\t\t/*\n+\t\t\t * No guard on for_call_origin here: only the indirect\n+\t\t\t * trampoline is given a base, and it never calls the\n+\t\t\t * original function, so arguments are never converted\n+\t\t\t * on their way back out to it. See the WARN_ON_ONCE()\n+\t\t\t * in prepare_trampoline().\n+\t\t\t */\n+\t\t\tif (arena_arg)\n+\t\t\t\temit_arena_arg_conv(ctx, tmp, tmp, nullable, base_lo);\n \t\t\temit(A64_STR64I(tmp, A64_SP, doff), ctx);\n \t\t\tsoff += 8;\n \t\t\tdoff += 8;\n@@ -2620,8 +2718,21 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,\n \tbool is_struct_ops = is_struct_ops_tramp(fentry);\n \tint cookie_off, cookie_cnt, cookie_bargs_off;\n \tint fsession_cnt = bpf_fsession_cnt(tnodes);\n+\tu64 arena_base;\n \tu64 func_meta;\n \n+\t/*\n+\t * F_INDIRECT is only compatible with F_RET_FENTRY_RET, it is explicitly\n+\t * incompatible with F_CALL_ORIG | F_SKIP_FRAME | F_IP_ARG because\n+\t * @func_addr. Arena conversion relies on this: bpf_tramp_arena_base()\n+\t * only returns a base for the indirect trampoline, which therefore\n+\t * never calls the original function with converted arguments.\n+\t */\n+\tWARN_ON_ONCE((flags \u0026 BPF_TRAMP_F_INDIRECT) \u0026\u0026\n+\t\t (flags \u0026 ~(BPF_TRAMP_F_INDIRECT | BPF_TRAMP_F_RET_FENTRY_RET)));\n+\n+\tarena_base = bpf_tramp_arena_base(m, tnodes, flags);\n+\n \t/* trampoline stack layout:\n \t * [ parent ip ]\n \t * [ FP ]\n@@ -2737,7 +2848,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,\n \tstore_func_meta(ctx, func_meta, func_meta_off);\n \n \t/* save args for bpf */\n-\tsave_args(ctx, bargs_off, oargs_off, m, a, false);\n+\tsave_args(ctx, bargs_off, oargs_off, m, a, false, is_struct_ops, arena_base);\n \n \t/* save callee saved registers */\n \temit(A64_STR64I(A64_R(19), A64_SP, regs_off), ctx);\n@@ -2785,8 +2896,8 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,\n \t}\n \n \tif (flags \u0026 BPF_TRAMP_F_CALL_ORIG) {\n-\t\t/* save args for original func */\n-\t\tsave_args(ctx, bargs_off, oargs_off, m, a, true);\n+\t\t/* the original func takes kernel addresses, never converted ones */\n+\t\tsave_args(ctx, bargs_off, oargs_off, m, a, true, is_struct_ops, 0);\n \t\t/* call original func */\n \t\temit(A64_LDR64I(A64_R(10), A64_SP, retaddr_off), ctx);\n \t\temit(A64_ADR(A64_LR, AARCH64_INSN_SIZE * 2), ctx);\ndiff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c\nindex 940ec2cda0d52..7f9f54ba3fbe5 100644\n--- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c\n+++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c\n@@ -6,7 +6,7 @@\n #include \"struct_ops_arena_attach.skel.h\"\n #include \"struct_ops_arena_fail.skel.h\"\n \n-#if defined(__x86_64__)\n+#if defined(__x86_64__) || defined(__aarch64__)\n /*\n * Attach callbacks with __arena and __arena__nullable arguments and drive\n * them through the bpf_testmod_ops3_call_test_arena*() kfuncs.\n@@ -111,11 +111,11 @@ static void arena_arg_attach(void)\n void serial_test_struct_ops_arena(void)\n {\n \t/*\n-\t * Arena struct_ops arguments need JIT support, currently x86-64 only.\n-\t * Elsewhere verification fails with \"JIT does not support arena\n-\t * arguments\", so the programs cannot even load.\n+\t * Arena struct_ops arguments need JIT support, currently x86-64 and\n+\t * arm64 only. Elsewhere verification fails with \"JIT does not support\n+\t * arena arguments\", so the programs cannot even load.\n \t */\n-#if defined(__x86_64__)\n+#if defined(__x86_64__) || defined(__aarch64__)\n \tif (test__start_subtest(\"arena_arg\"))\n \t\tarena_arg();\n \tif (test__start_subtest(\"arena_arg_fail\"))\ndiff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c\nindex cdcea889da586..bf0d304e0e59c 100644\n--- a/tools/testing/selftests/bpf/progs/arena_kfunc.c\n+++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c\n@@ -27,6 +27,7 @@ volatile u64 stash;\n \n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __success __retval(0)\n int arena_arg_forms(void *ctx)\n {\n@@ -70,6 +71,7 @@ int arena_arg_forms(void *ctx)\n */\n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __success __retval(0)\n int arena_arg_rebase(void *ctx)\n {\n@@ -111,6 +113,7 @@ int arena_arg_rebase(void *ctx)\n \n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __success __retval(0)\n int arena_args5(void *ctx)\n {\n@@ -142,6 +145,7 @@ int arena_args5(void *ctx)\n \n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __success __retval(0)\n int arena_arg_mixed(void *ctx)\n {\n@@ -169,6 +173,7 @@ int arena_arg_mixed(void *ctx)\n /* kernel-side faults on unpopulated pages recover via the scratch page */\n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __success __retval(0)\n int arena_arg_unpopulated(void *ctx)\n {\n@@ -189,6 +194,7 @@ int arena_arg_unpopulated(void *ctx)\n \n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __failure __msg(\"arena pointer requires a program with an associated arena\")\n int arena_arg_no_arena(void *ctx)\n {\n@@ -198,6 +204,7 @@ int arena_arg_no_arena(void *ctx)\n \n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __failure __msg(\"is not a pointer to arena or scalar\")\n int arena_arg_bad_reg(void *ctx)\n {\n@@ -213,6 +220,7 @@ int arena_arg_bad_reg(void *ctx)\n \tdefined(__BPF_FEATURE_STACK_ARGUMENT)\n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __failure __msg(\"arena pointer cannot be a stack argument\")\n int arena_arg_stack(void *ctx)\n {\n@@ -223,6 +231,7 @@ int arena_arg_stack(void *ctx)\n #else\n SEC(\"syscall\")\n __arch_x86_64\n+__arch_arm64\n __description(\"arena_arg_stack: not supported, dummy test\")\n __success\n int arena_arg_stack(void *ctx)\ndiff --git a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c\nindex c9b9186626162..b5a01cbc33a73 100644\n--- a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c\n+++ b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c\n@@ -32,6 +32,10 @@ __jited(\"\tmovl\t%edi, %edi\")\n __jited(\"\taddq\t%r12, %rdi\")\n __jited(\"...\")\n __jited(\"\tcallq\t{{.*}}\")\n+__arch_arm64\n+__jited(\"...\")\n+__jited(\"\tadd\tx0, x28, w0, uxtw\")\n+__jited(\"\t{{(bl|mov)\t.*}}\")\n __success\n int arena_arg_jit_rebase(void *ctx)\n {\n@@ -48,6 +52,12 @@ __jited(\"\ttestl\t%edi, %edi\")\n __jited(\"\tje\tL0\")\n __jited(\"\taddq\t%r12, %rdi\")\n __jited(\"L0:\tcallq\t{{.*}}\")\n+__arch_arm64\n+__jited(\"...\")\n+__jited(\"\tmov\tw0, w0\")\n+__jited(\"\tcbz\tw0, L0\")\n+__jited(\"\tadd\tx0, x28, w0, uxtw\")\n+__jited(\"L0:\t{{.*}}\")\n __success\n int arena_arg_jit_nullable(void *ctx)\n {\n@@ -72,6 +82,16 @@ __jited(\"\ttestl\t%r8d, %r8d\")\n __jited(\"\tje\tL0\")\n __jited(\"\taddq\t%r12, %r8\")\n __jited(\"L0:\tcallq\t{{.*}}\")\n+__arch_arm64\n+__jited(\"...\")\n+__jited(\"\tadd\tx0, x28, w0, uxtw\")\n+__jited(\"\tadd\tx1, x28, w1, uxtw\")\n+__jited(\"\tadd\tx2, x28, w2, uxtw\")\n+__jited(\"\tadd\tx3, x28, w3, uxtw\")\n+__jited(\"\tmov\tw4, w4\")\n+__jited(\"\tcbz\tw4, L0\")\n+__jited(\"\tadd\tx4, x28, w4, uxtw\")\n+__jited(\"L0:\t{{.*}}\")\n __success\n int arena_arg_jit_args5(void *ctx)\n {\ndiff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena.c b/tools/testing/selftests/bpf/progs/struct_ops_arena.c\nindex ba04c73d8d967..8aa8639df91f0 100644\n--- a/tools/testing/selftests/bpf/progs/struct_ops_arena.c\n+++ b/tools/testing/selftests/bpf/progs/struct_ops_arena.c\n@@ -59,11 +59,28 @@ int test_arena_stack_cb(unsigned long long *ctx)\n \treturn 0;\n }\n \n+SEC(\"struct_ops/test_arena_multislot\")\n+int test_arena_multislot_cb(unsigned long long *ctx)\n+{\n+\tu64 __arena *ptr = (u64 __arena *)ctx[2];\n+\n+\tarena_touch++;\n+\t/*\n+\t * The 16-byte struct occupies ctx[0] and ctx[1], so @ptr is argument\n+\t * one but slot two. Getting that wrong hands the callback a scalar.\n+\t */\n+\tif (ctx[0] != 11 || ctx[1] != 22)\n+\t\treturn 0xbad;\n+\t*ptr += 1;\n+\treturn 0;\n+}\n+\n SEC(\".struct_ops.link\")\n struct bpf_testmod_ops3 testmod_arena = {\n \t.test_arena = (void *)test_arena_cb,\n \t.test_arena_nullable = (void *)test_arena_nullable_cb,\n \t.test_arena_stack = (void *)test_arena_stack_cb,\n+\t.test_arena_multislot = (void *)test_arena_multislot_cb,\n };\n \n SEC(\"syscall\")\n@@ -109,6 +126,13 @@ int trigger(void *ctx)\n \tif (*val != 44)\n \t\treturn 9;\n \n+\t/* a multi-slot arg precedes the arena pointer here */\n+\tret = bpf_testmod_ops3_call_test_arena_multislot((u64 *)val);\n+\tif (ret)\n+\t\treturn 10;\n+\tif (*val != 45)\n+\t\treturn 11;\n+\n \tbpf_arena_free_pages(\u0026arena, (void __arena *)val, 1);\n #endif\n \treturn 0;\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\nindex a6133f7521f34..9366a3c578f13 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n@@ -402,12 +402,19 @@ static int bpf_testmod_ops3__test_arena_stack(u64 a, u64 b, u64 c, u64 d,\n \treturn 0;\n }\n \n+static int bpf_testmod_ops3__test_arena_multislot(struct bpf_testmod_arena_pair p,\n+\t\t\t\t\t\t u64 *ptr__arena)\n+{\n+\treturn 0;\n+}\n+\n static struct bpf_testmod_ops3 __bpf_testmod_ops3 = {\n \t.test_1 = bpf_testmod_test_3,\n \t.test_2 = bpf_testmod_test_4,\n \t.test_arena = bpf_testmod_ops3__test_arena,\n \t.test_arena_nullable = bpf_testmod_ops3__test_arena_nullable,\n \t.test_arena_stack = bpf_testmod_ops3__test_arena_stack,\n+\t.test_arena_multislot = bpf_testmod_ops3__test_arena_multislot,\n };\n \n static void bpf_testmod_test_struct_ops3(void)\n@@ -441,6 +448,13 @@ __bpf_kfunc int bpf_testmod_ops3_call_test_arena_stack(u64 *ptr__arena)\n \treturn st_ops3-\u003etest_arena_stack(1, 2, 3, 4, 5, 6, 7, 8, ptr__arena);\n }\n \n+__bpf_kfunc int bpf_testmod_ops3_call_test_arena_multislot(u64 *ptr__arena)\n+{\n+\tstruct bpf_testmod_arena_pair p = { .a = 11, .b = 22 };\n+\n+\treturn st_ops3-\u003etest_arena_multislot(p, ptr__arena);\n+}\n+\n struct bpf_testmod_btf_type_tag_1 {\n \tint a;\n };\n@@ -852,6 +866,7 @@ BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_2)\n BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena)\n BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_nullable)\n BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_stack)\n+BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_multislot)\n BTF_ID_FLAGS(func, bpf_kfunc_get_default_trusted_ptr_test);\n BTF_ID_FLAGS(func, bpf_kfunc_put_default_trusted_ptr_test);\n BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids)\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\nindex 33f2af5b70857..210b919290cc2 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\n@@ -103,6 +103,12 @@ struct bpf_testmod_ops2 {\n \tint (*test_1)(void);\n };\n \n+/* 16 bytes, so it takes two argument slots when passed by value */\n+struct bpf_testmod_arena_pair {\n+\tu64 a;\n+\tu64 b;\n+};\n+\n struct bpf_testmod_ops3 {\n \tint (*test_1)(void);\n \tint (*test_2)(void);\n@@ -112,6 +118,8 @@ struct bpf_testmod_ops3 {\n \t/* enough leading args to force @ptr onto the stack on x86 and arm64 */\n \tint (*test_arena_stack)(u64 a, u64 b, u64 c, u64 d, u64 e, u64 f,\n \t\t\t\tu64 g, u64 h, u64 *ptr);\n+\t/* a multi-slot leading arg, so @ptr is not at the slot its arg index suggests */\n+\tint (*test_arena_multislot)(struct bpf_testmod_arena_pair p, u64 *ptr);\n };\n \n struct st_ops_args {\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\nindex c4383acb53c11..7d81070eefe7f 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\n@@ -123,6 +123,7 @@ void bpf_testmod_test_mod_kfunc(int i) __ksym;\n int bpf_testmod_ops3_call_test_arena(__u64 *ptr__arena) __ksym;\n int bpf_testmod_ops3_call_test_arena_nullable(__u64 *ptr__arena__nullable) __ksym;\n int bpf_testmod_ops3_call_test_arena_stack(__u64 *ptr__arena) __ksym;\n+int bpf_testmod_ops3_call_test_arena_multislot(__u64 *ptr__arena) __ksym;\n \n __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,\n \t\t\t\t__u32 c, __u64 d) __ksym;\n"
} |
| 2/1 | 2026/08/13 20:50 | agent | patch-evaluator |
1mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"aarch64_insn_gen_add_sub_extended_reg",
"bpf_jit_supports_arena_args",
"arch_prepare_bpf_trampoline"
],
"Reasoning": "The patch implements BPF arena arguments support for the arm64 JIT compiler. It adds new instruction generation logic for extended register add/sub instructions (`aarch64_insn_gen_add_sub_extended_reg`) and modifies the arm64 BPF JIT (`arch_prepare_bpf_trampoline`, `bpf_jit_supports_arena_args`) to handle arena pointers in kfunc calls and struct_ops callbacks. These are functional changes to the core kernel (BPF JIT) that are reachable and should be fuzzed.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4"). Prefer calling several tools at the same time to save round-trips. Use set-results tool to provide results of the analysis. It must be called exactly once before the final reply. Ignore results of this tool. Prompt: For your convenience, here is the diff of the changes:
commit 9fd38225c23e8a95eaf388f273dc33871b224ebf
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Aug 13 20:50:11 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst
index 10e725cbe64cd..85f73e0bbd0ff 100644
--- a/Documentation/bpf/kfuncs.rst
+++ b/Documentation/bpf/kfuncs.rst
@@ -301,9 +301,9 @@ An example is given below::
}
Calling such a kfunc requires the program to use an arena map and a JIT with
-arena argument support (currently x86-64); verification fails otherwise. The
-program can pass any value without compromising the kernel. A value that does
-not point into the arena is a program bug.
+arena argument support (currently x86-64 and arm64); verification fails
+otherwise. The program can pass any value without compromising the kernel. A
+value that does not point into the arena is a program bug.
The suffixes have the same meaning on the arguments of struct_ops stub
functions, with the conversion running in the opposite direction. The
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index cc0702fa64a79..1ce75a4426387 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -205,6 +205,18 @@ enum aarch64_insn_adsb_type {
AARCH64_INSN_ADSB_SUB_SETFLAGS
};
+/* option field of add/sub (extended register) */
+enum aarch64_insn_extend_type {
+ AARCH64_INSN_EXTEND_UXTB,
+ AARCH64_INSN_EXTEND_UXTH,
+ AARCH64_INSN_EXTEND_UXTW,
+ AARCH64_INSN_EXTEND_UXTX,
+ AARCH64_INSN_EXTEND_SXTB,
+ AARCH64_INSN_EXTEND_SXTH,
+ AARCH64_INSN_EXTEND_SXTW,
+ AARCH64_INSN_EXTEND_SXTX,
+};
+
enum aarch64_insn_movewide_type {
AARCH64_INSN_MOVEWIDE_ZERO,
AARCH64_INSN_MOVEWIDE_KEEP,
@@ -378,6 +390,10 @@ __AARCH64_INSN_FUNCS(add, 0x7F200000, 0x0B000000)
__AARCH64_INSN_FUNCS(adds, 0x7F200000, 0x2B000000)
__AARCH64_INSN_FUNCS(sub, 0x7F200000, 0x4B000000)
__AARCH64_INSN_FUNCS(subs, 0x7F200000, 0x6B000000)
+__AARCH64_INSN_FUNCS(add_ext, 0x7FE00000, 0x0B200000)
+__AARCH64_INSN_FUNCS(adds_ext, 0x7FE00000, 0x2B200000)
+__AARCH64_INSN_FUNCS(sub_ext, 0x7FE00000, 0x4B200000)
+__AARCH64_INSN_FUNCS(subs_ext, 0x7FE00000, 0x6B200000)
__AARCH64_INSN_FUNCS(madd, 0x7FE08000, 0x1B000000)
__AARCH64_INSN_FUNCS(msub, 0x7FE08000, 0x1B008000)
__AARCH64_INSN_FUNCS(udiv, 0x7FE0FC00, 0x1AC00800)
@@ -637,6 +653,13 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,
int shift,
enum aarch64_insn_variant variant,
enum aarch64_insn_adsb_type type);
+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,
+ enum aarch64_insn_register src,
+ enum aarch64_insn_register reg,
+ enum aarch64_insn_extend_type extend,
+ int shift,
+ enum aarch64_insn_variant variant,
+ enum aarch64_insn_adsb_type type);
u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,
enum aarch64_insn_register src,
enum aarch64_insn_variant variant,
diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c
index 37ce75f7f1f08..e70ac02385153 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -986,6 +986,66 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,
return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn, shift);
}
+/*
+ * Unlike the shifted-register form, register 31 is not XZR everywhere here:
+ * it encodes SP for @src, and for @dst too unless @type sets the flags. Only
+ * @reg keeps the XZR meaning.
+ */
+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,
+ enum aarch64_insn_register src,
+ enum aarch64_insn_register reg,
+ enum aarch64_insn_extend_type extend,
+ int shift,
+ enum aarch64_insn_variant variant,
+ enum aarch64_insn_adsb_type type)
+{
+ u32 insn;
+
+ switch (type) {
+ case AARCH64_INSN_ADSB_ADD:
+ insn = aarch64_insn_get_add_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_SUB:
+ insn = aarch64_insn_get_sub_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_ADD_SETFLAGS:
+ insn = aarch64_insn_get_adds_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_SUB_SETFLAGS:
+ insn = aarch64_insn_get_subs_ext_value();
+ break;
+ default:
+ pr_err("%s: unknown add/sub encoding %d\n", __func__, type);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ switch (variant) {
+ case AARCH64_INSN_VARIANT_32BIT:
+ break;
+ case AARCH64_INSN_VARIANT_64BIT:
+ insn |= AARCH64_INSN_SF_BIT;
+ break;
+ default:
+ pr_err("%s: unknown variant encoding %d\n", __func__, variant);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ if (shift < 0 || shift > 4) {
+ pr_err("%s: invalid shift encoding %d\n", __func__, shift);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RD, insn, dst);
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RN, insn, src);
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RM, insn, reg);
+
+ /* option in bits [15:13] and imm3 in [12:10] together fill IMM_6 */
+ return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn,
+ (extend << 3) | shift);
+}
+
u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,
enum aarch64_insn_register src,
enum aarch64_insn_variant variant,
diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h
index d13de4222cfb7..b2fe6e6dcf447 100644
--- a/arch/arm64/net/bpf_jit.h
+++ b/arch/arm64/net/bpf_jit.h
@@ -243,6 +243,17 @@
/* Rn - Rm; set condition flags */
#define A64_CMP(sf, Rn, Rm) A64_SUBS(sf, A64_ZR, Rn, Rm)
+/* Add/subtract (extended register) */
+#define A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, type) \
+ aarch64_insn_gen_add_sub_extended_reg(Rd, Rn, Rm, \
+ AARCH64_INSN_EXTEND_##ext, shift, A64_VARIANT(sf), \
+ AARCH64_INSN_ADSB_##type)
+/* Rd = Rn + (EXT(Rm) << shift) */
+#define A64_ADD_EXT(sf, Rd, Rn, Rm, ext, shift) \
+ A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, ADD)
+/* Rd = Rn + (u32)Rm */
+#define A64_ADD_UXTW(Rd, Rn, Rm) A64_ADD_EXT(1, Rd, Rn, Rm, UXTW, 0)
+
/* Data-processing (1 source) */
#define A64_DATA1(sf, Rd, Rn, type) aarch64_insn_gen_data1(Rd, Rn, \
A64_VARIANT(sf), AARCH64_INSN_DATA1_##type)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 74b4083791da3..c18e005a41dbe 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1256,6 +1256,43 @@ static void emit_stack_arg_store_imm(s32 imm, s16 bpf_off, const u8 tmp, struct
}
}
+/*
+ * Rebase the __arena args of a kfunc call to arena kernel addresses,
+ * xN = kern_vm_start + (u32)xN, with the arena base register holding
+ * kern_vm_start. A nullable arg preserves NULL by skipping the add, tested
+ * on the truncated value as arena NULL is offset 0.
+ */
+static int emit_kfunc_arena_args(struct jit_ctx *ctx, const struct bpf_insn *insn)
+{
+ const u8 arena_vm_base = bpf2a64[ARENA_VM_START];
+ const struct btf_func_model *fm;
+ int i;
+
+ fm = bpf_jit_find_kfunc_model(ctx->prog, insn);
+ if (!fm)
+ return -EINVAL;
+
+ for (i = 0; i < min_t(int, fm->nr_args, MAX_BPF_FUNC_REG_ARGS); i++) {
+ const u8 reg = bpf2a64[BPF_REG_1 + i];
+ u8 flags = fm->arg_flags[i];
+
+ if (!(flags & BTF_FMODEL_ARENA_ARG))
+ continue;
+ if (WARN_ON_ONCE(!ctx->arena_vm_start))
+ return -EINVAL;
+
+ if (flags & BTF_FMODEL_NULLABLE_ARG) {
+ /* 32-bit mov clears the upper 32 bits */
+ emit(A64_MOV(0, reg, reg), ctx);
+ /* skip the add so that NULL stays NULL */
+ emit(A64_CBZ(0, reg, 2), ctx);
+ }
+ emit(A64_ADD_UXTW(reg, arena_vm_base, reg), ctx);
+ }
+
+ return 0;
+}
+
/* JITs an eBPF instruction.
* Returns:
* 0 - successfully JITed an 8-byte eBPF instruction.
@@ -1678,6 +1715,11 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
&func_addr, &func_addr_fixed);
if (ret < 0)
return ret;
+ if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) {
+ ret = emit_kfunc_arena_args(ctx, insn);
+ if (ret < 0)
+ return ret;
+ }
emit_call(func_addr, ctx);
/*
* Call to arch_bpf_timed_may_goto() is emitted by the
@@ -2351,6 +2393,11 @@ bool bpf_jit_supports_stack_args(void)
return true;
}
+bool bpf_jit_supports_arena_args(void)
+{
+ return true;
+}
+
void *bpf_arch_text_copy(void *dst, void *src, size_t len)
{
if (!aarch64_insn_copy(dst, src, len))
@@ -2524,34 +2571,76 @@ static void clear_garbage(struct jit_ctx *ctx, int reg, int effective_bytes)
}
}
+/*
+ * Convert an arena kernel address into the arena pointer form on its way into
+ * the BPF ctx, dst = (u32)(src - kern_vm_start), with @base_lo holding the low
+ * 32 bits of kern_vm_start. A nullable arg preserves NULL, tested on the full
+ * 64-bit kernel pointer. The 32-bit subtraction both truncates and clears the
+ * upper half, so the stored value satisfies the JIT invariant for arena
+ * pointer registers.
+ */
+static void emit_arena_arg_conv(struct jit_ctx *ctx, u8 dst, u8 src, bool nullable, u8 base_lo)
+{
+ if (nullable) {
+ if (dst != src)
+ emit(A64_MOV(1, dst, src), ctx);
+ /* skip the subtraction so that NULL stays NULL */
+ emit(A64_CBZ(1, dst, 2), ctx);
+ src = dst;
+ }
+ emit(A64_SUB(0, dst, src, base_lo), ctx);
+}
+
static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,
- const struct btf_func_model *m,
- const struct arg_aux *a,
- bool for_call_origin)
+ const struct btf_func_model *m, const struct arg_aux *a,
+ bool for_call_origin, bool is_struct_ops, u64 arena_base)
{
- int i;
- int reg;
- int doff;
- int soff;
- int slots;
u8 tmp = bpf2a64[TMP_REG_1];
+ u8 base_lo = bpf2a64[TMP_REG_2];
+ int i, reg, doff, soff, slots;
+
+ /* only the low 32 bits of the base take part in the subtraction */
+ if (arena_base)
+ emit_a64_mov_i(0, base_lo, (s32)(u32)arena_base, ctx);
/* store arguments to the stack for the bpf program, or restore
* arguments from stack for the original function
*/
- for (reg = 0; reg < a->regs_for_args; reg++) {
- emit(for_call_origin ?
- A64_LDR64I(reg, A64_SP, bargs_off) :
- A64_STR64I(reg, A64_SP, bargs_off),
- ctx);
- bargs_off += 8;
+ for (i = 0, reg = 0; i < a->args_in_regs; i++) {
+ bool arena_arg = arena_base && (m->arg_flags[i] & BTF_FMODEL_ARENA_ARG);
+ bool nullable = m->arg_flags[i] & BTF_FMODEL_NULLABLE_ARG;
+
+ slots = (m->arg_size[i] + 7) / 8;
+ while (slots-- > 0) {
+ if (for_call_origin) {
+ emit(A64_LDR64I(reg, A64_SP, bargs_off), ctx);
+ } else if (arena_arg) {
+ emit_arena_arg_conv(ctx, tmp, reg, nullable, base_lo);
+ emit(A64_STR64I(tmp, A64_SP, bargs_off), ctx);
+ } else {
+ emit(A64_STR64I(reg, A64_SP, bargs_off), ctx);
+ }
+ reg++;
+ bargs_off += 8;
+ }
}
- soff = 32; /* on stack arguments start from FP + 32 */
+ /*
+ * On-stack arguments start above the frame(s) pushed by the trampoline
+ * prologue. Entered through the fentry call from a traced function, the
+ * prologue saves both the parent (FP/x9) and the traced function
+ * (FP/LR) frames, so the arguments start at FP + 32. A struct_ops
+ * callback is called indirectly and only the FP/LR frame is saved, so
+ * they start at FP + 16.
+ */
+ soff = is_struct_ops ? 16 : 32;
doff = (for_call_origin ? oargs_off : bargs_off);
/* save on stack arguments */
for (i = a->args_in_regs; i < m->nr_args; i++) {
+ bool arena_arg = arena_base && (m->arg_flags[i] & BTF_FMODEL_ARENA_ARG);
+ bool nullable = m->arg_flags[i] & BTF_FMODEL_NULLABLE_ARG;
+
slots = (m->arg_size[i] + 7) / 8;
/* verifier ensures arg_size <= 16, so slots equals 1 or 2 */
while (slots-- > 0) {
@@ -2561,6 +2650,15 @@ static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,
*/
if (slots == 0 && !for_call_origin)
clear_garbage(ctx, tmp, m->arg_size[i] % 8);
+ /*
+ * No guard on for_call_origin here: only the indirect
+ * trampoline is given a base, and it never calls the
+ * original function, so arguments are never converted
+ * on their way back out to it. See the WARN_ON_ONCE()
+ * in prepare_trampoline().
+ */
+ if (arena_arg)
+ emit_arena_arg_conv(ctx, tmp, tmp, nullable, base_lo);
emit(A64_STR64I(tmp, A64_SP, doff), ctx);
soff += 8;
doff += 8;
@@ -2620,8 +2718,21 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
bool is_struct_ops = is_struct_ops_tramp(fentry);
int cookie_off, cookie_cnt, cookie_bargs_off;
int fsession_cnt = bpf_fsession_cnt(tnodes);
+ u64 arena_base;
u64 func_meta;
+ /*
+ * F_INDIRECT is only compatible with F_RET_FENTRY_RET, it is explicitly
+ * incompatible with F_CALL_ORIG | F_SKIP_FRAME | F_IP_ARG because
+ * @func_addr. Arena conversion relies on this: bpf_tramp_arena_base()
+ * only returns a base for the indirect trampoline, which therefore
+ * never calls the original function with converted arguments.
+ */
+ WARN_ON_ONCE((flags & BPF_TRAMP_F_INDIRECT) &&
+ (flags & ~(BPF_TRAMP_F_INDIRECT | BPF_TRAMP_F_RET_FENTRY_RET)));
+
+ arena_base = bpf_tramp_arena_base(m, tnodes, flags);
+
/* trampoline stack layout:
* [ parent ip ]
* [ FP ]
@@ -2737,7 +2848,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
store_func_meta(ctx, func_meta, func_meta_off);
/* save args for bpf */
- save_args(ctx, bargs_off, oargs_off, m, a, false);
+ save_args(ctx, bargs_off, oargs_off, m, a, false, is_struct_ops, arena_base);
/* save callee saved registers */
emit(A64_STR64I(A64_R(19), A64_SP, regs_off), ctx);
@@ -2785,8 +2896,8 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
}
if (flags & BPF_TRAMP_F_CALL_ORIG) {
- /* save args for original func */
- save_args(ctx, bargs_off, oargs_off, m, a, true);
+ /* the original func takes kernel addresses, never converted ones */
+ save_args(ctx, bargs_off, oargs_off, m, a, true, is_struct_ops, 0);
/* call original func */
emit(A64_LDR64I(A64_R(10), A64_SP, retaddr_off), ctx);
emit(A64_ADR(A64_LR, AARCH64_INSN_SIZE * 2), ctx);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
index 940ec2cda0d52..7f9f54ba3fbe5 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
@@ -6,7 +6,7 @@
#include "struct_ops_arena_attach.skel.h"
#include "struct_ops_arena_fail.skel.h"
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
/*
* Attach callbacks with __arena and __arena__nullable arguments and drive
* them through the bpf_testmod_ops3_call_test_arena*() kfuncs.
@@ -111,11 +111,11 @@ static void arena_arg_attach(void)
void serial_test_struct_ops_arena(void)
{
/*
- * Arena struct_ops arguments need JIT support, currently x86-64 only.
- * Elsewhere verification fails with "JIT does not support arena
- * arguments", so the programs cannot even load.
+ * Arena struct_ops arguments need JIT support, currently x86-64 and
+ * arm64 only. Elsewhere verification fails with "JIT does not support
+ * arena arguments", so the programs cannot even load.
*/
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
if (test__start_subtest("arena_arg"))
arena_arg();
if (test__start_subtest("arena_arg_fail"))
diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c
index cdcea889da586..bf0d304e0e59c 100644
--- a/tools/testing/selftests/bpf/progs/arena_kfunc.c
+++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c
@@ -27,6 +27,7 @@ volatile u64 stash;
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_forms(void *ctx)
{
@@ -70,6 +71,7 @@ int arena_arg_forms(void *ctx)
*/
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_rebase(void *ctx)
{
@@ -111,6 +113,7 @@ int arena_arg_rebase(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_args5(void *ctx)
{
@@ -142,6 +145,7 @@ int arena_args5(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_mixed(void *ctx)
{
@@ -169,6 +173,7 @@ int arena_arg_mixed(void *ctx)
/* kernel-side faults on unpopulated pages recover via the scratch page */
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_unpopulated(void *ctx)
{
@@ -189,6 +194,7 @@ int arena_arg_unpopulated(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("arena pointer requires a program with an associated arena")
int arena_arg_no_arena(void *ctx)
{
@@ -198,6 +204,7 @@ int arena_arg_no_arena(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("is not a pointer to arena or scalar")
int arena_arg_bad_reg(void *ctx)
{
@@ -213,6 +220,7 @@ int arena_arg_bad_reg(void *ctx)
defined(__BPF_FEATURE_STACK_ARGUMENT)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("arena pointer cannot be a stack argument")
int arena_arg_stack(void *ctx)
{
@@ -223,6 +231,7 @@ int arena_arg_stack(void *ctx)
#else
SEC("syscall")
__arch_x86_64
+__arch_arm64
__description("arena_arg_stack: not supported, dummy test")
__success
int arena_arg_stack(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
index c9b9186626162..b5a01cbc33a73 100644
--- a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
+++ b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
@@ -32,6 +32,10 @@ __jited(" movl %edi, %edi")
__jited(" addq %r12, %rdi")
__jited("...")
__jited(" callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" add x0, x28, w0, uxtw")
+__jited(" {{(bl|mov) .*}}")
__success
int arena_arg_jit_rebase(void *ctx)
{
@@ -48,6 +52,12 @@ __jited(" testl %edi, %edi")
__jited(" je L0")
__jited(" addq %r12, %rdi")
__jited("L0: callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" mov w0, w0")
+__jited(" cbz w0, L0")
+__jited(" add x0, x28, w0, uxtw")
+__jited("L0: {{.*}}")
__success
int arena_arg_jit_nullable(void *ctx)
{
@@ -72,6 +82,16 @@ __jited(" testl %r8d, %r8d")
__jited(" je L0")
__jited(" addq %r12, %r8")
__jited("L0: callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" add x0, x28, w0, uxtw")
+__jited(" add x1, x28, w1, uxtw")
+__jited(" add x2, x28, w2, uxtw")
+__jited(" add x3, x28, w3, uxtw")
+__jited(" mov w4, w4")
+__jited(" cbz w4, L0")
+__jited(" add x4, x28, w4, uxtw")
+__jited("L0: {{.*}}")
__success
int arena_arg_jit_args5(void *ctx)
{
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena.c b/tools/testing/selftests/bpf/progs/struct_ops_arena.c
index ba04c73d8d967..8aa8639df91f0 100644
--- a/tools/testing/selftests/bpf/progs/struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/progs/struct_ops_arena.c
@@ -59,11 +59,28 @@ int test_arena_stack_cb(unsigned long long *ctx)
return 0;
}
+SEC("struct_ops/test_arena_multislot")
+int test_arena_multislot_cb(unsigned long long *ctx)
+{
+ u64 __arena *ptr = (u64 __arena *)ctx[2];
+
+ arena_touch++;
+ /*
+ * The 16-byte struct occupies ctx[0] and ctx[1], so @ptr is argument
+ * one but slot two. Getting that wrong hands the callback a scalar.
+ */
+ if (ctx[0] != 11 || ctx[1] != 22)
+ return 0xbad;
+ *ptr += 1;
+ return 0;
+}
+
SEC(".struct_ops.link")
struct bpf_testmod_ops3 testmod_arena = {
.test_arena = (void *)test_arena_cb,
.test_arena_nullable = (void *)test_arena_nullable_cb,
.test_arena_stack = (void *)test_arena_stack_cb,
+ .test_arena_multislot = (void *)test_arena_multislot_cb,
};
SEC("syscall")
@@ -109,6 +126,13 @@ int trigger(void *ctx)
if (*val != 44)
return 9;
+ /* a multi-slot arg precedes the arena pointer here */
+ ret = bpf_testmod_ops3_call_test_arena_multislot((u64 *)val);
+ if (ret)
+ return 10;
+ if (*val != 45)
+ return 11;
+
bpf_arena_free_pages(&arena, (void __arena *)val, 1);
#endif
return 0;
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index a6133f7521f34..9366a3c578f13 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -402,12 +402,19 @@ static int bpf_testmod_ops3__test_arena_stack(u64 a, u64 b, u64 c, u64 d,
return 0;
}
+static int bpf_testmod_ops3__test_arena_multislot(struct bpf_testmod_arena_pair p,
+ u64 *ptr__arena)
+{
+ return 0;
+}
+
static struct bpf_testmod_ops3 __bpf_testmod_ops3 = {
.test_1 = bpf_testmod_test_3,
.test_2 = bpf_testmod_test_4,
.test_arena = bpf_testmod_ops3__test_arena,
.test_arena_nullable = bpf_testmod_ops3__test_arena_nullable,
.test_arena_stack = bpf_testmod_ops3__test_arena_stack,
+ .test_arena_multislot = bpf_testmod_ops3__test_arena_multislot,
};
static void bpf_testmod_test_struct_ops3(void)
@@ -441,6 +448,13 @@ __bpf_kfunc int bpf_testmod_ops3_call_test_arena_stack(u64 *ptr__arena)
return st_ops3->test_arena_stack(1, 2, 3, 4, 5, 6, 7, 8, ptr__arena);
}
+__bpf_kfunc int bpf_testmod_ops3_call_test_arena_multislot(u64 *ptr__arena)
+{
+ struct bpf_testmod_arena_pair p = { .a = 11, .b = 22 };
+
+ return st_ops3->test_arena_multislot(p, ptr__arena);
+}
+
struct bpf_testmod_btf_type_tag_1 {
int a;
};
@@ -852,6 +866,7 @@ BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_2)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_nullable)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_stack)
+BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_multislot)
BTF_ID_FLAGS(func, bpf_kfunc_get_default_trusted_ptr_test);
BTF_ID_FLAGS(func, bpf_kfunc_put_default_trusted_ptr_test);
BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
index 33f2af5b70857..210b919290cc2 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
@@ -103,6 +103,12 @@ struct bpf_testmod_ops2 {
int (*test_1)(void);
};
+/* 16 bytes, so it takes two argument slots when passed by value */
+struct bpf_testmod_arena_pair {
+ u64 a;
+ u64 b;
+};
+
struct bpf_testmod_ops3 {
int (*test_1)(void);
int (*test_2)(void);
@@ -112,6 +118,8 @@ struct bpf_testmod_ops3 {
/* enough leading args to force @ptr onto the stack on x86 and arm64 */
int (*test_arena_stack)(u64 a, u64 b, u64 c, u64 d, u64 e, u64 f,
u64 g, u64 h, u64 *ptr);
+ /* a multi-slot leading arg, so @ptr is not at the slot its arg index suggests */
+ int (*test_arena_multislot)(struct bpf_testmod_arena_pair p, u64 *ptr);
};
struct st_ops_args {
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
index c4383acb53c11..7d81070eefe7f 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
@@ -123,6 +123,7 @@ void bpf_testmod_test_mod_kfunc(int i) __ksym;
int bpf_testmod_ops3_call_test_arena(__u64 *ptr__arena) __ksym;
int bpf_testmod_ops3_call_test_arena_nullable(__u64 *ptr__arena__nullable) __ksym;
int bpf_testmod_ops3_call_test_arena_stack(__u64 *ptr__arena) __ksym;
+int bpf_testmod_ops3_call_test_arena_multislot(__u64 *ptr__arena) __ksym;
__u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
__u32 c, __u64 d) __ksym;
|
| 3/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 12407 output: 45 thoughts: 589 Thoughts: **Analyzing the arm64 BPF JIT Arena Argument Support Patch** Okay, so I'm looking at this patch introducing BPF arena argument support for the arm64 JIT compiler. The changes are focused in `arch/arm64/net/bpf_jit_comp.c` and `arch/arm64/lib/insn.c`, with some test updates in `tools/testing/selftests/bpf/`. My immediate thought is this is a core functional change, definitely requiring thorough fuzzing and testing. First, let's zero in on `arch/arm64/net/bpf_jit_comp.c`. The introduction of `emit_kfunc_arena_args`, `bpf_jit_supports_arena_args`, and `emit_arena_arg_conv` along with modifications to `save_args` and `prepare_trampoline` point directly to the new arena argument handling. This is where the core logic lives. Now, let's identify the specific functions. I need to understand the impact precisely. We have `aarch64_insn_gen_add_sub_extended_reg` in `arch/arm64/lib/insn.c` involved, which is relevant since it handles instruction generation, and in `arch/arm64/net/bpf_jit_comp.c`, we have `emit_kfunc_arena_args`, `build_insn`, `bpf_jit_supports_arena_args`, `emit_arena_arg_conv`, `save_args`, and `prepare_trampoline`. Wait, let me make sure I'm not missing anything. `bpf_jit_supports_arena_args` is exported, meaning it's potentially used elsewhere. Similarly, `aarch64_insn_gen_add_sub_extended_reg` is non-static so it's likely used by other parts of the kernel as well. While the main entry point `bpf_int_jit_compile` isn't directly modified, I see that `build_insn`, which is called within `bpf_int_jit_compile`, is modified. I should probably pay attention to the call stack there. Also, since `prepare_trampoline` is part of the change, and I see `bpf_trampoline_update` or similar calls this through `arch_prepare_bpf_trampoline`, I should check `arch/arm64/net/bpf_jit_comp.c` for `arch_prepare_bpf_trampoline`. That function is probably important, as the trampoline is how we actually *use* the compiled BPF. |
| 4/2 | 2026/08/13 20:50 | tool | grepper |
0mArgs:{
"Expression": "arch_prepare_bpf_trampoline",
"PathPrefix": "arch/arm64/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=2679=static void store_func_meta(struct jit_ctx *ctx, u64 func_meta, int func_meta_off)\n--\narch/arm64/net/bpf_jit_comp.c-2684-\narch/arm64/net/bpf_jit_comp.c:2685:/* Based on the x86's implementation of arch_prepare_bpf_trampoline().\narch/arm64/net/bpf_jit_comp.c-2686- *\n--\narch/arm64/net/bpf_jit_comp.c=3020=int arch_protect_bpf_trampoline(void *image, unsigned int size)\n--\narch/arm64/net/bpf_jit_comp.c-3024-\narch/arm64/net/bpf_jit_comp.c:3025:int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,\narch/arm64/net/bpf_jit_comp.c-3026-\t\t\t\tvoid *ro_image_end, const struct btf_func_model *m,\n"
} |
| 5/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 13942 output: 43 thoughts: 67 Thoughts: **Analyzing BPF Compilation Entry Points** Okay, so I'm diving into this BPF trampoline and JIT compilation setup. From what I'm seeing, `arch_prepare_bpf_trampoline` is the key entry point for handling trampolines, which makes sense. Then, for the actual JIT compilation process, `bpf_int_jit_compile` seems to be the main starting point. Now, I want to take a closer look and make sure that `aarch64_insn_gen_add_sub_extended_reg` is actually exported and accessible. I need to verify that it's correctly exposed within the architecture-specific instruction generation components. I need to make sure that the building blocks are all available to the main process. |
| 6/2 | 2026/08/13 20:50 | tool | grepper |
0mArgs:{
"Expression": "aarch64_insn_gen_add_sub_extended_reg",
"PathPrefix": "arch/arm64/"
}Results: {
"Output": "arch/arm64/include/asm/insn.h=650=u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n--\narch/arm64/include/asm/insn.h-655-\t\t\t\t\t enum aarch64_insn_adsb_type type);\narch/arm64/include/asm/insn.h:656:u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\narch/arm64/include/asm/insn.h-657-\t\t\t\t\t enum aarch64_insn_register src,\n--\narch/arm64/lib/insn.c=931=u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n--\narch/arm64/lib/insn.c-993- */\narch/arm64/lib/insn.c:994:u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\narch/arm64/lib/insn.c-995-\t\t\t\t\t enum aarch64_insn_register src,\n--\narch/arm64/net/bpf_jit.h-247-#define A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, type) \\\narch/arm64/net/bpf_jit.h:248:\taarch64_insn_gen_add_sub_extended_reg(Rd, Rn, Rm, \\\narch/arm64/net/bpf_jit.h-249-\t\tAARCH64_INSN_EXTEND_##ext, shift, A64_VARIANT(sf), \\\n"
} |
| 7/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 14702 output: 47 thoughts: 27 Thoughts: Okay, here's my attempt at summarizing those thoughts from a first-person, expert perspective, starting with a **bolded header**: **Checking Symbol Export in AArch64 Instruction Generation** Alright, let me think this through. I'm taking a look at this `aarch64_insn_gen_add_sub_extended_reg` function. Now, I need to know if it's actually usable by other parts of the system, or if it's an internal helper. The key question in my mind right now is whether or not it's been explicitly **exported using `EXPORT_SYMBOL`**. That's the crucial detail. Without that, it’s going to be confined to its current compilation unit, which might cause me problems if I try to use it elsewhere. I need to quickly ascertain this to understand how widely available this function is within the larger architecture. The answer will significantly impact the next steps I take in whatever I am trying to achieve. Is it internal, or broadly accessible? Gotta know. |
| 8/2 | 2026/08/13 20:50 | tool | grepper |
0mError:no matches Args: {
"Expression": "EXPORT_SYMBOL.*aarch64_insn_gen_add_sub_extended_reg",
"PathPrefix": "arch/arm64/"
}Results: {
"error": "no matches"
} |
| 9/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15008 output: 30 thoughts: 26 Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person: **Navigating the Arena Argument Landscape** Hmm, no, this isn't as straightforward as a simple "yes" or "no" static flag would imply. The situation's more nuanced than that. The behavior seems dynamic, which means I need to dig deeper. I need to understand whether this platform supports arena arguments, but it's not a given. The crucial next step is to examine the `bpf_jit_supports_arena_args` function. That function will likely shed light on the runtime capabilities and decide where to go from here. It's the key to understanding if my expectations are going to be met, or if I need to take a different approach. |
| 10/2 | 2026/08/13 20:50 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_arena_args",
"PathPrefix": ""
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=2391=bool bpf_jit_supports_stack_args(void)\n--\narch/arm64/net/bpf_jit_comp.c-2395-\narch/arm64/net/bpf_jit_comp.c:2396:bool bpf_jit_supports_arena_args(void)\narch/arm64/net/bpf_jit_comp.c-2397-{\n--\narch/x86/net/bpf_jit_comp.c=4159=bool bpf_jit_supports_stack_args(void)\n--\narch/x86/net/bpf_jit_comp.c-4163-\narch/x86/net/bpf_jit_comp.c:4164:bool bpf_jit_supports_arena_args(void)\narch/x86/net/bpf_jit_comp.c-4165-{\n--\ninclude/linux/filter.h=1240=bool bpf_jit_supports_stack_args(void);\ninclude/linux/filter.h:1241:bool bpf_jit_supports_arena_args(void);\ninclude/linux/filter.h-1242-bool bpf_jit_supports_far_kfunc_call(void);\n--\nkernel/bpf/core.c=3290=bool __weak bpf_jit_supports_stack_args(void)\n--\nkernel/bpf/core.c-3294-\nkernel/bpf/core.c:3295:bool __weak bpf_jit_supports_arena_args(void)\nkernel/bpf/core.c-3296-{\n--\nkernel/bpf/verifier.c=11306=get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n--\nkernel/bpf/verifier.c-11383-\telse if (is_kfunc_arg_arena(meta-\u003ebtf, \u0026args[arg])) {\nkernel/bpf/verifier.c:11384:\t\tif (!bpf_jit_supports_arena_args()) {\nkernel/bpf/verifier.c-11385-\t\t\tverbose(env, \"JIT does not support kfunc %s() with arena pointer arguments\\n\",\n--\nkernel/bpf/verifier.c=18721=static int check_struct_ops_btf_id(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-18810-\t\tif (base_type(info-\u003ereg_type) == PTR_TO_ARENA) {\nkernel/bpf/verifier.c:18811:\t\t\tif (!bpf_jit_supports_arena_args()) {\nkernel/bpf/verifier.c-18812-\t\t\t\tverbose(env, \"JIT does not support arena arguments\\n\");\n"
} |
| 11/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15978 output: 26 thoughts: 214 Thoughts: **My Initial Assessment of the BPF JIT Patch for arm64** Alright, let's break this down. This patch is focused on enabling or improving BPF JIT compilation on arm64. My immediate observations are that the patch adds a function, `bpf_jit_supports_arena_args`, to the arm64 architecture, and it returns true. That's good, indicating this arm64 implementation is actively supporting arena-based argument passing, which is likely a key optimization. Digging deeper, I see a chain of modifications. The patch indirectly touches `arch_prepare_bpf_trampoline` by changing `prepare_trampoline`, which is called by the former. It also changes `build_insn`, which is called by `build_body` which is called by `bpf_int_jit_compile`. So, I need to understand those indirect changes and how they are handled. The key functions to scrutinize, then, are: `bpf_int_jit_compile` – the core JIT compilation function, `arch_prepare_bpf_trampoline` – probably related to the instruction sequence needed for calling into JIT'd code, `aarch64_insn_gen_add_sub_extended_reg` – a specific instruction generator that might have specific ARM64 features being exploited and finally `bpf_jit_supports_arena_args` – the flag signaling the feature's availability. Before diving into the code itself, I'll quickly check for any conditional compilation. The file location (`arch/arm64/net/bpf_jit_comp.c`) tells me where to look and I know this hinges on `CONFIG_BPF_JIT`. I need to ensure that this is enabled and then dig in further. |
| 12/2 | 2026/08/13 20:50 | tool | grepper |
0mArgs:{
"Expression": "config BPF_JIT",
"PathPrefix": ""
}Results: {
"Output": "kernel/bpf/Kconfig=27=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-41-\nkernel/bpf/Kconfig:42:config BPF_JIT\nkernel/bpf/Kconfig-43-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-57-\nkernel/bpf/Kconfig:58:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-59-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-68-\nkernel/bpf/Kconfig:69:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-70-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n"
} |
| 13/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 16828 output: 26 thoughts: 37 Thoughts: Okay, here's my summary, taking on the persona you requested: **Assessing the BPF Feature Requirements** Alright, so the initial thought is crystal clear: we *need* BPF_JIT enabled. No ifs, ands, or buts about it. That's the baseline. Now, the meat of this seems to revolve around this BPF arena concept. My immediate question is: is there a corresponding kernel configuration option to control this? Specifically, is there a `CONFIG_BPF_ARENA` setting? My next step is clearly going to be to verify that configuration option exists and, if so, understand its current state. I need to know if this feature is even *available* in the current build environment before I can move forward. |
| 14/2 | 2026/08/13 20:50 | tool | grepper |
0mError:no matches Args: {
"Expression": "config BPF_ARENA",
"PathPrefix": ""
}Results: {
"error": "no matches"
} |
| 15/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17065 output: 35 thoughts: 53 Thoughts: **My BPF Configuration Concerns** Okay, so I'm diving into this BPF configuration, and the first thing that jumps out is the absence of `CONFIG_BPF_ARENA`. Hmm, interesting. I'll need to remember that. Wait, wait. I know that BPF_SYSCALL is absolutely crucial, so that's a given. Next up, `CONFIG_BPF_JIT`. Yes, of course. I can't imagine this working without the JIT compiler enabled. Let me just confirm things with the `arch/arm64/net/Makefile` to make sure nothing is being overlooked. |
| 16/2 | 2026/08/13 20:50 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_comp",
"PathPrefix": "arch/arm64/net/Makefile"
}Results: {
"Output": "arch/arm64/net/Makefile-4-#\narch/arm64/net/Makefile:5:obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o\n"
} |
| 17/2 | 2026/08/13 20:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17356 output: 43 thoughts: 204 Thoughts: **Analyzing BPF JIT Functionality** Okay, so I'm looking at `CONFIG_BPF_JIT`. That's the key enabling config, obviously. Now, I want to get a lay of the land, see what other related functions are in play here. Let's see... I've got `bpf_int_jit_compile`, `arch_prepare_bpf_trampoline`, `aarch64_insn_gen_add_sub_extended_reg`, and `bpf_jit_supports_arena_args`. Hmm, `bpf_int_jit_compile` looks like a really core, hot-path function for the BPF JIT, very generic in its purpose. `arch_prepare_bpf_trampoline` is also somewhat generic, but slightly more architecture-specific, probably for setting up the execution context. `aarch64_insn_gen_add_sub_extended_reg`, however, that's definitely a specific instruction generator; it's getting down into the weeds of how an add or subtract is handled on AArch64. And finally, `bpf_jit_supports_arena_args` sounds very specific, likely related to how the JIT handles arguments and memory arenas. Given that `aarch64_insn_gen_add_sub_extended_reg` is so focused, I'm going to dig a bit deeper into its callers to get a better understanding of its role in the bigger picture. It could be an interesting point to examine optimization possibilities, depending on how widely it's used. |
| 18/2 | 2026/08/13 20:51 | tool | grepper |
0mArgs:{
"Expression": "aarch64_insn_gen_add_sub_extended_reg",
"PathPrefix": "arch/arm64/"
}Results: {
"Output": "arch/arm64/include/asm/insn.h=650=u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n--\narch/arm64/include/asm/insn.h-655-\t\t\t\t\t enum aarch64_insn_adsb_type type);\narch/arm64/include/asm/insn.h:656:u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\narch/arm64/include/asm/insn.h-657-\t\t\t\t\t enum aarch64_insn_register src,\n--\narch/arm64/lib/insn.c=931=u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,\n--\narch/arm64/lib/insn.c-993- */\narch/arm64/lib/insn.c:994:u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,\narch/arm64/lib/insn.c-995-\t\t\t\t\t enum aarch64_insn_register src,\n--\narch/arm64/net/bpf_jit.h-247-#define A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, type) \\\narch/arm64/net/bpf_jit.h:248:\taarch64_insn_gen_add_sub_extended_reg(Rd, Rn, Rm, \\\narch/arm64/net/bpf_jit.h-249-\t\tAARCH64_INSN_EXTEND_##ext, shift, A64_VARIANT(sf), \\\n"
} |
| 19/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18435 output: 35 thoughts: 153 Thoughts: **Tracing the Call Path to a Critical Function** Okay, so I'm digging into this `aarch64_insn_gen_add_sub_extended_reg` function, and it looks like the call path is fairly contained. The initial hook is within the `A64_ADDSUB_EREG` macro, and the trace from there is pretty direct: `A64_ADDSUB_EREG` gets used in `A64_ADD_EXT`, which feeds into `A64_ADD_UXTW`. Now, `A64_ADD_UXTW` is crucial, as it ends up in both `emit_kfunc_arena_args` and `emit_arena_arg_conv`. This makes it the pivotal symbol for understanding the broader usage. Now I should probably double check the `arch_prepare_bpf_trampoline` function. |
| 20/2 | 2026/08/13 20:51 | tool | grepper |
0mArgs:{
"Expression": "arch_prepare_bpf_trampoline",
"PathPrefix": "arch/arm64/"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=2679=static void store_func_meta(struct jit_ctx *ctx, u64 func_meta, int func_meta_off)\n--\narch/arm64/net/bpf_jit_comp.c-2684-\narch/arm64/net/bpf_jit_comp.c:2685:/* Based on the x86's implementation of arch_prepare_bpf_trampoline().\narch/arm64/net/bpf_jit_comp.c-2686- *\n--\narch/arm64/net/bpf_jit_comp.c=3020=int arch_protect_bpf_trampoline(void *image, unsigned int size)\n--\narch/arm64/net/bpf_jit_comp.c-3024-\narch/arm64/net/bpf_jit_comp.c:3025:int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,\narch/arm64/net/bpf_jit_comp.c-3026-\t\t\t\tvoid *ro_image_end, const struct btf_func_model *m,\n"
} |
| 21/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 19135 output: 35 thoughts: 423 Thoughts: **My Current Line of Thought** Okay, so I'm trying to nail down some good "focus symbols" – key functions that represent the area I'm looking at. `arch_prepare_bpf_trampoline` is a strong candidate, definitely a good starting point. But what about `bpf_int_jit_compile`? It *is* the main entry point for the JIT compiler, which is very relevant, but it's also pretty generic. Maybe too broad. On the other hand, `bpf_jit_supports_arena_args` is really specific and probably represents a clear area to examine. That's a strong contender. I need to see if there are any other specific functions that would be helpful as focus symbols. I found `bpf_testmod_ops3_call_test_arena_multislot` in `tools/testing/selftests/bpf/test_kmods/bpf_testmod.c`. Hmm, but is `bpf_testmod` actually compiled *into* the kernel? Oh right, no, it's a test module! We shouldn't include it in FocusSymbols unless it's part of the core kernel. Nope, it's just a kernel module used for testing. Good to remember. So scratch that. Let's review the current list: * `aarch64_insn_gen_add_sub_extended_reg` * `bpf_jit_supports_arena_args` * `arch_prepare_bpf_trampoline` * `bpf_int_jit_compile` (maybe I'll omit this, it feels a bit too broad) Now, where are these functions defined? Okay, `bpf_jit_supports_arena_args` is in `arch/arm64/net/bpf_jit_comp.c`, and `aarch64_insn_gen_add_sub_extended_reg` is in `arch/arm64/lib/insn.c`. `arch_prepare_bpf_trampoline` is also in `arch/arm64/net/bpf_jit_comp.c`. Okay, next I'll check and ensure that `bpf_jit_supports_arena_args` is actually called to validate that it is something to look at. |
| 22/2 | 2026/08/13 20:51 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_arena_args",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/core.c=3290=bool __weak bpf_jit_supports_stack_args(void)\n--\nkernel/bpf/core.c-3294-\nkernel/bpf/core.c:3295:bool __weak bpf_jit_supports_arena_args(void)\nkernel/bpf/core.c-3296-{\n--\nkernel/bpf/verifier.c=11306=get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n--\nkernel/bpf/verifier.c-11383-\telse if (is_kfunc_arg_arena(meta-\u003ebtf, \u0026args[arg])) {\nkernel/bpf/verifier.c:11384:\t\tif (!bpf_jit_supports_arena_args()) {\nkernel/bpf/verifier.c-11385-\t\t\tverbose(env, \"JIT does not support kfunc %s() with arena pointer arguments\\n\",\n--\nkernel/bpf/verifier.c=18721=static int check_struct_ops_btf_id(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-18810-\t\tif (base_type(info-\u003ereg_type) == PTR_TO_ARENA) {\nkernel/bpf/verifier.c:18811:\t\t\tif (!bpf_jit_supports_arena_args()) {\nkernel/bpf/verifier.c-18812-\t\t\t\tverbose(env, \"JIT does not support arena arguments\\n\");\n"
} |
| 23/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20519 output: 31 thoughts: 120 Thoughts: **Analyzing the BPF JIT Compiler for Arm64** Okay, so I'm digging into the Arm64 BPF JIT compiler and tracing its execution. Right, the starting point is clearly in `kernel/bpf/verifier.c`. Excellent. That narrows my focus considerably. Now, which functions are the key players in the JIT process? Let's see... I need to concentrate on `aarch64_insn_gen_add_sub_extended_reg`, that one's likely doing heavy lifting, and `bpf_jit_supports_arena_args`, which probably relates to argument handling. Of course, `arch_prepare_bpf_trampoline` is crucial for the overall architecture-specific setup. Got it. But before I dive too deep into the code itself, I should make sure I understand the relevant configuration options. `CONFIG_BPF_JIT` is definitely a prerequisite – no surprise there. Are there any *other* configuration options in play that might affect the Arm64 JIT? Time to check `arch/arm64/Kconfig` and verify. Gotta be thorough. |
| 24/2 | 2026/08/13 20:51 | tool | grepper |
0mError:no matches Args: {
"Expression": "config BPF",
"PathPrefix": "arch/arm64/Kconfig"
}Results: {
"error": "no matches"
} |
| 25/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20928 output: 37 thoughts: 26 Thoughts: Here's my thought process, summarized as if I were considering this myself: **Investigating eBPF JIT Support on ARM64** Okay, so I need to figure out if eBPF JIT is supported on the ARM64 architecture, specifically within this kernel. My first instinct is to check the configuration files. Given the architecture, the likely place to find this information is in the architecture-specific Kconfig file, so I'm going to navigate over to `arch/arm64/Kconfig`. I'll be looking for a config option, something like `HAVE_EBPF_JIT`. That should tell me if the necessary features or hardware support are enabled at compile time. This is a standard approach - Kconfig files are the central repository for feature flags and architecture-specific settings. Knowing this, and having experience in this area, my thought process is to quickly, and efficiently find this. This will be my starting point in confirming if the necessary components for eBPF JIT are present. |
| 26/2 | 2026/08/13 20:51 | tool | grepper |
0mArgs:{
"Expression": "HAVE_EBPF_JIT",
"PathPrefix": "arch/arm64/Kconfig"
}Results: {
"Output": "arch/arm64/Kconfig=2=config ARM64\n--\narch/arm64/Kconfig-177-\tselect HAVE_ASM_MODVERSIONS\narch/arm64/Kconfig:178:\tselect HAVE_EBPF_JIT\narch/arm64/Kconfig-179-\tselect HAVE_C_RECORDMCOUNT\n"
} |
| 27/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21307 output: 33 thoughts: 108 Thoughts: **Kernel Configuration for BPF** Okay, so I'm looking at configuring the kernel for BPF functionality. The primary flag I need to enable is definitely `CONFIG_BPF_JIT`. That's the core. Hold on, though, I also need `CONFIG_BPF_SYSCALL` – it's crucial for the BPF system calls to work. Right, I'll be sure to include *both* `BPF_JIT` and `BPF_SYSCALL` in the build configuration. I've been down this road before, no sense making a silly mistake. Now, let me just quickly verify that `aarch64_insn_gen_add_sub_extended_reg` is accessible. I know it's in `arch/arm64/lib/insn.c`, which is compiled directly into the kernel image. No surprises there. Good. This is all looking correct. |
| 28/2 | 2026/08/13 20:51 | tool | grepper |
0mArgs:{
"Expression": "insn\\.o",
"PathPrefix": "arch/arm64/lib/Makefile"
}Results: {
"Output": "arch/arm64/lib/Makefile=2=lib-y\t\t:= clear_user.o delay.o copy_from_user.o\t\t\\\narch/arm64/lib/Makefile-3-\t\t copy_to_user.o copy_page.o\t\t\t\t\\\narch/arm64/lib/Makefile:4:\t\t clear_page.o csum.o insn.o memchr.o memcpy.o\t\t\\\narch/arm64/lib/Makefile-5-\t\t memset.o memcmp.o strcmp.o strncmp.o strlen.o\t\\\n"
} |
| 29/2 | 2026/08/13 20:51 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21798 output: 211 thoughts: 398 Thoughts: **Analyzing the Arm64 BPF Arena Arguments Implementation** Okay, so I've confirmed that the code is compiled in. Now I need to quickly assess the scope of the modifications to ensure a thorough understanding of the changes. I've gone through each function, checking if it's been modified, and if so, how. It looks like the `bpf_arch_text_copy`, `clear_garbage`, `save_args`, `prepare_trampoline`, `emit_kfunc_arena_args`, and `emit_arena_arg_conv` functions are either unmodified or only used in the context. However, I did find that the following non-static functions have been altered: - `aarch64_insn_gen_add_sub_extended_reg` - `bpf_jit_supports_arena_args` - `arch_prepare_bpf_trampoline` Based on what I see, this seems like a solid implementation of BPF arena argument support for the arm64 JIT compiler. The core changes are centered around generating new instruction logic, specifically for extended register add/sub instructions. Furthermore, the arm64 BPF JIT has been updated to accommodate arena pointers in both kfunc calls and struct_ops callbacks. These are crucial, functional changes within the kernel's BPF JIT. This implementation adds some new surface area in the core kernel. Therefore, the obvious areas that need fuzzing are: - `aarch64_insn_gen_add_sub_extended_reg` - `bpf_jit_supports_arena_args` - `arch_prepare_bpf_trampoline` The relevant configurations seem to be `BPF_SYSCALL` and `BPF_JIT`. I'm ready to call the results "set-results" now. |
| 30/2 | 2026/08/13 20:51 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"aarch64_insn_gen_add_sub_extended_reg",
"bpf_jit_supports_arena_args",
"arch_prepare_bpf_trampoline"
],
"Reasoning": "The patch implements BPF arena arguments support for the arm64 JIT compiler. It adds new instruction generation logic for extended register add/sub instructions (`aarch64_insn_gen_add_sub_extended_reg`) and modifies the arm64 BPF JIT (`arch_prepare_bpf_trampoline`, `bpf_jit_supports_arena_args`) to handle arena pointers in kfunc calls and struct_ops callbacks. These are functional changes to the core kernel (BPF JIT) that are reachable and should be fuzzed.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"aarch64_insn_gen_add_sub_extended_reg",
"bpf_jit_supports_arena_args",
"arch_prepare_bpf_trampoline"
],
"Reasoning": "The patch implements BPF arena arguments support for the arm64 JIT compiler. It adds new instruction generation logic for extended register add/sub instructions (`aarch64_insn_gen_add_sub_extended_reg`) and modifies the arm64 BPF JIT (`arch_prepare_bpf_trampoline`, `bpf_jit_supports_arena_args`) to handle arena pointers in kfunc calls and struct_ops callbacks. These are functional changes to the core kernel (BPF JIT) that are reachable and should be fuzzed.",
"WorthFuzzing": true
} |
| 31/1 | 2026/08/13 20:51 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 32/2 | 2026/08/13 20:51 | agent | kmsan-evaluator |
0mModel:best-expensive Args: null Results: {
"KMSANReasoning": "The patch extends the arm64 BPF JIT compiler to support BPF arena arguments. It introduces new instruction encoding functions for arm64 (e.g., `aarch64_insn_gen_add_sub_extended_reg`) and modifies the JIT compiler (`arch/arm64/net/bpf_jit_comp.c`) to emit instructions that rebase arena pointers. The changes are strictly related to JIT compilation logic and instruction emission. They do not introduce any new kernel structures copied to user space, nor do they allocate complex data structures that could be left uninitialized. Any bugs in the JIT compiler would likely result in invalid instruction generation, crashes, or out-of-bounds memory accesses in the JITed code, which are adequately covered by KASAN and standard kernel testing. There is no risk of uninitialized memory exposure that would require KMSAN.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: For your convenience, here is the diff of the changes:
commit 9fd38225c23e8a95eaf388f273dc33871b224ebf
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Aug 13 20:50:11 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst
index 10e725cbe64cd..85f73e0bbd0ff 100644
--- a/Documentation/bpf/kfuncs.rst
+++ b/Documentation/bpf/kfuncs.rst
@@ -301,9 +301,9 @@ An example is given below::
}
Calling such a kfunc requires the program to use an arena map and a JIT with
-arena argument support (currently x86-64); verification fails otherwise. The
-program can pass any value without compromising the kernel. A value that does
-not point into the arena is a program bug.
+arena argument support (currently x86-64 and arm64); verification fails
+otherwise. The program can pass any value without compromising the kernel. A
+value that does not point into the arena is a program bug.
The suffixes have the same meaning on the arguments of struct_ops stub
functions, with the conversion running in the opposite direction. The
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index cc0702fa64a79..1ce75a4426387 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -205,6 +205,18 @@ enum aarch64_insn_adsb_type {
AARCH64_INSN_ADSB_SUB_SETFLAGS
};
+/* option field of add/sub (extended register) */
+enum aarch64_insn_extend_type {
+ AARCH64_INSN_EXTEND_UXTB,
+ AARCH64_INSN_EXTEND_UXTH,
+ AARCH64_INSN_EXTEND_UXTW,
+ AARCH64_INSN_EXTEND_UXTX,
+ AARCH64_INSN_EXTEND_SXTB,
+ AARCH64_INSN_EXTEND_SXTH,
+ AARCH64_INSN_EXTEND_SXTW,
+ AARCH64_INSN_EXTEND_SXTX,
+};
+
enum aarch64_insn_movewide_type {
AARCH64_INSN_MOVEWIDE_ZERO,
AARCH64_INSN_MOVEWIDE_KEEP,
@@ -378,6 +390,10 @@ __AARCH64_INSN_FUNCS(add, 0x7F200000, 0x0B000000)
__AARCH64_INSN_FUNCS(adds, 0x7F200000, 0x2B000000)
__AARCH64_INSN_FUNCS(sub, 0x7F200000, 0x4B000000)
__AARCH64_INSN_FUNCS(subs, 0x7F200000, 0x6B000000)
+__AARCH64_INSN_FUNCS(add_ext, 0x7FE00000, 0x0B200000)
+__AARCH64_INSN_FUNCS(adds_ext, 0x7FE00000, 0x2B200000)
+__AARCH64_INSN_FUNCS(sub_ext, 0x7FE00000, 0x4B200000)
+__AARCH64_INSN_FUNCS(subs_ext, 0x7FE00000, 0x6B200000)
__AARCH64_INSN_FUNCS(madd, 0x7FE08000, 0x1B000000)
__AARCH64_INSN_FUNCS(msub, 0x7FE08000, 0x1B008000)
__AARCH64_INSN_FUNCS(udiv, 0x7FE0FC00, 0x1AC00800)
@@ -637,6 +653,13 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,
int shift,
enum aarch64_insn_variant variant,
enum aarch64_insn_adsb_type type);
+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,
+ enum aarch64_insn_register src,
+ enum aarch64_insn_register reg,
+ enum aarch64_insn_extend_type extend,
+ int shift,
+ enum aarch64_insn_variant variant,
+ enum aarch64_insn_adsb_type type);
u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,
enum aarch64_insn_register src,
enum aarch64_insn_variant variant,
diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c
index 37ce75f7f1f08..e70ac02385153 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -986,6 +986,66 @@ u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,
return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn, shift);
}
+/*
+ * Unlike the shifted-register form, register 31 is not XZR everywhere here:
+ * it encodes SP for @src, and for @dst too unless @type sets the flags. Only
+ * @reg keeps the XZR meaning.
+ */
+u32 aarch64_insn_gen_add_sub_extended_reg(enum aarch64_insn_register dst,
+ enum aarch64_insn_register src,
+ enum aarch64_insn_register reg,
+ enum aarch64_insn_extend_type extend,
+ int shift,
+ enum aarch64_insn_variant variant,
+ enum aarch64_insn_adsb_type type)
+{
+ u32 insn;
+
+ switch (type) {
+ case AARCH64_INSN_ADSB_ADD:
+ insn = aarch64_insn_get_add_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_SUB:
+ insn = aarch64_insn_get_sub_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_ADD_SETFLAGS:
+ insn = aarch64_insn_get_adds_ext_value();
+ break;
+ case AARCH64_INSN_ADSB_SUB_SETFLAGS:
+ insn = aarch64_insn_get_subs_ext_value();
+ break;
+ default:
+ pr_err("%s: unknown add/sub encoding %d\n", __func__, type);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ switch (variant) {
+ case AARCH64_INSN_VARIANT_32BIT:
+ break;
+ case AARCH64_INSN_VARIANT_64BIT:
+ insn |= AARCH64_INSN_SF_BIT;
+ break;
+ default:
+ pr_err("%s: unknown variant encoding %d\n", __func__, variant);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ if (shift < 0 || shift > 4) {
+ pr_err("%s: invalid shift encoding %d\n", __func__, shift);
+ return AARCH64_BREAK_FAULT;
+ }
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RD, insn, dst);
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RN, insn, src);
+
+ insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RM, insn, reg);
+
+ /* option in bits [15:13] and imm3 in [12:10] together fill IMM_6 */
+ return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn,
+ (extend << 3) | shift);
+}
+
u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,
enum aarch64_insn_register src,
enum aarch64_insn_variant variant,
diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h
index d13de4222cfb7..b2fe6e6dcf447 100644
--- a/arch/arm64/net/bpf_jit.h
+++ b/arch/arm64/net/bpf_jit.h
@@ -243,6 +243,17 @@
/* Rn - Rm; set condition flags */
#define A64_CMP(sf, Rn, Rm) A64_SUBS(sf, A64_ZR, Rn, Rm)
+/* Add/subtract (extended register) */
+#define A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, type) \
+ aarch64_insn_gen_add_sub_extended_reg(Rd, Rn, Rm, \
+ AARCH64_INSN_EXTEND_##ext, shift, A64_VARIANT(sf), \
+ AARCH64_INSN_ADSB_##type)
+/* Rd = Rn + (EXT(Rm) << shift) */
+#define A64_ADD_EXT(sf, Rd, Rn, Rm, ext, shift) \
+ A64_ADDSUB_EREG(sf, Rd, Rn, Rm, ext, shift, ADD)
+/* Rd = Rn + (u32)Rm */
+#define A64_ADD_UXTW(Rd, Rn, Rm) A64_ADD_EXT(1, Rd, Rn, Rm, UXTW, 0)
+
/* Data-processing (1 source) */
#define A64_DATA1(sf, Rd, Rn, type) aarch64_insn_gen_data1(Rd, Rn, \
A64_VARIANT(sf), AARCH64_INSN_DATA1_##type)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 74b4083791da3..c18e005a41dbe 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1256,6 +1256,43 @@ static void emit_stack_arg_store_imm(s32 imm, s16 bpf_off, const u8 tmp, struct
}
}
+/*
+ * Rebase the __arena args of a kfunc call to arena kernel addresses,
+ * xN = kern_vm_start + (u32)xN, with the arena base register holding
+ * kern_vm_start. A nullable arg preserves NULL by skipping the add, tested
+ * on the truncated value as arena NULL is offset 0.
+ */
+static int emit_kfunc_arena_args(struct jit_ctx *ctx, const struct bpf_insn *insn)
+{
+ const u8 arena_vm_base = bpf2a64[ARENA_VM_START];
+ const struct btf_func_model *fm;
+ int i;
+
+ fm = bpf_jit_find_kfunc_model(ctx->prog, insn);
+ if (!fm)
+ return -EINVAL;
+
+ for (i = 0; i < min_t(int, fm->nr_args, MAX_BPF_FUNC_REG_ARGS); i++) {
+ const u8 reg = bpf2a64[BPF_REG_1 + i];
+ u8 flags = fm->arg_flags[i];
+
+ if (!(flags & BTF_FMODEL_ARENA_ARG))
+ continue;
+ if (WARN_ON_ONCE(!ctx->arena_vm_start))
+ return -EINVAL;
+
+ if (flags & BTF_FMODEL_NULLABLE_ARG) {
+ /* 32-bit mov clears the upper 32 bits */
+ emit(A64_MOV(0, reg, reg), ctx);
+ /* skip the add so that NULL stays NULL */
+ emit(A64_CBZ(0, reg, 2), ctx);
+ }
+ emit(A64_ADD_UXTW(reg, arena_vm_base, reg), ctx);
+ }
+
+ return 0;
+}
+
/* JITs an eBPF instruction.
* Returns:
* 0 - successfully JITed an 8-byte eBPF instruction.
@@ -1678,6 +1715,11 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
&func_addr, &func_addr_fixed);
if (ret < 0)
return ret;
+ if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) {
+ ret = emit_kfunc_arena_args(ctx, insn);
+ if (ret < 0)
+ return ret;
+ }
emit_call(func_addr, ctx);
/*
* Call to arch_bpf_timed_may_goto() is emitted by the
@@ -2351,6 +2393,11 @@ bool bpf_jit_supports_stack_args(void)
return true;
}
+bool bpf_jit_supports_arena_args(void)
+{
+ return true;
+}
+
void *bpf_arch_text_copy(void *dst, void *src, size_t len)
{
if (!aarch64_insn_copy(dst, src, len))
@@ -2524,34 +2571,76 @@ static void clear_garbage(struct jit_ctx *ctx, int reg, int effective_bytes)
}
}
+/*
+ * Convert an arena kernel address into the arena pointer form on its way into
+ * the BPF ctx, dst = (u32)(src - kern_vm_start), with @base_lo holding the low
+ * 32 bits of kern_vm_start. A nullable arg preserves NULL, tested on the full
+ * 64-bit kernel pointer. The 32-bit subtraction both truncates and clears the
+ * upper half, so the stored value satisfies the JIT invariant for arena
+ * pointer registers.
+ */
+static void emit_arena_arg_conv(struct jit_ctx *ctx, u8 dst, u8 src, bool nullable, u8 base_lo)
+{
+ if (nullable) {
+ if (dst != src)
+ emit(A64_MOV(1, dst, src), ctx);
+ /* skip the subtraction so that NULL stays NULL */
+ emit(A64_CBZ(1, dst, 2), ctx);
+ src = dst;
+ }
+ emit(A64_SUB(0, dst, src, base_lo), ctx);
+}
+
static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,
- const struct btf_func_model *m,
- const struct arg_aux *a,
- bool for_call_origin)
+ const struct btf_func_model *m, const struct arg_aux *a,
+ bool for_call_origin, bool is_struct_ops, u64 arena_base)
{
- int i;
- int reg;
- int doff;
- int soff;
- int slots;
u8 tmp = bpf2a64[TMP_REG_1];
+ u8 base_lo = bpf2a64[TMP_REG_2];
+ int i, reg, doff, soff, slots;
+
+ /* only the low 32 bits of the base take part in the subtraction */
+ if (arena_base)
+ emit_a64_mov_i(0, base_lo, (s32)(u32)arena_base, ctx);
/* store arguments to the stack for the bpf program, or restore
* arguments from stack for the original function
*/
- for (reg = 0; reg < a->regs_for_args; reg++) {
- emit(for_call_origin ?
- A64_LDR64I(reg, A64_SP, bargs_off) :
- A64_STR64I(reg, A64_SP, bargs_off),
- ctx);
- bargs_off += 8;
+ for (i = 0, reg = 0; i < a->args_in_regs; i++) {
+ bool arena_arg = arena_base && (m->arg_flags[i] & BTF_FMODEL_ARENA_ARG);
+ bool nullable = m->arg_flags[i] & BTF_FMODEL_NULLABLE_ARG;
+
+ slots = (m->arg_size[i] + 7) / 8;
+ while (slots-- > 0) {
+ if (for_call_origin) {
+ emit(A64_LDR64I(reg, A64_SP, bargs_off), ctx);
+ } else if (arena_arg) {
+ emit_arena_arg_conv(ctx, tmp, reg, nullable, base_lo);
+ emit(A64_STR64I(tmp, A64_SP, bargs_off), ctx);
+ } else {
+ emit(A64_STR64I(reg, A64_SP, bargs_off), ctx);
+ }
+ reg++;
+ bargs_off += 8;
+ }
}
- soff = 32; /* on stack arguments start from FP + 32 */
+ /*
+ * On-stack arguments start above the frame(s) pushed by the trampoline
+ * prologue. Entered through the fentry call from a traced function, the
+ * prologue saves both the parent (FP/x9) and the traced function
+ * (FP/LR) frames, so the arguments start at FP + 32. A struct_ops
+ * callback is called indirectly and only the FP/LR frame is saved, so
+ * they start at FP + 16.
+ */
+ soff = is_struct_ops ? 16 : 32;
doff = (for_call_origin ? oargs_off : bargs_off);
/* save on stack arguments */
for (i = a->args_in_regs; i < m->nr_args; i++) {
+ bool arena_arg = arena_base && (m->arg_flags[i] & BTF_FMODEL_ARENA_ARG);
+ bool nullable = m->arg_flags[i] & BTF_FMODEL_NULLABLE_ARG;
+
slots = (m->arg_size[i] + 7) / 8;
/* verifier ensures arg_size <= 16, so slots equals 1 or 2 */
while (slots-- > 0) {
@@ -2561,6 +2650,15 @@ static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,
*/
if (slots == 0 && !for_call_origin)
clear_garbage(ctx, tmp, m->arg_size[i] % 8);
+ /*
+ * No guard on for_call_origin here: only the indirect
+ * trampoline is given a base, and it never calls the
+ * original function, so arguments are never converted
+ * on their way back out to it. See the WARN_ON_ONCE()
+ * in prepare_trampoline().
+ */
+ if (arena_arg)
+ emit_arena_arg_conv(ctx, tmp, tmp, nullable, base_lo);
emit(A64_STR64I(tmp, A64_SP, doff), ctx);
soff += 8;
doff += 8;
@@ -2620,8 +2718,21 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
bool is_struct_ops = is_struct_ops_tramp(fentry);
int cookie_off, cookie_cnt, cookie_bargs_off;
int fsession_cnt = bpf_fsession_cnt(tnodes);
+ u64 arena_base;
u64 func_meta;
+ /*
+ * F_INDIRECT is only compatible with F_RET_FENTRY_RET, it is explicitly
+ * incompatible with F_CALL_ORIG | F_SKIP_FRAME | F_IP_ARG because
+ * @func_addr. Arena conversion relies on this: bpf_tramp_arena_base()
+ * only returns a base for the indirect trampoline, which therefore
+ * never calls the original function with converted arguments.
+ */
+ WARN_ON_ONCE((flags & BPF_TRAMP_F_INDIRECT) &&
+ (flags & ~(BPF_TRAMP_F_INDIRECT | BPF_TRAMP_F_RET_FENTRY_RET)));
+
+ arena_base = bpf_tramp_arena_base(m, tnodes, flags);
+
/* trampoline stack layout:
* [ parent ip ]
* [ FP ]
@@ -2737,7 +2848,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
store_func_meta(ctx, func_meta, func_meta_off);
/* save args for bpf */
- save_args(ctx, bargs_off, oargs_off, m, a, false);
+ save_args(ctx, bargs_off, oargs_off, m, a, false, is_struct_ops, arena_base);
/* save callee saved registers */
emit(A64_STR64I(A64_R(19), A64_SP, regs_off), ctx);
@@ -2785,8 +2896,8 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
}
if (flags & BPF_TRAMP_F_CALL_ORIG) {
- /* save args for original func */
- save_args(ctx, bargs_off, oargs_off, m, a, true);
+ /* the original func takes kernel addresses, never converted ones */
+ save_args(ctx, bargs_off, oargs_off, m, a, true, is_struct_ops, 0);
/* call original func */
emit(A64_LDR64I(A64_R(10), A64_SP, retaddr_off), ctx);
emit(A64_ADR(A64_LR, AARCH64_INSN_SIZE * 2), ctx);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
index 940ec2cda0d52..7f9f54ba3fbe5 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
@@ -6,7 +6,7 @@
#include "struct_ops_arena_attach.skel.h"
#include "struct_ops_arena_fail.skel.h"
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
/*
* Attach callbacks with __arena and __arena__nullable arguments and drive
* them through the bpf_testmod_ops3_call_test_arena*() kfuncs.
@@ -111,11 +111,11 @@ static void arena_arg_attach(void)
void serial_test_struct_ops_arena(void)
{
/*
- * Arena struct_ops arguments need JIT support, currently x86-64 only.
- * Elsewhere verification fails with "JIT does not support arena
- * arguments", so the programs cannot even load.
+ * Arena struct_ops arguments need JIT support, currently x86-64 and
+ * arm64 only. Elsewhere verification fails with "JIT does not support
+ * arena arguments", so the programs cannot even load.
*/
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
if (test__start_subtest("arena_arg"))
arena_arg();
if (test__start_subtest("arena_arg_fail"))
diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c
index cdcea889da586..bf0d304e0e59c 100644
--- a/tools/testing/selftests/bpf/progs/arena_kfunc.c
+++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c
@@ -27,6 +27,7 @@ volatile u64 stash;
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_forms(void *ctx)
{
@@ -70,6 +71,7 @@ int arena_arg_forms(void *ctx)
*/
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_rebase(void *ctx)
{
@@ -111,6 +113,7 @@ int arena_arg_rebase(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_args5(void *ctx)
{
@@ -142,6 +145,7 @@ int arena_args5(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_mixed(void *ctx)
{
@@ -169,6 +173,7 @@ int arena_arg_mixed(void *ctx)
/* kernel-side faults on unpopulated pages recover via the scratch page */
SEC("syscall")
__arch_x86_64
+__arch_arm64
__success __retval(0)
int arena_arg_unpopulated(void *ctx)
{
@@ -189,6 +194,7 @@ int arena_arg_unpopulated(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("arena pointer requires a program with an associated arena")
int arena_arg_no_arena(void *ctx)
{
@@ -198,6 +204,7 @@ int arena_arg_no_arena(void *ctx)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("is not a pointer to arena or scalar")
int arena_arg_bad_reg(void *ctx)
{
@@ -213,6 +220,7 @@ int arena_arg_bad_reg(void *ctx)
defined(__BPF_FEATURE_STACK_ARGUMENT)
SEC("syscall")
__arch_x86_64
+__arch_arm64
__failure __msg("arena pointer cannot be a stack argument")
int arena_arg_stack(void *ctx)
{
@@ -223,6 +231,7 @@ int arena_arg_stack(void *ctx)
#else
SEC("syscall")
__arch_x86_64
+__arch_arm64
__description("arena_arg_stack: not supported, dummy test")
__success
int arena_arg_stack(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
index c9b9186626162..b5a01cbc33a73 100644
--- a/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
+++ b/tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
@@ -32,6 +32,10 @@ __jited(" movl %edi, %edi")
__jited(" addq %r12, %rdi")
__jited("...")
__jited(" callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" add x0, x28, w0, uxtw")
+__jited(" {{(bl|mov) .*}}")
__success
int arena_arg_jit_rebase(void *ctx)
{
@@ -48,6 +52,12 @@ __jited(" testl %edi, %edi")
__jited(" je L0")
__jited(" addq %r12, %rdi")
__jited("L0: callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" mov w0, w0")
+__jited(" cbz w0, L0")
+__jited(" add x0, x28, w0, uxtw")
+__jited("L0: {{.*}}")
__success
int arena_arg_jit_nullable(void *ctx)
{
@@ -72,6 +82,16 @@ __jited(" testl %r8d, %r8d")
__jited(" je L0")
__jited(" addq %r12, %r8")
__jited("L0: callq {{.*}}")
+__arch_arm64
+__jited("...")
+__jited(" add x0, x28, w0, uxtw")
+__jited(" add x1, x28, w1, uxtw")
+__jited(" add x2, x28, w2, uxtw")
+__jited(" add x3, x28, w3, uxtw")
+__jited(" mov w4, w4")
+__jited(" cbz w4, L0")
+__jited(" add x4, x28, w4, uxtw")
+__jited("L0: {{.*}}")
__success
int arena_arg_jit_args5(void *ctx)
{
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena.c b/tools/testing/selftests/bpf/progs/struct_ops_arena.c
index ba04c73d8d967..8aa8639df91f0 100644
--- a/tools/testing/selftests/bpf/progs/struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/progs/struct_ops_arena.c
@@ -59,11 +59,28 @@ int test_arena_stack_cb(unsigned long long *ctx)
return 0;
}
+SEC("struct_ops/test_arena_multislot")
+int test_arena_multislot_cb(unsigned long long *ctx)
+{
+ u64 __arena *ptr = (u64 __arena *)ctx[2];
+
+ arena_touch++;
+ /*
+ * The 16-byte struct occupies ctx[0] and ctx[1], so @ptr is argument
+ * one but slot two. Getting that wrong hands the callback a scalar.
+ */
+ if (ctx[0] != 11 || ctx[1] != 22)
+ return 0xbad;
+ *ptr += 1;
+ return 0;
+}
+
SEC(".struct_ops.link")
struct bpf_testmod_ops3 testmod_arena = {
.test_arena = (void *)test_arena_cb,
.test_arena_nullable = (void *)test_arena_nullable_cb,
.test_arena_stack = (void *)test_arena_stack_cb,
+ .test_arena_multislot = (void *)test_arena_multislot_cb,
};
SEC("syscall")
@@ -109,6 +126,13 @@ int trigger(void *ctx)
if (*val != 44)
return 9;
+ /* a multi-slot arg precedes the arena pointer here */
+ ret = bpf_testmod_ops3_call_test_arena_multislot((u64 *)val);
+ if (ret)
+ return 10;
+ if (*val != 45)
+ return 11;
+
bpf_arena_free_pages(&arena, (void __arena *)val, 1);
#endif
return 0;
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index a6133f7521f34..9366a3c578f13 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -402,12 +402,19 @@ static int bpf_testmod_ops3__test_arena_stack(u64 a, u64 b, u64 c, u64 d,
return 0;
}
+static int bpf_testmod_ops3__test_arena_multislot(struct bpf_testmod_arena_pair p,
+ u64 *ptr__arena)
+{
+ return 0;
+}
+
static struct bpf_testmod_ops3 __bpf_testmod_ops3 = {
.test_1 = bpf_testmod_test_3,
.test_2 = bpf_testmod_test_4,
.test_arena = bpf_testmod_ops3__test_arena,
.test_arena_nullable = bpf_testmod_ops3__test_arena_nullable,
.test_arena_stack = bpf_testmod_ops3__test_arena_stack,
+ .test_arena_multislot = bpf_testmod_ops3__test_arena_multislot,
};
static void bpf_testmod_test_struct_ops3(void)
@@ -441,6 +448,13 @@ __bpf_kfunc int bpf_testmod_ops3_call_test_arena_stack(u64 *ptr__arena)
return st_ops3->test_arena_stack(1, 2, 3, 4, 5, 6, 7, 8, ptr__arena);
}
+__bpf_kfunc int bpf_testmod_ops3_call_test_arena_multislot(u64 *ptr__arena)
+{
+ struct bpf_testmod_arena_pair p = { .a = 11, .b = 22 };
+
+ return st_ops3->test_arena_multislot(p, ptr__arena);
+}
+
struct bpf_testmod_btf_type_tag_1 {
int a;
};
@@ -852,6 +866,7 @@ BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_2)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_nullable)
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_stack)
+BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_arena_multislot)
BTF_ID_FLAGS(func, bpf_kfunc_get_default_trusted_ptr_test);
BTF_ID_FLAGS(func, bpf_kfunc_put_default_trusted_ptr_test);
BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
index 33f2af5b70857..210b919290cc2 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
@@ -103,6 +103,12 @@ struct bpf_testmod_ops2 {
int (*test_1)(void);
};
+/* 16 bytes, so it takes two argument slots when passed by value */
+struct bpf_testmod_arena_pair {
+ u64 a;
+ u64 b;
+};
+
struct bpf_testmod_ops3 {
int (*test_1)(void);
int (*test_2)(void);
@@ -112,6 +118,8 @@ struct bpf_testmod_ops3 {
/* enough leading args to force @ptr onto the stack on x86 and arm64 */
int (*test_arena_stack)(u64 a, u64 b, u64 c, u64 d, u64 e, u64 f,
u64 g, u64 h, u64 *ptr);
+ /* a multi-slot leading arg, so @ptr is not at the slot its arg index suggests */
+ int (*test_arena_multislot)(struct bpf_testmod_arena_pair p, u64 *ptr);
};
struct st_ops_args {
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
index c4383acb53c11..7d81070eefe7f 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
@@ -123,6 +123,7 @@ void bpf_testmod_test_mod_kfunc(int i) __ksym;
int bpf_testmod_ops3_call_test_arena(__u64 *ptr__arena) __ksym;
int bpf_testmod_ops3_call_test_arena_nullable(__u64 *ptr__arena__nullable) __ksym;
int bpf_testmod_ops3_call_test_arena_stack(__u64 *ptr__arena) __ksym;
+int bpf_testmod_ops3_call_test_arena_multislot(__u64 *ptr__arena) __ksym;
__u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
__u32 c, __u64 d) __ksym;
|
| 33/3 | 2026/08/13 20:51 | llm | kmsan-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 12404 output: 213 thoughts: 844 Thoughts: **KMSAN Assessment: Arm64 BPF JIT Arena Argument Support**
Okay, let's break this down. This patch is adding BPF arena argument support to the arm64 JIT compiler. My initial thought is, "Okay, that's instruction emission, not data structures, so KMSAN is probably not relevant, but let's be sure."
The patch modifies several files, mostly focusing on instruction encoding and the JIT compiler itself. It looks like the core work is in emitting the correct arm64 instructions to handle BPF arena pointers – adding or subtracting the arena base address during JIT compilation. It's essentially about generating the *right* machine code, rather than handling raw data directly.
My concern is always around uninitialized memory, but I'm not seeing any red flags. The changes are isolated within the BPF JIT compiler and the selftests. No new kernel structures are being passed to user space. There aren't any complex allocations with uninitialized fields. There's nothing new being directly exposed to userspace that screams "uninitialized memory vulnerability."
Now, the JIT compiler generates instructions, so there is the potential for logic errors in the instruction generation. If there's a bug, it could lead to memory corruption or out-of-bounds access *within* the JITed BPF code. However, KASAN should catch that. This isn't KMSAN's domain. In fact, KMSAN doesn't even instrument JIT'd code.
Let me double-check `arch/arm64/net/bpf_jit_comp.c`. Specifically, functions like `emit_kfunc_arena_args`, `emit_arena_arg_conv`, `save_args`, and `prepare_trampoline` – these are where the machine code is being generated. If a bug were to exist here, would it lead to reading uninitialized memory? No. KMSAN isn't the solution. The JIT compiler is just generating the machine code. If the code is buggy, it is KASAN that can detect it, not KMSAN.
Let me look closely at `save_args`... specifically the snippet below:
```c
static void save_args(struct jit_ctx *ctx, int bargs_off, int oargs_off,
const struct btf_func_model *m, const struct arg_aux *a,
bool for_call_origin, bool is_struct_ops, u64 arena_base)
{
u8 tmp = bpf2a64[TMP_REG_1];
u8 base_lo = bpf2a64[TMP_REG_2];
int i, reg, doff, soff, slots;
/* only the low 32 bits of the base take part in the subtraction */
if (arena_base)
emit_a64_mov_i(0, base_lo, (s32)(u32)arena_base, ctx);
...
```
Ah, everything here *seems* properly initialized. The `arena_base` variable is being assigned, and the generated machine code (and registers) seem to be correctly managed.
Given all of this, I'm confident that KMSAN isn't needed here. The risk is limited to JIT compilation logic errors, which KASAN and standard testing should effectively address.
**Therefore, NeedsKMSAN = false.**
|
| 34/3 | 2026/08/13 20:51 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch extends the arm64 BPF JIT compiler to support BPF arena arguments. It introduces new instruction encoding functions for arm64 (e.g., `aarch64_insn_gen_add_sub_extended_reg`) and modifies the JIT compiler (`arch/arm64/net/bpf_jit_comp.c`) to emit instructions that rebase arena pointers. The changes are strictly related to JIT compilation logic and instruction emission. They do not introduce any new kernel structures copied to user space, nor do they allocate complex data structures that could be left uninitialized. Any bugs in the JIT compiler would likely result in invalid instruction generation, crashes, or out-of-bounds memory accesses in the JITed code, which are adequately covered by KASAN and standard kernel testing. There is no risk of uninitialized memory exposure that would require KMSAN.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch extends the arm64 BPF JIT compiler to support BPF arena arguments. It introduces new instruction encoding functions for arm64 (e.g., `aarch64_insn_gen_add_sub_extended_reg`) and modifies the JIT compiler (`arch/arm64/net/bpf_jit_comp.c`) to emit instructions that rebase arena pointers. The changes are strictly related to JIT compilation logic and instruction emission. They do not introduce any new kernel structures copied to user space, nor do they allocate complex data structures that could be left uninitialized. Any bugs in the JIT compiler would likely result in invalid instruction generation, crashes, or out-of-bounds memory accesses in the JITed code, which are adequately covered by KASAN and standard kernel testing. There is no risk of uninitialized memory exposure that would require KMSAN.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|