Skip to contentSkip to conversation

io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic

PATCH In review Jens Axboe 3 participants 4 messages Jan 5 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH v2 1/1 io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic

A previous commit added this helper, and had it terminate if false is returned from the handler. However, that is completely opposite, it should abort the loop if true is returned.

Fix this up by having io_wq_for_each_worker() keep iterating as long as false is returned, and only abort if true is returned.

Fixes 751eedc4b4b7 ("io_uring/io-wq: move worker lists to struct io_wq_acct")

---

v2: fix the actual bug, rather than work-around it for the exit
condition only.

io_uring/io-wq.c +3 -3
index cd13d8aac3d2..6c5ef629e59a 100644
@@ -952,11 +952,11 @@ static bool io_wq_for_each_worker(struct io_wq *wq,
 				  void *data)
 {
 	for (int i = 0; i < IO_WQ_ACCT_NR; i++) {
-		if (!io_acct_for_each_worker(&wq->acct[i], func, data))
-			return false;
+		if (io_acct_for_each_worker(&wq->acct[i], func, data))
+			return true;
 	}
 
-	return true;
+	return false;
 }
 
 static bool io_wq_worker_wake(struct io_worker *worker, void *data)
Signature · 1 line
Jens Axboe
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Jens Axboe

A previous commit added this helper, and had it terminate if false is returned from the handler. However, that is completely opposite, it should abort the loop if true is returned.

Fix this up by having io_wq_for_each_worker() keep iterating as long as false is returned, and only abort if true is returned.

The fix is good, but the API is just weird.

io_acct_for_each_worker returning true indicates an error that will abort the wq walk. It is a non-issue, since all the two callers cannot fail and always return false for success :-)

Quoted 28 lines
Fixes 751eedc4b4b7 ("io_uring/io-wq: move worker lists to struct io_wq_acct")

---

v2: fix the actual bug, rather than work-around it for the exit
condition only.

io_uring/io-wq.c +3 -3
index cd13d8aac3d2..6c5ef629e59a 100644
@@ -952,11 +952,11 @@ static bool io_wq_for_each_worker(struct io_wq *wq,
 				  void *data)
 {
 	for (int i = 0; i < IO_WQ_ACCT_NR; i++) {
-		if (!io_acct_for_each_worker(&wq->acct[i], func, data))
-			return false;
+		if (io_acct_for_each_worker(&wq->acct[i], func, data))
+			return true;
 	}
 
-	return true;
+	return false;
 }
 
 static bool io_wq_worker_wake(struct io_worker *worker, void *data)
Signature · 1 line
Gabriel Krisman Bertazi
author maintainer
#2 lore raw
Quoted 9 lines · Gabriel Krisman Bertazi
Quoted 6 lines · Jens Axboe

A previous commit added this helper, and had it terminate if false is returned from the handler. However, that is completely opposite, it should abort the loop if true is returned.

Fix this up by having io_wq_for_each_worker() keep iterating as long as false is returned, and only abort if true is returned.

Quoted 7 lines

The fix is good, but the API is just weird.

io_acct_for_each_worker returning true indicates an error that will abort the wq walk. It is a non-issue, since all the two callers cannot fail and always return false for success :-)

Thanks for taking a look! Was going to post a followup just killing the return value of io_wq_for_each_worker() to void as nobody uses it. Only the cancelation side with its matching will use a true return, most of iterations want to iterate all of them.

Signature · 1 line
Jens Axboe
#3 lore raw

FOSS is generally in perfect condition for rip off :-)

Quoted 27 lines · Jens Axboe
Quoted 9 lines · Gabriel Krisman Bertazi
Quoted 6 lines · Jens Axboe

A previous commit added this helper, and had it terminate if false is returned from the handler. However, that is completely opposite, it should abort the loop if true is returned.

Fix this up by having io_wq_for_each_worker() keep iterating as long as false is returned, and only abort if true is returned.

Quoted 7 lines

The fix is good, but the API is just weird.

io_acct_for_each_worker returning true indicates an error that will abort the wq walk. It is a non-issue, since all the two callers cannot fail and always return false for success :-)

Thanks for taking a look! Was going to post a followup just killing the return value of io_wq_for_each_worker() to void as nobody uses it. Only the cancelation side with its matching will use a true return, most of iterations want to iterate all of them.

--
Jens Axboe