public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iouring: Fix min_timeout behaviour
@ 2026-06-06 20:11 Christian A. Ehrhardt
  2026-06-06 21:55 ` Jens Axboe
  2026-06-07 22:13 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Christian A. Ehrhardt @ 2026-06-06 20:11 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Christian A. Ehrhardt, Tip ten Brink, io-uring, linux-kernel

The wakeup condition if a min timeout is present and has
expired is that at least _one_ CQE was posted. Thus set
the cq_tail target to ->cq_min_tail + 1. Without this
commit a spurious wakeup can result in a premature wakeup
because io_should_wake() will return true even if _no_ CQE
was posted at all.

Tested by running the liburing testsuite with no regressions.

Additionally, tested by turning all calls to schedule() in
io_uring/wait.c into calls to schedule_timeout(1) to force
the spurious wakeups. With these spurious wakeups the
min-timeout.t test fails before and passes after this commit.

Cc: Jens Axboe <axboe@kernel.dk>
Cc: Tip ten Brink <tip@tenbrinkmeijs.com>
Fixes: e15cb2200b93 ("io_uring: fix min_wait wakeups for SQPOLL")
Cc: stable@vger.kernel.org
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
---
 io_uring/wait.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/wait.c b/io_uring/wait.c
index ec01e78a216d..d005ea17b35f 100644
--- a/io_uring/wait.c
+++ b/io_uring/wait.c
@@ -103,7 +103,7 @@ static enum hrtimer_restart io_cqring_min_timer_wakeup(struct hrtimer *timer)
 	}
 
 	/* any generated CQE posted past this time should wake us up */
-	iowq->cq_tail = iowq->cq_min_tail;
+	iowq->cq_tail = iowq->cq_min_tail + 1;
 
 	hrtimer_update_function(&iowq->t, io_cqring_timer_wakeup);
 	hrtimer_set_expires(timer, iowq->timeout);
-- 
2.43.0


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

* Re: [PATCH] iouring: Fix min_timeout behaviour
  2026-06-06 20:11 [PATCH] iouring: Fix min_timeout behaviour Christian A. Ehrhardt
@ 2026-06-06 21:55 ` Jens Axboe
  2026-06-07 10:40   ` Christian A. Ehrhardt
  2026-06-07 22:13 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2026-06-06 21:55 UTC (permalink / raw)
  To: Christian A. Ehrhardt; +Cc: Tip ten Brink, io-uring, linux-kernel

On 6/6/26 2:11 PM, Christian A. Ehrhardt wrote:
> The wakeup condition if a min timeout is present and has
> expired is that at least _one_ CQE was posted. Thus set
> the cq_tail target to ->cq_min_tail + 1. Without this
> commit a spurious wakeup can result in a premature wakeup
> because io_should_wake() will return true even if _no_ CQE
> was posted at all.
> 
> Tested by running the liburing testsuite with no regressions.
> 
> Additionally, tested by turning all calls to schedule() in
> io_uring/wait.c into calls to schedule_timeout(1) to force
> the spurious wakeups. With these spurious wakeups the
> min-timeout.t test fails before and passes after this commit.

Either this or the test case is broken, with or without the change
you sent for the test case. I'll take a look, but it's definitely
not passing as-is.

-- 
Jens Axboe


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

* Re: [PATCH] iouring: Fix min_timeout behaviour
  2026-06-06 21:55 ` Jens Axboe
@ 2026-06-07 10:40   ` Christian A. Ehrhardt
  0 siblings, 0 replies; 4+ messages in thread
From: Christian A. Ehrhardt @ 2026-06-07 10:40 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Tip ten Brink, io-uring, linux-kernel

On Sat, Jun 06, 2026 at 03:55:18PM -0600, Jens Axboe wrote:
> On 6/6/26 2:11 PM, Christian A. Ehrhardt wrote:
> > The wakeup condition if a min timeout is present and has
> > expired is that at least _one_ CQE was posted. Thus set
> > the cq_tail target to ->cq_min_tail + 1. Without this
> > commit a spurious wakeup can result in a premature wakeup
> > because io_should_wake() will return true even if _no_ CQE
> > was posted at all.
> > 
> > Tested by running the liburing testsuite with no regressions.
> > 
> > Additionally, tested by turning all calls to schedule() in
> > io_uring/wait.c into calls to schedule_timeout(1) to force
> > the spurious wakeups. With these spurious wakeups the
> > min-timeout.t test fails before and passes after this commit.
> 
> Either this or the test case is broken, with or without the change
> you sent for the test case. I'll take a look, but it's definitely
> not passing as-is.

I also tested with the zig reproducer from
	https://github.com/axboe/liburing/issues/1477
and with the spurious wakeups the reproducer shows the premature
wakeup without any CQE posted, too. It seems that the missing "+1"
is an oversight that got introduced between v1 and v2 of the commit
that fixed the above issue.


Best regards,
Christian

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

* Re: [PATCH] iouring: Fix min_timeout behaviour
  2026-06-06 20:11 [PATCH] iouring: Fix min_timeout behaviour Christian A. Ehrhardt
  2026-06-06 21:55 ` Jens Axboe
@ 2026-06-07 22:13 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-06-07 22:13 UTC (permalink / raw)
  To: Christian A. Ehrhardt; +Cc: Tip ten Brink, io-uring, linux-kernel


On Sat, 06 Jun 2026 22:11:20 +0200, Christian A. Ehrhardt wrote:
> The wakeup condition if a min timeout is present and has
> expired is that at least _one_ CQE was posted. Thus set
> the cq_tail target to ->cq_min_tail + 1. Without this
> commit a spurious wakeup can result in a premature wakeup
> because io_should_wake() will return true even if _no_ CQE
> was posted at all.
> 
> [...]

Applied, thanks!

[1/1] iouring: Fix min_timeout behaviour
      commit: 29fe1bd01b99714f3136f922230a643c2742cda9

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-06-07 22:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-06 20:11 [PATCH] iouring: Fix min_timeout behaviour Christian A. Ehrhardt
2026-06-06 21:55 ` Jens Axboe
2026-06-07 10:40   ` Christian A. Ehrhardt
2026-06-07 22:13 ` Jens Axboe

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