Re: [PATCH] iov_iter: Fix direct I/O across compatible device pgmaps
From: Naman Jain
Date: Thu Nov 26 2026 - 23:05:53 EST
On 11/26/2026 6:42 PM, David Hildenbrand (Arm) wrote:
On 11/26/26 06:34, 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 direct I/O now fills a bio using iov_iter_extract_bvecs(), which
retained the original restriction and bypasses bio_add_page().
For a non-atomic request handled by a single bio, only the data before
the pgmap boundary is submitted. The rest is not transferred, and the
request completes with 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(). This allows
compatible pages to be added as separate bvecs without relaxing the
same-pgmap requirement for PCI P2PDMA.
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>
---
block/blk.h | 19 -------------------
include/linux/memremap.h | 19 +++++++++++++++++++
lib/iov_iter.c | 3 ++-
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 50abfd9328861..460c064f1d1b0 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -142,25 +142,6 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,
return true;
}
-/*
- * Check if two pages from potentially different zone device pgmaps can
- * coexist as separate bvec entries in the same bio.
- *
- * The block DMA iterator (blk_dma_map_iter_start) caches the P2PDMA mapping
- * state from the first segment and applies it to all subsequent segments, so
- * P2PDMA pages from different pgmaps must not be mixed in the same bio.
- *
- * Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys() path
- * as normal RAM. PRIVATE and COHERENT pages never appear in bios.
- */
-static inline bool zone_device_pages_compatible(const struct page *a,
- const struct page *b)
-{
- if (is_pci_p2pdma_page(a) || is_pci_p2pdma_page(b))
- return zone_device_pages_have_same_pgmap(a, b);
- return true;
-}
-
static inline bool __bvec_gap_to_prev(const struct queue_limits *lim,
struct bio_vec *bprv, unsigned int offset)
{
diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index c8a4979d4c780..a1d447a847990 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -202,6 +202,25 @@ static inline bool is_pci_p2pdma_page(const struct page *page)
folio_is_pci_p2pdma(page_folio(page));
}
+/*
+ * Check if two pages from potentially different zone device pgmaps can
+ * coexist as separate bvec entries in the same bio.
+ *
+ * The block DMA iterator (blk_dma_map_iter_start) caches the P2PDMA mapping
+ * state from the first segment and applies it to all subsequent segments, so
+ * P2PDMA pages from different pgmaps must not be mixed in the same bio.
+ *
+ * Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys() path
+ * as normal RAM. PRIVATE and COHERENT pages never appear in bios.
+ */
Can you convert this to proper kernel doc while at it?
Also this should all be working on folios instead of pages. But that will need a
zone_device_folios_have_same_pgmap() so we can defer it, not suitable for this fix.
IIUC, you want me to change this comment to kernel doc, something like this.
/**
* zone_device_pages_compatible() - Check if pages can share a bio
* @a: First page
* @b: Second page
*
* Check if two pages from potentially different zone device pgmaps can
* coexist as separate bvec entries in the same bio.
*
* The block DMA iterator (blk_dma_map_iter_start()) caches the P2PDMA
* mapping state from the first segment and applies it to all subsequent
* segments, so P2PDMA pages from different pgmaps must not be mixed in
* the same bio.
*
* Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys()
* path as normal RAM. PRIVATE and COHERENT pages never appear in bios.
*
* Return: %true if the pages can coexist as separate bvec entries in the
* same bio, otherwise %false.
*/
I can do that in next version. Thanks.
Regards,
Naman