Skip to contentSkip to conversation

xen/arm: Allow balooning working with 1:1 memory mapping

PATCH Superseded Julien Grall 2 participants 3 messages Dec 16, 2013 – Dec 17, 2013

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 xen/arm: Allow balooning working with 1:1 memory mapping

With the lack of iommu, dom0 must have a 1:1 memory mapping for all these guest physical address. When the ballon decides to give back a page to the kernel, this page must have the same address as previously. Otherwise, we will loose the 1:1 mapping and will break DMA-capable devices.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>

---
Release: This is a bug that prevents DMA-capable devices to work after a guest has started.

Changes in v5:
- Export dom0_11_mapping and transform is_domain_direct_mapped in macro
- Add ifndef in common code to define is_domain_direct_mapped
Changes in v4:
- Fix typoes
- Update comment in the code
Changes in v3:
- Remove spurious page = NULL
- Rename is_dom0_mapped_11 to is_domain_direct_mapped
- Coding style
Changes in v2:
- Drop CONFIG_ARM and add is_dom0_mapped_11

---
 xen/arch/arm/domain_build.c  |    2 +-
 xen/common/memory.c          |   35 ++++++++++++++++++++++++++++++++++-
 xen/include/asm-arm/domain.h |    3 +++
 3 files changed, 38 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +1 -1
index faff88e..47b781b 100644
@@ -22,7 +22,7 @@
 static unsigned int __initdata opt_dom0_max_vcpus;
 integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);
 
-static int dom0_11_mapping = 1;
+int dom0_11_mapping = 1;
 
 #define DOM0_MEM_DEFAULT 0x8000000 /* 128 MiB */
 static u64 __initdata dom0_mem = DOM0_MEM_DEFAULT;
xen/common/memory.c +34 -1
index eb7b72b..1a93196 100644
@@ -29,6 +29,10 @@
 #include <xsm/xsm.h>
 #include <xen/trace.h>
 
+#ifndef is_domain_direct_mapped
+# define is_domain_direct_mapped(d) ((void)(d), 0)
+#endif
+
 struct memop_args {
     /* INPUT */
     struct domain *domain;     /* Domain to be affected. */
@@ -122,7 +126,29 @@ static void populate_physmap(struct memop_args *a)
         }
         else
         {
-            page = alloc_domheap_pages(d, a->extent_order, a->memflags);
+            if ( is_domain_direct_mapped(d) )
+            {
+                mfn = gpfn;
+                if ( !mfn_valid(mfn) )
+                {
+                    gdprintk(XENLOG_INFO, "Invalid mfn 0x%"PRI_xen_pfn"\n",
+                             mfn);
+                    goto out;
+                }
+
+                page = mfn_to_page(mfn);
+                if ( !get_page(page, d) )
+                {
+                    gdprintk(XENLOG_INFO,
+                             "mfn 0x%"PRI_xen_pfn" doesn't belong to the"
+                             " domain\n", mfn);
+                    goto out;
+                }
+                put_page(page);
+            }
+            else
+                page = alloc_domheap_pages(d, a->extent_order, a->memflags);
+
             if ( unlikely(page == NULL) ) 
             {
                 if ( !opt_tmem || (a->extent_order != 0) )
@@ -270,6 +296,13 @@ static void decrease_reservation(struct memop_args *a)
              && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) )
             continue;
 
+        /* With the lack for iommu on some ARM platform, domain with DMA-capable
+         * device must retrieve the same pfn when the hypercall
+         * populate_physmap is called.
+         */
+        if ( is_domain_direct_mapped(a->domain) )
+            continue;
+
         for ( j = 0; j < (1 << a->extent_order); j++ )
             if ( !guest_remove_page(a->domain, gmfn + j) )
                 goto out;
xen/include/asm-arm/domain.h +3 -0
index 28d39a0..3419c31 100644
@@ -86,6 +86,9 @@ enum domain_type {
 #define is_pv64_domain(d) (0)
 #endif
 
+extern int dom0_11_mapping;
+#define is_domain_direct_mapped(d) (dom0_11_mapping && (d) == dom0)
+
 struct vtimer {
         struct vcpu *v;
         int irq;
Signature · 1 line
1.7.10.4
Reviewed-by on v5 1/1
#1 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Julien Grall

With the lack of iommu, dom0 must have a 1:1 memory mapping for all these guest physical address. When the ballon decides to give back a page to the kernel, this page must have the same address as previously. Otherwise, we will loose the 1:1 mapping and will break DMA-capable devices.

if you do one more change (and a little bit of further cleanup - sorry I didn't notice this before):

xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 134

Quoted 11 lines
xen/common/memory.c +6 -1
@@ -122,7 +126,29 @@ static void populate_physmap(struct memop_args *a)
         }
         else
         {
-            page = alloc_domheap_pages(d, a->extent_order, a->memflags);
+            if ( is_domain_direct_mapped(d) )
+            {
+                mfn = gpfn;
+                if ( !mfn_valid(mfn) )
+                {
+                    gdprintk(XENLOG_INFO, "Invalid mfn 0x%"PRI_xen_pfn"\n",

"... %#"PRI_xen_pfn"\n" please.

xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 144

Quoted 10 lines
xen/common/memory.c +10 -0
+                             mfn);
+                    goto out;
+                }
+
+                page = mfn_to_page(mfn);
+                if ( !get_page(page, d) )
+                {
+                    gdprintk(XENLOG_INFO,
+                             "mfn 0x%"PRI_xen_pfn" doesn't belong to the"
+                             " domain\n", mfn);

Same here.

xen/include/asm-arm/domain.h enum domain_type { · line 90

Quoted 8 lines
xen/include/asm-arm/domain.h +2 -0
@@ -86,6 +86,9 @@ enum domain_type {
 #define is_pv64_domain(d) (0)
 #endif
 
+extern int dom0_11_mapping;
+#define is_domain_direct_mapped(d) (dom0_11_mapping && (d) == dom0)

This needs to be

#define is_domain_direct_mapped(d) ((d) == dom0 && dom0_11_mapping)

in order to make sure d is evaluated exactly once.

Jan

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Julien Grall

With the lack of iommu, dom0 must have a 1:1 memory mapping for all these guest physical address. When the ballon decides to give back a page to the kernel, this page must have the same address as previously. Otherwise, we will loose the 1:1 mapping and will break DMA-capable devices.

Quoted 6 lines
Quoted 2 lines

if you do one more change (and a little bit of further cleanup - sorry I didn't notice this before):

Thanks, I will do all the changes.

Signature · 1 line
Julien Grall