Skip to content

Commit a6d116d

Browse files
georgejguoKernel Patches Daemon
authored andcommitted
LoongArch: BPF: Fix sign extension for 12-bit immediates
When loading immediate values that fit within 12-bit signed range, the move_imm function incorrectly used zero extension instead of sign extension. The bug was exposed when scx_simple scheduler failed with -EINVAL in ops.init() after passing node = -1 to scx_bpf_create_dsq(). Due to incorrect sign extension, `node >= (int)nr_node_ids` evaluated to true instead of false, causing BPF program failure. Verified by testing with the scx_simple scheduler (located in tools/sched_ext/). After building with `make` and running ./tools/sched_ext/build/bin/scx_simple, the scheduler now initializes successfully with this fix. Fix this by using sign extension (sext) instead of zero extension for signed immediate values in move_imm. Fixes: 5dc6155 ("LoongArch: Add BPF JIT support") Reported-by: Bing Huang <[email protected]> Signed-off-by: George Guo <[email protected]>
1 parent 9a71dd4 commit a6d116d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/loongarch/net/bpf_jit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static inline void move_imm(struct jit_ctx *ctx, enum loongarch_gpr rd, long imm
122122
/* addiw rd, $zero, imm_11_0 */
123123
if (is_signed_imm12(imm)) {
124124
emit_insn(ctx, addiw, rd, LOONGARCH_GPR_ZERO, imm);
125-
goto zext;
125+
emit_sext_32(ctx, rd, is32);
126+
return;
126127
}
127128

128129
/* ori rd, $zero, imm_11_0 */

0 commit comments

Comments
 (0)