All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naman Jain <namjain@linux.microsoft.com>
To: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: David Hildenbrand <david@kernel.org>,
	Oscar Salvador <osalvador@suse.de>,
	Logan Gunthorpe <logang@deltatee.com>,
	Leon Romanovsky <leon@kernel.org>,
	Keith Busch <kbusch@kernel.org>,
	linux-block@vger.kernel.org, linux-mm@kvack.org,
	linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org,
	namjain@linux.microsoft.com
Subject: [PATCH] iov_iter: Fix direct I/O across compatible device pgmaps
Date: Thu, 26 Nov 2026 05:34:33 +0000	[thread overview]
Message-ID: <20261126053433.88531-1-namjain@linux.microsoft.com> (raw)

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@vger.kernel.org
Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
---
 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.
+ */
+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 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..a0c76b40a4f90 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_compatible(bv[*nr_vecs - 1].bv_page,
 				pages[i]))
 			break;
 
-- 
2.43.0


             reply	other threads:[~2026-11-26  5:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  5:34 Naman Jain [this message]
2026-11-26 13:12 ` [PATCH] iov_iter: Fix direct I/O across compatible device pgmaps David Hildenbrand (Arm)
2026-11-27  4:05   ` Naman Jain
2026-11-29 10:32     ` David Hildenbrand (Arm)
2026-11-30  4:44       ` Naman Jain
2026-11-30 10:57         ` David Hildenbrand (Arm)
2026-11-30 13:18       ` Christoph Hellwig
2026-11-30 13:27         ` David Hildenbrand (Arm)
2026-12-01  4:50           ` Naman Jain
2026-11-30 13:16   ` Christoph Hellwig
2026-11-30 13:31     ` David Hildenbrand (Arm)

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=20261126053433.88531-1-namjain@linux.microsoft.com \
    --to=namjain@linux.microsoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=david@kernel.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=logang@deltatee.com \
    --cc=osalvador@suse.de \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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.