Skip to content

Commit

Permalink
selftests/bpf: Fix wq test.
Browse files Browse the repository at this point in the history
The wq test was missing destroy(skel) part which was causing bpf progs to stay
loaded. That was causing test_progs to complain with
"Failed to unload bpf_testmod.ko from kernel: -11" message, but adding
destroy() wasn't enough, since wq callback may be delayed, so loop on unload of
bpf_testmod if errno is EAGAIN.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Fixes: 8290dba ("selftests/bpf: wq: add bpf_wq_start() checks")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Alexei Starovoitov committed Apr 24, 2024
1 parent 5305b37 commit 82e38a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void serial_test_wq(void)
usleep(50); /* 10 usecs should be enough, but give it extra */

ASSERT_EQ(wq_skel->bss->ok_sleepable, (1 << 1), "ok_sleepable");
wq__destroy(wq_skel);
}

void serial_test_failures_wq(void)
Expand Down
16 changes: 15 additions & 1 deletion tools/testing/selftests/bpf/testing_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,23 @@ int delete_module(const char *name, int flags)

int unload_bpf_testmod(bool verbose)
{
int ret, cnt = 0;

if (kern_sync_rcu())
fprintf(stdout, "Failed to trigger kernel-side RCU sync!\n");
if (delete_module("bpf_testmod", 0)) {

for (;;) {
ret = delete_module("bpf_testmod", 0);
if (!ret || errno != EAGAIN)
break;
if (++cnt > 10000) {
fprintf(stdout, "Unload of bpf_testmod timed out\n");
break;
}
usleep(100);
}

if (ret) {
if (errno == ENOENT) {
if (verbose)
fprintf(stdout, "bpf_testmod.ko is already unloaded.\n");
Expand Down

0 comments on commit 82e38a5

Please sign in to comment.