All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iommufd: Keep dmabuf MMIO attributes in domains added later
@ 2026-10-08 12:52 Andrea Parri
  2026-10-08 12:52 ` [PATCH v2 1/2] iommufd: Keep dmabuf PFNs MMIO when filling another domain Andrea Parri
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Andrea Parri @ 2026-10-08 12:52 UTC (permalink / raw)
  To: Jason Gunthorpe, Kevin Tian, Shuah Khan
  Cc: Andrea Parri, Joerg Roedel, Will Deacon, Robin Murphy,
	Nicolin Chen, iommu, linux-kselftest, linux-kernel

A VFIO PCI dmabuf mapped into an IOAS gets IOMMU_MMIO only in the domains
that exist when it is mapped. A domain attached afterwards, or an
IOMMU_IOAS_COPY of the area, reads the PFNs back from the existing
domain and maps the BAR as cacheable CPU memory. Patch 1 always takes
dmabuf PFNs from the recorded phys range instead.

Sashiko first reported this on patch 6 of David Woodhouse's RFC "KVM:
Allow alternative providers of guest_memfd backed by PFNMAP memory",
which picks the batch kind in pfn_reader_fill_dmabuf() from the
exporter's memory type. This fix does not depend on that series and
combines with it: with both, a domain added later gets the kind the
exporter reports.

The mock page table has no memory type bits, so the existing selftests
cannot see the difference. Patch 2 makes the mock record, per domain,
the pages mapped with IOMMU_MMIO, adds IOMMU_TEST_OP_MD_CHECK_MMIO, and
checks the domain filled later in two new tests, dmabuf_mmio_new_domain
and dmabuf_mmio_copy.

Tested on x86-64 under virtme-ng with CONFIG_IOMMUFD_TEST=y. Without
patch 1 both new tests fail on the second domain in all three mock
domain variants; in dmabuf_mmio_new_domain, a temporary print in
batch_to_domain() showed that domain mapped with IOMMU_READ |
IOMMU_WRITE | IOMMU_CACHE, where the first got IOMMU_READ | IOMMU_WRITE |
IOMMU_MMIO. With patch 1 the dmabuf tests pass, and the other iommufd
selftests give the same results as on the base tree. Patch 2 also
builds for i386 with W=1.

Not tested on hardware that uses the memory type bits (ARM SMMUv3, AMD
with SME, RISC-V).

Changes in v2:
- Validate the MMIO check range before converting 64-bit ioctl inputs
  to native-width page indices. Reject range overflow and values that
  cannot be represented on 32-bit kernels. (Sashiko)
- Patch 1 is unchanged.

V1: https://lore.kernel.org/all/20261005143737.2915-1-parri.andrea@gmail.com/

Andrea Parri (2):
  iommufd: Keep dmabuf PFNs MMIO when filling another domain
  iommufd/selftest: Check dmabuf MMIO mappings filled from another
    domain

 drivers/iommu/iommufd/iommufd_test.h          |  5 +
 drivers/iommu/iommufd/pages.c                 | 13 ++-
 drivers/iommu/iommufd/selftest.c              | 92 +++++++++++++++++++
 tools/testing/selftests/iommu/iommufd.c       | 51 ++++++++++
 tools/testing/selftests/iommu/iommufd_utils.h | 13 +++
 5 files changed, 170 insertions(+), 4 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-15 17:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 12:52 [PATCH v2 0/2] iommufd: Keep dmabuf MMIO attributes in domains added later Andrea Parri
2026-10-08 12:52 ` [PATCH v2 1/2] iommufd: Keep dmabuf PFNs MMIO when filling another domain Andrea Parri
2026-10-08 12:52 ` [PATCH v2 2/2] iommufd/selftest: Check dmabuf MMIO mappings filled from " Andrea Parri
2026-10-14 17:52   ` Jason Gunthorpe
2026-10-14 21:16     ` Andrea Parri
2026-10-14 23:59       ` Jason Gunthorpe
2026-10-15 17:22       ` Jason Gunthorpe
2026-10-15  0:44 ` (subset) [PATCH v2 0/2] iommufd: Keep dmabuf MMIO attributes in domains added later Jason Gunthorpe

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.