[PATCH next v2] workqueue: Avoid noise generated by userspace realtime tasks
From: Edward Adam Davis
Date: Fri Nov 27 2026 - 00:40:51 EST
A user creates a SCHED_FIFO real-time thread and pins it to CPU0, and arm
watchdog timer on CPU1 with 3s threshold. The real-time thread runs for an
extended period without voluntarily yielding the CPU, preventing standard
kworker threads on CPU0 from gaining access to the processor.
As a result, certain kernel works cannot be executed in a timely manner,
which may even trigger a watchdog report:
BUG: workqueue lockup - pool cpus=0 node=0 flags=0x0 nice=0 stuck for 5s!
Showing busy workqueues and worker pools:
workqueue mm_percpu_wq: flags=0x108
pwq 2: cpus=0 node=0 flags=0x0 nice=0 active=1 refcnt=2
pending: vmstat_update
To address this, a check for CPU-bound tasks has been added to the work
pool; this helps prevent false-positive reports caused by prolonged CPU
occupancy by real-time tasks.
Fixes: 82607adcf9cd ("workqueue: implement lockup detector")
Reported-by: syzbot+97fde463a8ffb9e839d2@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=97fde463a8ffb9e839d2
Signed-off-by: Edward Adam Davis <eadavis@xxxxxxxx>
---
v1 -> v2:
1. update subject
2. use cpu_curr_snapshot_rcu() to get stall cpu's current task
3. Exclude cases where tasks running on a stalled CPU are kernel threads
4. not for RT kernel
kernel/workqueue.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index baadc7815585..9bd9cccdf3cf 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -8287,6 +8287,23 @@ static void wq_watchdog_timer_fn(struct timer_list *unused)
if (!time_after(now, ts + thresh))
continue;
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ struct task_struct *p;
+ unsigned int policy;
+ int cpu;
+
+ cpu = pool->cpu;
+ if (cpu >= 0 && !(pool->flags & POOL_DISASSOCIATED)) {
+ guard(rcu)();
+ p = cpu_curr_snapshot_rcu(cpu);
+ if (p && !(p->flags & PF_KTHREAD)) {
+ policy = READ_ONCE(p->policy);
+ if (policy == SCHED_FIFO ||
+ policy == SCHED_RR)
+ continue;
+ }
+ }
+ }
lockup_detected = true;
stall_time = jiffies_to_msecs(now - pool_ts) / 1000;
max_stall_time = max(max_stall_time, stall_time);
--
2.43.0