Re: [PATCH v3 3/3] vfio: selftests: Test BAR write faults after clear_refs
From: David Matlack
Date: Mon Nov 02 2026 - 19:55:17 EST
On 2026-11-02 11:04 PM, Mina Almasry wrote:
> Add a regression test in vfio_pci_device_test to verify that huge_fault
> on writable MAP_SHARED VFIO PCI BAR mappings handles write faults after
> soft-dirty tracking clears VM_SOFTDIRTY and downgrades vma->vm_page_prot
> to read-only via /proc/self/clear_refs ("4").
>
> Use vfio_pci_find_mem_bar() to locate a memory-backed BAR of at least
> 2 MiB that is safe to read and write, and zap existing BAR mappings via
> PCI_COMMAND_MEMORY before each sub-test to verify both:
>
> 1. Read-then-write fault sequence after clear_refs, exercising in-place
> huge PMD/PUD write-protection upgrade via wp_huge_pmd()/wp_huge_pud().
> 2. Direct initial write fault on an unpopulated BAR VMA after clear_refs,
> exercising vmf_insert_pfn_pmd()/vmf_insert_pfn_pud() with
> FAULT_FLAG_WRITE set.
>
> Skip gracefully when the device has no known memory-backed BAR >= 2 MiB
> or when /proc/self/clear_refs soft-dirty tracking (CONFIG_MEM_SOFT_DIRTY)
> is unavailable.
>
> Suggested-by: Alex Williamson <alex@xxxxxxxxxxx>
> Cc: David Matlack <dmatlack@xxxxxxxxxx>
> Cc: Matt Evans <matt@xxxxxxxxxx>
> Signed-off-by: Mina Almasry <almasrymina@xxxxxxxxxx>
Reviewed-by: David Matlack <dmatlack@xxxxxxxxxx>