[RFC 4/6] iomap: refuse dmabuf iterators in iomap_file_buffered_write()

From: Mengmeng Zhao

Date: Thu Nov 05 2026 - 02:04:59 EST


From: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>

A buffered write copies through the CPU linear address, which a
device mapping cannot provide. fault_in_iov_iter_readable() treats
a dmabuf iterator as always readable, so the copy fails with a
WARN_ON_ONCE from iterate_and_advance2() and iomap_write_iter()
retries the unchanged remainder forever.

Refuse the iterator at the entry with -EOPNOTSUPP, as
generic_perform_write() and the generic read paths already do, so
that every generic buffered copy helper turns the iterator away
before touching the page cache.

Signed-off-by: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>
Signed-off-by: Li Wang <liwang@xxxxxxxxxx>
---
fs/iomap/buffered-io.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 0a5ebfda90f1..3f56bd225e8c 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1304,6 +1304,13 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
};
ssize_t ret;

+ /*
+ * A buffered write copies through the CPU linear address, which a
+ * device mapping cannot provide.
+ */
+ if (iov_iter_is_dmabuf_map(i))
+ return -EOPNOTSUPP;
+
if (iocb->ki_flags & IOCB_NOWAIT)
iter.flags |= IOMAP_NOWAIT;
if (iocb->ki_flags & IOCB_DONTCACHE)
--
2.43.0