[PATCH 2/2] fdmon-io_uring: check CQ ring directly in gsource_check

Jens Axboe posted 2 patches 6 days, 22 hours ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>
[PATCH 2/2] fdmon-io_uring: check CQ ring directly in gsource_check
Posted by Jens Axboe 6 days, 22 hours ago
gsource_check() only looks at the ppoll revents for the io_uring fd,
but CQEs can be posted during gsource_prepare()'s io_uring_submit()
call via kernel task_work processing on syscall exit. These completions
are already sitting in the CQ ring but the ring fd may not be signaled
yet, causing gsource_check() to return false.

Add a fallback io_uring_cq_ready() check so completions that arrive
during submission are dispatched immediately rather than waiting for
the next ppoll() cycle.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 util/fdmon-io_uring.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c
index 96392876b490..124e40594c17 100644
--- a/util/fdmon-io_uring.c
+++ b/util/fdmon-io_uring.c
@@ -352,7 +352,19 @@ static void fdmon_io_uring_gsource_prepare(AioContext *ctx)
 static bool fdmon_io_uring_gsource_check(AioContext *ctx)
 {
     gpointer tag = ctx->io_uring_fd_tag;
-    return g_source_query_unix_fd(&ctx->source, tag) & G_IO_IN;
+
+    /* Check ppoll revents (normal path) */
+    if (g_source_query_unix_fd(&ctx->source, tag) & G_IO_IN) {
+        return true;
+    }
+
+    /*
+     * Also check for CQEs that may have been posted during prepare's
+     * io_uring_submit() via task_work on syscall exit.  Without this,
+     * the main loop can miss completions and sleep in ppoll() until the
+     * next timer fires.
+     */
+    return io_uring_cq_ready(&ctx->fdmon_io_uring);
 }
 
 /* Dispatch CQE handlers that are ready */
-- 
2.51.0
Re: [PATCH 2/2] fdmon-io_uring: check CQ ring directly in gsource_check
Posted by Stefan Hajnoczi 1 day, 20 hours ago
On Fri, Feb 13, 2026 at 07:26:37AM -0700, Jens Axboe wrote:
> gsource_check() only looks at the ppoll revents for the io_uring fd,
> but CQEs can be posted during gsource_prepare()'s io_uring_submit()
> call via kernel task_work processing on syscall exit. These completions
> are already sitting in the CQ ring but the ring fd may not be signaled
> yet, causing gsource_check() to return false.
> 
> Add a fallback io_uring_cq_ready() check so completions that arrive
> during submission are dispatched immediately rather than waiting for
> the next ppoll() cycle.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>  util/fdmon-io_uring.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Re: [PATCH 2/2] fdmon-io_uring: check CQ ring directly in gsource_check
Posted by Kevin Wolf 6 days, 20 hours ago
Am 13.02.2026 um 15:26 hat Jens Axboe geschrieben:
> gsource_check() only looks at the ppoll revents for the io_uring fd,
> but CQEs can be posted during gsource_prepare()'s io_uring_submit()
> call via kernel task_work processing on syscall exit. These completions
> are already sitting in the CQ ring but the ring fd may not be signaled
> yet, causing gsource_check() to return false.
> 
> Add a fallback io_uring_cq_ready() check so completions that arrive
> during submission are dispatched immediately rather than waiting for
> the next ppoll() cycle.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>