[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 10/10] vpci/msix: Add function to clean MSIX resources


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jiqian Chen <Jiqian.Chen@xxxxxxx>
  • Date: Fri, 9 May 2025 17:05:42 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jxsqy2OG0XoDfK1Z06/jOcTFbFyd2+TnRkp4DczGZ1o=; b=RJwvhocb+CJoTK+jqShcwdh9I5itTKTXvawclxBKTcvj8n0tJA0FvFuk6pdHXAOgjCEQjJubJJIe0jGG9NiQGjL7F6LszXBwoWsxuqHDx5cWUKFO76FkDJSVe0zgsUamvsWhYlOZz76yAV32oOIQN2+Pc8g8YW727EJVvpcn3BOdqM6bOe3E5EocHC0WLnBiLbG1xBsiV+aTK2N51xNmXkfqYFMvACWEoAZb17EUtSvHmJ7lMpZj86cGa+Hq9aHoKVxu7ImGVrh/IFUPUScyLIfk7PQ6pbicIGa4ZnI+UuMAkR3hwIy6AMP3DT6tzzEgjBUAvhgDNVU8V9rc+VvUfw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hDEZQJj+tsXW/ncUe5HsNHj3twmqoXXT0cIj2NTcXMJaWRuidIK8dB86GTT2sdxJj+ez/iAJB5CW3rM/xw+jc7lsgdhjXmcxFM1AaePk0ujq71K7d6TLwJw+1qv2ZUby3mcPUbQLRd95gprZhOl7VVGoLBU7f6khFyeExMXoPjJ+xpF306ouVR3NvCDtG6LKzsEDTDl23Lho+Leiqf0nx8OcakmQ2BARiR7E5N/yOpKdqtJCnq7jdfV7zWQT5feRBSUAJOvbH8M7fI8qpdjycMT1XWE/LdLAKvJ/neFWVjdI8lPwiV0FuNrZ/3Ok3bsbt6gD95iOkrbBe9uMWQJWtw==
  • Cc: Huang Rui <ray.huang@xxxxxxx>, Jiqian Chen <Jiqian.Chen@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 09 May 2025 09:06:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When init_msix() fails, it needs to clean all MSIX resources.
So, add a new function to do that.

Signed-off-by: Jiqian Chen <Jiqian.Chen@xxxxxxx>
---
cc: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
---
v3->v4 changes:
* Change function name from fini_msix() to cleanup_msix().
* Change to use XFREE to free vpci->msix.
* In cleanup function, change the sequence of check and remove action according 
to init_msix().

v2->v3 changes:
* Remove unnecessary clean operations in fini_msix().

v1->v2 changes:
new patch.

Best regards,
Jiqian Chen.
---
 xen/drivers/vpci/msix.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index f8ce89b8b32f..b80491ed32bf 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -655,6 +655,27 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
     return 0;
 }
 
+static void cleanup_msix(struct pci_dev *pdev)
+{
+    struct vpci *vpci = pdev->vpci;
+    unsigned int msix_pos = pdev->msix_pos;
+
+    if ( !msix_pos )
+        return;
+
+    vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
+
+    if ( !vpci->msix )
+        return;
+
+    for ( unsigned int i = 0; i < ARRAY_SIZE(vpci->msix->table); i++ )
+        if ( vpci->msix->table[i] )
+            iounmap(vpci->msix->table[i]);
+
+    list_del(&vpci->msix->next);
+    XFREE(vpci->msix);
+}
+
 static int cf_check init_msix(struct pci_dev *pdev)
 {
     struct domain *d = pdev->domain;
@@ -709,7 +730,7 @@ static int cf_check init_msix(struct pci_dev *pdev)
 
     return rc;
 }
-REGISTER_VPCI_LEGACY_CAP(PCI_CAP_ID_MSIX, init_msix, NULL);
+REGISTER_VPCI_LEGACY_CAP(PCI_CAP_ID_MSIX, init_msix, cleanup_msix);
 
 /*
  * Local variables:
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.