Commit a39d3a96 authored by Ankit Agrawal's avatar Ankit Agrawal Committed by Oliver Upton

vfio: Convey kvm that the vfio-pci device is wc safe

The VM_ALLOW_ANY_UNCACHED flag is implemented for ARM64,
allowing KVM stage 2 device mapping attributes to use Normal-NC
rather than DEVICE_nGnRE, which allows guest mappings supporting
write-combining attributes (WC). ARM does not architecturally
guarantee this is safe, and indeed some MMIO regions like the GICv2
VCPU interface can trigger uncontained faults if Normal-NC is used.

To safely use VFIO in KVM the platform must guarantee full safety
in the guest where no action taken against a MMIO mapping can
trigger an uncontained failure. The expectation is that most VFIO PCI
platforms support this for both mapping types, at least in common
flows, based on some expectations of how PCI IP is integrated. So
make vfio-pci set the VM_ALLOW_ANY_UNCACHED flag.
Suggested-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Acked-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarMarc Zyngier <maz@kernel.org>
Signed-off-by: default avatarAnkit Agrawal <ankita@nvidia.com>
Link: https://lore.kernel.org/r/20240224150546.368-5-ankita@nvidia.comSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent 8c47ce3e
...@@ -1862,8 +1862,25 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma ...@@ -1862,8 +1862,25 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
/* /*
* See remap_pfn_range(), called from vfio_pci_fault() but we can't * See remap_pfn_range(), called from vfio_pci_fault() but we can't
* change vm_flags within the fault handler. Set them now. * change vm_flags within the fault handler. Set them now.
*
* VM_ALLOW_ANY_UNCACHED: The VMA flag is implemented for ARM64,
* allowing KVM stage 2 device mapping attributes to use Normal-NC
* rather than DEVICE_nGnRE, which allows guest mappings
* supporting write-combining attributes (WC). ARM does not
* architecturally guarantee this is safe, and indeed some MMIO
* regions like the GICv2 VCPU interface can trigger uncontained
* faults if Normal-NC is used.
*
* To safely use VFIO in KVM the platform must guarantee full
* safety in the guest where no action taken against a MMIO
* mapping can trigger an uncontained failure. The assumption is
* that most VFIO PCI platforms support this for both mapping types,
* at least in common flows, based on some expectations of how
* PCI IP is integrated. Hence VM_ALLOW_ANY_UNCACHED is set in
* the VMA flags.
*/ */
vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED | VM_IO | VM_PFNMAP |
VM_DONTEXPAND | VM_DONTDUMP);
vma->vm_ops = &vfio_pci_mmap_ops; vma->vm_ops = &vfio_pci_mmap_ops;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment