mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v3] selftests/bpf: Wait for wq callback before checking ok_sleepable
@ 2026-11-03  3:21 Jonathan Bastari Thamrin via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Jonathan Bastari Thamrin via B4 Relay @ 2026-11-03  3:21 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Shuah Khan
  Cc: bpf, linux-kselftest, linux-kernel, Mykyta Yatsenko, qikeyu2017,
	Jonathan Bastari Thamrin

From: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>

wq test fails with ok_sleepable reading 0 instead of 2 as workqueue
callback hasn't executed before check.

This happens as callback runs later on a kworker and 50us isn't always
enough.

Change from 50us sleep to waiting for callback by polling
ok_sleepable every 1ms for up to 10s. If the callback never runs, the
test fails instead of hanging, similar to ksock_wq.c. If test_run
fails, it skips the wait and goes to clean_up since the callback
was never queued.

Before (usleep(50)): 3 fails out of 5000 runs
Diagnosing issue (usleep(0)): 23 out of 100 runs
After: 0 out of 2000 runs
Tested using vmtest on x86_64, test pinned to one CPU with `yes` load

Link: https://github.com/kernel-patches/vmtest/issues/455
Signed-off-by: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>
---
Changes in v3:
- Go back to bounded polling on ok_sleepable, similar to
  ksock_wq.c, as unbounded wait in v2 can hang if callback never
  runs (Alexei)
- Skip the wait if test_run fails, and raise limit to 10s (Alexei)
- Drop the wq_cb_run flag and the progs/wq.c changes
- Link to v2: https://lore.kernel.org/r/20261102-wq-poll-fix-v2-1-48b7d12815b8@gmail.com

Changes in v2:
- Wait for callback via a wq_cb_run flag instead of polling with a
  timeout, similar to test_struct_ops_assoc.c (Kumar)
- Link to v1: https://lore.kernel.org/r/20261005-wq-poll-fix-v1-1-99ce4bac59f4@gmail.com
---
 tools/testing/selftests/bpf/prog_tests/wq.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c
index 97926e35aaf2..a4f71bc34fa6 100644
--- a/tools/testing/selftests/bpf/prog_tests/wq.c
+++ b/tools/testing/selftests/bpf/prog_tests/wq.c
@@ -4,10 +4,13 @@
 #include "wq.skel.h"
 #include "wq_failures.skel.h"
 
+#define CALLBACK_WAIT_RETRIES 10000
+#define CALLBACK_WAIT_US 1000
+
 void serial_test_wq(void)
 {
 	struct wq *wq_skel = NULL;
-	int err, prog_fd;
+	int err, prog_fd, i;
 
 	LIBBPF_OPTS(bpf_test_run_opts, topts);
 
@@ -25,11 +28,12 @@ void serial_test_wq(void)
 
 	prog_fd = bpf_program__fd(wq_skel->progs.test_syscall_array_sleepable);
 	err = bpf_prog_test_run_opts(prog_fd, &topts);
-	ASSERT_OK(err, "test_run");
-	ASSERT_EQ(topts.retval, 0, "test_run");
-
-	usleep(50); /* 10 usecs should be enough, but give it extra */
+	if (!ASSERT_OK(err, "test_run") || !ASSERT_EQ(topts.retval, 0, "test_run"))
+		goto clean_up;
 
+	/* wait for wq callback to finish and fail instead of hanging if it never runs */
+	for (i = 0; i < CALLBACK_WAIT_RETRIES && !READ_ONCE(wq_skel->bss->ok_sleepable); i++)
+		usleep(CALLBACK_WAIT_US);
 	ASSERT_EQ(wq_skel->bss->ok_sleepable, (1 << 1), "ok_sleepable");
 clean_up:
 	wq__destroy(wq_skel);

---
base-commit: cd5bc55288d4fd999595c8f2af6a5408cbe92a52
change-id: 20261102-wq-poll-fix-e3902f46512c

Best regards,
-- 
Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-03  3:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03  3:21 [PATCH bpf-next v3] selftests/bpf: Wait for wq callback before checking ok_sleepable Jonathan Bastari Thamrin via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®