summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2025-05-08 12:09:22 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2025-05-08 12:09:22 -0700
commitacaa3e726f4a29f32bca5146828565db56bc396f (patch)
tree50084e7c68e7393011f1d54fc27fb1f596d6189d
parent2c89c1b655c0b06823f4ee8b055140d8628fc4da (diff)
parentc1d9dac0db168198b6f63f460665256dedad9b6e (diff)
Merge tag 'vfio-v6.15-rc6' of https://github.com/awilliam/linux-vfio
Pull vfio fix from Alex Williamson: - Fix an issue in vfio-pci huge_fault handling by aligning faults to the order, resulting in deterministic use of huge pages. This avoids a race where simultaneous aligned and unaligned faults to the same PMD can result in a VM_FAULT_OOM and subsequent VM crash. (Alex Williamson) * tag 'vfio-v6.15-rc6' of https://github.com/awilliam/linux-vfio: vfio/pci: Align huge faults to order
-rw-r--r--drivers/vfio/pci/vfio_pci_core.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 35f9046af315..6328c3a05bcd 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1646,14 +1646,14 @@ static vm_fault_t vfio_pci_mmap_huge_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 = vmf->address & ~((PAGE_SIZE << order) - 1);
+ unsigned long pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
+ unsigned long pfn = vma_to_pfn(vma) + pgoff;
vm_fault_t ret = VM_FAULT_SIGBUS;
- pfn = vma_to_pfn(vma) + pgoff;
-
- if (order && (pfn & ((1 << order) - 1) ||
- vmf->address & ((PAGE_SIZE << order) - 1) ||
- vmf->address + (PAGE_SIZE << order) > vma->vm_end)) {
+ if (order && (addr < vma->vm_start ||
+ addr + (PAGE_SIZE << order) > vma->vm_end ||
+ pfn & ((1 << order) - 1))) {
ret = VM_FAULT_FALLBACK;
goto out;
}