Skip to contentSkip to conversation

Fix grant map/unmap with auto-translated guests

PATCH Superseded Roger Pau Monne 4 participants 22 messages Apr 23, 2014 – May 9, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix grant map/unmap with auto-translated guests

This series adds proper IOMMU entries when mapping foreign memory (either grants or foreign pages) inside of auto-translated guests when the p2m is not shared between HAP and IOMMUs, and disables p2m sharing when running on AMD hardware.

In order for the guest to know if it's safe to use grant mapped pages for IO with hardware devices a new xen feature is introduced in the last patch.

Thanks for the review, Roger.

#1 lore raw

PATCH v2 1/4 xen: make logdirty and iommu mutually exclusive

Prevent the usage of global logdirty if the domain is using the IOMMU, and also prevent passthrough of devices if logdirty is enabled.

---
 xen/arch/x86/mm/hap/hap.c       |    9 +++++++++
 xen/arch/x86/mm/shadow/common.c |    9 +++++++++
 xen/drivers/passthrough/iommu.c |    3 ++-
 3 files changed, 20 insertions(+), 1 deletions(-)
xen/arch/x86/mm/hap/hap.c +9 -0
index 68a0c25..352edfd 100644
@@ -175,6 +175,15 @@ out:
  */
 static int hap_enable_log_dirty(struct domain *d, bool_t log_global)
 {
+
+    if ( iommu_enabled && need_iommu(d) && log_global )
+    {
+        /*
+         * Refuse to turn on global log-dirty mode
+         * if the domain is using the IOMMU.
+         */
+        return -EINVAL;
+    }
     /* turn on PG_log_dirty bit in paging mode */
     paging_lock(d);
     d->arch.paging.mode |= PG_log_dirty;
xen/arch/x86/mm/shadow/common.c +9 -0
index 9258d2a..dd55455 100644
@@ -3422,6 +3422,15 @@ int shadow_enable_log_dirty(struct domain *d, bool_t log_global)
 {
     int ret;
 
+    if ( iommu_enabled && need_iommu(d) && log_global )
+    {
+        /*
+         * Refuse to turn on global log-dirty mode
+         * if the domain is using the IOMMU.
+         */
+        return -EINVAL;
+    }
+
     paging_lock(d);
     if ( shadow_mode_enabled(d) )
     {
xen/drivers/passthrough/iommu.c +2 -1
index 0cf0748..ef6660f 100644
@@ -292,7 +292,8 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn)
      * enabled for this domain */
     if ( unlikely(!need_iommu(d) &&
             (d->arch.hvm_domain.mem_sharing_enabled ||
-             d->mem_event->paging.ring_page)) )
+             d->mem_event->paging.ring_page ||
+             paging_mode_log_dirty(d))) )
         return -EXDEV;
 
     if ( !spin_trylock(&pcidevs_lock) )
Signature · 7 lines
1.7.7.5 (Apple Git-26)


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

Re: [PATCH v2 1/4] xen: make logdirty and iommu mutually exclusive

xen/arch/x86/mm/hap/hap.c out: · line 179

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:
xen/arch/x86/mm/hap/hap.c +2 -0
@@ -175,6 +175,15 @@ out:
  */
 static int hap_enable_log_dirty(struct domain *d, bool_t log_global)
 {
+
+    if ( iommu_enabled && need_iommu(d) && log_global )

need_iommu() implies iommu_enabled, and hence checking only the former ought to be sufficient.

Also, why do you do this here and in shadow code rather than in paging_log_dirty_enable()?

xen/drivers/passthrough/iommu.c static int assign_device(struct domain *d, u16 seg, u8 · line 297

Quoted 10 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -292,7 +292,8 @@ static int assign_device(struct domain *d, u16 seg, u8 
 bus, u8 devfn)
      * enabled for this domain */
     if ( unlikely(!need_iommu(d) &&
             (d->arch.hvm_domain.mem_sharing_enabled ||
-             d->mem_event->paging.ring_page)) )
+             d->mem_event->paging.ring_page ||
+             paging_mode_log_dirty(d))) )

I'm afraid that would return true also for non-global log dirty mode. This patch series
http://lists.xenproject.org/archives/html/xen-devel/2014-04/msg02750.html
(patch 1) introduces a way to know whether global mode is enabled
- maybe you should base your series on top of that one?

Jan

#3 lore raw

Re: [PATCH v2 1/4] xen: make logdirty and iommu mutually exclusive

Quoted 13 lines · Jan Beulich

xen/arch/x86/mm/hap/hap.c out: · line 179

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:
xen/arch/x86/mm/hap/hap.c +2 -0
@@ -175,6 +175,15 @@ out:
  */
 static int hap_enable_log_dirty(struct domain *d, bool_t log_global)
 {
+
+    if ( iommu_enabled && need_iommu(d) && log_global )

need_iommu() implies iommu_enabled, and hence checking only the former ought to be sufficient.

Quoted 2 lines

Also, why do you do this here and in shadow code rather than in paging_log_dirty_enable()?

Sight... yes, much better place. Will change it in next version.

Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/iommu.c +0 -1
@@ -292,7 +292,8 @@ static int assign_device(struct domain *d, u16 seg, u8 
 bus, u8 devfn)
      * enabled for this domain */
     if ( unlikely(!need_iommu(d) &&
             (d->arch.hvm_domain.mem_sharing_enabled ||
-             d->mem_event->paging.ring_page)) )
Quoted 8 lines

xen/drivers/passthrough/iommu.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) · line 296

Quoted 2 lines
xen/drivers/passthrough/iommu.c +2 -0
+             d->mem_event->paging.ring_page ||
+             paging_mode_log_dirty(d))) )

I'm afraid that would return true also for non-global log dirty mode. This patch series
http://lists.xenproject.org/archives/html/xen-devel/2014-04/msg02750.html
(patch 1) introduces a way to know whether global mode is enabled
- maybe you should base your series on top of that one?

Sure, this series are already on top of Mukesh p2m cleanup patches, I don't mind rebasing it on top of your series also.

Roger.

#4 lore raw

Re: [PATCH v2 1/4] xen: make logdirty and iommu mutually exclusive

Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich

xen/drivers/passthrough/iommu.c static int assign_device(struct domain *d, u16 seg, u8 · line 297

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +2 -1
@@ -292,7 +292,8 @@ static int assign_device(struct domain *d, u16 seg, u8 
 bus, u8 devfn)
      * enabled for this domain */
     if ( unlikely(!need_iommu(d) &&
             (d->arch.hvm_domain.mem_sharing_enabled ||
-             d->mem_event->paging.ring_page)) )
+             d->mem_event->paging.ring_page ||
+             paging_mode_log_dirty(d))) )

I'm afraid that would return true also for non-global log dirty mode. This patch series
http://lists.xenproject.org/archives/html/xen-devel/2014-04/msg02750.html
(patch 1) introduces a way to know whether global mode is enabled
- maybe you should base your series on top of that one?

Quoted 2 lines

Sure, this series are already on top of Mukesh p2m cleanup patches, I don't mind rebasing it on top of your series also.

I'm afraid I will have to wait for either you or Mukesh to rebase on top of each other, since your patches don't apply cleanly on top of Mukesh's p2m changes.

Roger.

#5 lore raw

Re: [PATCH v2 1/4] xen: make logdirty and iommu mutually exclusive

In reply to Roger Pau Monne

Hi,

Quoted 4 lines · Roger Pau Monne

Prevent the usage of global logdirty if the domain is using the IOMMU, and also prevent passthrough of devices if logdirty is enabled.

Yes, this is the sort of thing I had in mind (thuogh I agree with Jan's review comments).

Cheers,

Tim.

Quoted 63 lines
---
 xen/arch/x86/mm/hap/hap.c       |    9 +++++++++
 xen/arch/x86/mm/shadow/common.c |    9 +++++++++
 xen/drivers/passthrough/iommu.c |    3 ++-
 3 files changed, 20 insertions(+), 1 deletions(-)
xen/arch/x86/mm/hap/hap.c +9 -0
index 68a0c25..352edfd 100644
@@ -175,6 +175,15 @@ out:
  */
 static int hap_enable_log_dirty(struct domain *d, bool_t log_global)
 {
+
+    if ( iommu_enabled && need_iommu(d) && log_global )
+    {
+        /*
+         * Refuse to turn on global log-dirty mode
+         * if the domain is using the IOMMU.
+         */
+        return -EINVAL;
+    }
     /* turn on PG_log_dirty bit in paging mode */
     paging_lock(d);
     d->arch.paging.mode |= PG_log_dirty;
xen/arch/x86/mm/shadow/common.c +9 -0
index 9258d2a..dd55455 100644
@@ -3422,6 +3422,15 @@ int shadow_enable_log_dirty(struct domain *d, bool_t log_global)
 {
     int ret;
 
+    if ( iommu_enabled && need_iommu(d) && log_global )
+    {
+        /*
+         * Refuse to turn on global log-dirty mode
+         * if the domain is using the IOMMU.
+         */
+        return -EINVAL;
+    }
+
     paging_lock(d);
     if ( shadow_mode_enabled(d) )
     {
xen/drivers/passthrough/iommu.c +2 -1
index 0cf0748..ef6660f 100644
@@ -292,7 +292,8 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn)
      * enabled for this domain */
     if ( unlikely(!need_iommu(d) &&
             (d->arch.hvm_domain.mem_sharing_enabled ||
-             d->mem_event->paging.ring_page)) )
+             d->mem_event->paging.ring_page ||
+             paging_mode_log_dirty(d))) )
         return -EXDEV;
 
     if ( !spin_trylock(&pcidevs_lock) )
Signature · 1 line
1.7.7.5 (Apple Git-26)
#6 lore raw

PATCH v2 2/4 iommu: set correct IOMMU entries when iommu_hap_pt_share == 0

In reply to Roger Pau Monne

If the memory map is not shared between HAP and IOMMU we fail to set correct IOMMU mappings for memory types other than p2m_ram_rw.

This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw, p2m_map_foreign, p2m_ram_ro, p2m_grant_map_ro and p2m_ram_logdirty.

---
Changes since v1:
- Move the p2m type switch to IOMMU flags to an inline function that is shared between p2m-ept and p2m-pt.
- Make p2m_set_entry also use p2m_get_iommu_flags.

---
 xen/arch/x86/mm/p2m-ept.c |    7 ++++---
 xen/arch/x86/mm/p2m-pt.c  |   11 +++++------
 xen/include/asm-x86/p2m.h |   27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 9 deletions(-)
xen/arch/x86/mm/p2m-ept.c +4 -3
index 7dcfcb6..6e8a1af 100644
@@ -472,10 +472,11 @@ out:
             iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i,
-                                   IOMMUF_readable | IOMMUF_writable);
+                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, flags);
             else
                 for ( i = 0; i < (1 << order); i++ )
                     iommu_unmap_page(d, gfn + i);
xen/arch/x86/mm/p2m-pt.c +5 -6
index 915f60d..2b36a10 100644
@@ -291,9 +291,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
     int rc;
-    unsigned int iommu_pte_flags = (p2mt == p2m_ram_rw) ?
-                                   IOMMUF_readable|IOMMUF_writable:
-                                   0; 
+    unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     unsigned long old_mfn = 0;
 
     if ( tb_init_done )
@@ -456,10 +454,11 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         }
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1UL << page_order); i++ )
-                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i,
-                                   IOMMUF_readable|IOMMUF_writable);
+                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i, flags);
             else
                 for ( int i = 0; i < (1UL << page_order); i++ )
                     iommu_unmap_page(p2m->domain, gfn+i);
xen/include/asm-x86/p2m.h +27 -0
index 47604da..54f5a88 100644
@@ -670,6 +670,33 @@ void p2m_flush_nestedp2m(struct domain *d);
 void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
     l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level);
 
+/*
+ * p2m type to IOMMU flags
+ */
+static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
+{
+    unsigned int flags;
+
+    switch( p2mt )
+    {
+    case p2m_ram_rw:
+    case p2m_grant_map_rw:
+    case p2m_ram_logdirty:
+    case p2m_map_foreign:
+        flags =  IOMMUF_readable | IOMMUF_writable;
+        break;
+    case p2m_ram_ro:
+    case p2m_grant_map_ro:
+        flags = IOMMUF_readable;
+        break;
+    default:
+        flags = 0;
+        break;
+    }
+
+    return flags;
+}
+
 #endif /* _XEN_P2M_H */
 
 /*
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 2/4
#7 lore raw

Re: [PATCH v2 2/4] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

If the memory map is not shared between HAP and IOMMU we fail to set correct IOMMU mappings for memory types other than p2m_ram_rw.

This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw, p2m_map_foreign, p2m_ram_ro, p2m_grant_map_ro and p2m_ram_logdirty.

Quoted 100 lines

Changes since v1:
- Move the p2m type switch to IOMMU flags to an inline function that is shared between p2m-ept and p2m-pt.
- Make p2m_set_entry also use p2m_get_iommu_flags.

---
 xen/arch/x86/mm/p2m-ept.c |    7 ++++---
 xen/arch/x86/mm/p2m-pt.c  |   11 +++++------
 xen/include/asm-x86/p2m.h |   27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 9 deletions(-)
xen/arch/x86/mm/p2m-ept.c +4 -3
index 7dcfcb6..6e8a1af 100644
@@ -472,10 +472,11 @@ out:
             iommu_pte_flush(d, gfn, &ept_entry->epte, order, 
 vtd_pte_present);
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i,
-                                   IOMMUF_readable | IOMMUF_writable);
+                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, flags);
             else
                 for ( i = 0; i < (1 << order); i++ )
                     iommu_unmap_page(d, gfn + i);
xen/arch/x86/mm/p2m-pt.c +1 -3
index 915f60d..2b36a10 100644
@@ -291,9 +291,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long 
 gfn, mfn_t mfn,
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
     int rc;
-    unsigned int iommu_pte_flags = (p2mt == p2m_ram_rw) ?
-                                   IOMMUF_readable|IOMMUF_writable:
-                                   0; 
+    unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     unsigned long old_mfn = 0;
 

if ( tb_init_done )

xen/arch/x86/mm/p2m-pt.c +4 -3
@@ -456,10 +454,11 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long 
 gfn, mfn_t mfn,
         }
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1UL << page_order); i++ )
-                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i,
-                                   IOMMUF_readable|IOMMUF_writable);
+                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i, flags);
             else
                 for ( int i = 0; i < (1UL << page_order); i++ )
                     iommu_unmap_page(p2m->domain, gfn+i);
xen/include/asm-x86/p2m.h +27 -0
index 47604da..54f5a88 100644
@@ -670,6 +670,33 @@ void p2m_flush_nestedp2m(struct domain *d);
 void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
     l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int 
 level);
 
+/*
+ * p2m type to IOMMU flags
+ */
+static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
+{
+    unsigned int flags;
+
+    switch( p2mt )
+    {
+    case p2m_ram_rw:
+    case p2m_grant_map_rw:
+    case p2m_ram_logdirty:
+    case p2m_map_foreign:
+        flags =  IOMMUF_readable | IOMMUF_writable;
+        break;
+    case p2m_ram_ro:
+    case p2m_grant_map_ro:
+        flags = IOMMUF_readable;
+        break;
+    default:
+        flags = 0;
+        break;
+    }
+
+    return flags;
+}
+
 #endif /* _XEN_P2M_H */
 
Quoted 3 lines

/*

Signature · 1 line
1.7.7.5 (Apple Git-26)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 2/4
#8 lore raw

Re: [PATCH v2 2/4] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

If the memory map is not shared between HAP and IOMMU we fail to set correct IOMMU mappings for memory types other than p2m_ram_rw.

This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw, p2m_map_foreign, p2m_ram_ro, p2m_grant_map_ro and p2m_ram_logdirty.

Tested-by David Zhuang on v2 2/4
#9 lore raw

Re: [PATCH v2 2/4] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0

In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

If the memory map is not shared between HAP and IOMMU we fail to set correct IOMMU mappings for memory types other than p2m_ram_rw.

This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw, p2m_map_foreign, p2m_ram_ro, p2m_grant_map_ro and p2m_ram_logdirty.

Quoted 106 lines

---
Changes since v1:
- Move the p2m type switch to IOMMU flags to an inline function that is shared between p2m-ept and p2m-pt.
- Make p2m_set_entry also use p2m_get_iommu_flags.

---
 xen/arch/x86/mm/p2m-ept.c |    7 ++++---
 xen/arch/x86/mm/p2m-pt.c  |   11 +++++------
 xen/include/asm-x86/p2m.h |   27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 9 deletions(-)
xen/arch/x86/mm/p2m-ept.c +4 -3
index 7dcfcb6..6e8a1af 100644
@@ -472,10 +472,11 @@ out:
             iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i,
-                                   IOMMUF_readable | IOMMUF_writable);
+                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, flags);
             else
                 for ( i = 0; i < (1 << order); i++ )
                     iommu_unmap_page(d, gfn + i);
xen/arch/x86/mm/p2m-pt.c +5 -6
index 915f60d..2b36a10 100644
@@ -291,9 +291,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
     int rc;
-    unsigned int iommu_pte_flags = (p2mt == p2m_ram_rw) ?
-                                   IOMMUF_readable|IOMMUF_writable:
-                                   0; 
+    unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     unsigned long old_mfn = 0;
 
     if ( tb_init_done )
@@ -456,10 +454,11 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         }
         else
         {
-            if ( p2mt == p2m_ram_rw )
+            unsigned int flags = p2m_get_iommu_flags(p2mt);
+
+            if ( flags != 0 )
                 for ( i = 0; i < (1UL << page_order); i++ )
-                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i,
-                                   IOMMUF_readable|IOMMUF_writable);
+                    iommu_map_page(p2m->domain, gfn+i, mfn_x(mfn)+i, flags);
             else
                 for ( int i = 0; i < (1UL << page_order); i++ )
                     iommu_unmap_page(p2m->domain, gfn+i);
xen/include/asm-x86/p2m.h +27 -0
index 47604da..54f5a88 100644
@@ -670,6 +670,33 @@ void p2m_flush_nestedp2m(struct domain *d);
 void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
     l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level);
 
+/*
+ * p2m type to IOMMU flags
+ */
+static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
+{
+    unsigned int flags;
+
+    switch( p2mt )
+    {
+    case p2m_ram_rw:
+    case p2m_grant_map_rw:
+    case p2m_ram_logdirty:
+    case p2m_map_foreign:
+        flags =  IOMMUF_readable | IOMMUF_writable;
+        break;
+    case p2m_ram_ro:
+    case p2m_grant_map_ro:
+        flags = IOMMUF_readable;
+        break;
+    default:
+        flags = 0;
+        break;
+    }
+
+    return flags;
+}
+
 #endif /* _XEN_P2M_H */
 
 /*
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#10 lore raw

PATCH v2 3/4 amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

In reply to Roger Pau Monne

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Cc Suravee Suthikulpanit <[email protected]>
Cc Xiantao Zhang <[email protected]>
Cc Jan Beulich <[email protected]>

---
I have not tested this patch on AMD hardware, so I would like some confirmation that this actually works.
---
Changes since v1:
- Add a debug message when disabling iommu_hap_pt_share.

---
 xen/drivers/passthrough/amd/iommu_init.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +8 -0
index 4686813..a717601 100644
@@ -1255,6 +1255,14 @@ int __init amd_iommu_init(void)
     if ( iterate_ivrs_mappings(amd_iommu_setup_device_table) != 0 )
         goto error_out;
 
+    /*
+     * Disable sharing HAP page tables with AMD IOMMU,
+     * since it only supports p2m_ram_rw, and this would
+     * prevent doing IO to/from mapped grant frames.
+     */
+    iommu_hap_pt_share = 0;
+    printk(XENLOG_DEBUG "AMD-Vi: Disabled HAP memory map sharing with IOMMU\n");
+
     /* per iommu initialization  */
     for_each_amd_iommu ( iommu )
         if ( amd_iommu_init_one(iommu) != 0 )
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH v2 3/4] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Doesn't this need to go before patch 2?

Jan

#12 lore raw

Re: [PATCH v2 3/4] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Doesn't this need to go before patch 2?

It could certainly go before patch 2, but I don't see such a hard requirement in the ordering (either way AMD hardware needs both patches to work correctly, and applying one before the other is not going to break bisection AFAICT).

Roger.

#13 lore raw

Re: [PATCH v2 3/4] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 12:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Quoted 6 lines
Quoted 1 line

Doesn't this need to go before patch 2?

It could certainly go before patch 2, but I don't see such a hard requirement in the ordering (either way AMD hardware needs both patches to work correctly, and applying one before the other is not going to break bisection AFAICT).

Patch 2 allows the high bits in present IOMMU entries to be non-zero, thus allowing for IOMMU faults without this patch already in effect.

Jan

#14 lore raw

Re: [PATCH v2 3/4] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 12:04, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Doesn't this need to go before patch 2?

Quoted 7 lines
Quoted 4 lines

It could certainly go before patch 2, but I don't see such a hard requirement in the ordering (either way AMD hardware needs both patches to work correctly, and applying one before the other is not going to break bisection AFAICT).

Patch 2 allows the high bits in present IOMMU entries to be non-zero, thus allowing for IOMMU faults without this patch already in effect.

Since on AMD hardware iommu_hap_pt_share is always true (unless the user forces it to false), the previous patch has no effect without this one (because the previous patch only deals with iommu_hap_pt_share == false). I don't mind moving it anyway, and will do it in the next version.

Roger.

#15 lore raw

Re: [PATCH v2 3/4] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 16:31, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 12:04, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

According to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs.

Doesn't this need to go before patch 2?

It could certainly go before patch 2, but I don't see such a hard requirement in the ordering (either way AMD hardware needs both patches to work correctly, and applying one before the other is not going to break bisection AFAICT).

Quoted 7 lines
Quoted 2 lines

Patch 2 allows the high bits in present IOMMU entries to be non-zero, thus allowing for IOMMU faults without this patch already in effect.

Since on AMD hardware iommu_hap_pt_share is always true (unless the user forces it to false), the previous patch has no effect without this one (because the previous patch only deals with iommu_hap_pt_share == false). I don't mind moving it anyway, and will do it in the next version.

And right you are - feel free to keep the order then as it was.

Jan

#16 lore raw

PATCH v2 4/4 xen: expose that grant table mappings update the IOMMU

In reply to Roger Pau Monne

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

---
 xen/common/kernel.c           |    2 ++
 xen/include/public/features.h |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
xen/common/kernel.c +2 -0
index b371f8f..7589dc1 100644
@@ -316,11 +316,13 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
             case guest_type_pvh:
                 fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) |
                              (1U << XENFEAT_supervisor_mode_kernel) |
+                             (1U << XENFEAT_hvm_gntmap_supports_iommu) |
                              (1U << XENFEAT_hvm_callback_vector);
                 break;
             case guest_type_hvm:
                 fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) |
                              (1U << XENFEAT_hvm_callback_vector) |
+                             (1U << XENFEAT_hvm_gntmap_supports_iommu) |
                              (1U << XENFEAT_hvm_pirqs);
                 break;
             }
xen/include/public/features.h +6 -0
index a149aa6..eaa0187 100644
@@ -94,6 +94,12 @@
 /* operation as Dom0 is supported */
 #define XENFEAT_dom0                      11
 
+/*
+ * If set, GNTTABOP_map_grant_ref sets the proper IOMMU mappings so the
+ * resulting mapped page can be used for IO with hardware devices.
+ */
+#define XENFEAT_hvm_gntmap_supports_iommu 12
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#17 lore raw

Re: [PATCH v2 4/4] xen: expose that grant table mappings update the IOMMU

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

Considering Boris' pending introduction of a hypervisor capabilities CPUID leaf, I wonder whether we shouldn't stop surfacing HVM-only features via XENFEAT_* flags (which afaict originally were meant to be a PV vehicle only anyway).

Jan

#18 lore raw

Re: [PATCH v2 4/4] xen: expose that grant table mappings update the IOMMU

Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

Considering Boris' pending introduction of a hypervisor capabilities CPUID leaf, I wonder whether we shouldn't stop surfacing HVM-only features via XENFEAT_* flags (which afaict originally were meant to be a PV vehicle only anyway).

I don't have a strong opinion on the best way to publish this feature, so if you prefer to do it using the new CPUID leaf, I will rework this patch (although I have to say using XENFEAT_* seems easier).

Roger.

#19 lore raw

Re: [PATCH v2 4/4] xen: expose that grant table mappings update the IOMMU

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 09:43, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

Quoted 8 lines
Quoted 4 lines

Considering Boris' pending introduction of a hypervisor capabilities CPUID leaf, I wonder whether we shouldn't stop surfacing HVM-only features via XENFEAT_* flags (which afaict originally were meant to be a PV vehicle only anyway).

I don't have a strong opinion on the best way to publish this feature, so if you prefer to do it using the new CPUID leaf, I will rework this patch (although I have to say using XENFEAT_* seems easier).

Let's explicitly ask a few others who may have an opinion either way (by way of adding them to the To: list).

Jan

#20 lore raw

Re: [PATCH v2 4/4] xen: expose that grant table mappings update the IOMMU

Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 09:43, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

Considering Boris' pending introduction of a hypervisor capabilities CPUID leaf, I wonder whether we shouldn't stop surfacing HVM-only features via XENFEAT_* flags (which afaict originally were meant to be a PV vehicle only anyway).

Quoted 6 lines
Quoted 3 lines

I don't have a strong opinion on the best way to publish this feature, so if you prefer to do it using the new CPUID leaf, I will rework this patch (although I have to say using XENFEAT_* seems easier).

Let's explicitly ask a few others who may have an opinion either way (by way of adding them to the To: list).

Silence .. :-)

How about just the easier path for now (XENFEAT_*)?

Quoted 8 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH v2 4/4] xen: expose that grant table mappings update the IOMMU

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.05.14 at 20:39, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 09:43, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 10:16, <[email protected]> wrote:

Add a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.

Considering Boris' pending introduction of a hypervisor capabilities CPUID leaf, I wonder whether we shouldn't stop surfacing HVM-only features via XENFEAT_* flags (which afaict originally were meant to be a PV vehicle only anyway).

I don't have a strong opinion on the best way to publish this feature, so if you prefer to do it using the new CPUID leaf, I will rework this patch (although I have to say using XENFEAT_* seems easier).

Quoted 6 lines
Quoted 2 lines

Let's explicitly ask a few others who may have an opinion either way (by way of adding them to the To: list).

Silence .. :-)

How about just the easier path for now (XENFEAT_*)?

While continuing to think it being the wrong direction, I also don't want to stand in the way of this making progress...

Jan