Skip to content

Commit be4ff2e

Browse files
committed
bpf, arm32: Simplify tailcall handling
- treat tailcall count as 32-bit for access and update - change out_offset scope from file to function - minor format/structure changes for consistency Testing: (skipping fentry, fexit, freplace) ======== root@qemu-armhf:/usr/libexec/kselftests-bpf# modprobe test_bpf test_suite=test_tail_calls test_bpf: #0 Tail call leaf jited:1 967 PASS test_bpf: #1 Tail call 2 jited:1 1427 PASS test_bpf: #2 Tail call 3 jited:1 2373 PASS test_bpf: #3 Tail call 4 jited:1 2304 PASS test_bpf: #4 Tail call load/store leaf jited:1 1684 PASS test_bpf: #5 Tail call load/store jited:1 2249 PASS test_bpf: torvalds#6 Tail call error path, max count reached jited:1 22538 PASS test_bpf: torvalds#7 Tail call count preserved across function calls jited:1 1055668 PASS test_bpf: torvalds#8 Tail call error path, NULL target jited:1 513 PASS test_bpf: torvalds#9 Tail call error path, index out of range jited:1 392 PASS test_bpf: test_tail_calls: Summary: 10 PASSED, 0 FAILED, [10/10 JIT'ed] root@qemu-armhf:/usr/libexec/kselftests-bpf# ./test_progs -n 397/1-12,17-18,23-24,27-31 397/1 tailcalls/tailcall_1:OK 397/2 tailcalls/tailcall_2:OK 397/3 tailcalls/tailcall_3:OK 397/4 tailcalls/tailcall_4:OK 397/5 tailcalls/tailcall_5:OK 397/6 tailcalls/tailcall_6:OK 397/7 tailcalls/tailcall_bpf2bpf_1:OK 397/8 tailcalls/tailcall_bpf2bpf_2:OK 397/9 tailcalls/tailcall_bpf2bpf_3:OK 397/10 tailcalls/tailcall_bpf2bpf_4:OK 397/11 tailcalls/tailcall_bpf2bpf_5:OK 397/12 tailcalls/tailcall_bpf2bpf_6:OK 397/17 tailcalls/tailcall_poke:OK 397/18 tailcalls/tailcall_bpf2bpf_hierarchy_1:OK 397/23 tailcalls/tailcall_bpf2bpf_hierarchy_2:OK 397/24 tailcalls/tailcall_bpf2bpf_hierarchy_3:OK 397/27 tailcalls/tailcall_failure:OK 397/28 tailcalls/reject_tail_call_spin_lock:OK 397/29 tailcalls/reject_tail_call_rcu_lock:OK 397/30 tailcalls/reject_tail_call_preempt_lock:OK 397/31 tailcalls/reject_tail_call_ref:OK 397 tailcalls:OK Summary: 1/21 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Tony Ambardar <[email protected]>
1 parent 6d00f93 commit be4ff2e

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,23 +1403,21 @@ static inline void emit_ar_r(const u8 rd, const u8 rt, const u8 rm,
14031403
}
14041404
}
14051405

1406-
static int out_offset = -1; /* initialized on the first pass of build_body() */
14071406

1407+
/* Helper bpf_tail_call(void *prog_ctx, struct bpf_array *array, u32 index) */
1408+
#define cur_offset (ctx->idx - idx0)
1409+
#define jmp_offset (out_offset - (cur_offset) - 2)
14081410
static int emit_bpf_tail_call(struct jit_ctx *ctx)
14091411
{
1410-
1411-
/* bpf_tail_call(void *prog_ctx, struct bpf_array *array, u64 index) */
14121412
const s8 *r2 = bpf2a32[BPF_REG_2];
14131413
const s8 *r3 = bpf2a32[BPF_REG_3];
14141414
const s8 *tmp = bpf2a32[TMP_REG_1];
14151415
const s8 *tmp2 = bpf2a32[TMP_REG_2];
14161416
const s8 *tcc = bpf2a32[TCALL_CNT];
1417-
const s8 *tc;
1417+
static int out_offset = -1; /* initialized on JIT 1st pass */
14181418
const int idx0 = ctx->idx;
1419-
#define cur_offset (ctx->idx - idx0)
1420-
#define jmp_offset (out_offset - (cur_offset) - 2)
1421-
u32 lo, hi;
1422-
s8 r_array, r_index;
1419+
u32 tc_max;
1420+
s8 tc, r_array, r_index;
14231421
int off;
14241422

14251423
/* if (index >= array->map.max_entries)
@@ -1444,15 +1442,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx)
14441442
* goto out;
14451443
* tail_call_cnt++;
14461444
*/
1447-
lo = (u32)MAX_TAIL_CALL_CNT;
1448-
hi = (u32)((u64)MAX_TAIL_CALL_CNT >> 32);
1449-
tc = arm_bpf_get_reg64(tcc, tmp, ctx);
1450-
emit(ARM_CMP_I(tc[0], hi), ctx);
1451-
_emit(ARM_COND_EQ, ARM_CMP_I(tc[1], lo), ctx);
1445+
tc_max = (u32)MAX_TAIL_CALL_CNT;
1446+
tc = arm_bpf_get_reg32(tcc[1], tmp[1], ctx);
1447+
emit(ARM_CMP_I(tc, tc_max), ctx);
14521448
_emit(ARM_COND_CS, ARM_B(jmp_offset), ctx);
1453-
emit(ARM_ADDS_I(tc[1], tc[1], 1), ctx);
1454-
emit(ARM_ADC_I(tc[0], tc[0], 0), ctx);
1455-
arm_bpf_put_reg64(tcc, tmp, ARM_LR, ctx);
1449+
emit(ARM_ADD_I(tc, tc, 1), ctx);
1450+
arm_bpf_put_reg32(tcc[1], tc, tmp[0], ctx);
14561451

14571452
/* prog = array->ptrs[index]
14581453
* if (prog == NULL)
@@ -1485,9 +1480,9 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx)
14851480
return -1;
14861481
}
14871482
return 0;
1483+
}
14881484
#undef cur_offset
14891485
#undef jmp_offset
1490-
}
14911486

14921487
/* 0xabcd => 0xcdab */
14931488
static inline void emit_rev16(const u8 rd, const u8 rn, struct jit_ctx *ctx)

0 commit comments

Comments
 (0)