Skip to content

Commit 09584b4

Browse files
yonghong-songborkmann
authored andcommitted
bpf: fix selftests/bpf test_kmod.sh failure when CONFIG_BPF_JIT_ALWAYS_ON=y
With CONFIG_BPF_JIT_ALWAYS_ON is defined in the config file, tools/testing/selftests/bpf/test_kmod.sh failed like below: [root@localhost bpf]# ./test_kmod.sh sysctl: setting key "net.core.bpf_jit_enable": Invalid argument [ JIT enabled:0 hardened:0 ] [ 132.175681] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 132.458834] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:0 ] [ 133.456025] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 133.730935] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:1 ] [ 134.769730] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 135.050864] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:2 ] [ 136.442882] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 136.821810] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [root@localhost bpf]# The test_kmod.sh load/remove test_bpf.ko multiple times with different settings for sysctl net.core.bpf_jit_{enable,harden}. The failed test #297 of test_bpf.ko is designed such that JIT always fails. Commit 290af86 (bpf: introduce BPF_JIT_ALWAYS_ON config) introduced the following tightening logic: ... if (!bpf_prog_is_dev_bound(fp->aux)) { fp = bpf_int_jit_compile(fp); #ifdef CONFIG_BPF_JIT_ALWAYS_ON if (!fp->jited) { *err = -ENOTSUPP; return fp; } #endif ... With this logic, Test #297 always gets return value -ENOTSUPP when CONFIG_BPF_JIT_ALWAYS_ON is defined, causing the test failure. This patch fixed the failure by marking Test #297 as expected failure when CONFIG_BPF_JIT_ALWAYS_ON is defined. Fixes: 290af86 (bpf: introduce BPF_JIT_ALWAYS_ON config) Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent a6b8881 commit 09584b4

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

lib/test_bpf.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct bpf_test {
8383
__u32 result;
8484
} test[MAX_SUBTESTS];
8585
int (*fill_helper)(struct bpf_test *self);
86+
int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
8687
__u8 frag_data[MAX_DATA];
8788
int stack_depth; /* for eBPF only, since tests don't call verifier */
8889
};
@@ -2026,7 +2027,9 @@ static struct bpf_test tests[] = {
20262027
},
20272028
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
20282029
{ },
2029-
{ }
2030+
{ },
2031+
.fill_helper = NULL,
2032+
.expected_errcode = -EINVAL,
20302033
},
20312034
{
20322035
"check: div_k_0",
@@ -2036,7 +2039,9 @@ static struct bpf_test tests[] = {
20362039
},
20372040
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
20382041
{ },
2039-
{ }
2042+
{ },
2043+
.fill_helper = NULL,
2044+
.expected_errcode = -EINVAL,
20402045
},
20412046
{
20422047
"check: unknown insn",
@@ -2047,7 +2052,9 @@ static struct bpf_test tests[] = {
20472052
},
20482053
CLASSIC | FLAG_EXPECTED_FAIL,
20492054
{ },
2050-
{ }
2055+
{ },
2056+
.fill_helper = NULL,
2057+
.expected_errcode = -EINVAL,
20512058
},
20522059
{
20532060
"check: out of range spill/fill",
@@ -2057,7 +2064,9 @@ static struct bpf_test tests[] = {
20572064
},
20582065
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
20592066
{ },
2060-
{ }
2067+
{ },
2068+
.fill_helper = NULL,
2069+
.expected_errcode = -EINVAL,
20612070
},
20622071
{
20632072
"JUMPS + HOLES",
@@ -2149,6 +2158,8 @@ static struct bpf_test tests[] = {
21492158
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
21502159
{ },
21512160
{ },
2161+
.fill_helper = NULL,
2162+
.expected_errcode = -EINVAL,
21522163
},
21532164
{
21542165
"check: LDX + RET X",
@@ -2159,6 +2170,8 @@ static struct bpf_test tests[] = {
21592170
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
21602171
{ },
21612172
{ },
2173+
.fill_helper = NULL,
2174+
.expected_errcode = -EINVAL,
21622175
},
21632176
{ /* Mainly checking JIT here. */
21642177
"M[]: alt STX + LDX",
@@ -2333,6 +2346,8 @@ static struct bpf_test tests[] = {
23332346
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
23342347
{ },
23352348
{ },
2349+
.fill_helper = NULL,
2350+
.expected_errcode = -EINVAL,
23362351
},
23372352
{ /* Passes checker but fails during runtime. */
23382353
"LD [SKF_AD_OFF-1]",
@@ -5395,6 +5410,7 @@ static struct bpf_test tests[] = {
53955410
{ },
53965411
{ },
53975412
.fill_helper = bpf_fill_maxinsns4,
5413+
.expected_errcode = -EINVAL,
53985414
},
53995415
{ /* Mainly checking JIT here. */
54005416
"BPF_MAXINSNS: Very long jump",
@@ -5450,10 +5466,15 @@ static struct bpf_test tests[] = {
54505466
{
54515467
"BPF_MAXINSNS: Jump, gap, jump, ...",
54525468
{ },
5469+
#ifdef CONFIG_BPF_JIT_ALWAYS_ON
5470+
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5471+
#else
54535472
CLASSIC | FLAG_NO_DATA,
5473+
#endif
54545474
{ },
54555475
{ { 0, 0xababcbac } },
54565476
.fill_helper = bpf_fill_maxinsns11,
5477+
.expected_errcode = -ENOTSUPP,
54575478
},
54585479
{
54595480
"BPF_MAXINSNS: ld_abs+get_processor_id",
@@ -6344,7 +6365,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
63446365

63456366
*err = bpf_prog_create(&fp, &fprog);
63466367
if (tests[which].aux & FLAG_EXPECTED_FAIL) {
6347-
if (*err == -EINVAL) {
6368+
if (*err == tests[which].expected_errcode) {
63486369
pr_cont("PASS\n");
63496370
/* Verifier rejected filter as expected. */
63506371
*err = 0;

0 commit comments

Comments
 (0)