Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/2] vfio/pci: Provide kernel-side BAR alignment for huge page mapping
@ 2026-11-24  7:30 Guanghui Feng
  2026-11-24  7:30 ` [PATCH 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops Guanghui Feng
  2026-11-24  7:30 ` [PATCH 2/2] vfio/pci: Align BAR mappings for huge page support Guanghui Feng
  0 siblings, 2 replies; 5+ messages in thread
From: Guanghui Feng @ 2026-11-24  7:30 UTC (permalink / raw)
  To: alex, dakr, xinmengs, fengchengwen, jgg, kevin.tian, mattev,
	alifm, ankita, ritesh.list
  Cc: kvm, linux-kernel

VFIO PCI BAR regions support PMD/PUD huge page mapping via
vfio_pci_mmap_huge_fault() since commit f9e54c3a2f5b ("vfio/pci:
implement huge_fault support").  The huge_fault path requires both the
VA and the PFN to be aligned to the huge page boundary, checked by
is_aligned_for_order().  When alignment fails, huge_fault silently
returns VM_FAULT_FALLBACK and the mapping degrades to 4KB pages.

QEMU already handles this by pre-allocating an aligned VA region and
using MAP_FIXED, see QEMU commits 00b519c0bc ("vfio/helpers: Align
mmaps") and 3863e47828 ("hw/vfio: align mmap to power-of-2 of region
size for hugepfnmap").  Other userspace consumers (DPDK, custom VMMs,
test tools, and QEMU releases predating that change) typically call
mmap(fd, offset) with addr=0, relying on the kernel to select a suitable
VA.  Without kernel-side alignment guidance, these consumers silently
get 4KB mappings for large BARs.

This series adds a .get_unmapped_area callback to the VFIO device
file_operations, modelled after drivers/dax/device.c, that provides
PMD/PUD-aligned VA selection for BAR mappings.  It also sets
VM_HUGEPAGE on BAR VMAs, which keeps the huge mapping available to a
process that called prctl(PR_SET_THP_DISABLE,
PR_THP_DISABLE_EXCEPT_ADVISED).

Note: CONFIG_TRANSPARENT_HUGEPAGE=y is required at compile time for the
huge pfnmap infrastructure.  The runtime THP sysfs policy (enabled=never)
does NOT block VFIO BAR huge pages -- vma_file_bypass_thp_tuneables()
already bypasses it for PFNMAP VMAs with a .huge_fault handler (commit
e384abeb559d).

Performance impact for a 256MB BAR, 4KB pages vs PMD huge pages:
  - Page faults:       65536 -> 128   (512x reduction)
  - Page table memory: ~516KB -> ~4KB (129x reduction)
  - TLB pressure:      65536 entries (exceeds STLB) -> 128 entries (fits)

Patch 1 adds the vfio_device_ops callback infrastructure.
Patch 2 implements the PCI BAR alignment logic and VM_HUGEPAGE.

Compiled with W=1, checkpatch --strict clean (0 errors, 0 warnings).
Each patch compiles independently (bisect-safe).

Guanghui Feng (2):
  vfio: Add get_unmapped_area callback to vfio_device_ops
  vfio/pci: Align BAR mappings for huge page support

 drivers/vfio/pci/vfio_pci.c      |  3 +
 drivers/vfio/pci/vfio_pci_core.c | 95 ++++++++++++++++++++++++++++++++
 drivers/vfio/vfio_main.c         | 34 ++++++++++++
 include/linux/vfio.h             | 12 ++++
 include/linux/vfio_pci_core.h    |  8 +++
 5 files changed, 152 insertions(+)

-- 
2.43.7


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-24  7:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  7:30 [PATCH 0/2] vfio/pci: Provide kernel-side BAR alignment for huge page mapping Guanghui Feng
2026-11-24  7:30 ` [PATCH 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops Guanghui Feng
2026-11-24  7:48   ` sashiko-bot
2026-11-24  7:30 ` [PATCH 2/2] vfio/pci: Align BAR mappings for huge page support Guanghui Feng
2026-11-24  7:52   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox