[PATCH V1] nvme-pci: disable SR-IOV VFs on driver unbind

Bjorn Helgaas helgaas at kernel.org
Fri Feb 6 14:28:26 PST 2026


On Fri, Jan 30, 2026 at 12:53:25PM +0800, qinyuntan wrote:
> Hi All,
> 
> Thank you all for the insightful discussion!
> 
> I agree with Leon's point that not all devices are created equal when it
> comes to SR-IOV handling during driver unbind.
> 
> Looking at existing driver implementations, I found two different
> approaches:
> 
> 1) mlx5 - unconditionally disables SR-IOV in remove:
> 
>    drivers/net/ethernet/mellanox/mlx5/core/main.c:
>    static void remove_one(struct pci_dev *pdev)
>    {
>        ...
>        mlx5_sriov_disable(pdev, false);
>        ...
>    }
> 
>    drivers/net/ethernet/mellanox/mlx5/core/sriov.c:
>    void mlx5_sriov_disable(struct pci_dev *pdev, bool num_vf_change)
>    {
>        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
>        struct devlink *devlink = priv_to_devlink(dev);
>        int num_vfs = pci_num_vf(dev->pdev);
> 
>        pci_disable_sriov(pdev);  /* Always disable, no pci_vfs_assigned()
> check */
>        devl_lock(devlink);
>        mlx5_device_disable_sriov(dev, num_vfs, true, num_vf_change);
>        devl_unlock(devlink);
>    }
> 
> 2) ixgbe - checks pci_vfs_assigned() and skips disable if VFs are in use:
> 
>    drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:
>    static void ixgbe_remove(struct pci_dev *pdev)
>    {
>        ...
>    #ifdef CONFIG_PCI_IOV
>        ixgbe_disable_sriov(adapter);
>    #endif
>        ...
>    }
> 
>    drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c:
>    #ifdef CONFIG_PCI_IOV
>        if (pci_vfs_assigned(adapter->pdev)) {
>            e_dev_warn("Unloading driver while VFs are assigned - VFs will
> not be deallocated\n");
>            return -EPERM;
>        }
>        pci_disable_sriov(adapter->pdev);
>    #endif
> 
> Regarding the warning level discussion: I would prefer keeping it as
> dev_warn() rather than downgrading to dev_info(). As Leon mentioned,
> some devices do require SR-IOV to be disabled when the PF is unbound,
> and for those cases, this warning is important for operators to notice
> and take action. A warning level helps ensure it doesn't get lost in
> normal system logs.
> 
> Please let me know how you'd like to proceed.

"driver left SR-IOV enabled after remove\n" is KERN_WARNING today, and
I'm OK with leaving it that way.



More information about the Linux-nvme mailing list