Skip to content

Commit a39d3a9

Browse files
ankita-nvoupton
authored andcommitted
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: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Ankit Agrawal <ankita@nvidia.com> Link: https://lore.kernel.org/r/20240224150546.368-5-ankita@nvidia.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 8c47ce3 commit a39d3a9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,25 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
18621862
/*
18631863
* See remap_pfn_range(), called from vfio_pci_fault() but we can't
18641864
* change vm_flags within the fault handler. Set them now.
1865+
*
1866+
* VM_ALLOW_ANY_UNCACHED: The VMA flag is implemented for ARM64,
1867+
* allowing KVM stage 2 device mapping attributes to use Normal-NC
1868+
* rather than DEVICE_nGnRE, which allows guest mappings
1869+
* supporting write-combining attributes (WC). ARM does not
1870+
* architecturally guarantee this is safe, and indeed some MMIO
1871+
* regions like the GICv2 VCPU interface can trigger uncontained
1872+
* faults if Normal-NC is used.
1873+
*
1874+
* To safely use VFIO in KVM the platform must guarantee full
1875+
* safety in the guest where no action taken against a MMIO
1876+
* mapping can trigger an uncontained failure. The assumption is
1877+
* that most VFIO PCI platforms support this for both mapping types,
1878+
* at least in common flows, based on some expectations of how
1879+
* PCI IP is integrated. Hence VM_ALLOW_ANY_UNCACHED is set in
1880+
* the VMA flags.
18651881
*/
1866-
vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
1882+
vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED | VM_IO | VM_PFNMAP |
1883+
VM_DONTEXPAND | VM_DONTDUMP);
18671884
vma->vm_ops = &vfio_pci_mmap_ops;
18681885

18691886
return 0;

0 commit comments

Comments
 (0)