io_uring/rw: do not infer NOWAIT support from poll readiness
PATCH 1/1 io_uring/rw: do not infer NOWAIT support from poll readiness
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")
Assisted-by LLM
Signed-off-by Tianyi Chen <[email protected]>
--- io_uring/rw.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
io_uring/rw.c +8 -17
@@ -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. */
Signature · 1 line
2.55.0