On Tue, Dec 1, 2026 at 9:16 AM Qiliang Yuan <qiliang.yuan(a)linux.dev> wrote:
>
> udmabuf maps the ranges of a buffer that are backed by huge pages with
> PMDs, provided the mapping covers whole PMDs at an aligned address.
>
> The existing tests of huge page backed buffers only map a few pages, so
> they never get a PMD mapping or check what is read through one.
>
> Map a udmabuf of 8 huge pages, sized from hpage_pmd_size and the hugetlb
> page size so that it also fits 16 KiB and 64 KiB base pages, and read
> back what was written to the memfd, with a different pattern in each
> huge page: through a mapping of the whole buffer, which must be PMD
> aligned for a 64-bit task when THP support is built in, through a
> mapping at an unaligned offset, from a forked child that inherits the
> mapping of the whole buffer, through a buffer that starts one page into
> the memfd so that only PTEs can map it, and next to a mapped PMD after
> THP was disabled for the mapping with MADV_NOHUGEPAGE.
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan(a)linux.dev>
Reviewed-by: T.J. Mercier <tjmercier(a)google.com>
On Tue, Dec 1, 2026 at 9:16 AM Qiliang Yuan <qiliang.yuan(a)linux.dev> wrote:
>
> QEMU and crosvm hand guest memory to the host renderer and display as
> udmabufs for virtio-gpu blob resources. The guest memory is a memfd that
> is often backed by 2 MiB huge pages, and the host process mmap()s the
> dma-buf to access it with the CPU.
>
> udmabuf maps every page with its own PTE: the first fault inserts a PFN
> for each 4 KiB page of the whole VMA. Mapping and touching 4 GiB this way
> takes over 200 ms and a million PTEs, although the memory behind it is
> 2048 huge pages.
>
> Add a ->huge_fault() handler that maps a PMD-sized range with one PMD when
> it is backed by an aligned run of contiguous PFNs, and falls back to PTEs
> otherwise. Limit the pre-mapping on a fault to the PMD-sized range of the
> fault, so that it stays within one page table and never covers a range that
> is mapped with a PMD. Buffers backed by 4 KiB pages now take a fault for
> each PMD-sized range rather than one for the whole VMA, about 1.5 us each,
> or under 1 ms per GiB. The THP settings in sysfs don't apply to VM_PFNMAP
> mappings, so only MADV_NOHUGEPAGE and PR_SET_THP_DISABLE stop the PMD
> mappings.
>
> This depends on the series "mm: fix races between huge and non-huge
> faults in PFN mappings", which keeps a PTE fault that races with a PMD
> fault on the same range, after THP was disabled, from hitting a
> VM_BUG_ON or failing with VM_FAULT_OOM.
>
> Mapping a udmabuf over a memfd filled with data and reading a byte of
> each 4 KiB page through the mapping, base and patched kernels alternating
> over 6 rounds of 5 runs (7 runs for shmem 4K), median of the per-round
> medians and range in parentheses; nothp marks a task with
> PR_SET_THP_DISABLE set:
>
> backing size before (ms) after (ms) change
> hugetlb 256M 12.7 (12.6-13.9) 0.9 (0.9-0.9) -93%
> hugetlb 1G 50.5 (50.5-50.9) 3.7 (3.6-3.7) -93%
> hugetlb 4G 201 (201-202) 13.8 (13.5-13.9) -93%
> hugetlb 8G 402 (402-403) 26.8 (26.3-27.0) -93%
> shmem THP 1G 50.6 (50.6-50.8) 3.7 (3.6-3.7) -93%
> shmem THP 4G 201 (199-203) 13.7 (13.3-13.8) -93%
> shmem 4K 1G 50.5 (50.0-50.6) 51.4 (51.2-52.1) +2%
> shmem 4K nothp 1G 50.5 (50.2-50.7) 51.4 (51.1-51.5) +2%
> shmem 4K 4G 202 (201-202) 204 (204-205) +1%
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan(a)linux.dev>
> ---
> drivers/dma-buf/udmabuf.c | 73 +++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 68 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
> index 018937435356e..dd98d5a1b69fc 100644
> --- a/drivers/dma-buf/udmabuf.c
> +++ b/drivers/dma-buf/udmabuf.c
> @@ -44,12 +44,67 @@ struct udmabuf {
> struct miscdevice *device;
> };
>
> +#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP
I think you can switch both guards to CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
and drop the if (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_PFNMAP)) below.
(That's also what the DRM helper does in drm_gem_shmem_helper.c.)
> +/*
> + * Return whether the PMD-sized range of @vma at @addr is backed by one aligned
> + * run of contiguous PFNs, which can then be mapped with a single PMD.
> + */
> +static bool udmabuf_pmd_mappable(struct vm_area_struct *vma, unsigned long addr,
> + unsigned long *pfn)
> +{
> + struct udmabuf *ubuf = vma->vm_private_data;
> + const pgoff_t nr = PMD_SIZE >> PAGE_SHIFT;
> + unsigned long first;
> + pgoff_t pgoff, i;
> +
> + if (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_PFNMAP))
> + return false;
> +
> + if (!IS_ALIGNED(addr, PMD_SIZE) || addr < vma->vm_start ||
> + vma->vm_end - addr < PMD_SIZE)
> + return false;
> +
> + pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
You can use linear_page_index(vma, addr) here and below in udmabuf_vm_fault().
> + if (pgoff >= ubuf->pagecount || ubuf->pagecount - pgoff < nr)
> + return false;
> +
> + first = page_to_pfn(ubuf->pages[pgoff]);
> + if (!IS_ALIGNED(first, nr))
> + return false;
> +
> + for (i = 1; i < nr; i++) {
> + if (page_to_pfn(ubuf->pages[pgoff + i]) != first + i)
> + return false;
> + }
> +
> + *pfn = first;
> + return true;
> +}
> +
> +/*
> + * The THP settings in /sys/kernel/mm/transparent_hugepage/ don't apply to
> + * VM_PFNMAP mappings, so this is called even when THP is set to "never".
> + * Only MADV_NOHUGEPAGE or PR_SET_THP_DISABLE keep it from being called.
> + */
> +static vm_fault_t udmabuf_vm_huge_fault(struct vm_fault *vmf,
> + unsigned int order)
> +{
> + unsigned long pfn;
> +
> + if (order != PMD_ORDER ||
> + !udmabuf_pmd_mappable(vmf->vma, vmf->address & PMD_MASK, &pfn))
> + return VM_FAULT_FALLBACK;
> +
> + return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE);
> +}
> +#endif
> +
> static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
> {
> struct vm_area_struct *vma = vmf->vma;
> struct udmabuf *ubuf = vma->vm_private_data;
> pgoff_t pgoff = vmf->pgoff;
> - unsigned long addr, pfn;
> + unsigned long addr, end, pfn;
> vm_fault_t ret;
>
> if (pgoff >= ubuf->pagecount)
> @@ -61,11 +116,16 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
> if (ret & VM_FAULT_ERROR)
> return ret;
>
> - /* pre fault */
> - pgoff = vma->vm_pgoff;
> - addr = vma->vm_start;
> + /*
> + * Pre-fault the rest of the PMD-sized range of the fault. Staying
> + * within its page table keeps the walk off the ranges that
> + * udmabuf_vm_huge_fault() maps with a PMD.
> + */
> + addr = max(vma->vm_start, vmf->address & PMD_MASK);
> + end = pmd_addr_end(vmf->address, vma->vm_end);
> + pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
I saw your reply to sashiko. Kind of too bad we can't use
pte_table_clamped_end(vmf->address, vma->vm_end) (commit 169169e26ab4)
here yet since drm-misc-next is based on 7.4-rc2 and doesn't have it
yet. I guess we have to wait on Lorenzo's series anyway.
> - for (; addr < vma->vm_end; pgoff++, addr += PAGE_SIZE) {
> + for (; addr < end; pgoff++, addr += PAGE_SIZE) {
> if (addr == vmf->address)
> continue;
>
> @@ -89,6 +149,9 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
>
> static const struct vm_operations_struct udmabuf_vm_ops = {
> .fault = udmabuf_vm_fault,
> +#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP
> + .huge_fault = udmabuf_vm_huge_fault,
> +#endif
> };
>
> static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
>
> --
> 2.43.0
>
On Wed, Dec 02, 2026 at 02:54:07PM +1100, Alistair Popple wrote:
> So what I'm hearing is that the exporter should be unmapping as a defense
> against bad importers. I can definitely understand why that might be useful,
> especially as some kind of debug thing, but I don't think we should be basing
> the whole API design around the concept we can't trust importer to implement the
> contract correctly. Especially as that defense might not actually exist in a lot
> of cases anyway (eg. IOMMU disabled), in which case you have no choice but to
> trust the importer got things right.
+1
> I also sense there might be a deeper belief that the mapping of a resource
> (ie. the IOVA) is something owned by the resource rather than the user of that
> resource.
Well, this would be wrong. The IOVA is owned by the DMA API, the DMA
API is owned by its bound driver. In the kernel it is *never* owned by
the memory object being mapped by it.
Jason
On Thu, Dec 03, 2026 at 05:33:54PM +1100, Alistair Popple wrote:
> > I can see this working for the common cross-device ones, but I'm not
> > really sure what to do about transport specific things like ualink or
> > protected VRAM. Since who would write/control the swiss piece of the
> > library in those cases?
>
> That might come back to what Christian was suggesting earlier - separate those
> cases out and for them dma-buf for ualink/nvlink/XGMI is really just a way to
> hand some opaque data back to the importer.
They probably have to provide their own swiss library for their own
protocols.
A library for phys_addr_t, a library for ualink, etc.
They have different opaque types and there is clarity when they are
being used.
Jason
This series tightens the alignment requirements for buffers that are shared
between confidential-computing guests and the host, and adds a common
allocator for host-shared memory.
When a guest runs with private memory, buffers shared with the hypervisor
are not only accessed by the guest. They are also accessed by the host
kernel, and the host may manage the corresponding shared/private state at a
granularity larger than the guest page size.
Architectures such as Arm can detect incorrect accesses to Realm physical
address space PFNs through GPC faults. However, relying on that as the only
line of defence is fragile and can still lead to kernel crashes. The risk
is especially visible for shared buffers that are later mmapped into
userspace, such as guest_memfd or dma-buf backed allocations. Once
userspace can access the mapping, the kernel cannot guarantee that
applications will only touch the intended 4K region rather than the whole
host page mapped into their address space. Those userspace addresses may
also be passed back into the kernel and accessed through the linear map,
resulting in a GPC fault.
To avoid this, host-shared buffers must satisfy two constraints:
- the address must be aligned to the CoCo shared-granule size
- the size must be a multiple of that granule size
The series adds a common CoCo shared-memory layer for enforcing these
constraints. It provides shared-granule geometry and range-validation
helpers, byte-oriented private/shared transition helpers, and
alloc_cc_shared() and its node-aware variant. The allocator accepts a byte
count, rounds internally to the sharing granule and a power-of-two number
of pages, and returns a linear-map address. The entire allocation is shared
and zeroed, with its physical base aligned to the allocation size.
cc_shared_alloc_size() reports the actual size from compound-page metadata.
free_cc_shared() restores the complete allocation to private
state before returning it to the buddy allocator. If private state cannot
be restored safely, the allocation is deliberately leaked rather than
returning potentially shared memory for unrelated use.
The series also makes zeroing part of private-to-shared transitions, with
each architecture clearing memory at the appropriate point. Callers must
therefore initialize shared buffers after the transition; existing contents
are not preserved.
The shared-granule size defaults to PAGE_SIZE and can be overridden by an
architecture. The arm64 CCA changes to discover the host's IPA state change
alignment are not included in this series.
GIC ITS command queues and tables and the dma-buf system_cc_shared heap
use the common allocator. DMA direct, atomic DMA pools and SWIOTLB retain
their allocation paths and use checked byte rounding or transition helpers.
Restricted DMA pools are checked for shared-granule alignment.
Hyper-V users of set_memory_encrypted() and set_memory_decrypted() are not
changed to use cc_make_shared() by this series. Those paths are not
currently used by the arm64 CCA code path, and therefore are not part of
the arm64 CCA IPA state change alignment problem addressed here.
Notes:
* Codex assisted with implementation, review and series organization.
Changes from v10:
https://patch.msgid.link/20261116091137.94252-1-aneesh.kumar@kernel.org
* Replace page/size descriptors with byte-based alloc_cc_shared_node() and
alloc_cc_shared(), returning a linear-map address. Recover the full size
from compound metadata in cc_shared_alloc_size() and free_cc_shared().
* Share and zero the entire allocation. Document physical alignment and
low-memory/nonmovable requirements, including without memory encryption.
* Replace layout structures with cc_shared_round_size() for callers that
manage their own backing memory.
* Require a sleepable allocation context regardless of memory encryption.
* Split architecture zeroing changes and caller cleanups into separate
patches. Separate SWIOTLB alignment from transition-helper conversion.
* Add a dedicated MAINTAINERS entry for CoCo memory sharing and
encryption, including the common interfaces and allocator.
Changes from v9:
https://lore.kernel.org/all/20261104164555.3555725-1-aneesh.kumar@kernel.org
* Leak allocations after failed sharing in the common allocator and SWIOTLB.
* Move x86 zeroing from the AMD, TDX and Hyper-V vTOM callbacks to
set_memory_decrypted(), after a successful transition
* Add set_memory_decrypted_nozero() for VGA mappings, which must change
memory attributes without clearing device memory.
* Zero memory even when encryption is inactive in the generic, arm64 and
pSeries implementations of set_memory_decrypted().
* Move pSeries zeroing after sharing. Document why pKVM and s390 must clear
private contents before sharing
* Drop the GIC ITS VPE L1 preallocation patch from this series.
This issue predates the series and will be addressed separately.
* Add mm/cc_shared.c and include/linux/cc_shared.h to the TSM MAINTAINERS
entry.
Changes from v8:
https://lore.kernel.org/all/20260924100529.1398790-1-aneesh.kumar@kernel.org
* Rebase onto the 7.4-rc1
* Move TDX and AMD (including SEV-SNP) zeroing to their finish callbacks
so private-to-shared transitions clear the final shared mapping.
* Clear __GFP_MOVABLE for shared allocations, which cannot be migrated.
* Resolve NUMA_NO_NODE in the common ITS allocation helper to preserve
placement for all ITS callers.
* Stop SWIOTLB allocation retries when the reduced pool would fall below
the shared granule size, avoiding an allocation retry loop.
Changes from v7:
https://lore.kernel.org/all/20260921144847.501151-1-aneesh.kumar@kernel.org
* Add the following new patches:
* "irqchip/gic-v3-its: Preallocate VPE L1 tables"
* "mm: Assert CoCo shared allocations may sleep"
* "mm: Zero memory during shared memory transitions"
* Drop the arm64 RHI and shared granule size patches so that the series can
be rebased on top of upstream to enable Shashiko review.
Changes from v6:
https://lore.kernel.org/all/20260904103452.1197239-1-aneesh.kumar@kernel.org
* Add a common allocator and geometry/transition helpers for CoCo host-shared
memory.
* Convert GIC ITS, dma-direct, atomic DMA pools, and the dma-buf
system_cc_shared heap to the common allocator.
* Limit dma-buf scatterlist entries to the requested buffer size so rounded
backing is not exposed to importers.
Changes from v5:
https://lore.kernel.org/all/20260706060432.1375570-1-aneesh.kumar@kernel.org
* Rebased to latest kernel
* Drop patch arm64: realm: Move Realm memory encryption ops to RSI code
Changes from v4:
https://lore.kernel.org/all/20260427063108.909019-1-aneesh.kumar@kernel.org
* Rename the helpers to use CoCo terminology
(mem_cc_shared_granule_size() / mem_cc_align_to_shared_granule() instead of
mem_decrypt_granule_size() / mem_decrypt_align()).
* Use __DMA_ATTR_ALLOC_CC_SHARED to pass CoCo shared allocation requirements
down to CMA-based allocation helpers.
* Add validation for restricted DMA pools to reject pools that are not aligned
to the shared granule size.
* Add dma-buf system heap handling for cc-shared buffers.
* Split the previous combined DMA/SWIOTLB/ITS change into smaller subsystem
patches covering ITS, DMA direct, SWIOTLB, restricted DMA pools, dma-buf
system heap, and arm64 Realm support.
* Rework arm64 Realm support by moving Realm memory encryption ops into RSI
code and exposing the CCA shared granule size through arm64_mem_crypt_ops.
Changes from v3:
https://lore.kernel.org/all/20260309102625.2315725-1-aneesh.kumar@kernel.org
* Fix build error reported by kernel test robot <lkp(a)intel.com>
Changes from v2:
https://lore.kernel.org/all/20251221160920.297689-1-aneesh.kumar@kernel.org
* Rebase to latest kernel
* Consider swiotlb always decrypted and don't align when allocating from swiotlb.
Changes from v1:
* Rename the helper to mem_encrypt_align
* Improve the commit message
* Handle DMA allocations from contiguous memory
* Handle DMA allocations from the pool
* swiotlb is still considered unencrypted. Support for an encrypted swiotlb pool
is left as TODO and is independent of this series.
Cc: Andrew Morton <akpm(a)linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas(a)arm.com>
Cc: "Christian König" <christian.koenig(a)amd.com>
Cc: Jason Gunthorpe <jgg(a)ziepe.ca>
Cc: Joerg Roedel (AMD) <joro(a)8bytes.org>
Cc: Marc Zyngier <maz(a)kernel.org>
Cc: Marek Szyprowski <m.szyprowski(a)samsung.com>
Cc: Robin Murphy <robin.murphy(a)arm.com>
Cc: Steven Price <steven.price(a)arm.com>
Cc: Sumit Semwal <sumit.semwal(a)linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose(a)arm.com>
Cc: Will Deacon <will(a)kernel.org>
Cc: "T.J. Mercier" <tjmercier(a)google.com>
Cc: Madhavan Srinivasan <maddy(a)linux.ibm.com>
Cc: Heiko Carstens <hca(a)linux.ibm.com>
Cc: Christian Borntraeger <borntraeger(a)linux.ibm.com>
Cc: Sven Schnelle <svens(a)linux.ibm.com>
Cc: Dave Hansen <dave.hansen(a)linux.intel.com>
Cc: Kiryl Shutsemau <kas(a)kernel.org>
Cc: Rick Edgecombe <rick.p.edgecombe(a)intel.com>
Cc: Paolo Bonzini <pbonzini(a)redhat.com>
Cc: Thomas Gleixner <tglx(a)kernel.org>
Cc: Ingo Molnar <mingo(a)redhat.com>
Cc: Borislav Petkov <bp(a)alien8.de>
Cc: Haiyang Zhang <haiyangz(a)microsoft.com>
Cc: Wei Liu <wei.liu(a)kernel.org>
Cc: Dexuan Cui <decui(a)microsoft.com>
Cc: Andy Lutomirski <luto(a)kernel.org>
Cc: Peter Zijlstra <peterz(a)infradead.org>
Cc: Alexander Gordeev <agordeev(a)linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer(a)linux.ibm.com>
Cc: Vasily Gorbik <gor(a)linux.ibm.com>
Cc: x86(a)kernel.org
Cc: dri-devel(a)lists.freedesktop.org
Cc: iommu(a)lists.linux.dev
Cc: linaro-mm-sig(a)lists.linaro.org
Cc: linux-arm-kernel(a)lists.infradead.org
Cc: linux-media(a)vger.kernel.org
Cc: linux-mm(a)kvack.org
Cc: kvmarm(a)lists.linux.dev
Cc: patches(a)lists.linux.dev
Aneesh Kumar K.V (Arm) (23):
MAINTAINERS: Add CoCo memory sharing and encryption entry
mm: Add an allocator for CoCo shared memory
x86/mm: Use the non-zeroing decryption helper for VGA mappings
s390/mm: Clear memory before making it shared
powerpc/pseries: Clear memory after making it shared
arm64: Zero memory during private-to-shared transitions
x86/mm: Clear memory after successful decryption transitions
mm: Document zeroing by set_memory_decrypted() and update the fallback
drivers: hv: Remove redundant clearing after decryption
x86/kvmclock: Avoid clearing decrypted clock memory twice
dma-direct: Avoid redundant clearing of shared allocations
mm: Avoid zeroing CoCo shared allocations twice
irqchip/gic-v3-its: Resolve the default NUMA node explicitly
irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory
allocator
dma-contiguous: Derive shared alignment from DMA attributes
dma-pool: Align shared atomic pools to the CoCo sharing granule
dma-direct: Align CoCo shared DMA allocations to the shared granule
size
swiotlb: Align shared IO TLB pools to the shared granule size
swiotlb: Use the common CoCo memory transition helpers
swiotlb: Reject misaligned restricted DMA pools for CoCo guests
dma-buf: system_heap: Limit scatterlist entries to the buffer size
dma-buf: system_heap: Allocate shared buffers using CoCo shared memory
allocator
swiotlb: Make rounded shared pool capacity allocatable
MAINTAINERS | 13 +
arch/arm/mm/dma-mapping.c | 5 +-
arch/arm64/mm/mem_encrypt.c | 8 +-
arch/powerpc/platforms/pseries/svm.c | 13 +-
arch/s390/mm/init.c | 7 +
arch/x86/hyperv/hv_init.c | 1 -
arch/x86/include/asm/set_memory.h | 1 +
arch/x86/include/asm/vga.h | 4 +-
arch/x86/kernel/kvmclock.c | 18 +-
arch/x86/mm/pat/set_memory.c | 19 +-
drivers/dma-buf/heaps/system_heap.c | 125 ++++-----
drivers/firmware/arm_rmm/rsi.c | 9 +
drivers/hv/connection.c | 7 -
drivers/hv/hv.c | 10 +-
drivers/hv/hv_common.c | 2 -
drivers/iommu/dma-iommu.c | 2 +-
drivers/irqchip/irq-gic-v3-its.c | 144 +++++-----
drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c | 11 +
include/linux/cc_shared.h | 25 ++
include/linux/dma-map-ops.h | 9 +-
include/linux/set_memory.h | 8 +-
kernel/dma/contiguous.c | 47 +++-
kernel/dma/direct.c | 78 ++++--
kernel/dma/ops_helpers.c | 2 +-
kernel/dma/pool.c | 29 ++-
kernel/dma/swiotlb.c | 98 ++++---
kernel/kexec_file.c | 3 +-
mm/Makefile | 1 +
mm/cc_shared.c | 245 ++++++++++++++++++
29 files changed, 680 insertions(+), 264 deletions(-)
create mode 100644 include/linux/cc_shared.h
create mode 100644 mm/cc_shared.c
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
--
2.43.0
On Wed, Dec 02, 2026 at 02:20:20PM +0000, Lorenzo Stoakes (ARM) wrote:
> Nacked-by: Lorenzo Stoakes <ljs(a)kernel.org>
I didn't expect anything else after that "<... 12 MiB of text ...>" line.
Thanks
>
> --
> Cheers, Lorenzo
>
Hi Dave,
Dave Hansen <dave.hansen(a)intel.com> writes:
> On 12/2/26 01:54, Aneesh Kumar K.V (Arm) wrote:
>> This series tightens the alignment requirements for buffers that are shared
>> between confidential-computing guests and the host, and adds a common
>> allocator for host-shared memory.
>
> Thanks for splitting things out. So, serious question here: Have you,
> Aneesh, the human, gone and looked through this series?
>
> Because, I suspect that you want me, Dave, the human to go through
> these.
>
> There's already quite an asymmetry between submitter bandwidth and
> reviewer bandwidth. If you're not looking at these, in detail, before
> they go out the door but you expect me to do so, I'm not sure wor that
> could possible work.
Yes, I wrote this series. I used Codex to improve the grammar in commit
messages and code comments, and as an additional check when reviewing
changes I made.
This is v11 of the series and incorporates feedback from earlier
reviews. It has evolved through those discussions and is not an entirely
new series.
Was there a particular change, comment, or commit message that prompted
your concern?
-aneesh
On Wed, 2 Dec 2026 15:02:46 +0530
<mhonap(a)nvidia.com> wrote:
> From: Manish Honap <mhonap(a)nvidia.com>
>
> vfio_pci_core_do_io_rw() fills reads with 0xff and drops writes in one
> excluded window given by its caller. vfio_pci_bar_rw() sets it to the
> MSI-X table or to the part of a ROM BAR past the ROM image.
> vfio_pci_vga_rw() and nvgrace-gpu pass an empty window.
>
> The next patch for vfio-cxl series puts the MSI-X table on
> a per-BAR list of excluded ranges, and a BAR can then have more than one
> such range (CXL component register region range)
The "next patch" reference should be avoided in commit logs, series are
an ephemeral thing that exist on the mailing list, and especially here,
it's not even referring to the next patch in this series.
> Add a helper in vfio_pci_bar_rw() that sends the bytes before a range to
> the device in a call of their own, so no device access runs into the
> range, and fills or drops the bytes of the range. Use it for the MSI-X
> table and for the ROM BAR past the ROM image. Remove the window
> arguments from vfio_pci_core_do_io_rw() and its callers.
>
> No functional change.
>
> Signed-off-by: Manish Honap <mhonap(a)nvidia.com>
> ---
> drivers/vfio/pci/nvgrace-gpu/main.c | 4 +-
> drivers/vfio/pci/vfio_pci_rdwr.c | 115 ++++++++++++++++++----------
> include/linux/vfio_pci_core.h | 3 +-
> 3 files changed, 76 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c
> index 5ddec340b73b..432f6b9c2842 100644
> --- a/drivers/vfio/pci/nvgrace-gpu/main.c
> +++ b/drivers/vfio/pci/nvgrace-gpu/main.c
> @@ -787,7 +787,7 @@ nvgrace_gpu_map_and_read(struct nvgrace_gpu_pci_core_device *nvdev,
> ret = vfio_pci_core_do_io_rw(&nvdev->core_device, false,
> nvdev->resmem.ioaddr,
> buf, offset, mem_count,
> - 0, 0, false, VFIO_PCI_IO_WIDTH_8);
> + false, VFIO_PCI_IO_WIDTH_8);
> }
>
> return ret;
> @@ -925,7 +925,7 @@ nvgrace_gpu_map_and_write(struct nvgrace_gpu_pci_core_device *nvdev,
> ret = vfio_pci_core_do_io_rw(&nvdev->core_device, false,
> nvdev->resmem.ioaddr,
> (char __user *)buf, pos, mem_count,
> - 0, 0, true, VFIO_PCI_IO_WIDTH_8);
> + true, VFIO_PCI_IO_WIDTH_8);
> }
>
> return ret;
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index df8848087681..68008f28bcbe 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -12,6 +12,7 @@
>
> #include <linux/fs.h>
> #include <linux/pci.h>
> +#include <linux/range.h>
> #include <linux/uaccess.h>
> #include <linux/io.h>
> #include <linux/vfio.h>
> @@ -126,66 +127,41 @@ VFIO_IORDWR(16)
> VFIO_IORDWR(32)
> VFIO_IORDWR(64)
>
> -/*
> - * Read or write from an __iomem region (MMIO or I/O port) with an excluded
> - * range which is inaccessible. The excluded range drops writes and fills
> - * reads with -1. This is intended for handling MSI-X vector tables and
> - * leftover space for ROM BARs.
> - */
> +/* Read or write from an __iomem region (MMIO or I/O port) */
> ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
> void __iomem *io, char __user *buf,
> - loff_t off, size_t count, size_t x_start,
> - size_t x_end, bool iswrite,
> + loff_t off, size_t count, bool iswrite,
> enum vfio_pci_io_width max_width)
I think there's a better shape to this series, and I think we should
keep vfio_pci_core_do_io_rw() as the variant driver facing API. I'd
propose the following sequence replacing 1 and 3, interleave the virtio
patch as necessary:
1. Simple conversion from x_start, x_end to a range. Pass NULL for an
empty range rather than {0, 0}.
2. Split static __vfio_pci_do_io_rw() from vfio_pci_core_do_io_rw() as
the helper that reads contiguous chunks, called by the original
function that retains the range information.
3. Convert from a range to a list_head. Callers allocate the list on
the stack and vfio_pci_core_do_io_rw() learns to iterate a list of
excluded ranges.
4. Introduce the per BAR excluded range list, populating MSI-X. ROM
remains a stack allocated list based on pci_map_rom(). Common
vfio_pci_core_do_io_rw() call sites now use the list_head on the
BAR, while ROM, VGA, and variant driver decide whether to use a
list_head or NULL. For example the nvgrace use case could pass the
list_head from the BAR index or NULL.
Thanks,
Alex