All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
@ 2021-12-31 15:10 ` Hou Tao
  0 siblings, 0 replies; 4+ messages in thread
From: Hou Tao @ 2021-12-31 15:10 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Martin KaFai Lau, Yonghong Song, Daniel Borkmann,
	Andrii Nakryiko, Zi Shen Lim, Will Deacon, netdev, bpf,
	linux-arm-kernel, houtao1

The following error is reported when running "./test_progs -t for_each"
under arm64:

    bpf_jit: multi-func JIT bug 58 != 56
    ......
    JIT doesn't support bpf-to-bpf calls

The root cause is the size of BPF_PSEUDO_FUNC instruction increases
from 2 to 3 after the address of called bpf-function is settled and
there are two bpf-to-bpf calls in test_pkt_access. The generated
instructions are shown below:

>before callback_fn is jited, its addr is 0x1-00000001
0x48:  21 00 C0 D2    movz x1, #0x1, lsl #32
0x4c:  21 00 80 F2    movk x1, #0x1

>after callback_fn is jited, its addr is 0xfffffe0017f2fb84
0x48:  E1 3F C0 92    movn x1, #0x1ff, lsl #32
0x4c:  41 FE A2 F2    movk x1, #0x17f2, lsl #16
0x50:  81 70 9F F2    movk x1, #0xfb84

Fixing it by using emit_addr_mov_i64() for BPF_PSEUDO_FUNC, so
the size of jited image will not change.

Fixes: 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper")
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 arch/arm64/net/bpf_jit_comp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index f81e71f6e8bf..acfc3d4d712c 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -792,7 +792,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
 		u64 imm64;
 
 		imm64 = (u64)insn1.imm << 32 | (u32)imm;
-		emit_a64_mov_i64(dst, imm64, ctx);
+		if (bpf_pseudo_func(insn))
+			emit_addr_mov_i64(dst, imm64, ctx);
+		else
+			emit_a64_mov_i64(dst, imm64, ctx);
 
 		return 1;
 	}
-- 
2.27.0


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

* [PATCH] bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
@ 2021-12-31 15:10 ` Hou Tao
  0 siblings, 0 replies; 4+ messages in thread
From: Hou Tao @ 2021-12-31 15:10 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Martin KaFai Lau, Yonghong Song, Daniel Borkmann,
	Andrii Nakryiko, Zi Shen Lim, Will Deacon, netdev, bpf,
	linux-arm-kernel, houtao1

The following error is reported when running "./test_progs -t for_each"
under arm64:

    bpf_jit: multi-func JIT bug 58 != 56
    ......
    JIT doesn't support bpf-to-bpf calls

The root cause is the size of BPF_PSEUDO_FUNC instruction increases
from 2 to 3 after the address of called bpf-function is settled and
there are two bpf-to-bpf calls in test_pkt_access. The generated
instructions are shown below:

>before callback_fn is jited, its addr is 0x1-00000001
0x48:  21 00 C0 D2    movz x1, #0x1, lsl #32
0x4c:  21 00 80 F2    movk x1, #0x1

>after callback_fn is jited, its addr is 0xfffffe0017f2fb84
0x48:  E1 3F C0 92    movn x1, #0x1ff, lsl #32
0x4c:  41 FE A2 F2    movk x1, #0x17f2, lsl #16
0x50:  81 70 9F F2    movk x1, #0xfb84

Fixing it by using emit_addr_mov_i64() for BPF_PSEUDO_FUNC, so
the size of jited image will not change.

Fixes: 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper")
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 arch/arm64/net/bpf_jit_comp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index f81e71f6e8bf..acfc3d4d712c 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -792,7 +792,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
 		u64 imm64;
 
 		imm64 = (u64)insn1.imm << 32 | (u32)imm;
-		emit_a64_mov_i64(dst, imm64, ctx);
+		if (bpf_pseudo_func(insn))
+			emit_addr_mov_i64(dst, imm64, ctx);
+		else
+			emit_a64_mov_i64(dst, imm64, ctx);
 
 		return 1;
 	}
-- 
2.27.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
  2021-12-31 15:10 ` Hou Tao
@ 2022-01-05 19:50   ` patchwork-bot+netdevbpf
  -1 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-05 19:50 UTC (permalink / raw)
  To: Hou Tao
  Cc: ast, kafai, yhs, daniel, andrii, zlim.lnx, will, netdev, bpf,
	linux-arm-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Fri, 31 Dec 2021 23:10:18 +0800 you wrote:
> The following error is reported when running "./test_progs -t for_each"
> under arm64:
> 
>     bpf_jit: multi-func JIT bug 58 != 56
>     ......
>     JIT doesn't support bpf-to-bpf calls
> 
> [...]

Here is the summary with links:
  - bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
    https://git.kernel.org/bpf/bpf-next/c/e4a41c2c1fa9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH] bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
@ 2022-01-05 19:50   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-05 19:50 UTC (permalink / raw)
  To: Hou Tao
  Cc: ast, kafai, yhs, daniel, andrii, zlim.lnx, will, netdev, bpf,
	linux-arm-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Fri, 31 Dec 2021 23:10:18 +0800 you wrote:
> The following error is reported when running "./test_progs -t for_each"
> under arm64:
> 
>     bpf_jit: multi-func JIT bug 58 != 56
>     ......
>     JIT doesn't support bpf-to-bpf calls
> 
> [...]

Here is the summary with links:
  - bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC
    https://git.kernel.org/bpf/bpf-next/c/e4a41c2c1fa9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-01-05 19:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 15:10 [PATCH] bpf, arm64: use emit_addr_mov_i64() for BPF_PSEUDO_FUNC Hou Tao
2021-12-31 15:10 ` Hou Tao
2022-01-05 19:50 ` patchwork-bot+netdevbpf
2022-01-05 19:50   ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.