Direct I/O copies data from the CPU in four places, namely zero-filling holes, inline data, bounce pages and integrity metadata. A dma-buf iterator has no pages, so refuse it there.
A read that hits a hole or unwritten extent before i_size fails with -EOPNOTSUPP, even if I/O for an earlier extent was already submitted. Holes at or beyond i_size are skipped, as reads are truncated to i_size on completion. Signed-off-by: Mengmeng Zhao <[email protected]> Signed-off-by: Li Wang <[email protected]> Co-developed-by: Yun Wang <[email protected]> Signed-off-by: Yun Wang <[email protected]> Signed-off-by: Anuj Gupta <[email protected]> Signed-off-by: Nitesh Shetty <[email protected]> --- fs/iomap/direct-io.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f00b0841fdd0..1cd907204501 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,25 @@ 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 +642,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 +744,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.47.3
