Skip to contentSkip to conversation

iommu: setup inclusive mappings before enabling iommu

PATCH In review Roger Pau Monne 5 participants 7 messages Sep 14, 2018 – Sep 20, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iommu: setup inclusive mappings before enabling iommu

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

---
Cc: Suravee Suthikulpanit <[email protected]>
Cc: Brian Woods <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: Dario Faggioli <[email protected]>

---
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  2 ++
 xen/drivers/passthrough/arm/smmu.c          |  2 ++
 xen/drivers/passthrough/iommu.c             | 10 ----------
 xen/drivers/passthrough/vtd/iommu.c         |  2 ++
 xen/drivers/passthrough/x86/iommu.c         |  8 ++++++++
 5 files changed, 14 insertions(+), 10 deletions(-)
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -0
index 330f9ce386..4a633ca940 100644
@@ -300,6 +300,8 @@ static void __hwdom_init amd_iommu_hwdom_init(struct domain *d)
                                         IOMMU_MMIO_REGION_LENGTH - 1)) )
             BUG();
 
+    /* Make sure workarounds are applied (if needed) before adding devices. */
+    arch_iommu_hwdom_init(d);
     setup_hwdom_pci_devices(d, amd_iommu_add_device);
 }
 
xen/drivers/passthrough/arm/smmu.c +2 -0
index 43ece42a50..8f91807b1b 100644
@@ -2736,6 +2736,8 @@ static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
 		printk(XENLOG_WARNING
 		"map-reserved dom0-iommu option is not supported on ARM\n");
 	iommu_hwdom_reserved = 0;
+
+	arch_iommu_hwdom_init(d);
 }
 
 static void arm_smmu_iommu_domain_teardown(struct domain *d)
xen/drivers/passthrough/iommu.c +0 -10
index ee3f523fdf..ae6cf2f0ff 100644
@@ -238,16 +238,6 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     }
 
     hd->platform_ops->hwdom_init(d);
-
-    ASSERT(iommu_hwdom_inclusive != -1 && iommu_hwdom_inclusive != -1);
-    if ( iommu_hwdom_inclusive && !is_pv_domain(d) )
-    {
-        printk(XENLOG_WARNING
-               "IOMMU inclusive mappings are only supported on PV Dom0\n");
-        iommu_hwdom_inclusive = 0;
-    }
-
-    arch_iommu_hwdom_init(d);
 }
 
 void iommu_teardown(struct domain *d)
xen/drivers/passthrough/vtd/iommu.c +2 -0
index adc70f205a..bb422ec58c 100644
@@ -1313,6 +1313,8 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
 
     setup_hwdom_pci_devices(d, setup_hwdom_device);
     setup_hwdom_rmrr(d);
+    /* Make sure workarounds are applied before enabling the IOMMU(s). */
+    arch_iommu_hwdom_init(d);
 
     if ( iommu_flush_all() )
         printk(XENLOG_WARNING VTDPREFIX
xen/drivers/passthrough/x86/iommu.c +8 -0
index 47a078272a..b7c8b5be41 100644
@@ -210,6 +210,14 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
 
     BUG_ON(!is_hardware_domain(d));
 
+    ASSERT(iommu_hwdom_inclusive != -1 && iommu_hwdom_inclusive != -1);
+    if ( iommu_hwdom_inclusive && !is_pv_domain(d) )
+    {
+        printk(XENLOG_WARNING
+               "IOMMU inclusive mappings are only supported on PV Dom0\n");
+        iommu_hwdom_inclusive = 0;
+    }
+
     if ( iommu_hwdom_passthrough )
         return;
 
Signature · 7 lines
2.18.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Tested-by on v2 1/1
#1 lore raw
Quoted 20 lines · Roger Pau Monne

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Quoted 6 lines

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

I tested this too (sorry it took a bit more) and, like v1, it works.

Thanks,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 14.09.18 at 15:58, <[email protected]> wrote:

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Quoted 5 lines

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

With the exception of the ARM aspect (because it's not clear to me why the code removed from iommu_hwdom_init() doesn't need to re-appear in ARM-specific code as well)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 14.09.18 at 15:58, <[email protected]> wrote:

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

Quoted 7 lines
Quoted 2 lines

With the exception of the ARM aspect (because it's not clear to me why the code removed from iommu_hwdom_init() doesn't need to re-appear in ARM-specific code as well)

I guess you mean the following chunk:

- if ( iommu_hwdom_inclusive && !is_pv_domain(d) )
- {
- printk(XENLOG_WARNING
- "IOMMU inclusive mappings are only supported on PV Dom0\n");
- iommu_hwdom_inclusive = 0;
- }

I haven't added it for ARM because iommu_hwdom_inclusive is always set to 0 in the ARM case, so the condition would never match.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Ping: [PATCH v2] iommu: setup inclusive mappings before enabling iommu

In reply to Roger Pau Monne
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 14.09.18 at 15:58, <[email protected]> wrote:

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Quoted 5 lines

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

All,

I realize it's a bit early for a ping, but the master branch is stuck at a regression this patch is supposed to address. May I therefore please ask for timely review of this patch?

Thanks, Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 1/1
#5 lore raw
In reply to Roger Pau Monne
Quoted 23 lines

From: Roger Pau Monne [mailto:[email protected]]
Sent: Friday, September 14, 2018 9:59 PM

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Quoted 5 lines

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v2 1/1
#6 lore raw
In reply to Roger Pau Monne

Hi Roger,

Quoted 20 lines · Roger Pau Monne

Or else it can lead to freezes when enabling the iommu on certain Intel hardware:

[...]
(XEN) ELF: addresses:

(XEN)     virt_base        = 0xffffffff80000000
(XEN)     elf_paddr_offset = 0x0
(XEN)     virt_offset      = 0xffffffff80000000
(XEN)     virt_kstart      = 0xffffffff81000000
(XEN)     virt_kend        = 0xffffffff82953000
(XEN)     virt_entry       = 0xffffffff8274e180
(XEN)     p2m_base         = 0x8000000000

(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x295300 <freeze>

This restores the behavior before commit 66a9274cc3435 that changed the order and enabled the iommu without having the inclusive mappings setup.

Quoted 5 lines

Note that on AMD hardware the order is also changed to add inclusive mappings before adding any devices.

Quoted 96 lines

---
Cc: Suravee Suthikulpanit <[email protected]>
Cc: Brian Woods <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: Dario Faggioli <[email protected]>

---
  xen/drivers/passthrough/amd/pci_amd_iommu.c |  2 ++
  xen/drivers/passthrough/arm/smmu.c          |  2 ++
  xen/drivers/passthrough/iommu.c             | 10 ----------
  xen/drivers/passthrough/vtd/iommu.c         |  2 ++
  xen/drivers/passthrough/x86/iommu.c         |  8 ++++++++
  5 files changed, 14 insertions(+), 10 deletions(-)
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -0
index 330f9ce386..4a633ca940 100644
@@ -300,6 +300,8 @@ static void __hwdom_init amd_iommu_hwdom_init(struct domain *d)
                                          IOMMU_MMIO_REGION_LENGTH - 1)) )
              BUG();
 
+    /* Make sure workarounds are applied (if needed) before adding devices. */
+    arch_iommu_hwdom_init(d);
      setup_hwdom_pci_devices(d, amd_iommu_add_device);
  }
 
xen/drivers/passthrough/arm/smmu.c +2 -0
index 43ece42a50..8f91807b1b 100644
@@ -2736,6 +2736,8 @@ static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
  		printk(XENLOG_WARNING
  		"map-reserved dom0-iommu option is not supported on ARM\n");
  	iommu_hwdom_reserved = 0;
+
+	arch_iommu_hwdom_init(d);
  }
 
  static void arm_smmu_iommu_domain_teardown(struct domain *d)
xen/drivers/passthrough/iommu.c +0 -10
index ee3f523fdf..ae6cf2f0ff 100644
@@ -238,16 +238,6 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
      }
 
      hd->platform_ops->hwdom_init(d);
-
-    ASSERT(iommu_hwdom_inclusive != -1 && iommu_hwdom_inclusive != -1);
-    if ( iommu_hwdom_inclusive && !is_pv_domain(d) )
-    {
-        printk(XENLOG_WARNING
-               "IOMMU inclusive mappings are only supported on PV Dom0\n");
-        iommu_hwdom_inclusive = 0;
-    }
-
-    arch_iommu_hwdom_init(d);
  }
 
  void iommu_teardown(struct domain *d)
xen/drivers/passthrough/vtd/iommu.c +2 -0
index adc70f205a..bb422ec58c 100644
@@ -1313,6 +1313,8 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
 
      setup_hwdom_pci_devices(d, setup_hwdom_device);
      setup_hwdom_rmrr(d);
+    /* Make sure workarounds are applied before enabling the IOMMU(s). */
+    arch_iommu_hwdom_init(d);
 
      if ( iommu_flush_all() )
          printk(XENLOG_WARNING VTDPREFIX
xen/drivers/passthrough/x86/iommu.c +8 -0
index 47a078272a..b7c8b5be41 100644
@@ -210,6 +210,14 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
 
      BUG_ON(!is_hardware_domain(d));
 
+    ASSERT(iommu_hwdom_inclusive != -1 && iommu_hwdom_inclusive != -1);
+    if ( iommu_hwdom_inclusive && !is_pv_domain(d) )
+    {
+        printk(XENLOG_WARNING
+               "IOMMU inclusive mappings are only supported on PV Dom0\n");
+        iommu_hwdom_inclusive = 0;
+    }
+
      if ( iommu_hwdom_passthrough )
          return;
 
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel