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 --- 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