Skip to content

Commit

Permalink
selftests/bpf: Fix reorder of attachment in mixed mprog test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
borkmann committed Oct 6, 2023
1 parent a70af43 commit 829e012
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions tools/testing/selftests/bpf/prog_tests/tc_links.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,17 +1624,17 @@ static void test_tc_chain_mixed(int target)
if (!ASSERT_OK(err, "bpf_tc_hook_create"))
goto cleanup;

tc_opts.prog_fd = bpf_program__fd(skel->progs.tc5);
err = bpf_tc_attach(&tc_hook, &tc_opts);
if (!ASSERT_OK(err, "bpf_tc_attach"))
goto cleanup;

link = bpf_program__attach_tcx(skel->progs.tc6, loopback, &optl);
if (!ASSERT_OK_PTR(link, "link_attach"))
goto cleanup;

skel->links.tc6 = link;

tc_opts.prog_fd = bpf_program__fd(skel->progs.tc5);
err = bpf_tc_attach(&tc_hook, &tc_opts);
if (!ASSERT_OK(err, "bpf_tc_attach"))
goto cleanup;

assert_mprog_count(target, 1);

ASSERT_OK(system(ping_cmd), ping_cmd);
Expand Down
12 changes: 6 additions & 6 deletions tools/testing/selftests/bpf/prog_tests/tc_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2303,17 +2303,17 @@ static void test_tc_chain_mixed(int target)
if (!ASSERT_OK(err, "bpf_tc_hook_create"))
goto cleanup;

tc_opts.prog_fd = fd2;
err = bpf_tc_attach(&tc_hook, &tc_opts);
if (!ASSERT_OK(err, "bpf_tc_attach"))
goto cleanup_hook;

err = bpf_prog_attach_opts(fd3, loopback, target, &opta);
if (!ASSERT_EQ(err, 0, "prog_attach"))
goto cleanup_filter;
goto cleanup_hook;

detach_fd = fd3;

tc_opts.prog_fd = fd2;
err = bpf_tc_attach(&tc_hook, &tc_opts);
if (!ASSERT_OK(err, "bpf_tc_attach"))
goto cleanup_filter;

assert_mprog_count(target, 1);

ASSERT_OK(system(ping_cmd), ping_cmd);
Expand Down

0 comments on commit 829e012

Please sign in to comment.