Re: [PATCH bpf-next v2 02/11] LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs
From: George Guo
Date: Tue Jul 07 2026 - 06:24:55 EST
> 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>] */
...
#endif
Thanks,
George