Skip to contentSkip to conversation

VT-d: make dom0-strict work with buggy firmware

PATCH Superseded Paul Durrant 3 participants 9 messages Jun 8, 2018 – Jun 12, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover VT-d: make dom0-strict work with buggy firmware

When dom0-strict mode is enabled the iommu_inclusive_mapping workaround for firmware with undeclared RMRRs is rendered useless. This series fixes the problem.

Paul Durrant (2):
VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity
VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

 docs/misc/xen-command-line.markdown   |  6 ++++--
 xen/drivers/passthrough/iommu.c       |  2 +-
 xen/drivers/passthrough/vtd/iommu.c   |  2 +-
 xen/drivers/passthrough/vtd/x86/vtd.c | 34 +++++++++++++++++++++++-----------
 xen/include/xen/iommu.h               |  2 +-
 5 files changed, 30 insertions(+), 16 deletions(-)
Signature · 7 lines
2.11.0


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

PATCH 1/2 VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

It is hard to reconcile the comment at the top of the loop in vtd_set_hwdom_mapping() with the if statement following it. This patch re-phrases the logic, preserving the semantics, but making it easier to read.

The patch also modifies the Xen command line documentation to make it clear that iommu_inclusive_mapping only applies to pages up to and including the 4GB boundary.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Kevin Tian <[email protected]>

---
 docs/misc/xen-command-line.markdown   |  4 ++--
 xen/drivers/passthrough/vtd/x86/vtd.c | 26 +++++++++++++++-----------
 2 files changed, 17 insertions(+), 13 deletions(-)
docs/misc/xen-command-line.markdown +2 -2
index 8712a833a2..6beb28dada 100644
@@ -1212,8 +1212,8 @@ wait descriptor timed out', try increasing this value.
 
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
-option all pages not marked as unusable in the E820 table will get a mapping
-established.
+option all pages up to and including 4GB, not marked as unusable in the
+E820 table, will get a mapping established.
 
 ### irq\_ratelimit (x86)
 > `= <integer>`
xen/drivers/passthrough/vtd/x86/vtd.c +15 -11
index 88a60b3307..5c440ba183 100644
@@ -118,22 +118,26 @@ void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
 
     for ( i = 0; i < top; i++ )
     {
+        unsigned long pfn = pdx_to_pfn(i);
+        bool map;
         int rc = 0;
 
         /*
-         * Set up 1:1 mapping for dom0. Default to use only conventional RAM
-         * areas and let RMRRs include needed reserved regions. When set, the
-         * inclusive mapping maps in everything below 4GB except unusable
-         * ranges.
+         * Set up 1:1 mapping for dom0. Default to include only
+         * conventional RAM areas and let RMRRs include needed reserved
+         * regions. When set, the inclusive mapping maps in every pfn up
+         * to and including 4GB except those that fall in unusable ranges.
          */
-        unsigned long pfn = pdx_to_pfn(i);
+        if ( iommu_inclusive_mapping &&
+             pfn <= (0xffffffffUL >> PAGE_SHIFT) )
+            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
+        else
+            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
+
+        if ( !map )
+            continue;
 
-        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) ?
-             (!mfn_valid(_mfn(pfn)) ||
-              !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL)) :
-             iommu_inclusive_mapping ?
-             page_is_ram_type(pfn, RAM_TYPE_UNUSABLE) :
-             !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
+        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) && !mfn_valid(_mfn(pfn)) )
             continue;
 
         /* Exclude Xen bits */
Signature · 7 lines
2.11.0


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

Re: [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this value. · line 1216

Quoted 12 lines · Paul Durrant
docs/misc/xen-command-line.markdown +2 -2
index 8712a833a2..6beb28dada 100644
@@ -1212,8 +1212,8 @@ wait descriptor timed out', try increasing this value.
 
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
-option all pages not marked as unusable in the E820 table will get a mapping
-established.
+option all pages up to and including 4GB, not marked as unusable in the
+E820 table, will get a mapping established.

Sorry, I've reviewed the patches in the wrong order. You can ignore the comments I've made related to this in patch 2.

Quoted 17 lines
docs/misc/xen-command-line.markdown +0 -0
 ### irq\_ratelimit (x86)
 > `= <integer>`
xen/drivers/passthrough/vtd/x86/vtd.c +2 -2
index 88a60b3307..5c440ba183 100644
@@ -118,22 +118,26 @@ void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
 
     for ( i = 0; i < top; i++ )
     {
+        unsigned long pfn = pdx_to_pfn(i);
+        bool map;
         int rc = 0;
 
         /*
-         * Set up 1:1 mapping for dom0. Default to use only conventional RAM
-         * areas and let RMRRs include needed reserved regions. When set, the

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) · line 132

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +6 -3
-         * inclusive mapping maps in everything below 4GB except unusable
-         * ranges.
+         * Set up 1:1 mapping for dom0. Default to include only
+         * conventional RAM areas and let RMRRs include needed reserved
+         * regions. When set, the inclusive mapping maps in every pfn up
+         * to and including 4GB except those that fall in unusable ranges.
          */
-        unsigned long pfn = pdx_to_pfn(i);
+        if ( iommu_inclusive_mapping &&
+             pfn <= (0xffffffffUL >> PAGE_SHIFT) )

Please use GB(4) here for clarity.

Quoted 4 lines
xen/drivers/passthrough/vtd/x86/vtd.c +4 -0
+            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
+        else
+            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
+

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) · line 140

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +3 -6
+        if ( !map )
+            continue;
 
-        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) ?
-             (!mfn_valid(_mfn(pfn)) ||
-              !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL)) :
-             iommu_inclusive_mapping ?
-             page_is_ram_type(pfn, RAM_TYPE_UNUSABLE) :
-             !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
+        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) && !mfn_valid(_mfn(pfn)) )

I would maybe do this check before the page_is_ram_type one, so that you can discard invalid mfns earlier.

Thanks, Roger.

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

#3 lore raw

Re: [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

Quoted 65 lines

-----Original Message-----
From: Roger Pau Monne
Sent: 11 June 2018 11:31
To: Paul Durrant <[email protected]>
Cc: [email protected]; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

docs/misc/xen-

Quoted 1 line · Paul Durrant
docs/misc/xen- renamed from docs/misc/xen-command-line.markdown +0 -0

command-line.markdown

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this

Quoted 4 lines

index 8712a833a2..6beb28dada 100644

docs/misc/xen-command-line.markdown +0 -0
@@ -1212,8 +1212,8 @@ wait descriptor timed out', try increasing this

value.

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this · line 1213

Quoted 3 lines
docs/misc/xen-command-line.markdown +0 -0
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with

this

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this · line 1214

Quoted 1 line
docs/misc/xen-command-line.markdown +0 -1
-option all pages not marked as unusable in the E820 table will get a

mapping

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this value. · line 1216

Quoted 3 lines
docs/misc/xen-command-line.markdown +2 -1
-established.
+option all pages up to and including 4GB, not marked as unusable in the
+E820 table, will get a mapping established.

Sorry, I've reviewed the patches in the wrong order. You can ignore the comments I've made related to this in patch 2.

Review

Quoted 3 lines
docs/misc/xen-command-line.markdown +0 -0
 ### irq\_ratelimit (x86)
 > `= <integer>`
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/x86/vtd.c

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init

Quoted 4 lines

index 88a60b3307..5c440ba183 100644

xen/drivers/passthrough/vtd/x86/vtd.c +0 -0
@@ -118,22 +118,26 @@ void __hwdom_init

vtd_set_hwdom_mapping(struct domain *d)

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +2 -2
     for ( i = 0; i < top; i++ )
     {
+        unsigned long pfn = pdx_to_pfn(i);
+        bool map;
         int rc = 0;
 
         /*
-         * Set up 1:1 mapping for dom0. Default to use only conventional RAM
-         * areas and let RMRRs include needed reserved regions. When set,

the

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) · line 132

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +6 -3
-         * inclusive mapping maps in everything below 4GB except unusable
-         * ranges.
+         * Set up 1:1 mapping for dom0. Default to include only
+         * conventional RAM areas and let RMRRs include needed reserved
+         * regions. When set, the inclusive mapping maps in every pfn up
+         * to and including 4GB except those that fall in unusable ranges.
          */
-        unsigned long pfn = pdx_to_pfn(i);
+        if ( iommu_inclusive_mapping &&
+             pfn <= (0xffffffffUL >> PAGE_SHIFT) )
Quoted 1 line

Please use GB(4) here for clarity.

That would be better. I left it since that's what the old code used but it I'll change this one and the one below.

Quoted 16 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/x86/vtd.c +4 -0
+            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
+        else
+            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
+

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) · line 140

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +3 -6
+        if ( !map )
+            continue;
 
-        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) ?
-             (!mfn_valid(_mfn(pfn)) ||
-              !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL)) :
-             iommu_inclusive_mapping ?
-             page_is_ram_type(pfn, RAM_TYPE_UNUSABLE) :
-             !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
+        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) && !mfn_valid(_mfn(pfn)) )
Quoted 2 lines

I would maybe do this check before the page_is_ram_type one, so that you can discard invalid mfns earlier.

True.

Paul

Quoted 2 lines

Thanks, Roger.

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

#4 lore raw

Re: [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

Quoted 82 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 11 June 2018 11:35
To: Roger Pau Monne <[email protected]>
Cc: Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Tim (Xen.org) <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Ian Jackson <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

Quoted 13 lines

-----Original Message-----
From: Roger Pau Monne
Sent: 11 June 2018 11:31
To: Paul Durrant <[email protected]>
Cc: [email protected]; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/2] VT-d: re-phrase logic in vtd_set_hwdom_mapping() for clarity

Quoted 10 lines

docs/misc/xen-

Quoted 1 line · Paul Durrant
docs/misc/xen- renamed from docs/misc/xen-command-line.markdown +0 -0

command-line.markdown

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this

Quoted 4 lines

index 8712a833a2..6beb28dada 100644

docs/misc/xen-command-line.markdown +0 -0
@@ -1212,8 +1212,8 @@ wait descriptor timed out', try increasing this

value.

Quoted 2 lines
docs/misc/xen-command-line.markdown +0 -0
 Use this to work around firmware issues providing incorrect RMRR

entries.

Quoted 1 line

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this · line 1213

Quoted 1 line
docs/misc/xen-command-line.markdown +0 -0
 Rather than only mapping RAM pages for IOMMU accesses for Dom0,

with

Quoted 14 lines

this

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this · line 1214

Quoted 1 line
docs/misc/xen-command-line.markdown +0 -1
-option all pages not marked as unusable in the E820 table will get a

mapping

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this value. · line 1216

Quoted 3 lines
docs/misc/xen-command-line.markdown +2 -1
-established.
+option all pages up to and including 4GB, not marked as unusable in the
+E820 table, will get a mapping established.

Sorry, I've reviewed the patches in the wrong order. You can ignore the comments I've made related to this in patch 2.

Review

Quoted 3 lines
docs/misc/xen-command-line.markdown +0 -0
 ### irq\_ratelimit (x86)
 > `= <integer>`
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/x86/vtd.c

Quoted 14 lines

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init

Quoted 4 lines

index 88a60b3307..5c440ba183 100644

xen/drivers/passthrough/vtd/x86/vtd.c +0 -0
@@ -118,22 +118,26 @@ void __hwdom_init

vtd_set_hwdom_mapping(struct domain *d)

Quoted 9 lines
xen/drivers/passthrough/vtd/x86/vtd.c +2 -1
     for ( i = 0; i < top; i++ )
     {
+        unsigned long pfn = pdx_to_pfn(i);
+        bool map;
         int rc = 0;
 
         /*
-         * Set up 1:1 mapping for dom0. Default to use only conventional

RAM

Quoted 13 lines

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init · line 124

Quoted 1 line
xen/drivers/passthrough/vtd/x86/vtd.c +0 -1
-         * areas and let RMRRs include needed reserved regions. When set,

the

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +6 -3
-         * inclusive mapping maps in everything below 4GB except unusable
-         * ranges.
+         * Set up 1:1 mapping for dom0. Default to include only
+         * conventional RAM areas and let RMRRs include needed reserved
+         * regions. When set, the inclusive mapping maps in every pfn up
+         * to and including 4GB except those that fall in unusable ranges.
          */
-        unsigned long pfn = pdx_to_pfn(i);
+        if ( iommu_inclusive_mapping &&
+             pfn <= (0xffffffffUL >> PAGE_SHIFT) )
Quoted 4 lines
Quoted 1 line

Please use GB(4) here for clarity.

That would be better. I left it since that's what the old code used but it I'll change this one and the one below.

Actually since you pointed this out that my reasoning before was wrong. Because the comparison was with 0xffffffff >> PAGE_SHIFT (i.e. GB(4) - 1), the inclusive map does not include GB(4) itself... so the documentation was correct.

Paul

Quoted 25 lines
Quoted 17 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/x86/vtd.c +4 -0
+            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
+        else
+            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
+

xen/drivers/passthrough/vtd/x86/vtd.c void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) · line 140

Quoted 10 lines
xen/drivers/passthrough/vtd/x86/vtd.c +3 -6
+        if ( !map )
+            continue;
 
-        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) ?
-             (!mfn_valid(_mfn(pfn)) ||
-              !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL)) :
-             iommu_inclusive_mapping ?
-             page_is_ram_type(pfn, RAM_TYPE_UNUSABLE) :
-             !page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
+        if ( pfn > (0xffffffffUL >> PAGE_SHIFT) && !mfn_valid(_mfn(pfn)) )
Quoted 2 lines

I would maybe do this check before the page_is_ram_type one, so that you can discard invalid mfns earlier.

True.

Paul

Quoted 1 line
Quoted 6 lines
Quoted 1 line

Thanks, Roger.

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

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

#5 lore raw

PATCH 2/2 VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

In reply to Paul Durrant

The documentation for the iommu_inclusive_mapping Xen command line option states:

"Use this to work around firmware issues providing incorrect RMRR entries"

Unfortunately this workaround does not function correctly if the dom0-strict iommu option is also specified.

The documentation goes on to say:

"Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
option all pages up to and including 4GB, not marked as unusable in the E820 table, will get a mapping established."

This patch modifies the VT-d hardware domain initialization code such that the workaround will continue to function in dom0-strict mode, by mapping all pages not marked as unusable *unless* they are RAM pages not assigned to dom0.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Kevin Tian <[email protected]>

---
 docs/misc/xen-command-line.markdown   | 4 +++-
 xen/drivers/passthrough/iommu.c       | 2 +-
 xen/drivers/passthrough/vtd/iommu.c   | 2 +-
 xen/drivers/passthrough/vtd/x86/vtd.c | 8 ++++++++
 xen/include/xen/iommu.h               | 2 +-
 5 files changed, 14 insertions(+), 4 deletions(-)
docs/misc/xen-command-line.markdown +3 -1
index 6beb28dada..97768f1633 100644
@@ -1213,7 +1213,9 @@ wait descriptor timed out', try increasing this value.
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
 option all pages up to and including 4GB, not marked as unusable in the
-E820 table, will get a mapping established.
+E820 table, will get a mapping established. Note that if `dom0-strict`
+mode is enabled then conventional RAM pages not assigned to dom0 will not
+be mapped.
 
 ### irq\_ratelimit (x86)
 > `= <integer>`
xen/drivers/passthrough/iommu.c +1 -1
index 2c44fabf99..a483212356 100644
@@ -52,7 +52,7 @@ custom_param("iommu", parse_iommu_param);
 bool_t __initdata iommu_enable = 1;
 bool_t __read_mostly iommu_enabled;
 bool_t __read_mostly force_iommu;
-bool_t __hwdom_initdata iommu_dom0_strict;
+bool_t __read_mostly iommu_dom0_strict;
 bool_t __read_mostly iommu_verbose;
 bool_t __read_mostly iommu_workaround_bios_bug;
 bool_t __read_mostly iommu_igfx = 1;
xen/drivers/passthrough/vtd/iommu.c +1 -1
index 08bce92d40..e3f043288b 100644
@@ -1304,7 +1304,7 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
 {
     struct acpi_drhd_unit *drhd;
 
-    if ( !iommu_passthrough && !need_iommu(d) )
+    if ( !iommu_passthrough )
     {
         /* Set up 1:1 page table for hardware domain. */
         vtd_set_hwdom_mapping(d);
xen/drivers/passthrough/vtd/x86/vtd.c +8 -0
index 5c440ba183..42a8c7901d 100644
@@ -144,6 +144,14 @@ void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
         if ( xen_in_range(pfn) )
             continue;
 
+        /*
+         * If dom0-strict mode is enabled then exclude conventional RAM
+         * and let the common code map dom0's pages.
+         */
+        if ( iommu_dom0_strict &&
+             page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
+            continue;
+
         tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
         for ( j = 0; j < tmp; j++ )
         {
xen/include/xen/iommu.h +1 -1
index 33c8b221dc..6b42e3b876 100644
@@ -29,7 +29,7 @@
 #include <asm/iommu.h>
 
 extern bool_t iommu_enable, iommu_enabled;
-extern bool_t force_iommu, iommu_verbose;
+extern bool_t force_iommu, iommu_dom0_strict, iommu_verbose;
 extern bool_t iommu_workaround_bios_bug, iommu_igfx, iommu_passthrough;
 extern bool_t iommu_snoop, iommu_qinval, iommu_intremap, iommu_intpost;
 extern bool_t iommu_hap_pt_share;
Signature · 7 lines
2.11.0


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

Re: [PATCH 2/2] VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

Quoted 5 lines · Paul Durrant

The documentation for the iommu_inclusive_mapping Xen command line option states:

"Use this to work around firmware issues providing incorrect RMRR entries"

Quoted 8 lines

Unfortunately this workaround does not function correctly if the dom0-strict iommu option is also specified.

The documentation goes on to say:

"Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
option all pages up to and including 4GB, not marked as unusable in the E820 table, will get a mapping established."

My version of xen-command-line.markdown says:

"Use this to work around firmware issues providing incorrect RMRR entries. Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this option all pages not marked as unusable in the E820 table will get a mapping established."

I think the documentation or the code needs fixing, because the current code does indeed only map up to 4GB.

Quoted 46 lines

This patch modifies the VT-d hardware domain initialization code such that the workaround will continue to function in dom0-strict mode, by mapping all pages not marked as unusable *unless* they are RAM pages not assigned to dom0.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Kevin Tian <[email protected]>

---
 docs/misc/xen-command-line.markdown   | 4 +++-
 xen/drivers/passthrough/iommu.c       | 2 +-
 xen/drivers/passthrough/vtd/iommu.c   | 2 +-
 xen/drivers/passthrough/vtd/x86/vtd.c | 8 ++++++++
 xen/include/xen/iommu.h               | 2 +-
 5 files changed, 14 insertions(+), 4 deletions(-)
docs/misc/xen-command-line.markdown +3 -1
index 6beb28dada..97768f1633 100644
@@ -1213,7 +1213,9 @@ wait descriptor timed out', try increasing this value.
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
 option all pages up to and including 4GB, not marked as unusable in the
-E820 table, will get a mapping established.
+E820 table, will get a mapping established. Note that if `dom0-strict`
+mode is enabled then conventional RAM pages not assigned to dom0 will not
+be mapped.
 
 ### irq\_ratelimit (x86)
 > `= <integer>`
xen/drivers/passthrough/iommu.c +0 -0
index 2c44fabf99..a483212356 100644

xen/drivers/passthrough/iommu.c custom_param("iommu", parse_iommu_param); · line 55

Quoted 5 lines
xen/drivers/passthrough/iommu.c +1 -1
@@ -52,7 +52,7 @@ custom_param("iommu", parse_iommu_param);
 bool_t __initdata iommu_enable = 1;
 bool_t __read_mostly iommu_enabled;
 bool_t __read_mostly force_iommu;
-bool_t __hwdom_initdata iommu_dom0_strict;
+bool_t __read_mostly iommu_dom0_strict;

I'm not sure why you need to change the attributes of iommu_dom0_strict, AFAICT it's still only used in hwdom_init (or init) functions?

xen/drivers/passthrough/vtd/iommu.c static void __hwdom_init intel_iommu_hwdom_init(struct domain *d) · line 1307

Quoted 13 lines
xen/drivers/passthrough/iommu.c +0 -0
 bool_t __read_mostly iommu_verbose;
 bool_t __read_mostly iommu_workaround_bios_bug;
 bool_t __read_mostly iommu_igfx = 1;
xen/drivers/passthrough/vtd/iommu.c +1 -1
index 08bce92d40..e3f043288b 100644
@@ -1304,7 +1304,7 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
 {
     struct acpi_drhd_unit *drhd;
 
-    if ( !iommu_passthrough && !need_iommu(d) )
+    if ( !iommu_passthrough )

I think you will have to add an is_pv_domain(d) check here, or else PVH Dom0 will also get those mappings, which is wrong because in the PVH case we don't want to identity map PFNs into guest p2m.

PVH Dom0 wasn't calling vtd_set_hwdom_mapping because of the !need_iommu check.

Thanks, Roger.

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

#7 lore raw

Re: [PATCH 2/2] VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

Quoted 32 lines

-----Original Message-----
From: Roger Pau Monne
Sent: 11 June 2018 11:26
To: Paul Durrant <[email protected]>
Cc: [email protected]; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [Xen-devel] [PATCH 2/2] VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

Quoted 1 line · Paul Durrant

The documentation for the iommu_inclusive_mapping Xen command line

option

Quoted 3 lines

states:

"Use this to work around firmware issues providing incorrect RMRR

entries"

Quoted 2 lines

Unfortunately this workaround does not function correctly if the dom0-

strict

Quoted 5 lines

iommu option is also specified.

The documentation goes on to say:

"Rather than only mapping RAM pages for IOMMU accesses for Dom0, with

this

Quoted 2 lines

option all pages up to and including 4GB, not marked as unusable in the E820 table, will get a mapping established."

Quoted 7 lines

My version of xen-command-line.markdown says:

"Use this to work around firmware issues providing incorrect RMRR entries. Rather than only mapping RAM pages for IOMMU accesses for Dom0, with this
option all pages not marked as unusable in the E820 table will get a mapping established."

It will, without patch #1 applied.

Quoted 4 lines

I think the documentation or the code needs fixing, because the current code does indeed only map up to 4GB.

That's what patch #1 does :-)

Quoted 48 lines
Quoted 4 lines

This patch modifies the VT-d hardware domain initialization code such that the workaround will continue to function in dom0-strict mode, by mapping all pages not marked as unusable *unless* they are RAM pages not

assigned

docs/misc/xen-

Quoted 23 lines

to dom0.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Kevin Tian <[email protected]>

---
 docs/misc/xen-command-line.markdown   | 4 +++-
 xen/drivers/passthrough/iommu.c       | 2 +-
 xen/drivers/passthrough/vtd/iommu.c   | 2 +-
 xen/drivers/passthrough/vtd/x86/vtd.c | 8 ++++++++
 xen/include/xen/iommu.h               | 2 +-
 5 files changed, 14 insertions(+), 4 deletions(-)
docs/misc/xen- renamed from docs/misc/xen-command-line.markdown +0 -0

command-line.markdown

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this

Quoted 4 lines

index 6beb28dada..97768f1633 100644

docs/misc/xen-command-line.markdown +0 -0
@@ -1213,7 +1213,9 @@ wait descriptor timed out', try increasing this

value.

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this · line 1214

Quoted 2 lines
docs/misc/xen-command-line.markdown +0 -0
 Use this to work around firmware issues providing incorrect RMRR entries.
 Rather than only mapping RAM pages for IOMMU accesses for Dom0, with

this

docs/misc/xen-command-line.markdown wait descriptor timed out', try increasing this value.

Quoted 4 lines
docs/misc/xen-command-line.markdown +2 -1
 option all pages up to and including 4GB, not marked as unusable in the
-E820 table, will get a mapping established.
+E820 table, will get a mapping established. Note that if `dom0-strict`
+mode is enabled then conventional RAM pages not assigned to dom0 will

not

Review

Quoted 5 lines
docs/misc/xen-command-line.markdown +1 -0
+be mapped.
 
 ### irq\_ratelimit (x86)
 > `= <integer>`
(quoted diff) +0 -0

b/xen/drivers/passthrough/iommu.c

Quoted 14 lines

xen/drivers/passthrough/iommu.c custom_param("iommu", parse_iommu_param); · line 55

Quoted 9 lines

index 2c44fabf99..a483212356 100644

xen/drivers/passthrough/iommu.c +1 -1
@@ -52,7 +52,7 @@ custom_param("iommu", parse_iommu_param);
 bool_t __initdata iommu_enable = 1;
 bool_t __read_mostly iommu_enabled;
 bool_t __read_mostly force_iommu;
-bool_t __hwdom_initdata iommu_dom0_strict;
+bool_t __read_mostly iommu_dom0_strict;

I'm not sure why you need to change the attributes of iommu_dom0_strict, AFAICT it's still only used in hwdom_init (or init) functions?

That's true at this point. I plan to change it as part of PV-IOMMU. TBH though I prefer the consistency but I can drop the change if there are any major objections.

Quoted 16 lines

Review

Quoted 4 lines
xen/drivers/passthrough/iommu.c +0 -0
 bool_t __read_mostly iommu_verbose;
 bool_t __read_mostly iommu_workaround_bios_bug;
 bool_t __read_mostly iommu_igfx = 1;
(quoted diff) +0 -0

b/xen/drivers/passthrough/vtd/iommu.c

xen/drivers/passthrough/vtd/iommu.c static void __hwdom_init

Quoted 4 lines

index 08bce92d40..e3f043288b 100644

xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -1304,7 +1304,7 @@ static void __hwdom_init

intel_iommu_hwdom_init(struct domain *d)

xen/drivers/passthrough/vtd/iommu.c static void __hwdom_init intel_iommu_hwdom_init(struct domain *d) · line 1307

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
 {
     struct acpi_drhd_unit *drhd;
 
-    if ( !iommu_passthrough && !need_iommu(d) )
+    if ( !iommu_passthrough )
Quoted 6 lines

I think you will have to add an is_pv_domain(d) check here, or else PVH Dom0 will also get those mappings, which is wrong because in the PVH case we don't want to identity map PFNs into guest p2m.

PVH Dom0 wasn't calling vtd_set_hwdom_mapping because of the !need_iommu check.

Ah, ok. I'll add that.

Cheers,

Paul

Quoted 2 lines

Thanks, Roger.

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

#8 lore raw

Re: [PATCH 2/2] VT-d: reconcile iommu_inclusive_mapping and iommu=dom0-strict

Quoted 18 lines
Quoted 4 lines
Quoted 1 line · On 11.06.18 at 12:31, <[email protected]> wrote:

From: Roger Pau Monne
Sent: 11 June 2018 11:26
On Fri, Jun 08, 2018 at 04:30:30PM +0100, Paul Durrant wrote:

Quoted 13 lines

xen/drivers/passthrough/iommu.c custom_param("iommu", parse_iommu_param); · line 55

Quoted 8 lines
xen/drivers/passthrough/iommu.c +1 -1
@@ -52,7 +52,7 @@ custom_param("iommu", parse_iommu_param);
 bool_t __initdata iommu_enable = 1;
 bool_t __read_mostly iommu_enabled;
 bool_t __read_mostly force_iommu;
-bool_t __hwdom_initdata iommu_dom0_strict;
+bool_t __read_mostly iommu_dom0_strict;

I'm not sure why you need to change the attributes of iommu_dom0_strict, AFAICT it's still only used in hwdom_init (or init) functions?

Quoted 3 lines

That's true at this point. I plan to change it as part of PV-IOMMU. TBH though I prefer the consistency but I can drop the change if there are any major objections.

Yes, please change it only at the point it needs changing.

Jan

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