Root Cause Analysis
The failure is triggered in process_one_work() (kernel/workqueue.c:3468-3519) when global lockdep debugging (debug_locks) transitions from 1 to 0 while a work item with a non-zero lockdep_start_depth is executing.
1. How lockdep_start_depth == 5 is reached
With CONFIG_PREEMPT_RT=y (and CONFIG_PREEMPT_RT_NEEDS_BH_LOCK=n), kworker/1:2 enters a nested bottom-half work item with 5 lockdep entries held:
- Outer
process_one_work() for wg_packet_encrypt_worker() (drivers/net/wireguard/send.c:287) acquires pwq->wq->lockdep_map and its copied work->lockdep_map (kernel/workqueue.c:3472-3473) (depth = 2).
wg_packet_encrypt_worker() calls ptr_ring_consume_bh() (include/linux/ptr_ring.h:393-402) -> spin_lock_bh() -> __local_bh_disable_ip() (kernel/softirq.c:179-236), which acquires rcu_read_lock() (rcu_lock_map, depth = 3, RCU = 1) because !current->softirq_disable_cnt && preemptible().
- On
spin_unlock_bh() -> local_bh_enable() -> __local_bh_enable_ip() (kernel/softirq.c:281-330), bh_lock_map is released and __local_bh_enable(SOFTIRQ_OFFSET, false) keeps rcu_read_lock() held while calling __do_softirq() -> handle_softirqs() -> tasklet_action() -> workqueue_softirq_action() -> bh_worker() (kernel/workqueue.c:3858-3916).
bh_worker() calls worker_lock_callback(pool) (kernel/workqueue.c:3298-3310), which acquires spin_lock_nested(&pool->cb_lock, ...) (rt_spin_lock on PREEMPT_RT, kernel/locking/spinlock_rt.c:46-66). This acquires pool->cb_lock (depth = 4) and a second rcu_read_lock() (depth = 5, RCU = 2).
At kernel/workqueue.c:3468-3469, the inner process_one_work() for usb_giveback_urb_bh() (drivers/usb/core/hcd.c:1674) records:
rcu_start_depth = rcu_preempt_depth(); (2)
lockdep_start_depth = lockdep_depth(current); (5, since debug_locks is still 1)
2. Why lockdep_depth(current) != lockdep_start_depth triggers (lock=5->0)
lockdep_depth() is defined in include/linux/lockdep.h:279 as:
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
During worker->current_func(work) (usb_giveback_urb_bh), debug_locks is cleared to 0 (debug_locks_off() / __debug_locks_off()), as confirmed by debug_show_held_locks(current) (kernel/locking/lockdep.c:6891-6898) printing "INFO: lockdep is turned off.".
When usb_giveback_urb_bh() returns to process_one_work(), kernel/workqueue.c:3508-3510 evaluates:
if (unlikely((worker->task && in_atomic()) ||
lockdep_depth(current) != lockdep_start_depth ||
rcu_preempt_depth() != rcu_start_depth))
Because debug_locks is now 0, lockdep_depth(current) returns 0 regardless of current->lockdep_depth (and despite preempt=0x00000000 and RCU=2->2 showing no actual atomic, lock, or RCU state was leaked). Comparing 0 != 5 falsely triggers the BUG: workqueue leaked atomic, lock or RCU splat.
(Note: The exact caller that disabled debug_locksβeither on another CPU or via a non-WARN lockdep path such as lockdep table/depth exhaustion in kernel/locking/lockdep.c, given panic_on_warn=1 in CONFIG_CMDLINEβis not recorded in this stack trace; TAINT_SOFTLOCKUP has LOCKDEP_STILL_OK and CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=1 is enabled.)
3. Fix Direction
In kernel/workqueue.c:process_one_work(), the lockdep depth comparison (and lockdep_start_depth check) needs to account for debug_locks becoming 0 during work execution (e.g., skipping the lockdep depth mismatch check when !debug_locks, or checking debug_locks before comparing current->lockdep_depth against lockdep_start_depth).