riscv, bpf: Add ex_insn_off and ex_jmp_off for exception table handling
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 26 lines · Chris Mason
Quoted 10 lines · On Sat, 19 Jul 2025 09:17:28 +0000 Pu Lehui <[email protected]> wrote:
From: Pu Lehui <[email protected]>
Add
ex_insn_offandex_jmp_offfields to structrv_jit_contextso thatadd_exception_handler()does not need to be immediately followed by the instruction to add the exception table.ex_insn_offindicates the offset of the instruction to add the exception table, andex_jmp_offindicates the offset to jump over the faulting instruction. This is to prepare for adding the exception table to atomic instructions later, because some atomic instructions need to perform zext or other operations.Hi everyone,
I've been working on some patch review automation, and I recently ran it on the bpf-next branch. I don't know the verifier well enough to decide if this is a false positive, but Alexei asked me to kick off discussion, so:
Quoted 4 lines
arch/riscv/net/bpf_jit_comp64.c +0
-0[ ... ]
Quoted 11 lines
arch/riscv/net/bpf_jit_comp64.c
Quoted 11 lines
arch/riscv/net/bpf_jit_comp64.c +3
-5-static int emit_stx (u8 rd,s16 off,u8 rs,u8 size,struct rv_jit_context *ctx) +static void emit_stx (u8 rd,s16 off,u8 rs,u8 size,struct rv_jit_context *ctx) { -int insns_start; -if (is_12b_int (off)) { - insns_start = ctx->ninsns; + ctx->ex_insn_off = ctx->ninsns;emit_stx_insn (rd, off, rs, size, ctx); -return ctx->ninsns - insns_start; + ctx->ex_jmp_off = ctx->ex_jmp_off;
Hi Chris,
I'm not sure if I have misunderstood your intention, maybe just for talking about reviewing automation? But the code I checked in the bpf-next branch is inconsistent with yours. The code here in bpf-next is:
ctx->ex_jmp_off = ctx->ninsns;
Quoted 20 lines
Does this assignment leave
ex_jmp_offuninitialized? Looking atemit_ldx()andemit_st(), this should probably be "ctx->ex_jmp_off=ctx->ninsns;" to match the pattern. Without proper initialization,add_exception_handler()might use stale offset values when creating exception table entries for theis_12b_int()code path inemit_stx().arch/riscv/net/bpf_jit_comp64.c
Quoted 11 lines
arch/riscv/net/bpf_jit_comp64.c +3
-2+return ; }emit_imm (RV_REG_T1 , off, ctx);emit_add (RV_REG_T1 ,RV_REG_T1 , rd, ctx); - insns_start = ctx->ninsns; + ctx->ex_insn_off = ctx->ninsns;emit_stx_insn (RV_REG_T1 ,0 , rs, size, ctx); -return ctx->ninsns - insns_start; + ctx->ex_jmp_off = ctx->ninsns; }-chris
Quoted 43 lines · Pu Lehui
Quoted 26 lines · Chris Mason
Quoted 10 lines · On Sat, 19 Jul 2025 09:17:28 +0000 Pu Lehui <[email protected]> wrote:
From: Pu Lehui <[email protected]>
Add
ex_insn_offandex_jmp_offfields to structrv_jit_contextso thatadd_exception_handler()does not need to be immediately followed by the instruction to add the exception table.ex_insn_offindicates the offset of the instruction to add the exception table, andex_jmp_offindicates the offset to jump over the faulting instruction. This is to prepare for adding the exception table to atomic instructions later, because some atomic instructions need to perform zext or other operations.Hi everyone,
I've been working on some patch review automation, and I recently ran it on the bpf-next branch. I don't know the verifier well enough to decide if this is a false positive, but Alexei asked me to kick off discussion, so:
Quoted 4 lines
arch/riscv/net/bpf_jit_comp64.c +0
-0[ ... ]
Quoted 11 lines
arch/riscv/net/bpf_jit_comp64.c
Quoted 11 lines
arch/riscv/net/bpf_jit_comp64.c +3
-5-static int emit_stx (u8 rd,s16 off,u8 rs,u8 size,struct rv_jit_context *ctx) +static void emit_stx (u8 rd,s16 off,u8 rs,u8 size,struct rv_jit_context *ctx) { -int insns_start; -if (is_12b_int (off)) { - insns_start = ctx->ninsns; + ctx->ex_insn_off = ctx->ninsns;emit_stx_insn (rd, off, rs, size, ctx); -return ctx->ninsns - insns_start; + ctx->ex_jmp_off = ctx->ex_jmp_off;Hi Chris,
Quoted 7 lines
I'm not sure if I have misunderstood your intention, maybe just for talking about reviewing automation? But the code I checked in the bpf-next branch is inconsistent with yours. The code here in bpf-next is:
ctx->ex_jmp_off = ctx->ninsns;
You're right, the review tooling got confused because it only indexed the x86 version. Sorry about that, thanks for double checking.
-chris