| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/27 11:06 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_atomic_fetch_rmw",
"emit_arena_exentry",
"do_jit",
"bpf_int_jit_compile",
"bpf_jit_supports_insn",
"ex_handler_bpf"
],
"KMSANReasoning": "The patch adds x86 BPF JIT support for atomic fetch operations (BPF_AND | BPF_FETCH, BPF_OR | BPF_FETCH, BPF_XOR | BPF_FETCH) on arena memory by emitting a CMPXCHG loop and configuring exception table entries for arena fault recovery, along with updating BPF selftests and tools.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. The changes here involve BPF JIT machine code emission and exception table entry generation in arch/x86/net/bpf_jit_comp.c. All fields of the exception table entries (`ex-\u003einsn`, `ex-\u003edata`, `ex-\u003efixup`) are fully initialized. No kernel structures with uninitialized padding or uninitialized memory are copied to userspace, nor does any C branching depend on uninitialized variables.\n- Potential risks associated with JIT code generation (such as incorrect instruction offsets, displacement calculation in JNE jumps, or incorrect pt_regs offset mapping) would manifest as bad instruction execution, invalid memory access, or control-flow faults, which are covered by functional testing and standard KASAN/sanitizer builds.\n\nBecause there is no risk of uninitialized memory access or info-leaks, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies the x86 BPF JIT compiler (arch/x86/net/bpf_jit_comp.c) to support atomic fetch operations (BPF_AND, BPF_OR, BPF_XOR with BPF_FETCH) on BPF arena memory via a cmpxchg loop and sets up arena exception table entries to handle potential faults. This modifies core BPF JIT compilation and exception handling logic reachable through the bpf() system call.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/27 11:06 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit d9fe1ca121010baba460954ce089855d38cef398\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Sep 27 11:06:33 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex 6c7a0578760e7..570ee93a969a9 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -236,8 +236,17 @@ static const int reg2pt_regs[] = {\n \t[BPF_REG_7] = offsetof(struct pt_regs, r13),\n \t[BPF_REG_8] = offsetof(struct pt_regs, r14),\n \t[BPF_REG_9] = offsetof(struct pt_regs, r15),\n+\t/* Substituted for R0 by the CMPXCHG loop lowering below. */\n+\t[BPF_REG_AX] = offsetof(struct pt_regs, r10),\n };\n \n+static bool is_atomic_fetch_op(const struct bpf_insn *insn)\n+{\n+\treturn insn-\u003eimm == (BPF_AND | BPF_FETCH) ||\n+\t insn-\u003eimm == (BPF_OR | BPF_FETCH) ||\n+\t insn-\u003eimm == (BPF_XOR | BPF_FETCH);\n+}\n+\n /*\n * is_ereg() == true if BPF register 'reg' maps to x86-64 r8..r15\n * which need extra byte of encoding.\n@@ -1679,6 +1688,74 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,\n \treturn 0;\n }\n \n+/*\n+ * A fetching AND/OR/XOR can't be implemented with a single x86 insn, so do a\n+ * CMPXCHG loop. @index_reg is X86_REG_R12 for an arena access or -1 otherwise,\n+ * and @dst_reg/@src_reg are already substituted for R0 by the caller.\n+ *\n+ * For an arena access the CMPXCHG is the only insn that can fault; its address\n+ * is handed back in @fault. A fault has to resume at @resume, which is past the\n+ * loop and past the move that delivers the old value, but before the R0\n+ * restore. Both are NULL for the non-arena case, which needs no fixup.\n+ */\n+static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,\n+\t\t\t\t u32 src_reg, int index_reg, u8 **fault,\n+\t\t\t\t u8 **resume)\n+{\n+\tbool is64 = BPF_SIZE(insn-\u003ecode) == BPF_DW;\n+\tu8 *branch_target, *prog = *pprog;\n+\tint err;\n+\n+\tbranch_target = prog;\n+\n+\t/*\n+\t * Load old value. The arena case skips it and lets the loop start from\n+\t * whatever R0 happens to hold: a CMPXCHG that loses the comparison\n+\t * loads the current contents into RAX, so the loop converges, and the\n+\t * value it stores is computed from RAX, which by definition equalled\n+\t * memory whenever the store happened. That leaves the CMPXCHG as the\n+\t * only insn that can fault, which is worth an extra iteration here to\n+\t * keep this to a single exception table entry.\n+\t */\n+\tif (index_reg \u003c 0)\n+\t\temit_ldx(\u0026prog, BPF_SIZE(insn-\u003ecode), BPF_REG_0, dst_reg, insn-\u003eoff);\n+\n+\t/*\n+\t * Perform the (commutative) operation locally, put the result in\n+\t * the AUX_REG.\n+\t */\n+\temit_mov_reg(\u0026prog, is64, AUX_REG, BPF_REG_0);\n+\tmaybe_emit_mod(\u0026prog, AUX_REG, src_reg, is64);\n+\tEMIT2(simple_alu_opcodes[BPF_OP(insn-\u003eimm)],\n+\t add_2reg(0xC0, AUX_REG, src_reg));\n+\n+\t/* Attempt to swap in new value */\n+\tif (fault)\n+\t\t*fault = prog;\n+\tif (index_reg \u003c 0)\n+\t\terr = emit_atomic_rmw(\u0026prog, BPF_CMPXCHG, dst_reg, AUX_REG,\n+\t\t\t\t insn-\u003eoff, BPF_SIZE(insn-\u003ecode));\n+\telse\n+\t\terr = emit_atomic_rmw_index(\u0026prog, BPF_CMPXCHG, BPF_SIZE(insn-\u003ecode),\n+\t\t\t\t\t dst_reg, AUX_REG, index_reg, insn-\u003eoff);\n+\tif (WARN_ON(err))\n+\t\treturn err;\n+\n+\t/* ZF tells us whether we won the race. If it's cleared we need to try again. */\n+\tEMIT2(X86_JNE, -(prog - branch_target) - 2);\n+\t/* Return the pre-modification value */\n+\temit_mov_reg(\u0026prog, is64, src_reg, BPF_REG_0);\n+\n+\tif (resume)\n+\t\t*resume = prog;\n+\n+\t/* Restore R0 after clobbering RAX */\n+\temit_mov_reg(\u0026prog, true, BPF_REG_0, BPF_REG_AX);\n+\n+\t*pprog = prog;\n+\treturn 0;\n+}\n+\n /*\n * Metadata encoding for exception handling in JITed code.\n *\n@@ -1692,7 +1769,12 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,\n * | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |\n * +-----------+-------------+--------+-----------+---------+----------+\n *\n- * - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).\n+ * - INSN_LEN (8 bits): How far past the faulting insn to resume. That is its own length\n+ * for a single-insn access, but the distance to the end of the whole\n+ * sequence where one BPF insn became several, as for the CMPXCHG loop\n+ * of a fetching AND/OR/XOR. A sequence long enough to overflow this\n+ * field would first have to exceed BPF_MAX_INSN_SIZE, which do_jit()\n+ * rejects with -EFAULT before the image is used.\n * - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).\n * This is set to DONT_CLEAR if the insn does not read into a register.\n * - ARENA_REG (8 bits): Offset of the register that is used to calculate the\n@@ -1747,6 +1829,44 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\n \treturn true;\n }\n \n+/*\n+ * Record an arena access that may fault. @fault_ip is the address of the\n+ * faulting insn in the RO image, @resume_off how far past it execution has to\n+ * resume: for a multi-insn lowering that is the end of the whole sequence, not\n+ * the end of the one insn.\n+ */\n+static int emit_arena_exentry(struct bpf_prog *bpf_prog, u8 *image, u8 *rw_image,\n+\t\t\t int *excnt, u8 *fault_ip, u32 resume_off,\n+\t\t\t u32 fixup_reg, u32 arena_reg, bool is_write, s16 off)\n+{\n+\tstruct exception_table_entry *ex;\n+\ts64 delta;\n+\n+\tif (!bpf_prog-\u003eaux-\u003eextable)\n+\t\treturn 0;\n+\n+\tif (*excnt \u003e= bpf_prog-\u003eaux-\u003enum_exentries) {\n+\t\tpr_err(\"arena extable bug\\n\");\n+\t\treturn -EFAULT;\n+\t}\n+\tex = \u0026bpf_prog-\u003eaux-\u003eextable[(*excnt)++];\n+\n+\tdelta = fault_ip - (u8 *)\u0026ex-\u003einsn;\n+\t/* switch ex to rw buffer for writes */\n+\tex = (void *)rw_image + ((void *)ex - (void *)image);\n+\n+\tex-\u003einsn = delta;\n+\tex-\u003edata = EX_TYPE_BPF | FIELD_PREP(DATA_ARENA_OFFSET_MASK, off);\n+\tex-\u003efixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, resume_off) |\n+\t\t FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |\n+\t\t FIELD_PREP(FIXUP_REG_MASK, fixup_reg) |\n+\t\t FIXUP_ARENA_ACCESS;\n+\tif (is_write)\n+\t\tex-\u003efixup |= FIXUP_ARENA_WRITE;\n+\n+\treturn 0;\n+}\n+\n static void detect_reg_usage(struct bpf_insn *insn, int insn_cnt,\n \t\t\t bool *regs_used)\n {\n@@ -2624,28 +2744,8 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \t\t\t}\n populate_extable:\n \t\t\t{\n-\t\t\t\tstruct exception_table_entry *ex;\n-\t\t\t\tu8 *_insn = image + proglen + (start_of_ldx - temp);\n \t\t\t\tu32 arena_reg, fixup_reg;\n \t\t\t\tbool is_write;\n-\t\t\t\ts64 delta;\n-\n-\t\t\t\tif (!bpf_prog-\u003eaux-\u003eextable)\n-\t\t\t\t\tbreak;\n-\n-\t\t\t\tif (excnt \u003e= bpf_prog-\u003eaux-\u003enum_exentries) {\n-\t\t\t\t\tpr_err(\"mem32 extable bug\\n\");\n-\t\t\t\t\treturn -EFAULT;\n-\t\t\t\t}\n-\t\t\t\tex = \u0026bpf_prog-\u003eaux-\u003eextable[excnt++];\n-\n-\t\t\t\tdelta = _insn - (u8 *)\u0026ex-\u003einsn;\n-\t\t\t\t/* switch ex to rw buffer for writes */\n-\t\t\t\tex = (void *)rw_image + ((void *)ex - (void *)image);\n-\n-\t\t\t\tex-\u003einsn = delta;\n-\n-\t\t\t\tex-\u003edata = EX_TYPE_BPF;\n \n \t\t\t\t/*\n \t\t\t\t * src_reg/dst_reg holds the address in the arena region with upper\n@@ -2681,14 +2781,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \t\t\t\t\tis_write = true;\n \t\t\t\t}\n \n-\t\t\t\tex-\u003efixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |\n-\t\t\t\t\t FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |\n-\t\t\t\t\t FIELD_PREP(FIXUP_REG_MASK, fixup_reg);\n-\t\t\t\tex-\u003efixup |= FIXUP_ARENA_ACCESS;\n-\t\t\t\tif (is_write)\n-\t\t\t\t\tex-\u003efixup |= FIXUP_ARENA_WRITE;\n-\n-\t\t\t\tex-\u003edata |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn-\u003eoff);\n+\t\t\t\terr = emit_arena_exentry(bpf_prog, image, rw_image, \u0026excnt,\n+\t\t\t\t\t\t\t image + proglen + (start_of_ldx - temp),\n+\t\t\t\t\t\t\t prog - start_of_ldx, fixup_reg,\n+\t\t\t\t\t\t\t arena_reg, is_write, insn-\u003eoff);\n+\t\t\t\tif (err)\n+\t\t\t\t\treturn err;\n \t\t\t}\n \t\t\tbreak;\n \n@@ -2840,20 +2938,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \t\t\tfallthrough;\n \t\tcase BPF_STX | BPF_ATOMIC | BPF_W:\n \t\tcase BPF_STX | BPF_ATOMIC | BPF_DW: {\n-\t\t\tbool is64 = BPF_SIZE(insn-\u003ecode) == BPF_DW;\n \t\t\tu32 real_src_reg = src_reg;\n \t\t\tu32 real_dst_reg = dst_reg;\n+\t\t\tbool is_atomic_fetch = is_atomic_fetch_op(insn);\n \t\t\tu8 *old_prog;\n-\t\t\tbool is_atomic_fetch =\n-\t\t\t\t(insn-\u003eimm == (BPF_AND | BPF_FETCH) ||\n-\t\t\t\t insn-\u003eimm == (BPF_OR | BPF_FETCH) ||\n-\t\t\t\t insn-\u003eimm == (BPF_XOR | BPF_FETCH));\n-\t\t\tif (is_atomic_fetch) {\n-\t\t\t\t/*\n-\t\t\t\t * Can't be implemented with a single x86 insn.\n-\t\t\t\t * Need to do a CMPXCHG loop.\n-\t\t\t\t */\n \n+\t\t\tif (is_atomic_fetch) {\n \t\t\t\t/* Will need RAX as a CMPXCHG operand so save R0 */\n \t\t\t\told_prog = prog;\n \t\t\t\temit_mov_reg(\u0026prog, true, BPF_REG_AX, BPF_REG_0);\n@@ -2874,34 +2964,11 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (is_atomic_fetch) {\n-\t\t\t\tu8 *branch_target = prog;\n-\t\t\t\t/* Load old value */\n-\t\t\t\temit_ldx(\u0026prog, BPF_SIZE(insn-\u003ecode),\n-\t\t\t\t\t BPF_REG_0, real_dst_reg, insn-\u003eoff);\n-\t\t\t\t/*\n-\t\t\t\t * Perform the (commutative) operation locally,\n-\t\t\t\t * put the result in the AUX_REG.\n-\t\t\t\t */\n-\t\t\t\temit_mov_reg(\u0026prog, is64, AUX_REG, BPF_REG_0);\n-\t\t\t\tmaybe_emit_mod(\u0026prog, AUX_REG, real_src_reg, is64);\n-\t\t\t\tEMIT2(simple_alu_opcodes[BPF_OP(insn-\u003eimm)],\n-\t\t\t\t add_2reg(0xC0, AUX_REG, real_src_reg));\n-\t\t\t\t/* Attempt to swap in new value */\n-\t\t\t\terr = emit_atomic_rmw(\u0026prog, BPF_CMPXCHG,\n-\t\t\t\t\t\t real_dst_reg, AUX_REG,\n-\t\t\t\t\t\t insn-\u003eoff,\n-\t\t\t\t\t\t BPF_SIZE(insn-\u003ecode));\n-\t\t\t\tif (WARN_ON(err))\n+\t\t\t\terr = emit_atomic_fetch_rmw(\u0026prog, insn, real_dst_reg,\n+\t\t\t\t\t\t\t real_src_reg, -1, NULL,\n+\t\t\t\t\t\t\t NULL);\n+\t\t\t\tif (err)\n \t\t\t\t\treturn err;\n-\t\t\t\t/*\n-\t\t\t\t * ZF tells us whether we won the race. If it's\n-\t\t\t\t * cleared we need to try again.\n-\t\t\t\t */\n-\t\t\t\tEMIT2(X86_JNE, -(prog - branch_target) - 2);\n-\t\t\t\t/* Return the pre-modification value */\n-\t\t\t\temit_mov_reg(\u0026prog, is64, real_src_reg, BPF_REG_0);\n-\t\t\t\t/* Restore R0 after clobbering RAX */\n-\t\t\t\temit_mov_reg(\u0026prog, true, BPF_REG_0, BPF_REG_AX);\n \t\t\t\tbreak;\n \t\t\t}\n \n@@ -2925,6 +2992,33 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \t\t\tfallthrough;\n \t\tcase BPF_STX | BPF_PROBE_ATOMIC | BPF_W:\n \t\tcase BPF_STX | BPF_PROBE_ATOMIC | BPF_DW:\n+\t\t\tif (is_atomic_fetch_op(insn)) {\n+\t\t\t\tu32 real_src_reg = src_reg, real_dst_reg = dst_reg;\n+\t\t\t\tu8 *fault, *resume;\n+\n+\t\t\t\t/* Will need RAX as a CMPXCHG operand so save R0 */\n+\t\t\t\temit_mov_reg(\u0026prog, true, BPF_REG_AX, BPF_REG_0);\n+\t\t\t\tif (src_reg == BPF_REG_0)\n+\t\t\t\t\treal_src_reg = BPF_REG_AX;\n+\t\t\t\tif (dst_reg == BPF_REG_0)\n+\t\t\t\t\treal_dst_reg = BPF_REG_AX;\n+\n+\t\t\t\terr = emit_atomic_fetch_rmw(\u0026prog, insn, real_dst_reg,\n+\t\t\t\t\t\t\t real_src_reg, X86_REG_R12,\n+\t\t\t\t\t\t\t \u0026fault, \u0026resume);\n+\t\t\t\tif (err)\n+\t\t\t\t\treturn err;\n+\n+\t\t\t\terr = emit_arena_exentry(bpf_prog, image, rw_image, \u0026excnt,\n+\t\t\t\t\t\t\t image + proglen + (fault - temp),\n+\t\t\t\t\t\t\t resume - fault,\n+\t\t\t\t\t\t\t reg2pt_regs[real_src_reg],\n+\t\t\t\t\t\t\t reg2pt_regs[real_dst_reg],\n+\t\t\t\t\t\t\t true, insn-\u003eoff);\n+\t\t\t\tif (err)\n+\t\t\t\t\treturn err;\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t\tstart_of_ldx = prog;\n \n \t\t\tif (bpf_atomic_is_load_store(insn))\n@@ -4669,16 +4763,6 @@ bool bpf_jit_supports_arena(void)\n \n bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\n {\n-\tif (!in_arena)\n-\t\treturn true;\n-\tswitch (insn-\u003ecode) {\n-\tcase BPF_STX | BPF_ATOMIC | BPF_W:\n-\tcase BPF_STX | BPF_ATOMIC | BPF_DW:\n-\t\tif (insn-\u003eimm == (BPF_AND | BPF_FETCH) ||\n-\t\t insn-\u003eimm == (BPF_OR | BPF_FETCH) ||\n-\t\t insn-\u003eimm == (BPF_XOR | BPF_FETCH))\n-\t\t\treturn false;\n-\t}\n \treturn true;\n }\n \ndiff --git a/tools/sched_ext/include/scx/cid.bpf.h b/tools/sched_ext/include/scx/cid.bpf.h\nindex 69fb4e97bc771..d0d4cea19e29f 100644\n--- a/tools/sched_ext/include/scx/cid.bpf.h\n+++ b/tools/sched_ext/include/scx/cid.bpf.h\n@@ -3,8 +3,8 @@\n * BPF-side helpers for cids and cmasks. See kernel/sched/ext/cid.h for the\n * authoritative layout and semantics. The BPF-side helpers use the cmask_*\n * naming (no scx_ prefix); cmask is the SCX bitmap type so the prefix is\n- * redundant in BPF code. Atomics use __sync_val_compare_and_swap and every\n- * helper is inline (no .c counterpart).\n+ * redundant in BPF code. Atomics use the __sync_* builtins and every helper\n+ * is inline (no .c counterpart).\n *\n * Included by scx/common.bpf.h; don't include directly.\n *\n@@ -129,101 +129,38 @@ static __always_inline bool cmask_test(u32 cid, const struct scx_cmask __arena *\n \treturn *__cmask_word(cid, m) \u0026 BIT_U64(cid \u0026 63);\n }\n \n-/*\n- * x86 BPF JIT rejects BPF_OR | BPF_FETCH and BPF_AND | BPF_FETCH on arena\n- * pointers (see bpf_jit_supports_insn() in arch/x86/net/bpf_jit_comp.c). Only\n- * BPF_CMPXCHG / BPF_XCHG / BPF_ADD with FETCH are allowed. Implement\n- * test_and_{set,clear} and the atomic set/clear via a cmpxchg loop.\n- *\n- * CMASK_CAS_TRIES is sized so exhausting it means seconds of real spinning\n- * on one word - past any plausible contention. Abort hard.\n- */\n-#define CMASK_CAS_TRIES\t\t(1U \u003c\u003c 23)\n-\n static __always_inline void cmask_set(u32 cid, struct scx_cmask __arena *m)\n {\n-\tu64 __arena *w;\n-\tu64 bit, old, new;\n-\tu32 i;\n-\n \tif (!__cmask_contains(cid, m))\n \t\treturn;\n-\tw = __cmask_word(cid, m);\n-\tbit = BIT_U64(cid \u0026 63);\n-\tbpf_for(i, 0, CMASK_CAS_TRIES) {\n-\t\told = *w;\n-\t\tif (old \u0026 bit)\n-\t\t\treturn;\n-\t\tnew = old | bit;\n-\t\tif (__sync_val_compare_and_swap(w, old, new) == old)\n-\t\t\treturn;\n-\t}\n-\tscx_bpf_error(\"cmask_set CAS exhausted at cid %u\", cid);\n+\t__sync_fetch_and_or(__cmask_word(cid, m), BIT_U64(cid \u0026 63));\n }\n \n static __always_inline void cmask_clear(u32 cid, struct scx_cmask __arena *m)\n {\n-\tu64 __arena *w;\n-\tu64 bit, old, new;\n-\tu32 i;\n-\n \tif (!__cmask_contains(cid, m))\n \t\treturn;\n-\tw = __cmask_word(cid, m);\n-\tbit = BIT_U64(cid \u0026 63);\n-\tbpf_for(i, 0, CMASK_CAS_TRIES) {\n-\t\told = *w;\n-\t\tif (!(old \u0026 bit))\n-\t\t\treturn;\n-\t\tnew = old \u0026 ~bit;\n-\t\tif (__sync_val_compare_and_swap(w, old, new) == old)\n-\t\t\treturn;\n-\t}\n-\tscx_bpf_error(\"cmask_clear CAS exhausted at cid %u\", cid);\n+\t__sync_fetch_and_and(__cmask_word(cid, m), ~BIT_U64(cid \u0026 63));\n }\n \n static __always_inline bool cmask_test_and_set(u32 cid, struct scx_cmask __arena *m)\n {\n-\tu64 __arena *w;\n-\tu64 bit, old, new;\n-\tu32 i;\n+\tu64 bit;\n \n \tif (!__cmask_contains(cid, m))\n \t\treturn false;\n-\tw = __cmask_word(cid, m);\n \tbit = BIT_U64(cid \u0026 63);\n-\tbpf_for(i, 0, CMASK_CAS_TRIES) {\n-\t\told = *w;\n-\t\tif (old \u0026 bit)\n-\t\t\treturn true;\n-\t\tnew = old | bit;\n-\t\tif (__sync_val_compare_and_swap(w, old, new) == old)\n-\t\t\treturn false;\n-\t}\n-\tscx_bpf_error(\"cmask_test_and_set CAS exhausted at cid %u\", cid);\n-\treturn false;\n+\treturn __sync_fetch_and_or(__cmask_word(cid, m), bit) \u0026 bit;\n }\n \n static __always_inline bool cmask_test_and_clear(u32 cid, struct scx_cmask __arena *m)\n {\n-\tu64 __arena *w;\n-\tu64 bit, old, new;\n-\tu32 i;\n+\tu64 bit;\n \n \tif (!__cmask_contains(cid, m))\n \t\treturn false;\n-\tw = __cmask_word(cid, m);\n \tbit = BIT_U64(cid \u0026 63);\n-\tbpf_for(i, 0, CMASK_CAS_TRIES) {\n-\t\told = *w;\n-\t\tif (!(old \u0026 bit))\n-\t\t\treturn false;\n-\t\tnew = old \u0026 ~bit;\n-\t\tif (__sync_val_compare_and_swap(w, old, new) == old)\n-\t\t\treturn true;\n-\t}\n-\tscx_bpf_error(\"cmask_test_and_clear CAS exhausted at cid %u\", cid);\n-\treturn false;\n+\treturn __sync_fetch_and_and(__cmask_word(cid, m), ~bit) \u0026 bit;\n }\n \n static __always_inline void __cmask_set(u32 cid, struct scx_cmask __arena *m)\ndiff --git a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c\nindex 1ad5d03d07adb..2a535815bf1dc 100644\n--- a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c\n+++ b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c\n@@ -68,6 +68,12 @@ static void test_and(struct arena_atomics *skel)\n \n \tASSERT_EQ(skel-\u003earena-\u003eand64_value, 0x010ull \u003c\u003c 32, \"and64_value\");\n \tASSERT_EQ(skel-\u003earena-\u003eand32_value, 0x010, \"and32_value\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003eand64_result, 0x110ull \u003c\u003c 32, \"and64_result\");\n+\tASSERT_EQ(skel-\u003earena-\u003eand32_result, 0x110, \"and32_result\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003eand64_noreturn_value, 0x010ull \u003c\u003c 32, \"and64_noreturn_value\");\n+\tASSERT_EQ(skel-\u003earena-\u003eand32_noreturn_value, 0x010, \"and32_noreturn_value\");\n }\n \n static void test_or(struct arena_atomics *skel)\n@@ -85,6 +91,12 @@ static void test_or(struct arena_atomics *skel)\n \n \tASSERT_EQ(skel-\u003earena-\u003eor64_value, 0x111ull \u003c\u003c 32, \"or64_value\");\n \tASSERT_EQ(skel-\u003earena-\u003eor32_value, 0x111, \"or32_value\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003eor64_result, 0x110ull \u003c\u003c 32, \"or64_result\");\n+\tASSERT_EQ(skel-\u003earena-\u003eor32_result, 0x110, \"or32_result\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003eor64_noreturn_value, 0x111ull \u003c\u003c 32, \"or64_noreturn_value\");\n+\tASSERT_EQ(skel-\u003earena-\u003eor32_noreturn_value, 0x111, \"or32_noreturn_value\");\n }\n \n static void test_xor(struct arena_atomics *skel)\n@@ -102,6 +114,12 @@ static void test_xor(struct arena_atomics *skel)\n \n \tASSERT_EQ(skel-\u003earena-\u003exor64_value, 0x101ull \u003c\u003c 32, \"xor64_value\");\n \tASSERT_EQ(skel-\u003earena-\u003exor32_value, 0x101, \"xor32_value\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003exor64_result, 0x110ull \u003c\u003c 32, \"xor64_result\");\n+\tASSERT_EQ(skel-\u003earena-\u003exor32_result, 0x110, \"xor32_result\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003exor64_noreturn_value, 0x101ull \u003c\u003c 32, \"xor64_noreturn_value\");\n+\tASSERT_EQ(skel-\u003earena-\u003exor32_noreturn_value, 0x101, \"xor32_noreturn_value\");\n }\n \n static void test_cmpxchg(struct arena_atomics *skel)\n@@ -146,6 +164,27 @@ static void test_xchg(struct arena_atomics *skel)\n \tASSERT_EQ(skel-\u003earena-\u003exchg32_result, 1, \"xchg32_result\");\n }\n \n+static void test_fetch_r0(struct arena_atomics *skel)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, topts);\n+\tint err, prog_fd;\n+\n+\t/* No need to attach it, just run it directly */\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.fetch_r0);\n+\terr = bpf_prog_test_run_opts(prog_fd, \u0026topts);\n+\tif (!ASSERT_OK(err, \"test_run_opts err\"))\n+\t\treturn;\n+\tif (!ASSERT_OK(topts.retval, \"test_run_opts retval\"))\n+\t\treturn;\n+\n+\tASSERT_EQ(skel-\u003earena-\u003efetch_src_r0_value, 0x111, \"fetch_src_r0_value\");\n+\tASSERT_EQ(skel-\u003earena-\u003efetch_src_r0_result, 0x110, \"fetch_src_r0_result\");\n+\n+\tASSERT_EQ(skel-\u003earena-\u003efetch_dst_r0_value, 0x111, \"fetch_dst_r0_value\");\n+\tASSERT_EQ(skel-\u003earena-\u003efetch_dst_r0_result, 0x110, \"fetch_dst_r0_result\");\n+\tASSERT_EQ(skel-\u003earena-\u003efetch_dst_r0_readback, 0x111, \"fetch_dst_r0_readback\");\n+}\n+\n static void test_uaf(struct arena_atomics *skel)\n {\n \tLIBBPF_OPTS(bpf_test_run_opts, topts);\n@@ -256,6 +295,8 @@ void serial_test_arena_atomics(void)\n \t\ttest_cmpxchg(skel);\n \tif (test__start_subtest(\"xchg\"))\n \t\ttest_xchg(skel);\n+\tif (test__start_subtest(\"fetch_r0\"))\n+\t\ttest_fetch_r0(skel);\n \tif (test__start_subtest(\"uaf\"))\n \t\ttest_uaf(skel);\n \tif (test__start_subtest(\"load_acquire\"))\ndiff --git a/tools/testing/selftests/bpf/progs/arena_atomics.c b/tools/testing/selftests/bpf/progs/arena_atomics.c\nindex 73bc2b835f3fe..3beca5eab3873 100644\n--- a/tools/testing/selftests/bpf/progs/arena_atomics.c\n+++ b/tools/testing/selftests/bpf/progs/arena_atomics.c\n@@ -91,13 +91,22 @@ int sub(const void *ctx)\n \treturn 0;\n }\n \n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-_Atomic __u64 __arena_global and64_value = (0x110ull \u003c\u003c 32);\n-_Atomic __u32 __arena_global and32_value = 0x110;\n-#else\n+/*\n+ * Discarding the result of an atomic RMW is what selects the non-fetching\n+ * insn, so keep one of each width per operation to cover that lowering too.\n+ * Declared together rather than per operation to keep them in one place.\n+ */\n+_Atomic __u64 __arena_global and64_noreturn_value = (0x110ull \u003c\u003c 32);\n+_Atomic __u64 __arena_global or64_noreturn_value = (0x110ull \u003c\u003c 32);\n+_Atomic __u64 __arena_global xor64_noreturn_value = (0x110ull \u003c\u003c 32);\n+_Atomic __u32 __arena_global and32_noreturn_value = 0x110;\n+_Atomic __u32 __arena_global or32_noreturn_value = 0x110;\n+_Atomic __u32 __arena_global xor32_noreturn_value = 0x110;\n+\n __u64 __arena_global and64_value = (0x110ull \u003c\u003c 32);\n+__u64 __arena_global and64_result = 0;\n __u32 __arena_global and32_value = 0x110;\n-#endif\n+__u32 __arena_global and32_result = 0;\n \n SEC(\"raw_tp/sys_enter\")\n int and(const void *ctx)\n@@ -105,25 +114,19 @@ int and(const void *ctx)\n \tif (pid != (bpf_get_current_pid_tgid() \u003e\u003e 32))\n \t\treturn 0;\n #ifdef ENABLE_ATOMICS_TESTS\n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-\t__c11_atomic_fetch_and(\u0026and64_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n-\t__c11_atomic_fetch_and(\u0026and32_value, 0x011, memory_order_relaxed);\n-#else\n-\t__sync_fetch_and_and(\u0026and64_value, 0x011ull \u003c\u003c 32);\n-\t__sync_fetch_and_and(\u0026and32_value, 0x011);\n-#endif\n+\tand64_result = __sync_fetch_and_and(\u0026and64_value, 0x011ull \u003c\u003c 32);\n+\tand32_result = __sync_fetch_and_and(\u0026and32_value, 0x011);\n+\t__c11_atomic_fetch_and(\u0026and64_noreturn_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n+\t__c11_atomic_fetch_and(\u0026and32_noreturn_value, 0x011, memory_order_relaxed);\n #endif\n \n \treturn 0;\n }\n \n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-_Atomic __u32 __arena_global or32_value = 0x110;\n-_Atomic __u64 __arena_global or64_value = (0x110ull \u003c\u003c 32);\n-#else\n-__u32 __arena_global or32_value = 0x110;\n __u64 __arena_global or64_value = (0x110ull \u003c\u003c 32);\n-#endif\n+__u64 __arena_global or64_result = 0;\n+__u32 __arena_global or32_value = 0x110;\n+__u32 __arena_global or32_result = 0;\n \n SEC(\"raw_tp/sys_enter\")\n int or(const void *ctx)\n@@ -131,25 +134,19 @@ int or(const void *ctx)\n \tif (pid != (bpf_get_current_pid_tgid() \u003e\u003e 32))\n \t\treturn 0;\n #ifdef ENABLE_ATOMICS_TESTS\n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-\t__c11_atomic_fetch_or(\u0026or64_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n-\t__c11_atomic_fetch_or(\u0026or32_value, 0x011, memory_order_relaxed);\n-#else\n-\t__sync_fetch_and_or(\u0026or64_value, 0x011ull \u003c\u003c 32);\n-\t__sync_fetch_and_or(\u0026or32_value, 0x011);\n-#endif\n+\tor64_result = __sync_fetch_and_or(\u0026or64_value, 0x011ull \u003c\u003c 32);\n+\tor32_result = __sync_fetch_and_or(\u0026or32_value, 0x011);\n+\t__c11_atomic_fetch_or(\u0026or64_noreturn_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n+\t__c11_atomic_fetch_or(\u0026or32_noreturn_value, 0x011, memory_order_relaxed);\n #endif\n \n \treturn 0;\n }\n \n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-_Atomic __u64 __arena_global xor64_value = (0x110ull \u003c\u003c 32);\n-_Atomic __u32 __arena_global xor32_value = 0x110;\n-#else\n __u64 __arena_global xor64_value = (0x110ull \u003c\u003c 32);\n+__u64 __arena_global xor64_result = 0;\n __u32 __arena_global xor32_value = 0x110;\n-#endif\n+__u32 __arena_global xor32_result = 0;\n \n SEC(\"raw_tp/sys_enter\")\n int xor(const void *ctx)\n@@ -157,13 +154,10 @@ int xor(const void *ctx)\n \tif (pid != (bpf_get_current_pid_tgid() \u003e\u003e 32))\n \t\treturn 0;\n #ifdef ENABLE_ATOMICS_TESTS\n-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING\n-\t__c11_atomic_fetch_xor(\u0026xor64_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n-\t__c11_atomic_fetch_xor(\u0026xor32_value, 0x011, memory_order_relaxed);\n-#else\n-\t__sync_fetch_and_xor(\u0026xor64_value, 0x011ull \u003c\u003c 32);\n-\t__sync_fetch_and_xor(\u0026xor32_value, 0x011);\n-#endif\n+\txor64_result = __sync_fetch_and_xor(\u0026xor64_value, 0x011ull \u003c\u003c 32);\n+\txor32_result = __sync_fetch_and_xor(\u0026xor32_value, 0x011);\n+\t__c11_atomic_fetch_xor(\u0026xor64_noreturn_value, 0x011ull \u003c\u003c 32, memory_order_relaxed);\n+\t__c11_atomic_fetch_xor(\u0026xor32_noreturn_value, 0x011, memory_order_relaxed);\n #endif\n \n \treturn 0;\n@@ -213,6 +207,64 @@ int xchg(const void *ctx)\n \treturn 0;\n }\n \n+__u64 __arena_global fetch_src_r0_value = 0x110;\n+__u64 __arena_global fetch_src_r0_result = 0;\n+__u64 __arena_global fetch_dst_r0_value = 0x110;\n+__u64 __arena_global fetch_dst_r0_result = 0;\n+__u64 __arena_global fetch_dst_r0_readback = 0;\n+\n+/*\n+ * A fetching OR with the operand in r0, and one with the arena pointer in r0.\n+ * The x86 JIT needs RAX for its CMPXCHG loop and substitutes BPF_REG_AX for\n+ * whichever of the two is r0, so both have to keep working. Hand-written\n+ * because clang picks its own registers and will not reliably emit either.\n+ */\n+SEC(\"raw_tp/sys_enter\")\n+int fetch_r0(const void *ctx)\n+{\n+\tif (pid != (bpf_get_current_pid_tgid() \u003e\u003e 32))\n+\t\treturn 0;\n+#if defined(ENABLE_ATOMICS_TESTS) \u0026\u0026 defined(__BPF_FEATURE_ADDR_SPACE_CAST)\n+\tasm volatile (\n+\t\"r1 = %[fetch_src_r0_value] ll;\"\n+\t\"r1 = addr_space_cast(r1, 0x0, 0x1);\"\n+\t\"r0 = 0x011;\"\n+\t\".8byte %[fetch_src_r0_insn];\"\n+\t\"r2 = %[fetch_src_r0_result] ll;\"\n+\t\"r2 = addr_space_cast(r2, 0x0, 0x1);\"\n+\t\"*(u64 *)(r2 + 0) = r0;\"\n+\t:\n+\t: __imm_addr(fetch_src_r0_value),\n+\t __imm_insn(fetch_src_r0_insn,\n+\t\t BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0)),\n+\t __imm_addr(fetch_src_r0_result)\n+\t: __clobber_all);\n+\n+\tasm volatile (\n+\t\"r0 = %[fetch_dst_r0_value] ll;\"\n+\t\"r0 = addr_space_cast(r0, 0x0, 0x1);\"\n+\t\"r1 = 0x011;\"\n+\t\".8byte %[fetch_dst_r0_insn];\"\n+\t\"r2 = %[fetch_dst_r0_result] ll;\"\n+\t\"r2 = addr_space_cast(r2, 0x0, 0x1);\"\n+\t\"*(u64 *)(r2 + 0) = r1;\"\n+\t/* r0 is only read by the atomic, so it must still be the pointer. */\n+\t\"r3 = *(u64 *)(r0 + 0);\"\n+\t\"r2 = %[fetch_dst_r0_readback] ll;\"\n+\t\"r2 = addr_space_cast(r2, 0x0, 0x1);\"\n+\t\"*(u64 *)(r2 + 0) = r3;\"\n+\t:\n+\t: __imm_addr(fetch_dst_r0_value),\n+\t __imm_insn(fetch_dst_r0_insn,\n+\t\t BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0)),\n+\t __imm_addr(fetch_dst_r0_result),\n+\t __imm_addr(fetch_dst_r0_readback)\n+\t: __clobber_all);\n+#endif\n+\n+\treturn 0;\n+}\n+\n __u64 __arena_global uaf_sink;\n volatile __u64 __arena_global uaf_recovery_fails;\n \n@@ -221,15 +273,24 @@ int uaf(const void *ctx)\n {\n \tif (pid != (bpf_get_current_pid_tgid() \u003e\u003e 32))\n \t\treturn 0;\n+/*\n+ * arm64 stays excluded as it has been since this test was added: its JIT only\n+ * accepts arena RMW atomics when LSE is present, which is a run-time property.\n+ * The rest of the file shares that dependency without a guard, so on a non-LSE\n+ * arm64 the whole skeleton already fails to load.\n+ *\n+ * __BPF_FEATURE_ADDR_SPACE_CAST is required by the asm below, which spells\n+ * addr_space_cast textually. That and the mnemonic both arrived in LLVM 19.\n+ */\n #if defined(ENABLE_ATOMICS_TESTS) \u0026\u0026 !defined(__TARGET_ARCH_arm64) \u0026\u0026 \\\n- !defined(__TARGET_ARCH_x86)\n+\tdefined(__BPF_FEATURE_ADDR_SPACE_CAST)\n \t__u32 __arena *page32;\n \t__u64 __arena *page64;\n \tvoid __arena *page;\n \n \tpage = bpf_arena_alloc_pages(\u0026arena, NULL, 1, NUMA_NO_NODE, 0);\n \tbpf_arena_free_pages(\u0026arena, page, 1);\n-\tuaf_recovery_fails = 24;\n+\tuaf_recovery_fails = 26;\n \n \tpage32 = (__u32 __arena *)page;\n \tuaf_sink += __sync_fetch_and_add(page32, 1);\n@@ -282,6 +343,34 @@ int uaf(const void *ctx)\n \tuaf_recovery_fails -= 1;\n \tuaf_sink += __sync_lock_test_and_set(page64, 1);\n \tuaf_recovery_fails -= 1;\n+\n+\t/*\n+\t * The x86 JIT needs RAX for the CMPXCHG loop it lowers a fetching\n+\t * AND/OR/XOR into, and substitutes BPF_REG_AX for r0 when r0 is either\n+\t * operand. Only then does the fault fixup have to name that register,\n+\t * so spell both forms out: clang picks its own and never produces them.\n+\t */\n+\tasm volatile (\n+\t\"r0 = %[page];\"\n+\t\"r0 = addr_space_cast(r0, 0x0, 0x1);\"\n+\t\"r1 = 1;\"\n+\t\".8byte %[fetch_dst_r0];\"\n+\t: : [page]\"r\"(page64),\n+\t __imm_insn(fetch_dst_r0,\n+\t\t BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0))\n+\t: \"r0\", \"r1\", \"memory\");\n+\tuaf_recovery_fails -= 1;\n+\n+\tasm volatile (\n+\t\"r1 = %[page];\"\n+\t\"r1 = addr_space_cast(r1, 0x0, 0x1);\"\n+\t\"r0 = 1;\"\n+\t\".8byte %[fetch_src_r0];\"\n+\t: : [page]\"r\"(page64),\n+\t __imm_insn(fetch_src_r0,\n+\t\t BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0))\n+\t: \"r0\", \"r1\", \"memory\");\n+\tuaf_recovery_fails -= 1;\n #endif\n \n \treturn 0;\n"
} |
| 2/1 | 2026/09/27 11:06 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_atomic_fetch_rmw",
"emit_arena_exentry",
"do_jit",
"bpf_int_jit_compile",
"bpf_jit_supports_insn",
"ex_handler_bpf"
],
"Reasoning": "The patch modifies the x86 BPF JIT compiler (arch/x86/net/bpf_jit_comp.c) to support atomic fetch operations (BPF_AND, BPF_OR, BPF_XOR with BPF_FETCH) on BPF arena memory via a cmpxchg loop and sets up arena exception table entries to handle potential faults. This modifies core BPF JIT compilation and exception handling logic reachable through the bpf() system call.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any '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: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit d9fe1ca121010baba460954ce089855d38cef398
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 11:06:33 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6c7a0578760e7..570ee93a969a9 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -236,8 +236,17 @@ static const int reg2pt_regs[] = {
[BPF_REG_7] = offsetof(struct pt_regs, r13),
[BPF_REG_8] = offsetof(struct pt_regs, r14),
[BPF_REG_9] = offsetof(struct pt_regs, r15),
+ /* Substituted for R0 by the CMPXCHG loop lowering below. */
+ [BPF_REG_AX] = offsetof(struct pt_regs, r10),
};
+static bool is_atomic_fetch_op(const struct bpf_insn *insn)
+{
+ return insn->imm == (BPF_AND | BPF_FETCH) ||
+ insn->imm == (BPF_OR | BPF_FETCH) ||
+ insn->imm == (BPF_XOR | BPF_FETCH);
+}
+
/*
* is_ereg() == true if BPF register 'reg' maps to x86-64 r8..r15
* which need extra byte of encoding.
@@ -1679,6 +1688,74 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
return 0;
}
+/*
+ * A fetching AND/OR/XOR can't be implemented with a single x86 insn, so do a
+ * CMPXCHG loop. @index_reg is X86_REG_R12 for an arena access or -1 otherwise,
+ * and @dst_reg/@src_reg are already substituted for R0 by the caller.
+ *
+ * For an arena access the CMPXCHG is the only insn that can fault; its address
+ * is handed back in @fault. A fault has to resume at @resume, which is past the
+ * loop and past the move that delivers the old value, but before the R0
+ * restore. Both are NULL for the non-arena case, which needs no fixup.
+ */
+static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,
+ u32 src_reg, int index_reg, u8 **fault,
+ u8 **resume)
+{
+ bool is64 = BPF_SIZE(insn->code) == BPF_DW;
+ u8 *branch_target, *prog = *pprog;
+ int err;
+
+ branch_target = prog;
+
+ /*
+ * Load old value. The arena case skips it and lets the loop start from
+ * whatever R0 happens to hold: a CMPXCHG that loses the comparison
+ * loads the current contents into RAX, so the loop converges, and the
+ * value it stores is computed from RAX, which by definition equalled
+ * memory whenever the store happened. That leaves the CMPXCHG as the
+ * only insn that can fault, which is worth an extra iteration here to
+ * keep this to a single exception table entry.
+ */
+ if (index_reg < 0)
+ emit_ldx(&prog, BPF_SIZE(insn->code), BPF_REG_0, dst_reg, insn->off);
+
+ /*
+ * Perform the (commutative) operation locally, put the result in
+ * the AUX_REG.
+ */
+ emit_mov_reg(&prog, is64, AUX_REG, BPF_REG_0);
+ maybe_emit_mod(&prog, AUX_REG, src_reg, is64);
+ EMIT2(simple_alu_opcodes[BPF_OP(insn->imm)],
+ add_2reg(0xC0, AUX_REG, src_reg));
+
+ /* Attempt to swap in new value */
+ if (fault)
+ *fault = prog;
+ if (index_reg < 0)
+ err = emit_atomic_rmw(&prog, BPF_CMPXCHG, dst_reg, AUX_REG,
+ insn->off, BPF_SIZE(insn->code));
+ else
+ err = emit_atomic_rmw_index(&prog, BPF_CMPXCHG, BPF_SIZE(insn->code),
+ dst_reg, AUX_REG, index_reg, insn->off);
+ if (WARN_ON(err))
+ return err;
+
+ /* ZF tells us whether we won the race. If it's cleared we need to try again. */
+ EMIT2(X86_JNE, -(prog - branch_target) - 2);
+ /* Return the pre-modification value */
+ emit_mov_reg(&prog, is64, src_reg, BPF_REG_0);
+
+ if (resume)
+ *resume = prog;
+
+ /* Restore R0 after clobbering RAX */
+ emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);
+
+ *pprog = prog;
+ return 0;
+}
+
/*
* Metadata encoding for exception handling in JITed code.
*
@@ -1692,7 +1769,12 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
* | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |
* +-----------+-------------+--------+-----------+---------+----------+
*
- * - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).
+ * - INSN_LEN (8 bits): How far past the faulting insn to resume. That is its own length
+ * for a single-insn access, but the distance to the end of the whole
+ * sequence where one BPF insn became several, as for the CMPXCHG loop
+ * of a fetching AND/OR/XOR. A sequence long enough to overflow this
+ * field would first have to exceed BPF_MAX_INSN_SIZE, which do_jit()
+ * rejects with -EFAULT before the image is used.
* - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).
* This is set to DONT_CLEAR if the insn does not read into a register.
* - ARENA_REG (8 bits): Offset of the register that is used to calculate the
@@ -1747,6 +1829,44 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
return true;
}
+/*
+ * Record an arena access that may fault. @fault_ip is the address of the
+ * faulting insn in the RO image, @resume_off how far past it execution has to
+ * resume: for a multi-insn lowering that is the end of the whole sequence, not
+ * the end of the one insn.
+ */
+static int emit_arena_exentry(struct bpf_prog *bpf_prog, u8 *image, u8 *rw_image,
+ int *excnt, u8 *fault_ip, u32 resume_off,
+ u32 fixup_reg, u32 arena_reg, bool is_write, s16 off)
+{
+ struct exception_table_entry *ex;
+ s64 delta;
+
+ if (!bpf_prog->aux->extable)
+ return 0;
+
+ if (*excnt >= bpf_prog->aux->num_exentries) {
+ pr_err("arena extable bug\n");
+ return -EFAULT;
+ }
+ ex = &bpf_prog->aux->extable[(*excnt)++];
+
+ delta = fault_ip - (u8 *)&ex->insn;
+ /* switch ex to rw buffer for writes */
+ ex = (void *)rw_image + ((void *)ex - (void *)image);
+
+ ex->insn = delta;
+ ex->data = EX_TYPE_BPF | FIELD_PREP(DATA_ARENA_OFFSET_MASK, off);
+ ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, resume_off) |
+ FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
+ FIELD_PREP(FIXUP_REG_MASK, fixup_reg) |
+ FIXUP_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= FIXUP_ARENA_WRITE;
+
+ return 0;
+}
+
static void detect_reg_usage(struct bpf_insn *insn, int insn_cnt,
bool *regs_used)
{
@@ -2624,28 +2744,8 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
}
populate_extable:
{
- struct exception_table_entry *ex;
- u8 *_insn = image + proglen + (start_of_ldx - temp);
u32 arena_reg, fixup_reg;
bool is_write;
- s64 delta;
-
- if (!bpf_prog->aux->extable)
- break;
-
- if (excnt >= bpf_prog->aux->num_exentries) {
- pr_err("mem32 extable bug\n");
- return -EFAULT;
- }
- ex = &bpf_prog->aux->extable[excnt++];
-
- delta = _insn - (u8 *)&ex->insn;
- /* switch ex to rw buffer for writes */
- ex = (void *)rw_image + ((void *)ex - (void *)image);
-
- ex->insn = delta;
-
- ex->data = EX_TYPE_BPF;
/*
* src_reg/dst_reg holds the address in the arena region with upper
@@ -2681,14 +2781,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
is_write = true;
}
- ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |
- FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
- FIELD_PREP(FIXUP_REG_MASK, fixup_reg);
- ex->fixup |= FIXUP_ARENA_ACCESS;
- if (is_write)
- ex->fixup |= FIXUP_ARENA_WRITE;
-
- ex->data |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn->off);
+ err = emit_arena_exentry(bpf_prog, image, rw_image, &excnt,
+ image + proglen + (start_of_ldx - temp),
+ prog - start_of_ldx, fixup_reg,
+ arena_reg, is_write, insn->off);
+ if (err)
+ return err;
}
break;
@@ -2840,20 +2938,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
fallthrough;
case BPF_STX | BPF_ATOMIC | BPF_W:
case BPF_STX | BPF_ATOMIC | BPF_DW: {
- bool is64 = BPF_SIZE(insn->code) == BPF_DW;
u32 real_src_reg = src_reg;
u32 real_dst_reg = dst_reg;
+ bool is_atomic_fetch = is_atomic_fetch_op(insn);
u8 *old_prog;
- bool is_atomic_fetch =
- (insn->imm == (BPF_AND | BPF_FETCH) ||
- insn->imm == (BPF_OR | BPF_FETCH) ||
- insn->imm == (BPF_XOR | BPF_FETCH));
- if (is_atomic_fetch) {
- /*
- * Can't be implemented with a single x86 insn.
- * Need to do a CMPXCHG loop.
- */
+ if (is_atomic_fetch) {
/* Will need RAX as a CMPXCHG operand so save R0 */
old_prog = prog;
emit_mov_reg(&prog, true, BPF_REG_AX, BPF_REG_0);
@@ -2874,34 +2964,11 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
}
}
if (is_atomic_fetch) {
- u8 *branch_target = prog;
- /* Load old value */
- emit_ldx(&prog, BPF_SIZE(insn->code),
- BPF_REG_0, real_dst_reg, insn->off);
- /*
- * Perform the (commutative) operation locally,
- * put the result in the AUX_REG.
- */
- emit_mov_reg(&prog, is64, AUX_REG, BPF_REG_0);
- maybe_emit_mod(&prog, AUX_REG, real_src_reg, is64);
- EMIT2(simple_alu_opcodes[BPF_OP(insn->imm)],
- add_2reg(0xC0, AUX_REG, real_src_reg));
- /* Attempt to swap in new value */
- err = emit_atomic_rmw(&prog, BPF_CMPXCHG,
- real_dst_reg, AUX_REG,
- insn->off,
- BPF_SIZE(insn->code));
- if (WARN_ON(err))
+ err = emit_atomic_fetch_rmw(&prog, insn, real_dst_reg,
+ real_src_reg, -1, NULL,
+ NULL);
+ if (err)
return err;
- /*
- * ZF tells us whether we won the race. If it's
- * cleared we need to try again.
- */
- EMIT2(X86_JNE, -(prog - branch_target) - 2);
- /* Return the pre-modification value */
- emit_mov_reg(&prog, is64, real_src_reg, BPF_REG_0);
- /* Restore R0 after clobbering RAX */
- emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);
break;
}
@@ -2925,6 +2992,33 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
fallthrough;
case BPF_STX | BPF_PROBE_ATOMIC | BPF_W:
case BPF_STX | BPF_PROBE_ATOMIC | BPF_DW:
+ if (is_atomic_fetch_op(insn)) {
+ u32 real_src_reg = src_reg, real_dst_reg = dst_reg;
+ u8 *fault, *resume;
+
+ /* Will need RAX as a CMPXCHG operand so save R0 */
+ emit_mov_reg(&prog, true, BPF_REG_AX, BPF_REG_0);
+ if (src_reg == BPF_REG_0)
+ real_src_reg = BPF_REG_AX;
+ if (dst_reg == BPF_REG_0)
+ real_dst_reg = BPF_REG_AX;
+
+ err = emit_atomic_fetch_rmw(&prog, insn, real_dst_reg,
+ real_src_reg, X86_REG_R12,
+ &fault, &resume);
+ if (err)
+ return err;
+
+ err = emit_arena_exentry(bpf_prog, image, rw_image, &excnt,
+ image + proglen + (fault - temp),
+ resume - fault,
+ reg2pt_regs[real_src_reg],
+ reg2pt_regs[real_dst_reg],
+ true, insn->off);
+ if (err)
+ return err;
+ break;
+ }
start_of_ldx = prog;
if (bpf_atomic_is_load_store(insn))
@@ -4669,16 +4763,6 @@ bool bpf_jit_supports_arena(void)
bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
{
- if (!in_arena)
- return true;
- switch (insn->code) {
- case BPF_STX | BPF_ATOMIC | BPF_W:
- case BPF_STX | BPF_ATOMIC | BPF_DW:
- if (insn->imm == (BPF_AND | BPF_FETCH) ||
- insn->imm == (BPF_OR | BPF_FETCH) ||
- insn->imm == (BPF_XOR | BPF_FETCH))
- return false;
- }
return true;
}
diff --git a/tools/sched_ext/include/scx/cid.bpf.h b/tools/sched_ext/include/scx/cid.bpf.h
index 69fb4e97bc771..d0d4cea19e29f 100644
--- a/tools/sched_ext/include/scx/cid.bpf.h
+++ b/tools/sched_ext/include/scx/cid.bpf.h
@@ -3,8 +3,8 @@
* BPF-side helpers for cids and cmasks. See kernel/sched/ext/cid.h for the
* authoritative layout and semantics. The BPF-side helpers use the cmask_*
* naming (no scx_ prefix); cmask is the SCX bitmap type so the prefix is
- * redundant in BPF code. Atomics use __sync_val_compare_and_swap and every
- * helper is inline (no .c counterpart).
+ * redundant in BPF code. Atomics use the __sync_* builtins and every helper
+ * is inline (no .c counterpart).
*
* Included by scx/common.bpf.h; don't include directly.
*
@@ -129,101 +129,38 @@ static __always_inline bool cmask_test(u32 cid, const struct scx_cmask __arena *
return *__cmask_word(cid, m) & BIT_U64(cid & 63);
}
-/*
- * x86 BPF JIT rejects BPF_OR | BPF_FETCH and BPF_AND | BPF_FETCH on arena
- * pointers (see bpf_jit_supports_insn() in arch/x86/net/bpf_jit_comp.c). Only
- * BPF_CMPXCHG / BPF_XCHG / BPF_ADD with FETCH are allowed. Implement
- * test_and_{set,clear} and the atomic set/clear via a cmpxchg loop.
- *
- * CMASK_CAS_TRIES is sized so exhausting it means seconds of real spinning
- * on one word - past any plausible contention. Abort hard.
- */
-#define CMASK_CAS_TRIES (1U << 23)
-
static __always_inline void cmask_set(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
-
if (!__cmask_contains(cid, m))
return;
- w = __cmask_word(cid, m);
- bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (old & bit)
- return;
- new = old | bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return;
- }
- scx_bpf_error("cmask_set CAS exhausted at cid %u", cid);
+ __sync_fetch_and_or(__cmask_word(cid, m), BIT_U64(cid & 63));
}
static __always_inline void cmask_clear(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
-
if (!__cmask_contains(cid, m))
return;
- w = __cmask_word(cid, m);
- bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (!(old & bit))
- return;
- new = old & ~bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return;
- }
- scx_bpf_error("cmask_clear CAS exhausted at cid %u", cid);
+ __sync_fetch_and_and(__cmask_word(cid, m), ~BIT_U64(cid & 63));
}
static __always_inline bool cmask_test_and_set(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
+ u64 bit;
if (!__cmask_contains(cid, m))
return false;
- w = __cmask_word(cid, m);
bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (old & bit)
- return true;
- new = old | bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return false;
- }
- scx_bpf_error("cmask_test_and_set CAS exhausted at cid %u", cid);
- return false;
+ return __sync_fetch_and_or(__cmask_word(cid, m), bit) & bit;
}
static __always_inline bool cmask_test_and_clear(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
+ u64 bit;
if (!__cmask_contains(cid, m))
return false;
- w = __cmask_word(cid, m);
bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (!(old & bit))
- return false;
- new = old & ~bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return true;
- }
- scx_bpf_error("cmask_test_and_clear CAS exhausted at cid %u", cid);
- return false;
+ return __sync_fetch_and_and(__cmask_word(cid, m), ~bit) & bit;
}
static __always_inline void __cmask_set(u32 cid, struct scx_cmask __arena *m)
diff --git a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
index 1ad5d03d07adb..2a535815bf1dc 100644
--- a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
+++ b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
@@ -68,6 +68,12 @@ static void test_and(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->and64_value, 0x010ull << 32, "and64_value");
ASSERT_EQ(skel->arena->and32_value, 0x010, "and32_value");
+
+ ASSERT_EQ(skel->arena->and64_result, 0x110ull << 32, "and64_result");
+ ASSERT_EQ(skel->arena->and32_result, 0x110, "and32_result");
+
+ ASSERT_EQ(skel->arena->and64_noreturn_value, 0x010ull << 32, "and64_noreturn_value");
+ ASSERT_EQ(skel->arena->and32_noreturn_value, 0x010, "and32_noreturn_value");
}
static void test_or(struct arena_atomics *skel)
@@ -85,6 +91,12 @@ static void test_or(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->or64_value, 0x111ull << 32, "or64_value");
ASSERT_EQ(skel->arena->or32_value, 0x111, "or32_value");
+
+ ASSERT_EQ(skel->arena->or64_result, 0x110ull << 32, "or64_result");
+ ASSERT_EQ(skel->arena->or32_result, 0x110, "or32_result");
+
+ ASSERT_EQ(skel->arena->or64_noreturn_value, 0x111ull << 32, "or64_noreturn_value");
+ ASSERT_EQ(skel->arena->or32_noreturn_value, 0x111, "or32_noreturn_value");
}
static void test_xor(struct arena_atomics *skel)
@@ -102,6 +114,12 @@ static void test_xor(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->xor64_value, 0x101ull << 32, "xor64_value");
ASSERT_EQ(skel->arena->xor32_value, 0x101, "xor32_value");
+
+ ASSERT_EQ(skel->arena->xor64_result, 0x110ull << 32, "xor64_result");
+ ASSERT_EQ(skel->arena->xor32_result, 0x110, "xor32_result");
+
+ ASSERT_EQ(skel->arena->xor64_noreturn_value, 0x101ull << 32, "xor64_noreturn_value");
+ ASSERT_EQ(skel->arena->xor32_noreturn_value, 0x101, "xor32_noreturn_value");
}
static void test_cmpxchg(struct arena_atomics *skel)
@@ -146,6 +164,27 @@ static void test_xchg(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->xchg32_result, 1, "xchg32_result");
}
+static void test_fetch_r0(struct arena_atomics *skel)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ int err, prog_fd;
+
+ /* No need to attach it, just run it directly */
+ prog_fd = bpf_program__fd(skel->progs.fetch_r0);
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ if (!ASSERT_OK(err, "test_run_opts err"))
+ return;
+ if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
+ return;
+
+ ASSERT_EQ(skel->arena->fetch_src_r0_value, 0x111, "fetch_src_r0_value");
+ ASSERT_EQ(skel->arena->fetch_src_r0_result, 0x110, "fetch_src_r0_result");
+
+ ASSERT_EQ(skel->arena->fetch_dst_r0_value, 0x111, "fetch_dst_r0_value");
+ ASSERT_EQ(skel->arena->fetch_dst_r0_result, 0x110, "fetch_dst_r0_result");
+ ASSERT_EQ(skel->arena->fetch_dst_r0_readback, 0x111, "fetch_dst_r0_readback");
+}
+
static void test_uaf(struct arena_atomics *skel)
{
LIBBPF_OPTS(bpf_test_run_opts, topts);
@@ -256,6 +295,8 @@ void serial_test_arena_atomics(void)
test_cmpxchg(skel);
if (test__start_subtest("xchg"))
test_xchg(skel);
+ if (test__start_subtest("fetch_r0"))
+ test_fetch_r0(skel);
if (test__start_subtest("uaf"))
test_uaf(skel);
if (test__start_subtest("load_acquire"))
diff --git a/tools/testing/selftests/bpf/progs/arena_atomics.c b/tools/testing/selftests/bpf/progs/arena_atomics.c
index 73bc2b835f3fe..3beca5eab3873 100644
--- a/tools/testing/selftests/bpf/progs/arena_atomics.c
+++ b/tools/testing/selftests/bpf/progs/arena_atomics.c
@@ -91,13 +91,22 @@ int sub(const void *ctx)
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u64 __arena_global and64_value = (0x110ull << 32);
-_Atomic __u32 __arena_global and32_value = 0x110;
-#else
+/*
+ * Discarding the result of an atomic RMW is what selects the non-fetching
+ * insn, so keep one of each width per operation to cover that lowering too.
+ * Declared together rather than per operation to keep them in one place.
+ */
+_Atomic __u64 __arena_global and64_noreturn_value = (0x110ull << 32);
+_Atomic __u64 __arena_global or64_noreturn_value = (0x110ull << 32);
+_Atomic __u64 __arena_global xor64_noreturn_value = (0x110ull << 32);
+_Atomic __u32 __arena_global and32_noreturn_value = 0x110;
+_Atomic __u32 __arena_global or32_noreturn_value = 0x110;
+_Atomic __u32 __arena_global xor32_noreturn_value = 0x110;
+
__u64 __arena_global and64_value = (0x110ull << 32);
+__u64 __arena_global and64_result = 0;
__u32 __arena_global and32_value = 0x110;
-#endif
+__u32 __arena_global and32_result = 0;
SEC("raw_tp/sys_enter")
int and(const void *ctx)
@@ -105,25 +114,19 @@ int and(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_and(&and64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_and(&and32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_and(&and64_value, 0x011ull << 32);
- __sync_fetch_and_and(&and32_value, 0x011);
-#endif
+ and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
+ and32_result = __sync_fetch_and_and(&and32_value, 0x011);
+ __c11_atomic_fetch_and(&and64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_and(&and32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u32 __arena_global or32_value = 0x110;
-_Atomic __u64 __arena_global or64_value = (0x110ull << 32);
-#else
-__u32 __arena_global or32_value = 0x110;
__u64 __arena_global or64_value = (0x110ull << 32);
-#endif
+__u64 __arena_global or64_result = 0;
+__u32 __arena_global or32_value = 0x110;
+__u32 __arena_global or32_result = 0;
SEC("raw_tp/sys_enter")
int or(const void *ctx)
@@ -131,25 +134,19 @@ int or(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_or(&or64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_or(&or32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_or(&or64_value, 0x011ull << 32);
- __sync_fetch_and_or(&or32_value, 0x011);
-#endif
+ or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
+ or32_result = __sync_fetch_and_or(&or32_value, 0x011);
+ __c11_atomic_fetch_or(&or64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_or(&or32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u64 __arena_global xor64_value = (0x110ull << 32);
-_Atomic __u32 __arena_global xor32_value = 0x110;
-#else
__u64 __arena_global xor64_value = (0x110ull << 32);
+__u64 __arena_global xor64_result = 0;
__u32 __arena_global xor32_value = 0x110;
-#endif
+__u32 __arena_global xor32_result = 0;
SEC("raw_tp/sys_enter")
int xor(const void *ctx)
@@ -157,13 +154,10 @@ int xor(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_xor(&xor64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_xor(&xor32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
- __sync_fetch_and_xor(&xor32_value, 0x011);
-#endif
+ xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
+ xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
+ __c11_atomic_fetch_xor(&xor64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_xor(&xor32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
@@ -213,6 +207,64 @@ int xchg(const void *ctx)
return 0;
}
+__u64 __arena_global fetch_src_r0_value = 0x110;
+__u64 __arena_global fetch_src_r0_result = 0;
+__u64 __arena_global fetch_dst_r0_value = 0x110;
+__u64 __arena_global fetch_dst_r0_result = 0;
+__u64 __arena_global fetch_dst_r0_readback = 0;
+
+/*
+ * A fetching OR with the operand in r0, and one with the arena pointer in r0.
+ * The x86 JIT needs RAX for its CMPXCHG loop and substitutes BPF_REG_AX for
+ * whichever of the two is r0, so both have to keep working. Hand-written
+ * because clang picks its own registers and will not reliably emit either.
+ */
+SEC("raw_tp/sys_enter")
+int fetch_r0(const void *ctx)
+{
+ if (pid != (bpf_get_current_pid_tgid() >> 32))
+ return 0;
+#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+ asm volatile (
+ "r1 = %[fetch_src_r0_value] ll;"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 0x011;"
+ ".8byte %[fetch_src_r0_insn];"
+ "r2 = %[fetch_src_r0_result] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r0;"
+ :
+ : __imm_addr(fetch_src_r0_value),
+ __imm_insn(fetch_src_r0_insn,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0)),
+ __imm_addr(fetch_src_r0_result)
+ : __clobber_all);
+
+ asm volatile (
+ "r0 = %[fetch_dst_r0_value] ll;"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ "r1 = 0x011;"
+ ".8byte %[fetch_dst_r0_insn];"
+ "r2 = %[fetch_dst_r0_result] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r1;"
+ /* r0 is only read by the atomic, so it must still be the pointer. */
+ "r3 = *(u64 *)(r0 + 0);"
+ "r2 = %[fetch_dst_r0_readback] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r3;"
+ :
+ : __imm_addr(fetch_dst_r0_value),
+ __imm_insn(fetch_dst_r0_insn,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0)),
+ __imm_addr(fetch_dst_r0_result),
+ __imm_addr(fetch_dst_r0_readback)
+ : __clobber_all);
+#endif
+
+ return 0;
+}
+
__u64 __arena_global uaf_sink;
volatile __u64 __arena_global uaf_recovery_fails;
@@ -221,15 +273,24 @@ int uaf(const void *ctx)
{
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
+/*
+ * arm64 stays excluded as it has been since this test was added: its JIT only
+ * accepts arena RMW atomics when LSE is present, which is a run-time property.
+ * The rest of the file shares that dependency without a guard, so on a non-LSE
+ * arm64 the whole skeleton already fails to load.
+ *
+ * __BPF_FEATURE_ADDR_SPACE_CAST is required by the asm below, which spells
+ * addr_space_cast textually. That and the mnemonic both arrived in LLVM 19.
+ */
#if defined(ENABLE_ATOMICS_TESTS) && !defined(__TARGET_ARCH_arm64) && \
- !defined(__TARGET_ARCH_x86)
+ defined(__BPF_FEATURE_ADDR_SPACE_CAST)
__u32 __arena *page32;
__u64 __arena *page64;
void __arena *page;
page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
bpf_arena_free_pages(&arena, page, 1);
- uaf_recovery_fails = 24;
+ uaf_recovery_fails = 26;
page32 = (__u32 __arena *)page;
uaf_sink += __sync_fetch_and_add(page32, 1);
@@ -282,6 +343,34 @@ int uaf(const void *ctx)
uaf_recovery_fails -= 1;
uaf_sink += __sync_lock_test_and_set(page64, 1);
uaf_recovery_fails -= 1;
+
+ /*
+ * The x86 JIT needs RAX for the CMPXCHG loop it lowers a fetching
+ * AND/OR/XOR into, and substitutes BPF_REG_AX for r0 when r0 is either
+ * operand. Only then does the fault fixup have to name that register,
+ * so spell both forms out: clang picks its own and never produces them.
+ */
+ asm volatile (
+ "r0 = %[page];"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ "r1 = 1;"
+ ".8byte %[fetch_dst_r0];"
+ : : [page]"r"(page64),
+ __imm_insn(fetch_dst_r0,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0))
+ : "r0", "r1", "memory");
+ uaf_recovery_fails -= 1;
+
+ asm volatile (
+ "r1 = %[page];"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 1;"
+ ".8byte %[fetch_src_r0];"
+ : : [page]"r"(page64),
+ __imm_insn(fetch_src_r0,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0))
+ : "r0", "r1", "memory");
+ uaf_recovery_fails -= 1;
#endif
return 0;
|
| 3/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14634 output: 33 thoughts: 695 Thoughts: **Analyzing the BPF JIT Compiler Patch** Okay, let's break this down. First, I need to understand the scope of this patch. It looks like we're dealing with the x86 BPF JIT compiler, specifically `arch/x86/net/bpf_jit_comp.c`. The changes are concentrated there, with some supporting adjustments in `tools/sched_ext/` and the selftests. The diff itself tells the story. In `bpf_jit_comp.c`, we're seeing additions to the `reg2pt_regs[]` array, new functions like `is_atomic_fetch_op()`, `emit_atomic_fetch_rmw()`, and `emit_arena_exentry()`. This suggests modifications to how atomic operations within BPF programs are handled, particularly within the arena. The use of `emit_arena_exentry()` and the conditional calls to `emit_atomic_fetch_rmw()` in `do_jit()` are key. The updated `bpf_jit_supports_insn()` function now relaxes some restrictions related to arena atomic access, which could be important for performance or functionality, especially in the context of the selftests. The replacement of the `cmpxchg` loop in `scx/cid.bpf.h` with `__sync_fetch_and_or` and `__sync_fetch_and_and` strongly points to changes related to atomics and synchronization within BPF programs. The selftest changes further solidify that this patch is changing atomic operation handling within the arena. The fact that these selftests are modified tells me that we're talking about functionality that can be exercised and tested, meaning it's reachable and the patch's impact is real. Since this is the BPF JIT compiler in the x86 architecture, I can reach this using a standard QEMU setup through `bpf()` syscalls like `BPF_PROG_LOAD` and `BPF_PROG_TEST_RUN`. We're talking about core BPF functionality here. Given that this patch touches executable code within the BPF subsystem, which is a core subsystem, the "WorthFuzzing" flag should definitely be set to `true`. This warrants a deep dive into the configuration guards and dependencies related to `bpf_jit_comp.c`. Now, let's dig into the configurations and the compile dependencies to gain a precise understanding of the exposure of this logic. |
| 4/2 | 2026/09/27 11:06 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_comp",
"PathPrefix": "arch/x86/net"
}Results: {
"Output": "arch/x86/net/Makefile=6=ifeq ($(CONFIG_X86_32),y)\narch/x86/net/Makefile:7: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o\narch/x86/net/Makefile-8-else\narch/x86/net/Makefile:9: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o\narch/x86/net/Makefile-10-endif\n"
} |
| 5/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16047 output: 20 thoughts: 20 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Checking Kconfig for BPF Configuration** Alright, let's get down to brass tacks. I'm going to start by confirming the obvious: I need to ensure the core BPF features I'm interested in are actually enabled in the kernel configuration. Specifically, I'm thinking about `BPF_JIT` – the Just-In-Time compiler for BPF bytecode – and `BPF_SYSCALL`, which enables the BPF system call interface. These are fundamental, without them, I'm dead in the water before I even begin. I want to rule out a configuration issue immediately and make sure the kernel has the foundation for BPF functionality I intend to leverage. If these are disabled, I'll need to go back and address that first, likely by tweaking the kernel `.config` file and rebuilding. This is just a preliminary check, but a critical one. This is about ensuring the base functionality is present, before I start digging into the more complex stuff. |
| 6/2 | 2026/09/27 11:06 | tool | grepper |
0mArgs:{
"Expression": "config BPF_JIT"
}Results: {
"Output": "kernel/bpf/Kconfig=31=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-45-\nkernel/bpf/Kconfig:46:config BPF_JIT\nkernel/bpf/Kconfig-47-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-61-\nkernel/bpf/Kconfig:62:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-63-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-72-\nkernel/bpf/Kconfig:73:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-74-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n--\nkernel/bpf/Kconfig=105=config BPF_LSM\n--\nkernel/bpf/Kconfig-116-\nkernel/bpf/Kconfig:117:config BPF_JIT_KASAN\nkernel/bpf/Kconfig-118-\tbool\n"
} |
| 7/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16610 output: 34 thoughts: 31 Thoughts: Here's my take on those thoughts: **Analyzing BPF JIT Dependencies in the Kernel Configuration** Okay, let's dive into the kernel configuration to understand the dependencies of the BPF JIT compiler and the arena allocator. Specifically, I'm thinking about navigating to `kernel/bpf/Kconfig`, and focusing around line 46. I need to figure out what other configuration options need to be enabled before I can consider enabling `BPF_JIT` and the arena related features. This is critical for understanding the overall feature set that will be available when the kernel is configured. |
| 8/2 | 2026/09/27 11:06 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 30,
"LineCount": 50
}Results: {
"Contents": " 30:\t\n 31:\tconfig BPF_SYSCALL\n 32:\t\tbool \"Enable bpf() system call\"\n 33:\t\tselect BPF\n 34:\t\tselect IRQ_WORK\n 35:\t\tselect NEED_TASKS_RCU\n 36:\t\tselect TASKS_TRACE_RCU\n 37:\t\tselect BINARY_PRINTF\n 38:\t\tselect NET_SOCK_MSG if NET\n 39:\t\tselect NET_XGRESS if NET\n 40:\t\tselect PAGE_POOL if NET\n 41:\t\tdefault n\n 42:\t\thelp\n 43:\t\t Enable the bpf() system call that allows to manipulate BPF programs\n 44:\t\t and maps via file descriptors.\n 45:\t\n 46:\tconfig BPF_JIT\n 47:\t\tbool \"Enable BPF Just In Time compiler\"\n 48:\t\tdepends on BPF\n 49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n 50:\t\tselect EXECMEM\n 51:\t\thelp\n 52:\t\t BPF programs are normally handled by a BPF interpreter. This option\n 53:\t\t allows the kernel to generate native code when a program is loaded\n 54:\t\t into the kernel. This will significantly speed-up processing of BPF\n 55:\t\t programs.\n 56:\t\n 57:\t\t Note, an admin should enable this feature changing:\n 58:\t\t /proc/sys/net/core/bpf_jit_enable\n 59:\t\t /proc/sys/net/core/bpf_jit_harden (optional)\n 60:\t\t /proc/sys/net/core/bpf_jit_kallsyms (optional)\n 61:\t\n 62:\tconfig BPF_JIT_ALWAYS_ON\n 63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n 64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 65:\t\thelp\n 66:\t\t Enables BPF JIT and removes BPF interpreter to avoid speculative\n 67:\t\t execution of BPF instructions by the interpreter.\n 68:\t\n 69:\t\t When CONFIG_BPF_JIT_ALWAYS_ON is enabled, /proc/sys/net/core/bpf_jit_enable\n 70:\t\t is permanently set to 1 and setting any other value than that will\n 71:\t\t return failure.\n 72:\t\n 73:\tconfig BPF_JIT_DEFAULT_ON\n 74:\t\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n 75:\t\tdepends on HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 76:\t\n 77:\tconfig BPF_UNPRIV_DEFAULT_OFF\n 78:\t\tbool \"Disable unprivileged BPF by default\"\n 79:\t\tdefault y\n"
} |
| 9/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17562 output: 19 thoughts: 13 Thoughts: Here's a summary of my thought process: **Kconfig Configuration Exploration** Okay, so I'm thinking, beyond the immediate issue, it's always good practice to see if there's any relevant configuration options within the Kconfig system for "arena". Since I'm working with something that sounds like memory allocation, it's highly likely it could be governed by a Kconfig setting or two. This could allow for fine-tuning based on the build environment, target architecture, or specific project needs. Even if it seems straightforward now, understanding the potential for customization through Kconfig options is something that always pays off down the line. It's a quick check that might reveal some useful capabilities or prevent some headaches later. I need to make sure I am accounting for every possible variable. |
| 10/2 | 2026/09/27 11:06 | tool | grepper |
0mArgs:{
"Expression": "BPF_ARENA"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1048=static void build_epilogue(struct jit_ctx *ctx, bool was_classic)\n--\narch/arm64/net/bpf_jit_comp.c-1105-#define BPF_FIXUP_ARENA_REG_MASK GENMASK(20, 16)\narch/arm64/net/bpf_jit_comp.c:1106:#define BPF_ARENA_ACCESS BIT(21)\narch/arm64/net/bpf_jit_comp.c:1107:#define BPF_ARENA_WRITE BIT(22)\narch/arm64/net/bpf_jit_comp.c-1108-#define BPF_FIXUP_REG_MASK\tGENMASK(31, 27)\n--\narch/arm64/net/bpf_jit_comp.c=1111=bool ex_handler_bpf(const struct exception_table_entry *ex,\n--\narch/arm64/net/bpf_jit_comp.c-1116-\tint arena_reg = FIELD_GET(BPF_FIXUP_ARENA_REG_MASK, ex-\u003efixup);\narch/arm64/net/bpf_jit_comp.c:1117:\tbool is_arena = !!(ex-\u003efixup \u0026 BPF_ARENA_ACCESS);\narch/arm64/net/bpf_jit_comp.c:1118:\tbool is_write = !!(ex-\u003efixup \u0026 BPF_ARENA_WRITE);\narch/arm64/net/bpf_jit_comp.c-1119-\tunsigned long addr;\n--\narch/arm64/net/bpf_jit_comp.c=1135=static int add_exception_handler(const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1198-\tif (is_arena) {\narch/arm64/net/bpf_jit_comp.c:1199:\t\tex-\u003efixup |= BPF_ARENA_ACCESS;\narch/arm64/net/bpf_jit_comp.c-1200-\t\tif (is_write)\narch/arm64/net/bpf_jit_comp.c:1201:\t\t\tex-\u003efixup |= BPF_ARENA_WRITE;\narch/arm64/net/bpf_jit_comp.c-1202-\t\t/*\n--\ntools/sched_ext/include/scx/bpf_arena_common.bpf.h-16-\ntools/sched_ext/include/scx/bpf_arena_common.bpf.h:17:#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) \u0026\u0026 !defined(BPF_ARENA_FORCE_ASM)\ntools/sched_ext/include/scx/bpf_arena_common.bpf.h-18-#ifndef __arena\n--\ntools/testing/selftests/bpf/Makefile.buildvars=149=LIBARENA_ASAN_SKEL := libarena/libarena_asan.skel.h\ntools/testing/selftests/bpf/Makefile.buildvars:150:CFLAGS += -DHAS_BPF_ARENA_ASAN\ntools/testing/selftests/bpf/Makefile.buildvars-151-endif\n--\ntools/testing/selftests/bpf/libarena/Makefile=98=libarena_bench.bpf.o: $(LIBARENA_BENCH_OBJECTS)\n--\ntools/testing/selftests/bpf/libarena/Makefile-103-\t$(call msg,CLNG-BPF,libarena,$@)\ntools/testing/selftests/bpf/libarena/Makefile:104:\t$(Q)$(CLANG) $(BPF_CFLAGS) $(ASAN_FLAGS) -DBPF_ARENA_ASAN $(BPF_TARGET_ENDIAN) -c $\u003c -o $@\ntools/testing/selftests/bpf/libarena/Makefile-105-\n--\ntools/testing/selftests/bpf/libarena/include/bpf_arena_common.h-34-\ntools/testing/selftests/bpf/libarena/include/bpf_arena_common.h:35:#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) \u0026\u0026 !defined(BPF_ARENA_FORCE_ASM)\ntools/testing/selftests/bpf/libarena/include/bpf_arena_common.h-36-#define __arena __attribute__((address_space(1))) __attribute__((btf_type_tag(\"arena\")))\n--\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h-2-/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h:3:#ifndef BPF_ARENA_SPIN_LOCK_H\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h:4:#define BPF_ARENA_SPIN_LOCK_H\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h-5-\n--\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h=511=static __always_inline void arena_spin_unlock(arena_spinlock_t __arena *lock)\n--\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h-537-\ntools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h:538:#endif /* BPF_ARENA_SPIN_LOCK_H */\n--\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h=15=extern volatile bool asan_report_once;\n--\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-25-\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h:26:#ifdef BPF_ARENA_ASAN\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-27-\n--\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h=85=static void (*__asan_btf_anchors[])(intptr_t) = {\n--\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-91-\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h:92:#else /* BPF_ARENA_ASAN */\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-93-\n--\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h=97=__weak bool asan_ready(void) { return true; }\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-98-\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h:99:#endif /* BPF_ARENA_ASAN */\ntools/testing/selftests/bpf/libarena/include/libarena/asan.h-100-\n--\ntools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c=11=extern struct buddy __arena buddy;\ntools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c-12-\ntools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c:13:#ifdef BPF_ARENA_ASAN\ntools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c-14-\n--\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c=8=enum {\n--\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c-80-\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c:81:#ifdef BPF_ARENA_ASAN\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c-82-\n--\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c=468=__weak __noasan int asan_init(struct asan_init_args *args)\n--\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c-533-\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c:534:#endif /* BPF_ARENA_ASAN */\ntools/testing/selftests/bpf/libarena/src/asan.bpf.c-535-\n--\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-4-\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c:5:#ifdef HAS_BPF_ARENA_ASAN\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-6-#include \u003cunistd.h\u003e\n--\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c=37=static void run_test(void)\n--\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-81-\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c:82:#endif /* HAS_BPF_ARENA_ASAN */\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-83-\n--\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c=88=void serial_test_libarena_asan(void)\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-89-{\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c:90:#ifdef HAS_BPF_ARENA_ASAN\ntools/testing/selftests/bpf/prog_tests/libarena_asan.c-91-\trun_test();\n--\ntools/testing/selftests/bpf/progs/arena_htab.c=26=int arena_htab_llvm(void *ctx)\ntools/testing/selftests/bpf/progs/arena_htab.c-27-{\ntools/testing/selftests/bpf/progs/arena_htab.c:28:#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) || defined(BPF_ARENA_FORCE_ASM)\ntools/testing/selftests/bpf/progs/arena_htab.c-29-\tstruct htab __arena *htab;\n--\ntools/testing/selftests/bpf/progs/arena_htab_asm.c-2-/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */\ntools/testing/selftests/bpf/progs/arena_htab_asm.c:3:#define BPF_ARENA_FORCE_ASM\ntools/testing/selftests/bpf/progs/arena_htab_asm.c-4-#define arena_htab_llvm arena_htab_asm\n"
} |
| 11/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20692 output: 23 thoughts: 44 Thoughts: Okay, let's dive into this BPF arena implementation. I need to understand the details, so let's start with the basics. **Investigating the BPF Arena Implementation** My first instinct is to see if there's a specific configuration option associated with the BPF arena. I'll need to check the kernel's `Kconfig` files – that's where the build-time configuration options are defined. So, I'll `grep` through those files looking for something related to `BPF_MAP_TYPE_ARENA`. That should tell me if the arena feature is conditionally compiled. If it is, knowing the CONFIG option would be very useful, as I will know when the arena is enabled. If there isn't a dedicated `CONFIG` option, I'll widen the search and look for the arena usage itself, searching within the C source files for `BPF_MAP_TYPE_ARENA`. This should lead me to the core implementation. I will start there, and work through the details. I know this approach, combined with the documentation, will get me the full picture. |
| 12/2 | 2026/09/27 11:06 | tool | grepper |
0mArgs:{
"Expression": "BPF_MAP_TYPE_ARENA"
}Results: {
"Output": "include/linux/bpf_types.h=134=BPF_MAP_TYPE(BPF_MAP_TYPE_USER_RINGBUF, user_ringbuf_map_ops)\ninclude/linux/bpf_types.h:135:BPF_MAP_TYPE(BPF_MAP_TYPE_ARENA, arena_map_ops)\ninclude/linux/bpf_types.h-136-BPF_MAP_TYPE(BPF_MAP_TYPE_INSN_ARRAY, insn_array_map_ops)\n--\ninclude/uapi/linux/bpf.h=1000=enum bpf_map_type {\n--\ninclude/uapi/linux/bpf.h-1047-\tBPF_MAP_TYPE_CGRP_STORAGE,\ninclude/uapi/linux/bpf.h:1048:\tBPF_MAP_TYPE_ARENA,\ninclude/uapi/linux/bpf.h-1049-\tBPF_MAP_TYPE_INSN_ARRAY,\n--\ninclude/uapi/linux/bpf.h=1527=union bpf_attr {\n--\ninclude/uapi/linux/bpf.h-1554-\t\t *\ninclude/uapi/linux/bpf.h:1555:\t\t * BPF_MAP_TYPE_ARENA - contains the address where user space\ninclude/uapi/linux/bpf.h-1556-\t\t * is going to mmap() the arena. It has to be page aligned.\n--\nkernel/bpf/arena.c=86=u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena)\n--\nkernel/bpf/arena.c-92- * bpf_arena_map_kern_vm_start - kern_vm_start lookup by struct bpf_map *\nkernel/bpf/arena.c:93: * @map: a BPF_MAP_TYPE_ARENA map\nkernel/bpf/arena.c-94- *\n--\nkernel/bpf/arena.c=1092=__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1097-\nkernel/bpf/arena.c:1098:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1099-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1104=void *bpf_arena_alloc_pages_non_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1109-\nkernel/bpf/arena.c:1110:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1111-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1116=void *bpf_arena_alloc_pages_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1121-\nkernel/bpf/arena.c:1122:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1123-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1128=__bpf_kfunc void bpf_arena_free_pages(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1132-\nkernel/bpf/arena.c:1133:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)\nkernel/bpf/arena.c-1134-\t\treturn;\n--\nkernel/bpf/arena.c=1138=void bpf_arena_free_pages_non_sleepable(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1142-\nkernel/bpf/arena.c:1143:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)\nkernel/bpf/arena.c-1144-\t\treturn;\n--\nkernel/bpf/arena.c=1148=__bpf_kfunc int bpf_arena_reserve_pages(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1152-\nkernel/bpf/arena.c:1153:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA)\nkernel/bpf/arena.c-1154-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=250=static int bpf_map_update_value(struct bpf_map *map, struct file *map_file,\n--\nkernel/bpf/syscall.c-258-\t} else if (map-\u003emap_type == BPF_MAP_TYPE_CPUMAP ||\nkernel/bpf/syscall.c:259:\t\t map-\u003emap_type == BPF_MAP_TYPE_ARENA ||\nkernel/bpf/syscall.c-260-\t\t map-\u003emap_type == BPF_MAP_TYPE_STRUCT_OPS) {\n--\nkernel/bpf/syscall.c=1394=static int map_create_alloc(union bpf_attr *attr, bpfptr_t uattr, struct bpf_verifier_log *log,\n--\nkernel/bpf/syscall.c-1431-\tif (attr-\u003emap_type != BPF_MAP_TYPE_BLOOM_FILTER \u0026\u0026\nkernel/bpf/syscall.c:1432:\t attr-\u003emap_type != BPF_MAP_TYPE_ARENA \u0026\u0026\nkernel/bpf/syscall.c-1433-\t attr-\u003emap_type != BPF_MAP_TYPE_RHASH \u0026\u0026\n--\nkernel/bpf/syscall.c-1527-\tcase BPF_MAP_TYPE_CPUMAP:\nkernel/bpf/syscall.c:1528:\tcase BPF_MAP_TYPE_ARENA:\nkernel/bpf/syscall.c-1529-\tcase BPF_MAP_TYPE_INSN_ARRAY:\n--\nkernel/bpf/verifier.c=18226=static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-18310-\t insn-\u003esrc_reg == BPF_PSEUDO_MAP_IDX_VALUE) {\nkernel/bpf/verifier.c:18311:\t\tif (map-\u003emap_type == BPF_MAP_TYPE_ARENA) {\nkernel/bpf/verifier.c-18312-\t\t\t__mark_reg_unknown(env, dst_reg);\n--\nkernel/bpf/verifier.c=19858=static int check_map_prog_compatibility(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19923-\t\tcase BPF_MAP_TYPE_STACK:\nkernel/bpf/verifier.c:19924:\t\tcase BPF_MAP_TYPE_ARENA:\nkernel/bpf/verifier.c-19925-\t\tcase BPF_MAP_TYPE_INSN_ARRAY:\n--\nkernel/bpf/verifier.c-19939-\nkernel/bpf/verifier.c:19940:\tif (map-\u003emap_type == BPF_MAP_TYPE_ARENA) {\nkernel/bpf/verifier.c-19941-\t\tif (env-\u003eprog-\u003eaux-\u003earena) {\n--\ntools/bpf/bpftool/gen.c=263=static bool is_skel_data(const struct bpf_map *map, char *buf, size_t sz)\n--\ntools/bpf/bpftool/gen.c-266-\ntools/bpf/bpftool/gen.c:267:\tif (bpf_map__type(map) == BPF_MAP_TYPE_ARENA \u0026\u0026 bpf_map__initial_value(map, \u0026tmp_sz)) {\ntools/bpf/bpftool/gen.c-268-\t\tsnprintf(buf, sz, \"arena\");\n--\ntools/include/uapi/linux/bpf.h=1000=enum bpf_map_type {\n--\ntools/include/uapi/linux/bpf.h-1047-\tBPF_MAP_TYPE_CGRP_STORAGE,\ntools/include/uapi/linux/bpf.h:1048:\tBPF_MAP_TYPE_ARENA,\ntools/include/uapi/linux/bpf.h-1049-\tBPF_MAP_TYPE_INSN_ARRAY,\n--\ntools/include/uapi/linux/bpf.h=1527=union bpf_attr {\n--\ntools/include/uapi/linux/bpf.h-1554-\t\t *\ntools/include/uapi/linux/bpf.h:1555:\t\t * BPF_MAP_TYPE_ARENA - contains the address where user space\ntools/include/uapi/linux/bpf.h-1556-\t\t * is going to mmap() the arena. It has to be page aligned.\n--\ntools/lib/bpf/libbpf.c=163=static const char * const map_type_name[] = {\n--\ntools/lib/bpf/libbpf.c-196-\t[BPF_MAP_TYPE_CGRP_STORAGE]\t\t= \"cgrp_storage\",\ntools/lib/bpf/libbpf.c:197:\t[BPF_MAP_TYPE_ARENA]\t\t\t= \"arena\",\ntools/lib/bpf/libbpf.c-198-\t[BPF_MAP_TYPE_INSN_ARRAY]\t\t= \"insn_array\",\n--\ntools/lib/bpf/libbpf.c=1884=static size_t bpf_map_mmap_sz(const struct bpf_map *map)\n--\ntools/lib/bpf/libbpf.c-1891-\t\treturn array_map_mmap_sz(map-\u003edef.value_size, map-\u003edef.max_entries);\ntools/lib/bpf/libbpf.c:1892:\tcase BPF_MAP_TYPE_ARENA:\ntools/lib/bpf/libbpf.c-1893-\t\treturn page_sz * map-\u003edef.max_entries;\n--\ntools/lib/bpf/libbpf.c=3084=static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,\n--\ntools/lib/bpf/libbpf.c-3135-\ntools/lib/bpf/libbpf.c:3136:\t\tif (map-\u003edef.type != BPF_MAP_TYPE_ARENA)\ntools/lib/bpf/libbpf.c-3137-\t\t\tcontinue;\n--\ntools/lib/bpf/libbpf.c=5458=static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, bool is_inner)\n--\ntools/lib/bpf/libbpf.c-5527-\tcase BPF_MAP_TYPE_STACK:\ntools/lib/bpf/libbpf.c:5528:\tcase BPF_MAP_TYPE_ARENA:\ntools/lib/bpf/libbpf.c-5529-\t\tcreate_attr.btf_fd = 0;\n--\ntools/lib/bpf/libbpf.c=5700=bpf_object__create_maps(struct bpf_object *obj)\n--\ntools/lib/bpf/libbpf.c-5774-\t\t\t\t\tgoto err_out;\ntools/lib/bpf/libbpf.c:5775:\t\t\t} else if (map-\u003edef.type == BPF_MAP_TYPE_ARENA) {\ntools/lib/bpf/libbpf.c-5776-\t\t\t\tmap-\u003emmaped = mmap((void *)(long)map-\u003emap_extra,\n--\ntools/lib/bpf/libbpf.c=11599=int bpf_map__set_initial_value(struct bpf_map *map,\n--\ntools/lib/bpf/libbpf.c-11609-\ntools/lib/bpf/libbpf.c:11610:\tif (map-\u003edef.type == BPF_MAP_TYPE_ARENA)\ntools/lib/bpf/libbpf.c-11611-\t\tactual_sz = map-\u003eobj-\u003earena_data_sz;\n--\ntools/lib/bpf/libbpf.c=11621=void *bpf_map__initial_value(const struct bpf_map *map, size_t *psize)\n--\ntools/lib/bpf/libbpf.c-11631-\ntools/lib/bpf/libbpf.c:11632:\tif (map-\u003edef.type == BPF_MAP_TYPE_ARENA)\ntools/lib/bpf/libbpf.c-11633-\t\t*psize = map-\u003eobj-\u003earena_data_sz;\n--\ntools/lib/bpf/libbpf.c=15675=int bpf_object__load_skeleton(struct bpf_object_skeleton *s)\n--\ntools/lib/bpf/libbpf.c-15691-\ntools/lib/bpf/libbpf.c:15692:\t\tif (map-\u003edef.type == BPF_MAP_TYPE_ARENA)\ntools/lib/bpf/libbpf.c-15693-\t\t\t*map_skel-\u003emmaped = map-\u003emmaped + map-\u003eobj-\u003earena_data_off;\n--\ntools/lib/bpf/libbpf_probes.c=295=static int probe_map_create(enum bpf_map_type map_type)\n--\ntools/lib/bpf/libbpf_probes.c-356-\t\tbreak;\ntools/lib/bpf/libbpf_probes.c:357:\tcase BPF_MAP_TYPE_ARENA:\ntools/lib/bpf/libbpf_probes.c-358-\t\tkey_size\t= 0;\n--\ntools/sched_ext/scx_qmap.bpf.c=94=struct {\ntools/sched_ext/scx_qmap.bpf.c:95:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/sched_ext/scx_qmap.bpf.c-96-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/sched_ext/scx_sdt.bpf.c=26=struct {\ntools/sched_ext/scx_sdt.bpf.c:27:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/sched_ext/scx_sdt.bpf.c-28-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/libarena/include/libarena/common.h=29=struct {\ntools/testing/selftests/bpf/libarena/include/libarena/common.h:30:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/libarena/include/libarena/common.h-31-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/prog_tests/arena_direct_value.c=13=static void test_arena_direct_value_one_past_end(void)\n--\ntools/testing/selftests/bpf/prog_tests/arena_direct_value.c-31-\ntools/testing/selftests/bpf/prog_tests/arena_direct_value.c:32:\tmap_fd = bpf_map_create(BPF_MAP_TYPE_ARENA, \"arena_direct_value\",\ntools/testing/selftests/bpf/prog_tests/arena_direct_value.c-33-\t\t\t\t0, 0, ARENA_PAGES, \u0026map_opts);\n--\ntools/testing/selftests/bpf/progs/aggregate_ret_kfunc_arena.c=11=struct {\ntools/testing/selftests/bpf/progs/aggregate_ret_kfunc_arena.c:12:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/aggregate_ret_kfunc_arena.c-13-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_atomics.c=12=struct {\ntools/testing/selftests/bpf/progs/arena_atomics.c:13:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_atomics.c-14-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_htab.c=10=struct {\ntools/testing/selftests/bpf/progs/arena_htab.c:11:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_htab.c-12-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_kfunc.c=12=struct {\ntools/testing/selftests/bpf/progs/arena_kfunc.c:13:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_kfunc.c-14-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_kfunc_jit.c=17=struct {\ntools/testing/selftests/bpf/progs/arena_kfunc_jit.c:18:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_kfunc_jit.c-19-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_list.c=10=struct {\ntools/testing/selftests/bpf/progs/arena_list.c:11:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_list.c-12-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_mem_usage.c=7=struct {\ntools/testing/selftests/bpf/progs/arena_mem_usage.c:8:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_mem_usage.c-9-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_memcg.c=7=struct {\ntools/testing/selftests/bpf/progs/arena_memcg.c:8:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_memcg.c-9-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_spin_lock.c=10=struct {\ntools/testing/selftests/bpf/progs/arena_spin_lock.c:11:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_spin_lock.c-12-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/arena_strsearch.c=6=struct {\ntools/testing/selftests/bpf/progs/arena_strsearch.c:7:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/arena_strsearch.c-8-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/compute_live_registers.c=16=struct {\ntools/testing/selftests/bpf/progs/compute_live_registers.c:17:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/compute_live_registers.c-18-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/stream.c=21=struct {\ntools/testing/selftests/bpf/progs/stream.c:22:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/stream.c-23-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/struct_ops_arena.c=14=struct {\ntools/testing/selftests/bpf/progs/struct_ops_arena.c:15:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/struct_ops_arena.c-16-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_arena.c=21=struct {\ntools/testing/selftests/bpf/progs/verifier_arena.c:22:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_arena.c-23-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_arena_globals1.c=15=struct {\ntools/testing/selftests/bpf/progs/verifier_arena_globals1.c:16:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_arena_globals1.c-17-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_arena_globals2.c=14=struct {\ntools/testing/selftests/bpf/progs/verifier_arena_globals2.c:15:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_arena_globals2.c-16-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_arena_large.c=14=struct {\ntools/testing/selftests/bpf/progs/verifier_arena_large.c:15:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_arena_large.c-16-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_ldsx.c=262=struct {\ntools/testing/selftests/bpf/progs/verifier_ldsx.c:263:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_ldsx.c-264-\t__uint(map_flags, BPF_F_MMAPABLE);\n--\ntools/testing/selftests/bpf/progs/verifier_zext.c=10=struct {\ntools/testing/selftests/bpf/progs/verifier_zext.c:11:\t__uint(type, BPF_MAP_TYPE_ARENA);\ntools/testing/selftests/bpf/progs/verifier_zext.c-12-\t__uint(map_flags, BPF_F_MMAPABLE | BPF_F_NO_USER_CONV);\n"
} |
| 13/2 | 2026/09/27 11:06 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27376 output: 27 thoughts: 26 Thoughts: Here's my thought process, as if I were considering this myself: **Investigating the Compilation of `kernel/bpf/arena.c`** Alright, let's figure out where this `kernel/bpf/arena.c` file is getting compiled within the Linux kernel build system. My immediate instinct is to check the `kernel/bpf/Makefile` – that's the obvious place to start. This is a common pattern, and usually, the Makefile in a directory will handle the compilation of the sources within that same directory. I’d expect to find either a direct inclusion of `arena.c` in a variable defining objects or perhaps it might be included indirectly through some build flags or a more complex build structure defined within. Let’s dive in there and see what’s going on. I need to understand how this specific BPF-related source file fits into the larger picture of the kernel compilation. |
| 14/2 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "arena\\.o",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/Makefile=19=ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\nkernel/bpf/Makefile:20:obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o\nkernel/bpf/Makefile-21-endif\n"
} |
| 15/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27707 output: 40 thoughts: 456 Thoughts: **Analyzing BPF JIT Compilation Dependencies** Okay, so I'm digging into this `arena.o` module. I see it's dependent on `CONFIG_BPF_SYSCALL`, and of course `CONFIG_MMU` and `CONFIG_64BIT`, which is expected. Then I see `arch/x86/net/bpf_jit_comp.c` depends on `CONFIG_BPF_JIT`. I should double-check, but I believe the JIT compilation is key here. Let's check the `arch/x86/net/Makefile` to confirm the relationship between the architecture and `CONFIG_BPF_JIT`. Ah, there it is: on x86-64, it correctly builds `bpf_jit_comp.o` when `CONFIG_BPF_JIT` is enabled. Perfect. And, as expected, `CONFIG_BPF_SYSCALL` is essential for basically any BPF operation that requires interaction with the kernel – loading programs, creating maps (like this `arena` map we're looking at), running the verifier, you name it. Now, I wonder if there are any other relevant configs, like `CONFIG_BPF_JIT_ALWAYS_ON` or `CONFIG_BPF_JIT_DEFAULT_ON`, which might affect its behavior. But for now, I'm fairly certain the core drivers are `BPF_JIT` and `BPF_SYSCALL`. Let's quickly review the symbols modified within `arch/x86/net/bpf_jit_comp.c`: I see a few static ones: `is_atomic_fetch_op`, `emit_atomic_fetch_rmw`, `emit_arena_exentry`, and `do_jit`. Then there is a non-static symbol, the function `bpf_jit_supports_insn`. And it's important to keep track of this one, as well as checking the callers of `do_jit` in that file. That'll provide insight into how the JIT compilation process is actually triggered. |
| 16/2 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "do_jit\\(",
"PathPrefix": "arch/x86/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=1701=static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,\n--\narch/x86/net/bpf_jit_comp.c-1775- * of a fetching AND/OR/XOR. A sequence long enough to overflow this\narch/x86/net/bpf_jit_comp.c:1776: * field would first have to exceed BPF_MAX_INSN_SIZE, which do_jit()\narch/x86/net/bpf_jit_comp.c-1777- * rejects with -EFAULT before the image is used.\n--\narch/x86/net/bpf_jit_comp.c=2083=static int emit_kfunc_arena_args(struct bpf_prog *bpf_prog,\n--\narch/x86/net/bpf_jit_comp.c-2121-\narch/x86/net/bpf_jit_comp.c:2122:static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\narch/x86/net/bpf_jit_comp.c-2123-\t\t u8 *rw_image, int oldproglen, struct jit_context *ctx, bool jmp_padding)\n--\narch/x86/net/bpf_jit_comp.c=4389=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\narch/x86/net/bpf_jit_comp.c-4466-\t\t\tpadding = true;\narch/x86/net/bpf_jit_comp.c:4467:\t\tproglen = do_jit(env, prog, addrs, image, rw_image, oldproglen,\narch/x86/net/bpf_jit_comp.c-4468-\t\t\t\t \u0026ctx, padding);\n"
} |
| 17/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29205 output: 23 thoughts: 226 Thoughts: **Analyzing the BPF JIT Compiler Function** Okay, so I'm diving into `arch/x86/net/bpf_jit_comp.c` to understand the x86 BPF JIT compiler. The function I'm primarily interested in is `bpf_int_jit_compile()`. That's the main, non-static JIT function, right? Hold on a second, I need to double-check something. Is `do_jit` static? Let me just quickly confirm by looking at its definition: `static int do_jit(...)`. Yep, it's static. Now the next question is if `do_jit` gets inlined or remains a separate symbol in `vmlinux`. Knowing the compiler's behavior from past experience, and glancing at the codebase... it's huge, over 2000 lines. GCC and Clang definitely won't inline that monster! So even if it *could* be inlined from a technical perspective, it's virtually impossible given its size. `bpf_int_jit_compile` remains the external interface function. It's the one exported and called from the BPF core. I'm going to note this. I'll also keep in mind that I have to check on `bpf_jit_supports_insn`. I should look at where it's defined and how it's called. This could reveal important hints about instruction set support or feature detection within the JIT compiler. |
| 18/2 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_insn"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=3411=bool bpf_jit_supports_arena(void)\n--\narch/arm64/net/bpf_jit_comp.c-3415-\narch/arm64/net/bpf_jit_comp.c:3416:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\narch/arm64/net/bpf_jit_comp.c-3417-{\n--\narch/powerpc/net/bpf_jit_comp.c=551=bool bpf_jit_supports_far_kfunc_call(void)\n--\narch/powerpc/net/bpf_jit_comp.c-555-\narch/powerpc/net/bpf_jit_comp.c:556:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\narch/powerpc/net/bpf_jit_comp.c-557-{\n--\narch/riscv/net/bpf_jit_comp64.c=2197=bool bpf_jit_supports_arena(void)\n--\narch/riscv/net/bpf_jit_comp64.c-2209-\narch/riscv/net/bpf_jit_comp64.c:2210:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\narch/riscv/net/bpf_jit_comp64.c-2211-{\n--\narch/s390/net/bpf_jit_comp.c=3071=bool bpf_jit_supports_fsession(void)\n--\narch/s390/net/bpf_jit_comp.c-3075-\narch/s390/net/bpf_jit_comp.c:3076:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\narch/s390/net/bpf_jit_comp.c-3077-{\n--\narch/x86/net/bpf_jit_comp.c=4759=bool bpf_jit_supports_arena(void)\n--\narch/x86/net/bpf_jit_comp.c-4763-\narch/x86/net/bpf_jit_comp.c:4764:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\narch/x86/net/bpf_jit_comp.c-4765-{\n--\ninclude/linux/filter.h=1252=bool bpf_jit_supports_arena(void);\ninclude/linux/filter.h:1253:bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena);\ninclude/linux/filter.h-1254-bool bpf_jit_supports_private_stack(void);\n--\nkernel/bpf/core.c=3429=bool __weak bpf_jit_supports_arena(void)\n--\nkernel/bpf/core.c-3433-\nkernel/bpf/core.c:3434:bool __weak bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)\nkernel/bpf/core.c-3435-{\n--\nkernel/bpf/fixups.c=864=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1055-\t\t\tif (BPF_MODE(insn-\u003ecode) == BPF_MEMSX) {\nkernel/bpf/fixups.c:1056:\t\t\t\tif (!bpf_jit_supports_insn(insn, true)) {\nkernel/bpf/fixups.c-1057-\t\t\t\t\tverbose(env, \"sign extending loads from arena are not supported yet\\n\");\n--\nkernel/bpf/verifier.c=5253=static bool atomic_ptr_type_ok(struct bpf_verifier_env *env, int regno,\n--\nkernel/bpf/verifier.c-5264-\tif (is_arena_reg(env, regno))\nkernel/bpf/verifier.c:5265:\t\treturn bpf_jit_supports_insn(insn, true);\nkernel/bpf/verifier.c-5266-\tif (is_load_acq_unsafe(env, regno, insn))\n"
} |
| 19/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30946 output: 45 thoughts: 450 Thoughts: **My Analysis of the BPF JIT Atomic Operation Changes** Okay, so I'm looking at this recent patch concerning atomic operations within the BPF JIT compiler, specifically how it handles arena-based atomic operations. I see that the `bpf_jit_supports_insn` function, called by `atomic_ptr_type_ok` during verification, has been changed. Previously, it had some restrictions for arena operations, specifically disallowing `AND`, `OR`, and `XOR` with `FETCH` for certain atomic instructions. Now, it seems to unconditionally return `true` for all arena instructions. That's the first significant thing. Digging further, I see the meat of the change is in `do_jit()`. The code is now handling `is_atomic_fetch_op(insn)` correctly. Previously, it was just doing regular atomic fetch instructions (`BPF_STX | BPF_ATOMIC | BPF_W`/`DW`) that were lowered to `emit_atomic_fetch_rmw`. That part seems unchanged. But *now* it also supports `BPF_STX | BPF_PROBE_ATOMIC | BPF_W`/`DW` which are arena atomic fetch operations! This is the exciting part! The JIT compiler is generating a `CMPXCHG` loop using that same `emit_atomic_fetch_rmw` function. The arena base register, `R12`, is used as the `index_reg`. This makes sense for accessing the arena memory. And, crucially, it's creating an exception table entry via `emit_arena_exentry` to handle potential faults. Thinking about this, I need to know how these faults are handled, so I'm looking into the runtime behavior. If an arena atomic fetch faults, it's the `ex_handler_bpf` function that gets invoked. I'll need to go look into `arch/x86/net/bpf_jit_comp.c` to understand exactly how this exception handling is implemented. This is going to be key to evaluating the overall robustness and performance characteristics of this new arena atomic support. It's good to see that they've considered the failure cases and are making the system resilient. |
| 20/2 | 2026/09/27 11:07 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 1780,
"LineCount": 55
}Results: {
"Contents": "1780:\t * - ARENA_REG (8 bits): Offset of the register that is used to calculate the\n1781:\t * address for load/store when accessing the arena region.\n1782:\t * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.\n1783:\t * It is independent of DST_REG, since a read-modify-write both writes to\n1784:\t * memory and reads the old value into a register.\n1785:\t * - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.\n1786:\t *\n1787:\t * Bit layout of `data` (32-bit):\n1788:\t *\n1789:\t * +--------------+--------+--------------+\n1790:\t * |\t31-16\t | 15-8 | 7-0 |\n1791:\t * | |\t | |\n1792:\t * | ARENA_OFFSET | Unused | EX_TYPE_BPF |\n1793:\t * +--------------+--------+--------------+\n1794:\t *\n1795:\t * - ARENA_OFFSET (16 bits): Offset used to calculate the address for load/store when\n1796:\t * accessing the arena region.\n1797:\t */\n1798:\t\n1799:\t#define DONT_CLEAR 1\n1800:\t#define FIXUP_INSN_LEN_MASK\tGENMASK(7, 0)\n1801:\t#define FIXUP_REG_MASK\t\tGENMASK(15, 8)\n1802:\t#define FIXUP_ARENA_REG_MASK\tGENMASK(23, 16)\n1803:\t#define FIXUP_ARENA_WRITE\tBIT(30)\n1804:\t#define FIXUP_ARENA_ACCESS\tBIT(31)\n1805:\t#define DATA_ARENA_OFFSET_MASK\tGENMASK(31, 16)\n1806:\t\n1807:\tbool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\n1808:\t{\n1809:\t\tu32 reg = FIELD_GET(FIXUP_REG_MASK, x-\u003efixup);\n1810:\t\tu32 insn_len = FIELD_GET(FIXUP_INSN_LEN_MASK, x-\u003efixup);\n1811:\t\tbool is_arena = !!(x-\u003efixup \u0026 FIXUP_ARENA_ACCESS);\n1812:\t\tbool is_write = !!(x-\u003efixup \u0026 FIXUP_ARENA_WRITE);\n1813:\t\tunsigned long addr;\n1814:\t\ts16 off;\n1815:\t\tu32 arena_reg;\n1816:\t\n1817:\t\tif (is_arena) {\n1818:\t\t\tarena_reg = FIELD_GET(FIXUP_ARENA_REG_MASK, x-\u003efixup);\n1819:\t\t\toff = FIELD_GET(DATA_ARENA_OFFSET_MASK, x-\u003edata);\n1820:\t\t\taddr = *(unsigned long *)((void *)regs + arena_reg) + off;\n1821:\t\t\tbpf_prog_report_arena_violation(is_write, addr, regs-\u003eip);\n1822:\t\t}\n1823:\t\n1824:\t\t/* jump over faulting load and clear dest register */\n1825:\t\tif (reg != DONT_CLEAR)\n1826:\t\t\t*(unsigned long *)((void *)regs + reg) = 0;\n1827:\t\tregs-\u003eip += insn_len;\n1828:\t\n1829:\t\treturn true;\n1830:\t}\n1831:\t\n1832:\t/*\n1833:\t * Record an arena access that may fault. @fault_ip is the address of the\n1834:\t * faulting insn in the RO image, @resume_off how far past it execution has to\n"
} |
| 21/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32978 output: 20 thoughts: 1540 Thoughts: **Analyzing the BPF CMPXCHG Fault Handling and Identifying FocusSymbols** Okay, let's break this down. First, I see that this patch doesn't touch `ex_handler_bpf` directly, but it does update `reg2pt_regs`. Specifically, `BPF_REG_AX` is now mapped to `offsetof(struct pt_regs, r10)`, which is effectively r10 in the `pt_regs` structure. This is crucial because `reg2pt_regs` is indexed by `real_src_reg` and `real_dst_reg` in functions like `emit_arena_exentry`. Now, when a fault happens within the CMPXCHG loop, `ex_handler_bpf` gets called. It uses the `fixup` value to identify the register and zero it out. If `real_src_reg` was `BPF_REG_AX`, then it's effectively zeroing `r10`. The CMPXCHG logic in `emit_atomic_fetch_rmw` is interesting. The "resume" point (where execution jumps back if a fault occurs) is *before* `emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);`. This means that if a fault hits during the CMPXCHG, it restores R0 from RAX (which was earlier saved in BPF_REG_AX / r10), and also clears `src_reg` if necessary. So, the critical part is understanding what gets saved, what gets restored, and where the fault handler kicks in. Now, to identify the `FocusSymbols`, let's list the functions involved: * `bpf_int_jit_compile`: Entrypoint for BPF JIT compilation. * `do_jit`: Core JIT compilation logic. * `emit_atomic_fetch_rmw`: Implements atomic fetch-modify-write lowering. * `emit_arena_exentry`: Records arena exception table entries. * `bpf_jit_supports_insn`: Checks if an instruction is supported. * `ex_handler_bpf`: Exception handler for arena faults. Let's think carefully about the selection, in light of guideline 4. The static functions might not have distinct symbol addresses, but the non-static ones can be directly targeted. * `bpf_int_jit_compile`: This seems specific; it's the entry point. * `do_jit`: This also is specific and related to the x86 JIT compilation. * `emit_atomic_fetch_rmw`: *This is new logic*. It's crucial for the CMPXCHG. * `emit_arena_exentry`: This is also new logic, crucial for exception handling. * `bpf_jit_supports_insn`: This is helpful, as it defines supported BPF instructions. * `ex_handler_bpf`: This is *the* exception handler. Can we include all of them? `bpf_int_jit_compile` and `ex_handler_bpf` are specific entrypoints and error handling. `emit_atomic_fetch_rmw` and `emit_arena_exentry` are specific to new atomic fetch lowering and handling exceptions. `do_jit` is x86 specific. We need to make sure `ex_handler_bpf` only handles BPF faults, not *all* faults. Let's check who calls it. |
| 22/2 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "ex_handler_bpf"
}Results: {
"Output": "arch/arm64/include/asm/extable.h=36=bool insn_may_access_user(unsigned long addr, unsigned long esr);\n--\narch/arm64/include/asm/extable.h-38-#ifdef CONFIG_BPF_JIT\narch/arm64/include/asm/extable.h:39:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/arm64/include/asm/extable.h-40-\t\t struct pt_regs *regs);\n--\narch/arm64/include/asm/extable.h=42=static inline\narch/arm64/include/asm/extable.h:43:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/arm64/include/asm/extable.h-44-\t\t struct pt_regs *regs)\n--\narch/arm64/mm/extable.c=95=bool fixup_exception(struct pt_regs *regs, unsigned long esr)\n--\narch/arm64/mm/extable.c-104-\tcase EX_TYPE_BPF:\narch/arm64/mm/extable.c:105:\t\treturn ex_handler_bpf(ex, regs);\narch/arm64/mm/extable.c-106-\tcase EX_TYPE_UACCESS_ERR_ZERO:\n--\narch/arm64/net/bpf_jit_comp.c=1048=static void build_epilogue(struct jit_ctx *ctx, bool was_classic)\n--\narch/arm64/net/bpf_jit_comp.c-1110-\narch/arm64/net/bpf_jit_comp.c:1111:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/arm64/net/bpf_jit_comp.c-1112-\t\t struct pt_regs *regs)\n--\narch/arm64/net/bpf_jit_comp.c=1135=static int add_exception_handler(const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1207-\t\t * memory access. Pass the reg holding the unmodified 32-bit address to\narch/arm64/net/bpf_jit_comp.c:1208:\t\t * ex_handler_bpf.\narch/arm64/net/bpf_jit_comp.c-1209-\t\t */\n--\narch/loongarch/include/asm/extable.h=26=do {\t\t\t\t\t\t\t\\\n--\narch/loongarch/include/asm/extable.h-35-#ifdef CONFIG_BPF_JIT\narch/loongarch/include/asm/extable.h:36:bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs);\narch/loongarch/include/asm/extable.h-37-#else\narch/loongarch/include/asm/extable.h=38=static inline\narch/loongarch/include/asm/extable.h:39:bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs)\narch/loongarch/include/asm/extable.h-40-{\n--\narch/loongarch/mm/extable.c=45=bool fixup_exception(struct pt_regs *regs)\n--\narch/loongarch/mm/extable.c-58-\tcase EX_TYPE_BPF:\narch/loongarch/mm/extable.c:59:\t\treturn ex_handler_bpf(ex, regs);\narch/loongarch/mm/extable.c-60-\t}\n--\narch/loongarch/net/bpf_jit.c=608=static bool is_signed_bpf_cond(u8 cond)\n--\narch/loongarch/net/bpf_jit.c-617-\narch/loongarch/net/bpf_jit.c:618:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/loongarch/net/bpf_jit.c-619-\t\t struct pt_regs *regs)\n--\narch/riscv/include/asm/extable.h=38=static inline bool fixup_exception(struct pt_regs *regs) { return false; }\n--\narch/riscv/include/asm/extable.h-41-#if defined(CONFIG_BPF_JIT) \u0026\u0026 defined(CONFIG_ARCH_RV64I)\narch/riscv/include/asm/extable.h:42:bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs);\narch/riscv/include/asm/extable.h-43-#else\narch/riscv/include/asm/extable.h=44=static inline bool\narch/riscv/include/asm/extable.h:45:ex_handler_bpf(const struct exception_table_entry *ex,\narch/riscv/include/asm/extable.h-46-\t struct pt_regs *regs)\n--\narch/riscv/mm/extable.c=82=bool fixup_exception(struct pt_regs *regs)\n--\narch/riscv/mm/extable.c-93-\tcase EX_TYPE_BPF:\narch/riscv/mm/extable.c:94:\t\treturn ex_handler_bpf(ex, regs);\narch/riscv/mm/extable.c-95-\tcase EX_TYPE_UACCESS_ERR_ZERO:\n--\narch/riscv/net/bpf_jit_comp64.c=723=static int sign_extend(u8 rd, u8 rs, u8 sz, bool sign, struct rv_jit_context *ctx)\n--\narch/riscv/net/bpf_jit_comp64.c-756-\narch/riscv/net/bpf_jit_comp64.c:757:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/riscv/net/bpf_jit_comp64.c-758-\t\t struct pt_regs *regs)\n--\narch/s390/include/asm/extable.h=43=static inline void swap_ex_entry_fixup(struct exception_table_entry *a,\n--\narch/s390/include/asm/extable.h-58-\narch/s390/include/asm/extable.h:59:bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs);\narch/s390/include/asm/extable.h-60-\n--\narch/s390/include/asm/extable.h-62-\narch/s390/include/asm/extable.h:63:static inline bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs)\narch/s390/include/asm/extable.h-64-{\n--\narch/s390/mm/extable.c=119=bool fixup_exception(struct pt_regs *regs)\n--\narch/s390/mm/extable.c-129-\tcase EX_TYPE_BPF:\narch/s390/mm/extable.c:130:\t\treturn ex_handler_bpf(ex, regs);\narch/s390/mm/extable.c-131-\tcase EX_TYPE_UA_FAULT:\n--\narch/s390/net/bpf_jit_comp.c=696=static void bpf_jit_epilogue(struct bpf_jit *jit)\n--\narch/s390/net/bpf_jit_comp.c-712-\narch/s390/net/bpf_jit_comp.c:713:bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\narch/s390/net/bpf_jit_comp.c-714-{\n--\narch/s390/net/bpf_jit_comp.c=814=static int bpf_jit_probe_post(struct bpf_jit *jit, struct bpf_prog *fp,\n--\narch/s390/net/bpf_jit_comp.c-847-\t\t * infrastructure ignores the fixup field; it is handled by\narch/s390/net/bpf_jit_comp.c:848:\t\t * ex_handler_bpf().\narch/s390/net/bpf_jit_comp.c-849-\t\t */\n--\narch/x86/include/asm/extable.h=46=static inline void __noreturn ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr)\n--\narch/x86/include/asm/extable.h-53-#if defined(CONFIG_BPF_JIT) \u0026\u0026 defined(CONFIG_X86_64)\narch/x86/include/asm/extable.h:54:bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs);\narch/x86/include/asm/extable.h-55-#else\narch/x86/include/asm/extable.h:56:static inline bool ex_handler_bpf(const struct exception_table_entry *x,\narch/x86/include/asm/extable.h-57-\t\t\t\t struct pt_regs *regs) { return false; }\n--\narch/x86/mm/extable.c=299=int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code,\n--\narch/x86/mm/extable.c-340-\tcase EX_TYPE_BPF:\narch/x86/mm/extable.c:341:\t\treturn ex_handler_bpf(e, regs);\narch/x86/mm/extable.c-342-\tcase EX_TYPE_WRMSR:\n--\narch/x86/net/bpf_jit_comp.c=1701=static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,\n--\narch/x86/net/bpf_jit_comp.c-1806-\narch/x86/net/bpf_jit_comp.c:1807:bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\narch/x86/net/bpf_jit_comp.c-1808-{\n--\narch/x86/net/bpf_jit_comp.c=2122=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-2756-\t\t\t\t * the reg holding the unmodified 32-bit address to\narch/x86/net/bpf_jit_comp.c:2757:\t\t\t\t * ex_handler_bpf().\narch/x86/net/bpf_jit_comp.c-2758-\t\t\t\t *\n--\narch/x86/net/bpf_jit_comp.c-2920-\t\t\t\t * Compute size of x86 insn and its target dest x86 register.\narch/x86/net/bpf_jit_comp.c:2921:\t\t\t\t * ex_handler_bpf() will use lower 8 bits to adjust\narch/x86/net/bpf_jit_comp.c-2922-\t\t\t\t * pt_regs-\u003eip to jump over this x86 instruction\n"
} |
| 23/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38318 output: 18 thoughts: 831 Thoughts: **My Analysis of BPF JIT Compilation and Exception Handling** Okay, let's break this down. My primary focus is on understanding the BPF JIT compilation and exception handling on x86, specifically looking for the relevant functions and potential configurations that are involved. It seems `ex_handler_bpf` is a BPF-specific exception handler, triggered exclusively by BPF arena/probe faults which is a great starting point for understanding how errors are handled. `bpf_int_jit_compile` appears to be the core entry point for the JIT compilation process, and I should note that `do_jit` is the JIT function itself, located in `arch/x86/net/bpf_jit_comp.c`, and that's the main function I need to focus on. Along with `bpf_jit_supports_insn`, which is the instruction check function. I need to make sure I identify all relevant functions. I'm wondering if `emit_atomic_fetch_rmw` or `emit_arena_exentry` are inlined or available via kallsyms. `emit_atomic_fetch_rmw` is fairly substantial in size, around 50-60 lines, and called twice in `do_jit`. So inlining could go either way. Likewise, `emit_arena_exentry` is also called twice within `do_jit`. Including these along with the aforementioned functions seems like a safe and precise inclusion set. Hang on, let me quickly make sure I haven't missed anything. Ah, there's `is_atomic_fetch_op` in `arch/x86/net/bpf_jit_comp.c`, but it's a static 5-liner; I'm betting that's inlined. Now, let's take a look at their ubiquity. None of these functions are hot-paths in the general kernel context. They are: * `bpf_int_jit_compile`: JIT-specific, only run when compiling BPF programs. * `do_jit`: x86 BPF JIT specific. * `emit_atomic_fetch_rmw`: x86 JIT atomic lowering specific. * `emit_arena_exentry`: x86 arena exception table entry generation specific. * `bpf_jit_supports_insn`: Called during BPF verification for specific instructions. * `ex_handler_bpf`: BPF exception handler for arena access violations and probe faults. So, it's pretty isolated. Okay, let's move onto the required Kconfig options. First, `BPF_JIT` is mandatory for compiling `arch/x86/net/bpf_jit_comp.c`. Also, `BPF_SYSCALL` is a requirement as well, to allow the BPF syscall to load programs and create the arena map within `kernel/bpf/arena.c`. I should check if anything else is necessary. What about architecture configs, like `X86_64`? I see in `arch/x86/net/Makefile` that if `CONFIG_X86_64` is set, which is the case, `bpf_jit_comp.o` gets compiled. So, what about `CONFIG_BPF`? Ah, `BPF_JIT` depends on `BPF`, and `BPF_SYSCALL` selects `BPF`. And `CONFIG_BPF_ARENA`? No, there isn't. I've checked. `arena.o` is built with `obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o` under `ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)`. Good, it's built under a dependency and I can rely on that. Alright, I should double-check `kernel/bpf/` and `arch/x86/` one last time, just to be sure I've got everything. |
| 24/2 | 2026/09/27 11:07 | tool | grepper |
0mError:no matches Args: {
"Expression": "config.*ARENA"
}Results: {
"error": "no matches"
} |
| 25/2 | 2026/09/27 11:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40070 output: 206 thoughts: 405 Thoughts: **My Configuration Decision for the ARENA BPF JIT** Okay, so there's no direct `CONFIG` entry for "ARENA." That's the starting point. But, I know the ARENA functionality is deeply intertwined with the BPF JIT, so let's dig into that. Specifically, I'll need `CONFIG_BPF_JIT`. I'm checking `BPF_JIT_ALWAYS_ON`, it's not strictly *required*, but `BPF_JIT` is definitely essential. Now, let's make sure there aren't any hidden sysctls or dependencies related to `BPF_JIT`. The dependencies check reveals `BPF_JIT` depends on `BPF` and `HAVE_EBPF_JIT`. Of course, loading BPF programs from user space requires `BPF_SYSCALL` too. So the core config pieces are: `BPF_SYSCALL` and `BPF_JIT`. Now, time for a full double-check: * **WorthFuzzing:** It's absolutely worth fuzzing since there are logic modifications in the x86 BPF JIT compiler (`arch/x86/net/bpf_jit_comp.c`) for the arena. I'm seeing added support for atomic fetch operations (`BPF_AND | BPF_FETCH`, `BPF_OR | BPF_FETCH`, `BPF_XOR | BPF_FETCH`) within the BPF arena, which will generate CMPXCHG loops and arena exception handling records. Specifically, the atomic fetch lowering logic (`emit_atomic_fetch_rmw`) was refactored. * **FocusSymbols:** I'll focus on these symbols: `emit_atomic_fetch_rmw`, `emit_arena_exentry`, `do_jit`, `bpf_int_jit_compile`, `bpf_jit_supports_insn`, and `ex_handler_bpf`. * **EnableConfigs:** Confirmed: `BPF_SYSCALL` and `BPF_JIT`. Everything makes sense. The decision to include these two configs is the right one, based on the information provided. The logic is concise and complete. Time to call `set-results`. |
| 26/2 | 2026/09/27 11:07 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_atomic_fetch_rmw",
"emit_arena_exentry",
"do_jit",
"bpf_int_jit_compile",
"bpf_jit_supports_insn",
"ex_handler_bpf"
],
"Reasoning": "The patch modifies the x86 BPF JIT compiler (arch/x86/net/bpf_jit_comp.c) to support atomic fetch operations (BPF_AND, BPF_OR, BPF_XOR with BPF_FETCH) on BPF arena memory via a cmpxchg loop and sets up arena exception table entries to handle potential faults. This modifies core BPF JIT compilation and exception handling logic reachable through the bpf() system call.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_atomic_fetch_rmw",
"emit_arena_exentry",
"do_jit",
"bpf_int_jit_compile",
"bpf_jit_supports_insn",
"ex_handler_bpf"
],
"Reasoning": "The patch modifies the x86 BPF JIT compiler (arch/x86/net/bpf_jit_comp.c) to support atomic fetch operations (BPF_AND, BPF_OR, BPF_XOR with BPF_FETCH) on BPF arena memory via a cmpxchg loop and sets up arena exception table entries to handle potential faults. This modifies core BPF JIT compilation and exception handling logic reachable through the bpf() system call.",
"WorthFuzzing": true
} |
| 27/1 | 2026/09/27 11:07 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/09/27 11:07 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch adds x86 BPF JIT support for atomic fetch operations (BPF_AND | BPF_FETCH, BPF_OR | BPF_FETCH, BPF_XOR | BPF_FETCH) on arena memory by emitting a CMPXCHG loop and configuring exception table entries for arena fault recovery, along with updating BPF selftests and tools.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. The changes here involve BPF JIT machine code emission and exception table entry generation in arch/x86/net/bpf_jit_comp.c. All fields of the exception table entries (`ex-\u003einsn`, `ex-\u003edata`, `ex-\u003efixup`) are fully initialized. No kernel structures with uninitialized padding or uninitialized memory are copied to userspace, nor does any C branching depend on uninitialized variables.\n- Potential risks associated with JIT code generation (such as incorrect instruction offsets, displacement calculation in JNE jumps, or incorrect pt_regs offset mapping) would manifest as bad instruction execution, invalid memory access, or control-flow faults, which are covered by functional testing and standard KASAN/sanitizer builds.\n\nBecause there is no risk of uninitialized memory access or info-leaks, a dedicated KMSAN fuzzing session is not required.",
"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: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit d9fe1ca121010baba460954ce089855d38cef398
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 11:06:33 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6c7a0578760e7..570ee93a969a9 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -236,8 +236,17 @@ static const int reg2pt_regs[] = {
[BPF_REG_7] = offsetof(struct pt_regs, r13),
[BPF_REG_8] = offsetof(struct pt_regs, r14),
[BPF_REG_9] = offsetof(struct pt_regs, r15),
+ /* Substituted for R0 by the CMPXCHG loop lowering below. */
+ [BPF_REG_AX] = offsetof(struct pt_regs, r10),
};
+static bool is_atomic_fetch_op(const struct bpf_insn *insn)
+{
+ return insn->imm == (BPF_AND | BPF_FETCH) ||
+ insn->imm == (BPF_OR | BPF_FETCH) ||
+ insn->imm == (BPF_XOR | BPF_FETCH);
+}
+
/*
* is_ereg() == true if BPF register 'reg' maps to x86-64 r8..r15
* which need extra byte of encoding.
@@ -1679,6 +1688,74 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
return 0;
}
+/*
+ * A fetching AND/OR/XOR can't be implemented with a single x86 insn, so do a
+ * CMPXCHG loop. @index_reg is X86_REG_R12 for an arena access or -1 otherwise,
+ * and @dst_reg/@src_reg are already substituted for R0 by the caller.
+ *
+ * For an arena access the CMPXCHG is the only insn that can fault; its address
+ * is handed back in @fault. A fault has to resume at @resume, which is past the
+ * loop and past the move that delivers the old value, but before the R0
+ * restore. Both are NULL for the non-arena case, which needs no fixup.
+ */
+static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,
+ u32 src_reg, int index_reg, u8 **fault,
+ u8 **resume)
+{
+ bool is64 = BPF_SIZE(insn->code) == BPF_DW;
+ u8 *branch_target, *prog = *pprog;
+ int err;
+
+ branch_target = prog;
+
+ /*
+ * Load old value. The arena case skips it and lets the loop start from
+ * whatever R0 happens to hold: a CMPXCHG that loses the comparison
+ * loads the current contents into RAX, so the loop converges, and the
+ * value it stores is computed from RAX, which by definition equalled
+ * memory whenever the store happened. That leaves the CMPXCHG as the
+ * only insn that can fault, which is worth an extra iteration here to
+ * keep this to a single exception table entry.
+ */
+ if (index_reg < 0)
+ emit_ldx(&prog, BPF_SIZE(insn->code), BPF_REG_0, dst_reg, insn->off);
+
+ /*
+ * Perform the (commutative) operation locally, put the result in
+ * the AUX_REG.
+ */
+ emit_mov_reg(&prog, is64, AUX_REG, BPF_REG_0);
+ maybe_emit_mod(&prog, AUX_REG, src_reg, is64);
+ EMIT2(simple_alu_opcodes[BPF_OP(insn->imm)],
+ add_2reg(0xC0, AUX_REG, src_reg));
+
+ /* Attempt to swap in new value */
+ if (fault)
+ *fault = prog;
+ if (index_reg < 0)
+ err = emit_atomic_rmw(&prog, BPF_CMPXCHG, dst_reg, AUX_REG,
+ insn->off, BPF_SIZE(insn->code));
+ else
+ err = emit_atomic_rmw_index(&prog, BPF_CMPXCHG, BPF_SIZE(insn->code),
+ dst_reg, AUX_REG, index_reg, insn->off);
+ if (WARN_ON(err))
+ return err;
+
+ /* ZF tells us whether we won the race. If it's cleared we need to try again. */
+ EMIT2(X86_JNE, -(prog - branch_target) - 2);
+ /* Return the pre-modification value */
+ emit_mov_reg(&prog, is64, src_reg, BPF_REG_0);
+
+ if (resume)
+ *resume = prog;
+
+ /* Restore R0 after clobbering RAX */
+ emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);
+
+ *pprog = prog;
+ return 0;
+}
+
/*
* Metadata encoding for exception handling in JITed code.
*
@@ -1692,7 +1769,12 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
* | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |
* +-----------+-------------+--------+-----------+---------+----------+
*
- * - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).
+ * - INSN_LEN (8 bits): How far past the faulting insn to resume. That is its own length
+ * for a single-insn access, but the distance to the end of the whole
+ * sequence where one BPF insn became several, as for the CMPXCHG loop
+ * of a fetching AND/OR/XOR. A sequence long enough to overflow this
+ * field would first have to exceed BPF_MAX_INSN_SIZE, which do_jit()
+ * rejects with -EFAULT before the image is used.
* - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).
* This is set to DONT_CLEAR if the insn does not read into a register.
* - ARENA_REG (8 bits): Offset of the register that is used to calculate the
@@ -1747,6 +1829,44 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
return true;
}
+/*
+ * Record an arena access that may fault. @fault_ip is the address of the
+ * faulting insn in the RO image, @resume_off how far past it execution has to
+ * resume: for a multi-insn lowering that is the end of the whole sequence, not
+ * the end of the one insn.
+ */
+static int emit_arena_exentry(struct bpf_prog *bpf_prog, u8 *image, u8 *rw_image,
+ int *excnt, u8 *fault_ip, u32 resume_off,
+ u32 fixup_reg, u32 arena_reg, bool is_write, s16 off)
+{
+ struct exception_table_entry *ex;
+ s64 delta;
+
+ if (!bpf_prog->aux->extable)
+ return 0;
+
+ if (*excnt >= bpf_prog->aux->num_exentries) {
+ pr_err("arena extable bug\n");
+ return -EFAULT;
+ }
+ ex = &bpf_prog->aux->extable[(*excnt)++];
+
+ delta = fault_ip - (u8 *)&ex->insn;
+ /* switch ex to rw buffer for writes */
+ ex = (void *)rw_image + ((void *)ex - (void *)image);
+
+ ex->insn = delta;
+ ex->data = EX_TYPE_BPF | FIELD_PREP(DATA_ARENA_OFFSET_MASK, off);
+ ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, resume_off) |
+ FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
+ FIELD_PREP(FIXUP_REG_MASK, fixup_reg) |
+ FIXUP_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= FIXUP_ARENA_WRITE;
+
+ return 0;
+}
+
static void detect_reg_usage(struct bpf_insn *insn, int insn_cnt,
bool *regs_used)
{
@@ -2624,28 +2744,8 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
}
populate_extable:
{
- struct exception_table_entry *ex;
- u8 *_insn = image + proglen + (start_of_ldx - temp);
u32 arena_reg, fixup_reg;
bool is_write;
- s64 delta;
-
- if (!bpf_prog->aux->extable)
- break;
-
- if (excnt >= bpf_prog->aux->num_exentries) {
- pr_err("mem32 extable bug\n");
- return -EFAULT;
- }
- ex = &bpf_prog->aux->extable[excnt++];
-
- delta = _insn - (u8 *)&ex->insn;
- /* switch ex to rw buffer for writes */
- ex = (void *)rw_image + ((void *)ex - (void *)image);
-
- ex->insn = delta;
-
- ex->data = EX_TYPE_BPF;
/*
* src_reg/dst_reg holds the address in the arena region with upper
@@ -2681,14 +2781,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
is_write = true;
}
- ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |
- FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
- FIELD_PREP(FIXUP_REG_MASK, fixup_reg);
- ex->fixup |= FIXUP_ARENA_ACCESS;
- if (is_write)
- ex->fixup |= FIXUP_ARENA_WRITE;
-
- ex->data |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn->off);
+ err = emit_arena_exentry(bpf_prog, image, rw_image, &excnt,
+ image + proglen + (start_of_ldx - temp),
+ prog - start_of_ldx, fixup_reg,
+ arena_reg, is_write, insn->off);
+ if (err)
+ return err;
}
break;
@@ -2840,20 +2938,12 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
fallthrough;
case BPF_STX | BPF_ATOMIC | BPF_W:
case BPF_STX | BPF_ATOMIC | BPF_DW: {
- bool is64 = BPF_SIZE(insn->code) == BPF_DW;
u32 real_src_reg = src_reg;
u32 real_dst_reg = dst_reg;
+ bool is_atomic_fetch = is_atomic_fetch_op(insn);
u8 *old_prog;
- bool is_atomic_fetch =
- (insn->imm == (BPF_AND | BPF_FETCH) ||
- insn->imm == (BPF_OR | BPF_FETCH) ||
- insn->imm == (BPF_XOR | BPF_FETCH));
- if (is_atomic_fetch) {
- /*
- * Can't be implemented with a single x86 insn.
- * Need to do a CMPXCHG loop.
- */
+ if (is_atomic_fetch) {
/* Will need RAX as a CMPXCHG operand so save R0 */
old_prog = prog;
emit_mov_reg(&prog, true, BPF_REG_AX, BPF_REG_0);
@@ -2874,34 +2964,11 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
}
}
if (is_atomic_fetch) {
- u8 *branch_target = prog;
- /* Load old value */
- emit_ldx(&prog, BPF_SIZE(insn->code),
- BPF_REG_0, real_dst_reg, insn->off);
- /*
- * Perform the (commutative) operation locally,
- * put the result in the AUX_REG.
- */
- emit_mov_reg(&prog, is64, AUX_REG, BPF_REG_0);
- maybe_emit_mod(&prog, AUX_REG, real_src_reg, is64);
- EMIT2(simple_alu_opcodes[BPF_OP(insn->imm)],
- add_2reg(0xC0, AUX_REG, real_src_reg));
- /* Attempt to swap in new value */
- err = emit_atomic_rmw(&prog, BPF_CMPXCHG,
- real_dst_reg, AUX_REG,
- insn->off,
- BPF_SIZE(insn->code));
- if (WARN_ON(err))
+ err = emit_atomic_fetch_rmw(&prog, insn, real_dst_reg,
+ real_src_reg, -1, NULL,
+ NULL);
+ if (err)
return err;
- /*
- * ZF tells us whether we won the race. If it's
- * cleared we need to try again.
- */
- EMIT2(X86_JNE, -(prog - branch_target) - 2);
- /* Return the pre-modification value */
- emit_mov_reg(&prog, is64, real_src_reg, BPF_REG_0);
- /* Restore R0 after clobbering RAX */
- emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);
break;
}
@@ -2925,6 +2992,33 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
fallthrough;
case BPF_STX | BPF_PROBE_ATOMIC | BPF_W:
case BPF_STX | BPF_PROBE_ATOMIC | BPF_DW:
+ if (is_atomic_fetch_op(insn)) {
+ u32 real_src_reg = src_reg, real_dst_reg = dst_reg;
+ u8 *fault, *resume;
+
+ /* Will need RAX as a CMPXCHG operand so save R0 */
+ emit_mov_reg(&prog, true, BPF_REG_AX, BPF_REG_0);
+ if (src_reg == BPF_REG_0)
+ real_src_reg = BPF_REG_AX;
+ if (dst_reg == BPF_REG_0)
+ real_dst_reg = BPF_REG_AX;
+
+ err = emit_atomic_fetch_rmw(&prog, insn, real_dst_reg,
+ real_src_reg, X86_REG_R12,
+ &fault, &resume);
+ if (err)
+ return err;
+
+ err = emit_arena_exentry(bpf_prog, image, rw_image, &excnt,
+ image + proglen + (fault - temp),
+ resume - fault,
+ reg2pt_regs[real_src_reg],
+ reg2pt_regs[real_dst_reg],
+ true, insn->off);
+ if (err)
+ return err;
+ break;
+ }
start_of_ldx = prog;
if (bpf_atomic_is_load_store(insn))
@@ -4669,16 +4763,6 @@ bool bpf_jit_supports_arena(void)
bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
{
- if (!in_arena)
- return true;
- switch (insn->code) {
- case BPF_STX | BPF_ATOMIC | BPF_W:
- case BPF_STX | BPF_ATOMIC | BPF_DW:
- if (insn->imm == (BPF_AND | BPF_FETCH) ||
- insn->imm == (BPF_OR | BPF_FETCH) ||
- insn->imm == (BPF_XOR | BPF_FETCH))
- return false;
- }
return true;
}
diff --git a/tools/sched_ext/include/scx/cid.bpf.h b/tools/sched_ext/include/scx/cid.bpf.h
index 69fb4e97bc771..d0d4cea19e29f 100644
--- a/tools/sched_ext/include/scx/cid.bpf.h
+++ b/tools/sched_ext/include/scx/cid.bpf.h
@@ -3,8 +3,8 @@
* BPF-side helpers for cids and cmasks. See kernel/sched/ext/cid.h for the
* authoritative layout and semantics. The BPF-side helpers use the cmask_*
* naming (no scx_ prefix); cmask is the SCX bitmap type so the prefix is
- * redundant in BPF code. Atomics use __sync_val_compare_and_swap and every
- * helper is inline (no .c counterpart).
+ * redundant in BPF code. Atomics use the __sync_* builtins and every helper
+ * is inline (no .c counterpart).
*
* Included by scx/common.bpf.h; don't include directly.
*
@@ -129,101 +129,38 @@ static __always_inline bool cmask_test(u32 cid, const struct scx_cmask __arena *
return *__cmask_word(cid, m) & BIT_U64(cid & 63);
}
-/*
- * x86 BPF JIT rejects BPF_OR | BPF_FETCH and BPF_AND | BPF_FETCH on arena
- * pointers (see bpf_jit_supports_insn() in arch/x86/net/bpf_jit_comp.c). Only
- * BPF_CMPXCHG / BPF_XCHG / BPF_ADD with FETCH are allowed. Implement
- * test_and_{set,clear} and the atomic set/clear via a cmpxchg loop.
- *
- * CMASK_CAS_TRIES is sized so exhausting it means seconds of real spinning
- * on one word - past any plausible contention. Abort hard.
- */
-#define CMASK_CAS_TRIES (1U << 23)
-
static __always_inline void cmask_set(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
-
if (!__cmask_contains(cid, m))
return;
- w = __cmask_word(cid, m);
- bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (old & bit)
- return;
- new = old | bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return;
- }
- scx_bpf_error("cmask_set CAS exhausted at cid %u", cid);
+ __sync_fetch_and_or(__cmask_word(cid, m), BIT_U64(cid & 63));
}
static __always_inline void cmask_clear(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
-
if (!__cmask_contains(cid, m))
return;
- w = __cmask_word(cid, m);
- bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (!(old & bit))
- return;
- new = old & ~bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return;
- }
- scx_bpf_error("cmask_clear CAS exhausted at cid %u", cid);
+ __sync_fetch_and_and(__cmask_word(cid, m), ~BIT_U64(cid & 63));
}
static __always_inline bool cmask_test_and_set(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
+ u64 bit;
if (!__cmask_contains(cid, m))
return false;
- w = __cmask_word(cid, m);
bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (old & bit)
- return true;
- new = old | bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return false;
- }
- scx_bpf_error("cmask_test_and_set CAS exhausted at cid %u", cid);
- return false;
+ return __sync_fetch_and_or(__cmask_word(cid, m), bit) & bit;
}
static __always_inline bool cmask_test_and_clear(u32 cid, struct scx_cmask __arena *m)
{
- u64 __arena *w;
- u64 bit, old, new;
- u32 i;
+ u64 bit;
if (!__cmask_contains(cid, m))
return false;
- w = __cmask_word(cid, m);
bit = BIT_U64(cid & 63);
- bpf_for(i, 0, CMASK_CAS_TRIES) {
- old = *w;
- if (!(old & bit))
- return false;
- new = old & ~bit;
- if (__sync_val_compare_and_swap(w, old, new) == old)
- return true;
- }
- scx_bpf_error("cmask_test_and_clear CAS exhausted at cid %u", cid);
- return false;
+ return __sync_fetch_and_and(__cmask_word(cid, m), ~bit) & bit;
}
static __always_inline void __cmask_set(u32 cid, struct scx_cmask __arena *m)
diff --git a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
index 1ad5d03d07adb..2a535815bf1dc 100644
--- a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
+++ b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
@@ -68,6 +68,12 @@ static void test_and(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->and64_value, 0x010ull << 32, "and64_value");
ASSERT_EQ(skel->arena->and32_value, 0x010, "and32_value");
+
+ ASSERT_EQ(skel->arena->and64_result, 0x110ull << 32, "and64_result");
+ ASSERT_EQ(skel->arena->and32_result, 0x110, "and32_result");
+
+ ASSERT_EQ(skel->arena->and64_noreturn_value, 0x010ull << 32, "and64_noreturn_value");
+ ASSERT_EQ(skel->arena->and32_noreturn_value, 0x010, "and32_noreturn_value");
}
static void test_or(struct arena_atomics *skel)
@@ -85,6 +91,12 @@ static void test_or(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->or64_value, 0x111ull << 32, "or64_value");
ASSERT_EQ(skel->arena->or32_value, 0x111, "or32_value");
+
+ ASSERT_EQ(skel->arena->or64_result, 0x110ull << 32, "or64_result");
+ ASSERT_EQ(skel->arena->or32_result, 0x110, "or32_result");
+
+ ASSERT_EQ(skel->arena->or64_noreturn_value, 0x111ull << 32, "or64_noreturn_value");
+ ASSERT_EQ(skel->arena->or32_noreturn_value, 0x111, "or32_noreturn_value");
}
static void test_xor(struct arena_atomics *skel)
@@ -102,6 +114,12 @@ static void test_xor(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->xor64_value, 0x101ull << 32, "xor64_value");
ASSERT_EQ(skel->arena->xor32_value, 0x101, "xor32_value");
+
+ ASSERT_EQ(skel->arena->xor64_result, 0x110ull << 32, "xor64_result");
+ ASSERT_EQ(skel->arena->xor32_result, 0x110, "xor32_result");
+
+ ASSERT_EQ(skel->arena->xor64_noreturn_value, 0x101ull << 32, "xor64_noreturn_value");
+ ASSERT_EQ(skel->arena->xor32_noreturn_value, 0x101, "xor32_noreturn_value");
}
static void test_cmpxchg(struct arena_atomics *skel)
@@ -146,6 +164,27 @@ static void test_xchg(struct arena_atomics *skel)
ASSERT_EQ(skel->arena->xchg32_result, 1, "xchg32_result");
}
+static void test_fetch_r0(struct arena_atomics *skel)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ int err, prog_fd;
+
+ /* No need to attach it, just run it directly */
+ prog_fd = bpf_program__fd(skel->progs.fetch_r0);
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ if (!ASSERT_OK(err, "test_run_opts err"))
+ return;
+ if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
+ return;
+
+ ASSERT_EQ(skel->arena->fetch_src_r0_value, 0x111, "fetch_src_r0_value");
+ ASSERT_EQ(skel->arena->fetch_src_r0_result, 0x110, "fetch_src_r0_result");
+
+ ASSERT_EQ(skel->arena->fetch_dst_r0_value, 0x111, "fetch_dst_r0_value");
+ ASSERT_EQ(skel->arena->fetch_dst_r0_result, 0x110, "fetch_dst_r0_result");
+ ASSERT_EQ(skel->arena->fetch_dst_r0_readback, 0x111, "fetch_dst_r0_readback");
+}
+
static void test_uaf(struct arena_atomics *skel)
{
LIBBPF_OPTS(bpf_test_run_opts, topts);
@@ -256,6 +295,8 @@ void serial_test_arena_atomics(void)
test_cmpxchg(skel);
if (test__start_subtest("xchg"))
test_xchg(skel);
+ if (test__start_subtest("fetch_r0"))
+ test_fetch_r0(skel);
if (test__start_subtest("uaf"))
test_uaf(skel);
if (test__start_subtest("load_acquire"))
diff --git a/tools/testing/selftests/bpf/progs/arena_atomics.c b/tools/testing/selftests/bpf/progs/arena_atomics.c
index 73bc2b835f3fe..3beca5eab3873 100644
--- a/tools/testing/selftests/bpf/progs/arena_atomics.c
+++ b/tools/testing/selftests/bpf/progs/arena_atomics.c
@@ -91,13 +91,22 @@ int sub(const void *ctx)
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u64 __arena_global and64_value = (0x110ull << 32);
-_Atomic __u32 __arena_global and32_value = 0x110;
-#else
+/*
+ * Discarding the result of an atomic RMW is what selects the non-fetching
+ * insn, so keep one of each width per operation to cover that lowering too.
+ * Declared together rather than per operation to keep them in one place.
+ */
+_Atomic __u64 __arena_global and64_noreturn_value = (0x110ull << 32);
+_Atomic __u64 __arena_global or64_noreturn_value = (0x110ull << 32);
+_Atomic __u64 __arena_global xor64_noreturn_value = (0x110ull << 32);
+_Atomic __u32 __arena_global and32_noreturn_value = 0x110;
+_Atomic __u32 __arena_global or32_noreturn_value = 0x110;
+_Atomic __u32 __arena_global xor32_noreturn_value = 0x110;
+
__u64 __arena_global and64_value = (0x110ull << 32);
+__u64 __arena_global and64_result = 0;
__u32 __arena_global and32_value = 0x110;
-#endif
+__u32 __arena_global and32_result = 0;
SEC("raw_tp/sys_enter")
int and(const void *ctx)
@@ -105,25 +114,19 @@ int and(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_and(&and64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_and(&and32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_and(&and64_value, 0x011ull << 32);
- __sync_fetch_and_and(&and32_value, 0x011);
-#endif
+ and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
+ and32_result = __sync_fetch_and_and(&and32_value, 0x011);
+ __c11_atomic_fetch_and(&and64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_and(&and32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u32 __arena_global or32_value = 0x110;
-_Atomic __u64 __arena_global or64_value = (0x110ull << 32);
-#else
-__u32 __arena_global or32_value = 0x110;
__u64 __arena_global or64_value = (0x110ull << 32);
-#endif
+__u64 __arena_global or64_result = 0;
+__u32 __arena_global or32_value = 0x110;
+__u32 __arena_global or32_result = 0;
SEC("raw_tp/sys_enter")
int or(const void *ctx)
@@ -131,25 +134,19 @@ int or(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_or(&or64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_or(&or32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_or(&or64_value, 0x011ull << 32);
- __sync_fetch_and_or(&or32_value, 0x011);
-#endif
+ or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
+ or32_result = __sync_fetch_and_or(&or32_value, 0x011);
+ __c11_atomic_fetch_or(&or64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_or(&or32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
}
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
-_Atomic __u64 __arena_global xor64_value = (0x110ull << 32);
-_Atomic __u32 __arena_global xor32_value = 0x110;
-#else
__u64 __arena_global xor64_value = (0x110ull << 32);
+__u64 __arena_global xor64_result = 0;
__u32 __arena_global xor32_value = 0x110;
-#endif
+__u32 __arena_global xor32_result = 0;
SEC("raw_tp/sys_enter")
int xor(const void *ctx)
@@ -157,13 +154,10 @@ int xor(const void *ctx)
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS
-#ifdef __BPF_FEATURE_ATOMIC_MEM_ORDERING
- __c11_atomic_fetch_xor(&xor64_value, 0x011ull << 32, memory_order_relaxed);
- __c11_atomic_fetch_xor(&xor32_value, 0x011, memory_order_relaxed);
-#else
- __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
- __sync_fetch_and_xor(&xor32_value, 0x011);
-#endif
+ xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
+ xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
+ __c11_atomic_fetch_xor(&xor64_noreturn_value, 0x011ull << 32, memory_order_relaxed);
+ __c11_atomic_fetch_xor(&xor32_noreturn_value, 0x011, memory_order_relaxed);
#endif
return 0;
@@ -213,6 +207,64 @@ int xchg(const void *ctx)
return 0;
}
+__u64 __arena_global fetch_src_r0_value = 0x110;
+__u64 __arena_global fetch_src_r0_result = 0;
+__u64 __arena_global fetch_dst_r0_value = 0x110;
+__u64 __arena_global fetch_dst_r0_result = 0;
+__u64 __arena_global fetch_dst_r0_readback = 0;
+
+/*
+ * A fetching OR with the operand in r0, and one with the arena pointer in r0.
+ * The x86 JIT needs RAX for its CMPXCHG loop and substitutes BPF_REG_AX for
+ * whichever of the two is r0, so both have to keep working. Hand-written
+ * because clang picks its own registers and will not reliably emit either.
+ */
+SEC("raw_tp/sys_enter")
+int fetch_r0(const void *ctx)
+{
+ if (pid != (bpf_get_current_pid_tgid() >> 32))
+ return 0;
+#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+ asm volatile (
+ "r1 = %[fetch_src_r0_value] ll;"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 0x011;"
+ ".8byte %[fetch_src_r0_insn];"
+ "r2 = %[fetch_src_r0_result] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r0;"
+ :
+ : __imm_addr(fetch_src_r0_value),
+ __imm_insn(fetch_src_r0_insn,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0)),
+ __imm_addr(fetch_src_r0_result)
+ : __clobber_all);
+
+ asm volatile (
+ "r0 = %[fetch_dst_r0_value] ll;"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ "r1 = 0x011;"
+ ".8byte %[fetch_dst_r0_insn];"
+ "r2 = %[fetch_dst_r0_result] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r1;"
+ /* r0 is only read by the atomic, so it must still be the pointer. */
+ "r3 = *(u64 *)(r0 + 0);"
+ "r2 = %[fetch_dst_r0_readback] ll;"
+ "r2 = addr_space_cast(r2, 0x0, 0x1);"
+ "*(u64 *)(r2 + 0) = r3;"
+ :
+ : __imm_addr(fetch_dst_r0_value),
+ __imm_insn(fetch_dst_r0_insn,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0)),
+ __imm_addr(fetch_dst_r0_result),
+ __imm_addr(fetch_dst_r0_readback)
+ : __clobber_all);
+#endif
+
+ return 0;
+}
+
__u64 __arena_global uaf_sink;
volatile __u64 __arena_global uaf_recovery_fails;
@@ -221,15 +273,24 @@ int uaf(const void *ctx)
{
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
+/*
+ * arm64 stays excluded as it has been since this test was added: its JIT only
+ * accepts arena RMW atomics when LSE is present, which is a run-time property.
+ * The rest of the file shares that dependency without a guard, so on a non-LSE
+ * arm64 the whole skeleton already fails to load.
+ *
+ * __BPF_FEATURE_ADDR_SPACE_CAST is required by the asm below, which spells
+ * addr_space_cast textually. That and the mnemonic both arrived in LLVM 19.
+ */
#if defined(ENABLE_ATOMICS_TESTS) && !defined(__TARGET_ARCH_arm64) && \
- !defined(__TARGET_ARCH_x86)
+ defined(__BPF_FEATURE_ADDR_SPACE_CAST)
__u32 __arena *page32;
__u64 __arena *page64;
void __arena *page;
page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
bpf_arena_free_pages(&arena, page, 1);
- uaf_recovery_fails = 24;
+ uaf_recovery_fails = 26;
page32 = (__u32 __arena *)page;
uaf_sink += __sync_fetch_and_add(page32, 1);
@@ -282,6 +343,34 @@ int uaf(const void *ctx)
uaf_recovery_fails -= 1;
uaf_sink += __sync_lock_test_and_set(page64, 1);
uaf_recovery_fails -= 1;
+
+ /*
+ * The x86 JIT needs RAX for the CMPXCHG loop it lowers a fetching
+ * AND/OR/XOR into, and substitutes BPF_REG_AX for r0 when r0 is either
+ * operand. Only then does the fault fixup have to name that register,
+ * so spell both forms out: clang picks its own and never produces them.
+ */
+ asm volatile (
+ "r0 = %[page];"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ "r1 = 1;"
+ ".8byte %[fetch_dst_r0];"
+ : : [page]"r"(page64),
+ __imm_insn(fetch_dst_r0,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0))
+ : "r0", "r1", "memory");
+ uaf_recovery_fails -= 1;
+
+ asm volatile (
+ "r1 = %[page];"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 1;"
+ ".8byte %[fetch_src_r0];"
+ : : [page]"r"(page64),
+ __imm_insn(fetch_src_r0,
+ BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0))
+ : "r0", "r1", "memory");
+ uaf_recovery_fails -= 1;
#endif
return 0;
|
| 29/3 | 2026/09/27 11:07 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13846 output: 32 thoughts: 1785 Thoughts: **Analyzing BPF Atomic Operations and KMSAN Implications** Okay, so this patch touches `bpf_jit_comp.c`, `cid.bpf.h`, and some selftests, and it looks like it's enabling atomic operations on arena memory for BPF programs, specifically on x86-64. I need to understand this thoroughly, especially given the KMSAN implications. First, it seems like there are changes to how the JIT compiler handles registers, particularly with the introduction of `BPF_REG_AX`. I'll need to double-check how `BPF_REG_AX` is being used in relation to the CMPXCHG loop-related code. The new `is_atomic_fetch_op` helper looks straightforward, identifying fetch-and-modify operations. The `emit_atomic_fetch_rmw` function is the core of this change; it generates the x86 assembly for these atomic operations using a CMPXCHG loop, taking arena memory into account. It also takes `emit_arena_exentry` into account. The fact that the arena access may fault, meaning a separate exception table entry must be recorded, which now comes from a refactored helper function. I see that `do_jit()` is updated to handle these new atomic instructions, with specific handling for `BPF_STX | BPF_ATOMIC` and the new `BPF_PROBE_ATOMIC` instructions. A key part is the removal of the previous restriction on atomic operations in arena memory. This means this is x86-64 specific. The patch also simplifies code in `cid.bpf.h` by using `__sync_fetch_and_or` and `__sync_fetch_and_and`, which is great! And selftests are being updated to cover this new atomic functionality. This seems like a good, solid change. Now, the crucial question is KMSAN. The prompt's instructions are very clear: only set `NeedsKMSAN=true` if there's a risk of uninitialized memory *that's not* already caught by KASAN, LOCKDEP, or other standard tools. We really only care about detecting *new* uninitialized memory issues. This means there is no need if the code primarily risks out-of-bounds access, array overflows, NULL pointer dereferences, locking deadlocks, or use-after-free bugs. So, let's look at `emit_arena_exentry`. The key thing to check here is if all members of `struct exception_table_entry` are initialized, as this is the new code. The code shows all `ex` members are assigned: `ex->insn`, `ex->data`, and `ex->fixup`. I'll need to confirm that this struct is defined and all fields are initialized to ensure no uninitialized memory could be read. No memory is leaked. No data is lost. And if there is any type of uninitialized memory, it is handled in a correct manner. Given that all fields are assigned, and the primary change is *enabling* existing atomic operations in new contexts, I don't see any immediate red flags for uninitialized memory risks introduced by the patch itself. The update to `emit_arena_exentry` seems to have appropriate initialization and handling. I don't *think* this requires KMSAN, but I will need to verify all the data types and data flow. |
| 30/3 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "struct exception_table_entry \\{",
"PathPrefix": "arch/x86"
}Results: {
"Output": "arch/x86/include/asm/extable.h-22-\narch/x86/include/asm/extable.h:23:struct exception_table_entry {\narch/x86/include/asm/extable.h-24-\tint insn, fixup, data;\n"
} |
| 31/3 | 2026/09/27 11:07 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16481 output: 41 thoughts: 1184 Thoughts: **Analyzing BPF Atomic Fetch and Modify JIT Code** Okay, let's break this down. My initial thought was: the `struct exception_table_entry` in this context seems straightforward – `insn`, `fixup`, and `data` are all explicitly assigned in `emit_arena_exentry`. However, I was wondering about `emit_atomic_fetch_rmw`. How does that work in relation to uninitialized memory? The code emits instructions to the JIT buffer. My concern was around potential uninitialized memory issues in BPF JIT code generation or execution. The critical part here is this comment: "The arena case skips it and lets the loop start from whatever R0 happens to hold". This triggered the realization: KMSAN *doesn't* instrument the JIT-compiled BPF code itself or the underlying hardware registers. It focuses on LLVM-compiled C kernel code. Crucially, in the JIT code, `R0` is equivalent to `RAX` on x86. So, the first iteration of `CMPXCHG` on x86, `RAX` holds whatever was in `R0` previously. Then, if memory equals `RAX`, it stores `AUX_REG`. If memory does not equal `RAX`, the `CMPXCHG` instruction loads the value of memory into `RAX`. This sets the zero flag (`ZF=0`) and the `JNE` instruction jumps back to `branch_target`. I needed to understand the loop. Looking at `branch_target`: it is set *before* the potential `emit_ldx` instruction if `index_reg < 0`. If `index_reg >= 0`, `emit_ldx` is skipped. So `branch_target` is right before `emit_mov_reg(&prog, is64, AUX_REG, BPF_REG_0)`. This is where the magic happens: - On the first iteration, `AUX_REG = R0 OP src_reg`. - Then `CMPXCHG(memory, AUX_REG)`. - If memory != R0, RAX gets loaded with memory by CMPXCHG and ZF=0. - `JNE` jumps to `branch_target`. - On the next iteration, R0 (RAX) now contains the value loaded from memory by CMPXCHG. - `AUX_REG` = RAX OP src_reg and `CMPXCHG` tries the swap again. That's a clever x86 `CMPXCHG` loop lowering. It uses the `CMPXCHG` instruction to load the value of memory on failure, into the register that the value to be stored is calculated from. The key question is: is there any uninitialized memory in the kernel C code here? I need to verify by reviewing the patch as a whole. The patch touches: `arch/x86/net/bpf_jit_comp.c`, and some tools. The modifications in `arch/x86/net/bpf_jit_comp.c` are: - `reg2pt_regs`: added `[BPF_REG_AX] = offsetof(struct pt_regs, r10)` - `is_atomic_fetch_op` - `emit_atomic_fetch_rmw` - `emit_arena_exentry` - `do_jit` - `bpf_jit_supports_insn` And there are some changes in `tools/`. Does any of this introduce or modify kernel structures sent to user space where fields or padding might not be initialized? No. `reg2pt_regs` is simply a constant lookup table. Its used in the `ex_handler_bpf` to clear the target register on fault when an arena access faults. |
| 32/3 | 2026/09/27 11:07 | tool | grepper |
0mArgs:{
"Expression": "reg2pt_regs",
"PathPrefix": "arch/x86/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=210=static const int reg2hex[] = {\n--\narch/x86/net/bpf_jit_comp.c-227-\narch/x86/net/bpf_jit_comp.c:228:static const int reg2pt_regs[] = {\narch/x86/net/bpf_jit_comp.c-229-\t[BPF_REG_0] = offsetof(struct pt_regs, ax),\n--\narch/x86/net/bpf_jit_comp.c=1701=static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,\n--\narch/x86/net/bpf_jit_comp.c-1777- * rejects with -EFAULT before the image is used.\narch/x86/net/bpf_jit_comp.c:1778: * - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).\narch/x86/net/bpf_jit_comp.c-1779- * This is set to DONT_CLEAR if the insn does not read into a register.\n--\narch/x86/net/bpf_jit_comp.c=2122=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-2764-\t\t\t\t bpf_atomic_is_load_acq(insn)) {\narch/x86/net/bpf_jit_comp.c:2765:\t\t\t\t\tarena_reg = reg2pt_regs[src_reg];\narch/x86/net/bpf_jit_comp.c:2766:\t\t\t\t\tfixup_reg = reg2pt_regs[dst_reg];\narch/x86/net/bpf_jit_comp.c-2767-\t\t\t\t\tis_write = false;\n--\narch/x86/net/bpf_jit_comp.c-2777-\narch/x86/net/bpf_jit_comp.c:2778:\t\t\t\t\tarena_reg = reg2pt_regs[dst_reg];\narch/x86/net/bpf_jit_comp.c-2779-\t\t\t\t\tfixup_reg = load_reg \u003c 0 ? DONT_CLEAR :\narch/x86/net/bpf_jit_comp.c:2780:\t\t\t\t\t\t reg2pt_regs[load_reg];\narch/x86/net/bpf_jit_comp.c-2781-\t\t\t\t\tis_write = true;\n--\narch/x86/net/bpf_jit_comp.c-2927-\t\t\t\tex-\u003efixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |\narch/x86/net/bpf_jit_comp.c:2928:\t\t\t\t\t FIELD_PREP(FIXUP_REG_MASK, reg2pt_regs[dst_reg]);\narch/x86/net/bpf_jit_comp.c-2929-\t\t\t}\n--\narch/x86/net/bpf_jit_comp.c-3014-\t\t\t\t\t\t\t resume - fault,\narch/x86/net/bpf_jit_comp.c:3015:\t\t\t\t\t\t\t reg2pt_regs[real_src_reg],\narch/x86/net/bpf_jit_comp.c:3016:\t\t\t\t\t\t\t reg2pt_regs[real_dst_reg],\narch/x86/net/bpf_jit_comp.c-3017-\t\t\t\t\t\t\t true, insn-\u003eoff);\n"
} |
| 33/3 | 2026/09/27 11:07 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19526 output: 45 thoughts: 31 Thoughts: Here's my take on the thought process, tailored for an expert audience and presented as a first-person summary: **Diving into the BPF JIT Compiler** Okay, so I need to understand how this particular exception handler is working within the BPF JIT compilation process. The code's in `arch/x86/net/bpf_jit_comp.c`, specifically `ex_handler_bpf`. I'm going to quickly navigate there and analyze it to see how the exception handling is being implemented in that particular context. I need to understand this to properly assess this segment of the code. Let's see what's what. |
| 34/3 | 2026/09/27 11:08 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 1785,
"LineCount": 50
}Results: {
"Contents": "1785:\t * - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.\n1786:\t *\n1787:\t * Bit layout of `data` (32-bit):\n1788:\t *\n1789:\t * +--------------+--------+--------------+\n1790:\t * |\t31-16\t | 15-8 | 7-0 |\n1791:\t * | |\t | |\n1792:\t * | ARENA_OFFSET | Unused | EX_TYPE_BPF |\n1793:\t * +--------------+--------+--------------+\n1794:\t *\n1795:\t * - ARENA_OFFSET (16 bits): Offset used to calculate the address for load/store when\n1796:\t * accessing the arena region.\n1797:\t */\n1798:\t\n1799:\t#define DONT_CLEAR 1\n1800:\t#define FIXUP_INSN_LEN_MASK\tGENMASK(7, 0)\n1801:\t#define FIXUP_REG_MASK\t\tGENMASK(15, 8)\n1802:\t#define FIXUP_ARENA_REG_MASK\tGENMASK(23, 16)\n1803:\t#define FIXUP_ARENA_WRITE\tBIT(30)\n1804:\t#define FIXUP_ARENA_ACCESS\tBIT(31)\n1805:\t#define DATA_ARENA_OFFSET_MASK\tGENMASK(31, 16)\n1806:\t\n1807:\tbool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\n1808:\t{\n1809:\t\tu32 reg = FIELD_GET(FIXUP_REG_MASK, x-\u003efixup);\n1810:\t\tu32 insn_len = FIELD_GET(FIXUP_INSN_LEN_MASK, x-\u003efixup);\n1811:\t\tbool is_arena = !!(x-\u003efixup \u0026 FIXUP_ARENA_ACCESS);\n1812:\t\tbool is_write = !!(x-\u003efixup \u0026 FIXUP_ARENA_WRITE);\n1813:\t\tunsigned long addr;\n1814:\t\ts16 off;\n1815:\t\tu32 arena_reg;\n1816:\t\n1817:\t\tif (is_arena) {\n1818:\t\t\tarena_reg = FIELD_GET(FIXUP_ARENA_REG_MASK, x-\u003efixup);\n1819:\t\t\toff = FIELD_GET(DATA_ARENA_OFFSET_MASK, x-\u003edata);\n1820:\t\t\taddr = *(unsigned long *)((void *)regs + arena_reg) + off;\n1821:\t\t\tbpf_prog_report_arena_violation(is_write, addr, regs-\u003eip);\n1822:\t\t}\n1823:\t\n1824:\t\t/* jump over faulting load and clear dest register */\n1825:\t\tif (reg != DONT_CLEAR)\n1826:\t\t\t*(unsigned long *)((void *)regs + reg) = 0;\n1827:\t\tregs-\u003eip += insn_len;\n1828:\t\n1829:\t\treturn true;\n1830:\t}\n1831:\t\n1832:\t/*\n1833:\t * Record an arena access that may fault. @fault_ip is the address of the\n1834:\t * faulting insn in the RO image, @resume_off how far past it execution has to\n"
} |
| 35/3 | 2026/09/27 11:08 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20671 output: 317 thoughts: 1058 Thoughts: **KMSAN Assessment: No Need for Dedicated Fuzzing** Okay, let's break this down. I'm looking at the `ex_handler_bpf` function, specifically how it handles faults, and comparing it to `reg2pt_regs` to understand register mapping, particularly concerning `BPF_REG_AX` on x86, which is crucial for the CMPXCHG loop. My core thought is that the fault handling mechanism zeros the destination register in `pt_regs` (`regs`), and nothing in this process involves reading uninitialized memory. There's no copying of kernel structures to user space, no conditional branches based on potentially uninitialized variables, and no complex data structures with uninitialized fields. The JIT compiler explicitly generates machine code bytes, meaning branch calculations, registers, and fixups are all explicitly defined. The potential issues I can see arising from this patch, and I've carefully considered these, are JIT instruction encoding errors, exception handling offset miscalculations or register mapping issues, and concurrent race conditions. However, these would manifest as illegal instructions, crashes, bad execution, pt_regs corruption, incorrect resume IP, or logic bugs, memory safety issues that are well within the scope of testing, KASAN, and standard kernel checks. KMSAN isn't needed here. Now, let's apply the KMSAN criteria rigorously. I need to ask myself whether this patch introduces or modifies any of the following: kernel structures sent to userspace with potentially uninitialized fields; conditional logic relying on uninitialized variables; allocation of complex data structures with later uninitialized reads; or bounds checks that allow access to uninitialized bytes. The answer is emphatically no. I'm confident that the code introduced has no uninitialized memory usage or info-leak risks. All structures touched and created in the patch are properly initialized. Therefore, KMSAN is not necessary here. The KASAN tooling will detect any issues that can arise in the patch, and is the correct choice here. Let me articulate my reasoning clearly: This patch implements atomic fetch operations on arena pointers in the x86 BPF JIT, which lowers them to a CMPXCHG loop with associated fixup entries. KMSAN's purpose is to find uninitialized memory accesses (stack/heap uninitialized reads or kernel-to-user leaks). This patch doesn't do any of that. Potential issues will manifest as faults or memory corruption, which is detected by KASAN and standard kernel checks, which is the correct way to test this code. |
| 36/3 | 2026/09/27 11:08 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch adds x86 BPF JIT support for atomic fetch operations (BPF_AND | BPF_FETCH, BPF_OR | BPF_FETCH, BPF_XOR | BPF_FETCH) on arena memory by emitting a CMPXCHG loop and configuring exception table entries for arena fault recovery, along with updating BPF selftests and tools.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. The changes here involve BPF JIT machine code emission and exception table entry generation in arch/x86/net/bpf_jit_comp.c. All fields of the exception table entries (`ex-\u003einsn`, `ex-\u003edata`, `ex-\u003efixup`) are fully initialized. No kernel structures with uninitialized padding or uninitialized memory are copied to userspace, nor does any C branching depend on uninitialized variables.\n- Potential risks associated with JIT code generation (such as incorrect instruction offsets, displacement calculation in JNE jumps, or incorrect pt_regs offset mapping) would manifest as bad instruction execution, invalid memory access, or control-flow faults, which are covered by functional testing and standard KASAN/sanitizer builds.\n\nBecause there is no risk of uninitialized memory access or info-leaks, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch adds x86 BPF JIT support for atomic fetch operations (BPF_AND | BPF_FETCH, BPF_OR | BPF_FETCH, BPF_XOR | BPF_FETCH) on arena memory by emitting a CMPXCHG loop and configuring exception table entries for arena fault recovery, along with updating BPF selftests and tools.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. The changes here involve BPF JIT machine code emission and exception table entry generation in arch/x86/net/bpf_jit_comp.c. All fields of the exception table entries (`ex-\u003einsn`, `ex-\u003edata`, `ex-\u003efixup`) are fully initialized. No kernel structures with uninitialized padding or uninitialized memory are copied to userspace, nor does any C branching depend on uninitialized variables.\n- Potential risks associated with JIT code generation (such as incorrect instruction offsets, displacement calculation in JNE jumps, or incorrect pt_regs offset mapping) would manifest as bad instruction execution, invalid memory access, or control-flow faults, which are covered by functional testing and standard KASAN/sanitizer builds.\n\nBecause there is no risk of uninitialized memory access or info-leaks, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|