xen/arm: Allow balooning working with 1:1 memory mapping
PATCH v2 1/1 xen/arm: Allow balooning working with 1:1 memory mapping
With the lake 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.
---
Release: This is a bug that prevents DMA-capable devices to work after a guest has started.
Changes in v2
- Drop CONFIG_ARM and add is_dom0_mapped_11
--- xen/arch/arm/domain_build.c | 5 +++++ xen/common/memory.c | 32 ++++++++++++++++++++++++++++++-- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-x86/domain.h | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +5 -0
@@ -65,6 +65,11 @@ struct vcpu *__init alloc_dom0_vcpu0(void)return alloc_vcpu (dom0,0 ,0 ); } +int is_dom0_mapped_11 (void ) +{ +return dom0_11_mapping; +} +static void allocate_memory_11 (struct domain *d,struct kernel_info *kinfo) {paddr_t start;
xen/common/memory.c +30 -2
@@ -90,7 +90,7 @@ static void increase_reservation(struct memop_args *a)static void populate_physmap (struct memop_args *a) { -struct page_info *page; +struct page_info *page =NULL ;unsigned long i, j;xen_pfn_t gpfn, mfn;struct domain *d = a->domain;
@@ -122,7 +122,29 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +if ( d == dom0 &&is_dom0_mapped_11 () ) + { + 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 dom0\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,12 @@ static void decrease_reservation(struct memop_args *a) && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) ) continue; +/* With the lake for iommu on some ARM platform, dom0 must retrieve +* the same pfn when the hypercall populate_physmap is called. +*/ +if ( a->domain == dom0 &&is_dom0_mapped_11 () ) +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
@@ -86,6 +86,8 @@ enum domain_type {#define is_pv64_domain (d) (0)#endif +int is_dom0_mapped_11 (void ); +struct vtimer {struct vcpu *v;int irq;
xen/include/asm-x86/domain.h +2 -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_dom0_mapped_11 () (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
xen/common/memory.c static void increase_reservation(struct memop_args *a) · line 93
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/common/memory.c +1
-1@@ -90,7 +90,7 @@ static void increase_reservation(struct memop_args *a)static void populate_physmap (struct memop_args *a) { -struct page_info *page; +struct page_info *page =NULL ;
Why?
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 128
Quoted 9 lines
xen/common/memory.c +4
-1@@ -122,7 +122,29 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +if ( d == dom0 &&is_dom0_mapped_11 () ) + { + mfn = gpfn; +if (!mfn_valid (mfn))
Coding style.
Quoted 6 lines
xen/common/memory.c +6
-0+ { +gdprintk (XENLOG_INFO ,"Invalid mfn 0x%" PRI_xen_pfn"\n" , + mfn); + goto out; + } +
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 144
Quoted 10 lines
xen/common/memory.c +10
-0+ page =mfn_to_page (mfn); +if ( !get_page (page, d) ) + { +gdprintk (XENLOG_INFO , +"mfn 0x%" PRI_xen_pfn" doesn't belong to dom0\n" , + mfn); + goto out; + } +put_page (page); + }
I think this hack doesn't belong into a common file. Rather than having the (anyway oddly named) is_dom0_mapped_11(), it would seem more clean to have this implemented by an inline function for ARM, returning the struct page_info * (and getting #define-d to NULL for all other cases, perhaps not even in an x86 header, but right in the source file).
And even if we were to stay with the implementation here, for being at least half way sane the checking macro should take a domain argument rather than requiring the extra "d == dom0" check up front. Plus the "11" there is bogus - I first read this as "eleven" rather than "1:1", wondering what eleven here was about. I'd suggest something like is_domain_direct_mapped() or is_domain_identity_mapped().
Jan
Quoted 41 lines · Jan Beulich
xen/common/memory.c static void increase_reservation(struct memop_args *a) · line 93
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/common/memory.c +1
-1@@ -90,7 +90,7 @@ static void increase_reservation(struct memop_args *a)static void populate_physmap (struct memop_args *a) { -struct page_info *page; +struct page_info *page =NULL ;Why?
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 128
Quoted 9 lines
xen/common/memory.c +4
-1@@ -122,7 +122,29 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +if ( d == dom0 &&is_dom0_mapped_11 () ) + { + mfn = gpfn; +if (!mfn_valid (mfn))Coding style.
Quoted 6 lines
xen/common/memory.c +6
-0+ { +gdprintk (XENLOG_INFO ,"Invalid mfn 0x%" PRI_xen_pfn"\n" , + mfn); + goto out; + } +xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 144
Quoted 10 lines
xen/common/memory.c +10
-0+ page =mfn_to_page (mfn); +if ( !get_page (page, d) ) + { +gdprintk (XENLOG_INFO , +"mfn 0x%" PRI_xen_pfn" doesn't belong to dom0\n" , + mfn); + goto out; + } +put_page (page); + }
Quoted 6 lines
I think this hack doesn't belong into a common file. Rather than having the (anyway oddly named)
is_dom0_mapped_11(), it would seem more clean to have this implemented by an inline function for ARM, returning the structpage_info* (and getting #define-d to NULL for all other cases, perhaps not even in an x86 header, but right in the source file).
Considering that having a 1:1 mapping for dom0 is conceivable even on x86 (if you want PVH dom0 but your platform doesn't come with an IOMMU), I would prefer the approach taken here. However I find your alternative suggestion acceptable too.
Quoted 7 lines
And even if we were to stay with the implementation here, for being at least half way sane the checking macro should take a domain argument rather than requiring the extra "d == dom0" check up front. Plus the "11" there is bogus - I first read this as "eleven" rather than "1:1", wondering what eleven here was about. I'd suggest something like
is_domain_direct_mapped()oris_domain_identity_mapped().
I agree.
Quoted 49 lines · Stefano Stabellini
Quoted 41 lines · Jan Beulich
xen/common/memory.c static void increase_reservation(struct memop_args *a) · line 93
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/common/memory.c +1
-1@@ -90,7 +90,7 @@ static void increase_reservation(struct memop_args *a)static void populate_physmap (struct memop_args *a) { -struct page_info *page; +struct page_info *page =NULL ;Why?
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 128
Quoted 9 lines
xen/common/memory.c +4
-1@@ -122,7 +122,29 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +if ( d == dom0 &&is_dom0_mapped_11 () ) + { + mfn = gpfn; +if (!mfn_valid (mfn))Coding style.
Quoted 6 lines
xen/common/memory.c +6
-0+ { +gdprintk (XENLOG_INFO ,"Invalid mfn 0x%" PRI_xen_pfn"\n" , + mfn); + goto out; + } +xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 144
Quoted 10 lines
xen/common/memory.c +10
-0+ page =mfn_to_page (mfn); +if ( !get_page (page, d) ) + { +gdprintk (XENLOG_INFO , +"mfn 0x%" PRI_xen_pfn" doesn't belong to dom0\n" , + mfn); + goto out; + } +put_page (page); + }Quoted 6 lines
I think this hack doesn't belong into a common file. Rather than having the (anyway oddly named)
is_dom0_mapped_11(), it would seem more clean to have this implemented by an inline function for ARM, returning the structpage_info* (and getting #define-d to NULL for all other cases, perhaps not even in an x86 header, but right in the source file).
Quoted 4 lines
Considering that having a 1:1 mapping for dom0 is conceivable even on x86 (if you want PVH dom0 but your platform doesn't come with an IOMMU), I would prefer the approach taken here. However I find your alternative suggestion acceptable too.
I will stay on your solution, with is_dom0_mapped_11 modify to is_domain_direct_mapped().
Signature · 1 line
Julien Grall
Quoted 11 lines · Jan Beulich
xen/common/memory.c static void increase_reservation(struct memop_args *a) · line 93
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/common/memory.c +1
-1@@ -90,7 +90,7 @@ static void increase_reservation(struct memop_args *a)static void populate_physmap (struct memop_args *a) { -struct page_info *page; +struct page_info *page =NULL ;Why?
Spurious line from a previous version. I will remove it.
Quoted 47 lines
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 128
Quoted 10 lines
xen/common/memory.c +4
-1@@ -122,7 +122,29 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +if ( d == dom0 &&is_dom0_mapped_11 () ) + { + mfn = gpfn; +if (!mfn_valid (mfn))Coding style.
Quoted 6 lines
xen/common/memory.c +6
-0+ { +gdprintk (XENLOG_INFO ,"Invalid mfn 0x%" PRI_xen_pfn"\n" , + mfn); + goto out; + } +xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 144
Quoted 10 lines
xen/common/memory.c +10
-0+ page =mfn_to_page (mfn); +if ( !get_page (page, d) ) + { +gdprintk (XENLOG_INFO , +"mfn 0x%" PRI_xen_pfn" doesn't belong to dom0\n" , + mfn); + goto out; + } +put_page (page); + }I think this hack doesn't belong into a common file. Rather than having the (anyway oddly named)
is_dom0_mapped_11(), it would seem more clean to have this implemented by an inline function for ARM, returning the structpage_info* (and getting #define-d to NULL for all other cases, perhaps not even in an x86 header, but right in the source file).And even if we were to stay with the implementation here, for being at least half way sane the checking macro should take a domain argument rather than requiring the extra "d == dom0" check up front. Plus the "11" there is bogus - I first read this as "eleven" rather than "1:1", wondering what eleven here was about. I'd suggest something like
is_domain_direct_mapped()oris_domain_identity_mapped().Jan
Signature · 1 line
Julien Grall