Skip to content

Commit 355afae

Browse files
committed
io_uring: no read/write-retry on -EAGAIN error and O_NONBLOCK marked file
Actually two things that need fixing up here: - The io_rw_reissue() -EAGAIN retry is explicit to block devices and regular files, so don't ever attempt to do that on other types of files. - If we hit -EAGAIN on a nonblock marked file, don't arm poll handler for it. It should just complete with -EAGAIN. Cc: stable@vger.kernel.org Reported-by: Norman Maurer <norman.maurer@googlemail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 95d1c8e commit 355afae

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/io_uring.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,8 +2300,11 @@ static bool io_resubmit_prep(struct io_kiocb *req, int error)
23002300
static bool io_rw_reissue(struct io_kiocb *req, long res)
23012301
{
23022302
#ifdef CONFIG_BLOCK
2303+
umode_t mode = file_inode(req->file)->i_mode;
23032304
int ret;
23042305

2306+
if (!S_ISBLK(mode) && !S_ISREG(mode))
2307+
return false;
23052308
if ((res != -EAGAIN && res != -EOPNOTSUPP) || io_wq_current_is_worker())
23062309
return false;
23072310

@@ -3146,6 +3149,9 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
31463149
/* IOPOLL retry should happen for io-wq threads */
31473150
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
31483151
goto done;
3152+
/* no retry on NONBLOCK marked file */
3153+
if (req->file->f_flags & O_NONBLOCK)
3154+
goto done;
31493155
/* some cases will consume bytes even on error returns */
31503156
iov_iter_revert(iter, iov_count - iov_iter_count(iter));
31513157
ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false);
@@ -3287,10 +3293,14 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
32873293
*/
32883294
if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
32893295
ret2 = -EAGAIN;
3296+
/* no retry on NONBLOCK marked file */
3297+
if (ret2 == -EAGAIN && (req->file->f_flags & O_NONBLOCK))
3298+
goto done;
32903299
if (!force_nonblock || ret2 != -EAGAIN) {
32913300
/* IOPOLL retry should happen for io-wq threads */
32923301
if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN)
32933302
goto copy_iov;
3303+
done:
32943304
kiocb_done(kiocb, ret2, cs);
32953305
} else {
32963306
copy_iov:

0 commit comments

Comments
 (0)