* [PATCH] io_uring/rw: do not infer NOWAIT support from poll readiness
@ 2026-09-19 11:59 Tianyi Chen
0 siblings, 0 replies; only message in thread
From: Tianyi Chen @ 2026-09-19 11:59 UTC (permalink / raw)
To: io-uring; +Cc: axboe
A poll-ready file can still block if another reader consumes the data or
a write exceeds the available space. Without FMODE_NOWAIT or O_NONBLOCK,
IOCB_NOWAIT does not prevent this from blocking the ring submitter.
Remove the poll fallback and route unsupported requests to io-wq after
polling, rather than repeatedly retrying them in task work. Downgrade
multishot reads on these files to single-shot completion; files with
nonblocking support keep multishot behavior.
Fixes: f7c913438533 ("io_uring/rw: allow pollable non-blocking attempts for !FMODE_NOWAIT")
Closes: https://github.com/axboe/liburing/issues/1623
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@tychen.cc>
---
io_uring/rw.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 432820f86251..0c3585f8d5f0 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -34,21 +34,6 @@ struct io_rw {
rwf_t flags;
};
-static bool io_file_supports_nowait(struct io_kiocb *req, __poll_t mask)
-{
- /* If FMODE_NOWAIT is set for a file, we're golden */
- if (req->flags & REQ_F_SUPPORT_NOWAIT)
- return true;
- /* No FMODE_NOWAIT, if we can poll, check the status */
- if (io_file_can_poll(req)) {
- struct poll_table_struct pt = { ._key = mask };
-
- return vfs_poll(req->file, &pt) & mask;
- }
- /* No FMODE_NOWAIT support, and file isn't pollable. Tough luck. */
- return false;
-}
-
static int io_iov_buffer_select_prep(struct io_kiocb *req)
{
struct iovec __user *uiov;
@@ -859,6 +844,10 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
if (!(req->flags & REQ_F_FIXED_FILE))
req->flags |= io_file_get_flags(file);
+ /* Poll readiness cannot guarantee that a read or write will not block. */
+ if (!(req->flags & REQ_F_SUPPORT_NOWAIT))
+ req->flags |= REQ_F_FORCE_ASYNC;
+
kiocb->ki_flags = file->f_iocb_flags;
ret = kiocb_set_rw_flags(kiocb, rw->flags, rw_type);
if (unlikely(ret))
@@ -936,7 +925,7 @@ static int __io_read(struct io_kiocb *req, struct io_br_sel *sel,
if (force_nonblock) {
/* If the file doesn't support async, just async punt */
- if (unlikely(!io_file_supports_nowait(req, EPOLLIN)))
+ if (unlikely(!(req->flags & REQ_F_SUPPORT_NOWAIT)))
return -EAGAIN;
kiocb->ki_flags |= IOCB_NOWAIT;
} else {
@@ -1055,6 +1044,8 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
/* make it sync, multishot doesn't support async execution */
rw->kiocb.ki_complete = NULL;
ret = __io_read(req, &sel, issue_flags);
+ if (!(req->flags & REQ_F_SUPPORT_NOWAIT))
+ req->flags &= ~REQ_F_APOLL_MULTISHOT;
/*
* If we get -EAGAIN, recycle our buffer and just let normal poll
@@ -1149,7 +1140,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)
if (force_nonblock) {
/* If the file doesn't support async, just async punt */
- if (unlikely(!io_file_supports_nowait(req, EPOLLOUT)))
+ if (unlikely(!(req->flags & REQ_F_SUPPORT_NOWAIT)))
goto ret_eagain;
/* Check if we can support NOWAIT. */
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-19 12:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-19 11:59 [PATCH] io_uring/rw: do not infer NOWAIT support from poll readiness Tianyi Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox