LoongArch: BPF: arena features, exceptions, private stack and may_goto
Subsystems (5)
v2 cover LoongArch: BPF: arena features, exceptions, private stack and may_goto
This series adds the remaining LoongArch BPF JIT features and enables the matching selftests:
- internal-only MOV for per-CPU address resolution
- timed may_goto
- per-program private stacks
- exceptions (bpf_throw)
- sign-extending loads from arena (PROBE_MEM32SX)
- atomics on arena pointers (PROBE_ATOMIC)
- selftests: struct_ops private stack, arena LDSX, arena atomics, and a LoongArch deny list
Patch 1 ("LoongArch: BPF: Fix tail call count pointer offset for arena programs") is the same fix already posted separately for the bpf tree; several patches in this series (notably exceptions, patch 5) build on top of the helper it introduces, so it is included here, unchanged, to keep the series self-contained and applicable on bpf-next. It can be dropped once it lands via the bpf tree.
LoongArch: BPF: Fix tail call count pointer offset for arena programs
https://lore.kernel.org/all/[email protected]
Based on 7.2-rc1.
v2:
- Included the tail call count pointer offset fix as patch 1/11 (see above) instead of only referencing it, so the series applies cleanly on bpf-next without waiting on the bpf tree; the empty prog_array off-by-one was fixed independently upstream by commit 0379d10f09bc ("LoongArch: BPF: Fix off-by-one error in tail call"), now in 7.2-rc1.
- timed may_goto: store $ra at the ORC-mandated .ra_offset = -8 slot in the trampoline (it was stored at the wrong slot in v1), per Tiezhu Yang's review.
- Consolidated the earlier per-CPU MOV / timed may_goto and arena gating postings into one series; rebased on 7.2-rc1.
- selftests: use the upstream __arch_loongarch / "LOONGARCH" test_loader support now in 7.2-rc1 instead of introducing it.
- Prior postings:
https://lore.kernel.org/all/[email protected]
https://lore.kernel.org/all/[email protected]
George Guo (11):
LoongArch: BPF: Fix tail call count pointer offset for arena programs
LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
LoongArch: BPF: Add timed may_goto support
LoongArch: BPF: Add private stack support
LoongArch: BPF: Add exceptions (bpf_throw) support
LoongArch: BPF: Support sign-extending loads from arena
LoongArch: BPF: Support atomics on arena pointers selftests/bpf: Enable struct_ops private stack test for LoongArch selftests/bpf: Enable arena LDSX tests on LoongArch selftests/bpf: Enable arena atomics tests on LoongArch selftests/bpf: Add LoongArch deny list
arch/loongarch/include/asm/inst.h | 1 + arch/loongarch/kernel/stacktrace.c | 52 +++ arch/loongarch/net/Makefile | 2 +- arch/loongarch/net/bpf_jit.c | 397 ++++++++++++++++-- arch/loongarch/net/bpf_jit.h | 1 + arch/loongarch/net/bpf_timed_may_goto.S | 47 +++ .../testing/selftests/bpf/DENYLIST.loongarch | 1 + .../bpf/prog_tests/struct_ops_private_stack.c | 2 +- .../selftests/bpf/progs/arena_atomics.c | 3 + .../selftests/bpf/progs/verifier_ldsx.c | 17 + 10 files changed, 485 insertions(+), 38 deletions(-) create mode 100644 arch/loongarch/net/bpf_timed_may_goto.S create mode 100644 tools/testing/selftests/bpf/DENYLIST.loongarch
Signature · 1 line
2.25.1
PATCH v2 1/11 LoongArch: BPF: Fix tail call count pointer offset for arena programs
From: George Guo <[email protected]>
The tail call count (TCC) and its pointer occupy the two deepest slots of the callee-saved area set up by build_prologue(). An arena program reserves one extra word for REG_ARENA (arena_vm_start) right above them:
ra fp s0 s1 s2 s3 s4 s5 <- 8 words
[ REG_ARENA ] <- only if ctx->arena_vm_start
tail_call_cnt
tail_call_cnt_ptr <- loaded on tail call / bpf2bpf call
BPF_TAIL_CALL_CNT_PTR_STACK_OFF() hardcodes the pointer at round_up(stack, 16) - 80, which is only correct when REG_ARENA is absent. For an arena program the extra word shifts every slot below it down by 8 bytes, so the macro resolves to the tail_call_cnt slot (the counter value) instead of tail_call_cnt_ptr. The JIT then loads the counter value and dereferences it as the TCC pointer, corrupting memory or panicking the kernel whenever an arena program performs a tail call or a bpf2bpf call.
Replace the macro with a helper that accounts for the REG_ARENA slot, mirroring the reservation logic in build_prologue().
This is the same fix already posted separately for the bpf tree; it is included here, as patch 1/11, only so the rest of this series applies and builds cleanly on top of it. It can be dropped from this series once it lands via the bpf tree.
https://lore.kernel.org/all/[email protected]
--- arch/loongarch/net/bpf_jit.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
arch/loongarch/net/bpf_jit.c +19 -3
@@ -25,7 +25,23 @@#define REG_TCC LOONGARCH_GPR_A6#define REG_ARENA LOONGARCH_GPR_S6/* For storing arena_vm_start */ -#define BPF_TAIL_CALL_CNT_PTR_STACK_OFF (stack) (round_up(stack, 16) - 80) + +static int tail_call_cnt_ptr_stack_off (struct jit_ctx *ctx) +{ +/* Ten words are pushed below the BPF stack: ra, fp, s0-s5, and the +* tail call count plus its pointer, which occupy the two deepest +* slots of the callee-saved area. +*/ +int offset =sizeof (long ) *10 ; + +/* An arena program reserves one extra word above them (REG_ARENA), +* which pushes the tail call count pointer down by one slot. +*/ +if (ctx->arena_vm_start) + offset +=sizeof (long ); + +return round_up (ctx->stack_size,16 ) - offset; +}static const int regmap[] = {/* return value from in-kernel function, and exit value for eBPF program */
@@ -291,7 +307,7 @@ bool bpf_jit_supports_far_kfunc_call(void)static int emit_bpf_tail_call (struct jit_ctx *ctx,int insn) {int off, tc_ninsn =0 ; -int tcc_ptr_off =BPF_TAIL_CALL_CNT_PTR_STACK_OFF (ctx->stack_size); +int tcc_ptr_off =tail_call_cnt_ptr_stack_off (ctx);u8 a1 =LOONGARCH_GPR_A1 ;u8 a2 =LOONGARCH_GPR_A2 ;u8 t1 =LOONGARCH_GPR_T1 ;
@@ -1181,7 +1197,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extreturn ret;if (insn->src_reg ==BPF_PSEUDO_CALL ) { - tcc_ptr_off =BPF_TAIL_CALL_CNT_PTR_STACK_OFF (ctx->stack_size); + tcc_ptr_off =tail_call_cnt_ptr_stack_off (ctx);emit_insn (ctx, ldd,REG_TCC ,LOONGARCH_GPR_SP , tcc_ptr_off); }
Signature · 1 line
2.25.1
PATCH v2 2/11 LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
In reply to George GuoFrom: George Guo <[email protected]>
Support the internal-only BPF_MOV instruction that resolves the absolute address of per-CPU data from its per-CPU offset. This instruction is used only for internal inlining optimizations between the BPF verifier and the JITs (e.g. inlining bpf_get_smp_processor_id() and per-CPU map lookups).
LoongArch keeps the per-CPU offset of the current CPU in $r21 (__my_cpu_offset), so resolving a per-CPU address only requires adding $r21 to the source register holding the per-CPU offset. Advertise the capability via bpf_jit_supports_percpu_insn().
--- arch/loongarch/include/asm/inst.h | 1 + arch/loongarch/net/bpf_jit.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
arch/loongarch/include/asm/inst.h +1 -0
@@ -404,6 +404,7 @@ enum loongarch_gpr {LOONGARCH_GPR_T6 ,LOONGARCH_GPR_T7 ,LOONGARCH_GPR_T8 , +LOONGARCH_GPR_U0 =21 ,/* Kernel per-CPU base register ($r21) */ LOONGARCH_GPR_FP =22 ,LOONGARCH_GPR_S0 =23 , LOONGARCH_GPR_S1,
arch/loongarch/net/bpf_jit.c +14 -0
@@ -759,6 +759,15 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extmove_reg (ctx, dst, t1);break ; } +if (insn_is_mov_percpu_addr (insn)) { +if (dst != src) +move_reg (ctx, dst, src); +#ifdef CONFIG_SMP +/* dst += __my_cpu_offset, held in $r21 */ +emit_insn (ctx, addd, dst, dst,LOONGARCH_GPR_U0 ); +#endif +break ; + }switch (off) {case 0 :move_reg (ctx, dst, src);
@@ -2406,6 +2415,11 @@ bool bpf_jit_supports_fsession(void)return true; } +bool bpf_jit_supports_percpu_insn (void ) +{ +return true; +} +/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ bool bpf_jit_supports_subprog_tailcalls (void ) {
Signature · 1 line
2.25.1
PATCH v2 3/11 LoongArch: BPF: Add timed may_goto support
In reply to George GuoFrom: George Guo <[email protected]>
Implement arch_bpf_timed_may_goto() and advertise it through bpf_jit_supports_timed_may_goto() so the verifier lowers may_goto into the timed variant: instead of a fixed iteration counter, the loop is bounded by a wall-clock timeout maintained in a per-loop stack slot.
arch_bpf_timed_may_goto() uses a custom calling convention: the verifier passes the count/timestamp stack offset in BPF_REG_AX and expects the updated count back in the same register. The JIT call path therefore skips the usual 'BPF_REG_0 = C return value' move for this helper.
--- arch/loongarch/net/Makefile | 2 +- arch/loongarch/net/bpf_jit.c | 13 ++++++- arch/loongarch/net/bpf_timed_may_goto.S | 47 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 arch/loongarch/net/bpf_timed_may_goto.S
arch/loongarch/net/Makefile +1 -1
@@ -4,4 +4,4 @@ # # Copyright (C) 2022 Loongson Technology Corporation Limited # -obj-$(CONFIG_BPF_JIT) += bpf_jit.o +obj-$(CONFIG_BPF_JIT) += bpf_jit.o bpf_timed_may_goto.o
arch/loongarch/net/bpf_jit.c +12 -1
@@ -1229,7 +1229,13 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extmove_addr (ctx, t1, func_addr);emit_insn (ctx, jirl,LOONGARCH_GPR_RA , t1,0 ); -if (insn->src_reg !=BPF_PSEUDO_CALL ) +/* +* Call to arch_bpf_timed_may_goto() uses a custom calling +* convention with the argument and return value in BPF_REG_AX, +* so skip moving the C return value into BPF_REG_0. +*/ +if (insn->src_reg !=BPF_PSEUDO_CALL && + func_addr != (u64 )arch_bpf_timed_may_goto)move_reg (ctx, regmap[BPF_REG_0 ],LOONGARCH_GPR_A0 );break ;
@@ -2420,6 +2426,11 @@ bool bpf_jit_supports_percpu_insn(void)return true; } +bool bpf_jit_supports_timed_may_goto (void ) +{ +return true; +} +/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ bool bpf_jit_supports_subprog_tailcalls (void ) {
arch/loongarch/net/bpf_timed_may_goto.S new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 4/11 LoongArch: BPF: Add private stack support
In reply to George GuoFrom: George Guo <[email protected]>
Support per-program private stacks, advertised via bpf_jit_supports_private_stack(). When the verifier marks a program with jits_use_priv_stack (e.g. a sufficiently deep, potentially recursive tracing program), its BPF stack is moved off the kernel stack into a per-CPU allocation, reducing kernel stack pressure.
The private stack is sized as the verifier-computed stack depth plus two 16-byte guard regions for overflow/underflow detection, initialised at allocation time and validated in bpf_jit_free(). S5 (saved/restored but otherwise unused by the JIT) holds the private stack pointer, computed in the prologue from the current CPU's per-CPU offset ($r21).
--- arch/loongarch/net/bpf_jit.c | 112 ++++++++++++++++++++++++++++++++++- arch/loongarch/net/bpf_jit.h | 1 + 2 files changed, 110 insertions(+), 3 deletions(-)
arch/loongarch/net/bpf_jit.c +109 -3
@@ -25,6 +25,7 @@#define REG_TCC LOONGARCH_GPR_A6#define REG_ARENA LOONGARCH_GPR_S6/* For storing arena_vm_start */ +#define REG_PRIV_SP LOONGARCH_GPR_S5/* For storing the private stack pointer */ static int tail_call_cnt_ptr_stack_off (struct jit_ctx *ctx) {
@@ -43,6 +44,10 @@ static int tail_call_cnt_ptr_stack_off(struct jit_ctx *ctx)return round_up (ctx->stack_size,16 ) - offset; } +/* Memory size/value to protect private stack overflow/underflow */ +#define PRIV_STACK_GUARD_SZ 16 +#define PRIV_STACK_GUARD_VAL 0xEB9F12345678eb9fULL +static const int regmap[] = {/* return value from in-kernel function, and exit value for eBPF program */ [BPF_REG_0 ] =LOONGARCH_GPR_A5 ,
@@ -63,6 +68,15 @@ static const int regmap[] = { [BPF_REG_AX] = LOONGARCH_GPR_T0, }; +static void emit_percpu_ptr (struct jit_ctx *ctx,u8 dst,void __percpu *ptr) +{ +move_imm (ctx, dst, (__force long )ptr, false); +#ifdef CONFIG_SMP +/* dst += __my_cpu_offset, held in $r21 */ +emit_insn (ctx, addd, dst, dst,LOONGARCH_GPR_U0 ); +#endif +} +static void prepare_bpf_tail_call_cnt (struct jit_ctx *ctx,int *store_offset) {const struct bpf_prog *prog = ctx->prog;
@@ -164,7 +178,14 @@ static void build_prologue(struct jit_ctx *ctx) stack_adjust +=8 ; stack_adjust =round_up (stack_adjust,16 ); - stack_adjust += bpf_stack_adjust; + +/* +* When a private stack is used the BPF stack lives in a per-CPU +* allocation rather than on the kernel stack, so only the non-BPF +* part is reserved here. +*/ +if (!ctx->priv_sp_used) + stack_adjust += bpf_stack_adjust;/* * Save the original return address to a temporary register to prevent
@@ -219,8 +240,16 @@ static void build_prologue(struct jit_ctx *ctx)emit_insn (ctx, addid,LOONGARCH_GPR_FP ,LOONGARCH_GPR_SP , stack_adjust); -if (bpf_stack_adjust) +if (ctx->priv_sp_used) { +/* Set up the private stack pointer and the BPF frame pointer */ +void __percpu *priv_stack_ptr; + + priv_stack_ptr = prog->aux->priv_stack_ptr +PRIV_STACK_GUARD_SZ ; +emit_percpu_ptr (ctx,REG_PRIV_SP , priv_stack_ptr); +emit_insn (ctx, addid, regmap[BPF_REG_FP ],REG_PRIV_SP , bpf_stack_adjust); + }else if (bpf_stack_adjust) {emit_insn (ctx, addid, regmap[BPF_REG_FP ],LOONGARCH_GPR_SP , bpf_stack_adjust); + } ctx->stack_size = stack_adjust;
@@ -2225,6 +2254,39 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,return ret <0 ? ret : ret *LOONGARCH_INSN_SIZE ; } +static void priv_stack_init_guard (void __percpu *priv_stack_ptr,int alloc_size) +{ +int cpu, underflow_idx = (alloc_size -PRIV_STACK_GUARD_SZ ) >>3 ; +u64 *stack_ptr; + +for_each_possible_cpu (cpu) { + stack_ptr =per_cpu_ptr (priv_stack_ptr, cpu); + stack_ptr[0 ] =PRIV_STACK_GUARD_VAL ; + stack_ptr[1 ] =PRIV_STACK_GUARD_VAL ; + stack_ptr[underflow_idx] =PRIV_STACK_GUARD_VAL ; + stack_ptr[underflow_idx +1 ] =PRIV_STACK_GUARD_VAL ; + } +} + +static void priv_stack_check_guard (void __percpu *priv_stack_ptr,int alloc_size, +struct bpf_prog *prog) +{ +int cpu, underflow_idx = (alloc_size -PRIV_STACK_GUARD_SZ ) >>3 ; +u64 *stack_ptr; + +for_each_possible_cpu (cpu) { + stack_ptr =per_cpu_ptr (priv_stack_ptr, cpu); +if (stack_ptr[0 ] !=PRIV_STACK_GUARD_VAL || + stack_ptr[1 ] !=PRIV_STACK_GUARD_VAL || + stack_ptr[underflow_idx] !=PRIV_STACK_GUARD_VAL || + stack_ptr[underflow_idx +1 ] !=PRIV_STACK_GUARD_VAL ) { +pr_err ("BPF private stack overflow/underflow detected for prog %s\n" , +bpf_jit_get_prog_name (prog)); +break ; + } + } +} +struct bpf_prog *bpf_int_jit_compile (struct bpf_verifier_env *env,struct bpf_prog *prog) {bool extra_pass = false;
@@ -2233,7 +2295,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prstruct jit_ctx ctx;struct jit_data *jit_data;struct bpf_binary_header *header; -struct bpf_binary_header *ro_header; +struct bpf_binary_header *ro_header =NULL ; +void __percpu *priv_stack_ptr =NULL ; +int priv_stack_alloc_sz;/* * If BPF JIT was not enabled then we must fall back to
@@ -2249,6 +2313,22 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prreturn prog; prog->aux->jit_data = jit_data; } + priv_stack_ptr = prog->aux->priv_stack_ptr; +if (!priv_stack_ptr && prog->aux->jits_use_priv_stack) { +/* +* Allocate the actual private stack: the verifier-calculated +* stack size plus two guard regions to detect overflow and +* underflow. +*/ + priv_stack_alloc_sz =round_up (prog->aux->stack_depth,16 ) + +2 *PRIV_STACK_GUARD_SZ ; + priv_stack_ptr =__alloc_percpu_gfp (priv_stack_alloc_sz,16 ,GFP_KERNEL ); +if (!priv_stack_ptr) + goto out_priv_stack; + +priv_stack_init_guard (priv_stack_ptr, priv_stack_alloc_sz); + prog->aux->priv_stack_ptr = priv_stack_ptr; + }if (jit_data->ctx.offset) { ctx = jit_data->ctx; ro_header = jit_data->ro_header;
@@ -2264,6 +2344,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr ctx.prog = prog; ctx.arena_vm_start =bpf_arena_get_kern_vm_start (prog->aux->arena); ctx.user_vm_start =bpf_arena_get_user_vm_start (prog->aux->arena); + ctx.priv_sp_used = priv_stack_ptr ? true : false; ctx.offset =kvcalloc (prog->len +1 ,sizeof (u32),GFP_KERNEL );if (ctx.offset ==NULL )
@@ -2357,7 +2438,17 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prbpf_prog_fill_jited_linfo (prog, ctx.offset +1 ); out_offset: +/* +* A NULL ro_header here means the JIT failed, so release the +* private stack that was allocated above; on success the +* program keeps it until bpf_jit_free(). +*/ +if (!ro_header && priv_stack_ptr) { +free_percpu (priv_stack_ptr); + prog->aux->priv_stack_ptr =NULL ; + }kvfree (ctx.offset); +out_priv_stack:kfree (jit_data); prog->aux->jit_data =NULL ; }
@@ -2374,6 +2465,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prif (header) {bpf_arch_text_copy (&ro_header->size, &header->size,sizeof (header->size));bpf_jit_binary_pack_free (ro_header, header); + ro_header =NULL ; } goto out_offset; }
@@ -2383,6 +2475,8 @@ void bpf_jit_free(struct bpf_prog *prog)if (prog->jited) {struct jit_data *jit_data = prog->aux->jit_data;struct bpf_binary_header *hdr; +void __percpu *priv_stack_ptr; +int priv_stack_alloc_sz;/* * If we fail the final pass of JIT (from jit_subprogs), the
@@ -2395,6 +2489,13 @@ void bpf_jit_free(struct bpf_prog *prog) } hdr =bpf_jit_binary_pack_hdr (prog);bpf_jit_binary_pack_free (hdr,NULL ); + priv_stack_ptr = prog->aux->priv_stack_ptr; +if (priv_stack_ptr) { + priv_stack_alloc_sz =round_up (prog->aux->stack_depth,16 ) + +2 *PRIV_STACK_GUARD_SZ ; +priv_stack_check_guard (priv_stack_ptr, priv_stack_alloc_sz, prog); +free_percpu (prog->aux->priv_stack_ptr); + }WARN_ON_ONCE (!bpf_prog_kallsyms_verify_off (prog)); }
@@ -2431,6 +2532,11 @@ bool bpf_jit_supports_timed_may_goto(void)return true; } +bool bpf_jit_supports_private_stack (void ) +{ +return true; +} +/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ bool bpf_jit_supports_subprog_tailcalls (void ) {
arch/loongarch/net/bpf_jit.h +1 -0
@@ -22,6 +22,7 @@ struct jit_ctx {u32 stack_size;u64 arena_vm_start;u64 user_vm_start; +bool priv_sp_used; };struct jit_data {
Signature · 1 line
2.25.1
PATCH v2 5/11 LoongArch: BPF: Add exceptions (bpf_throw) support
In reply to George GuoFrom: George Guo <[email protected]>
Implement BPF exception support, advertised via bpf_jit_supports_exceptions(). bpf_throw() unwinds the stack to find the exception boundary program's frame and then invokes its exception callback with that frame's stack and frame pointers.
Finding the boundary frame needs arch_bpf_stack_walk(), which reports each frame's (ip, sp, fp). This is implemented on top of the ORC
unwinder: ORC updates the frame pointer per frame and walks JITed BPF code via its generated-code frame-pointer fallback, which expects the frame record at fp-8 ($ra) and fp-16 (previous fp) -- exactly what the LoongArch BPF prologue already lays down. The capability is therefore gated on CONFIG_UNWINDER_ORC; with other unwinders it returns false.
The walk is seeded with the live frame pointer ($r22). The kernel is built with -fomit-frame-pointer, so $fp is an ordinary callee-saved register preserved across the call from the JITed program into bpf_throw() down to arch_bpf_stack_walk(), where it still points at the innermost BPF frame for the ORC fallback to start from. It is captured in a thin wrapper with no large stack locals, because the worker that runs the unwind uses $r22 to address its own (pt_regs + unwind_state) frame and would otherwise clobber the live $fp before it could be read.
On the JIT side, the exception callback does not build a normal frame:
it receives the boundary program's frame pointer as its third argument (a2), sets FP to it and SP to FP - stack_size, and reuses the boundary's frame. Because the callee-saved register saves are anchored at the top of the frame (FP), the existing FP-relative epilogue restores the boundary's registers and returns to the boundary's caller regardless of the two programs' individual frame sizes. To keep the boundary and the callback agreeing on the layout, the s6 slot is always reserved for exception programs, mirroring the arena case.
--- arch/loongarch/kernel/stacktrace.c | 52 ++++++++++++++++++++++++++++ arch/loongarch/net/bpf_jit.c | 54 ++++++++++++++++++++++++++---- 2 files changed, 100 insertions(+), 6 deletions(-)
arch/loongarch/kernel/stacktrace.c +52 -0
@@ -4,6 +4,7 @@* * Copyright (C) 2022 Loongson Technology Corporation Limited */ +#include <linux/filter.h> #include <linux/sched.h> #include <linux/stacktrace.h> #include <linux/uaccess.h>
@@ -40,6 +41,57 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, } } +#ifdef CONFIG_UNWINDER_ORC +/* +* Used by BPF exception support (bpf_throw) to find the exception boundary +* frame. The ORC unwinder reports the stack and frame pointer of each frame +* and, via its generated-code fallback, can walk JITed BPF frames, which set +* up the expected frame record ($ra at fp-8, previous fp at fp-16). +*/ +static noinline void walk_stackframe_bpf(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), +void *cookie,unsigned long fp) +{ +unsigned long addr; +struct pt_regs dummyregs; +struct pt_regs *regs = &dummyregs; +struct unwind_state state; + + regs->regs[3 ] = (unsigned long )__builtin_frame_address (0 ); + regs->csr_era = (unsigned long )__builtin_return_address (0 ); + regs->regs[1 ] =0 ; + regs->regs[22 ] = fp; + +for (unwind_start (&state, current, regs); + !unwind_done (&state);unwind_next_frame (&state)) { + addr =unwind_get_return_address (&state); +if (!addr || !consume_fn (cookie, (u64 )addr, (u64 )state.sp, (u64 )state.fp)) +break ; + } +} + +void arch_bpf_stack_walk (bool (*consume_fn)(void *cookie,u64 ip,u64 sp,u64 bp), +void *cookie) +{ +unsigned long fp; + +/* +* Capture the live frame pointer ($r22/$fp) here, before handing off to +* the worker. The kernel is built with -fomit-frame-pointer, so $fp is +* an ordinary callee-saved register that is preserved across the call +* from the JITed BPF program into bpf_throw() down to here, and thus +* still points at the innermost BPF frame. The ORC frame-pointer +* fallback walks the BPF frames up to the exception boundary from it. +* +* This must be a thin wrapper with no large stack locals: the worker +* uses $r22 to address its frame, which would clobber the live $fp +* before it could be read. __builtin_frame_address() cannot be used +* either, as it is $sp-derived and would yield a kernel-stack frame. +*/ + asmvolatile ("move %0, $r22" :"=r" (fp)); +walk_stackframe_bpf (consume_fn, cookie, fp); +} +#endif /* CONFIG_UNWINDER_ORC */ +int arch_stack_walk_reliable (stack_trace_consume_fn consume_entry,void *cookie,struct task_struct *task) {
arch/loongarch/net/bpf_jit.c +48 -6
121 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 6/11 LoongArch: BPF: Support sign-extending loads from arena
In reply to George GuoFrom: George Guo <[email protected]>
A sign-extending load from an arena pointer is rewritten by the verifier to BPF_PROBE_MEM32SX once the JIT advertises support for it through bpf_jit_supports_insn(); the generic helper otherwise defaults to rejecting arena instructions. Add the callback and implement the load:
route BPF_PROBE_MEM32SX through the existing BPF_PROBE_MEM32 path, which adds the arena base held in REG_ARENA, while selecting the sign-extending load variants (ld.b/ld.h/ld.w), and register an exception table entry so a fault on the access is handled like the other arena probes.
--- arch/loongarch/net/bpf_jit.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
arch/loongarch/net/bpf_jit.c +25 -3
@@ -739,7 +739,8 @@ static int add_exception_handler(const struct bpf_insn *insn,if (BPF_MODE (insn->code) !=BPF_PROBE_MEM &&BPF_MODE (insn->code) !=BPF_PROBE_MEMSX && -BPF_MODE (insn->code) !=BPF_PROBE_MEM32 ) +BPF_MODE (insn->code) !=BPF_PROBE_MEM32 && +BPF_MODE (insn->code) !=BPF_PROBE_MEM32SX )return 0 ;if (WARN_ON_ONCE (ctx->num_exentries >= ctx->prog->aux->num_exentries))
@@ -1349,10 +1350,16 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extcase BPF_LDX |BPF_PROBE_MEM32 |BPF_H :case BPF_LDX |BPF_PROBE_MEM32 |BPF_W :case BPF_LDX |BPF_PROBE_MEM32 |BPF_DW : +/* LDX | PROBE_MEM32SX: dst = *(signed size *)(src + REG_ARENA + off) */ +case BPF_LDX |BPF_PROBE_MEM32SX |BPF_B : +case BPF_LDX |BPF_PROBE_MEM32SX |BPF_H : +case BPF_LDX |BPF_PROBE_MEM32SX |BPF_W : sign_extend =BPF_MODE (code) ==BPF_MEMSX || -BPF_MODE (code) ==BPF_PROBE_MEMSX ; +BPF_MODE (code) ==BPF_PROBE_MEMSX || +BPF_MODE (code) ==BPF_PROBE_MEM32SX ; -if (BPF_MODE (code) ==BPF_PROBE_MEM32 ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM32 || +BPF_MODE (code) ==BPF_PROBE_MEM32SX ) {emit_insn (ctx, addd, t2, src,REG_ARENA ); src = t2; }
@@ -2548,6 +2555,21 @@ bool bpf_jit_supports_arena(void)return true; } +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 : +/* Atomics on arena pointers are not implemented yet. */ +return false; + } + +return true; +} +bool bpf_jit_supports_fsession (void ) {return true;
Signature · 1 line
2.25.1
PATCH v2 7/11 LoongArch: BPF: Support atomics on arena pointers
In reply to George GuoFrom: George Guo <[email protected]>
Implement atomic operations on arena pointers (BPF_PROBE_ATOMIC): the read-modify-write ops, atomic_fetch_*, xchg, cmpxchg and load-acquire/store-release. For each, the arena base held in REG_ARENA is folded into the address and an exception table entry is registered on the access so a fault is handled like the other arena probes.
The exception entry must point at the actual memory-accessing instruction rather than the last one emitted: the fetch variants append a zero-extend after the am* op, and cmpxchg accesses memory with the ll of an ll/sc loop. Generalise add_exception_handler() to take explicit fault and resume instruction indices. A faulting ll resumes past the whole ll/sc loop: if the ll faults the sc is never reached, and once the ll succeeds the page is mapped so the sc cannot fault, so a single entry on the ll suffices.
--- arch/loongarch/net/bpf_jit.c | 182 ++++++++++++++++++++++++++++------- 1 file changed, 148 insertions(+), 34 deletions(-)
arch/loongarch/net/bpf_jit.c +148 -34
@@ -441,6 +441,16 @@ static void emit_store_stack_imm64(struct jit_ctx *ctx, int reg, int stack_off,emit_insn (ctx, std, reg,LOONGARCH_GPR_FP , stack_off); } +#define BPF_FIXUP_REG_MASK GENMASK(31, 27) +#define BPF_FIXUP_OFFSET_MASK GENMASK(26, 0) +#define REG_DONT_CLEAR_MARKER 0 + +static int add_exception_handler (const struct bpf_insn *insn, +struct jit_ctx *ctx,int dst_reg); +static int __add_exception_handler (const struct bpf_insn *insn, +struct jit_ctx *ctx,int dst_reg, +int fault_idx,int resume_idx); +static int emit_atomic_rmw (const struct bpf_insn *insn,struct jit_ctx *ctx) {const u8 t1 =LOONGARCH_GPR_T1 ;
@@ -452,9 +462,14 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)const s16 off = insn->off;const s32 imm = insn->imm;const bool isdw =BPF_SIZE (insn->code) ==BPF_DW ; +const bool arena =BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ; +bool zext = false; +int ret, ll_idx =0 ;move_imm (ctx, t1, off, false);emit_insn (ctx, addd, t1, dst, t1); +if (arena) +emit_insn (ctx, addd, t1, t1,REG_ARENA );move_reg (ctx, t3, src);switch (imm) {
@@ -510,7 +525,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)return -EINVAL ; }emit_insn (ctx, amaddb, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_H :if (!cpu_has_lam_bh) {
@@ -518,11 +533,11 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)return -EINVAL ; }emit_insn (ctx, amaddh, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_W :emit_insn (ctx, amaddw, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_DW :emit_insn (ctx, amaddd, src, t1, t3);
@@ -534,7 +549,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)emit_insn (ctx, amandd, src, t1, t3); }else {emit_insn (ctx, amandw, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true; }break ;case BPF_OR |BPF_FETCH :
@@ -542,7 +557,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)emit_insn (ctx, amord, src, t1, t3); }else {emit_insn (ctx, amorw, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true; }break ;case BPF_XOR |BPF_FETCH :
@@ -550,7 +565,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)emit_insn (ctx, amxord, src, t1, t3); }else {emit_insn (ctx, amxorw, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true; }break ;/* src = atomic_xchg(dst + off, src); */
@@ -562,7 +577,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)return -EINVAL ; }emit_insn (ctx, amswapb, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_H :if (!cpu_has_lam_bh) {
@@ -570,11 +585,11 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)return -EINVAL ; }emit_insn (ctx, amswaph, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_W :emit_insn (ctx, amswapw, src, t1, t3); -emit_zext_32 (ctx, src, true); + zext = true;break ;case BPF_DW :emit_insn (ctx, amswapd, src, t1, t3);
@@ -585,12 +600,14 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)case BPF_CMPXCHG :move_reg (ctx, t2, r0);if (isdw) { + ll_idx = ctx->idx;emit_insn (ctx, lld, r0, t1,0 );emit_insn (ctx, bne, t2, r0,4 );move_reg (ctx, t3, src);emit_insn (ctx, scd, t3, t1,0 );emit_insn (ctx, beq, t3,LOONGARCH_GPR_ZERO ,-4 ); }else { + ll_idx = ctx->idx;emit_insn (ctx, llw, r0, t1,0 );emit_zext_32 (ctx, t2, true);emit_zext_32 (ctx, r0, true);
@@ -600,12 +617,42 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)emit_insn (ctx, beq, t3,LOONGARCH_GPR_ZERO ,-6 );emit_zext_32 (ctx, r0, true); } +/* +* On arena the ll may fault (unmapped page); the page-fault +* handler restarts the program at @resume. Only the ll needs an +* entry: if it faults the sc is never reached, and once the ll +* succeeds the page is mapped so the sc cannot fault. Resume +* past the whole ll/sc loop. +*/ +if (arena) { + ret =__add_exception_handler (insn, ctx, +REG_DONT_CLEAR_MARKER , + ll_idx, ctx->idx); +if (ret) +return ret; + }break ;default :pr_err_once ("bpf-jit: invalid atomic read-modify-write opcode %02x\n" , imm);return -EINVAL ; } +/* +* For the single-instruction am* ops the memory access is the last +* emitted instruction; register its exception entry before emitting the +* deferred zero-extend so the fault resumes past it. cmpxchg handled +* its own entry above. +*/ +if (arena && imm !=BPF_CMPXCHG ) { + ret =__add_exception_handler (insn, ctx,REG_DONT_CLEAR_MARKER , + ctx->idx -1 , ctx->idx + (zext ?1 :0 )); +if (ret) +return ret; + } + +if (zext) +emit_zext_32 (ctx, src, true); +return 0 ; }
@@ -616,10 +663,37 @@ static int emit_atomic_ld_st(const struct bpf_insn *insn, struct jit_ctx *ctx)const u8 dst = regmap[insn->dst_reg];const s16 off = insn->off;const s32 imm = insn->imm; +const bool arena =BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ; +int ret;switch (imm) {/* dst_reg = load_acquire(src_reg + off16) */ case BPF_LOAD_ACQ : +if (arena) { +/* t1 = src + off + arena_vm_start; load from [t1]. */ +move_imm (ctx, t1, off, false); +emit_insn (ctx, addd, t1, src, t1); +emit_insn (ctx, addd, t1, t1,REG_ARENA ); +switch (BPF_SIZE (insn->code)) { +case BPF_B : +emit_insn (ctx, ldbu, dst, t1,0 ); +break ; +case BPF_H : +emit_insn (ctx, ldhu, dst, t1,0 ); +break ; +case BPF_W : +emit_insn (ctx, ldwu, dst, t1,0 ); +break ; +case BPF_DW : +emit_insn (ctx, ldd, dst, t1,0 ); +break ; + } + ret =add_exception_handler (insn, ctx,REG_DONT_CLEAR_MARKER ); +if (ret) +return ret; +emit_insn (ctx, dbar,0b10100 ); +break ; + }switch (BPF_SIZE (insn->code)) {case BPF_B :if (is_signed_imm12 (off)) {
@@ -658,6 +732,31 @@ static int emit_atomic_ld_st(const struct bpf_insn *insn, struct jit_ctx *ctx)break ;/* store_release(dst_reg + off16, src_reg) */ case BPF_STORE_REL : +if (arena) { +/* t1 = dst + off + arena_vm_start; store to [t1]. */ +emit_insn (ctx, dbar,0b10010 ); +move_imm (ctx, t1, off, false); +emit_insn (ctx, addd, t1, dst, t1); +emit_insn (ctx, addd, t1, t1,REG_ARENA ); +switch (BPF_SIZE (insn->code)) { +case BPF_B : +emit_insn (ctx, stb, src, t1,0 ); +break ; +case BPF_H : +emit_insn (ctx, sth, src, t1,0 ); +break ; +case BPF_W : +emit_insn (ctx, stw, src, t1,0 ); +break ; +case BPF_DW : +emit_insn (ctx, std, src, t1,0 ); +break ; + } + ret =add_exception_handler (insn, ctx,REG_DONT_CLEAR_MARKER ); +if (ret) +return ret; +break ; + }emit_insn (ctx, dbar,0b10010 );switch (BPF_SIZE (insn->code)) {case BPF_B :
@@ -708,10 +807,6 @@ static bool is_signed_bpf_cond(u8 cond) cond ==BPF_JSGE || cond ==BPF_JSLE ; } -#define BPF_FIXUP_REG_MASK GENMASK(31, 27) -#define BPF_FIXUP_OFFSET_MASK GENMASK(26, 0) -#define REG_DONT_CLEAR_MARKER 0 -bool ex_handler_bpf (const struct exception_table_entry *ex,struct pt_regs *regs) {
@@ -725,12 +820,21 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,return true; } -/* For accesses to BTF pointers, add an entry to the exception table */ -static int add_exception_handler (const struct bpf_insn *insn, -struct jit_ctx *ctx, -int dst_reg) +/* +* Register an exception table entry for a faulting instruction. +* +* @fault_idx is the ctx->image index of the instruction that may fault; +* @resume_idx is the index to resume execution at after the fault is handled. +* For a simple load/store these are the just-emitted instruction and the one +* right after it, but an atomic may need to fault on an instruction in the +* middle of a longer sequence (e.g. the ll of an ll/sc cmpxchg loop) and +* resume past the whole sequence, so both are passed explicitly. +*/ +static int __add_exception_handler (const struct bpf_insn *insn, +struct jit_ctx *ctx,int dst_reg, +int fault_idx,int resume_idx) { -unsigned long pc; +unsigned long pc, resume_pc;off_t ins_offset, fixup_offset;struct exception_table_entry *ex;
@@ -740,20 +844,22 @@ static int add_exception_handler(const struct bpf_insn *insn,if (BPF_MODE (insn->code) !=BPF_PROBE_MEM &&BPF_MODE (insn->code) !=BPF_PROBE_MEMSX &&BPF_MODE (insn->code) !=BPF_PROBE_MEM32 && -BPF_MODE (insn->code) !=BPF_PROBE_MEM32SX ) +BPF_MODE (insn->code) !=BPF_PROBE_MEM32SX && +BPF_MODE (insn->code) !=BPF_PROBE_ATOMIC )return 0 ;if (WARN_ON_ONCE (ctx->num_exentries >= ctx->prog->aux->num_exentries))return -EINVAL ; ex = &ctx->prog->aux->extable[ctx->num_exentries]; - pc = (unsigned long )&ctx->ro_image[ctx->idx -1 ]; + pc = (unsigned long )&ctx->ro_image[fault_idx]; + resume_pc = (unsigned long )&ctx->ro_image[resume_idx];/* * This is the relative offset of the instruction that may fault from * the exception table itself. This will be written to the exception * table and if this instruction faults, the destination register will -* be set to '0' and the execution will jump to the next instruction. +* be set to '0' and the execution will jump to @resume_pc. */ ins_offset = pc - (long )&ex->insn;if (WARN_ON_ONCE (ins_offset >=0 || ins_offset <INT_MIN ))
@@ -767,10 +873,10 @@ static int add_exception_handler(const struct bpf_insn *insn,* modifying the upper bits because the table is already sorted, and * isn't part of the main exception table. * -* The fixup_offset is set to the next instruction from the instruction -* that may fault. The execution will jump to this after handling the fault. +* The fixup_offset is set to the resume instruction. The execution will +* jump to this after handling the fault. */ - fixup_offset = (long )&ex->fixup - (pc +LOONGARCH_INSN_SIZE ); + fixup_offset = (long )&ex->fixup - resume_pc;if (!FIELD_FIT (BPF_FIXUP_OFFSET_MASK , fixup_offset))return -ERANGE ;
@@ -789,6 +895,14 @@ static int add_exception_handler(const struct bpf_insn *insn,return 0 ; } +/* The faulting instruction is the one just emitted; resume at the next. */ +static int add_exception_handler (const struct bpf_insn *insn, +struct jit_ctx *ctx,int dst_reg) +{ +return __add_exception_handler (insn, ctx, dst_reg, + ctx->idx -1 , ctx->idx); +} +static int build_insn (const struct bpf_insn *insn,struct jit_ctx *ctx,bool extra_pass) {u8 tm =-1 ;
@@ -1545,6 +1659,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extcase BPF_STX |BPF_ATOMIC |BPF_H :case BPF_STX |BPF_ATOMIC |BPF_W :case BPF_STX |BPF_ATOMIC |BPF_DW : +case BPF_STX |BPF_PROBE_ATOMIC |BPF_B : +case BPF_STX |BPF_PROBE_ATOMIC |BPF_H : +case BPF_STX |BPF_PROBE_ATOMIC |BPF_W : +case BPF_STX |BPF_PROBE_ATOMIC |BPF_DW :if (!bpf_atomic_is_load_store (insn)) ret =emit_atomic_rmw (insn, ctx);else
@@ -2557,16 +2675,12 @@ 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 : -/* Atomics on arena pointers are not implemented yet. */ -return false; - } - +/* +* All arena access instructions are implemented: regular and +* sign-extending loads/stores (BPF_PROBE_MEM32 / BPF_PROBE_MEM32SX) +* and atomics (BPF_PROBE_ATOMIC). The default weak helper rejects +* everything, so the override is required to enable arena programs. +*/ return true; }
Signature · 1 line
2.25.1
PATCH v2 8/11 selftests/bpf: Enable struct_ops private stack test for LoongArch
In reply to George GuoFrom: George Guo <[email protected]>
LoongArch now supports BPF private stacks via bpf_jit_supports_private_stack(), so let the struct_ops private stack runtime test (private_stack / private_stack_fail / private_stack_recur) run there instead of being skipped.
--- .../testing/selftests/bpf/prog_tests/struct_ops_private_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c +1 -1
@@ -5,7 +5,7 @@#include "struct_ops_private_stack_fail.skel.h" #include "struct_ops_private_stack_recur.skel.h" -#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || defined(__loongarch__)static void test_private_stack (void ) {struct struct_ops_private_stack *skel;
Signature · 1 line
2.25.1
PATCH v2 9/11 selftests/bpf: Enable arena LDSX tests on LoongArch
In reply to George GuoFrom: George Guo <[email protected]>
The verifier test_loader only runs an __arch_*-tagged test when the tag matches the running architecture. The arena sign-extending load (LDSX) subtests in verifier_ldsx are tagged for x86_64 and arm64 only, so they are skipped on LoongArch even though the JIT now supports the instruction.
Tag the arena LDSX subtests (disasm, exception, S8, S16, S32) with __arch_loongarch, and add the expected LoongArch JIT disassembly to the disasm subtest, so they run and are checked there.
--- .../testing/selftests/bpf/progs/verifier_ldsx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
tools/testing/selftests/bpf/progs/verifier_ldsx.c +17 -0
@@ -286,6 +286,19 @@ __jited("add x11, x0, x28") __jited("ldrsh x22, [x11, #0x18]") __jited("add x11, x0, x28") __jited("ldrsb x22, [x11, #0x20]") +__arch_loongarch +__jited("add.d $t2, $a5, $s6") +__jited("ld.w $s2, $t2, 16") +__jited("add.d $t2, $a5, $s6") +__jited("ld.h $s2, $t2, 24") +__jited("add.d $t2, $a5, $s6") +__jited("ld.b $s2, $t2, 32") +__jited("add.d $t2, $a0, $s6") +__jited("ld.w $s3, $t2, 16") +__jited("add.d $t2, $a0, $s6") +__jited("ld.h $s3, $t2, 24") +__jited("add.d $t2, $a0, $s6") +__jited("ld.b $s3, $t2, 32")__naked void arena_ldsx_disasm (void *ctx) { asm volatile (
@@ -317,6 +330,7 @@ __description("Arena LDSX Exception") __success __retval(0) __arch_x86_64 __arch_arm64 +__arch_loongarch__naked voidarena_ldsx_exception (void *ctx) { asm volatile (
@@ -338,6 +352,7 @@ __description("Arena LDSX, S8") __success __retval(-1) __arch_x86_64 __arch_arm64 +__arch_loongarch__naked voidarena_ldsx_s8 (void *ctx) { asm volatile (
@@ -369,6 +384,7 @@ __description("Arena LDSX, S16") __success __retval(-1) __arch_x86_64 __arch_arm64 +__arch_loongarch__naked voidarena_ldsx_s16 (void *ctx) { asm volatile (
@@ -400,6 +416,7 @@ __description("Arena LDSX, S32") __success __retval(-1) __arch_x86_64 __arch_arm64 +__arch_loongarch__naked voidarena_ldsx_s32 (void *ctx) { asm volatile (
Signature · 1 line
2.25.1
PATCH v2 10/11 selftests/bpf: Enable arena atomics tests on LoongArch
In reply to George GuoFrom: George Guo <[email protected]>
Now that the LoongArch JIT implements atomic operations on arena pointers, add LoongArch to the arena_atomics load-acquire/store-release architecture guard so those subtests run on LoongArch.
--- tools/testing/selftests/bpf/progs/arena_atomics.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/bpf/progs/arena_atomics.c +3 -0
@@ -29,6 +29,7 @@ bool skip_all_tests = true;#if defined(ENABLE_ATOMICS_TESTS ) && \ defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ + defined(__TARGET_ARCH_loongarch) || \ (defined(__TARGET_ARCH_riscv) && __riscv_xlen ==64 )) bool skip_lacq_srel_tests __attribute((__section__(".data"))) = false;#else
@@ -316,6 +317,7 @@ int load_acquire(const void *ctx)#if defined(ENABLE_ATOMICS_TESTS ) && \ defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ + defined(__TARGET_ARCH_loongarch) || \ (defined(__TARGET_ARCH_riscv) && __riscv_xlen ==64 ))#define LOAD_ACQUIRE_ARENA (SIZEOP ,SIZE ,SRC ,DST ) \
@@ -368,6 +370,7 @@ int store_release(const void *ctx)#if defined(ENABLE_ATOMICS_TESTS ) && \ defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ + defined(__TARGET_ARCH_loongarch) || \ (defined(__TARGET_ARCH_riscv) && __riscv_xlen ==64 ))#define STORE_RELEASE_ARENA (SIZEOP ,DST ,VAL ) \
Signature · 1 line
2.25.1
PATCH v2 11/11 selftests/bpf: Add LoongArch deny list
In reply to George GuoFrom: George Guo <[email protected]>
Add an empty test_progs deny list for LoongArch, mirroring the other architectures, so BPF CI and local vmtest have a place to record cases that cannot pass on LoongArch.
--- tools/testing/selftests/bpf/DENYLIST.loongarch | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/testing/selftests/bpf/DENYLIST.loongarch
tools/testing/selftests/bpf/DENYLIST.loongarch new file +1 -0
@@ -0,0 +1 @@ +# loongarch64 deny list for BPF CI and local vmtest
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH bpf-next v2 01/11] LoongArch: BPF: Fix tail call count pointer offset for arena programs
In reply to George GuoThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The newly added multi-line comments violate the BPF subsystem's preferred comment style. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added multi-line comments violate the BPF subsystem's preferred comment style. --
commit a7174bab96fc4c6edb488f83bc8733f74eac78c7
Author: George Guo <[email protected]>
LoongArch: BPF: Fix tail call count pointer offset for arena programs
This commit replaces the BPF_TAIL_CALL_CNT_PTR_STACK_OFF macro with a helper function, tail_call_cnt_ptr_stack_off(). This function properly accounts for the REG_ARENA slot in arena programs, resolving an issue where the JIT loaded the counter value instead of the tail call count pointer.
Quoted 6 lines
arch/loongarch/net/bpf_jit.c +0
-0@@ -25,7 +25,23 @@
arch/loongarch/net/bpf_jit.c line 34
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +7
-1#define REG_TCC LOONGARCH_GPR_A6#define REG_ARENA LOONGARCH_GPR_S6/* For storing arena_vm_start */ -#define BPF_TAIL_CALL_CNT_PTR_STACK_OFF (stack) (round_up(stack, 16) - 80) + +static int tail_call_cnt_ptr_stack_off (struct jit_ctx *ctx) +{ +/* Ten words are pushed below the BPF stack: ra, fp, s0-s5, and the +* tail call count plus its pointer, which occupy the two deepest +* slots of the callee-saved area. +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment format adhere to the BPF subsystem's preferred style? Multi-line comments in BPF-related paths usually require the opening /* to be on its own line.
arch/loongarch/net/bpf_jit.c line 39
Quoted 5 lines
arch/loongarch/net/bpf_jit.c +5
-0+int offset =sizeof (long ) *10 ; + +/* An arena program reserves one extra word above them (REG_ARENA), +* which pushes the tail call count pointer down by one slot. +*/
[Severity: Low]
This isn't a bug, but this comment also doesn't follow the preferred BPF subsystem multi-line comment style of placing the opening /* on its own line.
Quoted 5 lines
arch/loongarch/net/bpf_jit.c +5
-0+if (ctx->arena_vm_start) + offset +=sizeof (long ); + +return round_up (ctx->stack_size,16 ) - offset; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH bpf-next v2 05/11] LoongArch: BPF: Add exceptions (bpf_throw) support
In reply to George GuoThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The BPF frame pointer ($r22) can be clobbered by bpf_throw() before it is captured, causing stack…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The BPF frame pointer ($r22) can be clobbered by bpf_throw() before it is captured, causing stack unwinding to fail and crash.
- [Low] Multi-line comment does not follow the required BPF kernel comment style.
--
commit a22e7d51563237179d5ffdc8ffe6290c25f1ddba
Author: George Guo <[email protected]>
LoongArch: BPF: Add exceptions (bpf_throw) support
This patch implements BPF exception support for LoongArch. It introduces arch_bpf_stack_walk() to find the exception boundary frame using the ORC unwinder, allowing bpf_throw() to properly unwind the stack and invoke the exception callback.
Quoted 4 lines
arch/loongarch/kernel/stacktrace.c +0
-0
[ ... ]
Quoted 11 lines
arch/loongarch/kernel/stacktrace.c +11
-0+void arch_bpf_stack_walk (bool (*consume_fn)(void *cookie,u64 ip,u64 sp,u64 bp), +void *cookie) +{ +unsigned long fp; + +/* +* Capture the live frame pointer ($r22/$fp) here, before handing off to +* the worker. The kernel is built with -fomit-frame-pointer, so $fp is +* an ordinary callee-saved register that is preserved across the call +* from the JITed BPF program into bpf_throw() down to here, and thus +* still points at the innermost BPF frame. The ORC frame-pointer
arch/loongarch/kernel/stacktrace.c void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, · line 92
Quoted 10 lines
arch/loongarch/kernel/stacktrace.c +10
-0+* fallback walks the BPF frames up to the exception boundary from it. +* +* This must be a thin wrapper with no large stack locals: the worker +* uses $r22 to address its frame, which would clobber the live $fp +* before it could be read. __builtin_frame_address() cannot be used +* either, as it is $sp-derived and would yield a kernel-stack frame. +*/ + asmvolatile ("move %0, $r22" :"=r" (fp)); +walk_stackframe_bpf (consume_fn, cookie, fp); +}
[Severity: High]
Can the C compiler clobber the BPF frame pointer ($r22) before this inline assembly captures it?
Because the kernel is built with -fomit-frame-pointer, the compiler is free to use $r22 as a general-purpose callee-saved register. If the intermediate C caller (bpf_throw) modifies $r22 during its execution, this assembly will capture the clobbered value instead of the BPF frame pointer.
If the frame pointer is clobbered, the ORC unwinder will fail to find the exception boundary, leaving ctx.aux as NULL. bpf_throw() then unconditionally dereferences ctx.aux, which would cause a kernel panic.
Quoted 8 lines
arch/loongarch/net/bpf_jit.c +0
-0@@ -29,16 +29,20 @@static int tail_call_cnt_ptr_stack_off (struct jit_ctx *ctx) {
[ ... ]
arch/loongarch/net/bpf_jit.c line 44
Quoted 6 lines
arch/loongarch/net/bpf_jit.c +3
-2-/* An arena program reserves one extra word above them (REG_ARENA), -* which pushes the tail call count pointer down by one slot. +/* An arena or exception program reserves one extra word above them +* ($s6, see build_prologue()), which pushes the tail call count +* pointer down by one slot. */
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the BPF subsystem comment style? The BPF subsystem requires the opening /* of a multi-line comment to be on its own line.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH bpf-next v2 07/11] LoongArch: BPF: Support atomics on arena pointers
In reply to George GuoThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Critical] Faulting arena atomic operations fail to clear their destination registers, defeating the verifier's zero-extension tracking and enabling arbitrary out-of-bounds memory access.
- [High] Missing exception table entry for the sc (Store Conditional) instruction in BPF_PROBE_ATOMIC cmpxchg allows trivial kernel panics.
Pre-existing issues:
- [High] LoongArch's ex_handler_bpf does not report arena violations, breaking standard BPF arena semantics. --
commit 445332124b454806c0eb995caa9dad9e7668feba
Author: George Guo <[email protected]>
LoongArch: BPF: Support atomics on arena pointers
This commit implements atomic operations on arena pointers (BPF_PROBE_ATOMIC) for LoongArch. It adds exception table entries to handle page faults for these memory accesses.
Quoted 4 lines
arch/loongarch/net/bpf_jit.c +0
-0
[ ... ]
arch/loongarch/net/bpf_jit.c static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx) · line 607
Quoted 9 lines
arch/loongarch/net/bpf_jit.c +1
-0@@ -585,12 +600,14 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)case BPF_CMPXCHG :move_reg (ctx, t2, r0);if (isdw) { + ll_idx = ctx->idx;emit_insn (ctx, lld, r0, t1,0 );emit_insn (ctx, bne, t2, r0,4 );move_reg (ctx, t3, src);emit_insn (ctx, scd, t3, t1,0 );
[Severity: High]
Does this Store Conditional (scd) instruction need an exception table entry? If a BPF program executes a BPF_CMPXCHG operation on a read-only or Copy-On-Write (COW) arena page, the Load Linked (lld) instruction will succeed because it is a read, but the subsequent Store Conditional instruction could trigger a page fault due to the write violation. Since there is no exception table entry registered for this scd instruction, would this result in an unhandled kernel page fault oops?
Quoted 2 lines
arch/loongarch/net/bpf_jit.c +0
-0emit_insn (ctx, beq, t3,LOONGARCH_GPR_ZERO ,-4 ); }else {
[ ... ]
Quoted 5 lines
arch/loongarch/net/bpf_jit.c +1
-0@@ -600,12 +617,42 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)emit_insn (ctx, beq, t3,LOONGARCH_GPR_ZERO ,-6 );emit_zext_32 (ctx, r0, true); } +/*
arch/loongarch/net/bpf_jit.c static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx) · line 630
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +10
-0+* On arena the ll may fault (unmapped page); the page-fault +* handler restarts the program at @resume. Only the ll needs an +* entry: if it faults the sc is never reached, and once the ll +* succeeds the page is mapped so the sc cannot fault. Resume +* past the whole ll/sc loop. +*/ +if (arena) { + ret =__add_exception_handler (insn, ctx, +REG_DONT_CLEAR_MARKER , + ll_idx, ctx->idx);
[Severity: Critical]
Should the actual destination register (r0) be cleared here instead of using REG_DONT_CLEAR_MARKER? If a fault occurs on the arena pointer, the destination register retains its old value instead of being cleared. Because the verifier assumes the register has been bounded (e.g., upper 32-bits zeroed), leaving the hardware register with an unbounded value might allow out-of-bounds memory accesses.
Quoted 8 lines
arch/loongarch/net/bpf_jit.c +3
-0+if (ret) +return ret; + }break ;default :pr_err_once ("bpf-jit: invalid atomic read-modify-write opcode %02x\n" , imm);return -EINVAL ; }
arch/loongarch/net/bpf_jit.c static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx) · line 648
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +9
-0+/* +* For the single-instruction am* ops the memory access is the last +* emitted instruction; register its exception entry before emitting the +* deferred zero-extend so the fault resumes past it. cmpxchg handled +* its own entry above. +*/ +if (arena && imm !=BPF_CMPXCHG ) { + ret =__add_exception_handler (insn, ctx,REG_DONT_CLEAR_MARKER , + ctx->idx -1 , ctx->idx + (zext ?1 :0 ));
[Severity: Critical]
Is it safe to pass REG_DONT_CLEAR_MARKER for fetch atomics? Similar to the cmpxchg case, if an exception occurs on an invalid arena pointer, the source register is not cleared. This can cause a divergence from the verifier's zero extension tracking and potentially allow out-of-bounds memory accesses.
Quoted 9 lines
arch/loongarch/net/bpf_jit.c +7
-0+if (ret) +return ret; + } + +if (zext) +emit_zext_32 (ctx, src, true); +return 0 ; }
[ ... ]
Quoted 20 lines
arch/loongarch/net/bpf_jit.c +12
-0@@ -616,10 +663,37 @@ static int emit_atomic_ld_st(const struct bpf_insn *insn, struct jit_ctx *ctx)const u8 dst = regmap[insn->dst_reg];const s16 off = insn->off;const s32 imm = insn->imm; +const bool arena =BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ; +int ret;switch (imm) {/* dst_reg = load_acquire(src_reg + off16) */ case BPF_LOAD_ACQ : +if (arena) { +/* t1 = src + off + arena_vm_start; load from [t1]. */ +move_imm (ctx, t1, off, false); +emit_insn (ctx, addd, t1, src, t1); +emit_insn (ctx, addd, t1, t1,REG_ARENA ); +switch (BPF_SIZE (insn->code)) { +case BPF_B : +emit_insn (ctx, ldbu, dst, t1,0 ); +break ; +case BPF_H :
arch/loongarch/net/bpf_jit.c static int emit_atomic_ld_st(const struct bpf_insn *insn, struct jit_ctx *ctx) · line 691
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +10
-0+emit_insn (ctx, ldhu, dst, t1,0 ); +break ; +case BPF_W : +emit_insn (ctx, ldwu, dst, t1,0 ); +break ; +case BPF_DW : +emit_insn (ctx, ldd, dst, t1,0 ); +break ; + } + ret =add_exception_handler (insn, ctx,REG_DONT_CLEAR_MARKER );
[Severity: Critical]
Could we pass the actual destination register rather than REG_DONT_CLEAR_MARKER here? If the load acquisition faults on an unmapped arena pointer, the destination register will not be cleared. The verifier expects it to be cleared or bounded, which could allow out-of-bounds memory reads if the register keeps its prior unbounded value.
Quoted 5 lines
arch/loongarch/net/bpf_jit.c +5
-0+if (ret) +return ret; +emit_insn (ctx, dbar,0b10100 ); +break ; + }
[ ... ]
Quoted 12 lines
arch/loongarch/net/bpf_jit.c +0
-4@@ -708,10 +807,6 @@ static bool is_signed_bpf_cond(u8 cond) cond ==BPF_JSGE || cond ==BPF_JSLE ; } -#define BPF_FIXUP_REG_MASK GENMASK(31, 27) -#define BPF_FIXUP_OFFSET_MASK GENMASK(26, 0) -#define REG_DONT_CLEAR_MARKER 0 -bool ex_handler_bpf (const struct exception_table_entry *ex,struct pt_regs *regs) {
arch/loongarch/net/bpf_jit.c bool ex_handler_bpf(const struct exception_table_entry *ex, · line 821
Quoted 2 lines
arch/loongarch/net/bpf_jit.c +0
-0@@ -725,12 +820,21 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,return true; }
[Severity: High]
This is a pre-existing issue, but does ex_handler_bpf() need to report arena violations to user space? If a BPF program accesses an out-of-bounds arena pointer (such as the guard bands), this handler clears the destination register and resumes execution without delivering a SIGSEGV. Standard BPF arena semantics usually require calling bpf_prog_report_arena_violation() in this path to ensure the user space process is properly signaled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH bpf-next v2 10/11] selftests/bpf: Enable arena atomics tests on LoongArch
In reply to George GuoThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch enables arena atomics tests for LoongArch in `arena_atomics.c` but misses the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch enables arena atomics tests for LoongArch in arena_atomics.c but misses the identical architecture guard in test_parallel_spmc.bpf.c, failing to enable the libarena SPMC parallel tests. --
commit 6a78ab7798074b26b2ec91b91c15b4a58e0531a1
Author: George Guo <[email protected]>
selftests/bpf: Enable arena atomics tests on LoongArch
This patch adds LoongArch to the arena_atomics load-acquire/store-release architecture guards so those subtests are executed.
tools/testing/selftests/bpf/progs/arena_atomics.c bool skip_all_tests = true; · line 33
Quoted 10 lines
tools/testing/selftests/bpf/progs/arena_atomics.c +1
-0@@ -29,6 +29,7 @@ bool skip_all_tests = true;#if defined(ENABLE_ATOMICS_TESTS ) && \ defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \ (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ + defined(__TARGET_ARCH_loongarch) || \ (defined(__TARGET_ARCH_riscv) && __riscv_xlen ==64 ))
[Severity: Medium]
Should this patch also update the architecture guard in tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c?
It looks like spmc_tests_enabled() in that file has an identical architecture guard for arena atomics that currently misses LoongArch. Without adding it there as well, those parallel SPMC arena atomics tests will be skipped and return -EOPNOTSUPP.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Huacai Chen
maintainerHi, Tiezhu and Hengqi,
Could you please pay some time to review this series?
Huacai
Quoted 73 lines · George Guo
This series adds the remaining LoongArch BPF JIT features and enables the matching selftests:
- internal-only MOV for per-CPU address resolution
- timedmay_goto
- per-program private stacks
- exceptions (bpf_throw)
- sign-extending loads from arena (PROBE_MEM32SX)
- atomics on arena pointers (PROBE_ATOMIC)
- selftests:struct_opsprivate stack, arena LDSX, arena atomics, and a LoongArch deny listPatch 1 ("LoongArch: BPF: Fix tail call count pointer offset for arena programs") is the same fix already posted separately for the bpf tree; several patches in this series (notably exceptions, patch 5) build on top of the helper it introduces, so it is included here, unchanged, to keep the series self-contained and applicable on bpf-next. It can be dropped once it lands via the bpf tree.
LoongArch: BPF: Fix tail call count pointer offset for arena programs
https://lore.kernel.org/all/[email protected]Based on 7.2-rc1.
v2:
- Included the tail call count pointer offset fix as patch 1/11 (see above) instead of only referencing it, so the series applies cleanly on bpf-next without waiting on the bpf tree; the emptyprog_arrayoff-by-one was fixed independently upstream by commit0379d10f09bc("LoongArch: BPF: Fix off-by-one error in tail call"), now in 7.2-rc1.
- timedmay_goto: store $ra at the ORC-mandated .ra_offset = -8 slot in the trampoline (it was stored at the wrong slot in v1), per Tiezhu Yang's review.
- Consolidated the earlier per-CPU MOV / timedmay_gotoand arena gating postings into one series; rebased on 7.2-rc1.
- selftests: use the upstream__arch_loongarch/ "LOONGARCH"test_loadersupport now in 7.2-rc1 instead of introducing it.
- Prior postings:https://lore.kernel.org/all/[email protected] https://lore.kernel.org/all/[email protected]George Guo (11):
LoongArch: BPF: Fix tail call count pointer offset for arena programs
LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
LoongArch: BPF: Add timedmay_gotosupport
LoongArch: BPF: Add private stack support
LoongArch: BPF: Add exceptions (bpf_throw) support
LoongArch: BPF: Support sign-extending loads from arena
LoongArch: BPF: Support atomics on arena pointers selftests/bpf: Enablestruct_opsprivate stack test for LoongArch selftests/bpf: Enable arena LDSX tests on LoongArch selftests/bpf: Enable arena atomics tests on LoongArch selftests/bpf: Add LoongArch deny listarch/loongarch/include/asm/inst.h | 1 + arch/loongarch/kernel/stacktrace.c | 52 +++ arch/loongarch/net/Makefile | 2 +- arch/loongarch/net/bpf_jit.c | 397 ++++++++++++++++-- arch/loongarch/net/bpf_jit.h | 1 + arch/loongarch/net/bpf_timed_may_goto.S | 47 +++ .../testing/selftests/bpf/DENYLIST.loongarch | 1 + .../bpf/prog_tests/struct_ops_private_stack.c | 2 +- .../selftests/bpf/progs/arena_atomics.c | 3 + .../selftests/bpf/progs/verifier_ldsx.c | 17 + 10 files changed, 485 insertions(+), 38 deletions(-) create mode 100644 arch/loongarch/net/bpf_timed_may_goto.S create mode 100644 tools/testing/selftests/bpf/DENYLIST.loongarch--
2.25.1
Tiezhu Yang
maintainerRe: [PATCH bpf-next v2 01/11] LoongArch: BPF: Fix tail call count pointer offset for arena programs
In reply to George GuoQuoted 51 lines · George Guo
From: George Guo <[email protected]>
The tail call count (TCC) and its pointer occupy the two deepest slots of the callee-saved area set up by
build_prologue(). An arena program reserves one extra word forREG_ARENA(arena_vm_start) right above them:ra fp s0 s1 s2 s3 s4 s5 <- 8 words
[REG_ARENA] <- only ifctx->arena_vm_start
tail_call_cnt
tail_call_cnt_ptr<- loaded on tail call / bpf2bpf call
BPF_TAIL_CALL_CNT_PTR_STACK_OFF()hardcodes the pointer atround_up(stack, 16)- 80, which is only correct whenREG_ARENAis absent. For an arena program the extra word shifts every slot below it down by 8 bytes, so the macro resolves to thetail_call_cntslot (the counter value) instead oftail_call_cnt_ptr. The JIT then loads the counter value and dereferences it as the TCC pointer, corrupting memory or panicking the kernel whenever an arena program performs a tail call or a bpf2bpf call.Replace the macro with a helper that accounts for the
REG_ARENAslot, mirroring the reservation logic inbuild_prologue().This is the same fix already posted separately for the bpf tree; it is included here, as patch 1/11, only so the rest of this series applies and builds cleanly on top of it. It can be dropped from this series once it lands via the bpf tree.
https://lore.kernel.org/all/[email protected]Fixes ef54c517a937 ("LoongArch: BPF: Implement PROBE_MEM32 pseudo instructions")Signed-off-by George Guo <[email protected]>--- arch/loongarch/net/bpf_jit.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)arch/loongarch/net/bpf_jit.c +7
-1@@ -25,7 +25,23 @@#define REG_TCC LOONGARCH_GPR_A6#define REG_ARENA LOONGARCH_GPR_S6/* For storing arena_vm_start */ -#define BPF_TAIL_CALL_CNT_PTR_STACK_OFF (stack) (round_up(stack, 16) - 80) + +static int tail_call_cnt_ptr_stack_off (struct jit_ctx *ctx) +{ +/* Ten words are pushed below the BPF stack: ra, fp, s0-s5, and the +* tail call count plus its pointer, which occupy the two deepest +* slots of the callee-saved area. +*/
arch/loongarch/net/bpf_jit.c line 44
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +10
-0+int offset =sizeof (long ) *10 ; + +/* An arena program reserves one extra word above them (REG_ARENA), +* which pushes the tail call count pointer down by one slot. +*/ +if (ctx->arena_vm_start) + offset +=sizeof (long ); + +return round_up (ctx->stack_size,16 ) - offset; +}
This introduces a runtime helper to dynamically calculate the stack offset. If another optional slot is introduced in the future, this helper will need further adjustments.
Quoted 12 lines
arch/loongarch/net/bpf_jit.c +1
-1static const int regmap[] = {/* return value from in-kernel function, and exit value for eBPF program */ @@ -291,7 +307,7 @@ bool bpf_jit_supports_far_kfunc_call(void)static int emit_bpf_tail_call (struct jit_ctx *ctx,int insn) {int off, tc_ninsn =0 ; -int tcc_ptr_off =BPF_TAIL_CALL_CNT_PTR_STACK_OFF (ctx->stack_size); +int tcc_ptr_off =tail_call_cnt_ptr_stack_off (ctx);u8 a1 =LOONGARCH_GPR_A1 ;u8 a2 =LOONGARCH_GPR_A2 ;u8 t1 =LOONGARCH_GPR_T1 ;
arch/loongarch/net/bpf_jit.c static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext · line 1203
Quoted 8 lines
arch/loongarch/net/bpf_jit.c +1
-1@@ -1181,7 +1197,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extreturn ret;if (insn->src_reg ==BPF_PSEUDO_CALL ) { - tcc_ptr_off =BPF_TAIL_CALL_CNT_PTR_STACK_OFF (ctx->stack_size); + tcc_ptr_off =tail_call_cnt_ptr_stack_off (ctx);emit_insn (ctx, ldd,REG_TCC ,LOONGARCH_GPR_SP , tcc_ptr_off); }
Please see the following simple and long-term solution, just move the arena slot below TCC context slots, this ensures a constant offset, reducing complex runtime calculations and eliminating extra instructions.
LoongArch: BPF: Optimize redundant TCC loads in epilogue
https://lore.kernel.org/loongarch/[email protected]/
LoongArch: BPF: Move arena register slot below TCC context
https://lore.kernel.org/loongarch/[email protected]/
Thanks,
Tiezhu
Tiezhu Yang
maintainerRe: [PATCH bpf-next v2 11/11] selftests/bpf: Add LoongArch deny list
In reply to George GuoQuoted 18 lines · George Guo
From: George Guo <[email protected]>
Add an empty
test_progsdeny list for LoongArch, mirroring the other architectures, so BPF CI and local vmtest have a place to record cases that cannot pass on LoongArch.Signed-off-by George Guo <[email protected]>--- tools/testing/selftests/bpf/DENYLIST.loongarch | 1 + 1 file changed, 1 insertion(+)create mode 100644
tools/testing/selftests/bpf/DENYLIST.loongarchtools/testing/selftests/bpf/DENYLIST.loongarch new file +0
-0
tools/testing/selftests/bpf/DENYLIST.loongarch line 1
Quoted 1 line
tools/testing/selftests/bpf/DENYLIST.loongarch new file +1
-0@@ -0,0 +1 @@ +# loongarch64 deny list for BPF CI and local vmtest
LoongArch doesn't have an active BPF CI yet, there is no need to add an empty DENYLIST.
If there are already known test failures on LoongArch, it would be much more valuable to either:
1. Fix those failures directly, or
2. Report those failures.
We should only consider adding CI after all current test failures are resolved.
Thanks,
Tiezhu
Tiezhu Yang
maintainerRe: [PATCH bpf-next v2 02/11] LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
In reply to George GuoQuoted 35 lines · George Guo
From: George Guo <[email protected]>
Support the internal-only
BPF_MOVinstruction that resolves the absolute address of per-CPU data from its per-CPU offset. This instruction is used only for internal inlining optimizations between the BPF verifier and the JITs (e.g. inliningbpf_get_smp_processor_id()and per-CPU map lookups).LoongArch keeps the per-CPU offset of the current CPU in $r21 (
__my_cpu_offset), so resolving a per-CPU address only requires adding $r21 to the source register holding the per-CPU offset. Advertise the capability viabpf_jit_supports_percpu_insn().Signed-off-by George Guo <[email protected]>--- arch/loongarch/include/asm/inst.h | 1 + arch/loongarch/net/bpf_jit.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)arch/loongarch/include/asm/inst.h +1
-0@@ -404,6 +404,7 @@ enum loongarch_gpr {LOONGARCH_GPR_T6 ,LOONGARCH_GPR_T7 ,LOONGARCH_GPR_T8 , +LOONGARCH_GPR_U0 =21 ,/* Kernel per-CPU base register ($r21) */ LOONGARCH_GPR_FP =22 ,LOONGARCH_GPR_S0 =23 , LOONGARCH_GPR_S1,arch/loongarch/net/bpf_jit.c +0
-0
arch/loongarch/net/bpf_jit.c static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext · line 768
Quoted 10 lines
arch/loongarch/net/bpf_jit.c +7
-0@@ -759,6 +759,15 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extmove_reg (ctx, dst, t1);break ; } +if (insn_is_mov_percpu_addr (insn)) { +if (dst != src) +move_reg (ctx, dst, src); +#ifdef CONFIG_SMP +/* dst += __my_cpu_offset, held in $r21 */ +emit_insn (ctx, addd, dst, dst,LOONGARCH_GPR_U0 ); +#endif
How to test? Did you test under !CONFIG_SMP?
Thanks,
Tiezhu
Tiezhu Yang
maintainerRe: [PATCH bpf-next v2 07/11] LoongArch: BPF: Support atomics on arena pointers
In reply to George GuoQuoted 16 lines · George Guo
From: George Guo <[email protected]>
Implement atomic operations on arena pointers (
BPF_PROBE_ATOMIC): the read-modify-write ops, atomic_fetch_*, xchg, cmpxchg and load-acquire/store-release. For each, the arena base held inREG_ARENAis folded into the address and an exception table entry is registered on the access so a fault is handled like the other arena probes.The exception entry must point at the actual memory-accessing instruction rather than the last one emitted: the fetch variants append a zero-extend after the am* op, and cmpxchg accesses memory with the ll of an ll/sc loop. Generalise
add_exception_handler()to take explicit fault and resume instruction indices. A faulting ll resumes past the whole ll/sc loop: if the ll faults the sc is never reached, and once the ll succeeds the page is mapped so the sc cannot fault, so a single entry on the ll suffices.
...
arch/loongarch/net/bpf_jit.c bool bpf_jit_supports_arena(void) · line 2569
Quoted 13 lines
bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena) {arch/loongarch/net/bpf_jit.c +0
-10-if (!in_arena) -return true; - -switch (insn->code) { -case BPF_STX |BPF_ATOMIC |BPF_W : -case BPF_STX |BPF_ATOMIC |BPF_DW : -/* Atomics on arena pointers are not implemented yet. */ -return false; - } -
Adding code in patch 6 and deleting it in patch 7
is unnecessary code noise.
Please implement it cleanly in patch 6 from the start.
arch/loongarch/net/bpf_jit.c bool bpf_jit_supports_arena(void) · line 2685
Quoted 8 lines
arch/loongarch/net/bpf_jit.c +6
-0+/* +* All arena access instructions are implemented: regular and +* sign-extending loads/stores (BPF_PROBE_MEM32 / BPF_PROBE_MEM32SX) +* and atomics (BPF_PROBE_ATOMIC). The default weak helper rejects +* everything, so the override is required to enable arena programs. +*/ return true; }
Thanks,
Tiezhu
Tiezhu Yang
maintainerQuoted 11 lines · George Guo
This series adds the remaining LoongArch BPF JIT features and enables the matching selftests:
- internal-only MOV for per-CPU address resolution
- timedmay_goto
- per-program private stacks
- exceptions (bpf_throw)
- sign-extending loads from arena (PROBE_MEM32SX)
- atomics on arena pointers (PROBE_ATOMIC)
- selftests:struct_opsprivate stack, arena LDSX, arena atomics, and a LoongArch deny list
Please provide the test execution logs to ensure they don't fail.
Thanks,
Tiezhu
Re: [PATCH bpf-next v2 01/11] LoongArch: BPF: Fix tail call count pointer offset for arena programs
In reply to Tiezhu YangHi Tiezhu,
Thanks for reviewing!
Quoted 3 lines
This introduces a runtime helper to dynamically calculate the stack offset. If another optional slot is introduced in the future, this helper will need further adjustments.
Fair -- that's exactly the tradeoff. This patch was written to be the minimal, obviously-correct fix on top of the existing layout (arena slot above tcc/tcc_ptr) so it could go to the bpf tree as a standalone, backportable fix. It does mean any future optional slot needs another "if (...)" in the helper, as you say.
Quoted 10 lines
Please see the following simple and long-term solution, just move the arena slot below TCC context slots, this ensures a constant offset, reducing complex runtime calculations and eliminating extra instructions.
LoongArch: BPF: Optimize redundant TCC loads in epilogue
https://lore.kernel.org/loongarch/[email protected]/LoongArch: BPF: Move arena register slot below TCC context
https://lore.kernel.org/loongarch/[email protected]/
I read through both -- the reordering is a nice fix: with the arena slot moved below tcc_ptr instead of above it, tcc_ptr's offset from $fp stays a fixed 80 regardless of arena, so the original hardcoded macro is correct again everywhere and the runtime branch goes away entirely. Agreed that's the better long-term shape.
One thing to work out: this series (patch 5, exceptions/bpf_throw) also needs an optional extra slot for exception programs, using the same mechanism as arena (it currently piggybacks on the same ctx->arena_vm_start || is_exception_prog check your patch 2/4 would replace). If your reordering lands, I'd extend it the same way -- moving the exception-program slot below tcc_ptr too, rather than adding a runtime check back in.
Where does your series stand? I'd rather rebase this patch series on top of your fixed-offset approach once it's in bpf-next than have both land and immediately conflict. Let me know what's the best way to sequence these.
Thanks,
George
Tiezhu Yang
maintainerRe: [PATCH bpf-next v2 01/11] LoongArch: BPF: Fix tail call count pointer offset for arena programs
Quoted 38 lines · George Guo
Hi Tiezhu,
Thanks for reviewing!Quoted 3 lines
This introduces a runtime helper to dynamically calculate the stack offset. If another optional slot is introduced in the future, this helper will need further adjustments.
Fair -- that's exactly the tradeoff. This patch was written to be the minimal, obviously-correct fix on top of the existing layout (arena slot above tcc/tcc_ptr) so it could go to the bpf tree as a standalone, backportable fix. It does mean any future optional slot needs another "if (...)" in the helper, as you say.
Quoted 10 lines
Please see the following simple and long-term solution, just move the arena slot below TCC context slots, this ensures a constant offset, reducing complex runtime calculations and eliminating extra instructions.
LoongArch: BPF: Optimize redundant TCC loads in epilogue
https://lore.kernel.org/loongarch/[email protected]/LoongArch: BPF: Move arena register slot below TCC context
https://lore.kernel.org/loongarch/[email protected]/I read through both -- the reordering is a nice fix: with the arena slot moved below
tcc_ptrinstead of above it, tcc_ptr's offset from $fp stays a fixed 80 regardless of arena, so the original hardcoded macro is correct again everywhere and the runtime branch goes away entirely. Agreed that's the better long-term shape.One thing to work out: this series (patch 5, exceptions/bpf_throw) also needs an optional extra slot for exception programs, using the same mechanism as arena (it currently piggybacks on the same
ctx->arena_vm_start || is_exception_progcheck your patch 2/4 would replace). If your reordering lands, I'd extend it the same way -- moving the exception-program slot belowtcc_ptrtoo, rather than adding a runtime check back in.
Quoted 4 lines
Where does your series stand? I'd rather rebase this patch series on top of your fixed-offset approach once it's in bpf-next than have both land and immediately conflict. Let me know what's the best way to sequence these.
I am currently addressing the comments from the CI bot and will send out v3 shortly.
Once this series is upstream, you can rebase your patches on top of it.
Thanks,
Tiezhu
Re: [PATCH bpf-next v2 02/11] LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
In reply to Tiezhu YangQuoted 1 line
How to test? Did you test under !CONFIG_SMP?
Good question -- here's why skipping the $r21 add under !CONFIG_SMP is correct, not just untested:
1. $r21 is unconditionally zeroed at the earliest point in boot, regardless of CONFIG_SMP:
arch/loongarch/kernel/head.S:75
/* GPR21 used for percpu base (runtime), initialized as 0 */ move u0, zero
2. The only other writer, set_my_cpu_offset(), lives in arch/loongarch/kernel/smp.c, which is obj-$(CONFIG_SMP) += smp.o -- i.e. not even compiled into a !CONFIG_SMP kernel. So on !CONFIG_SMP, $r21 stays exactly 0 for the kernel's entire lifetime; nothing ever touches it again after head.S.
This also isn't a LoongArch-specific judgment call -- it's exactly the pattern x86's own upstream JIT uses for the identical instruction:
arch/x86/net/bpf_jit_comp.c, insn_is_mov_percpu_addr():
EMIT_mov(dst_reg, src_reg);
#ifdef CONFIG_SMP
/* add <dst>, gs:[<off>] */
...
#endifThanks,
George
Re: [PATCH bpf-next v2 07/11] LoongArch: BPF: Support atomics on arena pointers
In reply to Tiezhu YangQuoted 2 lines
Adding code in patch 6 and deleting it in patch 7 is unnecessary code noise. Please implement it cleanly in patch 6 from the start.
Agreed, will fix in the next revision -- patch 6 will introduce bpf_jit_supports_insn() without the atomics-rejection case at all, since patch 6 itself has nothing to do with atomics; patch 7 then won't need to touch the function.
Thanks,
George
Quoted 1 line
Please provide the test execution logs to ensure they don't fail.
Test execution logs below, LoongArch (2-vCPU QEMU/KVM 3A5000 guest), based on 7.2.0-rc1 + this series:
Feature Test(s)
--------------------------------------------------------------
1 offset / TCC pointer tailcalls 2 internal-only MOV (percpu) cpumask, percpu_alloc 3 timed may_goto iters 4 private stack struct_ops_private_stack 5 exceptions exceptions 6 sign-extending arena loads verifier_ldsx 7 arena atomics arena_atomics arena gating (regression check) arena_list, arena_htab, verifier_arena
$ sudo ./test_progs -t tailcalls #476/1 tailcalls/tailcall_1:OK #476/2 tailcalls/tailcall_2:OK #476/3 tailcalls/tailcall_3:OK #476/4 tailcalls/tailcall_4:OK #476/5 tailcalls/tailcall_5:OK #476/6 tailcalls/tailcall_6:OK #476/7 tailcalls/tailcall_bpf2bpf_1:OK #476/8 tailcalls/tailcall_bpf2bpf_2:OK #476/9 tailcalls/tailcall_bpf2bpf_3:OK #476/10 tailcalls/tailcall_bpf2bpf_4:OK #476/11 tailcalls/tailcall_bpf2bpf_5:OK #476/12 tailcalls/tailcall_bpf2bpf_6:OK #476/13 tailcalls/tailcall_bpf2bpf_fentry:OK #476/14 tailcalls/tailcall_bpf2bpf_fexit:OK #476/15 tailcalls/tailcall_bpf2bpf_fentry_fexit:OK #476/16 tailcalls/tailcall_bpf2bpf_fentry_entry:OK #476/17 tailcalls/tailcall_poke:OK #476/18 tailcalls/tailcall_bpf2bpf_hierarchy_1:OK #476/19 tailcalls/tailcall_bpf2bpf_hierarchy_fentry:OK #476/20 tailcalls/tailcall_bpf2bpf_hierarchy_fexit:OK #476/21 tailcalls/tailcall_bpf2bpf_hierarchy_fentry_fexit:OK #476/22 tailcalls/tailcall_bpf2bpf_hierarchy_fentry_entry:OK #476/23 tailcalls/tailcall_bpf2bpf_hierarchy_2:OK #476/24 tailcalls/tailcall_bpf2bpf_hierarchy_3:OK #476/25 tailcalls/tailcall_freplace:OK #476/26 tailcalls/tailcall_bpf2bpf_freplace:OK #476/27 tailcalls/tailcall_failure:OK #476/28 tailcalls/reject_tail_call_spin_lock:OK #476/29 tailcalls/reject_tail_call_rcu_lock:OK #476/30 tailcalls/reject_tail_call_preempt_lock:OK #476/31 tailcalls/reject_tail_call_ref:OK #476/32 tailcalls/tailcall_sleepable:OK #476/33 tailcalls/tailcall_cgrp_storage:OK #476/34 tailcalls/tailcall_cgrp_storage_diff_storage:OK #476/35 tailcalls/tailcall_cgrp_storage_no_storage:OK #476/36 tailcalls/tailcall_cgrp_storage_no_storage_leaf:OK #476/37 tailcalls/tailcall_cgrp_storage_no_storage_bridge:OK #476 tailcalls:OK Summary: 1/37 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t cpumask #98/1 cpumask/test_alloc_free_cpumask:OK #98/2 cpumask/test_set_clear_cpu:OK #98/3 cpumask/test_setall_clear_cpu:OK #98/4 cpumask/test_first_firstzero_cpu:OK #98/5 cpumask/test_firstand_nocpu:OK #98/6 cpumask/test_test_and_set_clear:OK #98/7 cpumask/test_and_or_xor:OK #98/8 cpumask/test_intersects_subset:OK #98/9 cpumask/test_copy_any_anyand:OK #98/10 cpumask/test_insert_leave:OK #98/11 cpumask/test_insert_remove_release:OK #98/12 cpumask/test_global_mask_rcu:OK #98/13 cpumask/test_global_mask_array_one_rcu:OK #98/14 cpumask/test_global_mask_array_rcu:OK #98/15 cpumask/test_global_mask_array_l2_rcu:OK #98/16 cpumask/test_global_mask_nested_rcu:OK #98/17 cpumask/test_global_mask_nested_deep_rcu:OK #98/18 cpumask/test_global_mask_nested_deep_array_rcu:OK #98/19 cpumask/test_cpumask_weight:OK #98/20 cpumask/test_refcount_null_tracking:OK #98/21 cpumask/test_populate_reject_small_mask:OK #98/22 cpumask/test_populate_reject_unaligned:OK #98/23 cpumask/test_populate:OK #98/24 cpumask/test_alloc_no_release:OK #98/25 cpumask/test_alloc_double_release:OK #98/26 cpumask/test_acquire_wrong_cpumask:OK #98/27 cpumask/test_mutate_cpumask:OK #98/28 cpumask/test_insert_remove_no_release:OK #98/29 cpumask/test_cpumask_null:OK #98/30 cpumask/test_global_mask_out_of_rcu:OK #98/31 cpumask/test_global_mask_no_null_check:OK #98/32 cpumask/test_global_mask_rcu_no_null_check:OK #98/33 cpumask/test_invalid_nested_array:OK #98/34 cpumask/test_populate_invalid_destination:OK #98/35 cpumask/test_populate_invalid_source:OK #98 cpumask:OK Summary: 1/35 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t percpu_alloc #288/1 percpu_alloc/array:OK #288/2 percpu_alloc/array_sleepable:OK #288/3 percpu_alloc/cgrp_local_storage:OK #288/4 percpu_alloc/failure_tests:OK #288/5 percpu_alloc/test_array_map_1:OK #288/6 percpu_alloc/test_array_map_2:OK #288/7 percpu_alloc/test_array_map_3:OK #288/8 percpu_alloc/test_array_map_4:OK #288/9 percpu_alloc/test_array_map_5:OK #288/10 percpu_alloc/test_array_map_6:OK #288/11 percpu_alloc/test_array_map_7:OK #288/12 percpu_alloc/test_array_map_8:OK #288/13 percpu_alloc/cpu_flag_percpu_array:OK #288/14 percpu_alloc/cpu_flag_percpu_hash:OK #288/15 percpu_alloc/cpu_flag_lru_percpu_hash:OK #288/16 percpu_alloc/cpu_flag_percpu_cgroup_storage:OK #288/17 percpu_alloc/cpu_flag_array:OK #288/18 percpu_alloc/cpu_flag_hash:OK #288 percpu_alloc:OK Summary: 1/18 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t iters #162/1 iters/force_clang_to_emit_btf_for_externs:OK #162/2 iters/create_and_destroy:OK #162/3 iters/create_and_forget_to_destroy_fail:OK #162/4 iters/destroy_without_creating_fail:OK #162/5 iters/compromise_iter_w_direct_write_fail:OK #162/6 iters/compromise_iter_w_direct_write_and_skip_destroy_fail:OK #162/7 iters/compromise_iter_w_helper_write_fail:OK #162/8 iters/leak_iter_from_subprog_fail:OK #162/9 iters/valid_stack_reuse:OK #162/10 iters/double_create_fail:OK #162/11 iters/double_destroy_fail:OK #162/12 iters/next_without_new_fail:OK #162/13 iters/next_after_destroy_fail:OK #162/14 iters/read_from_iter_slot_fail:OK #162/15 iters/stacksafe_should_not_conflate_stack_spill_and_iter:OK #162/16 iters/force_clang_to_emit_btf_for_externs:OK #162/17 iters/consume_first_item_only:OK #162/18 iters/missing_null_check_fail:OK #162/19 iters/wrong_sized_read_fail:OK #162/20 iters/simplest_loop:OK #162/21 iters/widening_stack_size_bug:OK #162/22 iters/iter_err_unsafe_c_loop:OK #162/23 iters/iter_err_unsafe_asm_loop:OK #162/24 iters/iter_err_too_permissive1:OK #162/25 iters/iter_err_too_permissive2:OK #162/26 iters/iter_err_too_permissive3:OK #162/27 iters/delayed_read_mark:OK #162/28 iters/delayed_precision_mark:OK #162/29 iters/loop_state_deps1:OK #162/30 iters/loop_state_deps2:OK #162/31 iters/loop_state_deps3:OK #162/32 iters/triple_continue:OK #162/33 iters/widen_spill:OK #162/34 iters/absent_mark_in_the_middle_state:OK #162/35 iters/absent_mark_in_the_middle_state2:OK #162/36 iters/absent_mark_in_the_middle_state3:OK #162/37 iters/iter_while_loop:OK #162/38 iters/iter_while_loop_auto_cleanup:OK #162/39 iters/iter_for_loop:OK #162/40 iters/iter_bpf_for_each_macro:OK #162/41 iters/iter_bpf_for_macro:OK #162/42 iters/iter_pragma_unroll_loop:OK #162/43 iters/iter_manual_unroll_loop:OK #162/44 iters/iter_multiple_sequential_loops:OK #162/45 iters/iter_limit_cond_break_loop:OK #162/46 iters/iter_obfuscate_counter:OK #162/47 iters/iter_search_loop:OK #162/48 iters/iter_array_fill:OK #162/49 iters/iter_nested_iters:OK #162/50 iters/iter_nested_deeply_iters:OK #162/51 iters/iter_subprog_iters:OK #162/52 iters/iter_tricky_but_fine:OK #162/53 iters/iter_stack_array_loop:OK #162/54 iters/iter_pass_iter_ptr_to_subprog:OK #162/55 iters/checkpoint_states_deletion:OK #162/56 iters/iter_arr_with_actual_elem_count:OK #162/57 iters/iter_subprog_check_stacksafe:OK #162/58 iters/iter_new_bad_arg:OK #162/59 iters/iter_next_bad_arg:OK #162/60 iters/iter_destroy_bad_arg:OK #162/61 iters/clean_live_states:OK #162/62 iters/absent_mark_in_the_middle_state4:OK #162/63 iters/stack_misc_vs_scalar_in_a_loop:OK #162/64 iters/iter_css_task_for_each:OK #162/65 iters/cgroup_id_printer:OK #162/66 iters/iter_css_task_for_each_sleep:OK #162/67 iters/iter_next_trusted:OK #162/68 iters/iter_next_trusted_or_null:OK #162/69 iters/iter_next_rcu:OK #162/70 iters/iter_next_rcu_or_null:OK #162/71 iters/iter_next_rcu_not_trusted:OK #162/72 iters/iter_next_ptr_mem_not_trusted:OK #162/73 iters/iter_ret_rcu_test_protected:OK #162/74 iters/iter_ret_rcu_test_type:OK #162/75 iters/iter_ret_rcu_test_protected_nostruct:OK #162/76 iters/iter_ret_rcu_test_type_nostruct:OK #162/77 iters/testmod_seq_empty:OK #162/78 iters/testmod_seq_full:OK #162/79 iters/testmod_seq_truncated:OK #162/80 iters/testmod_seq_getter_before_bad:OK #162/81 iters/testmod_seq_getter_after_bad:OK #162/82 iters/testmod_seq_getter_good:OK #162/83 iters/num:OK #162/84 iters/testmod_seq:OK #162/85 iters/task_vma:OK #162/86 iters/task:OK #162/87 iters/css_task:OK #162/88 iters/css:OK #162/89 iters/iter_tasks_without_lock:OK #162/90 iters/iter_css_without_lock:OK #162/91 iters/iter_tasks_lock_and_unlock:OK #162/92 iters/iter_css_lock_and_unlock:OK #162/93 iters/iter_css_task_for_each:OK #162 iters:OK Summary: 1/93 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t struct_ops_private_stack #468/1 struct_ops_private_stack/private_stack:OK #468/2 struct_ops_private_stack/private_stack_fail:OK #468/3 struct_ops_private_stack/private_stack_recur:OK #468 struct_ops_private_stack:OK Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t exceptions #113/1 exceptions/exception_throw_always_1:OK #113/2 exceptions/exception_throw_always_2:OK #113/3 exceptions/exception_throw_unwind_1:OK #113/4 exceptions/exception_throw_unwind_2:OK #113/5 exceptions/exception_throw_default:OK #113/6 exceptions/exception_throw_default_value:OK #113/7 exceptions/exception_tail_call:OK #113/8 exceptions/exception_ext:OK #113/9 exceptions/exception_ext_mod_cb_runtime:OK #113/10 exceptions/exception_throw_subprog:OK #113/11 exceptions/exception_assert_nz_gfunc:OK #113/12 exceptions/exception_assert_zero_gfunc:OK #113/13 exceptions/exception_assert_neg_gfunc:OK #113/14 exceptions/exception_assert_pos_gfunc:OK #113/15 exceptions/exception_assert_negeq_gfunc:OK #113/16 exceptions/exception_assert_poseq_gfunc:OK #113/17 exceptions/exception_assert_nz_gfunc_with:OK #113/18 exceptions/exception_assert_zero_gfunc_with:OK #113/19 exceptions/exception_assert_neg_gfunc_with:OK #113/20 exceptions/exception_assert_pos_gfunc_with:OK #113/21 exceptions/exception_assert_negeq_gfunc_with:OK #113/22 exceptions/exception_assert_poseq_gfunc_with:OK #113/23 exceptions/exception_bad_assert_nz_gfunc:OK #113/24 exceptions/exception_bad_assert_zero_gfunc:OK #113/25 exceptions/exception_bad_assert_neg_gfunc:OK #113/26 exceptions/exception_bad_assert_pos_gfunc:OK #113/27 exceptions/exception_bad_assert_negeq_gfunc:OK #113/28 exceptions/exception_bad_assert_poseq_gfunc:OK #113/29 exceptions/exception_bad_assert_nz_gfunc_with:OK #113/30 exceptions/exception_bad_assert_zero_gfunc_with:OK #113/31 exceptions/exception_bad_assert_neg_gfunc_with:OK #113/32 exceptions/exception_bad_assert_pos_gfunc_with:OK #113/33 exceptions/exception_bad_assert_negeq_gfunc_with:OK #113/34 exceptions/exception_bad_assert_poseq_gfunc_with:OK #113/35 exceptions/exception_assert_range:OK #113/36 exceptions/exception_assert_range_with:OK #113/37 exceptions/exception_bad_assert_range:OK #113/38 exceptions/exception_bad_assert_range_with:OK #113/39 exceptions/exception_throw_from_void_global:OK #113/40 exceptions/non-throwing fentry -> exception_cb:OK #113/41 exceptions/throwing fentry -> exception_cb:OK #113/42 exceptions/non-throwing fexit -> exception_cb:OK #113/43 exceptions/throwing fexit -> exception_cb:OK #113/44 exceptions/throwing extension (with custom cb) -> exception_cb:OK #113/45 exceptions/throwing extension -> global func in exception_cb:OK #113/46 exceptions/exception_ext_mod_cb_runtime:OK #113/47 exceptions/throwing extension (with custom cb) -> global func in exception_cb:OK #113/48 exceptions/exception_ext:OK #113/49 exceptions/non-throwing fentry -> non-throwing subprog:OK #113/50 exceptions/throwing fentry -> non-throwing subprog:OK #113/51 exceptions/non-throwing fentry -> throwing subprog:OK #113/52 exceptions/throwing fentry -> throwing subprog:OK #113/53 exceptions/non-throwing fexit -> non-throwing subprog:OK #113/54 exceptions/throwing fexit -> non-throwing subprog:OK #113/55 exceptions/non-throwing fexit -> throwing subprog:OK #113/56 exceptions/throwing fexit -> throwing subprog:OK #113/57 exceptions/non-throwing fmod_ret -> non-throwing subprog:OK #113/58 exceptions/non-throwing fmod_ret -> non-throwing global subprog:OK #113/59 exceptions/non-throwing extension -> non-throwing subprog:OK #113/60 exceptions/non-throwing extension -> throwing subprog:OK #113/61 exceptions/non-throwing extension -> non-throwing subprog:OK #113/62 exceptions/non-throwing extension -> throwing global subprog:OK #113/63 exceptions/throwing extension -> throwing global subprog:OK #113/64 exceptions/throwing extension -> non-throwing global subprog:OK #113/65 exceptions/non-throwing extension -> main subprog:OK #113/66 exceptions/throwing extension -> main subprog:OK #113/67 exceptions/reject_exception_cb_type_1:OK #113/68 exceptions/reject_exception_cb_type_2:OK #113/69 exceptions/reject_exception_cb_type_3:OK #113/70 exceptions/reject_exception_cb_type_4:OK #113/71 exceptions/reject_exception_cb_type_5:OK #113/72 exceptions/reject_async_callback_throw:OK #113/73 exceptions/reject_with_lock:OK #113/74 exceptions/reject_subprog_with_lock:OK #113/75 exceptions/reject_with_rcu_read_lock:OK #113/76 exceptions/reject_subprog_with_rcu_read_lock:OK #113/77 exceptions/reject_with_rbtree_add_throw:OK #113/78 exceptions/reject_with_reference:OK #113/79 exceptions/reject_global_subprog_throw_with_reference:OK #113/80 exceptions/reject_with_cb_reference:OK #113/81 exceptions/reject_with_cb:OK #113/82 exceptions/reject_with_subprog_reference:OK #113/83 exceptions/reject_throwing_exception_cb:OK #113/84 exceptions/reject_exception_cb_call_global_func:OK #113/85 exceptions/reject_exception_cb_call_static_func:OK #113/86 exceptions/reject_multiple_exception_cb:OK #113/87 exceptions/reject_exception_throw_cb:OK #113/88 exceptions/reject_exception_throw_cb_diff:OK #113/89 exceptions/reject_subprog_rcu_lock_throw:OK #113/90 exceptions/reject_subprog_throw_preempt_lock:OK #113/91 exceptions/reject_subprog_throw_irq_lock:OK #113/92 exceptions/reject_set_exception_cb_bad_ret1:OK #113/93 exceptions/reject_set_exception_cb_bad_ret2:OK #113/94 exceptions/reject_out_of_range_global_throw:OK #113/95 exceptions/check_assert_eq_int_min:OK #113/96 exceptions/check_assert_eq_int_max:OK #113/97 exceptions/check_assert_eq_zero:OK #113/98 exceptions/check_assert_eq_llong_min:OK #113/99 exceptions/check_assert_eq_llong_max:OK #113/100 exceptions/check_assert_lt_pos:OK #113/101 exceptions/check_assert_lt_zero:OK #113/102 exceptions/check_assert_lt_neg:OK #113/103 exceptions/check_assert_le_pos:OK #113/104 exceptions/check_assert_le_zero:OK #113/105 exceptions/check_assert_le_neg:OK #113/106 exceptions/check_assert_gt_pos:OK #113/107 exceptions/check_assert_gt_zero:OK #113/108 exceptions/check_assert_gt_neg:OK #113/109 exceptions/check_assert_ge_pos:OK #113/110 exceptions/check_assert_ge_zero:OK #113/111 exceptions/check_assert_ge_neg:OK #113/112 exceptions/check_assert_range_s64:OK #113/113 exceptions/check_assert_range_u64:OK #113/114 exceptions/check_assert_single_range_s64:OK #113/115 exceptions/check_assert_single_range_u64:OK #113/116 exceptions/check_assert_generic:OK #113/117 exceptions/check_assert_with_return:OK #113 exceptions:OK Summary: 1/117 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t verifier_ldsx #636/1 verifier_ldsx/LDSX, S8:OK #636/2 verifier_ldsx/LDSX, S8 @unpriv:OK #636/3 verifier_ldsx/LDSX, S16:OK #636/4 verifier_ldsx/LDSX, S16 @unpriv:OK #636/5 verifier_ldsx/LDSX, S32:OK #636/6 verifier_ldsx/LDSX, S32 @unpriv:OK #636/7 verifier_ldsx/LDSX, S8 range checking, privileged:OK #636/8 verifier_ldsx/LDSX, S16 range checking:OK #636/9 verifier_ldsx/LDSX, S16 range checking @unpriv:OK #636/10 verifier_ldsx/LDSX, S32 range checking:OK #636/11 verifier_ldsx/LDSX, S32 range checking @unpriv:OK #636/12 verifier_ldsx/LDSX, xdp s32 xdp_md->data:OK #636/13 verifier_ldsx/LDSX, xdp s32 xdp_md->data_end:OK #636/14 verifier_ldsx/LDSX, xdp s32 xdp_md->data_meta:OK #636/15 verifier_ldsx/LDSX, tcx s32 __sk_buff->data:OK #636/16 verifier_ldsx/LDSX, tcx s32 __sk_buff->data_end:OK #636/17 verifier_ldsx/LDSX, tcx s32 __sk_buff->data_meta:OK #636/18 verifier_ldsx/LDSX, flow_dissector s32 __sk_buff->data:OK #636/19 verifier_ldsx/LDSX, flow_dissector s32 __sk_buff->data_end:OK #636/20 verifier_ldsx/Arena LDSX Disasm:OK #636/21 verifier_ldsx/Arena LDSX Exception:OK #636/22 verifier_ldsx/Arena LDSX, S8:OK #636/23 verifier_ldsx/Arena LDSX, S16:OK #636/24 verifier_ldsx/Arena LDSX, S32:OK #636 verifier_ldsx:OK Summary: 1/24 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t arena_atomics #1/1 arena_atomics/add:OK #1/2 arena_atomics/sub:OK #1/3 arena_atomics/and:OK #1/4 arena_atomics/or:OK #1/5 arena_atomics/xor:OK #1/6 arena_atomics/cmpxchg:OK #1/7 arena_atomics/xchg:OK #1/8 arena_atomics/uaf:OK #1/9 arena_atomics/load_acquire:OK #1/10 arena_atomics/store_release:OK #1 arena_atomics:OK Summary: 1/10 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t arena_list #4/1 arena_list/arena_list_1:OK #4/2 arena_list/arena_list_1000:OK #4/3 arena_list/arena_list_1_nonsleepable:OK #4/4 arena_list/arena_list_1000_nonsleepable:OK #4 arena_list:OK Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t arena_htab #3/1 arena_htab/arena_htab_llvm:OK #3/2 arena_htab/arena_htab_asm:OK #3 arena_htab:OK Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -t verifier_arena #584/1 verifier_arena/basic_alloc1_nosleep:OK #584/2 verifier_arena/basic_alloc2_nosleep:OK #584/3 verifier_arena/basic_alloc3_nosleep:OK #584/4 verifier_arena/basic_reserve1_nosleep:OK #584/5 verifier_arena/basic_reserve2_nosleep:OK #584/6 verifier_arena/reserve_twice_nosleep:OK #584/7 verifier_arena/reserve_invalid_region_nosleep:OK #584/8 verifier_arena/basic_alloc1:OK #584/9 verifier_arena/basic_alloc2:OK #584/10 verifier_arena/basic_alloc3:OK #584/11 verifier_arena/basic_reserve1:OK #584/12 verifier_arena/basic_reserve2:OK #584/13 verifier_arena/reserve_twice:OK #584/14 verifier_arena/reserve_invalid_region:OK #584/15 verifier_arena/arena_kfuncs_under_bpf_lock:OK #584/16 verifier_arena/scalar_add_arena_ptr:OK #584/17 verifier_arena/arena_ptr_add_arena_ptr:OK #584/18 verifier_arena/scalar_xor_arena_ptr:OK #584/19 verifier_arena/arena_ptr_add_to_non_arena_ptr:OK #584/20 verifier_arena/non_arena_ptr_add_to_arena_ptr:OK #584/21 verifier_arena/check_arena_arg_ret:OK #584/22 verifier_arena/iter_maps1:OK #584/23 verifier_arena/iter_maps2:OK #584/24 verifier_arena/iter_maps3:OK #584 verifier_arena:OK #585/1 verifier_arena_globals1/check_reserve1:OK #585/2 verifier_arena_globals1/check_relocation:OK #585 verifier_arena_globals1:OK #586/1 verifier_arena_globals2/check_reserve2:OK #586 verifier_arena_globals2:OK #587/1 verifier_arena_large/big_alloc1:OK #587/2 verifier_arena_large/access_reserved:OK #587/3 verifier_arena_large/request_partially_reserved:OK #587/4 verifier_arena_large/free_reserved:OK #587/5 verifier_arena_large/big_alloc2:OK #587/6 verifier_arena_large/big_alloc3:OK #587 verifier_arena_large:OK Summary: 4/33 PASSED, 0 SKIPPED, 0 FAILED
Thanks,
George