* [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue
@ 2026-11-29 18:32 Yun Wang
2026-11-29 18:33 ` [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking Yun Wang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yun Wang @ 2026-11-29 18:32 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, Hao Xu, Mengmeng Zhao, io-uring, linux-kernel
A read or write that completes with -EAGAIN or -EOPNOTSUPP from a
nonblocking attempt is reissued from io-wq. This series fixes two cases
where that reissue has no bound, and stops the retry for dma-buf
requests, where it can never succeed.
I found this while testing the ext4 dma-buf series [1] for bugs. A
direct read into a dma-buf registered buffer that covers [mapped | hole]
of a sparse file fails with -EOPNOTSUPP at the hole every time. The
completion runs outside io-wq, so io_rw_should_reissue() lets the
request be reissued again and again, and the CQE is never posted. An
8 KiB read of 4 KiB of data followed by a hole took 348 device reads
instead of 2 before it returned. A read of 2 MiB of data followed by a
hole had not returned after 5 seconds and had read 15.6 GiB (15932 MiB)
from the device by then. Only exiting the ring stops it.
The loop is not specific to dma-buf or ext4. It happens whenever the
completion of a blocking attempt keeps returning -EAGAIN or -EOPNOTSUPP
and does not run in the io-wq worker that issued it. On v7.4-rc2 it can
be reproduced on a raw NVMe namespace with fault injection (see patch
1), or with a FUSE server that uses FUSE_ASYNC_DIO and FOPEN_DIRECT_IO.
The loop exists since v6.14. Before that, these completions were not
reissued at all.
Patch 1 makes io_rw_should_reissue() look at IOCB_NOWAIT in the kiocb
instead of at the current thread. A request is still reissued once after
a nonblocking attempt, so the nvme multipath case from commit
b08e02045002 and the LVM snapshot case from commit 927069c4ac2c keep
working.
Patch 2 clears REQ_F_FORCE_ASYNC on reissue. Without it, an IOSQE_ASYNC
request on a pollable file (FUSE) is issued nonblocking again from
io-wq, and patch 1 alone does not stop the loop.
Patch 3 stops converting -EOPNOTSUPP to -EAGAIN, and stops reissuing,
for REQ_F_DMABUF requests. dma-buf I/O has no buffered fallback, so the
blocking retry fails the same way. This costs a second device read, and
with RWF_NOWAIT the application is told to retry something that cannot
succeed. Unlike patches 1 and 2, this is only a cost and not a loop, so
it is not marked for stable.
Patches 1 and 2 are needed together to fix the loop for every case.
Patch 3 is independent of them.
Testing, all on v7.4-rc2 unless noted:
- NVMe fault injection in QEMU, raw device and ext4: without the series
a single 4 KiB read uses up every injected failure and then succeeds.
With it, the read fails with -EOPNOTSUPP after two attempts, or one
with IOSQE_ASYNC. The patched kernel gives the same result on a
KIOXIA BG5.
- FUSE reproducer, default and IOSQE_ASYNC, with -EAGAIN and
-EOPNOTSUPP: without the series the request is reissued until the
reproducer's server gives up after 20 failures (21 READs). With it,
the server sees 2 READs. Also run with KASAN and lockdep: no reports.
- dma-buf on a raw NVMe namespace (patch 3): see the patch. A buffered
write from user memory to the same device is still retried and
succeeds.
- With the ext4 dma-buf series: the sparse-file read above returns after
two device reads with patches 1 and 2, and after one with patch 3.
The series is based on v7.4-rc2 and also applies to io_uring-7.4.
Patches 2 and 3 conflict with the io_req_{set,clear}_flags() conversion
in for-7.5/io_uring. I can rebase them onto it if you prefer.
On tool use: Gemini (gemini-4-neon-high) found the IOSQE_ASYNC path that
my first version of patch 1 missed, which patch 2 fixes. The patches,
the changelogs and this cover letter were written with AI assistance
(Claude, claude-opus-5-5). Claude was also used to build the tests that
do not depend on the ext4 series (NVMe fault injection, FUSE, dma-buf on
a raw NVMe namespace), to check that the problem is not caused by that
series. I reviewed the patches and the test results.
[1] https://lore.kernel.org/all/20261113070621.273953-1-mengmeng.zhao@linux.dev/
Yun Wang (3):
io_uring/rw: don't reissue requests that were issued blocking
io_uring: clear REQ_F_FORCE_ASYNC when reissuing a request
io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP
io_uring/io_uring.c | 2 +-
io_uring/rw.c | 16 +++++++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking
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
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
2 siblings, 0 replies; 4+ messages in thread
From: Yun Wang @ 2026-11-29 18:33 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, Hao Xu, Mengmeng Zhao, io-uring, linux-kernel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] io_uring: clear REQ_F_FORCE_ASYNC when reissuing a request
2026-11-29 18:32 [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue Yun Wang
2026-11-29 18:33 ` [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking Yun Wang
@ 2026-11-29 18:33 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: Yun Wang @ 2026-11-29 18:33 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, Hao Xu, Mengmeng Zhao, io-uring, linux-kernel
When a read or write is reissued, io_free_batch_list() clears
REQ_F_REISSUE and queues the request to io-wq, but leaves
REQ_F_FORCE_ASYNC set. For a request submitted with IOSQE_ASYNC on a
file that implements ->poll(), io_wq_submit_work() then issues it with
IO_URING_F_NONBLOCK again, so the retry that should be blocking is
another nonblocking attempt with IOCB_NOWAIT set. io_rw_should_reissue()
allows a reissue after a nonblocking attempt, so such a request is
still reissued forever when its completion keeps returning -EAGAIN or
-EOPNOTSUPP.
REQ_F_REISSUE means the nonblocking attempt has been made and the
request should now be issued from blocking context. Clear
REQ_F_FORCE_ASYNC together with it, so that io-wq issues the retry
blocking. The request is already being queued to io-wq at this point;
the only other effect is that the retry no longer sets
IO_WQ_WORK_CONCURRENT.
FUSE regular files implement ->poll(). With a FUSE server that has
FUSE_ASYNC_DIO and FOPEN_DIRECT_IO and answers every READ with
-EOPNOTSUPP or -EAGAIN, an IORING_OP_READ with IOSQE_ASYNC is still
reissued until the server stops failing with the previous patch alone.
With both patches it fails after two attempts.
Fixes: d803d123948f ("io_uring/rw: handle -EAGAIN retry at IO completion time")
Cc: stable@vger.kernel.org
Signed-off-by: Yun Wang <arsenova@a7snv.com>
---
io_uring/io_uring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 5db57bf675f0..c08714d10d5b 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1187,7 +1187,7 @@ static void io_free_batch_list(struct io_ring_ctx *ctx,
if (unlikely(req->flags & IO_REQ_CLEAN_SLOW_FLAGS)) {
if (req->flags & REQ_F_REISSUE) {
node = req->comp_list.next;
- req->flags &= ~REQ_F_REISSUE;
+ req->flags &= ~(REQ_F_REISSUE | REQ_F_FORCE_ASYNC);
io_queue_iowq(req);
continue;
}
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP
2026-11-29 18:32 [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue Yun Wang
2026-11-29 18:33 ` [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking Yun Wang
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 ` Yun Wang
2 siblings, 0 replies; 4+ messages in thread
From: Yun Wang @ 2026-11-29 18:34 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, Hao Xu, Mengmeng Zhao, io-uring, linux-kernel
io_uring treats -EOPNOTSUPP from a nonblocking read or write like
-EAGAIN and retries the request from io-wq, both when ->read_iter() or
->write_iter() returns it and when it is passed to ->ki_complete(),
because some filesystems and block devices return -EOPNOTSUPP for
IOCB_NOWAIT requests that they can serve when allowed to block.
That retry cannot succeed for a request that uses a dma-buf registered
buffer. dma-buf I/O has no buffered fallback, so wherever the I/O path
gives up with -EOPNOTSUPP, it gives up again from blocking context,
even where the first -EOPNOTSUPP was caused by IOCB_NOWAIT.
For example, register a dma-buf against a raw NVMe namespace opened
with O_DIRECT, then clear O_DIRECT with F_SETFL. blkdev_read_iter()
refuses the buffered read of a dma-buf iterator with -EOPNOTSUPP. A
write fails in blkdev_write_iter() because IOCB_NOWAIT is set without
IOCB_DIRECT, and then fails again in blkdev_buffered_write() because of
the dma-buf iterator. With the ext4 dma-buf support under review, a
direct read that reaches a hole inside the file fails the same way, and
so does a write to a file with data journalling, which ext4 turns into
a buffered write.
The retry costs a second issue. For a read that covers mapped blocks
before the hole, those blocks are read from the device a second time.
With RWF_NOWAIT, the -EOPNOTSUPP is turned into -EAGAIN and returned to
userspace, which asks the application to retry something that cannot
succeed.
Leave -EOPNOTSUPP alone for REQ_F_DMABUF requests. The flag is still set
after io_detach_dmabuf_map(), so io_complete_rw() can check it.
The one IOCB_NOWAIT-specific -EOPNOTSUPP that a blocking retry can fix
comes from submit_bio_noacct() for a device without NOWAIT support.
dma-buf I/O does not reach it today: only NVMe implements
->init_dma_buf_io_ctx, and NVMe namespaces and multipath devices
support NOWAIT. This needs another look if stacking drivers gain
dma-buf support.
Tested on v7.4-rc2 with QEMU NVMe and udmabuf buffers, using the raw
device case above: with RWF_NOWAIT, reads and writes now fail with
-EOPNOTSUPP instead of -EAGAIN, and the write is no longer queued to
io-wq a second time. A buffered write from user memory to the same
device, the case the -EOPNOTSUPP retry exists for, is still retried
from io-wq and succeeds. Also tested with the ext4 dma-buf series, on
QEMU NVMe and on a KIOXIA BG5: a hole read with RWF_NOWAIT gets
-EOPNOTSUPP, and a read of [mapped | hole] issues one device read
instead of two.
Fixes: 62e4bf5b25d4 ("io_uring/rsrc: add dmabuf backed registered buffers")
Signed-off-by: Yun Wang <arsenova@a7snv.com>
---
io_uring/rw.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 7917d1536c47..0ab7cf3d503a 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -545,7 +545,9 @@ static void __io_complete_rw_common(struct io_kiocb *req, long res)
{
if (res == req->cqe.res)
return;
- if ((res == -EOPNOTSUPP || res == -EAGAIN) && io_rw_should_reissue(req)) {
+ if ((res == -EAGAIN ||
+ (res == -EOPNOTSUPP && !(req->flags & REQ_F_DMABUF))) &&
+ io_rw_should_reissue(req)) {
req->flags |= REQ_F_REISSUE | REQ_F_BL_NO_RECYCLE;
} else {
req_set_fail(req);
@@ -944,7 +946,8 @@ static int __io_read(struct io_kiocb *req, struct io_br_sel *sel,
* issue, even though they should be returning -EAGAIN. To be safe,
* retry from blocking context for either.
*/
- if (ret == -EOPNOTSUPP && force_nonblock)
+ if (ret == -EOPNOTSUPP && force_nonblock &&
+ !(req->flags & REQ_F_DMABUF))
ret = -EAGAIN;
if (ret == -EAGAIN) {
@@ -1172,7 +1175,8 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)
* Raw bdev writes will return -EOPNOTSUPP for IOCB_NOWAIT. Just
* retry them without IOCB_NOWAIT.
*/
- if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
+ if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT) &&
+ !(req->flags & REQ_F_DMABUF))
ret2 = -EAGAIN;
/* no retry on NONBLOCK nor RWF_NOWAIT */
if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT))
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-29 18:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 18:32 [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue Yun Wang
2026-11-29 18:33 ` [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking Yun Wang
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
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®