Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Speed up module_attach test

The module_attach test contains subtests which check that unloading a
module while there are BPF programs attached to its functions is not
possible because the module is still referenced.

The problem is that the test calls the generic unload_module() helper
function which is used for module cleanup after test_progs terminate and
tries to wait until all module references are released. This
unnecessarily slows down the module_attach subtests since each
unsuccessful call to unload_module() takes about 1 second.

Introduce try_unload_module() which takes the number of retries as a
parameter. Make unload_module() call it with the currently used amount
of 10000 retries but call it with just 1 retry from module_attach tests
as it is always expected to fail. This speeds up the module_attach()
test significantly.

Before:

# time ./test_progs -t module_attach
[...]
Summary: 1/14 PASSED, 0 SKIPPED, 0 FAILED

real 0m5.011s
user 0m0.293s
sys 0m0.108s

After:

# time ./test_progs -t module_attach
[...]
Summary: 1/14 PASSED, 0 SKIPPED, 0 FAILED

real 0m0.350s
user 0m0.197s
sys 0m0.063s

Signed-off-by: Viktor Malik <vmalik@redhat.com>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260306101628.3822284-1-vmalik@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Viktor Malik and committed by
Alexei Starovoitov
900b7cc7 e95e85b8

+9 -3
+1 -1
tools/testing/selftests/bpf/prog_tests/module_attach.c
··· 151 151 if (!ASSERT_OK_PTR(link, "module_attach attach")) 152 152 goto cleanup; 153 153 154 - ASSERT_ERR(unload_bpf_testmod(false), "unload_bpf_testmod"); 154 + ASSERT_ERR(try_unload_module("bpf_testmod", 1, false), "try_unload_module"); 155 155 bpf_link__destroy(link); 156 156 cleanup: 157 157 test_module_attach__destroy(skel);
+7 -2
tools/testing/selftests/bpf/testing_helpers.c
··· 368 368 return syscall(__NR_delete_module, name, flags); 369 369 } 370 370 371 - int unload_module(const char *name, bool verbose) 371 + int try_unload_module(const char *name, int retries, bool verbose) 372 372 { 373 373 int ret, cnt = 0; 374 374 ··· 379 379 ret = delete_module(name, 0); 380 380 if (!ret || errno != EAGAIN) 381 381 break; 382 - if (++cnt > 10000) { 382 + if (++cnt > retries) { 383 383 fprintf(stdout, "Unload of %s timed out\n", name); 384 384 break; 385 385 } ··· 398 398 if (verbose) 399 399 fprintf(stdout, "Successfully unloaded %s.ko.\n", name); 400 400 return 0; 401 + } 402 + 403 + int unload_module(const char *name, bool verbose) 404 + { 405 + return try_unload_module(name, 10000, verbose); 401 406 } 402 407 403 408 static int __load_module(const char *path, const char *param_values, bool verbose)
+1
tools/testing/selftests/bpf/testing_helpers.h
··· 40 40 int delete_module(const char *name, int flags); 41 41 int load_module(const char *path, bool verbose); 42 42 int load_module_params(const char *path, const char *param_values, bool verbose); 43 + int try_unload_module(const char *name, int retries, bool verbose); 43 44 int unload_module(const char *name, bool verbose); 44 45 45 46 static inline __u64 get_time_ns(void)