Re: [PATCH v3 1/1] PCI/IOV: Add reentrant locking in sriov_add_vfs/sriov_del_vfs for complete serialization

From: Benjamin Block

Date: Thu Feb 26 2026 - 08:42:54 EST


On Wed, Feb 25, 2026 at 10:24:34PM +0200, ionut.nechita@xxxxxxxxxxxxx wrote:
> From: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
>
--8<--
>
> Instead, introduce owner tracking for pci_rescan_remove_lock via a new
> pci_lock_rescan_remove_reentrant() helper. This function checks if the
> current task already holds the lock:
> - If the lock is not held: acquires it and returns true, providing
> full serialization against concurrent hotplug events (including
> platform-generated events on s390).
> - If the lock is already held by the current task (reentrant call from
> remove_store or sriov_numvfs_store paths): returns false without
> re-acquiring, avoiding deadlock while the caller already provides
> the necessary serialization.
> - If the lock is held by another task (concurrent hotplug): blocks
> until the lock is released, then acquires it, providing complete
> serialization. This is the key improvement over a trylock approach.
>
--8<--
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index bccc7a4bdd794..467362c277f19 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3509,19 +3509,38 @@ EXPORT_SYMBOL_GPL(pci_rescan_bus);
> * routines should always be executed under this mutex.
> */
> DEFINE_MUTEX(pci_rescan_remove_lock);
> +static struct task_struct *pci_rescan_remove_owner;
^
const *pci_rescan_remove_owner

Minor nitpick: you could declare this `const`; making it clear that this is
not meant to be used to modify the task in any way.

> void pci_lock_rescan_remove(void)
> {
> mutex_lock(&pci_rescan_remove_lock);
> + pci_rescan_remove_owner = current;
> }
> EXPORT_SYMBOL_GPL(pci_lock_rescan_remove);
>
> void pci_unlock_rescan_remove(void)
> {
> + pci_rescan_remove_owner = NULL;
> mutex_unlock(&pci_rescan_remove_lock);
> }
> EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove);
>
> +bool pci_lock_rescan_remove_reentrant(void)
> +{
> + if (pci_rescan_remove_owner == current)
> + return false;
> + pci_lock_rescan_remove();
> + return true;
> +}
> +EXPORT_SYMBOL_GPL(pci_lock_rescan_remove_reentrant);

Otherwise this looks good to me.

I've run tests on s390 with hot-unplug from within Linux and externally
triggered, driver unbind/unload, s390 PCI recovery, and some other minor
tests.
No lockdep splats, no other warnings/splats; it looks good to me.


Reviewed-by: Benjamin Block <bblock@xxxxxxxxxxxxx>
Tested-by: Benjamin Block <bblock@xxxxxxxxxxxxx>

--
Best Regards, Benjamin Block / Linux on IBM Z Kernel Development
IBM Deutschland Research & Development GmbH / https://www.ibm.com/privacy
Vors. Aufs.-R.: Wolfgang Wendt / Geschäftsführung: David Faller
Sitz der Ges.: Ehningen / Registergericht: AmtsG Stuttgart, HRB 243294