Re: [PATCH v3 2/2] PCI/IOV: Fix race between SR-IOV enable/disable and hotplug

From: Benjamin Block

Date: Tue Mar 17 2026 - 13:36:35 EST


On Tue, Mar 17, 2026 at 02:18:00PM +0100, Lukas Wunner wrote:
> On Tue, Mar 17, 2026 at 02:08:11PM +0100, Lukas Wunner wrote:
> > However pci_stop_and_remove_bus_device() implicitly unbinds the
> > driver before removing the device. Remind me, what's the need
> > to unbind before calling that function?
>
> Never mind, read Günter Röck's e-mail only now. So this is just
> a bandaid to work around the too coarse-grained pci_lock_rescan_remove().
>
> I've been arguing for a while that we need to move to more
> fine-grained locking, but it's difficult to get there without
> breaking things, it's difficult to make sense of a lot of old code
> and it's difficult to allocate time to tech debt problems like this
> because employers always want developers to focus on enabling shiny
> new features first. :(

I agree, it's a mess :/

The quick idea here was to prevent the found AB-BA circular lock by
moving the removal of the SR-IOV VFs in front of the call to
pci_stop_and_remove_bus_device_locked(), and that is typically done when
the device driver is unbound (it's the expectation in
pci_device_remove()).

But it's just a quick idea, maybe someone else has a better one. I'm
also not sure this is the only place where we'd need to deal with this
particular AB-BA circular lock scenario (`pdev->dev` and
`pci_rescan_remove_lock`).

I'll run a few more tests, and see if I can scare up some other/new
lockdep warning with this change.

--
Best Regards und Beste Grüße, Benjamin Block
PGP KeyID: 9610 2BB8 2E17 6F65 2362 6DF2 46E0 4E05 67A3 2E9E