Re: [PATCH v13 1/2] PCI/IOV: Make pci_lock_rescan_remove() reentrant and protect sriov_add_vfs/sriov_del_vfs
From: Benjamin Block
Date: Tue Apr 21 2026 - 08:51:39 EST
On Tue, Apr 21, 2026 at 10:34:20AM +0300, Ionut Nechita (Wind River) wrote:
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index b63cd0c310bc..0e62081bc5e5 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3513,16 +3513,30 @@ 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;
You could make this variable `const`:
static const struct task_struct *pci_rescan_remove_owner;
so it is clear that this pointer is not meant to be used to modify the
task_struct in any way - just for these comparisons.
> +static unsigned int pci_rescan_remove_depth;
>
> void pci_lock_rescan_remove(void)
> {
> - mutex_lock(&pci_rescan_remove_lock);
> + if (pci_rescan_remove_owner == current) {
> + pci_rescan_remove_depth++;
> + } else {
> + mutex_lock(&pci_rescan_remove_lock);
> + pci_rescan_remove_owner = current;
> + pci_rescan_remove_depth = 1;
> + }
> }
> EXPORT_SYMBOL_GPL(pci_lock_rescan_remove);
>
> void pci_unlock_rescan_remove(void)
> {
> - mutex_unlock(&pci_rescan_remove_lock);
> + if (WARN_ON(pci_rescan_remove_owner != current))
> + return;
> +
> + if (--pci_rescan_remove_depth == 0) {
> + pci_rescan_remove_owner = NULL;
> + mutex_unlock(&pci_rescan_remove_lock);
> + }
> }
> EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove);
But anyway, with, or without this change, this looks good to me. I hadn't run
into any linker issues, but I only ever used our debug config.
Also holds up with my tests on my s390 rig.
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