public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: "Ionut Nechita (Wind River)" <ionut.nechita@windriver.com>
Cc: linux-pci@vger.kernel.org, helgaas@kernel.org,
	sebott@linux.ibm.com, schnelle@linux.ibm.com,
	bblock@linux.ibm.com, alifm@linux.ibm.com, julianr@linux.ibm.com,
	dtatulea@nvidia.com, mani@kernel.org, ionut_n2001@yahoo.com,
	sunlightlinux@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/1] PCI/IOV: Add reentrant locking in sriov_add_vfs/sriov_del_vfs for complete serialization
Date: Tue, 3 Mar 2026 19:19:31 +0100	[thread overview]
Message-ID: <aacmM9bAPstfDpgY@wunner.de> (raw)
In-Reply-To: <20260303080903.28693-2-ionut.nechita@windriver.com>

On Tue, Mar 03, 2026 at 10:09:02AM +0200, Ionut Nechita (Wind River) wrote:
> +++ b/drivers/pci/iov.c
> @@ -629,19 +629,23 @@ static int sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)
>  {
>  	unsigned int i;
>  	int rc;
> +	bool locked;
>  
>  	if (dev->no_vf_scan)
>  		return 0;
>  
> +	locked = pci_lock_rescan_remove_reentrant();
>  	for (i = 0; i < num_vfs; i++) {
>  		rc = pci_iov_add_virtfn(dev, i);
>  		if (rc)
>  			goto failed;
>  	}
> +	pci_unlock_rescan_remove_reentrant(locked);

I think a nicer API would be to have a counter which
is incremented by pci_lock_rescan_remove_reentrant() if owner is current,
is decremented by pci_unlock_rescan_remove_reentrant() if owner is current
and pci_unlock_rescan_remove_reentrant() unlocks only if it hits 0.

No need for an atomic counter as this happens under the lock.

Then you don't need this bool which leaks out of the API into the callers.

Also, I would put this in the existing pci_lock_rescan_remove(),
i.e. without introducing a new _reentrant variant, because these
deadlocks exist elsewhere.  They're known to happen on unplug in
pciehp as well.

Thanks,

Lukas

  reply	other threads:[~2026-03-03 18:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03  8:09 [PATCH v5 0/1] PCI/IOV: Add reentrant locking in sriov_add_vfs/sriov_del_vfs Ionut Nechita (Wind River)
2026-03-03  8:09 ` [PATCH v5 1/1] PCI/IOV: Add reentrant locking in sriov_add_vfs/sriov_del_vfs for complete serialization Ionut Nechita (Wind River)
2026-03-03 18:19   ` Lukas Wunner [this message]
2026-03-03 19:28     ` Lukas Wunner
2026-03-03 19:56       ` Niklas Schnelle
2026-03-03 20:02         ` Keith Busch

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=aacmM9bAPstfDpgY@wunner.de \
    --to=lukas@wunner.de \
    --cc=alifm@linux.ibm.com \
    --cc=bblock@linux.ibm.com \
    --cc=dtatulea@nvidia.com \
    --cc=helgaas@kernel.org \
    --cc=ionut.nechita@windriver.com \
    --cc=ionut_n2001@yahoo.com \
    --cc=julianr@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=schnelle@linux.ibm.com \
    --cc=sebott@linux.ibm.com \
    --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