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 3/3] io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP
Date: Sun, 29 Nov 2026 18:34:03 +0000 [thread overview]
Message-ID: <20261129183214.3303492-4-arsenova@a7snv.com> (raw)
In-Reply-To: <20261129183214.3303492-1-arsenova@a7snv.com>
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
prev parent reply other threads:[~2026-11-29 18:34 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 ` [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 [this message]
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-4-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®