History

workqueue: Move kthread_flush_worker() out of alloc_and_link_pwqs()

kthread_flush_worker() can't be called with wq_pool_mutex held. Prepare for moving wq_pool_mutex and cpu hotplug lock out of alloc_and_link_pwqs().

Lai Jiangshan committed 2 years ago

Commit 4e9a3731 parent c5178e61 file · +8 −7Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+8−7
@@ -5467,12 +5467,6 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq) · 5466 unmodified lines
54675467 }
54685468 cpus_read_unlock();
54695469
5470− /* for unbound pwq, flush the pwq_release_worker ensures that the
5471− * pwq_release_workfn() completes before calling kfree(wq).
5472− */
5473− if (ret)
5474− kthread_flush_worker(pwq_release_worker);
5475−
54765470 return ret;
54775471
54785472 enomem:
@@ -5705,8 +5699,15 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, · 226 unmodified lines
57055699 return wq;
57065700
57075701 err_free_node_nr_active:
5708− if (wq->flags & WQ_UNBOUND)
5702+ /*
5703+ * Failed alloc_and_link_pwqs() may leave pending pwq->release_work,
5704+ * flushing the pwq_release_worker ensures that the pwq_release_workfn()
5705+ * completes before calling kfree(wq).
5706+ */
5707+ if (wq->flags & WQ_UNBOUND) {
5708+ kthread_flush_worker(pwq_release_worker);
57095709 free_node_nr_active(wq->node_nr_active);
5710+ }
57105711 err_unreg_lockdep:
57115712 wq_unregister_lockdep(wq);
57125713 wq_free_lockdep(wq);