mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Benjamin Block <bblock@linux.ibm.com>
To: "Ionut Nechita (Wind River)" <ionut.nechita@windriver.com>
Cc: linux-pci@vger.kernel.org, bhelgaas@google.com,
	helgaas@kernel.org, sebott@linux.ibm.com, schnelle@linux.ibm.com,
	alifm@linux.ibm.com, julianr@linux.ibm.com, dtatulea@nvidia.com,
	mani@kernel.org, lukas@wunner.de, kbusch@kernel.org,
	ionut_n2001@yahoo.com, sunlightlinux@gmail.com,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v6 1/1] PCI/IOV: Make pci_lock_rescan_remove() reentrant and protect sriov_add_vfs/sriov_del_vfs
Date: Fri, 6 Mar 2026 16:26:45 +0100	[thread overview]
Message-ID: <20260306152645.GL1971507@p1gen4-pw042f0m> (raw)
In-Reply-To: <20260306082108.17322-2-ionut.nechita@windriver.com>

Hey Ionut,

On Fri, Mar 06, 2026 at 10:21:08AM +0200, Ionut Nechita (Wind River) wrote:
--8<--
> Fixes: 18f9e9d150fc ("PCI/IOV: Factor out sriov_add_vfs()")
> Cc: stable@vger.kernel.org
> Suggested-by: Lukas Wunner <lukas@wunner.de>
> Tested-by: Dragos Tatulea <dtatulea@nvidia.com>
> Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
> Tested-by: Benjamin Block <bblock@linux.ibm.com>

I'm not sure whether you are aware of this, but generally, once you make
substantially changes to a patch, it is common practice to remove the previous
Tested-by and/or Reviewed-by tags again:
https://docs.kernel.org/process/submitting-patches.html#reviewer-s-statement-of-oversight
(3. paragraph).

It's a bit of a judgement call what level of change is necessary to be
"substantial", but anyway, I thought I'd mention it :)

> Signed-off-by: Ionut Nechita <ionut_n2001@yahoo.com>
> Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
> ---
--8<--
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index bccc7a4bdd794..c7efb8e1010d3 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3509,16 +3509,27 @@ 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;
> +static unsigned int pci_rescan_remove_count;
>  
>  void pci_lock_rescan_remove(void)
>  {
> +	if (pci_rescan_remove_owner == current) {
> +		pci_rescan_remove_count++;
> +		return;
> +	}
>  	mutex_lock(&pci_rescan_remove_lock);
> +	pci_rescan_remove_owner = current;
> +	pci_rescan_remove_count = 1;
>  }
>  EXPORT_SYMBOL_GPL(pci_lock_rescan_remove);
>  
>  void pci_unlock_rescan_remove(void)
>  {
> -	mutex_unlock(&pci_rescan_remove_lock);
> +	if (--pci_rescan_remove_count == 0) {
> +		pci_rescan_remove_owner = NULL;
> +		mutex_unlock(&pci_rescan_remove_lock);
> +	}
>  }
>  EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove);

I'm not sure Lukas meant to revert to a local cache for the task_struct, just
that the counter variable itself doesn't need to be an atomic.

How the counting is done itself is probably very much a taste question. I've
run tests in my test lab with this change:

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6686cee98afc..28c0384424db 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -3510,27 +3510,23 @@ EXPORT_SYMBOL_GPL(pci_rescan_bus);
  */
 DEFINE_MUTEX(pci_rescan_remove_lock);
 EXPORT_SYMBOL_GPL(pci_rescan_remove_lock);
-static struct task_struct *pci_rescan_remove_owner;
-static unsigned int pci_rescan_remove_count;
+static size_t pci_rescan_remove_reentrant_count = 0;
 
 void pci_lock_rescan_remove(void)
 {
-	if (pci_rescan_remove_owner == current) {
-		pci_rescan_remove_count++;
-		return;
-	}
-	mutex_lock(&pci_rescan_remove_lock);
-	pci_rescan_remove_owner = current;
-	pci_rescan_remove_count = 1;
+	if (mutex_get_owner(&pci_rescan_remove_lock) == (unsigned long)current)
+		pci_rescan_remove_reentrant_count++;
+	else
+		mutex_lock(&pci_rescan_remove_lock);
 }
 EXPORT_SYMBOL_GPL(pci_lock_rescan_remove);
 
 void pci_unlock_rescan_remove(void)
 {
-	if (--pci_rescan_remove_count == 0) {
-		pci_rescan_remove_owner = NULL;
+	if (pci_rescan_remove_reentrant_count > 0)
+		pci_rescan_remove_reentrant_count--;
+	else
 		mutex_unlock(&pci_rescan_remove_lock);
-	}
 }
 EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove);
 
But like I said, the counting comes down to about the same as with your patch
(as far as I can tell), just that it also uses the mutex_get_owner() call.

-- 
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

      reply	other threads:[~2026-03-06 15:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06  8:21 [PATCH v6 0/1] " Ionut Nechita (Wind River)
2026-03-06  8:21 ` [PATCH v6 1/1] " Ionut Nechita (Wind River)
2026-03-06 15:26   ` Benjamin Block [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260306152645.GL1971507@p1gen4-pw042f0m \
    --to=bblock@linux.ibm.com \
    --cc=alifm@linux.ibm.com \
    --cc=bhelgaas@google.com \
    --cc=dtatulea@nvidia.com \
    --cc=helgaas@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=ionut.nechita@windriver.com \
    --cc=ionut_n2001@yahoo.com \
    --cc=julianr@linux.ibm.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mani@kernel.org \
    --cc=schnelle@linux.ibm.com \
    --cc=sebott@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=sunlightlinux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®