]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: hisilicon/qm - adjust the internal processing sequence of the vf enable and...
authorChenghai Huang <huangchenghai2@huawei.com>
Sat, 1 Jun 2024 02:51:49 +0000 (10:51 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 7 Jun 2024 11:46:40 +0000 (19:46 +0800)
When the vf is enabled, the value of vfs_num must be assigned
after the VF configuration is complete. Otherwise, the device
may be accessed before the virtual configuration is complete,
causing an error.

When the vf is disabled, clear vfs_num and execute
qm_pm_put_sync before hisi_qm_sriov_disable is return.
Otherwise, if qm_clear_vft_config fails, users may access the
device when the PCI virtualization is disabled, resulting in an
error.

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/qm.c

index 3dac8d8e856866bb2361f73b4a23fa72476acfcd..f614fd228b562480083225db48c060c155901a64 100644 (file)
@@ -3793,14 +3793,13 @@ int hisi_qm_sriov_enable(struct pci_dev *pdev, int max_vfs)
                goto err_put_sync;
        }
 
-       qm->vfs_num = num_vfs;
-
        ret = pci_enable_sriov(pdev, num_vfs);
        if (ret) {
                pci_err(pdev, "Can't enable VF!\n");
                qm_clear_vft_config(qm);
                goto err_put_sync;
        }
+       qm->vfs_num = num_vfs;
 
        pci_info(pdev, "VF enabled, vfs_num(=%d)!\n", num_vfs);
 
@@ -3822,7 +3821,6 @@ EXPORT_SYMBOL_GPL(hisi_qm_sriov_enable);
 int hisi_qm_sriov_disable(struct pci_dev *pdev, bool is_frozen)
 {
        struct hisi_qm *qm = pci_get_drvdata(pdev);
-       int ret;
 
        if (pci_vfs_assigned(pdev)) {
                pci_err(pdev, "Failed to disable VFs as VFs are assigned!\n");
@@ -3837,13 +3835,10 @@ int hisi_qm_sriov_disable(struct pci_dev *pdev, bool is_frozen)
 
        pci_disable_sriov(pdev);
 
-       ret = qm_clear_vft_config(qm);
-       if (ret)
-               return ret;
-
+       qm->vfs_num = 0;
        qm_pm_put_sync(qm);
 
-       return 0;
+       return qm_clear_vft_config(qm);
 }
 EXPORT_SYMBOL_GPL(hisi_qm_sriov_disable);