From: Mengmeng Zhao <mengmeng.zhao@linux.dev>
To: arsenova@a7snv.com
Cc: adilger.kernel@dilger.ca, anuj1072538@gmail.com,
anuj20.g@samsung.com, asml.silence@gmail.com, axboe@kernel.dk,
brauner@kernel.org, christian.koenig@amd.com, corbet@lwn.net,
djbw@kernel.org, dri-devel@lists.freedesktop.org, hch@lst.de,
jack@suse.cz, libaokun@linux.alibaba.com,
linaro-mm-sig@lists.linaro.org, linux-block@vger.kernel.org,
linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-xfs@vger.kernel.org,
liwang@kylinos.cn, mcgrof@kernel.org, mengmeng.zhao@linux.dev,
nj.shetty@samsung.com, nvdimm@lists.linux.dev,
ojaswin@linux.ibm.com, phasta@kernel.org, rdunlap@infradead.org,
ritesh.list@gmail.com, skhan@linuxfoundation.org,
sumit.semwal@linaro.org, tytso@mit.edu, viro@zeniv.linux.org.uk,
willy@infradead.org, yi.zhang@huawei.com,
zhaomengmeng@kylinos.cn
Subject: [RFC PATCH v3 2/8] iomap: add dma-buf direct I/O guards
Date: Thu, 26 Nov 2026 18:07:21 +0800 [thread overview]
Message-ID: <20261126100721.313677-1-mengmeng.zhao@linux.dev> (raw)
In-Reply-To: <20261125171600.4053585-1-arsenova@a7snv.com>
From: Nitesh Shetty <nj.shetty@samsung.com>
Direct I/O copies data from the CPU in four places, zero-filling
holes, inline data, bounce pages and integrity metadata. A dma-buf
iterator has no pages behind it, so refuse it there.
Reads that encounter a hole or unwritten extent before i_size
therefore return -EOPNOTSUPP for the entire operation, even if I/O
for an earlier mapped extent was already submitted.
Holes that start at or beyond i_size are stepped over since reads
are truncated to i_size before completion.
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Co-developed-by: Yun Wang <arsenova@a7snv.com>
Signed-off-by: Yun Wang <arsenova@a7snv.com>
Reviewed-by: Li Wang <liwang@kylinos.cn>
[Mengmeng Zhao: remove the registration helper and fold in
Yun Wang's past-EOF step-over fix]
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
---
fs/iomap/direct-io.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index ad041ac3252a..de07a4efcbf7 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -425,6 +425,11 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
unsigned int alignment;
ssize_t ret = 0;
+ /* integrity metadata is generated from the data pages */
+ if (iov_iter_is_dmabuf_map(dio->submit.iter) &&
+ (iomap->flags & IOMAP_F_INTEGRITY))
+ return -EOPNOTSUPP;
+
/*
* File systems that write out of place and always allocate new blocks
* need each bio to be block aligned as that's the unit of allocation.
@@ -589,7 +594,24 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
static int iomap_dio_hole_iter(struct iomap_iter *iter, struct iomap_dio *dio)
{
- loff_t copied = iov_iter_zero(iomap_length(iter), dio->submit.iter);
+ loff_t copied;
+
+ if (iov_iter_is_dmabuf_map(dio->submit.iter)) {
+ u64 length = iomap_length(iter);
+
+ /* zero-filling walks the data pages */
+ if (iter->pos < dio->i_size)
+ return -EOPNOTSUPP;
+ /*
+ * Past EOF there is nothing to zero: the read is truncated to
+ * i_size before it is reported, so step over the hole.
+ */
+ iov_iter_advance(dio->submit.iter, length);
+ dio->size += length;
+ return iomap_iter_advance(iter, length);
+ }
+
+ copied = iov_iter_zero(iomap_length(iter), dio->submit.iter);
if (dio->flags & IOMAP_DIO_FSBLOCK_ALIGNED) {
loff_t aligned_copied = round_down(copied,
@@ -619,6 +641,10 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio)
loff_t pos = iomi->pos;
u64 copied;
+ /* inline data is copied from the CPU */
+ if (iov_iter_is_dmabuf_map(iter))
+ return -EOPNOTSUPP;
+
if (WARN_ON_ONCE(!inline_data))
return -EIO;
@@ -717,6 +743,10 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
if (!iomi.len)
return NULL;
+ /* bouncing copies the data from the CPU */
+ if (iov_iter_is_dmabuf_map(iter) && (dio_flags & IOMAP_DIO_BOUNCE))
+ return ERR_PTR(-EOPNOTSUPP);
+
dio = kmalloc_obj(*dio);
if (!dio)
return ERR_PTR(-ENOMEM);
--
2.43.0
next prev parent reply other threads:[~2026-11-26 10:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:16 [RFC PATCH v2 2/8] iomap: add dma-buf direct I/O guards Yun Wang
2026-11-26 10:07 ` Mengmeng Zhao [this message]
2026-11-26 10:23 ` Mengmeng Zhao
2026-11-26 11:20 ` arsenova
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=20261126100721.313677-1-mengmeng.zhao@linux.dev \
--to=mengmeng.zhao@linux.dev \
--cc=adilger.kernel@dilger.ca \
--cc=anuj1072538@gmail.com \
--cc=anuj20.g@samsung.com \
--cc=arsenova@a7snv.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=mcgrof@kernel.org \
--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.