]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pds_core: delete VF dev on reset
authorShannon Nelson <shannon.nelson@amd.com>
Fri, 16 Feb 2024 22:29:51 +0000 (14:29 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 May 2025 07:43:58 +0000 (09:43 +0200)
[ Upstream commit 2dac60e062340c1e5c975ad6465192d11c40d47a ]

When the VF is hit with a reset, remove the aux device in
the prepare for reset and try to restore it after the reset.
The userland mechanics will need to recover and rebuild whatever
uses the device afterwards.

Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: dfd76010f8e8 ("pds_core: remove write-after-free of client_id")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/amd/pds_core/auxbus.c
drivers/net/ethernet/amd/pds_core/main.c

index fb7a5403e630db0c3d5f51d475d4744ffa7e87e6..b76a9b7e0aed66e31d048b65ac2e0585d7f9654c 100644 (file)
@@ -177,6 +177,9 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
        struct pds_auxiliary_dev *padev;
        int err = 0;
 
+       if (!cf)
+               return -ENODEV;
+
        mutex_lock(&pf->config_lock);
 
        padev = pf->vfs[cf->vf_id].padev;
@@ -195,14 +198,27 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
 int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
 {
        struct pds_auxiliary_dev *padev;
-       enum pds_core_vif_types vt;
        char devname[PDS_DEVNAME_LEN];
+       enum pds_core_vif_types vt;
+       unsigned long mask;
        u16 vt_support;
        int client_id;
        int err = 0;
 
+       if (!cf)
+               return -ENODEV;
+
        mutex_lock(&pf->config_lock);
 
+       mask = BIT_ULL(PDSC_S_FW_DEAD) |
+              BIT_ULL(PDSC_S_STOPPING_DRIVER);
+       if (cf->state & mask) {
+               dev_err(pf->dev, "%s: can't add dev, VF client in bad state %#lx\n",
+                       __func__, cf->state);
+               err = -ENXIO;
+               goto out_unlock;
+       }
+
        /* We only support vDPA so far, so it is the only one to
         * be verified that it is available in the Core device and
         * enabled in the devlink param.  In the future this might
index eddbf0acdde77f1ab6fa1d82fd76bd899bbd609d..346a69e95c880547866848466c885608cc21a061 100644 (file)
@@ -475,6 +475,14 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)
        pdsc_stop_health_thread(pdsc);
        pdsc_fw_down(pdsc);
 
+       if (pdev->is_virtfn) {
+               struct pdsc *pf;
+
+               pf = pdsc_get_pf_struct(pdsc->pdev);
+               if (!IS_ERR(pf))
+                       pdsc_auxbus_dev_del(pdsc, pf);
+       }
+
        pdsc_unmap_bars(pdsc);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
@@ -510,6 +518,14 @@ static void pdsc_reset_done(struct pci_dev *pdev)
 
        pdsc_fw_up(pdsc);
        pdsc_restart_health_thread(pdsc);
+
+       if (pdev->is_virtfn) {
+               struct pdsc *pf;
+
+               pf = pdsc_get_pf_struct(pdsc->pdev);
+               if (!IS_ERR(pf))
+                       pdsc_auxbus_dev_add(pdsc, pf);
+       }
 }
 
 static const struct pci_error_handlers pdsc_err_handler = {