From: Gerd Bayer <gbayer@linux.ibm.com>
To: Niklas Schnelle <schnelle@linux.ibm.com>,
Bjorn Helgaas <helgaas@kernel.org>
Cc: Lukas Wunner <lukas@wunner.de>, Keith Busch <kbusch@kernel.org>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Benjamin Block <bblock@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Farhan Ali <alifm@linux.ibm.com>,
Julian Ruess <julianr@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] PCI/IOV: Fix race between SR-IOV enable/disable and hotplug
Date: Wed, 10 Dec 2025 19:05:02 +0100 [thread overview]
Message-ID: <79c9f452ab031dfa34eccca8951cb257d2056b41.camel@linux.ibm.com> (raw)
In-Reply-To: <20251119-revert_sriov_lock-v2-2-ea50eb1e8f96@linux.ibm.com>
On Wed, 2025-11-19 at 13:34 +0100, Niklas Schnelle wrote:
> Commit 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when
> enabling/disabling SR-IOV") tried to fix a race between the VF removal
> inside sriov_del_vfs() and concurrent hot unplug by taking the PCI
> rescan/remove lock in sriov_del_vfs(). Similarly the PCI rescan/remove
> lock was also taken in sriov_add_vfs() to protect addition of VFs.
>
> This approach however causes deadlock on trying to remove PFs with
> SR-IOV enabled because PFs disable SR-IOV during removal and this
> removal happens under the PCI rescan/remove lock. So the original fix
> had to be reverted.
>
> Instead of taking the PCI rescan/remove lock in sriov_add_vfs() and
> sriov_del_vfs(), fix the race that occurs with SR-IOV enable and disable
> vs hotplug higher up in the callchain by taking the lock in
> sriov_numvfs_store() before calling into the driver's sriov_configure()
> callback.
I agree, adding the lock to sriov_numvfs_store() is adding the missing
serialization against other threads that create or remove PCI devices
without getting into the middle of implicit PCI VF device removal in
the course of a PF removal that grabbed pci_lock_rescan_remove()
already.
>
> Cc: stable@vger.kernel.org
> Fixes: 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV")
> Reported-by: Benjamin Block <bblock@linux.ibm.com>
> Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> ---
> drivers/pci/iov.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index ac4375954c9479b5f4a0e666b5215094fdaeefc2..c6dc1b44bf602a0b1785b684f768fcd563f5b2aa 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -495,7 +495,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
>
> if (num_vfs == 0) {
> /* disable VFs */
> + pci_lock_rescan_remove();
> ret = pdev->driver->sriov_configure(pdev, 0);
> + pci_unlock_rescan_remove();
> goto exit;
> }
>
> @@ -507,7 +509,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
> goto exit;
> }
>
> + pci_lock_rescan_remove();
> ret = pdev->driver->sriov_configure(pdev, num_vfs);
> + pci_unlock_rescan_remove();
> if (ret < 0)
> goto exit;
>
This LGTM, feel free to add
Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
Thank you!
next prev parent reply other threads:[~2025-12-10 18:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 12:34 [PATCH v2 0/2] PCI/IOV: Fix deadlock when removing PF with enabled SR-IOV Niklas Schnelle
2025-11-19 12:34 ` [PATCH v2 1/2] Revert "PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV" Niklas Schnelle
2025-12-10 17:35 ` Gerd Bayer
2025-11-19 12:34 ` [PATCH v2 2/2] PCI/IOV: Fix race between SR-IOV enable/disable and hotplug Niklas Schnelle
2025-12-10 18:05 ` Gerd Bayer [this message]
2025-11-19 12:43 ` [PATCH v2 0/2] PCI/IOV: Fix deadlock when removing PF with enabled SR-IOV Niklas Schnelle
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=79c9f452ab031dfa34eccca8951cb257d2056b41.camel@linux.ibm.com \
--to=gbayer@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=bblock@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=helgaas@kernel.org \
--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=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=schnelle@linux.ibm.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