Root Cause Analysis
1. Mechanism and Involved Entities
In kernel/workqueue.c:process_one_work():
rcu_start_depth = rcu_preempt_depth();
lockdep_start_depth = lockdep_depth(current);
...
worker->current_func(work);
...
if (unlikely((worker->task && in_atomic()) ||
lockdep_depth(current) != lockdep_start_depth ||
rcu_preempt_depth() != rcu_start_depth)) {
pr_err("BUG: workqueue leaked atomic, lock or RCU: %s[%d]\n"
" preempt=0x%08x lock=%d->%d RCU=%d->%d workfn=%ps\n",
current->comm, task_pid_nr(current), preempt_count(),
lockdep_start_depth, lockdep_depth(current),
rcu_start_depth, rcu_preempt_depth(),
worker->current_func);
debug_show_held_locks(current);
dump_stack();
}
In include/linux/lockdep.h:
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
2. Triggering Sequence & Invariant Violation
-
Initial non-zero lock depth in BH workers:
On standard workqueues executed by dedicated kthreads (worker_thread()), workers enter process_one_work() with zero locks held (lockdep_start_depth == 0).
However, for bottom-half workqueues (WQ_BH), work items are dispatched through bh_worker() directly from softirq processing (in this trace: irq_forced_thread_fn -> local_bh_enable -> __do_softirq -> handle_softirqs -> tasklet_action -> workqueue_softirq_action -> bh_worker). On kernels built with CONFIG_PREEMPT_RT=y, bh_worker() legitimately holds outer locks across work item execution (specifically pool->cb_lock via worker_lock_callback(pool) at line 3865, alongside the surrounding softirq context). Hence, lockdep_depth(current) at work function entry records lockdep_start_depth = 3.
-
Disabling of lockdep during work item execution:
While the work item tcp_tsq_workfn is executing (or concurrently on another CPU), lockdep gets deactivated (debug_locks = 0 via debug_locks_off()). This can occur due to lockdep internal table limits (e.g., MAX_LOCK_DEPTH, MAX_LOCK_CHAINS) or another lockdep check failing elsewhere in the kernel.
-
False-positive lock leak detection:
When process_one_work() completes worker->current_func(work) and executes the post-condition check:
lockdep_depth(current) evaluates debug_locks ? current->lockdep_depth : 0.
- Because
debug_locks == 0, lockdep_depth(current) returns 0.
- For standard kworkers where
lockdep_start_depth == 0, 0 != 0 evaluated to false. But for bh_worker, lockdep_depth(current) != lockdep_start_depth evaluates to 0 != 3 (true).
process_one_work() does not guard the depth comparison with a check for debug_locks (unlike other kernel sanity checks such as WARN_ON_ONCE(debug_locks && p->lockdep_depth) in kernel/freezer.c).
- As a result, it reports a spurious lock leak:
preempt=0x00000000 lock=3->0 RCU=2->2 workfn=tcp_tsq_workfn
- Immediately following this,
debug_show_held_locks(current) is called, which confirms that lockdep was shut off by printing:
INFO: lockdep is turned off.