public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Naman Jain <namjain@linux.microsoft.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Logan Gunthorpe <logang@deltatee.com>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	Saurabh Sengar <ssengar@linux.microsoft.com>,
	Long Li <longli@microsoft.com>,
	Michael Kelley <mhklinux@outlook.com>,
	namjain@linux.microsoft.com
Subject: [PATCH v2 0/2] block: fix pgmap handling for zone device pages in bio merge paths
Date: Fri, 10 Apr 2026 15:34:12 +0000	[thread overview]
Message-ID: <20260410153414.4159050-1-namjain@linux.microsoft.com> (raw)

When zone device memory is registered in multiple chunks, each chunk
gets its own dev_pagemap. A single bio can contain bvecs from different
pgmaps -- iov_iter_extract_bvecs() breaks at pgmap boundaries but the
outer loop in bio_iov_iter_get_pages() continues filling the same bio.

There are two problems with the current code:

1. biovec_phys_mergeable() has no pgmap check, so the request merge,
   DMA mapping, and integrity merge paths can coalesce physically
   contiguous bvec segments from different pgmaps. This makes it
   impossible to recover the correct pgmap for the merged segment
   via page_pgmap().

2. bio_add_page() and bio_integrity_add_page() reject pages from a
   different pgmap entirely (returning 0), rather than just skipping
   the merge and adding them as new bvec entries. This forces callers
   to start a new bio unnecessarily.

Patch 1 fixes the merge-path gap by adding a pgmap check to
biovec_phys_mergeable().

Patch 2 introduces zone_device_pages_compatible() which replaces the
blanket zone_device_pages_have_same_pgmap() rejection in bio_add_page()
and bio_integrity_add_page(). Pages that are safe to coexist as separate
bvec entries (e.g. MEMORY_DEVICE_GENERIC from different pgmaps) are now
accepted, while P2PDMA pages from different pgmaps or mixed P2PDMA and
non-P2PDMA pages are still rejected, since the DMA iterator caches the
P2PDMA mapping state from the first segment.
zone_device_pages_have_same_pgmap() is kept as a merge guard so pages
from different pgmaps are not coalesced into the same bvec segment.

Changes since v1:
https://lore.kernel.org/all/20260401082329.1602328-1-namjain@linux.microsoft.com/
- Reworked patch 2 to introduce zone_device_pages_compatible() which
  rejects P2PDMA pages from different pgmaps at the bio-building level,
  not just at merge time. The previous version only moved the pgmap check
  into the merge conditional without preventing incompatible pages from
  being added as separate bvec entries. (Christoph Hellwig)

Naman Jain (2):
  block: add pgmap check to biovec_phys_mergeable
  block: relax pgmap check in bio_add_page for compatible zone device
    pages

 block/bio-integrity.c |  6 +++---
 block/bio.c           |  6 +++---
 block/blk.h           | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 6 deletions(-)

-- 
2.43.0


             reply	other threads:[~2026-04-10 15:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 15:34 Naman Jain [this message]
2026-04-10 15:34 ` [PATCH v2 1/2] block: add pgmap check to biovec_phys_mergeable Naman Jain
2026-04-10 15:34 ` [PATCH v2 2/2] block: relax pgmap check in bio_add_page for compatible zone device pages Naman Jain

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=20260410153414.4159050-1-namjain@linux.microsoft.com \
    --to=namjain@linux.microsoft.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=jhubbard@nvidia.com \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=longli@microsoft.com \
    --cc=mhklinux@outlook.com \
    --cc=ssengar@linux.microsoft.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox