| #
33b2c64f |
| 12-Oct-2026 |
Yun Lu <luyun@kylinos.cn> |
selftests/bpf: Add task work BUSY window test
Add a regression test for reusing a bpf_task_work context while its scheduling irq_work is still BUSY. A test that schedules from a thread pinned to on
selftests/bpf: Add task work BUSY window test
Add a regression test for reusing a bpf_task_work context while its scheduling irq_work is still BUSY. A test that schedules from a thread pinned to one CPU never observes that window: irq_work_queue() self-IPIs the local CPU and the invocation completes before the thread's next syscall.
Use an fexit program on task_work_add() to delay the scheduling handler's return with a time- and iteration-bounded busy-wait, after the first-round callback was published and before the handler's tail state transition. The target task attempts to reuse the same context from a later syscall, strictly after its own callback wrapper returned, so the context is STANDBY at that point. A valid window requires the fexit program to observe the attempt's acknowledgment before returning, which proves the attempt ran while the old handler, and thus the BUSY irq_work, was still in flight. With the map and program references held and no competing scheduler, the only possible source of -EBUSY for that attempt is the BUSY check in the acquire path. Check that the attempt is rejected with -EBUSY, that scheduling succeeds on a bounded retry once BUSY clears, and that the second callback runs exactly once.
Each attempt uses dedicated workers and a fresh map value. Reset the shared slots before enabling the workers. Stop and join them at the end of the attempt, then wait for their TIDs to disappear from PID lookup before checking the final callback count or starting another attempt. join alone can return before exit_task_work(); a signal-zero tgkill probe still finds the worker until after its exit task_work has run. Bound that wait and fail on unexpected probe errors. Callback deliveries are also matched against the window's generation.
Missed windows are counted and retried within a bounded attempt budget; hard failures fail the test. Record the busy-wait elapsed time after worker cleanup as a diagnostic, without asserting a wall-clock bound, since host vCPU preemption can stretch wall-clock time without affecting the gate behavior under test.
Skip when fewer than two CPUs are available or when the loaded kconfig extern identifies CONFIG_PREEMPT_RT. Check that extern before attaching programs or starting workers. Load and attach errors fail the test instead of being inferred from tracefs file paths and reported as unsupported.
Signed-off-by: Yun Lu <luyun@kylinos.cn> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261012061915.231254-5-luyun_611@163.com
show more ...
|