From: sashiko-bot@kernel.org
To: "Samiullah Khawaja" <skhawaja@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] vfio/pci: Disable sriov on PF device close
Date: Wed, 05 Aug 2026 01:03:12 +0000 [thread overview]
Message-ID: <20260805010313.403391F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805003355.728299-2-skhawaja@google.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Acquiring `device_lock()` inside `vfio_pci_core_close_device()` introduces a guaranteed AB-BA deadlock if the device is unbound from the driver while still in use by userspace.
- [High] Synchronously tearing down SR-IOV VFs from the PF's `close_device` path deadlocks if any VF is actively in use by VFIO.
- [High] Calling `pci_disable_sriov()` without holding `pci_rescan_remove_lock` causes an immediate lockdep splat and races with PCI bus enumeration.
- [Medium] Time-of-Check to Time-of-Use (TOCTOU) races around `device_lock()` allow VFs to be enabled immediately before hardware reset, defeating the purpose of the patch.
--
--- Patch [1]: [RFC PATCH 1/1] vfio/pci: Disable sriov on PF device close ---
commit 996eca93815cca91725d215b78730f993e057c49
Author: Samiullah Khawaja <skhawaja@google.com>
vfio/pci: Disable sriov on PF device close
When a user closes a VFIO device file descriptor for an SR-IOV Physical
Function, the device is reset. This reset disrupts the VFs without notifying
the core PCI driver model. This commit disables SR-IOV prior to issuing the
PF reset so VFs are torn down gracefully at the software level.
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index a113c55845e10..b36c77eb3c407 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -826,6 +826,13 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
> #if IS_ENABLED(CONFIG_EEH)
> eeh_dev_release(vdev->pdev);
> #endif
> +
> + if (pci_num_vf(vdev->pdev)) {
[Severity: Medium]
Is it possible for VFs to be enabled concurrently right after this check?
Since pci_num_vf() is evaluated locklessly before acquiring the device lock, a
concurrent sysfs write to sriov_numvfs could enable VFs immediately after this
returns 0, causing the teardown to be skipped.
Additionally, because the device lock is dropped before the hardware reset in
vfio_pci_core_disable(), a concurrent sysfs write can acquire the lock,
successfully enable SR-IOV, and release the lock before the reset occurs.
Could this recreate the exact hardware state mismatch the patch attempts to fix?
> + device_lock(&vdev->pdev->dev);
[Severity: High]
Does acquiring the device lock here introduce an AB-BA deadlock during device
unbind?
When a device is unbound, the PCI core acquires the device lock in
device_release_driver() and invokes the driver's remove callback. For
vfio-pci, this calls vfio_unregister_group_dev(), which blocks indefinitely
waiting for userspace to close all active file descriptors.
When userspace closes the device fd, vfio_pci_core_close_device() is invoked.
Because this patch tries to acquire the device lock, the fd release thread
will block forever waiting for the unbind thread, and the unbind thread will
wait forever for the fd release thread to finish.
> + vfio_pci_core_sriov_configure(vdev, 0);
[Severity: High]
Can tearing down VFs from the PF's close path deadlock if a VF is actively in
use by VFIO?
When vfio_pci_core_close_device() calls pci_disable_sriov(), the PCI core
synchronously removes all VF devices from the bus. If a VF is also bound to
vfio-pci and currently opened by userspace, removing the VF triggers
vfio_pci_remove(), which blocks indefinitely until the VF file descriptor is
closed.
If a single process holds both the PF and VF open and exits, exit_files()
schedules the fput() for both file descriptors sequentially. If the PF is
closed first, the thread hangs here waiting for the VF to close, preventing
the VF's fput() from ever running.
[Severity: High]
Does this code trigger a lockdep warning by manipulating the PCI bus topology
without the required lock?
Calling vfio_pci_core_sriov_configure() here ultimately calls
pci_stop_and_remove_bus_device() to remove VFs from the PCI bus. That function
enforces a strict locking requirement via
lockdep_assert_held(&pci_rescan_remove_lock).
Because this global mutex is omitted, closing a PF with active VFs could race
against concurrent PCI hotplug or sysfs rescan operations.
> + device_unlock(&vdev->pdev->dev);
> + }
> +
> vfio_pci_dma_buf_cleanup(vdev);
>
> vfio_pci_core_disable(vdev);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805003355.728299-2-skhawaja@google.com?part=1
next prev parent reply other threads:[~2026-08-05 1:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 0:33 [RFC PATCH 0/1] vfio/pci: Disable sriov on PF device close Samiullah Khawaja
2026-08-05 0:33 ` [RFC PATCH 1/1] " Samiullah Khawaja
2026-08-05 1:03 ` sashiko-bot [this message]
2026-08-05 9:34 ` Tian, Kevin
2026-08-05 15:03 ` Alex Williamson
2026-08-06 19:47 ` Jason Gunthorpe
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=20260805010313.403391F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=skhawaja@google.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