Skip to content

Commit e1ddaa5

Browse files
Johan Almbladhgregkh
authored andcommitted
bpf/tests: Fix error in tail call limit tests
[ Upstream commit 18935a7 ] 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 <paul@cilium.io> Reported-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn> Link: https://lore.kernel.org/bpf/20210914091842.4186267-14-johan.almbladh@anyfinetworks.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 739b927 commit e1ddaa5

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

lib/test_bpf.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8992,10 +8992,15 @@ static __init int test_bpf(void)
89928992
struct tail_call_test {
89938993
const char *descr;
89948994
struct bpf_insn insns[MAX_INSNS];
8995+
int flags;
89958996
int result;
89968997
int stack_depth;
89978998
};
89988999

9000+
/* Flags that can be passed to tail call test cases */
9001+
#define FLAG_NEED_STATE BIT(0)
9002+
#define FLAG_RESULT_IN_STATE BIT(1)
9003+
89999004
/*
90009005
* Magic marker used in test snippets for tail calls below.
90019006
* BPF_LD/MOV to R2 and R2 with this immediate value is replaced
@@ -9065,32 +9070,38 @@ static struct tail_call_test tail_call_tests[] = {
90659070
{
90669071
"Tail call error path, max count reached",
90679072
.insns = {
9068-
BPF_ALU64_IMM(BPF_ADD, R1, 1),
9069-
BPF_ALU64_REG(BPF_MOV, R0, R1),
9073+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
9074+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
9075+
BPF_STX_MEM(BPF_W, R1, R2, 0),
90709076
TAIL_CALL(0),
90719077
BPF_EXIT_INSN(),
90729078
},
9073-
.result = MAX_TAIL_CALL_CNT + 1,
9079+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
9080+
.result = (MAX_TAIL_CALL_CNT + 1 + 1) * MAX_TESTRUNS,
90749081
},
90759082
{
90769083
"Tail call error path, NULL target",
90779084
.insns = {
9078-
BPF_ALU64_IMM(BPF_MOV, R0, -1),
9085+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
9086+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
9087+
BPF_STX_MEM(BPF_W, R1, R2, 0),
90799088
TAIL_CALL(TAIL_CALL_NULL),
9080-
BPF_ALU64_IMM(BPF_MOV, R0, 1),
90819089
BPF_EXIT_INSN(),
90829090
},
9083-
.result = 1,
9091+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
9092+
.result = MAX_TESTRUNS,
90849093
},
90859094
{
90869095
"Tail call error path, index out of range",
90879096
.insns = {
9088-
BPF_ALU64_IMM(BPF_MOV, R0, -1),
9097+
BPF_LDX_MEM(BPF_W, R2, R1, 0),
9098+
BPF_ALU64_IMM(BPF_ADD, R2, 1),
9099+
BPF_STX_MEM(BPF_W, R1, R2, 0),
90899100
TAIL_CALL(TAIL_CALL_INVALID),
9090-
BPF_ALU64_IMM(BPF_MOV, R0, 1),
90919101
BPF_EXIT_INSN(),
90929102
},
9093-
.result = 1,
9103+
.flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
9104+
.result = MAX_TESTRUNS,
90949105
},
90959106
};
90969107

@@ -9196,6 +9207,8 @@ static __init int test_tail_calls(struct bpf_array *progs)
91969207
for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
91979208
struct tail_call_test *test = &tail_call_tests[i];
91989209
struct bpf_prog *fp = progs->ptrs[i];
9210+
int *data = NULL;
9211+
int state = 0;
91999212
u64 duration;
92009213
int ret;
92019214

@@ -9212,7 +9225,11 @@ static __init int test_tail_calls(struct bpf_array *progs)
92129225
if (fp->jited)
92139226
jit_cnt++;
92149227

9215-
ret = __run_one(fp, NULL, MAX_TESTRUNS, &duration);
9228+
if (test->flags & FLAG_NEED_STATE)
9229+
data = &state;
9230+
ret = __run_one(fp, data, MAX_TESTRUNS, &duration);
9231+
if (test->flags & FLAG_RESULT_IN_STATE)
9232+
ret = state;
92169233
if (ret == test->result) {
92179234
pr_cont("%lld PASS", duration);
92189235
pass_cnt++;

0 commit comments

Comments
 (0)