Re: [PATCH 2/2] block: allow different-pgmap pages as separate bvecs in bio_add_page

From: Christoph Hellwig

Date: Thu Apr 02 2026 - 01:31:20 EST


On Thu, Apr 02, 2026 at 10:51:05AM +0530, Naman Jain wrote:
> When a direct I/O request spans pages from different chunks (different
> pgmaps), the current code rejected the second page entirely:
>
> if (!zone_device_pages_have_same_pgmap(bv->bv_page, page))
> return 0; // Rejection - forces bio split or I/O error
>
> Both chunks are regular RAM from the DMA perspective
> (MEMORY_DEVICE_GENERIC, not P2PDMA). The only requirement is that they not
> be merged into the same bvec segment, which patch 1/2 enforces by adding
> the pgmap check to biovec_phys_mergeable().
>
> This patch allows pages from different pgmaps to be added as separate bvec
> entries in the same bio, eliminating bio splits and I/O failures
> when buffers span pgmap boundaries.

Which as I said we can't do in general, as different pgmaps cna have
different DMA mapping requirements. We might be able to relax this
if we know multiple pgmaps can be mapped in the same way. I.e.
replace zone_device_pages_have_same_pgmap with
zone_device_pages_compatible and add additional conditions to it.

> --- a/block/bio-integrity.c
> +++ b/block/bio-integrity.c
> @@ -231,6 +231,9 @@ int bio_integrity_add_page(struct bio *bio, struct page
> *page,
> if (bip->bip_vcnt > 0) {
> struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
>
> + if (is_pci_p2pdma_page(bv->bv_page) !=
> + is_pci_p2pdma_page(page))
> + return 0;
> if (zone_device_pages_have_same_pgmap(bv->bv_page, page) &&

The above is implied by not having the same pgmap.