Commit 355afaeb authored by Jens Axboe's avatar Jens Axboe

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: default avatarNorman Maurer <norman.maurer@googlemail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 95d1c8e5
...@@ -2300,8 +2300,11 @@ static bool io_resubmit_prep(struct io_kiocb *req, int error) ...@@ -2300,8 +2300,11 @@ static bool io_resubmit_prep(struct io_kiocb *req, int error)
static bool io_rw_reissue(struct io_kiocb *req, long res) static bool io_rw_reissue(struct io_kiocb *req, long res)
{ {
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
umode_t mode = file_inode(req->file)->i_mode;
int ret; int ret;
if (!S_ISBLK(mode) && !S_ISREG(mode))
return false;
if ((res != -EAGAIN && res != -EOPNOTSUPP) || io_wq_current_is_worker()) if ((res != -EAGAIN && res != -EOPNOTSUPP) || io_wq_current_is_worker())
return false; return false;
...@@ -3146,6 +3149,9 @@ static int io_read(struct io_kiocb *req, bool force_nonblock, ...@@ -3146,6 +3149,9 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
/* IOPOLL retry should happen for io-wq threads */ /* IOPOLL retry should happen for io-wq threads */
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL)) if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
goto done; goto done;
/* no retry on NONBLOCK marked file */
if (req->file->f_flags & O_NONBLOCK)
goto done;
/* some cases will consume bytes even on error returns */ /* some cases will consume bytes even on error returns */
iov_iter_revert(iter, iov_count - iov_iter_count(iter)); iov_iter_revert(iter, iov_count - iov_iter_count(iter));
ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false); 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, ...@@ -3287,10 +3293,14 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
*/ */
if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT)) if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
ret2 = -EAGAIN; ret2 = -EAGAIN;
/* no retry on NONBLOCK marked file */
if (ret2 == -EAGAIN && (req->file->f_flags & O_NONBLOCK))
goto done;
if (!force_nonblock || ret2 != -EAGAIN) { if (!force_nonblock || ret2 != -EAGAIN) {
/* IOPOLL retry should happen for io-wq threads */ /* IOPOLL retry should happen for io-wq threads */
if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN) if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN)
goto copy_iov; goto copy_iov;
done:
kiocb_done(kiocb, ret2, cs); kiocb_done(kiocb, ret2, cs);
} else { } else {
copy_iov: copy_iov:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment