Give arm64 the native entry of bpf_throw() that x86-64 has: the verifier retargets the call to bpf_throw() to bpf_throw_entry(), which pushes a frame record whose return address is the one into the program and saves R6-R9 of the throw site, x19-x22, below it as a struct bpf_throw_regs, then calls bpf_throw_unwind() with it. Nothing consumes the registers yet. Signed-off-by: Kumar Kartikeya Dwivedi --- arch/arm64/net/Makefile | 1 + arch/arm64/net/bpf_jit_comp.c | 8 ++++++++ arch/arm64/net/bpf_throw.S | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 arch/arm64/net/bpf_throw.S diff --git a/arch/arm64/net/Makefile b/arch/arm64/net/Makefile index 3ae382bfca87..70d18f067d01 100644 --- a/arch/arm64/net/Makefile +++ b/arch/arm64/net/Makefile @@ -3,3 +3,4 @@ # ARM64 networking code # obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o +obj-$(CONFIG_BPF_SYSCALL) += bpf_throw.o diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 6a99f883a091..cc0ee9b3726b 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -3499,6 +3500,13 @@ bool bpf_jit_supports_timed_may_goto(void) return true; } +#ifdef CONFIG_BPF_SYSCALL +void *bpf_arch_throw_entry(void) +{ + return (void *)bpf_throw_entry; +} +#endif + bool bpf_jit_inlines_helper_call(s32 imm) { switch (imm) { diff --git a/arch/arm64/net/bpf_throw.S b/arch/arm64/net/bpf_throw.S new file mode 100644 index 000000000000..aac1c5e967e1 --- /dev/null +++ b/arch/arm64/net/bpf_throw.S @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ + +#include +#include + +/* + * Native entry of the bpf_throw() kfunc. The verifier retargets the call to + * bpf_throw() here, so the BPF register file of the throw site is still intact + * on entry and x30 is the return address into the program. Push a frame record + * whose link register is that address and save R6-R9, x19-x22, below it as a + * struct bpf_throw_regs: saved[i] sits at [sp + 16 + 8 * i]. Then hand it to + * bpf_throw_unwind(), which never returns. + */ +SYM_FUNC_START(bpf_throw_entry) + stp x29, x30, [sp, #-(16 + BPF_THROW_REGS_SIZE)]! + mov x29, sp + stp x19, x20, [sp, #16] + stp x21, x22, [sp, #32] + + /* bpf_throw_unwind(regs, cookie); the cookie is R1 of the caller. */ + mov x1, x0 + add x0, sp, #16 + bl bpf_throw_unwind + brk #0x1 +SYM_FUNC_END(bpf_throw_entry) -- 2.53.0