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

[PATCH v3 11/11] vpci/msix: Add function to clean MSIX resources


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jiqian Chen <Jiqian.Chen@xxxxxxx>
  • Date: Mon, 21 Apr 2025 14:19:03 +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=QxL1V2Itz6NoD7DRvN+OfCh1LknThOBHHwX8mxG5dWI=; b=v+fw5O0ly+TDb0jEyKNIfn7GI3fp74td4Nyk1At33M4QvvYCcRPdR0OKZtCRhF0wslTtTDjwPth/A0JoSMwjoUfMiyxxh3Ve6uEirBQelGZrwAwDC8QLevR7HArIN0IBYZssdNap6NxphFjJCnMit/KhJUyO9pgTN7+So+SyalPXk/DJxc12l03QdmzJ4GBooXDBQ553eC5D/B6I0IqqLYz6UnxuJTcCKfXq4iKsmULo54m3gsV+uWisxFmeH1hcgqS+6UxLWjykHcREvq5WwOVY762u8xdS80lMZhsR2JKMQfhjYqqhV+KL8aYwJQ9Vch5OO7VwrKMV9zCTXfDNQA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A/tnlSbusmgWhh1SHg1Ib4v7DTB74/8FhjbjZu25kKt+iiNctGfZKG+1oiTSO4f2o/fRZxIm4kv6/AA79jXQqn6zVEFXEHu3czFnxwA9kkn3g8HaYH84ReneGdoJOssXyHpnBDsVvsdEcZ2SyIBSC3OXsJD4OuTCFamUiuotJ1J0m+FVLEjMUb6YR6YvO0Ji94uaMYxcH68UlIV/vibwwC8hIVsocWQ80YEWzCz2jVQ53U+YMjKmgKmmAwQUG7OqkjXsEaos57bW804AzZ9+HbynKSxHvP4VyKXyzs0PC1p/xCuWJ1+6U0B20YA40SDSMeqmqwBzaLWq2NzbmxJtEg==
  • Cc: Huang Rui <ray.huang@xxxxxxx>, Jiqian Chen <Jiqian.Chen@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 21 Apr 2025 06:19:50 +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>
---
v2->v3 changes:
* Remove unnecessary clean operations in fini_msix().

v1->v2 changes:
new patch.

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

diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index 0228ffd9fda9..e322c260f6bc 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -703,6 +703,25 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
     return 0;
 }
 
+static void fini_msix(struct pci_dev *pdev)
+{
+    struct vpci *vpci = pdev->vpci;
+    unsigned int msix_pos = pdev->msix_pos;
+
+    if ( !msix_pos || !vpci->msix )
+        return;
+
+    list_del(&vpci->msix->next);
+
+    for ( unsigned int i = 0; i < ARRAY_SIZE(vpci->msix->table); i++ )
+        if ( vpci->msix->table[i] )
+            iounmap(vpci->msix->table[i]);
+
+    vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
+    xfree(vpci->msix);
+    vpci->msix = NULL;
+}
+
 static int cf_check init_msix(struct pci_dev *pdev)
 {
     struct domain *d = pdev->domain;
@@ -757,7 +776,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, fini_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®.