vfio/platform: keep logical vm_pgoff in MMIO region mmap
Subsystems (3)
PATCH 1/1 vfio/platform: keep logical vm_pgoff in MMIO region mmap
vfio_platform_mmap_mmio() overwrites vma->vm_pgoff with the physical frame number of the MMIO region and passes it to remap_pfn_range(). The VMA is inserted into the device file's mapping->i_mmap interval tree keyed by vm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode's i_mapping precisely so that unmap_mapping_range() can revoke all mappings associated with a device (see vfio_device_cdev_open()).
With a raw PFN in vm_pgoff the interval tree entry lands in the wrong coordinate space and unmap_mapping_range() cannot find the VMA, leaving stale MMIO mappings behind any revocation attempt. Keep vm_pgoff in the logical VFIO offset space, as vfio-pci does, and pass the physical PFN to remap_pfn_range() explicitly.
---
drivers/vfio/platform/vfio_platform_common.c +2 -3
@@ -559,6 +559,5 @@ vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - vma->vm_pgoff = (region.addr >>PAGE_SHIFT ) + pgoff; - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, +return remap_pfn_range (vma, vma->vm_start, + (region.addr >>PAGE_SHIFT ) + pgoff, req_len, vma->vm_page_prot); }
Eric Auger
maintainerHi Abdifatah,
Quoted 22 lines · Abdifatah Suruur
vfio_platform_mmap_mmio()overwritesvma->vm_pgoffwith the physical frame number of the MMIO region and passes it toremap_pfn_range(). The VMA is inserted into the device file'smapping->i_mmapinterval tree keyed byvm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode'si_mappingprecisely so thatunmap_mapping_range()can revoke all mappings associated with a device (seevfio_device_cdev_open()).With a raw PFN in
vm_pgoffthe interval tree entry lands in the wrong coordinate space andunmap_mapping_range()cannot find the VMA, leaving stale MMIO mappings behind any revocation attempt. Keepvm_pgoffin the logical VFIO offset space, as vfio-pci does, and pass the physical PFN toremap_pfn_range()explicitly.Fixes fad4d5b1f042a ("vfio/platform: support MMAP of MMIO regions")Signed-off-by Abdifatah Suruur <[email protected]>---
drivers/vfio/platform/vfio_platform_common.c line 563
Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c +2
-3@@ -559,6 +559,5 @@ vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - vma->vm_pgoff = (region.addr >>PAGE_SHIFT ) + pgoff; - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, +return remap_pfn_range (vma, vma->vm_start, + (region.addr >>PAGE_SHIFT ) + pgoff, req_len, vma->vm_page_prot); }
While at it, don't you want to fix the same pattern in cdx/main.c, fsl-mc/vfio_fsl_mc.c?
Thanks
Eric
Quoted 2 lines · Eric Auger
While at it, don't you want to fix the same pattern in
cdx/main.c,fsl-mc/vfio_fsl_mc.c?
Yes - sent as separate patches for both drivers:
- [PATCH] vfio/fsl-mc: keep logical vm_pgoff in MMIO region mmap <[email protected]>
- [PATCH] vfio/cdx: keep logical vm_pgoff in MMIO region mmap <[email protected]>
And a follow-up for the cdx mmap path: MAP_PRIVATE mappings go through the COW special case in get_remap_pgoff(), which overwrites vm_pgoff with the raw PFN regardless of the mmap_mmio change, so vfio_cdx_mmap() needs the VM_SHARED guard the other drivers already have:
- [PATCH] vfio/cdx: reject non-shared MMIO mmaps
<[email protected]>
Thanks for the reviews.
Abdifatah
Eric Auger
maintainerQuoted 10 lines · Abdifatah Suruur
Quoted 2 lines · Eric Auger
While at it, don't you want to fix the same pattern in
cdx/main.c,fsl-mc/vfio_fsl_mc.c?Yes - sent as separate patches for both drivers:
- [PATCH] vfio/fsl-mc: keep logical
vm_pgoffin MMIO region mmap <[email protected]>
- [PATCH] vfio/cdx: keep logicalvm_pgoffin MMIO region mmap <[email protected]>
Quoted 7 lines
And a follow-up for the cdx mmap path:
MAP_PRIVATEmappings go through the COW special case inget_remap_pgoff(), which overwritesvm_pgoffwith the raw PFN regardless of themmap_mmiochange, sovfio_cdx_mmap()needs theVM_SHAREDguard the other drivers already have:- [PATCH] vfio/cdx: reject non-shared MMIO mmaps
<[email protected]>
OK thanks!
Eric
Quoted 5 lines
Thanks for the reviews.
Abdifatah
Quoted 22 lines · Abdifatah Suruur
vfio_platform_mmap_mmio()overwritesvma->vm_pgoffwith the physical frame number of the MMIO region and passes it toremap_pfn_range(). The VMA is inserted into the device file'smapping->i_mmapinterval tree keyed byvm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode'si_mappingprecisely so thatunmap_mapping_range()can revoke all mappings associated with a device (seevfio_device_cdev_open()).With a raw PFN in
vm_pgoffthe interval tree entry lands in the wrong coordinate space andunmap_mapping_range()cannot find the VMA, leaving stale MMIO mappings behind any revocation attempt. Keepvm_pgoffin the logical VFIO offset space, as vfio-pci does, and pass the physical PFN toremap_pfn_range()explicitly.Fixes fad4d5b1f042a ("vfio/platform: support MMAP of MMIO regions")Signed-off-by Abdifatah Suruur <[email protected]>---
drivers/vfio/platform/vfio_platform_common.c line 563
Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c +2
-3@@ -559,6 +559,5 @@ vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - vma->vm_pgoff = (region.addr >>PAGE_SHIFT ) + pgoff; - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, +return remap_pfn_range (vma, vma->vm_start, + (region.addr >>PAGE_SHIFT ) + pgoff, req_len, vma->vm_page_prot); }
Eric
Alex Williamson
maintainerQuoted 21 lines · On Thu, 3 Sep 2026 12:29:27 +0300 Abdifatah Suruur <[email protected]> wrote:
vfio_platform_mmap_mmio()overwritesvma->vm_pgoffwith the physical frame number of the MMIO region and passes it toremap_pfn_range(). The VMA is inserted into the device file'smapping->i_mmapinterval tree keyed byvm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode'si_mappingprecisely so thatunmap_mapping_range()can revoke all mappings associated with a device (seevfio_device_cdev_open()).With a raw PFN in
vm_pgoffthe interval tree entry lands in the wrong coordinate space andunmap_mapping_range()cannot find the VMA, leaving stale MMIO mappings behind any revocation attempt. Keepvm_pgoffin the logical VFIO offset space, as vfio-pci does, and pass the physical PFN toremap_pfn_range()explicitly.Fixes fad4d5b1f042a ("vfio/platform: support MMAP of MMIO regions")Signed-off-by Abdifatah Suruur <[email protected]>---
drivers/vfio/platform/vfio_platform_common.c line 563
Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c +2
-3@@ -559,6 +559,5 @@ vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - vma->vm_pgoff = (region.addr >>PAGE_SHIFT ) + pgoff; - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, +return remap_pfn_range (vma, vma->vm_start, + (region.addr >>PAGE_SHIFT ) + pgoff, req_len, vma->vm_page_prot); }
Like the read-only mapping fixes, this is a hygiene issue, none of platform, fsl-mc, or cdx actually make use of unmap_mapping_range() to expose such an issue. That should be noted in the cover letter for proper scoping.
This also applies to the cdx non-shared mmaps.
Also, please just group all 7 patches you have on the list into a single series. They're all hygiene/hardening, they're doing the same thing through different vfio bus drivers, they're much easier for me to track as a series.
The Fixes: tags throughout are also somewhat suspect. It's reasonable hardening to clear VM_MAYWRITE for a !VFIO_REGION_INFO_FLAG_WRITE region, but if there are no !VFIO_REGION_INFO_FLAG_WRITE regions, it's not really fixing anything.
It's more arguable that there's a latent issue here where unmap_mapping_range() would fail, but even if we consider that worth a
Fixes: tag, the attribution is wrong. We didn't introduce that shared namespace until b7c5e64fecfa. TBH, it's not a reachable issue in the codebase, I'd drop it. Thanks,
Alex