Skip to content

Commit b066abb

Browse files
seehearfeelborkmann
authored andcommitted
bpf, tests: Add module parameter test_suite to test_bpf module
After commit 9298e63 ("bpf/tests: Add exhaustive tests of ALU operand magnitudes"), when modprobe test_bpf.ko with JIT on mips64, there exists segment fault due to the following reason: [...] ALU64_MOV_X: all register value magnitudes jited:1 Break instruction in kernel code[#1] [...] It seems that the related JIT implementations of some test cases in test_bpf() have problems. At this moment, I do not care about the segment fault while I just want to verify the test cases of tail calls. Based on the above background and motivation, add the following module parameter test_suite to the test_bpf.ko: test_suite=<string>: only the specified test suite will be run, the string can be "test_bpf", "test_tail_calls" or "test_skb_segment". If test_suite is not specified, but test_id, test_name or test_range is specified, set 'test_bpf' as the default test suite. This is useful to only test the corresponding test suite when specifying the valid test_suite string. Any invalid test suite will result in -EINVAL being returned and no tests being run. If the test_suite is not specified or specified as empty string, it does not change the current logic, all of the test cases will be run. Here are some test results: # dmesg -c # modprobe test_bpf # dmesg | grep Summary test_bpf: Summary: 1009 PASSED, 0 FAILED, [0/997 JIT'ed] test_bpf: test_tail_calls: Summary: 8 PASSED, 0 FAILED, [0/8 JIT'ed] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_bpf # dmesg | tail -1 test_bpf: Summary: 1009 PASSED, 0 FAILED, [0/997 JIT'ed] # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_tail_calls # dmesg test_bpf: #0 Tail call leaf jited:0 21 PASS [...] test_bpf: #7 Tail call error path, index out of range jited:0 32 PASS test_bpf: test_tail_calls: Summary: 8 PASSED, 0 FAILED, [0/8 JIT'ed] # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_skb_segment # dmesg test_bpf: #0 gso_with_rx_frags PASS test_bpf: #1 gso_linear_no_head_frag PASS test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED # rmmod test_bpf # dmesg -c # modprobe test_bpf test_id=1 # dmesg test_bpf: test_bpf: set 'test_bpf' as the default test_suite. test_bpf: #1 TXA jited:0 54 51 50 PASS test_bpf: Summary: 1 PASSED, 0 FAILED, [0/1 JIT'ed] # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_bpf test_name=TXA # dmesg test_bpf: #1 TXA jited:0 54 50 51 PASS test_bpf: Summary: 1 PASSED, 0 FAILED, [0/1 JIT'ed] # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_tail_calls test_range=6,7 # dmesg test_bpf: #6 Tail call error path, NULL target jited:0 41 PASS test_bpf: #7 Tail call error path, index out of range jited:0 32 PASS test_bpf: test_tail_calls: Summary: 2 PASSED, 0 FAILED, [0/2 JIT'ed] # rmmod test_bpf # dmesg -c # modprobe test_bpf test_suite=test_skb_segment test_id=1 # dmesg test_bpf: #1 gso_linear_no_head_frag PASS test_bpf: test_skb_segment: Summary: 1 PASSED, 0 FAILED By the way, the above segment fault has been fixed in the latest bpf-next tree which contains the mips64 JIT rework. Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Johan Almbladh <[email protected]> Acked-by: Johan Almbladh <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 252c765 commit b066abb

File tree

1 file changed

+135
-77
lines changed

1 file changed

+135
-77
lines changed

lib/test_bpf.c

Lines changed: 135 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14316,72 +14316,9 @@ module_param_string(test_name, test_name, sizeof(test_name), 0);
1431614316
static int test_id = -1;
1431714317
module_param(test_id, int, 0);
1431814318

14319-
static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
14319+
static int test_range[2] = { 0, INT_MAX };
1432014320
module_param_array(test_range, int, NULL, 0);
1432114321

14322-
static __init int find_test_index(const char *test_name)
14323-
{
14324-
int i;
14325-
14326-
for (i = 0; i < ARRAY_SIZE(tests); i++) {
14327-
if (!strcmp(tests[i].descr, test_name))
14328-
return i;
14329-
}
14330-
return -1;
14331-
}
14332-
14333-
static __init int prepare_bpf_tests(void)
14334-
{
14335-
if (test_id >= 0) {
14336-
/*
14337-
* if a test_id was specified, use test_range to
14338-
* cover only that test.
14339-
*/
14340-
if (test_id >= ARRAY_SIZE(tests)) {
14341-
pr_err("test_bpf: invalid test_id specified.\n");
14342-
return -EINVAL;
14343-
}
14344-
14345-
test_range[0] = test_id;
14346-
test_range[1] = test_id;
14347-
} else if (*test_name) {
14348-
/*
14349-
* if a test_name was specified, find it and setup
14350-
* test_range to cover only that test.
14351-
*/
14352-
int idx = find_test_index(test_name);
14353-
14354-
if (idx < 0) {
14355-
pr_err("test_bpf: no test named '%s' found.\n",
14356-
test_name);
14357-
return -EINVAL;
14358-
}
14359-
test_range[0] = idx;
14360-
test_range[1] = idx;
14361-
} else {
14362-
/*
14363-
* check that the supplied test_range is valid.
14364-
*/
14365-
if (test_range[0] >= ARRAY_SIZE(tests) ||
14366-
test_range[1] >= ARRAY_SIZE(tests) ||
14367-
test_range[0] < 0 || test_range[1] < 0) {
14368-
pr_err("test_bpf: test_range is out of bound.\n");
14369-
return -EINVAL;
14370-
}
14371-
14372-
if (test_range[1] < test_range[0]) {
14373-
pr_err("test_bpf: test_range is ending before it starts.\n");
14374-
return -EINVAL;
14375-
}
14376-
}
14377-
14378-
return 0;
14379-
}
14380-
14381-
static __init void destroy_bpf_tests(void)
14382-
{
14383-
}
14384-
1438514322
static bool exclude_test(int test_id)
1438614323
{
1438714324
return test_id < test_range[0] || test_id > test_range[1];
@@ -14553,6 +14490,10 @@ static __init int test_skb_segment(void)
1455314490
for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
1455414491
const struct skb_segment_test *test = &skb_segment_tests[i];
1455514492

14493+
cond_resched();
14494+
if (exclude_test(i))
14495+
continue;
14496+
1455614497
pr_info("#%d %s ", i, test->descr);
1455714498

1455814499
if (test_skb_segment_single(test)) {
@@ -14934,6 +14875,8 @@ static __init int test_tail_calls(struct bpf_array *progs)
1493414875
int ret;
1493514876

1493614877
cond_resched();
14878+
if (exclude_test(i))
14879+
continue;
1493714880

1493814881
pr_info("#%d %s ", i, test->descr);
1493914882
if (!fp) {
@@ -14966,29 +14909,144 @@ static __init int test_tail_calls(struct bpf_array *progs)
1496614909
return err_cnt ? -EINVAL : 0;
1496714910
}
1496814911

14912+
static char test_suite[32];
14913+
module_param_string(test_suite, test_suite, sizeof(test_suite), 0);
14914+
14915+
static __init int find_test_index(const char *test_name)
14916+
{
14917+
int i;
14918+
14919+
if (!strcmp(test_suite, "test_bpf")) {
14920+
for (i = 0; i < ARRAY_SIZE(tests); i++) {
14921+
if (!strcmp(tests[i].descr, test_name))
14922+
return i;
14923+
}
14924+
}
14925+
14926+
if (!strcmp(test_suite, "test_tail_calls")) {
14927+
for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
14928+
if (!strcmp(tail_call_tests[i].descr, test_name))
14929+
return i;
14930+
}
14931+
}
14932+
14933+
if (!strcmp(test_suite, "test_skb_segment")) {
14934+
for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
14935+
if (!strcmp(skb_segment_tests[i].descr, test_name))
14936+
return i;
14937+
}
14938+
}
14939+
14940+
return -1;
14941+
}
14942+
14943+
static __init int prepare_test_range(void)
14944+
{
14945+
int valid_range;
14946+
14947+
if (!strcmp(test_suite, "test_bpf"))
14948+
valid_range = ARRAY_SIZE(tests);
14949+
else if (!strcmp(test_suite, "test_tail_calls"))
14950+
valid_range = ARRAY_SIZE(tail_call_tests);
14951+
else if (!strcmp(test_suite, "test_skb_segment"))
14952+
valid_range = ARRAY_SIZE(skb_segment_tests);
14953+
else
14954+
return 0;
14955+
14956+
if (test_id >= 0) {
14957+
/*
14958+
* if a test_id was specified, use test_range to
14959+
* cover only that test.
14960+
*/
14961+
if (test_id >= valid_range) {
14962+
pr_err("test_bpf: invalid test_id specified for '%s' suite.\n",
14963+
test_suite);
14964+
return -EINVAL;
14965+
}
14966+
14967+
test_range[0] = test_id;
14968+
test_range[1] = test_id;
14969+
} else if (*test_name) {
14970+
/*
14971+
* if a test_name was specified, find it and setup
14972+
* test_range to cover only that test.
14973+
*/
14974+
int idx = find_test_index(test_name);
14975+
14976+
if (idx < 0) {
14977+
pr_err("test_bpf: no test named '%s' found for '%s' suite.\n",
14978+
test_name, test_suite);
14979+
return -EINVAL;
14980+
}
14981+
test_range[0] = idx;
14982+
test_range[1] = idx;
14983+
} else if (test_range[0] != 0 || test_range[1] != INT_MAX) {
14984+
/*
14985+
* check that the supplied test_range is valid.
14986+
*/
14987+
if (test_range[0] < 0 || test_range[1] >= valid_range) {
14988+
pr_err("test_bpf: test_range is out of bound for '%s' suite.\n",
14989+
test_suite);
14990+
return -EINVAL;
14991+
}
14992+
14993+
if (test_range[1] < test_range[0]) {
14994+
pr_err("test_bpf: test_range is ending before it starts.\n");
14995+
return -EINVAL;
14996+
}
14997+
}
14998+
14999+
return 0;
15000+
}
15001+
1496915002
static int __init test_bpf_init(void)
1497015003
{
1497115004
struct bpf_array *progs = NULL;
1497215005
int ret;
1497315006

14974-
ret = prepare_bpf_tests();
15007+
if (strlen(test_suite) &&
15008+
strcmp(test_suite, "test_bpf") &&
15009+
strcmp(test_suite, "test_tail_calls") &&
15010+
strcmp(test_suite, "test_skb_segment")) {
15011+
pr_err("test_bpf: invalid test_suite '%s' specified.\n", test_suite);
15012+
return -EINVAL;
15013+
}
15014+
15015+
/*
15016+
* if test_suite is not specified, but test_id, test_name or test_range
15017+
* is specified, set 'test_bpf' as the default test suite.
15018+
*/
15019+
if (!strlen(test_suite) &&
15020+
(test_id != -1 || strlen(test_name) ||
15021+
(test_range[0] != 0 || test_range[1] != INT_MAX))) {
15022+
pr_info("test_bpf: set 'test_bpf' as the default test_suite.\n");
15023+
strscpy(test_suite, "test_bpf", sizeof(test_suite));
15024+
}
15025+
15026+
ret = prepare_test_range();
1497515027
if (ret < 0)
1497615028
return ret;
1497715029

14978-
ret = test_bpf();
14979-
destroy_bpf_tests();
14980-
if (ret)
14981-
return ret;
15030+
if (!strlen(test_suite) || !strcmp(test_suite, "test_bpf")) {
15031+
ret = test_bpf();
15032+
if (ret)
15033+
return ret;
15034+
}
1498215035

14983-
ret = prepare_tail_call_tests(&progs);
14984-
if (ret)
14985-
return ret;
14986-
ret = test_tail_calls(progs);
14987-
destroy_tail_call_tests(progs);
14988-
if (ret)
14989-
return ret;
15036+
if (!strlen(test_suite) || !strcmp(test_suite, "test_tail_calls")) {
15037+
ret = prepare_tail_call_tests(&progs);
15038+
if (ret)
15039+
return ret;
15040+
ret = test_tail_calls(progs);
15041+
destroy_tail_call_tests(progs);
15042+
if (ret)
15043+
return ret;
15044+
}
1499015045

14991-
return test_skb_segment();
15046+
if (!strlen(test_suite) || !strcmp(test_suite, "test_skb_segment"))
15047+
return test_skb_segment();
15048+
15049+
return 0;
1499215050
}
1499315051

1499415052
static void __exit test_bpf_exit(void)

0 commit comments

Comments
 (0)