From: Fred Griffoul <griffoul@gmail.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Sean Christopherson" <seanjc@google.com>,
"Marc Zyngier" <maz@kernel.org>,
"Oliver Upton" <oupton@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Kevin Tian" <kevin.tian@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
Ackerley Tng <ackerleytng@google.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>, Joerg Roedel <joro@8bytes.org>,
Robin Murphy <robin.murphy@arm.com>,
Alex Williamson <alex@shazbot.org>, Shuah Khan <shuah@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
iommu@lists.linux.dev, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
linux-kselftest@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, x86@kernel.org
Subject: [RFC PATCH 0/6] KVM: guest_memfd: back guest_memfd with an imported dma-buf
Date: Mon, 5 Oct 2026 09:55:46 +0000 [thread overview]
Message-ID: <20261005095552.52748-1-griffoul@gmail.com> (raw)
In-Reply-To: <20260720111259.122911-1-dwmw2@infradead.org>
From: Fred Griffoul <fgriffo@amazon.co.uk>
This extends David Woodhouse's "KVM: Allow alternative providers of
guest_memfd backed by PFNMAP memory" RFC (v2) to let guest_memfd import
a dma-buf as its page source:
https://lore.kernel.org/kvm/20260720111259.122911-1-dwmw2@infradead.org/
The memory owner is a plain dma-buf exporter, linking against neither
KVM nor iommufd. guest_memfd imports it for the guest (stage-2) plane
and iommufd imports the same buffer for the device (DMA) plane, so one
object and one invalidation protocol serve both. This is a concrete
answer to the "how do we plug into iommufd without masquerading as a
dma-buf" question from David's cover: the provider does not pretend to
be anything; the dma-buf is the shared object.
Applies on top of David's v2 series.
Patches:
1 KVM: guest_memfd: Add a writable result to get_pfn()
Give get_pfn() a writable out-param so a backing can map a page
present but read-only (KVM_MEM_READONLY is rejected on guest_memfd
slots). A guest write then exits as a memory fault. Stage-2 only;
KVM's own host-mapped accesses are unaffected.
2 dma-buf: Add get_phys() to describe a physical run
New exporter op: for an offset+len, return one physically contiguous
backed run and an attribute word (RAM/MMIO, plus READONLY). -ENOENT
for an unbacked byte, -ENODEV when revoked. Lets a page-table-building
importer ask where the memory is instead of taking a scatterlist.
Converts vfio-pci, the iommufd selftest exporter and the sample;
iommufd behaviour is unchanged.
3 dma-buf: Add ranged mapping invalidation
Invalidate a byte range rather than the whole buffer. The callback
means "re-query this range" and covers loss, replacement and
read-only flips. Importers without the callback still get a
whole-buffer invalidation.
4 dma-buf: Allow dynamic attach without a device
Allow a dynamic importer with no struct device, for a consumer (KVM)
that only needs the physical layout and builds its own tables. Such
an importer must not map the attachment for DMA.
5 KVM: guest_memfd: Add dma-buf backing
Add GUEST_MEMFD_FLAG_USE_DMABUF and a dmabuf_fd to
KVM_CREATE_GUEST_MEMFD. guest_memfd attaches as a revocable importer
without a device, serves faults from get_phys() (largest aligned RAM
run, read-only honoured), and zaps the range on the invalidation
callback.
6 samples/kvm, selftests/kvm: Exercise dma-buf backing
Turn the sample into a dma-buf exporter (a toy memory owner: one root
region, a child per VM, move/donate/reclaim, absent and read-only
pages, a scratch page, per-child ioctl allowlists) and move the
selftests to feed one dma-buf fd to both guest_memfd and iommufd.
Scope: non-confidential VMs, RAM backings only; iommufd keeps its
single-range import for now. As with David's series, this is largely
AI-assisted and is posted to get the interface shape reviewed.
Fred Griffoul (6):
KVM: guest_memfd: Add a writable result to get_pfn()
dma-buf: Add get_phys() to describe a physical run
dma-buf: Add ranged mapping invalidation
dma-buf: Allow dynamic attach without a device
KVM: guest_memfd: Add dma-buf backing
samples/kvm, selftests/kvm: Exercise dma-buf backing
arch/arm64/kvm/mmu.c | 13 +-
arch/arm64/kvm/nested.c | 10 +-
arch/x86/kvm/mmu/mmu.c | 18 +-
arch/x86/kvm/svm/sev.c | 4 +-
drivers/dma-buf/dma-buf.c | 92 +-
drivers/iommu/iommufd/iommufd_private.h | 8 -
drivers/iommu/iommufd/iommufd_test.h | 16 +
drivers/iommu/iommufd/pages.c | 74 +-
drivers/iommu/iommufd/selftest.c | 106 +-
drivers/vfio/pci/vfio_pci_dmabuf.c | 58 +-
include/linux/dma-buf.h | 70 +
include/linux/kvm_host.h | 12 +-
include/linux/vfio_pci_core.h | 3 -
include/trace/events/dma_buf.h | 2 +-
include/uapi/linux/kvm.h | 6 +-
samples/kvm/gmem_provider.c | 1311 ++++++++++-------
samples/kvm/gmem_provider.h | 144 +-
tools/include/uapi/linux/kvm.h | 6 +-
tools/testing/selftests/kvm/Makefile.kvm | 3 +-
.../kvm/gmem_provider_nvme_dma_test.c | 28 +-
.../testing/selftests/kvm/include/kvm_util.h | 25 +-
.../testing/selftests/kvm/x86/gmem_poc_test.c | 824 +++++++++++
.../kvm/x86/gmem_provider_hugepage_test.c | 30 +-
.../kvm/x86/gmem_provider_iommufd_test.c | 42 +-
.../kvm/x86/gmem_provider_readonly_test.c | 172 +++
.../kvm/x86/gmem_provider_revoke_test.c | 34 +-
.../selftests/kvm/x86/gmem_provider_test.c | 190 +--
.../kvm/x86/gmem_provider_vfio_test.c | 45 +-
virt/kvm/Kconfig | 1 +
virt/kvm/guest_memfd.c | 252 +++-
30 files changed, 2703 insertions(+), 896 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86/gmem_poc_test.c
create mode 100644 tools/testing/selftests/kvm/x86/gmem_provider_readonly_test.c
--
2.47.3
next prev parent reply other threads:[~2026-10-05 9:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 11:03 [RFC PATCH v2 00/11] KVM: Allow alternative providers of guest_memfd backed by PFNMAP memory David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 01/11] KVM: selftests: sev_smoke_test: Only run VM types the host offers David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 02/11] KVM: selftests: sev_init2_tests: Derive SEV availability from KVM David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 03/11] KVM: SEV: Remove struct page dependency from SNP gmem paths David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 04/11] KVM: guest_memfd: Introduce guest memory ops and route native gmem through them David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 05/11] iommufd: Look up private-interconnect phys via exporter symbols David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 06/11] iommufd: Plumb dma-buf memory-type (RAM vs MMIO) through the phys map David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 07/11] KVM: guest_memfd: Add ops-driven page revocation David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 08/11] samples/kvm: Add guest_memfd backing sample David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 09/11] selftests/kvm: gmem_provider KVM-only tests David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 10/11] selftests/kvm: gmem_provider iommufd tests David Woodhouse
2026-07-20 11:03 ` [RFC PATCH v2 11/11] samples/kvm, selftests/kvm: Allow the gmem_provider NVMe DMA test on arm64 David Woodhouse
2026-07-20 15:11 ` [RFC PATCH v2 00/11] KVM: Allow alternative providers of guest_memfd backed by PFNMAP memory Paolo Bonzini
2026-07-20 16:39 ` David Woodhouse
2026-07-23 0:24 ` Ackerley Tng
2026-07-23 9:40 ` David Woodhouse
2026-07-23 16:01 ` Ackerley Tng
2026-10-05 9:55 ` Fred Griffoul [this message]
2026-10-05 9:55 ` [RFC PATCH 1/6] KVM: guest_memfd: Add a writable result to get_pfn() Fred Griffoul
2026-10-05 9:55 ` [RFC PATCH 2/6] dma-buf: Add get_phys() to describe a physical run Fred Griffoul
2026-10-05 10:07 ` Christian König
2026-10-05 13:20 ` Fred Griffoul
2026-10-05 14:53 ` Christian König
2026-10-05 9:55 ` [RFC PATCH 3/6] dma-buf: Add ranged mapping invalidation Fred Griffoul
2026-10-05 10:08 ` Christian König
2026-10-05 9:55 ` [RFC PATCH 4/6] dma-buf: Allow dynamic attach without a device Fred Griffoul
2026-10-05 9:55 ` [RFC PATCH 5/6] KVM: guest_memfd: Add dma-buf backing Fred Griffoul
2026-10-05 9:55 ` [RFC PATCH 6/6] samples/kvm, selftests/kvm: Exercise " Fred Griffoul
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=20261005095552.52748-1-griffoul@gmail.com \
--to=griffoul@gmail.com \
--cc=ackerleytng@google.com \
--cc=alex@shazbot.org \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=christian.koenig@amd.com \
--cc=dave.hansen@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=dwmw2@infradead.org \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joey.gouly@arm.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=robin.murphy@arm.com \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yuzenghui@huawei.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
all inboxes | Powered by JetHome®