bpf: handle CONFIG_SMP=n configuration in x86 BPF JIT
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 4 Apr 2024 03:47:26 +0000 (20:47 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 4 Apr 2024 04:36:35 +0000 (21:36 -0700)
On non-SMP systems, there is no "per-CPU" data, it's just global data.
So in such case just don't do this_cpu_off-based per-CPU address adjustment.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202404040951.d4CUx5S6-lkp@intel.com/
Fixes: 7bdbf7446305 ("bpf: add special internal-only MOV instruction to resolve per-CPU addrs")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240404034726.2766740-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/x86/net/bpf_jit_comp.c

index af89dd117dce466dccd22e5d6653f7abeff5b059..964e8154da6648b69075b48fab603632468efc38 100644 (file)
@@ -1383,15 +1383,14 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 *rw_image
                                EMIT3(0x0F, 0x44, add_2reg(0xC0, AUX_REG, dst_reg));
                                break;
                        } else if (insn_is_mov_percpu_addr(insn)) {
-                               u32 off = (u32)(unsigned long)&this_cpu_off;
-
                                /* mov <dst>, <src> (if necessary) */
                                EMIT_mov(dst_reg, src_reg);
-
+#ifdef CONFIG_SMP
                                /* add <dst>, gs:[<off>] */
                                EMIT2(0x65, add_1mod(0x48, dst_reg));
                                EMIT3(0x03, add_1reg(0x04, dst_reg), 0x25);
-                               EMIT(off, 4);
+                               EMIT((u32)(unsigned long)&this_cpu_off, 4);
+#endif
                                break;
                        }
                        fallthrough;