diff mbox series

[SRU,O,2/3] UBUNTU: SAUCE: Revert "vfio/pci: Insert full vma on mmap'd MMIO fault"

Message ID 20241210152352.877132-3-jacob.martin@canonical.com
State New
Headers show
Series Fix vfio_pci soft lockup on VM start while using PCIe passthrough | expand

Commit Message

Jacob Martin Dec. 10, 2024, 3:23 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2089306

This reverts commit "vfio/pci: Insert full vma on mmap'd MMIO fault".

The original commit changes vfio_pci to pre-fault the entire vma when
handling a fault. For PCIe devices with large BAR regions, this can take
a very long time to complete, causing kernel soft lockup warnings. This
is particularly noticeable when launching a virtual machine with a
passthrough PCIe GPU.

Signed-off-by: Jacob Martin <jacob.martin@canonical.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index ba0ce0075b2f..89ea2181a648 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1662,7 +1662,6 @@  static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
 	struct vm_area_struct *vma = vmf->vma;
 	struct vfio_pci_core_device *vdev = vma->vm_private_data;
 	unsigned long pfn, pgoff = vmf->pgoff - vma->vm_pgoff;
-	unsigned long addr = vma->vm_start;
 	vm_fault_t ret = VM_FAULT_SIGBUS;
 
 	pfn = vma_to_pfn(vma);
@@ -1670,25 +1669,11 @@  static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
 	down_read(&vdev->memory_lock);
 
 	if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled(vdev))
-		goto out_unlock;
+		goto out_disabled;
 
 	ret = vmf_insert_pfn(vma, vmf->address, pfn + pgoff);
-	if (ret & VM_FAULT_ERROR)
-		goto out_unlock;
 
-	/*
-	 * Pre-fault the remainder of the vma, abort further insertions and
-	 * supress error if fault is encountered during pre-fault.
-	 */
-	for (; addr < vma->vm_end; addr += PAGE_SIZE, pfn++) {
-		if (addr == vmf->address)
-			continue;
-
-		if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR)
-			break;
-	}
-
-out_unlock:
+out_disabled:
 	up_read(&vdev->memory_lock);
 
 	return ret;