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

[XEN][PATCH v11 11/20] xen/iommu: Introduce iommu_remove_dt_device()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Thu, 31 Aug 2023 21:59:38 -0700
  • 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
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=xshnPL3bDlSXz1SSqrZ2OojIbY+USaVA9VSd3/Ty7gY=; b=Gz3v70KIQfqQT43Am88qqO9mc8Nvl8+3g47znZtYLbQ5okhw3ybDNTAqtTlPpC/NPl+xWTIADyFH/mTwcTTcT8qQOH93btctB0D5fEP7ePWrf7aVFaONzQr762AmB0yeW+IsmTER6NRUJKdwcboslT5xJhHJOgOROsW80Si4QIGul63TWPLuNWqDGCHABl/eUU/pFlUEuw+yH7JV2Tq3iAD19gte1w9zCi8Djd4KR/6QZizVDwefLG+dtrLZGx6wWOHV3SYBxKslt5rjNaGt7a9/pTeKhTLN9hODXDmkt0+d1XWog60C693FkdyXVsQ8VNd/F8MllqwuEVSUsOIFQQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNO8iPyieYQEIv4Pb0LITNx5IHz7P6nm5Ez1dA+zn8SRTuRbGxYAGdyEh4ICZJGvF+w/tYsKr1eCp1I2qyL1HQ3pnjTxazYaxIHvNzXiOLrcJiZZYq58tAqFIoZuh9usv1C+ZwaHqa2g7xU1v6ikFvMBprsn8APMtDoN2h/V4SAYyQnmyaK3J31vQHuqiAjQ7Xw5ZB9HXhToI4M9C/CxuHrw3QFuymFQm+1AedNWcbr7/i+iplMUVaU89YYzA6t8GI4iTBteWLcRysrAUxdMEZf2orA58UvmHrqDSFX/Q1AIa6mp8elGjzexgipT/1JNfFiVs3TSeFw4lSsB5Q8Dng==
  • Cc: <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>, <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 01 Sep 2023 05:12:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Remove master device from the IOMMU. This will be helpful when removing the
overlay nodes using dynamic programming during run time.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>

---
Changes from v10:
    Add comment regarding return values of iommu_remove_dt_device().
    Add ASSERT to check if is_protected is removed or not.
Changes from v7:
    Add check if IOMMU is enabled.
    Fix indentation of fail.
---
---
 xen/drivers/passthrough/device_tree.c | 43 +++++++++++++++++++++++++++
 xen/include/xen/iommu.h               | 10 +++++++
 2 files changed, 53 insertions(+)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index 687c61e7da..80f6efc606 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -127,6 +127,49 @@ int iommu_release_dt_devices(struct domain *d)
     return 0;
 }
 
+int iommu_remove_dt_device(struct dt_device_node *np)
+{
+    const struct iommu_ops *ops = iommu_get_ops();
+    struct device *dev = dt_to_dev(np);
+    int rc;
+
+    if ( !iommu_enabled )
+        return 1;
+
+    if ( !ops )
+        return -EOPNOTSUPP;
+
+    spin_lock(&dtdevs_lock);
+
+    if ( iommu_dt_device_is_assigned_locked(np) )
+    {
+        rc = -EBUSY;
+        goto fail;
+    }
+
+    if ( !ops->remove_device )
+    {
+        rc = -EOPNOTSUPP;
+        goto fail;
+    }
+
+    /*
+     * De-register the device from the IOMMU driver.
+     * The driver is responsible for removing is_protected flag.
+     */
+    rc = ops->remove_device(0, dev);
+
+    if ( !rc )
+    {
+        ASSERT(!dt_device_is_protected(np));
+        iommu_fwspec_free(dev);
+    }
+
+ fail:
+    spin_unlock(&dtdevs_lock);
+    return rc;
+}
+
 int iommu_add_dt_device(struct dt_device_node *np)
 {
     const struct iommu_ops *ops = iommu_get_ops();
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index a18b68e247..84bd77395e 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -235,6 +235,16 @@ int iommu_add_dt_device(struct dt_device_node *np);
 int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
 
+/*
+ * Helper to remove master device from the IOMMU.
+ *
+ * Return values:
+ *  0 : device is de-registerd from IOMMU.
+ * <0 : error while removing the device from IOMMU.
+ * >0 : IOMMU is not enabled/present or device is not connected to it.
+ */
+int iommu_remove_dt_device(struct dt_device_node *np);
+
 #endif /* HAS_DEVICE_TREE */
 
 struct page_info;
-- 
2.17.1




 


Rackspace

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