Skip to content

Commit 18935a7

Browse files
Johan Almbladhborkmann
Johan Almbladh
authored andcommitted
bpf/tests: Fix error in tail call limit tests
This patch fixes an error in the tail call limit test that caused the test to fail on for x86-64 JIT. Previously, the register R0 was used to report the total number of tail calls made. However, after a tail call fall-through, the value of the R0 register is undefined. Now, all tail call error path tests instead use context state to store the count. Fixes: 874be05 ("bpf, tests: Add tail call test suite") Reported-by: Paul Chaignon <[email protected]> Reported-by: Tiezhu Yang <[email protected]> Signed-off-by: Johan Almbladh <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Tiezhu Yang <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f536a7c commit 18935a7

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lib/test_bpf.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12180,10 +12180,15 @@ static __init int test_bpf(void)
1218012180
struct tail_call_test {
1218112181
const char *descr;
1218212182
struct bpf_insn insns[MAX_INSNS];
12183+
int flags;
1218312184
int result;
1218412185
int stack_depth;
1218512186
};
1218612187

12188+
/* Flags that can be passed to tail call test cases */
12189+
#define FLAG_NEED_STATE BIT(0)
12190+
#define FLAG_RESULT_IN_STATE BIT(1)
12191+
1218712192
/*
1218812193
* Magic marker used in test snippets for tail calls below.
1218912194
* BPF_LD/MOV to R2 and R2 with this immediate value is replaced
@@ -12253,32 +12258,38 @@ static struct tail_call_test tail_call_tests[] = {
1225312258
{
1225412259
"Tail call error path, max count reached",
1225512260
.insns = {
12256-
BPF_ALU64_IMM(BPF_ADD, R1, 1),
12257-
BPF_ALU64_REG(BPF_MOV, R0, R1),
12261+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
12262+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
12263+
BPF_STX_MEM(BPF_W, R1, R2, 0),
1225812264
TAIL_CALL(0),
1225912265
BPF_EXIT_INSN(),
1226012266
},
12261-
.result = MAX_TAIL_CALL_CNT + 1,
12267+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
12268+
.result = (MAX_TAIL_CALL_CNT + 1 + 1) * MAX_TESTRUNS,
1226212269
},
1226312270
{
1226412271
"Tail call error path, NULL target",
1226512272
.insns = {
12266-
BPF_ALU64_IMM(BPF_MOV, R0, -1),
12273+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
12274+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
12275+
BPF_STX_MEM(BPF_W, R1, R2, 0),
1226712276
TAIL_CALL(TAIL_CALL_NULL),
12268-
BPF_ALU64_IMM(BPF_MOV, R0, 1),
1226912277
BPF_EXIT_INSN(),
1227012278
},
12271-
.result = 1,
12279+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
12280+
.result = MAX_TESTRUNS,
1227212281
},
1227312282
{
1227412283
"Tail call error path, index out of range",
1227512284
.insns = {
12276-
BPF_ALU64_IMM(BPF_MOV, R0, -1),
12285+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
12286+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
12287+
BPF_STX_MEM(BPF_W, R1, R2, 0),
1227712288
TAIL_CALL(TAIL_CALL_INVALID),
12278-
BPF_ALU64_IMM(BPF_MOV, R0, 1),
1227912289
BPF_EXIT_INSN(),
1228012290
},
12281-
.result = 1,
12291+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
12292+
.result = MAX_TESTRUNS,
1228212293
},
1228312294
};
1228412295

@@ -12384,6 +12395,8 @@ static __init int test_tail_calls(struct bpf_array *progs)
1238412395
for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
1238512396
struct tail_call_test *test = &tail_call_tests[i];
1238612397
struct bpf_prog *fp = progs->ptrs[i];
12398+
int *data = NULL;
12399+
int state = 0;
1238712400
u64 duration;
1238812401
int ret;
1238912402

@@ -12400,7 +12413,11 @@ static __init int test_tail_calls(struct bpf_array *progs)
1240012413
if (fp->jited)
1240112414
jit_cnt++;
1240212415

12403-
ret = __run_one(fp, NULL, MAX_TESTRUNS, &duration);
12416+
if (test->flags & FLAG_NEED_STATE)
12417+
data = &state;
12418+
ret = __run_one(fp, data, MAX_TESTRUNS, &duration);
12419+
if (test->flags & FLAG_RESULT_IN_STATE)
12420+
ret = state;
1240412421
if (ret == test->result) {
1240512422
pr_cont("%lld PASS", duration);
1240612423
pass_cnt++;

0 commit comments

Comments
 (0)