Skip to contentSkip to conversation

xen/arm: introduce dummy iommu node for dom0

PATCH In review Sergiy Kibrik 5 participants 6 messages Jan 11, 2022 – Feb 7, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xen/arm: introduce dummy iommu node for dom0

Currently no IOMMU properties are exposed to dom0, thus kernel by default assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no swiotlb services we introduce dummy xen-iommu node in FDT and link protected device nodes to it, using here device tree iommu bindings.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Andrii Anisov <[email protected]>

Changelog:

v3: rebased over staging & remove redundand phandle_iommu attribute, discussion:

	https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01753.html

v2: re-use common iommu dt bindings to let guests know which devices are protected:

	https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html
 xen/arch/arm/domain_build.c           | 42 +++++++++++++++++++++++++++
 xen/include/public/device_tree_defs.h |  1 +
 2 files changed, 43 insertions(+)
xen/arch/arm/domain_build.c +42 -0
index 6931c022a2..b82ba72fac 100644
@@ -845,6 +845,12 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,
         }
     }
 
+    if ( iommu_node && is_iommu_enabled(d) && dt_device_is_protected(node) )
+    {
+        res = fdt_property_cell(kinfo->fdt, "iommus", GUEST_PHANDLE_IOMMU);
+        if ( res )
+            return res;
+    }
     return 0;
 }
 
@@ -1479,6 +1485,38 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
     return res;
 }
 
+static int __init make_iommu_node(const struct domain *d,
+                                  const struct kernel_info *kinfo)
+{
+    const char compat[] = "xen,iommu-el2-v1";
+    int res;
+
+    if ( !is_iommu_enabled(d) )
+        return 0;
+
+    dt_dprintk("Create iommu node\n");
+
+    res = fdt_begin_node(kinfo->fdt, "xen-iommu");
+    if ( res )
+        return res;
+
+    res = fdt_property(kinfo->fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "#iommu-cells", 0);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "phandle", GUEST_PHANDLE_IOMMU);
+
+    res = fdt_end_node(kinfo->fdt);
+    if ( res )
+        return res;
+
+    return res;
+}
+
 static int __init make_gic_node(const struct domain *d, void *fdt,
                                 const struct dt_device_node *node)
 {
@@ -2127,6 +2165,10 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
         if ( res )
             return res;
 
+        res = make_iommu_node(d, kinfo);
+        if ( res )
+            return res;
+
         res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->mem);
         if ( res )
             return res;
xen/include/public/device_tree_defs.h +1 -0
index 209d43de3f..df58944bd0 100644
@@ -7,6 +7,7 @@
  * onwards. Reserve a high value for the GIC phandle.
  */
 #define GUEST_PHANDLE_GIC (65000)
+#define GUEST_PHANDLE_IOMMU (GUEST_PHANDLE_GIC + 1)
 
 #define GUEST_ROOT_ADDRESS_CELLS 2
 #define GUEST_ROOT_SIZE_CELLS 2
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 9 lines · Sergiy Kibrik

Currently no IOMMU properties are exposed to dom0, thus kernel by default assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no swiotlb services we introduce dummy xen-iommu node in FDT and link protected device nodes to it, using here device tree iommu bindings.

I think the patch looks good. I have no further comments on the code:

Before committing it to the Xen tree, I'd like to wait that the Linux side, especially the change to Documentation/devicetree/bindings/arm/xen.txt, is acked.

Quoted 101 lines

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Andrii Anisov <[email protected]>

Changelog:

v3: rebased over staging & remove redundand phandle_iommu attribute, discussion:

	https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01753.html

v2: re-use common iommu dt bindings to let guests know which devices are protected:

	https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html
 xen/arch/arm/domain_build.c           | 42 +++++++++++++++++++++++++++
 xen/include/public/device_tree_defs.h |  1 +
 2 files changed, 43 insertions(+)
xen/arch/arm/domain_build.c +42 -0
index 6931c022a2..b82ba72fac 100644
@@ -845,6 +845,12 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,
         }
     }
 
+    if ( iommu_node && is_iommu_enabled(d) && dt_device_is_protected(node) )
+    {
+        res = fdt_property_cell(kinfo->fdt, "iommus", GUEST_PHANDLE_IOMMU);
+        if ( res )
+            return res;
+    }
     return 0;
 }
 
@@ -1479,6 +1485,38 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
     return res;
 }
 
+static int __init make_iommu_node(const struct domain *d,
+                                  const struct kernel_info *kinfo)
+{
+    const char compat[] = "xen,iommu-el2-v1";
+    int res;
+
+    if ( !is_iommu_enabled(d) )
+        return 0;
+
+    dt_dprintk("Create iommu node\n");
+
+    res = fdt_begin_node(kinfo->fdt, "xen-iommu");
+    if ( res )
+        return res;
+
+    res = fdt_property(kinfo->fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "#iommu-cells", 0);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "phandle", GUEST_PHANDLE_IOMMU);
+
+    res = fdt_end_node(kinfo->fdt);
+    if ( res )
+        return res;
+
+    return res;
+}
+
 static int __init make_gic_node(const struct domain *d, void *fdt,
                                 const struct dt_device_node *node)
 {
@@ -2127,6 +2165,10 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
         if ( res )
             return res;
 
+        res = make_iommu_node(d, kinfo);
+        if ( res )
+            return res;
+
         res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->mem);
         if ( res )
             return res;
xen/include/public/device_tree_defs.h +1 -0
index 209d43de3f..df58944bd0 100644
@@ -7,6 +7,7 @@
  * onwards. Reserve a high value for the GIC phandle.
  */
 #define GUEST_PHANDLE_GIC (65000)
+#define GUEST_PHANDLE_IOMMU (GUEST_PHANDLE_GIC + 1)
 
 #define GUEST_ROOT_ADDRESS_CELLS 2
 #define GUEST_ROOT_SIZE_CELLS 2
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#2 lore raw
In reply to Sergiy Kibrik

Hi,

Quoted 11 lines · Sergiy Kibrik

Currently no IOMMU properties are exposed to dom0, thus kernel by default assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no swiotlb services we introduce dummy xen-iommu node in FDT and link protected device nodes to it, using here device tree iommu bindings.

Regards,
Rahul

Quoted 102 lines

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Andrii Anisov <[email protected]>

Changelog:

v3: rebased over staging & remove redundand phandle_iommu attribute, discussion:

	https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01753.html

v2: re-use common iommu dt bindings to let guests know which devices are protected:

	https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html

xen/arch/arm/domain_build.c | 42 +++++++++++++++++++++++++++
xen/include/public/device_tree_defs.h | 1 +

2 files changed, 43 insertions(+)
xen/arch/arm/domain_build.c +42 -0
index 6931c022a2..b82ba72fac 100644
@@ -845,6 +845,12 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,
        }
    }
 
+    if ( iommu_node && is_iommu_enabled(d) && dt_device_is_protected(node) )
+    {
+        res = fdt_property_cell(kinfo->fdt, "iommus", GUEST_PHANDLE_IOMMU);
+        if ( res )
+            return res;
+    }
    return 0;
 }
 
@@ -1479,6 +1485,38 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
    return res;
 }
 
+static int __init make_iommu_node(const struct domain *d,
+                                  const struct kernel_info *kinfo)
+{
+    const char compat[] = "xen,iommu-el2-v1";
+    int res;
+
+    if ( !is_iommu_enabled(d) )
+        return 0;
+
+    dt_dprintk("Create iommu node\n");
+
+    res = fdt_begin_node(kinfo->fdt, "xen-iommu");
+    if ( res )
+        return res;
+
+    res = fdt_property(kinfo->fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "#iommu-cells", 0);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "phandle", GUEST_PHANDLE_IOMMU);
+
+    res = fdt_end_node(kinfo->fdt);
+    if ( res )
+        return res;
+
+    return res;
+}
+
 static int __init make_gic_node(const struct domain *d, void *fdt,
                                const struct dt_device_node *node)
 {
@@ -2127,6 +2165,10 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
        if ( res )
            return res;
 
+        res = make_iommu_node(d, kinfo);
+        if ( res )
+            return res;
+
        res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->mem);
        if ( res )
            return res;
xen/include/public/device_tree_defs.h +1 -0
index 209d43de3f..df58944bd0 100644
@@ -7,6 +7,7 @@
 * onwards. Reserve a high value for the GIC phandle.
 */
 #define GUEST_PHANDLE_GIC (65000)
+#define GUEST_PHANDLE_IOMMU (GUEST_PHANDLE_GIC + 1)
 
 #define GUEST_ROOT_ADDRESS_CELLS 2
 #define GUEST_ROOT_SIZE_CELLS 2
Signature · 1 line
2.25.1
#3 lore raw
Quoted 14 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Rahul Singh
Sent: 2022年1月14日 16:22
To: Sergiy Kibrik <[email protected]>
Cc: xen-devel <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Oleksandr Tyshchenko <[email protected]>; Andrii Anisov <[email protected]>
Subject: Re: [XEN PATCH v3] xen/arm: introduce dummy iommu node for dom0

Quoted 11 lines

Hi,

Quoted 1 line

On 11 Jan 2022, at 11:26 am, Sergiy Kibrik <[email protected]>

Quoted 2 lines · wrote:

Currently no IOMMU properties are exposed to dom0, thus kernel by

default

Quoted 4 lines

assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no

[Jiamei Xie]
behing? Typo

Best wishes
Jiamei Xie

Quoted 127 lines

swiotlb

Quoted 1 line

services we introduce dummy xen-iommu node in FDT and link protected

device

Quoted 3 lines

nodes to it, using here device tree iommu bindings.

Regards,
Rahul

Quoted 10 lines

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Andrii Anisov <[email protected]>

Changelog:

v3: rebased over staging & remove redundand phandle_iommu attribute,

discussion:

Quoted 1 line
	https://lists.xenproject.org/archives/html/xen-devel/2021-

12/msg01753.html

Quoted 2 lines

v2: re-use common iommu dt bindings to let guests know which devices

are protected:

Quoted 1 line
	https://lists.xenproject.org/archives/html/xen-devel/2021-

10/msg00073.html

Quoted 2 lines

xen/arch/arm/domain_build.c | 42

+++++++++++++++++++++++++++

xen/arch/arm/domain_build.c static int __init write_properties(struct domain *d,

Quoted 8 lines

xen/include/public/device_tree_defs.h | 1 +

2 files changed, 43 insertions(+)
xen/arch/arm/domain_build.c +0 -0
index 6931c022a2..b82ba72fac 100644
@@ -845,6 +845,12 @@ static int __init write_properties(struct domain *d,

struct kernel_info *kinfo,

xen/arch/arm/domain_build.c static int __init write_properties(struct domain *d, · line 848

Quoted 4 lines
xen/arch/arm/domain_build.c +1 -0
        }
    }
 
+    if ( iommu_node && is_iommu_enabled(d) &&

dt_device_is_protected(node) )

xen/arch/arm/domain_build.c static int __init write_properties(struct domain *d, · line 850

Quoted 2 lines
xen/arch/arm/domain_build.c +2 -0
+    {
+        res = fdt_property_cell(kinfo->fdt, "iommus",

GUEST_PHANDLE_IOMMU);

xen/arch/arm/domain_build.c static int __init make_cpus_node(const struct

Quoted 7 lines
xen/arch/arm/domain_build.c +3 -0
+        if ( res )
+            return res;
+    }
    return 0;
 }
 
@@ -1479,6 +1485,38 @@ static int __init make_cpus_node(const struct

domain *d, void *fdt)

Quoted 17 lines
xen/arch/arm/domain_build.c +14 -0
    return res;
 }
 
+static int __init make_iommu_node(const struct domain *d,
+                                  const struct kernel_info *kinfo)
+{
+    const char compat[] = "xen,iommu-el2-v1";
+    int res;
+
+    if ( !is_iommu_enabled(d) )
+        return 0;
+
+    dt_dprintk("Create iommu node\n");
+
+    res = fdt_begin_node(kinfo->fdt, "xen-iommu");
+    if ( res )
+        return res;

xen/arch/arm/domain_build.c static int __init make_cpus_node(const struct domain *d, void *fdt)

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+
+    res = fdt_property(kinfo->fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "#iommu-cells", 0);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "phandle",

GUEST_PHANDLE_IOMMU);

xen/arch/arm/domain_build.c static int __init handle_node(struct domain *d,

Quoted 12 lines
xen/arch/arm/domain_build.c +8 -0
+
+    res = fdt_end_node(kinfo->fdt);
+    if ( res )
+        return res;
+
+    return res;
+}
+
 static int __init make_gic_node(const struct domain *d, void *fdt,
                                const struct dt_device_node *node)
 {
@@ -2127,6 +2165,10 @@ static int __init handle_node(struct domain *d,

struct kernel_info *kinfo,

Quoted 11 lines
xen/arch/arm/domain_build.c +4 -0
        if ( res )
            return res;
 
+        res = make_iommu_node(d, kinfo);
+        if ( res )
+            return res;
+
        res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo-
 mem);
        if ( res )
            return res;

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/include/public/device_tree_defs.h

Quoted 15 lines

index 209d43de3f..df58944bd0 100644

xen/include/public/device_tree_defs.h +1 -1
@@ -7,6 +7,7 @@
 * onwards. Reserve a high value for the GIC phandle.
 */
 #define GUEST_PHANDLE_GIC (65000)
+#define GUEST_PHANDLE_IOMMU (GUEST_PHANDLE_GIC + 1)
 
 #define GUEST_ROOT_ADDRESS_CELLS 2
 #define GUEST_ROOT_SIZE_CELLS 2
--

2.25.1

#4 lore raw
Quoted 9 lines
Quoted 6 lines
Quoted 1 line

Currently no IOMMU properties are exposed to dom0, thus kernel by

default

Quoted 4 lines

assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no

[Jiamei Xie]
behing? Typo

Oops, typo indeed.
Thank you!

- Sergiy

#5 lore raw
In reply to Sergiy Kibrik

Hi,

Quoted 33 lines · Sergiy Kibrik

Currently no IOMMU properties are exposed to dom0, thus kernel by default assumes no protection and enables swiotlb-xen, which leads to costly and unnecessary buffers bouncing.

To let kernel know which device is behing IOMMU and hence needs no swiotlb services we introduce dummy xen-iommu node in FDT and link protected device nodes to it, using here device tree iommu bindings.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Andrii Anisov <[email protected]>

Changelog:

v3: rebased over staging & remove redundand phandle_iommu attribute, discussion:

	https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01753.html

v2: re-use common iommu dt bindings to let guests know which devices are protected:

	https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html
  xen/arch/arm/domain_build.c           | 42 +++++++++++++++++++++++++++
  xen/include/public/device_tree_defs.h |  1 +
  2 files changed, 43 insertions(+)
xen/arch/arm/domain_build.c +0 -0
index 6931c022a2..b82ba72fac 100644

xen/arch/arm/domain_build.c static int __init write_properties(struct domain *d, struct kernel_info *kinfo, · line 848

Quoted 4 lines
xen/arch/arm/domain_build.c +1 -0
@@ -845,6 +845,12 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,
          }
      }
 
+    if ( iommu_node && is_iommu_enabled(d) && dt_device_is_protected(node) )

I think it should be sufficient to check dt_device_is_protected() because it is set it means that device behind an IOMMU known by Xen. So iommu_node will always be valid.

Furthermore, you can't assign to dom0 a device that was protected with enabling the IOMMU for the domain.

Quoted 26 lines
xen/arch/arm/domain_build.c +19 -0
+    {
+        res = fdt_property_cell(kinfo->fdt, "iommus", GUEST_PHANDLE_IOMMU);
+        if ( res )
+            return res;
+    }
      return 0;
  }
 
@@ -1479,6 +1485,38 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
      return res;
  }
 
+static int __init make_iommu_node(const struct domain *d,
+                                  const struct kernel_info *kinfo)
+{
+    const char compat[] = "xen,iommu-el2-v1";
+    int res;
+
+    if ( !is_iommu_enabled(d) )
+        return 0;
+
+    dt_dprintk("Create iommu node\n");
+
+    res = fdt_begin_node(kinfo->fdt, "xen-iommu");
+    if ( res )
+        return res;

xen/arch/arm/domain_build.c static int __init make_cpus_node(const struct domain *d, void *fdt) · line 1511

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+
+    res = fdt_property(kinfo->fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "#iommu-cells", 0);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(kinfo->fdt, "phandle", GUEST_PHANDLE_IOMMU);

Please don't hardocode the phandle for the IOMMU. Instead we should use one for an IOMMU that is used by Xen.

This will reduce the risk to use a phandle that could be possibly used in the host Device-Tree.

Cheers,

Signature · 1 line
Julien Grall