Re: [PATCH v3 2/3] vfio: selftests: Add vfio_pci_find_mem_bar() helper

From: David Matlack

Date: Thu Nov 05 2026 - 17:57:00 EST


On Tue, Nov 3, 2026 at 10:59 AM Alex Williamson <alex@xxxxxxxxxxx> wrote:
>
> On Mon, 2 Nov 2026 23:04:44 +0000
> Mina Almasry <almasrymina@xxxxxxxxxx> wrote:
>
> > Add vfio_pci_find_mem_bar() to libvfio to locate a BAR (or range within
> > a BAR) of at least min_size bytes that behaves like ordinary memory and
> > can be safely read and written without device-specific side effects.
> >
> > Detection is backed by a table of known devices, starting with QEMU's
> > pci-testdev (1b36:0005) BAR 2 when configured with membar=<size> and
> > membar-backed=on.
>
> Should we test for this?
>
> We could toggle memory decode around writing a short, unique pattern
> with read-back verification. This might be unnecessary for a physical
> device, but per the definition of this function it should also be
> harmless. For the pci-testdev, which is our only match in this
> proposal, it validates the BAR is backed by real memory and not handled
> as an unimplemented memory range.
>
> For the use case in patch 3/ it doesn't matter, but for future use
> cases I'd rather see that we generate a skip or failure based on the
> test here rather than debug failures in the test case consumers.

Sounds good to me.