Skip to content

vfio/pci: fix huge_fault write handling and add selftest

Mina Almasry kvm linux-kselftest lkml stable 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 6 repliesIn review
  2. v22 patches 2 repliesSuperseded
  3. v11 patch 1 replySuperseded

Changes in v3 from the cover letter

- Add Patch 2/3 introducing vfio_pci_find_mem_bar() in libvfio to locate
a memory-backed BAR (or range within a BAR) from a table of known
devices (starting with QEMU's pci-testdev 1b36:0005 BAR 2), per David Matlack.
- Update Patch 3/3 (bar_write_fault_after_clear_refs) to require a known memory-backed BAR >= SZ_2M via vfio_pci_find_mem_bar(), zap BAR
mappings via PCI_COMMAND_MEMORY before both sub-tests instead of re-mmapping (addressing both David Matlack's and Sashiko's feedback),
and leave PCI_COMMAND_MEMORY enabled afterward.
- Link to v2: https://lore.kernel.org/all/[email protected]/

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3vfio/pci: pass FAULT_FLAG_WRITE to vmf_insert_pfn_pmd/pud()drivers/vfio/pci/vfio_pci_core.c+4 -20 replies
2/3vfio: selftests: Add vfio_pci_find_mem_bar() helpertools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h tools/testing/selftests/vfio/lib/vfio_pci_device.c+77 -03 replies
3/3vfio: selftests: Test BAR write faults after clear_refstools/testing/selftests/vfio/vfio_pci_device_test.c+65 -03 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchDavid Matlack
1/3
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] vfio/pci: fix huge_fault write handling and add selftest

Fix vfio_pci_vmf_insert_pfn() passing write=false to vmf_insert_pfn_pmd() and vmf_insert_pfn_pud(), which causes an infinite write page-fault loop when vma->vm_page_prot starts read-only (such as after soft-dirty clearing via /proc/<pid>/clear_refs in CRIU or live migration, or on arm64 without hardware DBM), and add a companion VFIO PCI selftest covering both read-then-write upgrade and initial write faults after clear_refs.

Changes in v3:
- Add Patch 2/3 introducing vfio_pci_find_mem_bar() in libvfio to locate
a memory-backed BAR (or range within a BAR) from a table of known
devices (starting with QEMU's pci-testdev 1b36:0005 BAR 2), per David Matlack.
- Update Patch 3/3 (bar_write_fault_after_clear_refs) to require a known memory-backed BAR >= SZ_2M via vfio_pci_find_mem_bar(), zap BAR
mappings via PCI_COMMAND_MEMORY before both sub-tests instead of re-mmapping (addressing both David Matlack's and Sashiko's feedback),
and leave PCI_COMMAND_MEMORY enabled afterward.
- Link to v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Expand Patch 1/2 commit log with practical trigger scenarios (CRIU / clear_refs soft-dirty clearing and arm64 software dirty tracking) for stable backport evaluation, per Alex Williamson.
- Drop the Assisted-by tag from Patch 1/2.
- Add Patch 2/2 selftest in vfio_pci_device_test (bar_write_fault_after_clear_refs), as suggested by Alex Williamson.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Mina Almasry (3):
vfio/pci: pass FAULT_FLAG_WRITE to vmf_insert_pfn_pmd/pud()
vfio: selftests: Add vfio_pci_find_mem_bar() helper
vfio: selftests: Test BAR write faults after clear_refs

 drivers/vfio/pci/vfio_pci_core.c              |  6 +-
 .../lib/include/libvfio/vfio_pci_device.h     | 10 +++
 .../selftests/vfio/lib/vfio_pci_device.c      | 67 +++++++++++++++++++
 .../selftests/vfio/vfio_pci_device_test.c     | 65 ++++++++++++++++++
 4 files changed, 146 insertions(+), 2 deletions(-)

base-commit: 076d7e989cb69f6ded7d60f2a080eb909930061b

Signature · 1 line
2.56.0.385.gac671c819a-goog