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

[PATCH v6 8/8] vpci/msix: Free MSIX resources when init_msix() fails


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jiqian Chen <Jiqian.Chen@xxxxxxx>
  • Date: Thu, 12 Jun 2025 17:29: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=XF1q4U46xvoiaeVV4plSO6XloONzJt5pNCKauR4m3Ug=; b=HM4RMtoZCNZy1eKB3dldXQB4jikkKFhdbm7V9X3vBcbqJ+8LaRNRdVeH0FoKVyAMWG5rdg4/xdzN3Yy8G9ZOJCAAYL31v03IxyMqsHkel2H5JPCpeTRwrfwjbdKsjHBEgf1gsq+ghe7tJp8T15/Ry5Lb43gVEy3Ap6gpjXv2cGzyl2wuPKnbVcOA37Ye1dfwJmHj9cQO8lMU9Vy9bpiu7n7SLW/cq2I9FQtnFoDml5pEx5pZ7VffqA3B/366emGAc2PpM4h11OVnnshAEL7GmuyOqUjxJjnbF7aYCS/43/Q0b9VLbKcVbIRtt1dKPTaybCyib3SPUvRmhnOxQ801bg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gduMruJjmwDbdrjQRBeqsBfhLf0VnLMTzkD9LqDq0Xx4BJC4+MdZvIe4h65RmVLweUOTCwVbUA0lCTaCPgqeIzbHHNu0fL8rhkeY6w90HBD2bQerSSL1Xl5oyGN5C/tqSBpkNxCyyr4dm3XOBlybru6uyQKjq5g30a7ybkPoXX0feDEmCGCTY1SSakG4QLoMPwo/vlTE4ktsfpLNKUBHR9ZPo0Jsux3Lm357OGGwQkTmXeXmZYPckwgVBEFxmQ59DoGOVESYwg8QpWrGIUTanu8KQVAfRm/EYoqctVNcqHPEbNH/szRPs1tI8fGye9TNuDZu/atqZKzmAernhuoPEA==
  • Cc: Huang Rui <ray.huang@xxxxxxx>, Jiqian Chen <Jiqian.Chen@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 12 Jun 2025 09:30:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When init_msix() fails, current logic return fail and free MSIX-related
resources in vpci_deassign_device(). But the previous new changes will
hide MSIX capability and return success, it can't reach
vpci_deassign_device() to remove resources if hiding success, so those
resources must be removed in cleanup function of MSIX.

To do that, implement cleanup function for MSIX.

Signed-off-by: Jiqian Chen <Jiqian.Chen@xxxxxxx>
---
cc: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
---
v5->v6 changes:
* Change the logic to add dummy handler when !vpci->msix in cleanup_msix().

v4->v5 changes:
* Change definition "static void cleanup_msix" to "static int cf_check 
cleanup_msix" since cleanup hook is changed to be int.
* Add a read-only register for MSIX Control Register in the end of 
cleanup_msix().

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 | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index 674815ead025..da293e7494fd 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -655,6 +655,33 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
     return 0;
 }
 
+static int cf_check cleanup_msix(struct pci_dev *pdev)
+{
+    int rc;
+    struct vpci *vpci = pdev->vpci;
+    const unsigned int msix_pos = pdev->msix_pos;
+
+    if ( !msix_pos )
+        return 0;
+
+    rc = vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
+    if ( rc )
+        return rc;
+
+    if ( vpci->msix )
+    {
+        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);
+    }
+
+    return vpci_add_register(pdev->vpci, vpci_hw_read16, NULL,
+                             msix_control_reg(msix_pos), 2, NULL);
+}
+
 static int cf_check init_msix(struct pci_dev *pdev)
 {
     struct domain *d = pdev->domain;
@@ -709,7 +736,7 @@ static int cf_check init_msix(struct pci_dev *pdev)
 
     return rc;
 }
-REGISTER_VPCI_CAP(PCI_CAP_ID_MSIX, init_msix, NULL);
+REGISTER_VPCI_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®.