netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: x86: avoid link error with CONFIG_SMP=n
@ 2024-04-04 12:33 Arnd Bergmann
  2024-04-04 14:28 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2024-04-04 12:33 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	John Fastabend
  Cc: Arnd Bergmann, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	David S. Miller, David Ahern, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Kumar Kartikeya Dwivedi, Menglong Dong, Leon Hwang,
	Peter Zijlstra, bpf, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

On UP systems, this_cpu_off is not defined, so the new percpu code in bpf
fails to link:

x86_64-linux-ld: vmlinux.o: in function `do_jit':
bpf_jit_comp.c:(.text+0xbab14): undefined reference to `this_cpu_off'

Use offset zero on UP builds instead.

Fixes: 7bdbf7446305 ("bpf: add special internal-only MOV instruction to resolve per-CPU addrs")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I assume this is not the correct fix, or at least not the best one, so
please treat this as a bug report. It does address the link failure for
me, so I applied this to my randconfig build tree.
---
 arch/x86/net/bpf_jit_comp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index d6ebb9136f3c..8b8eebb89a9b 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1383,7 +1383,10 @@ 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;
+				u32 off = 0;
+
+				if (IS_ENABLED(CONFIG_SMP))
+					off = (u32)(unsigned long)&this_cpu_off;
 
 				/* mov <dst>, <src> (if necessary) */
 				EMIT_mov(dst_reg, src_reg);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: x86: avoid link error with CONFIG_SMP=n
  2024-04-04 12:33 [PATCH] bpf: x86: avoid link error with CONFIG_SMP=n Arnd Bergmann
@ 2024-04-04 14:28 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2024-04-04 14:28 UTC (permalink / raw)
  To: Arnd Bergmann, Alexei Starovoitov, Andrii Nakryiko,
	John Fastabend
  Cc: Arnd Bergmann, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	David S. Miller, David Ahern, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Kumar Kartikeya Dwivedi, Menglong Dong, Leon Hwang,
	Peter Zijlstra, bpf, netdev, linux-kernel

On 4/4/24 2:33 PM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> On UP systems, this_cpu_off is not defined, so the new percpu code in bpf
> fails to link:
> 
> x86_64-linux-ld: vmlinux.o: in function `do_jit':
> bpf_jit_comp.c:(.text+0xbab14): undefined reference to `this_cpu_off'
> 
> Use offset zero on UP builds instead.
> 
> Fixes: 7bdbf7446305 ("bpf: add special internal-only MOV instruction to resolve per-CPU addrs")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I assume this is not the correct fix, or at least not the best one, so
> please treat this as a bug report. It does address the link failure for
> me, so I applied this to my randconfig build tree.
> ---
>   arch/x86/net/bpf_jit_comp.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index d6ebb9136f3c..8b8eebb89a9b 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -1383,7 +1383,10 @@ 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;
> +				u32 off = 0;
> +
> +				if (IS_ENABLED(CONFIG_SMP))
> +					off = (u32)(unsigned long)&this_cpu_off;
>   

Thanks, there was already a fix in bpf-next tree in here:
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=1e9e0b85255e6eca6036b59d8a5fbca6501905ac

>   				/* mov <dst>, <src> (if necessary) */
>   				EMIT_mov(dst_reg, src_reg);
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-04 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04 12:33 [PATCH] bpf: x86: avoid link error with CONFIG_SMP=n Arnd Bergmann
2024-04-04 14:28 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).