From: Mengmeng Zhao <mengmeng.zhao@linux.dev>
To: Christoph Hellwig <hch@lst.de>,
Anuj Gupta <anuj1072538@gmail.com>,
Nitesh Shetty <nj.shetty@samsung.com>,
Jens Axboe <axboe@kernel.dk>,
Sumit Semwal <sumit.semwal@linaro.org>,
christian.koenig@amd.com, Philipp Stanner <phasta@kernel.org>,
Dan Williams <djbw@kernel.org>,
Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
tytso@mit.edu, Andreas Dilger <adilger.kernel@dilger.ca>,
Baokun Li <libaokun@linux.alibaba.com>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>,
asml.silence@gmail.com, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, nvdimm@lists.linux.dev,
linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-doc@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
Li Wang <liwang@kylinos.cn>,
Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Subject: [RFC PATCH v2 3/8] iomap: don't ask for a buffered fallback for dma-buf iterators
Date: Fri, 13 Nov 2026 15:06:16 +0800 [thread overview]
Message-ID: <20261113070621.273953-4-mengmeng.zhao@linux.dev> (raw)
In-Reply-To: <20261113070621.273953-1-mengmeng.zhao@linux.dev>
From: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
-ENOTBLK tells the caller to retry with buffered I/O. A dma-buf iterator
has no pages to copy, so the callers refuse that fallback, which would
turn the error into a successful transfer of zero bytes.
Report the reason instead: a busy folio becomes -EAGAIN, which the caller
can retry, any other invalidation failure keeps its error code, and
-ENOTBLK from ->iomap_begin() becomes -EOPNOTSUPP when nothing was
transferred. A partial direct I/O still reports its progress. Both
branches are reachable only through a file that opted into dma-buf I/O,
which ext4 does in the last patch.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
---
.../filesystems/iomap/operations.rst | 3 +++
fs/iomap/direct-io.c | 20 +++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst
index da982ca7e413..ca59716d225c 100644
--- a/Documentation/filesystems/iomap/operations.rst
+++ b/Documentation/filesystems/iomap/operations.rst
@@ -513,6 +513,9 @@ Return Values
cache before issuing the I/O to storage.
The ``->iomap_begin`` or ``->iomap_end`` functions may also return
this value.
+ A dma-buf iterator cannot fall back to buffered I/O, so it gets
+ ``-EAGAIN`` when the failure is retryable and ``-EOPNOTSUPP`` when no
+ data could be transferred.
* ``-EIOCBQUEUED``: The asynchronous direct I/O request has been
queued and will be completed separately.
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 4a2b0f9df5a7..83fda6973bb9 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -706,7 +706,9 @@ static int iomap_dio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
* completing partial requests asynchronously.
*
* Returns -ENOTBLK In case of a page invalidation invalidation failure for
- * writes. The callers needs to fall back to buffered I/O in this case.
+ * writes. The callers needs to fall back to buffered I/O in this case. A
+ * dma-buf iterator cannot use that fallback, so it gets -EAGAIN when the
+ * failure is retryable and -EOPNOTSUPP when nothing was transferred.
*/
struct iomap_dio *
__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
@@ -806,7 +808,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
/*
* Try to invalidate cache pages for the range we are writing.
* If this invalidation fails, let the caller fall back to
- * buffered I/O.
+ * buffered I/O unless the iterator cannot be handled there.
*/
ret = kiocb_invalidate_pages(iocb, iomi.len);
if (ret) {
@@ -820,6 +822,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
* the caller tries again.
*/
ret = -EAGAIN;
+ } else if (iov_iter_is_dmabuf_map(iter)) {
+ /*
+ * A dma-buf iterator has no buffered
+ * fallback, so -ENOTBLK would hide the
+ * real failure. A busy folio is retryable.
+ */
+ if (ret == -EBUSY)
+ ret = -EAGAIN;
} else {
/* fall back to buffered write */
ret = -ENOTBLK;
@@ -867,6 +877,12 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
if (ret == -ENOTBLK) {
wait_for_completion = true;
ret = 0;
+ /*
+ * A dma-buf iterator cannot use that fallback. Anything
+ * already transferred is still reported as a short I/O.
+ */
+ if (!dio->size && iov_iter_is_dmabuf_map(iter))
+ ret = -EOPNOTSUPP;
}
if (ret < 0)
iomap_dio_set_error(dio, ret);
--
2.43.0
next prev parent reply other threads:[~2026-11-13 7:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 7:06 [RFC PATCH v2 0/8] ext4: Add dma-buf read/write support Mengmeng Zhao
2026-11-13 7:06 ` [RFC PATCH v2 1/8] block: factor out bdev_init_dma_buf_io_ctx() Mengmeng Zhao
2026-11-13 7:24 ` sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 2/8] iomap: add dma-buf direct I/O guards Mengmeng Zhao
2026-11-13 7:31 ` sashiko-bot
2026-11-13 7:06 ` Mengmeng Zhao [this message]
2026-11-13 7:28 ` [RFC PATCH v2 3/8] iomap: don't ask for a buffered fallback for dma-buf iterators sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 4/8] blk-mq: factor out a dma-buf bio refusal helper Mengmeng Zhao
2026-11-13 7:12 ` sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 5/8] blk-crypto: refuse dma-buf bios in the fallback path Mengmeng Zhao
2026-11-13 7:24 ` sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 6/8] fs: add FMODE_CAN_DMABUF_IO and require it for dma-buf I/O contexts Mengmeng Zhao
2026-11-13 7:24 ` sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 7/8] dax: refuse dma-buf iterators in dax_iomap_rw() Mengmeng Zhao
2026-11-13 7:25 ` sashiko-bot
2026-11-13 7:06 ` [RFC PATCH v2 8/8] ext4: support dma-buf registered buffers for direct I/O Mengmeng Zhao
2026-11-13 7:26 ` sashiko-bot
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=20261113070621.273953-4-mengmeng.zhao@linux.dev \
--to=mengmeng.zhao@linux.dev \
--cc=adilger.kernel@dilger.ca \
--cc=anuj1072538@gmail.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=christian.koenig@amd.com \
--cc=corbet@lwn.net \
--cc=djbw@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=liwang@kylinos.cn \
--cc=nj.shetty@samsung.com \
--cc=nvdimm@lists.linux.dev \
--cc=ojaswin@linux.ibm.com \
--cc=phasta@kernel.org \
--cc=rdunlap@infradead.org \
--cc=ritesh.list@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=sumit.semwal@linaro.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=yi.zhang@huawei.com \
--cc=zhaomengmeng@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.