Skip to contentSkip to conversation

workqueue: BUG_ON() a pwq release before workqueue_init()

PATCH Applied Breno Leitao 2 participants 2 messages Sep 11 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueue: BUG_ON() a pwq release before workqueue_init()

put_pwq() bounces the release to pwq_release_worker to get out from under pool->lock. workqueue_init() creates that kthread_worker well after workqueue_init_early() has built the system workqueues, so a pwq allocation failing partway through apply_wqattrs_prepare() unwinds through apply_wqattrs_cleanup() and dereferences a NULL worker.

There is no way back from that. Running the release inline is not an option, that is what the bounce exists for, and workqueue_init_early() already BUG_ON()s a system workqueue it failed to allocate.

BUG_ON() the missing worker instead of oopsing inside kthread_queue_work().

---
 kernel/workqueue.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/workqueue.c +8 -0
index 39187f424c34e7..e618108c6127da 100644
@@ -1771,6 +1771,14 @@ static void put_pwq(struct pool_workqueue *pwq)
 	lockdep_assert_held(&pwq->pool->lock);
 	if (likely(--pwq->refcnt))
 		return;
+
+	/*
+	 * pwq_release_worker is only created in workqueue_init(). Getting
+	 * here before that means an early workqueue allocation failed, which
+	 * is fatal anyway.
+	 */
+	BUG_ON(!pwq_release_worker);
+
 	/*
 	 * @pwq can't be released under pool->lock, bounce to a dedicated
 	 * kthread_worker to avoid A-A deadlocks.

---
base-commit: d8c2ce77cd09077ec57c4bed5678f76425157ccd
change-id: 20260911-tejun_bug_on-5b72d9012b12

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
maintainer Applied
#1 lore raw

Hello,

Applied to wq/for-7.4.

Thanks.

Signature · 1 line
tejun