From: Tianyi Chen <hi@tychen.cc>
To: io-uring@vger.kernel.org
Cc: axboe@kernel.dk
Subject: [PATCH] io_uring/rw: do not infer NOWAIT support from poll readiness
Date: Sat, 19 Sep 2026 19:59:47 +0800 [thread overview]
Message-ID: <20260919115948.1269869-1-hi@tychen.cc> (raw)
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
reply other threads:[~2026-09-19 12:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919115948.1269869-1-hi@tychen.cc \
--to=hi@tychen.cc \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox