* [PATCH bpf-next v2 1/3] bpf: arm64: Add support for instructions array
2025-11-17 13:07 [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps Puranjay Mohan
@ 2025-11-17 13:07 ` Puranjay Mohan
2025-11-18 12:43 ` Xu Kuohai
2025-11-17 13:07 ` [PATCH bpf-next v2 2/3] bpf: arm64: Add support for indirect jumps Puranjay Mohan
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Puranjay Mohan @ 2025-11-17 13:07 UTC (permalink / raw)
To: bpf
Cc: Puranjay Mohan, Puranjay Mohan, Alexei Starovoitov,
Andrii Nakryiko, Daniel Borkmann, Martin KaFai Lau,
Eduard Zingerman, Xu Kuohai, Catalin Marinas, Will Deacon,
kernel-team, Anton Protopopov
Add support for the instructions array map type in the arm64 JIT by
calling bpf_prog_update_insn_ptrs() with the offsets that map
xlated_offset to the jited_offset in the final image. arm64 JIT already
has this offset array which was being used for
bpf_prog_fill_jited_linfo() and can be used directly for
bpf_prog_update_insn_ptrs.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
arch/arm64/net/bpf_jit_comp.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 0c9a50a1e73e..4a2afc0cefc4 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -2231,6 +2231,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
for (i = 0; i <= prog->len; i++)
ctx.offset[i] *= AARCH64_INSN_SIZE;
bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
+ /*
+ * The bpf_prog_update_insn_ptrs function expects offsets to
+ * point to the first byte of the jitted instruction (unlike
+ * the bpf_prog_fill_jited_linfo above, which, for historical
+ * reasons, expects to point to the next instruction)
+ */
+ bpf_prog_update_insn_ptrs(prog, ctx.offset, ctx.ro_image);
out_off:
if (!ro_header && priv_stack_ptr) {
free_percpu(priv_stack_ptr);
--
2.47.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH bpf-next v2 1/3] bpf: arm64: Add support for instructions array
2025-11-17 13:07 ` [PATCH bpf-next v2 1/3] bpf: arm64: Add support for instructions array Puranjay Mohan
@ 2025-11-18 12:43 ` Xu Kuohai
0 siblings, 0 replies; 7+ messages in thread
From: Xu Kuohai @ 2025-11-18 12:43 UTC (permalink / raw)
To: Puranjay Mohan, bpf
Cc: Puranjay Mohan, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Martin KaFai Lau, Eduard Zingerman,
Catalin Marinas, Will Deacon, kernel-team, Anton Protopopov
On 11/17/2025 9:07 PM, Puranjay Mohan wrote:
> Add support for the instructions array map type in the arm64 JIT by
> calling bpf_prog_update_insn_ptrs() with the offsets that map
> xlated_offset to the jited_offset in the final image. arm64 JIT already
> has this offset array which was being used for
> bpf_prog_fill_jited_linfo() and can be used directly for
> bpf_prog_update_insn_ptrs.
>
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
> ---
> arch/arm64/net/bpf_jit_comp.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 0c9a50a1e73e..4a2afc0cefc4 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -2231,6 +2231,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
> for (i = 0; i <= prog->len; i++)
> ctx.offset[i] *= AARCH64_INSN_SIZE;
> bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
> + /*
> + * The bpf_prog_update_insn_ptrs function expects offsets to
> + * point to the first byte of the jitted instruction (unlike
> + * the bpf_prog_fill_jited_linfo above, which, for historical
> + * reasons, expects to point to the next instruction)
> + */
> + bpf_prog_update_insn_ptrs(prog, ctx.offset, ctx.ro_image);
> out_off:
> if (!ro_header && priv_stack_ptr) {
> free_percpu(priv_stack_ptr);
Acked-by: Xu Kuohai <xukuohai@huawei.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next v2 2/3] bpf: arm64: Add support for indirect jumps
2025-11-17 13:07 [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps Puranjay Mohan
2025-11-17 13:07 ` [PATCH bpf-next v2 1/3] bpf: arm64: Add support for instructions array Puranjay Mohan
@ 2025-11-17 13:07 ` Puranjay Mohan
2025-11-18 12:43 ` Xu Kuohai
2025-11-17 13:07 ` [PATCH bpf-next v2 3/3] selftests: bpf: Enable gotox tests from arm64 Puranjay Mohan
2025-11-22 0:53 ` [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps patchwork-bot+netdevbpf
3 siblings, 1 reply; 7+ messages in thread
From: Puranjay Mohan @ 2025-11-17 13:07 UTC (permalink / raw)
To: bpf
Cc: Puranjay Mohan, Puranjay Mohan, Alexei Starovoitov,
Andrii Nakryiko, Daniel Borkmann, Martin KaFai Lau,
Eduard Zingerman, Xu Kuohai, Catalin Marinas, Will Deacon,
kernel-team, Anton Protopopov
Add support for a new instruction
BPF_JMP|BPF_X|BPF_JA, SRC=0, DST=Rx, off=0, imm=0
which does an indirect jump to a location stored in Rx. The register
Rx should have type PTR_TO_INSN. This new type assures that the Rx
register contains a value (or a range of values) loaded from a
correct jump table – map of type instruction array.
ARM64 JIT supports indirect jumps to all registers through the A64_BR()
macro, use it to implement this new instruction.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
arch/arm64/net/bpf_jit_comp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 4a2afc0cefc4..4cfb549f2b43 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1452,6 +1452,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
emit(A64_ASR(is64, dst, dst, imm), ctx);
break;
+ /* JUMP reg */
+ case BPF_JMP | BPF_JA | BPF_X:
+ emit(A64_BR(dst), ctx);
+ break;
/* JUMP off */
case BPF_JMP | BPF_JA:
case BPF_JMP32 | BPF_JA:
--
2.47.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v2 2/3] bpf: arm64: Add support for indirect jumps
2025-11-17 13:07 ` [PATCH bpf-next v2 2/3] bpf: arm64: Add support for indirect jumps Puranjay Mohan
@ 2025-11-18 12:43 ` Xu Kuohai
0 siblings, 0 replies; 7+ messages in thread
From: Xu Kuohai @ 2025-11-18 12:43 UTC (permalink / raw)
To: Puranjay Mohan, bpf
Cc: Puranjay Mohan, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Martin KaFai Lau, Eduard Zingerman,
Catalin Marinas, Will Deacon, kernel-team, Anton Protopopov
On 11/17/2025 9:07 PM, Puranjay Mohan wrote:
> Add support for a new instruction
>
> BPF_JMP|BPF_X|BPF_JA, SRC=0, DST=Rx, off=0, imm=0
>
> which does an indirect jump to a location stored in Rx. The register
> Rx should have type PTR_TO_INSN. This new type assures that the Rx
> register contains a value (or a range of values) loaded from a
> correct jump table – map of type instruction array.
>
> ARM64 JIT supports indirect jumps to all registers through the A64_BR()
> macro, use it to implement this new instruction.
>
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
> ---
> arch/arm64/net/bpf_jit_comp.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 4a2afc0cefc4..4cfb549f2b43 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -1452,6 +1452,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
> emit(A64_ASR(is64, dst, dst, imm), ctx);
> break;
>
> + /* JUMP reg */
> + case BPF_JMP | BPF_JA | BPF_X:
> + emit(A64_BR(dst), ctx);
> + break;
> /* JUMP off */
> case BPF_JMP | BPF_JA:
> case BPF_JMP32 | BPF_JA:
Acked-by: Xu Kuohai <xukuohai@huawei.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next v2 3/3] selftests: bpf: Enable gotox tests from arm64
2025-11-17 13:07 [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps Puranjay Mohan
2025-11-17 13:07 ` [PATCH bpf-next v2 1/3] bpf: arm64: Add support for instructions array Puranjay Mohan
2025-11-17 13:07 ` [PATCH bpf-next v2 2/3] bpf: arm64: Add support for indirect jumps Puranjay Mohan
@ 2025-11-17 13:07 ` Puranjay Mohan
2025-11-22 0:53 ` [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps patchwork-bot+netdevbpf
3 siblings, 0 replies; 7+ messages in thread
From: Puranjay Mohan @ 2025-11-17 13:07 UTC (permalink / raw)
To: bpf
Cc: Puranjay Mohan, Puranjay Mohan, Alexei Starovoitov,
Andrii Nakryiko, Daniel Borkmann, Martin KaFai Lau,
Eduard Zingerman, Xu Kuohai, Catalin Marinas, Will Deacon,
kernel-team, Anton Protopopov
arm64 JIT now supports gotox instruction and jumptables, so run tests in
verifier_gotox.c for arm64.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/verifier_gotox.c b/tools/testing/selftests/bpf/progs/verifier_gotox.c
index b6710f134a1d..536c9f3e2170 100644
--- a/tools/testing/selftests/bpf/progs/verifier_gotox.c
+++ b/tools/testing/selftests/bpf/progs/verifier_gotox.c
@@ -6,7 +6,7 @@
#include "bpf_misc.h"
#include "../../../include/linux/filter.h"
-#ifdef __TARGET_ARCH_x86
+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
#define DEFINE_SIMPLE_JUMP_TABLE_PROG(NAME, SRC_REG, OFF, IMM, OUTCOME) \
\
@@ -384,6 +384,6 @@ jt0_%=: \
: __clobber_all);
}
-#endif /* __TARGET_ARCH_x86 */
+#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 */
char _license[] SEC("license") = "GPL";
--
2.47.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps
2025-11-17 13:07 [PATCH bpf-next v2 0/3] bpf: arm64: Indirect jumps Puranjay Mohan
` (2 preceding siblings ...)
2025-11-17 13:07 ` [PATCH bpf-next v2 3/3] selftests: bpf: Enable gotox tests from arm64 Puranjay Mohan
@ 2025-11-22 0:53 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-22 0:53 UTC (permalink / raw)
To: Puranjay Mohan
Cc: bpf, puranjay12, ast, andrii, daniel, martin.lau, eddyz87,
xukuohai, catalin.marinas, will, kernel-team
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Mon, 17 Nov 2025 13:07:28 +0000 you wrote:
> Changes in v1->v2:
> v1: https://lore.kernel.org/all/20251117004656.33292-1-puranjay@kernel.org/
> - Dropped patch 3 that was ignoring relocations for .jumptables. LLVM
> has been fixed to not emit relocations for .jumptables, so this patch
> is not needed.
> - Added Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com>
>
> [...]
Here is the summary with links:
- [bpf-next,v2,1/3] bpf: arm64: Add support for instructions array
https://git.kernel.org/bpf/bpf-next/c/84b1c40d5b4d
- [bpf-next,v2,2/3] bpf: arm64: Add support for indirect jumps
https://git.kernel.org/bpf/bpf-next/c/f4a66cf1cb14
- [bpf-next,v2,3/3] selftests: bpf: Enable gotox tests from arm64
https://git.kernel.org/bpf/bpf-next/c/d8774a36235e
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] 7+ messages in thread