Skip to content

Commit 00d9846

Browse files
committed
selftests/bpf: Fix reorder of attachment in mixed mprog test
Martin reported that on his local dev machine the test_tc_chain_mixed() fails as "test_tc_chain_mixed:FAIL:seen_tc5 unexpected seen_tc5: actual 1 != expected 0". However, when running in a more isolated setup (qemu in particular), it works fine for him. The reason is that there is a small race-window where seen_tc5 could turn into true given we first attach legacy tc, and then tcx. Fix it by swapping the order of attachment. Fixes: ccd9a8b ("selftests/bpf: Add various more tcx test cases") Reported-by: Martin KaFai Lau <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 77041b4 commit 00d9846

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tools/testing/selftests/bpf/prog_tests/tc_links.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,17 +1624,17 @@ static void test_tc_chain_mixed(int target)
16241624
if (!ASSERT_OK(err, "bpf_tc_hook_create"))
16251625
goto cleanup;
16261626

1627-
tc_opts.prog_fd = bpf_program__fd(skel->progs.tc5);
1628-
err = bpf_tc_attach(&tc_hook, &tc_opts);
1629-
if (!ASSERT_OK(err, "bpf_tc_attach"))
1630-
goto cleanup;
1631-
16321627
link = bpf_program__attach_tcx(skel->progs.tc6, loopback, &optl);
16331628
if (!ASSERT_OK_PTR(link, "link_attach"))
16341629
goto cleanup;
16351630

16361631
skel->links.tc6 = link;
16371632

1633+
tc_opts.prog_fd = bpf_program__fd(skel->progs.tc5);
1634+
err = bpf_tc_attach(&tc_hook, &tc_opts);
1635+
if (!ASSERT_OK(err, "bpf_tc_attach"))
1636+
goto cleanup;
1637+
16381638
assert_mprog_count(target, 1);
16391639

16401640
ASSERT_OK(system(ping_cmd), ping_cmd);

tools/testing/selftests/bpf/prog_tests/tc_opts.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,17 +2303,17 @@ static void test_tc_chain_mixed(int target)
23032303
if (!ASSERT_OK(err, "bpf_tc_hook_create"))
23042304
goto cleanup;
23052305

2306-
tc_opts.prog_fd = fd2;
2307-
err = bpf_tc_attach(&tc_hook, &tc_opts);
2308-
if (!ASSERT_OK(err, "bpf_tc_attach"))
2309-
goto cleanup_hook;
2310-
23112306
err = bpf_prog_attach_opts(fd3, loopback, target, &opta);
23122307
if (!ASSERT_EQ(err, 0, "prog_attach"))
2313-
goto cleanup_filter;
2308+
goto cleanup_hook;
23142309

23152310
detach_fd = fd3;
23162311

2312+
tc_opts.prog_fd = fd2;
2313+
err = bpf_tc_attach(&tc_hook, &tc_opts);
2314+
if (!ASSERT_OK(err, "bpf_tc_attach"))
2315+
goto cleanup_filter;
2316+
23172317
assert_mprog_count(target, 1);
23182318

23192319
ASSERT_OK(system(ping_cmd), ping_cmd);

0 commit comments

Comments
 (0)