From: Johan Almbladh <johan.almbladh@anyfinetworks.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, iii@linux.ibm.com,
paul@cilium.io, yangtiezhu@loongson.cn, netdev@vger.kernel.org,
bpf@vger.kernel.org,
Johan Almbladh <johan.almbladh@anyfinetworks.com>
Subject: [PATCH bpf v4 13/14] bpf/tests: Fix error in tail call limit tests
Date: Tue, 14 Sep 2021 11:18:41 +0200 [thread overview]
Message-ID: <20210914091842.4186267-14-johan.almbladh@anyfinetworks.com> (raw)
In-Reply-To: <20210914091842.4186267-1-johan.almbladh@anyfinetworks.com>
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: 874be05f525e ("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>
---
lib/test_bpf.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 7475abfd2186..ddb9a8089d2e 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -12179,10 +12179,15 @@ static __init int test_bpf(void)
struct tail_call_test {
const char *descr;
struct bpf_insn insns[MAX_INSNS];
+ int flags;
int result;
int stack_depth;
};
+/* Flags that can be passed to tail call test cases */
+#define FLAG_NEED_STATE BIT(0)
+#define FLAG_RESULT_IN_STATE BIT(1)
+
/*
* Magic marker used in test snippets for tail calls below.
* BPF_LD/MOV to R2 and R2 with this immediate value is replaced
@@ -12252,32 +12257,38 @@ static struct tail_call_test tail_call_tests[] = {
{
"Tail call error path, max count reached",
.insns = {
- BPF_ALU64_IMM(BPF_ADD, R1, 1),
- BPF_ALU64_REG(BPF_MOV, R0, R1),
+ BPF_LDX_MEM(BPF_W, R2, R1, 0),
+ BPF_ALU64_IMM(BPF_ADD, R2, 1),
+ BPF_STX_MEM(BPF_W, R1, R2, 0),
TAIL_CALL(0),
BPF_EXIT_INSN(),
},
- .result = MAX_TAIL_CALL_CNT + 1,
+ .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
+ .result = (MAX_TAIL_CALL_CNT + 1 + 1) * MAX_TESTRUNS,
},
{
"Tail call error path, NULL target",
.insns = {
- BPF_ALU64_IMM(BPF_MOV, R0, -1),
+ BPF_LDX_MEM(BPF_W, R2, R1, 0),
+ BPF_ALU64_IMM(BPF_ADD, R2, 1),
+ BPF_STX_MEM(BPF_W, R1, R2, 0),
TAIL_CALL(TAIL_CALL_NULL),
- BPF_ALU64_IMM(BPF_MOV, R0, 1),
BPF_EXIT_INSN(),
},
- .result = 1,
+ .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
+ .result = MAX_TESTRUNS,
},
{
"Tail call error path, index out of range",
.insns = {
- BPF_ALU64_IMM(BPF_MOV, R0, -1),
+ BPF_LDX_MEM(BPF_W, R2, R1, 0),
+ BPF_ALU64_IMM(BPF_ADD, R2, 1),
+ BPF_STX_MEM(BPF_W, R1, R2, 0),
TAIL_CALL(TAIL_CALL_INVALID),
- BPF_ALU64_IMM(BPF_MOV, R0, 1),
BPF_EXIT_INSN(),
},
- .result = 1,
+ .flags = FLAG_NEED_STATE | FLAG_RESULT_IN_STATE,
+ .result = MAX_TESTRUNS,
},
};
@@ -12383,6 +12394,8 @@ static __init int test_tail_calls(struct bpf_array *progs)
for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
struct tail_call_test *test = &tail_call_tests[i];
struct bpf_prog *fp = progs->ptrs[i];
+ int *data = NULL;
+ int state = 0;
u64 duration;
int ret;
@@ -12399,7 +12412,11 @@ static __init int test_tail_calls(struct bpf_array *progs)
if (fp->jited)
jit_cnt++;
- ret = __run_one(fp, NULL, MAX_TESTRUNS, &duration);
+ if (test->flags & FLAG_NEED_STATE)
+ data = &state;
+ ret = __run_one(fp, data, MAX_TESTRUNS, &duration);
+ if (test->flags & FLAG_RESULT_IN_STATE)
+ ret = state;
if (ret == test->result) {
pr_cont("%lld PASS", duration);
pass_cnt++;
--
2.30.2
next prev parent reply other threads:[~2021-09-14 9:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-14 9:18 [PATCH bpf v4 00/14] bpf/tests: Extend JIT test suite coverage Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 01/14] bpf/tests: Allow different number of runs per test case Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 02/14] bpf/tests: Reduce memory footprint of test suite Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 03/14] bpf/tests: Add exhaustive tests of ALU shift values Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 04/14] bpf/tests: Add exhaustive tests of ALU operand magnitudes Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 05/14] bpf/tests: Add exhaustive tests of JMP " Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 06/14] bpf/tests: Add staggered JMP and JMP32 tests Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 07/14] bpf/tests: Add exhaustive test of LD_IMM64 immediate magnitudes Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 08/14] bpf/tests: Add test case flag for verifier zero-extension Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 09/14] bpf/tests: Add JMP tests with small offsets Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 10/14] bpf/tests: Add JMP tests with degenerate conditional Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 11/14] bpf/tests: Expand branch conversion JIT test Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 12/14] bpf/tests: Add more BPF_END byte order conversion tests Johan Almbladh
2021-09-14 9:18 ` Johan Almbladh [this message]
2021-09-14 12:41 ` [PATCH bpf v4 13/14] bpf/tests: Fix error in tail call limit tests Tiezhu Yang
2021-09-14 12:55 ` Tiezhu Yang
2021-09-14 13:09 ` Johan Almbladh
2021-09-14 9:18 ` [PATCH bpf v4 14/14] bpf/tests: Add tail call limit test with external function call Johan Almbladh
2021-09-15 20:00 ` [PATCH bpf v4 00/14] bpf/tests: Extend JIT test suite coverage patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210914091842.4186267-14-johan.almbladh@anyfinetworks.com \
--to=johan.almbladh@anyfinetworks.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=iii@linux.ibm.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul@cilium.io \
--cc=songliubraving@fb.com \
--cc=yangtiezhu@loongson.cn \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).