Skip to contentSkip to conversation

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

PATCH Superseded Julien Grall 2 participants 2 messages Dec 16, 2013

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 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  |    5 +++++
 xen/common/memory.c          |   31 ++++++++++++++++++++++++++++++-
 xen/include/asm-arm/domain.h |    2 ++
 xen/include/asm-x86/domain.h |    2 ++
 4 files changed, 39 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +5 -0
index faff88e..2bbee36 100644
@@ -65,6 +65,11 @@ struct vcpu *__init alloc_dom0_vcpu0(void)
     return alloc_vcpu(dom0, 0, 0);
 }
 
+int is_domain_direct_mapped(struct domain *d)
+{
+    return (dom0_11_mapping && d == dom0);
+}
+
 static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo)
 {
     paddr_t start;
xen/common/memory.c +30 -1
index eb7b72b..edbbdc4 100644
@@ -122,7 +122,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 +292,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 +2 -0
index 28d39a0..dbc1389 100644
@@ -86,6 +86,8 @@ enum domain_type {
 #define is_pv64_domain(d) (0)
 #endif
 
+int is_domain_direct_mapped(struct domain *d);
+
 struct vtimer {
         struct vcpu *v;
         int irq;
xen/include/asm-x86/domain.h +2 -0
index 9d39061..2c7f809 100644
@@ -16,6 +16,8 @@
 #define is_pv_32on64_domain(d) (is_pv_32bit_domain(d))
 #define is_pv_32on64_vcpu(v)   (is_pv_32on64_domain((v)->domain))
 
+#define is_domain_direct_mapped(d) (0)
+
 #define is_hvm_pv_evtchn_domain(d) (has_hvm_container_domain(d) && \
         d->arch.hvm_domain.irq.callback_via_type == HVMIRQ_callback_vector)
 #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))
Signature · 1 line
1.7.10.4
#1 lore raw

xen/arch/arm/domain_build.c struct vcpu *__init alloc_dom0_vcpu0(void) · line 68

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/arch/arm/domain_build.c +1 -0
@@ -65,6 +65,11 @@ struct vcpu *__init alloc_dom0_vcpu0(void)
     return alloc_vcpu(dom0, 0, 0);
 }
 
+int is_domain_direct_mapped(struct domain *d)

bool_t please, and const struct domain *.

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

Quoted 7 lines
xen/include/asm-arm/domain.h +1 -0
@@ -86,6 +86,8 @@ enum domain_type {
 #define is_pv64_domain(d) (0)
 #endif
 
+int is_domain_direct_mapped(struct domain *d);

Furthermore, if this could be made a macro, ...

xen/include/asm-x86/domain.h line 19

Quoted 7 lines
xen/include/asm-x86/domain.h +1 -0
@@ -16,6 +16,8 @@
 #define is_pv_32on64_domain(d) (is_pv_32bit_domain(d))
 #define is_pv_32on64_vcpu(v)   (is_pv_32on64_domain((v)->domain))
 
+#define is_domain_direct_mapped(d) (0)

... you wouldn't need this here, but rather put it inside an "#ifndef is_domain_direct_mapped" in xen/common/memory.c itself.

And you'll want to make sure (even if unlikely to be needed in practice) that you evaluate the macro argument exactly once in both flavors, i.e. in the case here

#define is_domain_direct_mapped(d) ((void)(d), 0)

or, assuming that d being NULL is a mistake anyway (and would crash elsewhere)

#define is_domain_direct_mapped(d) (!(d))

Jan