Skip to content

Commit 878ee3c

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-arm64-indirect-jumps'
Puranjay Mohan says: ==================== bpf: arm64: Indirect jumps 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> This set adds the support of indirect jumps to the arm64 JIT. It involves calling bpf_prog_update_insn_ptrs() to support instructions array map. The second piece is supporting BPF_JMP|BPF_X|BPF_JA, SRC=0, DST=Rx, off=0, imm=0 instruction that is trivial to implement on arm64. The final patch enables selftests on arm64: [root@localhost bpf]# ./test_progs-cpuv4 -a "*gotox*" #20/1 bpf_gotox/one-switch:OK #20/2 bpf_gotox/one-switch-non-zero-sec-offset:OK #20/3 bpf_gotox/two-switches:OK #20/4 bpf_gotox/big-jump-table:OK #20/5 bpf_gotox/static-global:OK #20/6 bpf_gotox/nonstatic-global:OK #20/7 bpf_gotox/other-sec:OK #20/8 bpf_gotox/static-global-other-sec:OK #20/9 bpf_gotox/nonstatic-global-other-sec:OK #20/10 bpf_gotox/one-jump-two-maps:OK #20/11 bpf_gotox/one-map-two-jumps:OK #20 bpf_gotox:OK #537/1 verifier_gotox/jump_table_ok:OK #537/2 verifier_gotox/jump_table_reserved_field_src_reg:OK #537/3 verifier_gotox/jump_table_reserved_field_non_zero_off:OK #537/4 verifier_gotox/jump_table_reserved_field_non_zero_imm:OK #537/5 verifier_gotox/jump_table_no_jump_table:OK #537/6 verifier_gotox/jump_table_incorrect_dst_reg_type:OK #537/7 verifier_gotox/jump_table_invalid_read_size_u32:OK #537/8 verifier_gotox/jump_table_invalid_read_size_u16:OK #537/9 verifier_gotox/jump_table_invalid_read_size_u8:OK #537/10 verifier_gotox/jump_table_misaligned_access:OK #537/11 verifier_gotox/jump_table_invalid_mem_acceess_pos:OK #537/12 verifier_gotox/jump_table_invalid_mem_acceess_neg:OK #537/13 verifier_gotox/jump_table_add_sub_ok:OK #537/14 verifier_gotox/jump_table_no_writes:OK #537/15 verifier_gotox/jump_table_use_reg_r0:OK #537/16 verifier_gotox/jump_table_use_reg_r1:OK #537/17 verifier_gotox/jump_table_use_reg_r2:OK #537/18 verifier_gotox/jump_table_use_reg_r3:OK #537/19 verifier_gotox/jump_table_use_reg_r4:OK #537/20 verifier_gotox/jump_table_use_reg_r5:OK #537/21 verifier_gotox/jump_table_use_reg_r6:OK #537/22 verifier_gotox/jump_table_use_reg_r7:OK #537/23 verifier_gotox/jump_table_use_reg_r8:OK #537/24 verifier_gotox/jump_table_use_reg_r9:OK #537/25 verifier_gotox/jump_table_outside_subprog:OK #537/26 verifier_gotox/jump_table_contains_non_unique_values:OK #537 verifier_gotox:OK Summary: 2/37 PASSED, 0 SKIPPED, 0 FAILED ==================== Link: https://patch.msgid.link/20251117130732.11107-1-puranjay@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 792f258 + d8774a3 commit 878ee3c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
14521452
emit(A64_ASR(is64, dst, dst, imm), ctx);
14531453
break;
14541454

1455+
/* JUMP reg */
1456+
case BPF_JMP | BPF_JA | BPF_X:
1457+
emit(A64_BR(dst), ctx);
1458+
break;
14551459
/* JUMP off */
14561460
case BPF_JMP | BPF_JA:
14571461
case BPF_JMP32 | BPF_JA:
@@ -2231,6 +2235,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
22312235
for (i = 0; i <= prog->len; i++)
22322236
ctx.offset[i] *= AARCH64_INSN_SIZE;
22332237
bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
2238+
/*
2239+
* The bpf_prog_update_insn_ptrs function expects offsets to
2240+
* point to the first byte of the jitted instruction (unlike
2241+
* the bpf_prog_fill_jited_linfo above, which, for historical
2242+
* reasons, expects to point to the next instruction)
2243+
*/
2244+
bpf_prog_update_insn_ptrs(prog, ctx.offset, ctx.ro_image);
22342245
out_off:
22352246
if (!ro_header && priv_stack_ptr) {
22362247
free_percpu(priv_stack_ptr);

tools/testing/selftests/bpf/progs/verifier_gotox.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "bpf_misc.h"
77
#include "../../../include/linux/filter.h"
88

9-
#ifdef __TARGET_ARCH_x86
9+
#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
1010

1111
#define DEFINE_SIMPLE_JUMP_TABLE_PROG(NAME, SRC_REG, OFF, IMM, OUTCOME) \
1212
\
@@ -384,6 +384,6 @@ jt0_%=: \
384384
: __clobber_all);
385385
}
386386

387-
#endif /* __TARGET_ARCH_x86 */
387+
#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 */
388388

389389
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)