public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic
@ 2026-01-05 16:57 Jens Axboe
  2026-01-05 18:07 ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2026-01-05 16:57 UTC (permalink / raw)
  To: io-uring; +Cc: Max Kellermann

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.

Cc: stable@vger.kernel.org
Fixes: 751eedc4b4b7 ("io_uring/io-wq: move worker lists to struct io_wq_acct")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

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

diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index cd13d8aac3d2..6c5ef629e59a 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -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)

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic
  2026-01-05 16:57 [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic Jens Axboe
@ 2026-01-05 18:07 ` Gabriel Krisman Bertazi
  2026-01-05 18:41   ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Krisman Bertazi @ 2026-01-05 18:07 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Max Kellermann

Jens Axboe <axboe@kernel.dk> writes:

> 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 :-)

Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>


> Cc: stable@vger.kernel.org
> Fixes: 751eedc4b4b7 ("io_uring/io-wq: move worker lists to struct io_wq_acct")
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
> ---
>
> v2: fix the actual bug, rather than work-around it for the exit
>     condition only.
>
> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
> index cd13d8aac3d2..6c5ef629e59a 100644
> --- a/io_uring/io-wq.c
> +++ b/io_uring/io-wq.c
> @@ -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)

-- 
Gabriel Krisman Bertazi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic
  2026-01-05 18:07 ` Gabriel Krisman Bertazi
@ 2026-01-05 18:41   ` Jens Axboe
  2026-01-05 18:54     ` David Kahurani
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2026-01-05 18:41 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: io-uring, Max Kellermann

On 1/5/26 11:07 AM, Gabriel Krisman Bertazi wrote:
> Jens Axboe <axboe@kernel.dk> writes:
> 
>> 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 :-)
> 
> Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic
  2026-01-05 18:41   ` Jens Axboe
@ 2026-01-05 18:54     ` David Kahurani
  0 siblings, 0 replies; 4+ messages in thread
From: David Kahurani @ 2026-01-05 18:54 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Gabriel Krisman Bertazi, io-uring, Max Kellermann

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

On Mon, Jan 5, 2026 at 9:41 PM Jens Axboe <axboe@kernel.dk> wrote:
>
> On 1/5/26 11:07 AM, Gabriel Krisman Bertazi wrote:
> > Jens Axboe <axboe@kernel.dk> writes:
> >
> >> 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 :-)
> >
> > Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
>
> 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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-05 18:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05 16:57 [PATCH v2] io_uring/io-wq: fix incorrect io_wq_for_each_worker() termination logic Jens Axboe
2026-01-05 18:07 ` Gabriel Krisman Bertazi
2026-01-05 18:41   ` Jens Axboe
2026-01-05 18:54     ` David Kahurani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox