xen/arm: Allow balooning working with 1:1 memory mapping
PATCH 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 device.
--- xen/common/memory.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
xen/common/memory.c +40 -2
@@ -28,6 +28,9 @@#include <public/memory.h> #include <xsm/xsm.h> #include <xen/trace.h> +#ifdef CONFIG_ARM +#include <asm/platform.h> +#endif struct memop_args {/* INPUT */
@@ -90,7 +93,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 +125,33 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +#ifdef CONFIG_ARM +if ( d == dom0 &&platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_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 +#endif + { + page =alloc_domheap_pages (d, a->extent_order, a->memflags); + } +if (unlikely (page ==NULL ) ) {if ( !opt_tmem || (a->extent_order !=0 ) )
@@ -270,6 +299,15 @@ static void decrease_reservation(struct memop_args *a) && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) ) continue; +#ifdef CONFIG_ARM +/* With the lake for iommu, dom0 must retrieve the same pfn when +* the hypercall populate_physmap is called. +*/ +if ( a->domain == dom0 && +platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_11 ) ) +continue ; +#endif +for ( j =0 ; j < (1 << a->extent_order); j++ )if ( !guest_remove_page (a->domain, gmfn + j) ) goto out;
Signature · 1 line
1.8.3.1
Quoted 54 lines · Julien Grall
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 device.
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>--- xen/common/memory.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)xen/common/memory.c +17
-2@@ -28,6 +28,9 @@#include <public/memory.h> #include <xsm/xsm.h> #include <xen/trace.h> +#ifdef CONFIG_ARM +#include <asm/platform.h> +#endif struct memop_args {/* INPUT */ @@ -90,7 +93,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 +125,33 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +#ifdef CONFIG_ARM +if ( d == dom0 &&platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_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) )
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 150
Quoted 10 lines
xen/common/memory.c +10
-0+ { +gdprintk (XENLOG_INFO , +"mfn 0x%" PRI_xen_pfn" doesn't belong to dom0\n" , + mfn); + goto out; + } + put_page(page); + } + else +#endif
I don't know if the x86 maintainers would like that, but I would prefer to remove the ifdef CONFIG_ARM.
You just need to define a new function called is_dom0_mapped_11, that always returns false on x86 and on ARM is implemented by d == dom0 && platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11).
Then you can use it on common code.
Quoted 26 lines
xen/common/memory.c +13
-0+ { + page =alloc_domheap_pages (d, a->extent_order, a->memflags); + } +if (unlikely (page ==NULL ) ) {if ( !opt_tmem || (a->extent_order !=0 ) )@@ -270,6 +299,15 @@ static void decrease_reservation(struct memop_args *a) && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) ) continue; +#ifdef CONFIG_ARM +/* With the lake for iommu, dom0 must retrieve the same pfn when +* the hypercall populate_physmap is called. +*/ +if ( a->domain == dom0 && +platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_11 ) ) +continue ; +#endif +for ( j =0 ; j < (1 << a->extent_order); j++ )if ( !guest_remove_page (a->domain, gmfn + j) ) goto out;Signature · 1 line
1.8.3.1
Quoted 64 lines · Stefano Stabellini
Quoted 63 lines · Julien Grall
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 device.
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>--- xen/common/memory.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)xen/common/memory.c +26
-2@@ -28,6 +28,9 @@#include <public/memory.h> #include <xsm/xsm.h> #include <xen/trace.h> +#ifdef CONFIG_ARM +#include <asm/platform.h> +#endif struct memop_args {/* INPUT */ @@ -90,7 +93,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 +125,33 @@ static void populate_physmap(struct memop_args *a) }else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +#ifdef CONFIG_ARM +if ( d == dom0 &&platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_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
Quoted 8 lines
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 150
Quoted 1 line
xen/common/memory.c +1
-0+#endif I don't know if the x86 maintainers would like that, but I would prefer to remove the ifdef
CONFIG_ARM.
You just need to define a new function calledis_dom0_mapped_11, that always returns false on x86 and on ARM is implemented by d == dom0 &&platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11).
Then you can use it on common code.
With this solution, it's less clear that it's ARM specific code. We are introducing a workaround that will never be used on x86.
I would wait an opinion from other maintainers before sending a new version of this patch.
Signature · 1 line
Julien Grall
Quoted 80 lines · Julien Grall
Quoted 68 lines · Stefano Stabellini
Quoted 67 lines · Julien Grall
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 device.
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>--- xen/common/memory.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)xen/common/memory.c +20
-2@@ -28,6 +28,9 @@#include <public/memory.h> #include <xsm/xsm.h> #include <xen/trace.h> +#ifdef CONFIG_ARM +#include <asm/platform.h> +#endif struct memop_args {/* INPUT */ @@ -90,7 +93,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 +125,33 @@ static void populate_physmap(struct memop_args *a) } else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +#ifdef CONFIG_ARM + if ( d == dom0 && platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_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 todom0\n",
xen/common/memory.c +6
-0+ mfn); + goto out; + } +put_page (page); + } +else Quoted 8 lines
Quoted 1 line
+#endif
I don't know if the x86 maintainers would like that, but I would prefer to remove the ifdef
CONFIG_ARM.
You just need to define a new function calledis_dom0_mapped_11, that always returns false on x86 and on ARM is implemented by d == dom0 &&platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11).
Then you can use it on common code.
Quoted 6 lines
With this solution, it's less clear that it's ARM specific code. We are introducing a workaround that will never be used on x86.
I would wait an opinion from other maintainers before sending a new version of this patch.
Ping, any input for X86 maintainers (Keir, Jan)?
Signature · 1 line
Julien Grall
Ping, any input for X86 maintainers (Keir, Jan)?
Quoted 86 lines · Julien Grall
Quoted 68 lines · Stefano Stabellini
Quoted 67 lines · Julien Grall
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 device.
Signed-off-by Julien Grall <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>--- xen/common/memory.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)xen/common/memory.c +20
-2@@ -28,6 +28,9 @@#include <public/memory.h> #include <xsm/xsm.h> #include <xen/trace.h> +#ifdef CONFIG_ARM +#include <asm/platform.h> +#endif struct memop_args {/* INPUT */ @@ -90,7 +93,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 +125,33 @@ static void populate_physmap(struct memop_args *a) } else { - page =alloc_domheap_pages (d, a->extent_order, a->memflags); +#ifdef CONFIG_ARM + if ( d == dom0 && platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_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 todom0\n",
xen/common/memory.c +6
-0+ mfn); + goto out; + } +put_page (page); + } +else Quoted 8 lines
Quoted 1 line
+#endif
I don't know if the x86 maintainers would like that, but I would prefer to remove the ifdef
CONFIG_ARM.
You just need to define a new function calledis_dom0_mapped_11, that always returns false on x86 and on ARM is implemented by d == dom0 &&platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11).
Then you can use it on common code.With this solution, it's less clear that it's ARM specific code. We are introducing a workaround that will never be used on x86.
I would wait an opinion from other maintainers before sending a new version of this patch.
Signature · 1 line
Julien Grall