BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: implement insn_is_cast_user() helper for JITs
@ 2024-03-24 18:32 Puranjay Mohan
  2024-03-25 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Puranjay Mohan @ 2024-03-24 18:32 UTC (permalink / raw)
  To: David S. Miller, David Ahern, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, netdev, bpf, linux-kernel
  Cc: puranjay12

Implement a helper function to check if an instruction is
addr_space_cast from as(0) to as(1). Use this helper in the x86 JIT.

Other JITs can use this helper when they add support for this instruction.

Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
---
 arch/x86/net/bpf_jit_comp.c |  3 +--
 include/linux/filter.h      | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 9b3136187938..98349d11fae2 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1350,8 +1350,7 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 *rw_image
 			break;
 
 		case BPF_ALU64 | BPF_MOV | BPF_X:
-			if (insn->off == BPF_ADDR_SPACE_CAST &&
-			    insn->imm == 1U << 16) {
+			if (insn_is_cast_user(insn)) {
 				if (dst_reg != src_reg)
 					/* 32-bit mov */
 					emit_mov_reg(&prog, false, dst_reg, src_reg);
diff --git a/include/linux/filter.h b/include/linux/filter.h
index cf12bfa2a78c..42dbceb04ca6 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -228,6 +228,16 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
 	return insn->code == (BPF_ALU | BPF_MOV | BPF_X) && insn->imm == 1;
 }
 
+/* addr_space_cast from as(0) to as(1) is for converting bpf arena pointers
+ * to pointers in user vma.
+ */
+static inline bool insn_is_cast_user(const struct bpf_insn *insn)
+{
+	return insn->code == (BPF_ALU64 | BPF_MOV | BPF_X) &&
+			      insn->off == BPF_ADDR_SPACE_CAST &&
+			      insn->imm == 1U << 16;
+}
+
 /* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */
 #define BPF_LD_IMM64(DST, IMM)					\
 	BPF_LD_IMM64_RAW(DST, 0, IMM)
-- 
2.40.1


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

* Re: [PATCH bpf-next] bpf: implement insn_is_cast_user() helper for JITs
  2024-03-24 18:32 [PATCH bpf-next] bpf: implement insn_is_cast_user() helper for JITs Puranjay Mohan
@ 2024-03-25 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-25 16:20 UTC (permalink / raw)
  To: Puranjay Mohan
  Cc: davem, dsahern, ast, daniel, andrii, martin.lau, eddyz87, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, tglx,
	mingo, bp, dave.hansen, x86, hpa, netdev, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Sun, 24 Mar 2024 18:32:26 +0000 you wrote:
> Implement a helper function to check if an instruction is
> addr_space_cast from as(0) to as(1). Use this helper in the x86 JIT.
> 
> Other JITs can use this helper when they add support for this instruction.
> 
> Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: implement insn_is_cast_user() helper for JITs
    https://git.kernel.org/bpf/bpf-next/c/770546ae9f4c

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] 2+ messages in thread

end of thread, other threads:[~2024-03-25 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-24 18:32 [PATCH bpf-next] bpf: implement insn_is_cast_user() helper for JITs Puranjay Mohan
2024-03-25 16:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox