Skip to contentSkip to conversation

workqueue: Always queue work items to the newest PWQ for order workqueues

PATCH Applied Lai Jiangshan 3 participants 3 messages Jul 3, 2024 Workqueue

lore
Share & tools
lore

Lai Jiangshan

author reviewer
#0 lore raw

PATCH 1/1 workqueue: Always queue work items to the newest PWQ for order workqueues

From: Lai Jiangshan <[email protected]>

To ensure non-reentrancy, __queue_work() attempts to enqueue a work item to the pool of the currently executing worker. This is not only unnecessary for an ordered workqueue, where order inherently suggests non-reentrancy, but it could also disrupt the sequence if the item is not enqueued on the newest PWQ.

Just queue it to the newest PWQ and let order management guarantees non-reentrancy.

Fixes 4c065dbce1e8("workqueue: Enable unbound cpumask update on ordered workqueues")
---
 kernel/workqueue.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/workqueue.c +5 -1
index c910f3c28664..d4fecd23ea44 100644
@@ -2271,9 +2271,13 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
 	 * If @work was previously on a different pool, it might still be
 	 * running there, in which case the work needs to be queued on that
 	 * pool to guarantee non-reentrancy.
+	 *
+	 * For ordered workqueue, work items must be queued on the newest pwq
+	 * for accurate order management.  Guaranteed order also guarantees
+	 * non-reentrancy.  See the comments above unplug_oldest_pwq().
 	 */
 	last_pool = get_work_pool(work);
-	if (last_pool && last_pool != pool) {
+	if (last_pool && last_pool != pool && !(wq->flags & __WQ_ORDERED)) {
 		struct worker *worker;
 
 		raw_spin_lock(&last_pool->lock);
Signature · 1 line
2.19.1.6.gb485710b
maintainer Applied
#1 lore raw
Quoted 8 lines · Lai Jiangshan

From: Lai Jiangshan <[email protected]>

To ensure non-reentrancy, __queue_work() attempts to enqueue a work item to the pool of the currently executing worker. This is not only unnecessary for an ordered workqueue, where order inherently suggests non-reentrancy, but it could also disrupt the sequence if the item is not enqueued on the newest PWQ.

Quoted 5 lines

Just queue it to the newest PWQ and let order management guarantees non-reentrancy.

Fixes 4c065dbce1e8("workqueue: Enable unbound cpumask update on ordered workqueues")

Applied to wq/for-6.10-fixes w/ stable cc added.

Thanks.

Signature · 1 line
tejun
Acked-by on v1 1/1
#2 lore raw
In reply to Lai Jiangshan
Quoted 26 lines · Lai Jiangshan

From: Lai Jiangshan <[email protected]>

To ensure non-reentrancy, __queue_work() attempts to enqueue a work item to the pool of the currently executing worker. This is not only unnecessary for an ordered workqueue, where order inherently suggests non-reentrancy, but it could also disrupt the sequence if the item is not enqueued on the newest PWQ.

Just queue it to the newest PWQ and let order management guarantees non-reentrancy.

Fixes 4c065dbce1e8("workqueue: Enable unbound cpumask update on ordered workqueues")
---
  kernel/workqueue.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
kernel/workqueue.c +1 -0
index c910f3c28664..d4fecd23ea44 100644
@@ -2271,9 +2271,13 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
  	 * If @work was previously on a different pool, it might still be
  	 * running there, in which case the work needs to be queued on that
  	 * pool to guarantee non-reentrancy.
+	 *

kernel/workqueue.c static void __queue_work(int cpu, struct workqueue_struct *wq, · line 2283

Quoted 10 lines
kernel/workqueue.c +4 -1
+	 * For ordered workqueue, work items must be queued on the newest pwq
+	 * for accurate order management.  Guaranteed order also guarantees
+	 * non-reentrancy.  See the comments above unplug_oldest_pwq().
  	 */
  	last_pool = get_work_pool(work);
-	if (last_pool && last_pool != pool) {
+	if (last_pool && last_pool != pool && !(wq->flags & __WQ_ORDERED)) {
  		struct worker *worker;
 
  		raw_spin_lock(&last_pool->lock);

Thanks for the fix again.