Re: [PATCH] vfio/pci: Only lock the upstream bridge if the reset may need it

From: Samiullah Khawaja

Date: Tue Nov 24 2026 - 17:00:48 EST


On Tue, Nov 24, 2026 at 02:57:43PM -0700, Alex Williamson wrote:
On Tue, 24 Nov 2026 21:04:57 +0000
Samiullah Khawaja <skhawaja@xxxxxxxxxx> wrote:

On Tue, Nov 24, 2026 at 08:48:52AM -0700, Alex Williamson wrote:
>On Fri, 20 Nov 2026 22:21:16 +0000
>Samiullah Khawaja <skhawaja@xxxxxxxxxx> wrote:
>
>> On Thu, Nov 19, 2026 at 02:32:37PM -0800, Alex Williamson wrote:
>> >On Wed, 18 Nov 2026 16:37:06 -0800
>> >Alex Williamson <alex@xxxxxxxxxxx> wrote:
>> >
>> >> On Thu, 12 Nov 2026 23:57:00 +0000
>> >> Samiullah Khawaja <skhawaja@xxxxxxxxxx> wrote:
>> >>
>> >> > Commit 962ae6892d8b ("vfio/pci: Lock upstream bridge for
>> >> > vfio_pci_core_disable()") makes vfio_pci_core_disable() trylock the
>> >> > upstream bridge before resetting the device, and skips the reset if the
>> >> > trylock fails.
>> >> >
>> >> > All VFs of a PF have the same upstream bridge. Take a device with two
>> >> > VFs, both used by one process. When the process is killed, both VFs can
>> >> > be released at the same time. The first one takes the bridge lock and
>> >> > does its FLR, the second one fails the trylock and is never reset.
>> >> >
>> >> > The bridge lock is only needed for a bus reset, which is done through
>> >> > the bridge. A VF is reset with FLR, and pci_parent_bus_reset() never
>> >> > resets the bus for it because the PF and the other VFs are on the same
>> >> > bus.
>> >> >
>> >> > Add pci_reset_needs_bridge_lock(), which returns true if any reset
>> >> > method enabled for the device is a bus reset, and only lock the bridge
>> >> > in vfio_pci_core_disable() when it does.
>> >> >
>> >> > Fixes: 962ae6892d8b ("vfio/pci: Lock upstream bridge for vfio_pci_core_disable()")
>> >> > Cc: stable@xxxxxxxxxxxxxxx
>> >> > Signed-off-by: Samiullah Khawaja <skhawaja@xxxxxxxxxx>
>> >> > ---
>> >> > Tested in QEMU with an igb PF behind a PCIe root port, bound to vfio-pci
>> >> > with two VFs. Both VFs are opened through VFIO and then closed from two
>> >> > threads at the same time, counting FLRs with a kprobe on pcie_flr().
>> >> > Without this patch one VF missed its FLR in 50 of 50 rounds, with it
>> >> > both VFs were reset in every round. I will send a VFIO selftest for this
>> >> > separately.
>> >> > ---
>> >> > drivers/pci/pci.c | 28 ++++++++++++++++++++++++++++
>> >> > drivers/vfio/pci/vfio_pci_core.c | 3 ++-
>> >> > include/linux/pci.h | 1 +
>> >> > 3 files changed, 31 insertions(+), 1 deletion(-)
>> >> >
>>

[snip]

>I think the test I'm proposing precludes a bus reset, ie. there is no
>upstream bridge, the device flags prevent it, or we're provided with a
>VF. It's only those cases where we can't do a bus reset anyway, that
>we can skip the bridge device lock. I think that means it's useful in
>PCI-core as well as vfio-pci. Did I miss something?

Yes, the slot reset probe doesn't account for the VFs and will allow
reset of the slot when hotplug is enabled.

I think that is probably a fix that needs to be done orthogonal to this.
I will send a v2 of this by doing the needs_bridge_lock() as you
mentioned above.

Yes, there might be a latent bug in the slot reset path. I know s390
has some weird per-VF slot reset, but they set the per_func_slot flag.
The test in pci_dev_reset_slot_function() probably needs to account for
both VFs and multifunction devices as:

((dev->multifunction || dev->is_virtfn) &&
!dev->slot->per_func_slot)

Yes, that is exactly the fix I am thinking about. Let me send this one
also separately.

As you suggest though, that's a separate fix. Thanks,

Alex