mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yun Wang <arsenova@a7snv.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	Hao Xu <haoxu@linux.alibaba.com>,
	Mengmeng Zhao <mengmeng.zhao@linux.dev>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking
Date: Sun, 29 Nov 2026 18:33:14 +0000	[thread overview]
Message-ID: <20261129183214.3303492-2-arsenova@a7snv.com> (raw)
In-Reply-To: <20261129183214.3303492-1-arsenova@a7snv.com>

io_rw_should_reissue() decides whether a read or write that completed
with -EAGAIN or -EOPNOTSUPP is retried from io-wq. It uses
io_wq_current_is_worker() to tell whether the request has already been
issued from blocking context. That only works when ->ki_complete() runs
in the io-wq worker that issued the request. When the completion runs
anywhere else, for example in the block layer completion path, in the
iomap s_dio_done_wq worker, or in a FUSE server thread answering an
async direct I/O request, the check is false and the request is
reissued even though the previous attempt was already a blocking one.
If the lower layer keeps returning the same error, the request is
reissued forever and its CQE is never posted.

Before v6.14 such completions were not reissued:
io_rw_should_reissue() returned false outside the submitting thread
group and outside task context, and a reissue flagged from an async
completion was not acted upon. The two commits in the Fixes tags made
these completions reissue from io-wq, which is what the nvme multipath
retry from a kworker needs.

The kiocb already records how the request was issued: __io_read() and
io_write() set IOCB_NOWAIT for a nonblocking attempt and clear it for a
blocking one. Use that instead. A request that was issued nonblocking
can still be reissued once from io-wq, so the nvme multipath case keeps
working, and so does the LVM snapshot case, where REQ_NOWAIT bios fail
with -EOPNOTSUPP while the snapshot is being created. That retry was
restored by
commit 927069c4ac2c ("Revert "io_uring/rw: drop -EOPNOTSUPP check in __io_complete_rw_common()"").
IOPOLL requests keep their current behaviour.

This can be reproduced with NVMe fault injection. NVME_SC_INVALID_OPCODE
with DNR set is mapped to BLK_STS_NOTSUPP:

  cd /sys/kernel/debug/nvme0n1/fault_inject
  echo 0x02 > opcode; echo 0x01 > status; echo 1 > dont_retry
  echo 20 > times; echo 100 > probability
  fio --name=r --ioengine=io_uring --direct=1 --rw=read --bs=4k \
      --size=4k --filename=/dev/nvme0n1

Without this patch the single 4 KiB read uses up all 20 injected
failures, then completes successfully, and fio reports no error; the
loop is only bounded by the injection count. With this patch the read
fails with -EOPNOTSUPP after two attempts, one nonblocking and one
blocking. The same holds for an ext4 file on that device. Both kernels
were tested in QEMU. The patched kernel was also tested on a KIOXIA BG5,
with the same result. A FUSE server with FUSE_ASYNC_DIO and
FOPEN_DIRECT_IO that answers READ with -EAGAIN or -EOPNOTSUPP shows the
same loop for IORING_OP_READ.

Fixes: d803d123948f ("io_uring/rw: handle -EAGAIN retry at IO completion time")
Fixes: b08e02045002 ("io_uring/rw: don't gate retry on completion context")
Cc: stable@vger.kernel.org
Signed-off-by: Yun Wang <arsenova@a7snv.com>
---
 io_uring/rw.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3a8559ff4dc6..7917d1536c47 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -490,8 +490,10 @@ static bool io_rw_should_reissue(struct io_kiocb *req)
 
 	if (!S_ISBLK(mode) && !S_ISREG(mode))
 		return false;
-	if ((req->flags & REQ_F_NOWAIT) || (io_wq_current_is_worker() &&
-	    !(req->flags & REQ_F_IOPOLL)))
+	if ((req->flags & REQ_F_NOWAIT) ||
+	    (!(req->flags & REQ_F_IOPOLL) &&
+	     (io_wq_current_is_worker() ||
+	      !(rw->kiocb.ki_flags & IOCB_NOWAIT))))
 		return false;
 	/*
 	 * If ref is dying, we might be running poll reap from the exit work.
-- 
2.56.1



  reply	other threads:[~2026-11-29 18:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 18:32 [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue Yun Wang
2026-11-29 18:33 ` Yun Wang [this message]
2026-11-29 18:33 ` [PATCH 2/3] io_uring: clear REQ_F_FORCE_ASYNC when reissuing a request Yun Wang
2026-11-29 18:34 ` [PATCH 3/3] io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP Yun Wang

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=20261129183214.3303492-2-arsenova@a7snv.com \
    --to=arsenova@a7snv.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=haoxu@linux.alibaba.com \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mengmeng.zhao@linux.dev \
    /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

all inboxes | Powered by JetHome®