RE: [RFC PATCH 1/1] vfio/pci: Disable sriov on PF device close

"Tian, Kevin" <[email protected]> Wed, 5 Aug 2026 09:34:32 +0000
Newsgroups org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <CO1PR11MB483582006360CC4F32F97F838CD32@CO1PR11MB4835.namprd11.prod.outlook.com>
> From: Samiullah Khawaja <[email protected]>
> Sent: Wednesday, August 5, 2026 8:34 AM
> 
> When userspace closes a VFIO device file descriptor, the vfio driver
> performs a hardware reset on the PCIe device to ensure it is returned to
> a clean state. However, if the closed device is an SR-IOV Physical
> Function (PF), it may have instantiated Virtual Functions (VFs) that are
> actively bound to host kernel drivers (or other vfio instances).
> 
> When the PF is hardware-reset via VFIO, it implicitly disrupts SR-IOV
> operations at the device level. Because this reset happens without notifying
> the core PCI driver model, the kernel drivers bound to the VFs remain loaded
> and operate under the assumption that the VF hardware is still functional.
> 
> This creates a state mismatch between the kernel's view of the hardware
> and the actual device state. Subsequent attempts by the host OS or bound
> drivers to interact with the VFs will fail, leading to unexpected
> errors.
> 
> Disable SR-IOV on the device prior to issuing the PF reset so that the
> VFs can teardown and remove at the software level also.
> 
> Signed-off-by: Samiullah Khawaja <[email protected]>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index a113c55845e1..b36c77eb3c40 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)) {
> +		device_lock(&vdev->pdev->dev);
> +		vfio_pci_core_sriov_configure(vdev, 0);
> +		device_unlock(&vdev->pdev->dev);
> +	}
> +

Sashiko reported several locking issues with this change:

https://sashiko.dev/#/patchset/20260805003355.728299-2-skhawaja%40google.com

Actually it is a discouraged usage allowing kernel drivers bound to VFs
which belongs to a PF owned by vfio userspace. 

vfio_pci_bus_notifier prints a warning message upon 
BUS_NOTIFY_BOUND_DRIVER:

	"VF %s bound to driver %s while PF bound to driver %s\n"

Fixing this alone is insufficient to remove that warning...