Re: [PATCH v2] iov_iter: Allow DMA-compatible device pages in bvec extraction
From: Christoph Hellwig
Date: Thu Dec 03 2026 - 05:04:13 EST
On Thu, Dec 03, 2026 at 11:02:29AM +0100, David Hildenbrand (Arm) wrote:
> On 12/3/26 09:43, Naman Jain wrote:
> > Commit 38446014648c ("block: don't merge different kinds of P2P transfers
> > in a single bio") made bio_add_page() reject pages from different
> > dev_pagemaps. This was needed for PCI P2PDMA, but also rejected pages
> > with compatible DMA mapping requirements.
> >
> > Commit 41c665aae2b5 ("block: relax pgmap check in bio_add_page for
> > compatible zone device pages") allows these pages in separate bvecs.
> > Commit 13920e4b7b784 ("block: add pgmap check to biovec_phys_mergeable")
> > prevents physically contiguous bvecs from different pgmaps from being
> > merged into one segment.
> >
> > But iov_iter_extract_bvecs() still rejects pages from different pgmaps
> > without checking their DMA compatibility. Direct I/O uses this helper,
> > so a non-atomic request submitted as a single bio transfers only the
> > data before the pgmap boundary and returns fewer bytes than requested.
> >
> > Fix this by moving zone_device_pages_compatible() from blk.h to
> > memremap.h and using it in iov_iter_extract_bvecs(). Rename the helper to
> > zone_device_pages_dma_compatible() to make its purpose clear.
> >
> > Fixes: 38446014648c ("block: don't merge different kinds of P2P transfers in a single bio")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Naman Jain <namjain@xxxxxxxxxxxxxxxxxxx>
> > ---
>
> [...]
>
> > static inline bool folio_is_device_coherent(const struct folio *folio)
> > {
> > return folio_is_zone_device(folio) &&
> > diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> > index 56c59a2b589d3..32b57f5747782 100644
> > --- a/lib/iov_iter.c
> > +++ b/lib/iov_iter.c
> > @@ -4,6 +4,7 @@
> > #include <linux/fault-inject-usercopy.h>
> > #include <linux/uio.h>
> > #include <linux/pagemap.h>
> > +#include <linux/memremap.h>
> > #include <linux/highmem.h>
> > #include <linux/slab.h>
> > #include <linux/vmalloc.h>
> > @@ -1968,7 +1969,7 @@ ssize_t iov_iter_extract_bvecs(struct iov_iter *iter, struct bio_vec *bv,
> > unsigned int nr_to_add;
> >
> > if (*nr_vecs > 0 &&
> > - !zone_device_pages_have_same_pgmap(bv[*nr_vecs - 1].bv_page,
> > + !zone_device_pages_dma_compatible(bv[*nr_vecs - 1].bv_page,
> > pages[i]))
>
> Nit: ^ I'd just fit that into a single line to de-uglify.
No, avoid ureadably long lines. This is excactly as it should be.