Re: [PATCH] LoongArch: BPF: Fix the offset of stptr.w and stptr.d stores

From: Tiezhu Yang

Date: Tue Nov 17 2026 - 23:14:53 EST


On 11/18/26 11:02 AM, George Guo 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:

...

diff --git a/arch/loongarch/net/bpf_jit.h b/arch/loongarch/net/bpf_jit.h
index 2bd0dc5b911c..5207ad30fade 100644
--- a/arch/loongarch/net/bpf_jit.h
+++ b/arch/loongarch/net/bpf_jit.h
@@ -52,6 +52,15 @@ do { \
#define is_signed_imm52(val) signed_imm_check(val, 52)
#define is_unsigned_imm12(val) unsigned_imm_check(val, 12)
+/*
+ * ldptr.{w,d} and stptr.{w,d} take a 14-bit signed immediate in units of
+ * 4 bytes: they reach a multiple of 4 in [-32768, 32764], passed as off >> 2.
+ */
+static inline bool is_ptr_off(int off)
+{
+ return !(off & 3) && is_signed_imm16(off);
+}
+

Please use a self-documenting function name and remove the redundant
comment:

static inline bool is_aligned_signed_imm16(int off)
{
return !(off & 3) && is_signed_imm16(off);
}

Moreover, please remove the unused is_signed_imm14 macro in bpf_jit.h.

Thanks,
Tiezhu