From 00d98463dfa7142e4fa48dace2f77c6efcfef460 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Fri, 6 Oct 2023 06:22:21 +0000 Subject: [PATCH] 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: ccd9a8be2e42 ("selftests/bpf: Add various more tcx test cases") Reported-by: Martin KaFai Lau Signed-off-by: Daniel Borkmann --- tools/testing/selftests/bpf/prog_tests/tc_links.c | 10 +++++----- tools/testing/selftests/bpf/prog_tests/tc_opts.c | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/tc_links.c b/tools/testing/selftests/bpf/prog_tests/tc_links.c index 073fbdbea96875..7d3e875402752d 100644 --- a/tools/testing/selftests/bpf/prog_tests/tc_links.c +++ b/tools/testing/selftests/bpf/prog_tests/tc_links.c @@ -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); diff --git a/tools/testing/selftests/bpf/prog_tests/tc_opts.c b/tools/testing/selftests/bpf/prog_tests/tc_opts.c index 2174bea3427ebb..25d7842748a469 100644 --- a/tools/testing/selftests/bpf/prog_tests/tc_opts.c +++ b/tools/testing/selftests/bpf/prog_tests/tc_opts.c @@ -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);