KVM/VFIO: guest_memfd support for device MMIO resources
Subsystems (8)
v2 cover KVM/VFIO: guest_memfd support for device MMIO resources
This series adds a guest_memfd device-resource framework for exposing PCI BAR memory to guests. The intended use is confidential device assignment, where KVM needs to coordinate private device mappings with shared access through VFIO. The Arm CCA backend is provided separately; these patches contain the guest_memfd, VFIO and IOMMUFD interfaces it uses.
The guest_memfd framework and Arm CCA backend are available together at:
https://git.gitlab.arm.com/linux-arm/linux-cca.git cca/topics/cca-da-gmem-backend
Userspace creates a device-backed guest_memfd using the ordinary VFIO device fd as resource_fd, with GUEST_MEMFD_FLAG_USE_RESOURCE and GUEST_MEMFD_FLAG_INIT_SHARED. The resource mapping superblock selects its provider; get_pfn identifies PFN-backed memory. Eligible BAR intervals are registered as guest_memfd memslots. File offsets use the existing VFIO region-offset namespace, allowing one guest_memfd to cover multiple BAR intervals. The device-backed guest_memfd fd rejects mmap and fallocate; shared guest faults obtain bare BAR PFNs from the provider instead of resolving the memslot HVA or allocating folios.
IOMMUFD resolves and pins the device's existing vDEVICE after its backend validates the VM association. Its MMIO mutex coordinates conversion and device state changes. VFIO supplies BAR PFNs, validates eligible ranges and excludes dma-buf exports while a guest_memfd provider is attached.
Without GUEST_MEMFD_FLAG_MMAP, attachment rejects existing VFIO BAR VMAs, and new VFIO mmap calls. With the flag, existing and new BAR VMAs are allowed through the VFIO fd. Attachment invalidates existing BAR mappings, including huge mappings. Subsequent faults use base-page mappings so each page's shared-range attributes are checked separately. Mapping the PFN-backed guest_memfd fd remains disabled (We can decide on this later).
VFIO BAR read/write, ioeventfd and userspace mapping faults check the requested range's guest_memfd attributes.
This series depends on:
* Ackerley Tng's "Allow guest_memfd to be created using a resource (pool) fd" RFC, which provides the tmpfs resource-provider API:
https://lore.kernel.org/all/[email protected]/
* The IOMMUFD/TSM series, which provides the vIOMMU and vDEVICE interfaces:
https://lore.kernel.org/all/[email protected]/
Notes:
* Codex assisted with implementation, review and series organization.
* Changes from v1:
https://lore.kernel.org/all/[email protected]
* Require GUEST_MEMFD_FLAG_MMAP to allow VFIO BAR mmap while a provider is attached; disable it by default.
* Use the common guest_memfd_provider_operations for folio and PFN providers. Select operations through the resource mapping superblock and forward VFIO operations to the device driver.
Aneesh Kumar K.V (Arm) (13):
KVM: guest_memfd: Support PFN-backed resource providers
KVM: guest_memfd: Support private/shared conversion of device memory
iommufd: Support MMIO provider attachment to vDEVICEs
KVM: guest_memfd: Add device provider access callbacks vfio/pci: Track userspace BAR mappings
vfio: Dispatch guest_memfd provider operations through the filesystem vfio/pci: Restrict host BAR access for guest_memfd providers vfio/pci: Provide guest_memfd backing for PCI BARs
KVM: guest_memfd: Add a provider detach callback
vfio/pci: Detach guest_memfd access before teardown
KVM: guest_memfd: Remove device mappings on final close
KVM: Invalidate guest_memfd mappings before removing memslot bindings vfio/pci: Allow VFIO BAR mmap with an attached guest_memfd
Documentation/virt/kvm/api.rst | 26 +- drivers/iommu/iommufd/viommu.c | 86 ++++ drivers/vfio/pci/Kconfig | 11 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/vfio_pci.c | 3 + drivers/vfio/pci/vfio_pci_core.c | 34 ++ drivers/vfio/pci/vfio_pci_dmabuf.c | 10 + drivers/vfio/pci/vfio_pci_gmem.c | 362 +++++++++++++++ drivers/vfio/pci/vfio_pci_gmem.h | 26 ++ drivers/vfio/pci/vfio_pci_gmem_access.c | 135 ++++++ drivers/vfio/pci/vfio_pci_rdwr.c | 13 +- drivers/vfio/vfio_main.c | 121 ++++- include/linux/guest_memfd.h | 60 ++- include/linux/iommufd.h | 26 ++ include/linux/kvm_host.h | 11 + include/linux/vfio.h | 4 + include/linux/vfio_pci_core.h | 30 ++ mm/shmem.c | 3 +- virt/kvm/guest_memfd.c | 566 ++++++++++++++++++++++-- virt/kvm/guest_memfd.h | 6 + virt/kvm/kvm_main.c | 4 + 21 files changed, 1492 insertions(+), 47 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci_gmem.c create mode 100644 drivers/vfio/pci/vfio_pci_gmem.h create mode 100644 drivers/vfio/pci/vfio_pci_gmem_access.c
Signature · 1 line
2.43.0
RFC PATCH v2 1/13 KVM: guest_memfd: Support PFN-backed resource providers
Device resources such as PCI BARs supply PFNs directly and cannot use the folio allocation path. Extend guest_memfd provider operations with bind() and get_pfn() callbacks and identify the backing type from the callbacks supplied by the provider.
Require providers to supply either folio allocation or PFN lookup, along with the callbacks appropriate to that backing type. PFN providers require INIT_SHARED and architecture support for protected device mappings.
Pass creation flags to providers so they can control mappings through the resource fd. Keep mmap on PFN-backed guest_memfd files disabled.
Resolve shared faults through get_pfn() without taking folio references. Reject dirty logging and read-only device memslots.
Provider release may run after file release and must not access the VM.
--- Documentation/virt/kvm/api.rst | 4 + include/linux/guest_memfd.h | 39 ++++++-- include/linux/kvm_host.h | 6 ++ mm/shmem.c | 3 +- virt/kvm/guest_memfd.c | 165 +++++++++++++++++++++++++++------ 5 files changed, 180 insertions(+), 37 deletions(-)
Documentation/virt/kvm/api.rst +4 -0
@@ -6529,6 +6529,10 @@ specified via KVM_CREATE_GUEST_MEMFD. Currently defined flags: require noswap and huge=never mount options. ============================= ================================================ +With USE_RESOURCE, the resource mapping superblock supplies provider +operations. Callbacks identify folio or PFN backing. PFN providers require +INIT_SHARED and a VM supporting protected resource mappings; mmap is disabled. + When the KVM MMU performs a PFN lookup to service a guest fault, the fault will always be consumed from guest_memfd, regardless of whether it is a shared or a private fault (unless in-place conversion is disabled and the backing
include/linux/guest_memfd.h +31 -8
@@ -7,23 +7,46 @@struct file ;struct folio ;struct mempolicy ; +struct kvm ; + +/* Binding data stays valid only while the provider is active. */ +struct guest_memfd_device_binding { +/* Architecture-specific mapping owner, e.g. an RMM vDEVICE handle. */ +unsigned long owner; +u64 vdev_id; +}; + +struct guest_memfd { +struct kvm *kvm; +u64 size; +u64 flags; +};/** -* struct guest_memfd_provider_operations - Operations for external memory providers -* @attach: Attach to a resource file, perform filesystem-specific validation, -* and return an opaque provider context. -* @release: Release provider context and unpin any resources. -* @alloc_folio: Allocate an uninserted folio for a given index and NUMA policy. -* @invalidate_folio: Notify provider that a folio has been invalidated. +* struct guest_memfd_provider_operations - External memory provider operations +* @attach: Validate the resource and attach it to the core context. Return +* an opaque provider or ERR_PTR(). Success pins backing resources +* and these operations until release(). +* @release: Release the provider context and backing references. Must not +* access the VM or invoke callbacks that do; the file may be gone. +* @alloc_folio: Allocate an uninserted folio for an index and NUMA policy. +* @invalidate_folio: Notify the folio provider before releasing a folio. +* @bind: Validate a PFN interval and return its protected mapping owner. +* @get_pfn: Resolve a shared resource offset without taking a folio reference. * -* Used by filesystems and device drivers that provide memory for guest_memfd. +* Provider operations supply exactly one of alloc_folio() and get_pfn(). +* PFN providers start shared and require the bind and conversion callbacks +* supported by the core. Folio providers use core allocation and conversion. */ struct guest_memfd_provider_operations { -void *(*attach)(struct file *resource_file); +void *(*attach)(struct file *resource,struct guest_memfd *gmem);void (*release)(void *provider);struct folio *(*alloc_folio)(void *provider,pgoff_t index,struct mempolicy *mpol);void (*invalidate_folio)(void *provider,struct folio *folio); +int (*bind)(void *provider,u64 offset,u64 size, +struct guest_memfd_device_binding *binding); +int (*get_pfn)(void *provider,u64 offset,unsigned long *pfn); };#endif /* _LINUX_GUEST_MEMFD_H */
include/linux/kvm_host.h +6 -0
@@ -56,6 +56,7 @@*/ #define KVM_MEMSLOT_INVALID (1UL << 16)#define KVM_MEMSLOT_GMEM_ONLY (1UL << 17) +#define KVM_MEMSLOT_GMEM_DEVICE (1UL << 18)/* * Bit 63 of the memslot generation number is an "update in-progress flag",
@@ -2605,9 +2606,14 @@ static inline bool kvm_is_private_gfn(struct kvm *kvm, gfn_t gfn)#endif /* kvm_arch_has_private_mem */ #ifdef CONFIG_KVM_GUEST_MEMFD +struct guest_memfd_device_binding ; +bool kvm_gmem_is_private_gfn (struct kvm *kvm,gfn_t gfn);bool kvm_gmem_range_has_attributes (struct kvm_memory_slot *slot,gfn_t start,gfn_t end,u64 attributes); +bool kvm_arch_gmem_device_supported (struct kvm *kvm); +void kvm_arch_gmem_device_bind (struct kvm_memory_slot *slot, +const struct guest_memfd_device_binding *binding);int kvm_gmem_set_attributes (struct kvm_memory_slot *slot,gfn_t start,gfn_t end,u64 attributes);bool kvm_arch_supports_gmem_init_shared (struct kvm *kvm);
mm/shmem.c +2 -1
@@ -5239,7 +5239,8 @@ static const struct inode_operations shmem_special_inode_operations = { };#ifdef CONFIG_KVM_GUEST_MEMFD -static void *shmem_gmem_attach (struct file *resource_file) +static void *shmem_gmem_attach (struct file *resource_file, +struct guest_memfd *gmem) {struct inode *inode =file_inode (resource_file);struct shmem_sb_info *sbinfo;
virt/kvm/guest_memfd.c +137 -28
290 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH v2 2/13 KVM: guest_memfd: Support private/shared conversion of device memory
In reply to Aneesh Kumar K.V (Arm)Allow architectures to convert device-backed guest_memfd ranges to private memory. Coordinate conversion with the device provider and update guest_memfd attributes only after the architecture operation succeeds.
Hold the inode invalidate lock across conversion and the attribute update. Provider callbacks allow a device conversion lock to cover the same operation, with the inode lock acquired first. This prevents faults and competing device operations from observing an incomplete conversion.
--- include/linux/guest_memfd.h | 12 +++ include/linux/kvm_host.h | 5 + virt/kvm/guest_memfd.c | 201 +++++++++++++++++++++++++++++++++++- 3 files changed, 213 insertions(+), 5 deletions(-)
include/linux/guest_memfd.h +12 -0
@@ -9,6 +9,12 @@ struct folio;struct mempolicy ;struct kvm ; +struct guest_memfd_device_request { +u64 gpa; +u64 pa; +u64 vdev_id; +}; +/* Binding data stays valid only while the provider is active. */ struct guest_memfd_device_binding {/* Architecture-specific mapping owner, e.g. an RMM vDEVICE handle. */
@@ -33,6 +39,8 @@ struct guest_memfd {* @invalidate_folio: Notify the folio provider before releasing a folio. * @bind: Validate a PFN interval and return its protected mapping owner. * @get_pfn: Resolve a shared resource offset without taking a folio reference. +* @prepare_conversion: Prepare protected PFN conversion; NULL request shares. +* @finish_conversion: Finish conversion after attribute publication. * * Provider operations supply exactly one of alloc_folio() and get_pfn(). * PFN providers start shared and require the bind and conversion callbacks
@@ -47,6 +55,10 @@ struct guest_memfd_provider_operations {int (*bind)(void *provider,u64 offset,u64 size,struct guest_memfd_device_binding *binding);int (*get_pfn)(void *provider,u64 offset,unsigned long *pfn); +int (*prepare_conversion)(void *provider, +const struct guest_memfd_device_request *req); +void (*finish_conversion)(void *provider, + const struct guest_memfd_device_request *req); };#endif /* _LINUX_GUEST_MEMFD_H */
include/linux/kvm_host.h +5 -0
@@ -2614,6 +2614,11 @@ bool kvm_gmem_range_has_attributes(struct kvm_memory_slot *slot, gfn_t start,bool kvm_arch_gmem_device_supported (struct kvm *kvm);void kvm_arch_gmem_device_bind (struct kvm_memory_slot *slot,const struct guest_memfd_device_binding *binding); +int kvm_arch_gmem_device_map (struct kvm *kvm, +const struct kvm_memory_slot *slot, +u64 gpa,u64 size,u64 pa); +int kvm_arch_gmem_device_unmap (struct kvm *kvm,u64 gpa,u64 size); +int kvm_gmem_device_map (struct kvm *kvm,u64 gpa,u64 size,u64 pa,u64 vdev_id);int kvm_gmem_set_attributes (struct kvm_memory_slot *slot,gfn_t start,gfn_t end,u64 attributes);bool kvm_arch_supports_gmem_init_shared (struct kvm *kvm);
virt/kvm/guest_memfd.c +196 -5
241 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [RFC PATCH v2 02/13] KVM: guest_memfd: Support private/shared conversion of device memory
Quoted 28 lines · Aneesh Kumar K.V (Arm)
[...snip...]
virt/kvm/guest_memfd.c +25
-0+static int kvm_gmem_device_convert (struct inode *inode,pgoff_t start, +pgoff_t nr_pages,const struct guest_memfd_device_request *req, +const struct kvm_memory_slot *slot) +{ +struct gmem_inode *gi =GMEM_I (inode); +u64 attrs = req ?KVM_MEMORY_ATTRIBUTE_PRIVATE :0 ; +bool prepared = false; +int ret; + +MA_STATE (mas, &gi->attributes, start, start + nr_pages -1 ); + +filemap_invalidate_lock (inode->i_mapping); +if (__kvm_gmem_range_has_attributes (inode, start, nr_pages, attrs)) { + ret =0 ; + goto out; + } + +if (req && !__kvm_gmem_range_has_attributes (inode, start, nr_pages,0 )) { + ret = -EEXIST ; + goto out; + } + + ret =kvm_gmem_mas_preallocate (&mas, attrs, start, nr_pages); +if (ret) + goto out;
virt/kvm/guest_memfd.c void __weak kvm_arch_gmem_device_bind(struct kvm_memory_slot *slot, · line 1175
Quoted 10 lines
virt/kvm/guest_memfd.c +10
-0+ +kvm_gmem_invalidate_start (inode, start, start + nr_pages,KVM_FILTER_SHARED ); +if (req &&READ_ONCE (gi->device.kvm->vm_dead)) + ret = -EIO ; +else + ret = gi->provider_ops->prepare_conversion (gi->provider, req); +if (!ret) { + prepared = true; +if (req) + ret =kvm_gmem_device_make_private (inode, slot, req, nr_pages);
Is there a way to avoid making private from within the conversion flow?
kvm_gmem_device_map() below already does it as part of vcpu_run.
If we do the above, we'd be aligned with regular conversions, where to-shared conversions eagerly update arch state (make_shared) but to-private notifications to the firmware are done lazily.
Quoted 57 lines
virt/kvm/guest_memfd.c +54
-0+else + ret =kvm_gmem_device_make_shared (inode, start, start + nr_pages); + } +if (!ret) { +mas_store_prealloc (&mas,xa_mk_value (attrs)); +kvm_gmem_device_update_private (gi); + }else { +mas_destroy (&mas); + } + +kvm_gmem_invalidate_end (inode, start, start + nr_pages); +if (prepared) + gi->provider_ops->finish_conversion (gi->provider, req); +out: +filemap_invalidate_unlock (inode->i_mapping); +return ret; +} + +int kvm_gmem_device_map (struct kvm *kvm,u64 gpa,u64 size,u64 pa,u64 vdev_id) +{ +struct guest_memfd_device_request req = { gpa, pa, vdev_id }; +struct kvm_memory_slot *slot; +gfn_t gfn = gpa >>PAGE_SHIFT ; +struct file *file; +int ret; + +if (!size) +return -EINVAL ; + +if (!PAGE_ALIGNED (gpa | size | pa)) +return -EINVAL ; + +/* Caller holds SRCU across the pending architecture request. */ + slot =gfn_to_memslot (kvm, gfn); +if (!slot || (slot->flags &KVM_MEMSLOT_INVALID )) +return -EINVAL ; + +if (!(slot->flags &KVM_MEMSLOT_GMEM_DEVICE )) +return -EINVAL ; + +if ((size >>PAGE_SHIFT ) > slot->npages - (gfn - slot->base_gfn)) +return -EINVAL ; + + file =kvm_gmem_get_file (slot); +if (!file) +return -ENOENT ; + ret =kvm_gmem_device_convert (file_inode (file), +kvm_gmem_get_index (slot, gfn), + size >>PAGE_SHIFT , &req, slot); +fput (file); +return ret; +} +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_gmem_device_map); +
Re: [RFC PATCH v2 02/13] KVM: guest_memfd: Support private/shared conversion of device memory
Quoted 43 lines · Ackerley Tng
Quoted 28 lines · Aneesh Kumar K.V (Arm)
[...snip...]
virt/kvm/guest_memfd.c +25
-0+static int kvm_gmem_device_convert (struct inode *inode,pgoff_t start, +pgoff_t nr_pages,const struct guest_memfd_device_request *req, +const struct kvm_memory_slot *slot) +{ +struct gmem_inode *gi =GMEM_I (inode); +u64 attrs = req ?KVM_MEMORY_ATTRIBUTE_PRIVATE :0 ; +bool prepared = false; +int ret; + +MA_STATE (mas, &gi->attributes, start, start + nr_pages -1 ); + +filemap_invalidate_lock (inode->i_mapping); +if (__kvm_gmem_range_has_attributes (inode, start, nr_pages, attrs)) { + ret =0 ; + goto out; + } + +if (req && !__kvm_gmem_range_has_attributes (inode, start, nr_pages,0 )) { + ret = -EEXIST ; + goto out; + } + + ret =kvm_gmem_mas_preallocate (&mas, attrs, start, nr_pages); +if (ret) + goto out;virt/kvm/guest_memfd.c void __weak kvm_arch_gmem_device_bind(struct kvm_memory_slot *slot, · line 1175
Quoted 10 lines
virt/kvm/guest_memfd.c +10
-0+ +kvm_gmem_invalidate_start (inode, start, start + nr_pages,KVM_FILTER_SHARED ); +if (req &&READ_ONCE (gi->device.kvm->vm_dead)) + ret = -EIO ; +else + ret = gi->provider_ops->prepare_conversion (gi->provider, req); +if (!ret) { + prepared = true; +if (req) + ret =kvm_gmem_device_make_private (inode, slot, req, nr_pages);Is there a way to avoid making private from within the conversion flow?
Quoted 6 lines
kvm_gmem_device_map()below already does it as part ofvcpu_run.If we do the above, we'd be aligned with regular conversions, where to-shared conversions eagerly update arch state (
make_shared) but to-private notifications to the firmware are done lazily.
I was a bit confused above. IIUC to handle RMI_EXIT_VDEV_VALIDATE_MAPPING, the conversion is not done from outside the kernel, instead it is done in the vcpu_run completion hook.
Can we make the flow that userspace is required to do the conversion request from userspace after an exit due to RMI_EXIT_VDEV_VALIDATE_MAPPING, and then just do the delegate + map + validate in the vcpu_run completion hook?
The rest are a little outside the guest_memfd field, but I'll make the suggestion anyway.
It looks like delegate and map don't need the vcpu context, only validate does, so validate has to be done in the vcpu_run completion hook.
Delegate needs the host physical addresses, so we'd need to translate the IPAs to PAs, could that be a VM ioctl? It could look up the memslots and translate IPA to PA?
RMI_RTT_DEV_MAP also doesn't need the vcpu context, IIUC it does need the VM context so it could be a VM ioctl too? If it looks up the memslot, it'll also find the guest_memfd, where it can find the device information.
I'm just thinking that the vcpu_run completion context is doing too much, and there are so many possible errors that could be better communicated to userspace if they're separate ioctls.
Or perhaps at least delegate + map could be one required ioctl call by userspace before doing vcpu_run to continue after a RMI_EXIT_VDEV_VALIDATE_MAPPING exit.
Quoted 57 lines
Quoted 57 lines
virt/kvm/guest_memfd.c +54
-0+else + ret =kvm_gmem_device_make_shared (inode, start, start + nr_pages); + } +if (!ret) { +mas_store_prealloc (&mas,xa_mk_value (attrs)); +kvm_gmem_device_update_private (gi); + }else { +mas_destroy (&mas); + } + +kvm_gmem_invalidate_end (inode, start, start + nr_pages); +if (prepared) + gi->provider_ops->finish_conversion (gi->provider, req); +out: +filemap_invalidate_unlock (inode->i_mapping); +return ret; +} + +int kvm_gmem_device_map (struct kvm *kvm,u64 gpa,u64 size,u64 pa,u64 vdev_id) +{ +struct guest_memfd_device_request req = { gpa, pa, vdev_id }; +struct kvm_memory_slot *slot; +gfn_t gfn = gpa >>PAGE_SHIFT ; +struct file *file; +int ret; + +if (!size) +return -EINVAL ; + +if (!PAGE_ALIGNED (gpa | size | pa)) +return -EINVAL ; + +/* Caller holds SRCU across the pending architecture request. */ + slot =gfn_to_memslot (kvm, gfn); +if (!slot || (slot->flags &KVM_MEMSLOT_INVALID )) +return -EINVAL ; + +if (!(slot->flags &KVM_MEMSLOT_GMEM_DEVICE )) +return -EINVAL ; + +if ((size >>PAGE_SHIFT ) > slot->npages - (gfn - slot->base_gfn)) +return -EINVAL ; + + file =kvm_gmem_get_file (slot); +if (!file) +return -ENOENT ; + ret =kvm_gmem_device_convert (file_inode (file), +kvm_gmem_get_index (slot, gfn), + size >>PAGE_SHIFT , &req, slot); +fput (file); +return ret; +} +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_gmem_device_map); +
Re: [RFC PATCH v2 02/13] KVM: guest_memfd: Support private/shared conversion of device memory
Quoted 39 lines · Ackerley Tng
[...snip...]
Quoted 9 lines
Is there a way to avoid making private from within the conversion flow?
kvm_gmem_device_map()below already does it as part ofvcpu_run.If we do the above, we'd be aligned with regular conversions, where to-shared conversions eagerly update arch state (
make_shared) but to-private notifications to the firmware are done lazily.I was a bit confused above. IIUC to handle
RMI_EXIT_VDEV_VALIDATE_MAPPING, the conversion is not done from outside the kernel, instead it is done in thevcpu_runcompletion hook.Can we make the flow that userspace is required to do the conversion request from userspace after an exit due to
RMI_EXIT_VDEV_VALIDATE_MAPPING, and then just do the delegate + map + validate in thevcpu_runcompletion hook?The rest are a little outside the
guest_memfdfield, but I'll make the suggestion anyway.It looks like delegate and map don't need the vcpu context, only validate does, so validate has to be done in the
vcpu_runcompletion hook.Delegate needs the host physical addresses, so we'd need to translate the IPAs to PAs, could that be a VM ioctl? It could look up the memslots and translate IPA to PA?
RMI_RTT_DEV_MAPalso doesn't need the vcpu context, IIUC it does need the VM context so it could be a VM ioctl too? If it looks up the memslot, it'll also find theguest_memfd, where it can find the device information.
Quoted 8 lines
I'm just thinking that the
vcpu_runcompletion context is doing too much, and there are so many possible errors that could be better communicated to userspace if they're separate ioctls.Or perhaps at least delegate + map could be one required ioctl call by userspace before doing
vcpu_runto continue after aRMI_EXIT_VDEV_VALIDATE_MAPPINGexit.
The delegate+map actually seems really similar to the KVM_ARM_RMI_POPULATE ioctl. KVM_ARM_RMI_POPULATE already calls into gmem using kvm_gmem_populate(), which can do delegate+map, can that be reused/extended as part of RMI_EXIT_VDEV_VALIDATE_MAPPING handling?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
[...snip...]
Re: [RFC PATCH v2 02/13] KVM: guest_memfd: Support private/shared conversion of device memory
In reply to Ackerley TngQuoted 47 lines · Ackerley Tng
Quoted 45 lines · Ackerley Tng
Quoted 28 lines · Aneesh Kumar K.V (Arm)
[...snip...]
virt/kvm/guest_memfd.c +25
-0+static int kvm_gmem_device_convert (struct inode *inode,pgoff_t start, +pgoff_t nr_pages,const struct guest_memfd_device_request *req, +const struct kvm_memory_slot *slot) +{ +struct gmem_inode *gi =GMEM_I (inode); +u64 attrs = req ?KVM_MEMORY_ATTRIBUTE_PRIVATE :0 ; +bool prepared = false; +int ret; + +MA_STATE (mas, &gi->attributes, start, start + nr_pages -1 ); + +filemap_invalidate_lock (inode->i_mapping); +if (__kvm_gmem_range_has_attributes (inode, start, nr_pages, attrs)) { + ret =0 ; + goto out; + } + +if (req && !__kvm_gmem_range_has_attributes (inode, start, nr_pages,0 )) { + ret = -EEXIST ; + goto out; + } + + ret =kvm_gmem_mas_preallocate (&mas, attrs, start, nr_pages); +if (ret) + goto out;virt/kvm/guest_memfd.c void __weak kvm_arch_gmem_device_bind(struct kvm_memory_slot *slot, · line 1175
Quoted 10 lines
virt/kvm/guest_memfd.c +10
-0+ +kvm_gmem_invalidate_start (inode, start, start + nr_pages,KVM_FILTER_SHARED ); +if (req &&READ_ONCE (gi->device.kvm->vm_dead)) + ret = -EIO ; +else + ret = gi->provider_ops->prepare_conversion (gi->provider, req); +if (!ret) { + prepared = true; +if (req) + ret =kvm_gmem_device_make_private (inode, slot, req, nr_pages);Is there a way to avoid making private from within the conversion flow?
kvm_gmem_device_map()below already does it as part ofvcpu_run.
Quoted 9 lines
Quoted 4 lines
If we do the above, we'd be aligned with regular conversions, where to-shared conversions eagerly update arch state (
make_shared) but to-private notifications to the firmware are done lazily.I was a bit confused above. IIUC to handle
RMI_EXIT_VDEV_VALIDATE_MAPPING, the conversion is not done from outside the kernel, instead it is done in thevcpu_runcompletion hook.
All of that has changed in the latest series. kvm_complete_vdev_map_validate() now does the following. For the dependent changes in other subsystems, you may want to fetch the Git branch mentioned in the cover letter.
static void kvm_complete_vdev_map_validate(struct kvm_vcpu *vcpu)
{
struct kvm *kvm = vcpu->kvm;
struct realm_rec *rec = &vcpu->arch.rec;
struct realm *realm = &kvm->arch.realm;
struct kvm_memory_slot *slot;
unsigned long start = rec->run->exit.dev_mem_base;
unsigned long top = rec->run->exit.dev_mem_top;
unsigned long rd = virt_to_phys(realm->rd);
unsigned long rec_phys = virt_to_phys(rec->rec_page);
int idx, ret;
if (vcpu->run->cca_exit.response != KVM_ARM64_TIO_RESPONSE_APPROVE ||
top <= start || !PAGE_ALIGNED(start | top | rec->run->exit.dev_mem_pa) ||
!kvm_realm_is_private_address(realm, start) ||
!kvm_realm_is_private_address(realm, top - 1))
goto reject;
idx = srcu_read_lock(&kvm->srcu);
slot = gfn_to_memslot(kvm, gpa_to_gfn(start));
if (!slot || (slot->flags & KVM_MEMSLOT_INVALID) ||
!(slot->flags & KVM_MEMSLOT_GMEM_DEVICE) ||
gpa_to_gfn(top - 1) >= slot->base_gfn + slot->npages ||
slot->arch.device.vdev_id != rec->run->exit.vdev_id_1)
goto out_reject;
/* Userspace installs the mapping through guest_memfd before approval. */
if (!kvm_gmem_range_has_attributes(slot, gpa_to_gfn(start),
gpa_to_gfn(top), KVM_MEMORY_ATTRIBUTE_PRIVATE))
goto out_reject;
while (start < top) {
unsigned long next, rmi_ret;
ret = rmi_rtt_dev_validate(rd, rec_phys, start, top, &next, &rmi_ret);
if (ret || rmi_ret || next <= start || next > top)
goto out_reject;
start = next;
}
srcu_read_unlock(&kvm->srcu, idx);
return;
out_reject:
srcu_read_unlock(&kvm->srcu, idx);
reject:
rec->run->enter.flags |= REC_ENTER_FLAG_DEV_MEM_RESPONSE;
}-aneesh
Re: [RFC PATCH v2 02/13] KVM: guest_memfd: Support private/shared conversion of device memory
In reply to Ackerley TngQuoted 43 lines · Ackerley Tng
Quoted 28 lines · Aneesh Kumar K.V (Arm)
[...snip...]
virt/kvm/guest_memfd.c +25
-0+static int kvm_gmem_device_convert (struct inode *inode,pgoff_t start, +pgoff_t nr_pages,const struct guest_memfd_device_request *req, +const struct kvm_memory_slot *slot) +{ +struct gmem_inode *gi =GMEM_I (inode); +u64 attrs = req ?KVM_MEMORY_ATTRIBUTE_PRIVATE :0 ; +bool prepared = false; +int ret; + +MA_STATE (mas, &gi->attributes, start, start + nr_pages -1 ); + +filemap_invalidate_lock (inode->i_mapping); +if (__kvm_gmem_range_has_attributes (inode, start, nr_pages, attrs)) { + ret =0 ; + goto out; + } + +if (req && !__kvm_gmem_range_has_attributes (inode, start, nr_pages,0 )) { + ret = -EEXIST ; + goto out; + } + + ret =kvm_gmem_mas_preallocate (&mas, attrs, start, nr_pages); +if (ret) + goto out;virt/kvm/guest_memfd.c void __weak kvm_arch_gmem_device_bind(struct kvm_memory_slot *slot, · line 1175
Quoted 10 lines
virt/kvm/guest_memfd.c +10
-0+ +kvm_gmem_invalidate_start (inode, start, start + nr_pages,KVM_FILTER_SHARED ); +if (req &&READ_ONCE (gi->device.kvm->vm_dead)) + ret = -EIO ; +else + ret = gi->provider_ops->prepare_conversion (gi->provider, req); +if (!ret) { + prepared = true; +if (req) + ret =kvm_gmem_device_make_private (inode, slot, req, nr_pages);Is there a way to avoid making private from within the conversion flow?
Quoted 6 lines
kvm_gmem_device_map()below already does it as part ofvcpu_run.If we do the above, we'd be aligned with regular conversions, where to-shared conversions eagerly update arch state (
make_shared) but to-private notifications to the firmware are done lazily.
For the TDISP flow, the vdev must be mapped before the guest can issue evidence accept. The flow I am currently trying to follow is: the guest requests validation of the MMIO range, triggering a VM exit; VFIO validates the range and then converts it to private via kvm_gmem_set_attributes_ioctl().
In my new series, I have added a backend operation that abstracts this across folios, RAM PFNs, and device PFNs.
-aneesh
RFC PATCH v2 3/13 iommufd: Support MMIO provider attachment to vDEVICEs
In reply to Aneesh Kumar K.V (Arm)Allow a device MMIO provider to attach to the existing vDEVICE after the backend validates its association with the VM. Keep the vDEVICE and IOMMUFD context alive until the provider detaches.
Add a per-vDEVICE MMIO mutex to serialize provider attachment and detachment, and allow providers and backends to use the same lock for memory conversion and device state changes. Provide a callback to query whether private MMIO ranges remain.
--- drivers/iommu/iommufd/viommu.c | 86 ++++++++++++++++++++++++++++++++++ include/linux/iommufd.h | 26 ++++++++++ 2 files changed, 112 insertions(+)
drivers/iommu/iommufd/viommu.c +86 -0
@@ -250,6 +250,7 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd) goto out_unlock_igroup; } +mutex_init (&vdev->mmio_lock); vdev->virt_id = virt_id; vdev->viommu = viommu;refcount_inc (&viommu->obj.users);
@@ -487,3 +488,88 @@ int iommufd_hw_queue_alloc_ioctl(struct iommufd_ucmd *ucmd)iommufd_put_object (ucmd->ictx, &viommu->obj);return rc; } + +struct iommufd_vdevice * +iommufd_device_attach_mmio_provider (struct iommufd_device *idev, +struct kvm *kvm,void *data, +bool (*has_private_mmio)(void *), +unsigned long *owner) +{ +struct iommufd_vdevice *vdev; +int ret; + +if (!idev) +return ERR_PTR (-ENODEV ); + +guard (mutex)(&idev->igroup->lock); +if (idev->destroying) +return ERR_PTR (-EOPNOTSUPP ); + + vdev = idev->vdev; +if (!vdev) +return ERR_PTR (-EOPNOTSUPP ); + +if (!vdev->viommu->ops || + !vdev->viommu->ops->vdevice_get_mmio_owner) +return ERR_PTR (-EOPNOTSUPP ); + +guard (mutex)(&vdev->mmio_lock); +if (vdev->mmio_provider_data) +return ERR_PTR (-EBUSY ); + + ret = vdev->viommu->ops->vdevice_get_mmio_owner (vdev, kvm, owner); +if (ret) +return ERR_PTR (ret); + +/* IOMMU_DESTROY must wait for the attached gmem provider to detach. */ + ret =iommufd_try_inc_users (idev->ictx, &vdev->obj); +if (ret) +return ERR_PTR (ret); + +iommufd_ctx_get (idev->ictx); + vdev->mmio_provider_data = data; + vdev->has_private_mmio = has_private_mmio; +return vdev; +} +EXPORT_SYMBOL_NS_GPL (iommufd_device_attach_mmio_provider,"IOMMUFD" ); + +void iommufd_vdevice_detach_mmio_provider (struct iommufd_vdevice *vdev) +{ +struct iommufd_ctx *ictx = vdev->viommu->ictx; + + scoped_guard(mutex, &vdev->mmio_lock) { +WARN_ON (iommufd_vdevice_has_private_mmio (vdev)); + vdev->mmio_provider_data =NULL ; + vdev->has_private_mmio =NULL ; + } +refcount_dec (&vdev->obj.users); +iommufd_ctx_put (ictx); +} +EXPORT_SYMBOL_NS_GPL (iommufd_vdevice_detach_mmio_provider,"IOMMUFD" ); + +void iommufd_vdevice_mmio_lock (struct iommufd_vdevice *vdev) +{ +mutex_lock (&vdev->mmio_lock); +} +EXPORT_SYMBOL_NS_GPL (iommufd_vdevice_mmio_lock,"IOMMUFD" ); + +void iommufd_vdevice_mmio_unlock (struct iommufd_vdevice *vdev) +{ +mutex_unlock (&vdev->mmio_lock); +} +EXPORT_SYMBOL_NS_GPL (iommufd_vdevice_mmio_unlock,"IOMMUFD" ); + +/** +* iommufd_vdevice_has_private_mmio() - check for private MMIO ranges +* @vdev: vDEVICE whose private MMIO state is being checked +* +* Return: true if the attached provider has committed private ranges. +*/ +bool iommufd_vdevice_has_private_mmio (struct iommufd_vdevice *vdev) +{ +lockdep_assert_held (&vdev->mmio_lock); +if (!vdev->has_private_mmio) +return false; +return vdev->has_private_mmio (vdev->mmio_provider_data); +} +EXPORT_SYMBOL_NS_GPL (iommufd_vdevice_has_private_mmio,"IOMMUFD" );
include/linux/iommufd.h +26 -0
@@ -7,10 +7,12 @@#define __LINUX_IOMMUFD_H#include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/iommu.h> #include <linux/refcount.h> +#include <linux/mutex.h> #include <linux/types.h> #include <linux/xarray.h> #include <uapi/linux/iommufd.h>
@@ -26,6 +28,7 @@ struct iommufd_device;struct iommufd_viommu_ops ;struct tsm_dev ;struct page ; +struct kvm ;struct tsm_guest_req_info ;enum iommufd_object_type {
@@ -73,6 +76,19 @@ int iommufd_device_replace(struct iommufd_device *idev, ioasid_t pasid, u32 *pt_id);void iommufd_device_detach (struct iommufd_device *idev,ioasid_t pasid); +/* The returned opaque vDEVICE pins its IOMMUFD context and physical owner. */ +struct iommufd_vdevice * +iommufd_device_attach_mmio_provider (struct iommufd_device *idev, +struct kvm *kvm,void *data, +bool (*has_private_mmio)(void *), +unsigned long *owner); +void iommufd_vdevice_detach_mmio_provider (struct iommufd_vdevice *vdev); +void iommufd_vdevice_mmio_lock (struct iommufd_vdevice *vdev); +void iommufd_vdevice_mmio_unlock (struct iommufd_vdevice *vdev); +DEFINE_GUARD(iommufd_vdevice_mmio, struct iommufd_vdevice *, + iommufd_vdevice_mmio_lock(_T), iommufd_vdevice_mmio_unlock(_T)) +bool iommufd_vdevice_has_private_mmio (struct iommufd_vdevice *vdev); +struct iommufd_ctx *iommufd_device_to_ictx (struct iommufd_device *idev);u32 iommufd_device_to_id (struct iommufd_device *idev);
@@ -130,6 +146,12 @@ struct iommufd_vdevice {*/ u64 virt_id; +/* Serializes provider attachment and conversion. */ +struct mutex mmio_lock; +/* Attached provider and callbacks, protected by mmio_lock until detach. */ +void *mmio_provider_data; +bool (*has_private_mmio)(void *data); +/* Guest TSM requests accepted by this vdevice; set by vdevice_init(). */ u64 tsm_req_op_mask;u32 tsm_tvm_arch;
@@ -187,6 +209,7 @@ struct iommufd_hw_queue {* include/uapi/linux/iommufd.h) * If driver has a deinit function to revert what vdevice_init op * does, it should set it to the @vdev->destroy function pointer +* @vdevice_get_mmio_owner: Validate the VM and return its MMIO owner. * @vdevice_tsm_req: Forward a guest TSM request to a driver-owned vDEVICE * @get_hw_queue_size: Get the size of a driver-defined HW queue structure for a * given @viommu corresponding to @queue_type. Driver should
@@ -218,6 +241,9 @@ struct iommufd_viommu_ops { const struct iommu_user_data *user_data);int (*cache_invalidate)(struct iommufd_viommu *viommu,struct iommu_user_data_array *array); +/* Owner lookup runs with vdevice->mmio_lock held. */ +int (*vdevice_get_mmio_owner)(struct iommufd_vdevice *vdev, +struct kvm *kvm,unsigned long *owner);const size_t vdevice_size;int (*vdevice_init)(struct iommufd_vdevice *vdev); ssize_t (*vdevice_tsm_req)(struct iommufd_vdevice *vdev,
Signature · 1 line
2.43.0
RFC PATCH v2 4/13 KVM: guest_memfd: Add device provider access callbacks
In reply to Aneesh Kumar K.V (Arm)Expose callbacks for device providers to check whether a range is shared, query whether private ranges remain, and invalidate shared guest mappings.
Use a nonblocking acquisition of the inode invalidate lock for host access checks, avoiding deadlock with conversion while a provider holds its memory lock. Invalidate shared mappings under SRCU and the KVM MMU lock, advancing the MMU invalidation sequence so concurrent faults retry.
Initialize callback state before attaching the provider and publish the guest_memfd file after creation completes.
--- include/linux/guest_memfd.h | 6 ++ virt/kvm/guest_memfd.c | 117 ++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+)
include/linux/guest_memfd.h +6 -0
@@ -26,6 +26,12 @@ struct guest_memfd {struct kvm *kvm;u64 size;u64 flags; +struct file *gmem_file; + +/* Revoke shared guest translations synchronously. */ +void (*invalidate)(struct guest_memfd *gmem); +bool (*has_private)(struct guest_memfd *gmem); +bool (*host_accessible)(struct guest_memfd *gmem,u64 offset,u64 size); };/**
virt/kvm/guest_memfd.c +117 -0
141 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH v2 5/13 vfio/pci: Track userspace BAR mappings
In reply to Aneesh Kumar K.V (Arm)Track userspace mappings of PCI BARs so a later patch can reject guest_memfd attachment while such mappings exist.
Count the initial mmap explicitly because vm_ops->open() is not called for it. Use the VMA open and close callbacks to track duplication and unmapping, keeping the count nonzero until the last mapping is unmapped.
--- drivers/vfio/pci/vfio_pci_core.c | 19 +++++++++++++++++++ include/linux/vfio_pci_core.h | 2 ++ 2 files changed, 21 insertions(+)
drivers/vfio/pci/vfio_pci_core.c +19 -0
@@ -1806,7 +1806,23 @@ static vm_fault_t vfio_pci_mmap_page_fault(struct vm_fault *vmf)return vfio_pci_mmap_huge_fault (vmf,0 ); } +static void vfio_pci_mmap_open (struct vm_area_struct *vma) +{ +struct vfio_pci_core_device *vdev = vma->vm_private_data; + +atomic_inc (&vdev->mmap_count); +} + +static void vfio_pci_mmap_close (struct vm_area_struct *vma) +{ +struct vfio_pci_core_device *vdev = vma->vm_private_data; + +atomic_dec (&vdev->mmap_count); +} +static const struct vm_operations_struct vfio_pci_mmap_ops = { + .open = vfio_pci_mmap_open, + .close = vfio_pci_mmap_close, .fault = vfio_pci_mmap_page_fault, #ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP .huge_fault = vfio_pci_mmap_huge_fault,
@@ -1888,6 +1904,8 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vmavm_flags_set (vma,VM_ALLOW_ANY_UNCACHED |VM_IO |VM_PFNMAP |VM_DONTEXPAND |VM_DONTDUMP ); vma->vm_ops = &vfio_pci_mmap_ops; +/* Initial mmap does not invoke vm_ops->open(). */ +vfio_pci_mmap_open (vma);return 0 ; }
@@ -2197,6 +2215,7 @@ int vfio_pci_core_init_dev(struct vfio_device *core_vdev)return ret;INIT_LIST_HEAD (&vdev->dmabufs);init_rwsem (&vdev->memory_lock); +atomic_set (&vdev->mmap_count,0 );xa_init (&vdev->ctx);return 0 ;
include/linux/vfio_pci_core.h +2 -0
@@ -8,6 +8,7 @@* Author: Tom Lyon, [email protected] */ +#include <linux/atomic.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/vfio.h>
@@ -148,6 +149,7 @@ struct vfio_pci_core_device {struct vfio_pci_core_device *sriov_pf_core_dev;struct notifier_block nb;struct rw_semaphore memory_lock; +atomic_t mmap_count;struct list_head dmabufs; };
Signature · 1 line
2.43.0
RFC PATCH v2 6/13 vfio: Dispatch guest_memfd provider operations through the filesystem
In reply to Aneesh Kumar K.V (Arm)Expose guest_memfd provider operations through the VFIO mapping superblock and forward them to the device driver. Validate the driver callbacks before attachment and keep the source file pinned through provider release.
--- drivers/vfio/vfio_main.c | 115 ++++++++++++++++++++++++++++++++++++++- include/linux/vfio.h | 4 ++ 2 files changed, 118 insertions(+), 1 deletion(-)
drivers/vfio/vfio_main.c +114 -1
@@ -14,8 +14,10 @@#include <linux/compat.h> #include <linux/device.h> #include <linux/fs.h> +#include <linux/guest_memfd.h> #include <linux/idr.h> #include <linux/iommu.h> +#include <linux/kvm.h> #if IS_ENABLED (CONFIG_KVM )#include <linux/kvm_host.h> #endif
@@ -248,9 +250,120 @@ struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev, }EXPORT_SYMBOL_GPL (_vfio_alloc_device); +struct vfio_gmem_provider { +const struct guest_memfd_provider_operations *ops; +void *data; +struct file *file; +}; + +static void *vfio_gmem_provider_attach (struct file *file, +struct guest_memfd *gmem) +{ +const struct guest_memfd_provider_operations *ops; +struct vfio_gmem_provider *provider; +struct vfio_device_file *df; +void *data; + +/* Reject other file types before interpreting their private_data. */ +if (file->f_op != &vfio_device_fops) +return ERR_PTR (-EOPNOTSUPP ); + + df = file->private_data; + ops = df->device->ops->gmem_provider_ops; +/* Every provider must support attachment and release. */ +if (!ops || !ops->attach || !ops->release) +return ERR_PTR (-EOPNOTSUPP ); + +/* VFIO requires PFN lookup, binding and conversion. */ +if (!ops->get_pfn || !ops->bind || !ops->prepare_conversion || + !ops->finish_conversion) +return ERR_PTR (-EOPNOTSUPP ); + +/* VFIO provides PFNs, not folios. */ +if (ops->alloc_folio || ops->invalidate_folio) +return ERR_PTR (-EOPNOTSUPP ); + + provider =kzalloc_obj (*provider); +if (!provider) +return ERR_PTR (-ENOMEM ); + + data = ops->attach (file, gmem); +if (IS_ERR (data)) { +kfree (provider); +return data; + } + + provider->ops = ops; + provider->data = data; +/* Pin the driver operations through release(), including its return. */ + provider->file =get_file (file); +return provider; +} + +static void vfio_gmem_provider_release (void *data) +{ +struct vfio_gmem_provider *provider = data; + + provider->ops->release (provider->data); +fput (provider->file); +kfree (provider); +} + +static int vfio_gmem_provider_bind (void *data,u64 offset,u64 size, +struct guest_memfd_device_binding *binding) +{ +struct vfio_gmem_provider *provider = data; + +return provider->ops->bind (provider->data, offset, size, binding); +} + +static int vfio_gmem_provider_get_pfn (void *data,u64 offset,unsigned long *pfn) +{ +struct vfio_gmem_provider *provider = data; + +return provider->ops->get_pfn (provider->data, offset, pfn); +} + +static int vfio_gmem_provider_prepare_conversion ( +void *context,const struct guest_memfd_device_request *req) +{ +struct vfio_gmem_provider *provider = context; + +return provider->ops->prepare_conversion (provider->data, req); +} + +static void vfio_gmem_provider_finish_conversion ( +void *context,const struct guest_memfd_device_request *req) +{ +struct vfio_gmem_provider *provider = context; + + provider->ops->finish_conversion (provider->data, req); +} + + + +static const struct guest_memfd_provider_operations vfio_gmem_provider_ops = { + .attach = vfio_gmem_provider_attach, + .release = vfio_gmem_provider_release, + .bind = vfio_gmem_provider_bind, + .get_pfn = vfio_gmem_provider_get_pfn, + .prepare_conversion = vfio_gmem_provider_prepare_conversion, + .finish_conversion = vfio_gmem_provider_finish_conversion, +}; + +static const struct super_operations vfio_fs_super_ops = { + .statfs = simple_statfs, + .gmem_provider_ops = &vfio_gmem_provider_ops, +}; +static int vfio_fs_init_fs_context (struct fs_context *fc) { -return init_pseudo (fc,VFIO_MAGIC ) ?0 : -ENOMEM ; +struct pseudo_fs_context *ctx =init_pseudo (fc,VFIO_MAGIC ); + +if (!ctx) +return -ENOMEM ; + ctx->ops = &vfio_fs_super_ops; +return 0 ; }static struct file_system_type vfio_fs_type = {
include/linux/vfio.h +4 -0
@@ -81,6 +81,8 @@ struct vfio_device {struct dentry *debug_root; }; +struct guest_memfd_provider_operations ; +/** * struct vfio_device_ops - VFIO bus driver device callbacks *
@@ -111,9 +113,11 @@ struct vfio_device {* if none was provided. * @dma_unmap: Called when userspace unmaps IOVA from the container * this device is attached to. +* @gmem_provider_ops: Optional driver guest_memfd resource operations * @device_feature: Optional, fill in the VFIO_DEVICE_FEATURE ioctl */ struct vfio_device_ops { +const struct guest_memfd_provider_operations *gmem_provider_ops;char *name;int (*init)(struct vfio_device *vdev);void (*release)(struct vfio_device *vdev);
Signature · 1 line
2.43.0
RFC PATCH v2 7/13 vfio/pci: Restrict host BAR access for guest_memfd providers
In reply to Aneesh Kumar K.V (Arm)Add the access and invalidation helpers needed by a PCI guest_memfd provider. Check shared-range attributes for BAR read/write and ioeventfd access, and revoke shared guest mappings when VFIO changes device state.
Reject new VFIO mmap and dma-buf exports while a provider is attached.
--- drivers/vfio/pci/Kconfig | 11 +++ drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci_core.c | 9 ++- drivers/vfio/pci/vfio_pci_dmabuf.c | 10 +++ drivers/vfio/pci/vfio_pci_gmem.h | 15 ++++ drivers/vfio/pci/vfio_pci_gmem_access.c | 101 ++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_rdwr.c | 13 ++- include/linux/vfio_pci_core.h | 22 ++++++ 8 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci_gmem.h create mode 100644 drivers/vfio/pci/vfio_pci_gmem_access.c
drivers/vfio/pci/Kconfig +11 -0
@@ -55,6 +55,17 @@ config VFIO_PCI_ZDEV_KVM To enable s390x KVM vfio-pci extensions, say Y. +config VFIO_PCI_GMEM + bool "VFIO PCI device guest_memfd resource provider" + depends on VFIO_PCI && IOMMUFD && KVM + depends on KVM_GUEST_MEMFD + help + Allow the VFIO PCI device fd to provide BAR PFNs to guest_memfd, + including confidential-device range conversion through its + existing IOMMUFD vDEVICE. This requires a capable TSM backend. + Shared access is revoked before private range mapping and is + restored only after private mappings and device state permit it. + config VFIO_PCI_DMABUF def_bool y if VFIO_PCI_CORE && PCI_P2PDMA && DMA_SHARED_BUFFER
drivers/vfio/pci/Makefile +1 -0
@@ -3,6 +3,7 @@ vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) += vfio_pci_zdev.o vfio-pci-core-$(CONFIG_VFIO_PCI_DMABUF) += vfio_pci_dmabuf.o +vfio-pci-core-$(CONFIG_VFIO_PCI_GMEM) += vfio_pci_gmem_access.o obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o
drivers/vfio/pci/vfio_pci_core.c +8 -1
@@ -1713,7 +1713,10 @@ static void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev)loff_t end =VFIO_PCI_INDEX_TO_OFFSET (VFIO_PCI_ROM_REGION_INDEX );loff_t len = end - start; -unmap_mapping_range (core_vdev->inode->i_mapping, start, len, true); +/* An attached provider excludes every VFIO BAR VMA. */ +if (!vdev->gmem) +unmap_mapping_range (core_vdev->inode->i_mapping, start, len, true); +vfio_pci_gmem_invalidate (vdev); }void vfio_pci_zap_and_down_write_memory_lock (struct vfio_pci_core_device *vdev)
@@ -1838,6 +1841,10 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vmau64 phys_len, req_len, pgoff, req_start;void __iomem *bar_io; +guard (rwsem_read)(&vdev->memory_lock); +if (vdev->gmem) +return -EBUSY ; + index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -PAGE_SHIFT );if (index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions)
drivers/vfio/pci/vfio_pci_dmabuf.c +10 -0
@@ -306,6 +306,16 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,/* dma_buf_put() now frees priv */ INIT_LIST_HEAD (&priv->dmabufs_elm);down_write (&vdev->memory_lock); +/* +* dma-buf consumers bypass guest_memfd range access checks, and their +* mappings are not revoked by conversion to private memory. Exclude +* exports while attached; memory_lock serializes this with attachment. +*/ +if (vdev->gmem) { +up_write (&vdev->memory_lock); +dma_buf_put (priv->dmabuf); +return -EBUSY ; + }dma_resv_lock (priv->dmabuf->resv,NULL ); priv->revoked = !__vfio_pci_memory_enabled (vdev);list_add_tail (&priv->dmabufs_elm, &vdev->dmabufs);
drivers/vfio/pci/vfio_pci_gmem.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef VFIO_PCI_GMEM_H +#define VFIO_PCI_GMEM_H + +#include <linux/guest_memfd.h> + +struct iommufd_vdevice ; +struct vfio_pci_core_device ; + +struct vfio_pci_gmem { +struct guest_memfd *gmem; +struct iommufd_vdevice *ivdev; +}; + +#endif /* VFIO_PCI_GMEM_H */
drivers/vfio/pci/vfio_pci_gmem_access.c new file +101 -0
101 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_rdwr.c +10 -3
@@ -44,7 +44,9 @@ int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev, \ { \if (test_mem) { \down_read (&vdev->memory_lock); \ -if (!__vfio_pci_memory_enabled (vdev)) { \ +if (!__vfio_pci_memory_enabled (vdev) || \ + !vfio_pci_gmem_io_access_allowed (vdev, io, \ + sizeof(u##size))) { \up_read (&vdev->memory_lock); \return -EIO ; \ } \
@@ -70,7 +72,9 @@ int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \ { \if (test_mem) { \down_read (&vdev->memory_lock); \ -if (!__vfio_pci_memory_enabled (vdev)) { \ +if (!__vfio_pci_memory_enabled (vdev) || \ + !vfio_pci_gmem_io_access_allowed (vdev, io, \ + sizeof(u##size))) { \up_read (&vdev->memory_lock); \return -EIO ; \ } \
@@ -380,7 +384,10 @@ static int vfio_pci_ioeventfd_handler(void *opaque, void *unused)if (ioeventfd->test_mem) {if (!down_read_trylock (&vdev->memory_lock))return 1 ;/* Lock contended, use thread */ -if (!__vfio_pci_memory_enabled (vdev)) { +if (!__vfio_pci_memory_enabled (vdev) || + !vfio_pci_gmem_access_allowed (vdev, +VFIO_PCI_INDEX_TO_OFFSET (ioeventfd->bar) + + ioeventfd->pos, ioeventfd->count)) {up_read (&vdev->memory_lock);return 0 ; }
include/linux/vfio_pci_core.h +22 -0
@@ -151,8 +151,30 @@ struct vfio_pci_core_device {struct rw_semaphore memory_lock;atomic_t mmap_count;struct list_head dmabufs; +/* Attached provider; publication/removal require memory_lock for write. */ +struct vfio_pci_gmem *gmem; }; +#if IS_ENABLED (CONFIG_VFIO_PCI_GMEM ) +void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev); +bool vfio_pci_gmem_access_allowed (struct vfio_pci_core_device *vdev, +u64 offset,u64 size); +bool vfio_pci_gmem_io_access_allowed (struct vfio_pci_core_device *vdev, +void __iomem *io,size_t size); +#else +static inline void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev) {} +static inline bool vfio_pci_gmem_access_allowed (struct vfio_pci_core_device *vdev, +u64 offset,u64 size) +{ +return true; +} +static inline bool vfio_pci_gmem_io_access_allowed (struct vfio_pci_core_device *vdev, +void __iomem *io,size_t size) +{ +return true; +} +#endif +enum vfio_pci_io_width {VFIO_PCI_IO_WIDTH_1 =1 ,VFIO_PCI_IO_WIDTH_2 =2 ,
Signature · 1 line
2.43.0
RFC PATCH v2 8/13 vfio/pci: Provide guest_memfd backing for PCI BARs
In reply to Aneesh Kumar K.V (Arm)Allow an ordinary VFIO PCI device fd to supply BAR memory to guest_memfd. Validate eligible BAR ranges and provide their PFNs for shared guest mappings. Keep the VFIO file and its IOMMUFD vDEVICE alive while the provider is attached.
Reject attachment while VFIO BAR mappings or dma-buf exports exist.
Hold the vDEVICE MMIO mutex across conversion and attribute updates. Before private conversion, take the VFIO memory lock for writing to wait for ongoing BAR reads and writes to finish. Host access checks try inode invalidate lock without waiting, avoiding deadlock with conversion, which acquires that lock first.
--- Documentation/virt/kvm/api.rst | 6 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 3 + drivers/vfio/pci/vfio_pci_gmem.c | 325 +++++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_gmem.h | 3 + include/linux/vfio_pci_core.h | 1 + 6 files changed, 339 insertions(+) create mode 100644 drivers/vfio/pci/vfio_pci_gmem.c
Documentation/virt/kvm/api.rst +6 -0
@@ -6533,6 +6533,12 @@ With USE_RESOURCE, the resource mapping superblock supplies provider operations. Callbacks identify folio or PFN backing. PFN providers require INIT_SHARED and a VM supporting protected resource mappings; mmap is disabled. +For a VFIO PCI device resource, creation fails with EBUSY if any VFIO BAR +VMA or dma-buf export exists. This includes unfaulted mappings and mappings +inherited by another process. Userspace must remove all such mappings before +creating the device guest_memfd. While the provider is attached, mmap() on +any VFIO fd for that device fails with EBUSY. + When the KVM MMU performs a PFN lookup to service a guest fault, the fault will always be consumed from guest_memfd, regardless of whether it is a shared or a private fault (unless in-place conversion is disabled and the backing
drivers/vfio/pci/Makefile +1 -0
@@ -4,6 +4,7 @@ vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_con vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) += vfio_pci_zdev.o vfio-pci-core-$(CONFIG_VFIO_PCI_DMABUF) += vfio_pci_dmabuf.o vfio-pci-core-$(CONFIG_VFIO_PCI_GMEM) += vfio_pci_gmem_access.o +vfio-pci-core-$(CONFIG_VFIO_PCI_GMEM) += vfio_pci_gmem.o obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o
drivers/vfio/pci/vfio_pci.c +3 -0
@@ -147,6 +147,9 @@ static int vfio_pci_init_dev(struct vfio_device *core_vdev) }static const struct vfio_device_ops vfio_pci_ops = { +#if IS_ENABLED(CONFIG_VFIO_PCI_GMEM) + .gmem_provider_ops = &vfio_pci_gmem_provider_ops, +#endif .name ="vfio-pci" , .init = vfio_pci_init_dev, .release = vfio_pci_core_release_dev,
drivers/vfio/pci/vfio_pci_gmem.c new file +325 -0
325 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_gmem.h +3 -0
@@ -9,7 +9,10 @@ struct vfio_pci_core_device;struct vfio_pci_gmem {struct guest_memfd *gmem; +struct vfio_pci_core_device *vdev;struct iommufd_vdevice *ivdev; +struct file *resource; +unsigned long owner; };#endif /* VFIO_PCI_GMEM_H */
include/linux/vfio_pci_core.h +1 -0
@@ -156,6 +156,7 @@ struct vfio_pci_core_device { };#if IS_ENABLED (CONFIG_VFIO_PCI_GMEM ) +extern const struct guest_memfd_provider_operations vfio_pci_gmem_provider_ops;void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev);bool vfio_pci_gmem_access_allowed (struct vfio_pci_core_device *vdev,u64 offset,u64 size);
Signature · 1 line
2.43.0
RFC PATCH v2 9/13 KVM: guest_memfd: Add a provider detach callback
In reply to Aneesh Kumar K.V (Arm)Add detach() to the guest_memfd provider operations. Providers must disable new bindings and private requests and stop and drain callbacks that access the VM before returning.
This separates quiescing VM access from release(), which may run after the guest_memfd file and its VM reference have been released.
--- include/linux/guest_memfd.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/guest_memfd.h +3 -0
@@ -47,6 +47,8 @@ struct guest_memfd {* @get_pfn: Resolve a shared resource offset without taking a folio reference. * @prepare_conversion: Prepare protected PFN conversion; NULL request shares. * @finish_conversion: Finish conversion after attribute publication. +* @detach: Disable new bindings and private requests before final cleanup. +* Stop and drain callbacks that access the VM before returning. * * Provider operations supply exactly one of alloc_folio() and get_pfn(). * PFN providers start shared and require the bind and conversion callbacks
@@ -65,6 +67,7 @@ struct guest_memfd_provider_operations { const struct guest_memfd_device_request *req);void (*finish_conversion)(void *provider,const struct guest_memfd_device_request *req); + void (*detach)(void *provider); };#endif /* _LINUX_GUEST_MEMFD_H */
Signature · 1 line
2.43.0
RFC PATCH v2 10/13 vfio/pci: Detach guest_memfd access before teardown
In reply to Aneesh Kumar K.V (Arm)Implement the guest_memfd detach callback and forward it through the VFIO filesystem provider. Require the backing driver to supply the callback.
Mark the provider detached under the vDEVICE MMIO mutex and VFIO memory lock, draining in-flight access and invalidation callbacks. Reject further host accesses, PFN lookups, bindings and private conversions while allowing shared cleanup.
--- drivers/vfio/pci/vfio_pci_gmem.c | 25 +++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_gmem.h | 6 ++++++ drivers/vfio/pci/vfio_pci_gmem_access.c | 7 +++++-- drivers/vfio/vfio_main.c | 10 ++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-)
drivers/vfio/pci/vfio_pci_gmem.c +25 -0
@@ -176,6 +176,8 @@ static int vfio_gmem_bind(void *data, u64 offset, u64 size,int ret;guard (iommufd_vdevice_mmio)(ctx->ivdev); +if (ctx->callbacks_detached) +return -ENODEV ; ret =vfio_gmem_resolve_bar_range (ctx, offset, size, &bar, &off, &pa);if (ret)return ret;
@@ -219,6 +221,8 @@ static int vfio_gmem_get_pfn(void *data, u64 offset, unsigned long *pfn)int ret;guard (rwsem_read)(&vdev->memory_lock); +if (ctx->callbacks_detached) +return -ENODEV ;if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled (vdev))return -EAGAIN ;
@@ -248,6 +252,10 @@ static int vfio_gmem_prepare_conversion(void *context,struct vfio_pci_gmem *ctx = context;iommufd_vdevice_mmio_lock (ctx->ivdev); +if (req && ctx->callbacks_detached) { +iommufd_vdevice_mmio_unlock (ctx->ivdev); +return -ENODEV ; + }if (req && req->vdev_id != ctx->ivdev->virt_id) {iommufd_vdevice_mmio_unlock (ctx->ivdev);return -EPERM ;
@@ -287,6 +295,22 @@ static void vfio_gmem_finish_conversion(void *context,iommufd_vdevice_mmio_unlock (ctx->ivdev); } +/** +* vfio_gmem_detach() - stop invalidation callbacks before core teardown +* @data: attached provider context +* +* Mark the provider detached under the VFIO memory lock. VFIO userspace +* mappings remain excluded until release clears the provider association. +*/ +static void vfio_gmem_detach (void *data) +{ +struct vfio_pci_gmem *ctx = data; + +guard (iommufd_vdevice_mmio)(ctx->ivdev); +scoped_guard (rwsem_write, &ctx->vdev->memory_lock) + ctx->callbacks_detached = true; +} +/** * vfio_gmem_release() - release a provider after successful core cleanup * @data: provider context to release
@@ -318,6 +342,7 @@ const struct guest_memfd_provider_operations vfio_pci_gmem_provider_ops = { .get_pfn = vfio_gmem_get_pfn, .prepare_conversion = vfio_gmem_prepare_conversion, .finish_conversion = vfio_gmem_finish_conversion, + .detach = vfio_gmem_detach, .release = vfio_gmem_release, };EXPORT_SYMBOL_GPL (vfio_pci_gmem_provider_ops);
drivers/vfio/pci/vfio_pci_gmem.h +6 -0
@@ -13,6 +13,12 @@ struct vfio_pci_gmem {struct iommufd_vdevice *ivdev;struct file *resource;unsigned long owner; +/* +* Disables callbacks and new bind/private requests. Set once with +* both the vDEVICE MMIO and VFIO memory locks held; readers hold +* either lock. Shared cleanup remains allowed after detachment. +*/ + bool callbacks_detached; };#endif /* VFIO_PCI_GMEM_H */
drivers/vfio/pci/vfio_pci_gmem_access.c +5 -2
@@ -14,7 +14,7 @@* Called by vfio_pci_zap_bars() after it removes host BAR mappings. Notify * guest_memfd synchronously so KVM removes the corresponding shared guest * mappings. This helper does not remove host mappings or change attributes. -* Skip notification if no provider is attached. +* Skip notification if no provider is attached or its callbacks are detached. * */ void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev)
@@ -22,7 +22,7 @@ void vfio_pci_gmem_invalidate(struct vfio_pci_core_device *vdev)struct vfio_pci_gmem *ctx = vdev->gmem;lockdep_assert_held_write (&vdev->memory_lock); -if (ctx) +if (ctx && !ctx->callbacks_detached) ctx->gmem->invalidate (ctx->gmem); }
@@ -35,6 +35,7 @@ void vfio_pci_gmem_invalidate(struct vfio_pci_core_device *vdev)* Consult completed guest_memfd attributes for the requested interval. * Private mappings in another interval do not block this access. Try the * inode lock instead of waiting in the reverse order from conversion. +* Detachment excludes access during teardown. * * Return: true when the requested interval is accessible. */
@@ -51,6 +52,8 @@ bool vfio_pci_gmem_access_allowed(struct vfio_pci_core_device *vdev,if (!ctx->ivdev)return false; +if (ctx->callbacks_detached) +return false;return ctx->gmem->host_accessible (ctx->gmem, offset, size); }
drivers/vfio/vfio_main.c +8 -2
@@ -274,9 +274,9 @@ static void *vfio_gmem_provider_attach(struct file *file,if (!ops || !ops->attach || !ops->release)return ERR_PTR (-EOPNOTSUPP ); -/* VFIO requires PFN lookup, binding and conversion. */ +/* VFIO requires PFN lookup, binding, conversion and detachment. */ if (!ops->get_pfn || !ops->bind || !ops->prepare_conversion || - !ops->finish_conversion) + !ops->finish_conversion || !ops->detach)return ERR_PTR (-EOPNOTSUPP );/* VFIO provides PFNs, not folios. */
@@ -340,7 +340,12 @@ static void vfio_gmem_provider_finish_conversion( provider->ops->finish_conversion (provider->data, req); } +static void vfio_gmem_provider_detach (void *data) +{ +struct vfio_gmem_provider *provider = data; + provider->ops->detach (provider->data); +}static const struct guest_memfd_provider_operations vfio_gmem_provider_ops = { .attach = vfio_gmem_provider_attach,
@@ -349,6 +354,7 @@ static const struct guest_memfd_provider_operations vfio_gmem_provider_ops = { .get_pfn = vfio_gmem_provider_get_pfn, .prepare_conversion = vfio_gmem_provider_prepare_conversion, .finish_conversion = vfio_gmem_provider_finish_conversion, + .detach = vfio_gmem_provider_detach, };static const struct super_operations vfio_fs_super_ops = {
Signature · 1 line
2.43.0
RFC PATCH v2 11/13 KVM: guest_memfd: Remove device mappings on final close
In reply to Aneesh Kumar K.V (Arm)On final guest_memfd close, detach the device provider before removing private device mappings. Keep memslot bindings available so cleanup can resolve device ranges to guest addresses.
Hold the inode invalidate lock across detach and conversion cleanup, and clear the core file pointer before releasing the file-owned VM reference. Require PFN providers to supply detach() and reject it for folio providers.
--- Documentation/virt/kvm/api.rst | 3 ++- virt/kvm/guest_memfd.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-)
Documentation/virt/kvm/api.rst +2 -1
@@ -6537,7 +6537,8 @@ For a VFIO PCI device resource, creation fails with EBUSY if any VFIO BAR VMA or dma-buf export exists. This includes unfaulted mappings and mappings inherited by another process. Userspace must remove all such mappings before creating the device guest_memfd. While the provider is attached, mmap() on -any VFIO fd for that device fails with EBUSY. +any VFIO fd for that device fails with EBUSY. Closing the guest_memfd releases +the provider once its last reference is dropped and cleanup completes. When the KVM MMU performs a PFN lookup to service a guest fault, the fault will always be consumed from guest_memfd, regardless of whether it is a shared or a
virt/kvm/guest_memfd.c +24 -3
@@ -340,6 +340,7 @@ static void kvm_gmem_invalidate_end(struct inode *inode, pgoff_t start,static int kvm_gmem_device_convert (struct inode *inode,pgoff_t start,pgoff_t nr_pages,const struct guest_memfd_device_request *req,const struct kvm_memory_slot *slot); +static void kvm_gmem_device_close (struct inode *inode);static long kvm_gmem_punch_hole (struct inode *inode,loff_t offset,loff_t len) {
@@ -462,6 +463,9 @@ static int kvm_gmem_release(struct inode *inode, struct file *file)filemap_invalidate_lock (inode->i_mapping); +if (gmem_provider_has_pfns (GMEM_I (inode))) +kvm_gmem_device_close (inode); +xa_for_each (&f->bindings, index, slot)WRITE_ONCE (slot->gmem.file,NULL );
@@ -1339,6 +1343,23 @@ int kvm_gmem_device_map(struct kvm *kvm, u64 gpa, u64 size, u64 pa, u64 vdev_id) }EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_gmem_device_map); +static void kvm_gmem_device_close (struct inode *inode) +{ +struct gmem_inode *gi =GMEM_I (inode); +int ret; + + gi->provider_ops->detach (gi->provider); + ret = gi->provider_ops->prepare_conversion (gi->provider,NULL ); +if (!ret) { + ret =kvm_gmem_device_make_shared (inode,0 , +i_size_read (inode) >>PAGE_SHIFT ); +if (!ret) +WRITE_ONCE (gi->device_has_private, false); + gi->provider_ops->finish_conversion (gi->provider,NULL ); + } +WRITE_ONCE (gi->device.gmem_file,NULL ); +} +static int kvm_gmem_validate_provider (struct kvm *kvm,struct gmem_inode *gi,const struct guest_memfd_provider_operations *ops)
@@ -1355,14 +1376,14 @@ static int kvm_gmem_validate_provider(struct kvm *kvm,if (!ops->get_pfn) {/* PFN-specific callbacks are invalid for folio providers. */ if (ops->bind || ops->prepare_conversion || - ops->finish_conversion) + ops->finish_conversion || ops->detach)return -EOPNOTSUPP ;return 0 ; } -/* PFN providers must support binding and conversion. */ +/* PFN providers must support binding, conversion and detachment. */ if (!ops->bind || !ops->prepare_conversion || - !ops->finish_conversion) + !ops->finish_conversion || !ops->detach)return -EOPNOTSUPP ;/* PFN providers do not manage folios. */
Signature · 1 line
2.43.0
RFC PATCH v2 12/13 KVM: Invalidate guest_memfd mappings before removing memslot bindings
In reply to Aneesh Kumar K.V (Arm)Unmap guest_memfd ranges before deleting the memslot. Remove private device mappings before committing deletion, and invalidate remaining mappings while holding the inode invalidate lock.
--- virt/kvm/guest_memfd.c | 70 ++++++++++++++++++++++++++++++++++++++++-- virt/kvm/guest_memfd.h | 6 ++++ virt/kvm/kvm_main.c | 4 +++ 3 files changed, 77 insertions(+), 3 deletions(-)
virt/kvm/guest_memfd.c +67 -3
@@ -1307,6 +1307,58 @@ static int kvm_gmem_device_convert(struct inode *inode, pgoff_t start,return ret; } +/** +* kvm_gmem_prepare_memslot_delete() - remove guest_memfd mappings before deletion +* @slot: original guest_memfd memslot being removed +* +* The caller has replaced the active slot with an entry marked +* KVM_MEMSLOT_INVALID, preventing new guest faults from creating mappings. +* Remove private device mappings, then invalidate the remaining guest_memfd +* mappings, including shared mappings. +* +* Perform this cleanup while the guest_memfd binding still provides the +* file-offset-to-GPA translation needed to locate the guest mappings. +* The device provider remains attached until guest_memfd close. +* +* Caller holds slots_lock. +* Return: 0 on success or a negative error code. +*/ +int kvm_gmem_prepare_memslot_delete (const struct kvm_memory_slot *slot) +{ +struct file *file =READ_ONCE (slot->gmem.file); +pgoff_t start = slot->gmem.pgoff; +pgoff_t end = start + slot->npages; +struct inode *inode; +int ret; + +/* slots_lock keeps the bindings alive until file release can finish. */ + file =get_file_active (&file); +if (!file) { +/* Let .release drain the bindings before deletion can discard them. */ +if (READ_ONCE (slot->gmem.file)) +return -EBUSY ; +return 0 ; + } + + inode =file_inode (file); +if (gmem_provider_has_pfns (GMEM_I (inode))) { + ret =kvm_gmem_device_convert (inode, start, slot->npages,NULL ,NULL ); +if (ret) + goto out; + } + +filemap_invalidate_lock (inode->i_mapping); +__kvm_gmem_invalidate_start (file->private_data, start, end, +kvm_gmem_get_all_gfns_filter (inode)); +__kvm_gmem_invalidate_end (file->private_data, start, end); +filemap_invalidate_unlock (inode->i_mapping); + ret =0 ; +out: +fput (file); +return ret; +} + +int kvm_gmem_device_map (struct kvm *kvm,u64 gpa,u64 size,u64 pa,u64 vdev_id) {struct guest_memfd_device_request req = { gpa, pa, vdev_id };
@@ -1608,11 +1660,19 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,return r; } -static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct gmem_file *f) +static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct file *file) { +struct gmem_file *f = file->private_data;unsigned long start = slot->gmem.pgoff;unsigned long end = start + slot->npages; +/* +* Unmap this slot's guest mappings before removing it from f->bindings. +* The invalidation helper walks f->bindings to find the slots to unmap. +*/ +__kvm_gmem_invalidate_start (f, start, end, +kvm_gmem_get_all_gfns_filter (file_inode (file))); +__kvm_gmem_invalidate_end (f, start, end);xa_store_range (&f->bindings, start, end -1 ,NULL ,GFP_KERNEL );/*
@@ -1644,12 +1704,16 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)* until the caller drops slots_lock. */ if (!file) { -__kvm_gmem_unbind (slot, slot->gmem.file->private_data); +struct file *closing_file = slot->gmem.file; + +filemap_invalidate_lock (closing_file->f_mapping); +__kvm_gmem_unbind (slot, closing_file); +filemap_invalidate_unlock (closing_file->f_mapping);return ; }filemap_invalidate_lock (file->f_mapping); -__kvm_gmem_unbind (slot, file->private_data); +__kvm_gmem_unbind (slot, file);filemap_invalidate_unlock (file->f_mapping); }
virt/kvm/guest_memfd.h +6 -0
@@ -11,6 +11,7 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args);int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned int fd,uoff_t offset);void kvm_gmem_unbind (struct kvm_memory_slot *slot); +int kvm_gmem_prepare_memslot_delete (const struct kvm_memory_slot *slot);#else static inline int kvm_gmem_init (struct module *module) {
@@ -29,6 +30,11 @@ static inline void kvm_gmem_unbind(struct kvm_memory_slot *slot) {WARN_ON_ONCE (1 ); } + +static inline int kvm_gmem_prepare_memslot_delete (const struct kvm_memory_slot *slot) +{ +return 0 ; +}#endif /* CONFIG_KVM_GUEST_MEMFD */ #endif /* __KVM_GUEST_MEMFD_H__ */
virt/kvm/kvm_main.c +4 -0
@@ -1696,6 +1696,10 @@ static int kvm_prepare_memory_region(struct kvm *kvm, } r =kvm_arch_prepare_memory_region (kvm, old, new, change); +if (!r && change ==KVM_MR_DELETE ) { +if (old->flags &KVM_MEM_GUEST_MEMFD ) + r =kvm_gmem_prepare_memslot_delete (old); + }/* Free the bitmap on failure if it was allocated above. */ if (r && new && new->dirty_bitmap && (!old || !old->dirty_bitmap))
Signature · 1 line
2.43.0
RFC PATCH v2 13/13 vfio/pci: Allow VFIO BAR mmap with an attached guest_memfd
In reply to Aneesh Kumar K.V (Arm)Allow existing and new VFIO BAR VMAs when the attached guest_memfd was created with GUEST_MEMFD_FLAG_MMAP. Keep BAR VMA exclusion when the flag is absent. CPU mappings use the VFIO fd; mmap on the PFN-backed guest_memfd fd remains disabled.
Invalidate existing BAR mappings, including huge mappings, during attachment. Subsequent faults use base-page mappings so each page's shared-range attributes are checked separately. Hold memory_lock from the attribute check through PTE insertion.
Invalidate BAR mappings before private conversion and on provider detach. Taking memory_lock for writing waits for active faults, BAR read/write and ioeventfd accesses before invalidation.
--- Documentation/virt/kvm/api.rst | 29 +++++++++++----- drivers/vfio/pci/vfio_pci_core.c | 16 ++++++--- drivers/vfio/pci/vfio_pci_gmem.c | 46 ++++++++++++++++--------- drivers/vfio/pci/vfio_pci_gmem.h | 2 ++ drivers/vfio/pci/vfio_pci_gmem_access.c | 31 +++++++++++++++++ include/linux/vfio_pci_core.h | 5 +++ 6 files changed, 99 insertions(+), 30 deletions(-)
Documentation/virt/kvm/api.rst +20 -9
@@ -6514,8 +6514,9 @@ The capability KVM_CAP_GUEST_MEMFD_FLAGS enumerates the `flags` that can be specified via KVM_CREATE_GUEST_MEMFD. Currently defined flags: ============================= ================================================ - GUEST_MEMFD_FLAG_MMAP Enable using mmap() on the guest_memfd file - descriptor. + GUEST_MEMFD_FLAG_MMAP Enable userspace mappings. For VFIO PCI + resources, mappings use the resource fd; + otherwise they use the guest_memfd fd. GUEST_MEMFD_FLAG_INIT_SHARED Make all memory in the file shared during KVM_CREATE_GUEST_MEMFD (memory files created without INIT_SHARED will be marked private).
@@ -6531,13 +6532,23 @@ specified via KVM_CREATE_GUEST_MEMFD. Currently defined flags: With USE_RESOURCE, the resource mapping superblock supplies provider operations. Callbacks identify folio or PFN backing. PFN providers require -INIT_SHARED and a VM supporting protected resource mappings; mmap is disabled. - -For a VFIO PCI device resource, creation fails with EBUSY if any VFIO BAR -VMA or dma-buf export exists. This includes unfaulted mappings and mappings -inherited by another process. Userspace must remove all such mappings before -creating the device guest_memfd. While the provider is attached, mmap() on -any VFIO fd for that device fails with EBUSY. Closing the guest_memfd releases +INIT_SHARED and a VM supporting protected resource mappings. Mapping a +PFN-backed guest_memfd fd is not supported. + +For a VFIO PCI device resource, creation fails with EBUSY if another provider +or any dma-buf export exists. Without GUEST_MEMFD_FLAG_MMAP, creation also fails +with EBUSY if any VFIO BAR VMA exists, including unfaulted or inherited VMAs. +While attached without MMAP, mmap() on any VFIO fd for the device fails with +EBUSY. With MMAP, existing BAR VMAs and new VFIO mmap() calls are allowed. +Attachment revokes existing BAR translations, including huge mappings. While +attached, faults use base-page mappings and check the guest_memfd attributes +for the faulting page. + +Conversion to private memory revokes VFIO BAR translations before delegation. +Access to a private page raises SIGBUS; conversion back to shared permits new +faults on the existing VMA. Reset, power and memory-decode changes also revoke +BAR translations. Detachment revokes translations and blocks faults until +provider release clears the association. Closing the guest_memfd releases the provider once its last reference is dropped and cleanup completes. When the KVM MMU performs a PFN lookup to service a guest fault, the fault will
drivers/vfio/pci/vfio_pci_core.c +12 -4
@@ -1713,9 +1713,7 @@ static void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev)loff_t end =VFIO_PCI_INDEX_TO_OFFSET (VFIO_PCI_ROM_REGION_INDEX );loff_t len = end - start; -/* An attached provider excludes every VFIO BAR VMA. */ -if (!vdev->gmem) -unmap_mapping_range (core_vdev->inode->i_mapping, start, len, true); +unmap_mapping_range (core_vdev->inode->i_mapping, start, len, true);vfio_pci_gmem_invalidate (vdev); }
@@ -1766,6 +1764,15 @@ vm_fault_t vfio_pci_vmf_insert_pfn(struct vfio_pci_core_device *vdev,if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled (vdev))return VM_FAULT_SIGBUS ; +/* Check each page separately while guest_memfd controls BAR access. */ +if (order && vdev->gmem) +return VM_FAULT_FALLBACK ; + +/* memory_lock keeps revocation from racing admission and PTE insertion. */ +if (!vfio_pci_gmem_access_allowed (vdev, + (u64 )vmf->pgoff <<PAGE_SHIFT ,PAGE_SIZE )) +return VM_FAULT_SIGBUS ; +if (!order)return vmf_insert_pfn (vmf->vma, vmf->address, pfn);
@@ -1842,7 +1849,8 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vmavoid __iomem *bar_io;guard (rwsem_read)(&vdev->memory_lock); -if (vdev->gmem) + +if (!vfio_pci_gmem_mmap_allowed (vdev))return -EBUSY ; index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -PAGE_SHIFT );
drivers/vfio/pci/vfio_pci_gmem.c +29 -17
98 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_gmem.h +2 -0
@@ -21,4 +21,6 @@ struct vfio_pci_gmem { bool callbacks_detached; }; +void vfio_gmem_invalidate_mmio (struct vfio_pci_gmem *ctx); +#endif /* VFIO_PCI_GMEM_H */
drivers/vfio/pci/vfio_pci_gmem_access.c +31 -0
@@ -2,6 +2,7 @@/* Shared/private access and guest revocation are controlled by guest_memfd. */ #include <linux/guest_memfd.h> #include <linux/iommufd.h> +#include <linux/kvm.h> #include <linux/vfio_pci_core.h> #include "vfio_pci_gmem.h"
@@ -26,6 +27,36 @@ void vfio_pci_gmem_invalidate(struct vfio_pci_core_device *vdev) ctx->gmem->invalidate (ctx->gmem); } +/** +* vfio_gmem_invalidate_mmio() - revoke VFIO and shared guest BAR mappings +* @ctx: attached provider context +* +* Drain VFIO faults and host I/O, then remove existing BAR PTEs before +* delegation or teardown. The BAR zap also invalidates shared guest mappings +* while core callbacks remain attached. During private conversion the inode +* invalidate lock excludes new access through the host_accessible() check. +* +* Caller holds the vDEVICE MMIO mutex, except during attachment before the +* vDEVICE is assigned. No private conversion can start at that point. +*/ +void vfio_gmem_invalidate_mmio (struct vfio_pci_gmem *ctx) +{ +if (ctx->ivdev) +lockdep_assert_held (&ctx->ivdev->mmio_lock); + +vfio_pci_zap_and_down_write_memory_lock (ctx->vdev); +up_write (&ctx->vdev->memory_lock); +} + +/* Serialize the creation flag check with attachment under memory_lock. */ +bool vfio_pci_gmem_mmap_allowed (struct vfio_pci_core_device *vdev) +{ +struct vfio_pci_gmem *ctx = vdev->gmem; + +lockdep_assert_held (&vdev->memory_lock); +return !ctx || (ctx->gmem->flags &GUEST_MEMFD_FLAG_MMAP ); +} +/** * vfio_pci_gmem_access_allowed() - check a host BAR access against its range * @vdev: VFIO PCI device supplying the BAR
include/linux/vfio_pci_core.h +5 -0
@@ -158,12 +158,17 @@ struct vfio_pci_core_device {#if IS_ENABLED (CONFIG_VFIO_PCI_GMEM )extern const struct guest_memfd_provider_operations vfio_pci_gmem_provider_ops;void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev); +bool vfio_pci_gmem_mmap_allowed (struct vfio_pci_core_device *vdev);bool vfio_pci_gmem_access_allowed (struct vfio_pci_core_device *vdev,u64 offset,u64 size);bool vfio_pci_gmem_io_access_allowed (struct vfio_pci_core_device *vdev,void __iomem *io,size_t size);#else static inline void vfio_pci_gmem_invalidate (struct vfio_pci_core_device *vdev) {} +static inline bool vfio_pci_gmem_mmap_allowed (struct vfio_pci_core_device *vdev) +{ +return true; +}static inline bool vfio_pci_gmem_access_allowed (struct vfio_pci_core_device *vdev,u64 offset,u64 size) {
Signature · 1 line
2.43.0
Quoted 5 lines · Aneesh Kumar K.V (Arm)
This series adds a
guest_memfddevice-resource framework for exposing PCI BAR memory to guests. The intended use is confidential device assignment, where KVM needs to coordinate private device mappings with shared access through VFIO. The Arm CCA backend is provided separately; these patches contain theguest_memfd, VFIO and IOMMUFD interfaces it uses.
Thank you for this revision to guest_memfd + VFIO support!
Quoted 12 lines
The
guest_memfdframework and Arm CCA backend are available together at:https://git.gitlab.arm.com/linux-arm/linux-cca.git cca/topics/cca-da-gmem-backend
Userspace creates a device-backed
guest_memfdusing the ordinary VFIO device fd asresource_fd, withGUEST_MEMFD_FLAG_USE_RESOURCEandGUEST_MEMFD_FLAG_INIT_SHARED.
The resource mapping superblock selects its
provider;get_pfnidentifies PFN-backed memory. Eligible BAR intervals are registered asguest_memfdmemslots.
Quoted 2 lines
File offsets use the existing VFIO
region-offset namespace,
Yes, this is great, thank you. I think we should have guest_memfd and VFIO share the same offset to PFN mapping.
Quoted 2 lines
allowing one
guest_memfdto cover multiple BAR
intervals.
Yes, this is an advantage I see of using guest_memfd to wrap VFIO too, instead of requiring separate memslots for each shared/private range.
Quoted 9 lines
The device-backed
guest_memfdfd rejects mmap and fallocate; shared guest faults obtain bare BAR PFNs from the provider instead of resolving the memslot HVA or allocating folios.IOMMUFD resolves and pins the device's existing vDEVICE after its backend validates the VM association. Its MMIO mutex coordinates conversion and device state changes. VFIO supplies BAR PFNs, validates eligible ranges and excludes dma-buf exports while a
guest_memfdprovider is attached.
Quoted 7 lines
Without
GUEST_MEMFD_FLAG_MMAP, attachment rejects existing VFIO BAR VMAs, and new VFIO mmap calls. With the flag, existing and new BAR VMAs are allowed through the VFIO fd. Attachment invalidates existing BAR mappings, including huge mappings. Subsequent faults use base-page mappings so each page's shared-range attributes are checked separately. Mapping the PFN-backedguest_memfdfd remains disabled (We can decide on this later).
I saw your other email regarding how to handle read/write/faulting (mmap). I still think we should have all these be blocked on the wrapped VFIO fd and have it handled through guest_memfd.
The gmem_device_host_accessible() function in this series has a comment that explains this, which is that the shared/private attribute is guarded by filemap_invalidate_lock() in guest_memfd, and so having providers call back into guest_memfd is probably going to cause locking issues. That's also what I figured when I was trying to implement the integration with the sample memory provider in [1].
[1] https://lore.kernel.org/all/20261022-gmem-alternative-providers-v2-45-5dd1dc6c660a@google.com/
Quoted 3 lines
VFIO BAR read/write, ioeventfd and userspace mapping faults check the requested range's
guest_memfdattributes.
Thanks for calling out ioeventfd, this is one other backdoor to possibly access guest-private memory. To avoid calling back into guest_memfd to check shared/private status, I have these suggestions:
1. Treat the ioeventfd setup as yet another "mapping" alongside stage 2, host userspace, IOMMU page tables. For IOMMU page tables, guest_memfd will have to do mappings eagerly on conversion to shared since the IOMMU cannot handle faults. We could also "zap" the eventfd-to-VFIO connection on conversion to private and "map" the connection back on conversion to shared.
2. Take a shortcut for now and say that if the VFIO is wrapped by guest_memfd, always block ioeventfd setup.
Quoted 7 lines
This series depends on:
* Ackerley Tng's "Allowguest_memfdto be created using a resource (pool) fd" RFC, which provides the tmpfs resource-provider API:
https://lore.kernel.org/all/[email protected]/
* The IOMMUFD/TSM series, which provides the vIOMMU and vDEVICE interfaces:
https://lore.kernel.org/all/[email protected]/
For easier testing, is there a VFIO sample we could use? How about mdpy? Is mdpy representative enough for selftests?
Quoted 3 lines
[...snip...]
Quoted 55 lines · Ackerley Tng
Quoted 5 lines · Aneesh Kumar K.V (Arm)
This series adds a
guest_memfddevice-resource framework for exposing PCI BAR memory to guests. The intended use is confidential device assignment, where KVM needs to coordinate private device mappings with shared access through VFIO. The Arm CCA backend is provided separately; these patches contain theguest_memfd, VFIO and IOMMUFD interfaces it uses.Thank you for this revision to
guest_memfd+ VFIO support!Quoted 12 lines
The
guest_memfdframework and Arm CCA backend are available together at:https://git.gitlab.arm.com/linux-arm/linux-cca.git cca/topics/cca-da-gmem-backend
Userspace creates a device-backed
guest_memfdusing the ordinary VFIO device fd asresource_fd, withGUEST_MEMFD_FLAG_USE_RESOURCEandGUEST_MEMFD_FLAG_INIT_SHARED.
The resource mapping superblock selects its
provider;get_pfnidentifies PFN-backed memory. Eligible BAR intervals are registered asguest_memfdmemslots.Quoted 2 lines
File offsets use the existing VFIO
region-offset namespace,Yes, this is great, thank you. I think we should have
guest_memfdand VFIO share the same offset to PFN mapping.Quoted 2 lines
allowing one
guest_memfdto cover multiple BAR
intervals.Yes, this is an advantage I see of using
guest_memfdto wrap VFIO too, instead of requiring separate memslots for each shared/private range.Quoted 9 lines
The device-backed
guest_memfdfd rejects mmap and fallocate; shared guest faults obtain bare BAR PFNs from the provider instead of resolving the memslot HVA or allocating folios.IOMMUFD resolves and pins the device's existing vDEVICE after its backend validates the VM association. Its MMIO mutex coordinates conversion and device state changes. VFIO supplies BAR PFNs, validates eligible ranges and excludes dma-buf exports while a
guest_memfdprovider is attached.Quoted 7 lines
Without
GUEST_MEMFD_FLAG_MMAP, attachment rejects existing VFIO BAR VMAs, and new VFIO mmap calls. With the flag, existing and new BAR VMAs are allowed through the VFIO fd. Attachment invalidates existing BAR mappings, including huge mappings. Subsequent faults use base-page mappings so each page's shared-range attributes are checked separately. Mapping the PFN-backedguest_memfdfd remains disabled (We can decide on this later).I saw your other email regarding how to handle read/write/faulting (mmap). I still think we should have all these be blocked on the wrapped VFIO fd and have it handled through
guest_memfd.
Quoted 9 lines
The
gmem_device_host_accessible()function in this series has a comment that explains this, which is that the shared/private attribute is guarded byfilemap_invalidate_lock()inguest_memfd, and so having providers call back intoguest_memfdis probably going to cause locking issues. That's also what I figured when I was trying to implement the integration with the sample memory provider in [1].[1] https://lore.kernel.org/all/20261022-gmem-alternative-providers-v2-45-5dd1dc6c660a@google.com/
This series uses a trylock to avoid that deadlock.
static bool gmem_device_host_accessible(struct guest_memfd *gdev,
u64 offset, u64 size)
{
...
/*
* Keep guest_memfd attributes stable against conversion while checking
* host access. This check only reads attributes, so a shared lock lets
* other access checks run concurrently.
*
* VFIO callers hold memory_lock, but conversion takes the invalidate
* lock exclusively before taking memory_lock for writing.
* Waiting here could deadlock with conversion. Try the shared lock and
* deny access if it cannot be acquired.
*/
if (!filemap_invalidate_trylock_shared(inode->i_mapping))
return false;
...
}
Isn't it much easier to have the provider gate PFN access using the callback provided by guest_memfd when sharing the PFN, rather than supporting every ioctl exposed by the provider fd through guest_memfd?
We should probably also get feedback from VFIO and VMM developers on this. I wonder whether they would be comfortable switching to guest_memfd as suggested here.
Quoted 9 lines
Quoted 4 lines
VFIO BAR read/write, ioeventfd and userspace mapping faults check the requested range's
guest_memfdattributes.Thanks for calling out ioeventfd, this is one other backdoor to possibly access guest-private memory. To avoid calling back into
guest_memfdto check shared/private status, I have these suggestions:
Quoted 7 lines
1. Treat the ioeventfd setup as yet another "mapping" alongside stage 2, host userspace, IOMMU page tables. For IOMMU page tables,
guest_memfdwill have to do mappings eagerly on conversion to shared since the IOMMU cannot handle faults. We could also "zap" the eventfd-to-VFIO connection on conversion to private and "map" the connection back on conversion to shared.
I am not sure how scalable that is, since each new provider would require another set of ioctls. Also requiring the VMM to use guest_memfd for PCI BAR access in CoCo configurations and the VFIO fd in non-CoCo configurations adds unnecessary complexity on the VMM side.
Quoted 3 lines
2. Take a shortcut for now and say that if the VFIO is wrapped by
guest_memfd, always block ioeventfd setup.
I am not sure that would work, because every CoCo configuration has some BAR regions, such as the MSI-X table and PBA, that are emulated by the VMM.
Quoted 9 lines
Quoted 8 lines
This series depends on:
* Ackerley Tng's "Allowguest_memfdto be created using a resource (pool) fd" RFC, which provides the tmpfs resource-provider API:
https://lore.kernel.org/all/[email protected]/
* The IOMMUFD/TSM series, which provides the vIOMMU and vDEVICE interfaces:
https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
For easier testing, is there a VFIO sample we could use? How about mdpy? Is mdpy representative enough for selftests?
All my tests use the full CoCo device-assignment flow with kvmtool.
-aneesh