Re: [PATCH v2] LoongArch: BPF: Fix the offset of stptr.w and stptr.d stores
From: Tiezhu Yang
Date: Wed Nov 18 2026 - 20:11:39 EST
On 11/18/26 7:59 PM, Huacai Chen wrote:
On Wed, Nov 18, 2026 at 3:15 PM George Guo <dongtai.guo@xxxxxxxxx> wrote:
From: George Guo <guodongtai@xxxxxxxxxx>
When testing bpf selftests "jit_insns" and "jit_insns_blinded", the
"ldst_offsets" subtest fails for word and doubleword stores:
...
#define is_signed_imm12(val) signed_imm_check(val, 12)Is there instructions really take a 14bit imm (not something like
-#define is_signed_imm14(val) signed_imm_check(val, 14)
ldptr.d/stptr.d)?
If yes, I suggest keeping is_signed_imm14() because maybe we need it in future.
According to the LoongArch Reference Manual, there are 8 instructions
in total that take a 14-bit signed immediate (si14):
ldptr.{w,d}, stptr.{w,d}, ll.{w,d}, and sc.{w,d}.
All of them implicitly shift si14 left by 2 bits when calculating the
virtual address (vaddr = GR[rj] + SignExtend({si14, 2'b0}, GRLEN)),
so none of them take an unscaled 14-bit immediate directly.
In the JIT, byte offsets for all these instructions should be validated
with is_aligned_signed_imm16() and encoded as (off >> 2). Removing the
unused is_signed_imm14() macro also helps prevent similar misuse in the
future.
So there is no need to keep is_signed_imm14(), and v2 should be good
to go.
Thanks,
Tiezhu