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

From: Lukas Wunner

Date: Tue Mar 17 2026 - 09:14:09 EST


On Tue, Mar 17, 2026 at 12:33:34PM +0100, Benjamin Block wrote:
> @@ -518,8 +520,13 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
> if (kstrtoul(buf, 0, &val) < 0)
> return -EINVAL;
>
> - if (val && device_remove_file_self(dev, attr))
> + if (val && device_remove_file_self(dev, attr)) {
> + device_lock(dev);
> + kill_device(dev);
> + device_unlock(dev);
> + device_driver_detach(dev);
> pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
> + }
> return count;
> }
> static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0220, NULL,
>
> Marking the device dead prevents re-binding after the unbind.

That can also be achieved through the PCI_DEV_ALLOW_BINDING flag,
though you'd have to add a pci_dev_disallow_binding() helper in
drivers/pci/pci.h to go alongside the existing
pci_dev_allow_binding() and pci_dev_binding_disallowed() helpers.

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?

Thanks,

Lukas