Prerequisite patches for R82 upstreaming
cover Prerequisite patches for R82 upstreaming
In this serie I've taken out patches from the R82 branch already in the ML[1] and some new patches I've done based on the current status of staging that will not impact the current Armv8-R earlyboot work.
[1] https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/
Luca Fancellu (3):
common/vmap: Fall back to simple allocator when !HAS_VMAP arm/setup: Move MMU specific extern declarations to mmu/mm.h xen/arm: Use vmap_contig instead of __vmap where it's possible
Penny Zheng (2):
xen/arm: only map the init text section RW in free_init_memory xen/arm: do not give memory back to static heap
xen/arch/arm/alternative.c | 3 +-- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/cpuerrata.c | 5 ++-- xen/arch/arm/include/asm/mmu/mm.h | 11 +++++++++ xen/arch/arm/include/asm/setup.h | 11 --------- xen/arch/arm/kernel.c | 5 ++-- xen/arch/arm/livepatch.c | 3 +-- xen/arch/arm/mmu/setup.c | 16 +++++++++---- xen/arch/arm/setup.c | 27 +++++++++++---------- xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/device-tree/device-tree.c | 3 +++ xen/common/vmap.c | 7 ++++++ xen/include/xen/bootfdt.h | 11 ++++++++- xen/include/xen/vmap.h | 9 ++----- xen/include/xen/xvmalloc.h | 36 ++++++++++++++++++++++++---- 16 files changed, 100 insertions(+), 55 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 common/vmap: Fall back to simple allocator when !HAS_VMAP
When HAS_VMAP is disabled, the xv{malloc,zalloc,...} functions should fall back to the simple x{malloc,zalloc,...} variant, implement that because MPU systems won't have virtual memory.
Additionally remove VMAP_VIRT_START from vmap.h guards since MPU systems won't have it defined and move iounmap function to the vmap.c file, because it uses the vunmap function that won't be compiled in when !HAS_VMAP.
---
This is a rework of this one: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
where I hope I've understood correctly what Jan Beulich was suggesting here:
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/#25409119
--- xen/common/vmap.c | 7 +++++++ xen/include/xen/vmap.h | 9 ++------- xen/include/xen/xvmalloc.h | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 12 deletions(-)
xen/common/vmap.c +7 -0
@@ -426,3 +426,10 @@ void *_xvrealloc(void *va, size_t size, unsigned int align)return ptr; } + +void iounmap (void __iomem *va) +{ +unsigned long addr = (unsigned long )(void __force *)va; + +vunmap ((void *)(addr &PAGE_MASK )); +}
xen/include/xen/vmap.h +2 -7
@@ -5,7 +5,7 @@* purpose area (VMAP_DEFAULT) and a livepatch-specific area (VMAP_XEN). The * latter is used when loading livepatches and the former for everything else. */ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__#include <xen/mm-frame.h>
@@ -128,12 +128,7 @@ void __iomem *ioremap(paddr_t pa, size_t len);unsigned int vmap_size (const void *va);/* Analogous to vunmap(), but for IO memory mapped via ioremap() */ -static inline void iounmap (void __iomem *va) -{ -unsigned long addr = (unsigned long )(void __force *)va; - -vunmap ((void *)(addr &PAGE_MASK )); -} +void iounmap (void __iomem *va);/* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ void *arch_vmap_virt_end (void );
xen/include/xen/xvmalloc.h +31 -5
@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP ) +/* Free any of the above. */ void xvfree (void *va); +/* Underlying functions */ +void *_xvmalloc (size_t size,unsigned int align); +void *_xvzalloc (size_t size,unsigned int align); +void *_xvrealloc (void *va,size_t size,unsigned int align); + +#else + +static inline void xvfree (void *va) +{ +xfree (va); +} + +void *_xvmalloc (size_t size,unsigned int align) +{ +return _xmalloc (size, align); +} + +void *_xvzalloc (size_t size,unsigned int align) +{ +return _xzalloc (size, align); +} + +void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif +/* Free an allocation, and zero the pointer to it. */ #define XVFREE (p) do { \ xvfree(p); \ (p) = NULL; \ } while ( false ) -/* Underlying functions */ -void *_xvmalloc (size_t size,unsigned int align); -void *_xvzalloc (size_t size,unsigned int align); -void *_xvrealloc (void *va,size_t size,unsigned int align); -static inline void *_xvmalloc_array (size_t size,unsigned int align,unsigned long num) {
Signature · 1 line
2.34.1
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
xen/common/vmap.c void *_xvrealloc(void *va, size_t size, unsigned int align) · line 435
Quoted 13 lines · Luca Fancellu
xen/common/vmap.c +7
-0@@ -426,3 +426,10 @@ void *_xvrealloc(void *va, size_t size, unsigned int align)return ptr; } + +void iounmap (void __iomem *va) +{ +unsigned long addr = (unsigned long )(void __force *)va; + +vunmap ((void *)(addr &PAGE_MASK )); +}
Why is this being moved here, and converted from inline to out-of-line? What the description says is insufficient imo, as even if you mean to only support vmap_contig() and ioremap() on MPU systems, you'll still need both vunmap() and iounmap().
Plus, if it really needs converting, I don't think it should live at the very end of the file, past _xvmalloc() and friends. Better suitable places may then be next to vunmap() itself, or between vfree() and xvfree().
xen/include/xen/vmap.h line 9
Quoted 9 lines
xen/include/xen/vmap.h +1
-1@@ -5,7 +5,7 @@* purpose area (VMAP_DEFAULT) and a livepatch-specific area (VMAP_XEN). The * latter is used when loading livepatches and the former for everything else. */ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__
With this adjustment, where are the functions defined that you "unhide" the declarations of, in the MPU case? As you say in the description, vmap.c won't be built in that case.
Also both here and ...
xen/include/xen/xvmalloc.h line 43
Quoted 7 lines
xen/include/xen/xvmalloc.h +1
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP )
... here: Please use the shorter #ifdef when possible.
Jan
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Quoted 24 lines · Jan Beulich
xen/common/vmap.c void *_xvrealloc(void *va, size_t size, unsigned int align) · line 435
Quoted 13 lines · Luca Fancellu
xen/common/vmap.c +7
-0@@ -426,3 +426,10 @@ void *_xvrealloc(void *va, size_t size, unsigned int align)return ptr; } + +void iounmap (void __iomem *va) +{ +unsigned long addr = (unsigned long )(void __force *)va; + +vunmap ((void *)(addr &PAGE_MASK )); +}Why is this being moved here, and converted from inline to out-of-line? What the description says is insufficient imo, as even if you mean to only support
vmap_contig()andioremap()on MPU systems, you'll still need bothvunmap()andiounmap().
Quoted 3 lines
Plus, if it really needs converting, I don't think it should live at the very end of the file, past
_xvmalloc()and friends. Better suitable places may then be next tovunmap()itself, or betweenvfree()andxvfree().
I’ll try to keep it as it was originally, I gave a brief look into the R82 branch and it should be fine. I’m planning to define vmap_config(), vunmap(), ioremap(), iounmap() in a vmap-mpu.c under arch/arm/mpu
Quoted 14 lines
xen/include/xen/vmap.h line 9
Quoted 10 lines
xen/include/xen/vmap.h +1
-1@@ -5,7 +5,7 @@* purpose area (VMAP_DEFAULT) and a livepatch-specific area (VMAP_XEN). The * latter is used when loading livepatches and the former for everything else. */ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__With this adjustment, where are the functions defined that you "unhide" the declarations of, in the MPU case? As you say in the description,
vmap.cwon't be built in that case.
Sure, I’ll wrap what can’t be used in MPU case with HAS_VMAP, I would like to keep out:
void *vmap_contig(mfn_t mfn, unsigned int nr);
void vunmap(const void *va);
void __iomem *ioremap(paddr_t pa, size_t len);
static inline void iounmap(void __iomem *va)
static inline void vm_init(void)
In order to don’t put too many #ifdef, are you ok if I move the declarations in order to have these close to each other. like below:
xen/include/xen/vmap.h +31 -25
@@ -11,6 +11,8 @@#include <xen/mm-frame.h> #include <xen/page-size.h> +#ifdef CONFIG_HAS_VMAP +/* Identifiers for the linear ranges tracked by vmap */ enum vmap_region {/*
@@ -68,25 +70,6 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,*/ void *vmap (const mfn_t *mfn,unsigned int nr); -/* -* Maps physically contiguous pages onto the VMAP_DEFAULT vmap region -* -* @param mfn Base mfn of the physical region -* @param nr Number of mfns in the physical region -* @return Pointer to the mapped area on success; NULL otherwise. -*/ -void *vmap_contig (mfn_t mfn,unsigned int nr); - -/* -* Unmaps a range of virtually contiguous memory from one of the vmap regions -* -* The system remembers internally how wide the mapping is and unmaps it all. -* It also can determine the vmap region type from the `va`. -* -* @param va Virtual base address of the range to unmap -*/ -void vunmap (const void *va); -/* * Allocate `size` octets of possibly non-contiguous physical memory and map * them contiguously in the VMAP_DEFAULT vmap region
@@ -112,6 +95,33 @@ void *vzalloc(size_t size);*/ void vfree (void *va); +/* Return the number of pages in the mapping starting at address 'va' */ +unsigned int vmap_size (const void *va); + +/* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ +void *arch_vmap_virt_end (void ); + +#else /* !CONFIG_HAS_VMAP */ + +/* +* Maps physically contiguous pages onto the VMAP_DEFAULT vmap region +* +* @param mfn Base mfn of the physical region +* @param nr Number of mfns in the physical region +* @return Pointer to the mapped area on success; NULL otherwise. +*/ +void *vmap_contig (mfn_t mfn,unsigned int nr); + +/* +* Unmaps a range of virtually contiguous memory from one of the vmap regions +* +* The system remembers internally how wide the mapping is and unmaps it all. +* It also can determine the vmap region type from the `va`. +* +* @param va Virtual base address of the range to unmap +*/ +void vunmap (const void *va); +/* * Analogous to vmap_contig(), but for IO memory *
@@ -124,9 +134,6 @@ void vfree(void *va);*/ void __iomem *ioremap (paddr_t pa,size_t len); -/* Return the number of pages in the mapping starting at address 'va' */ -unsigned int vmap_size (const void *va); -/* Analogous to vunmap(), but for IO memory mapped via ioremap() */ static inline void iounmap (void __iomem *va) {
@@ -135,9 +142,6 @@ static inline void iounmap(void __iomem *va)vunmap ((void *)(addr &PAGE_MASK )); } -/* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ -void *arch_vmap_virt_end (void ); -/* Initialises the VMAP_DEFAULT virtual range */ static inline void vm_init (void ) {
@@ -146,4 +150,6 @@ static inline void vm_init(void)#endif } +#endif /* CONFIG_HAS_VMAP */ +#endif /* __XEN_VMAP_H__ */
Quoted 9 lines
Also both here and ...
Quoted 6 lines
xen/include/xen/xvmalloc.h +0
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr)))))
Quoted 3 lines
xen/include/xen/xvmalloc.h line 43
Quoted 1 line
xen/include/xen/xvmalloc.h +1
-0+#if defined(CONFIG_HAS_VMAP )... here: Please use the shorter #ifdef when possible.
sure I will
Quoted 2 lines
Jan
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Quoted 52 lines · Luca Fancellu
Quoted 24 lines · Jan Beulich
xen/common/vmap.c void *_xvrealloc(void *va, size_t size, unsigned int align) · line 435
Quoted 13 lines · Luca Fancellu
xen/common/vmap.c +7
-0@@ -426,3 +426,10 @@ void *_xvrealloc(void *va, size_t size, unsigned int align)return ptr; } + +void iounmap (void __iomem *va) +{ +unsigned long addr = (unsigned long )(void __force *)va; + +vunmap ((void *)(addr &PAGE_MASK )); +}Why is this being moved here, and converted from inline to out-of-line? What the description says is insufficient imo, as even if you mean to only support
vmap_contig()andioremap()on MPU systems, you'll still need bothvunmap()andiounmap().Quoted 3 lines
Plus, if it really needs converting, I don't think it should live at the very end of the file, past
_xvmalloc()and friends. Better suitable places may then be next tovunmap()itself, or betweenvfree()andxvfree().I’ll try to keep it as it was originally, I gave a brief look into the R82 branch and it should be fine. I’m planning to define
vmap_config(),vunmap(),ioremap(),iounmap()in avmap-mpu.cunderarch/arm/mpuQuoted 14 lines
xen/include/xen/vmap.h line 9
Quoted 10 lines
xen/include/xen/vmap.h +1
-1@@ -5,7 +5,7 @@* purpose area (VMAP_DEFAULT) and a livepatch-specific area (VMAP_XEN). The * latter is used when loading livepatches and the former for everything else. */ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__With this adjustment, where are the functions defined that you "unhide" the declarations of, in the MPU case? As you say in the description,
vmap.cwon't be built in that case.Sure, I’ll wrap what can’t be used in MPU case with
HAS_VMAP, I would like to keep out:void *vmap_contig(mfn_t mfn, unsigned int nr);
void
vunmap(const void *va);
Quoted 7 lines
void
__iomem*ioremap(paddr_t pa,size_tlen);static inline void
iounmap(void __iomem *va)static inline void
vm_init(void)In order to don’t put too many #ifdef, are you ok if I move the declarations in order to have these close to each other. like below:
Some re-arrangement ought to be fine, especially when the #ifdef is accompanied by a comment. I can't see how there can be #else though.
Jan
Quoted 98 lines
xen/include/xen/vmap.h +31
-25@@ -11,6 +11,8 @@#include <xen/mm-frame.h> #include <xen/page-size.h> +#ifdef CONFIG_HAS_VMAP +/* Identifiers for the linear ranges tracked by vmap */ enum vmap_region {/* @@ -68,25 +70,6 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,*/ void *vmap (const mfn_t *mfn,unsigned int nr); -/* -* Maps physically contiguous pages onto the VMAP_DEFAULT vmap region -* -* @param mfn Base mfn of the physical region -* @param nr Number of mfns in the physical region -* @return Pointer to the mapped area on success; NULL otherwise. -*/ -void *vmap_contig (mfn_t mfn,unsigned int nr); - -/* -* Unmaps a range of virtually contiguous memory from one of the vmap regions -* -* The system remembers internally how wide the mapping is and unmaps it all. -* It also can determine the vmap region type from the `va`. -* -* @param va Virtual base address of the range to unmap -*/ -void vunmap (const void *va); -/* * Allocate `size` octets of possibly non-contiguous physical memory and map * them contiguously in the VMAP_DEFAULT vmap region @@ -112,6 +95,33 @@ void *vzalloc(size_t size);*/ void vfree (void *va); +/* Return the number of pages in the mapping starting at address 'va' */ +unsigned int vmap_size (const void *va); + +/* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ +void *arch_vmap_virt_end (void ); + +#else /* !CONFIG_HAS_VMAP */ + +/* +* Maps physically contiguous pages onto the VMAP_DEFAULT vmap region +* +* @param mfn Base mfn of the physical region +* @param nr Number of mfns in the physical region +* @return Pointer to the mapped area on success; NULL otherwise. +*/ +void *vmap_contig (mfn_t mfn,unsigned int nr); + +/* +* Unmaps a range of virtually contiguous memory from one of the vmap regions +* +* The system remembers internally how wide the mapping is and unmaps it all. +* It also can determine the vmap region type from the `va`. +* +* @param va Virtual base address of the range to unmap +*/ +void vunmap (const void *va); +/* * Analogous to vmap_contig(), but for IO memory * @@ -124,9 +134,6 @@ void vfree(void *va);*/ void __iomem *ioremap (paddr_t pa,size_t len); -/* Return the number of pages in the mapping starting at address 'va' */ -unsigned int vmap_size (const void *va); -/* Analogous to vunmap(), but for IO memory mapped via ioremap() */ static inline void iounmap (void __iomem *va) {@@ -135,9 +142,6 @@ static inline void iounmap(void __iomem *va)vunmap ((void *)(addr &PAGE_MASK )); } -/* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ -void *arch_vmap_virt_end (void ); -/* Initialises the VMAP_DEFAULT virtual range */ static inline void vm_init (void ) {@@ -146,4 +150,6 @@ static inline void vm_init(void)#endif } +#endif /* CONFIG_HAS_VMAP */ +#endif /* __XEN_VMAP_H__ */
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Quoted 11 lines
Quoted 11 lines
Sure, I’ll wrap what can’t be used in MPU case with
HAS_VMAP, I would like to keep out:void *vmap_contig(mfn_t mfn, unsigned int nr);
void
vunmap(const void *va);void
__iomem*ioremap(paddr_t pa,size_tlen);
Quoted 8 lines
Quoted 5 lines
static inline void
iounmap(void __iomem *va)static inline void
vm_init(void)In order to don’t put too many #ifdef, are you ok if I move the declarations in order to have these close to each other. like below:
Some re-arrangement ought to be fine, especially when the #ifdef is accompanied by a comment. I can't see how there can be #else though.
Yes right, clearly not tested, thanks I’ll do the changes
Quoted 2 lines
Jan
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
In reply to Luca FancelluQuoted 31 lines · Luca Fancellu
xen/include/xen/xvmalloc.h +20
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP ) +/* Free any of the above. */ void xvfree (void *va); +/* Underlying functions */ +void *_xvmalloc (size_t size,unsigned int align); +void *_xvzalloc (size_t size,unsigned int align); +void *_xvrealloc (void *va,size_t size,unsigned int align); + +#else + +static inline void xvfree (void *va) +{ +xfree (va); +} + +void *_xvmalloc (size_t size,unsigned int align) +{ +return _xmalloc (size, align); +} + +void *_xvzalloc (size_t size,unsigned int align)
xen/include/xen/xvmalloc.h line 75
Quoted 10 lines
xen/include/xen/xvmalloc.h +10
-0+{ +return _xzalloc (size, align); +} + +void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif
Does this really compile with the wrappers not being static inline ?
That aside, could we not do this using conditional aliases, rather than wrapping the functions? It would certainly be shorter, code wise.
~Andrew
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Quoted 40 lines · Andrew Cooper
Quoted 35 lines · Luca Fancellu
xen/include/xen/xvmalloc.h +24
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP ) +/* Free any of the above. */ void xvfree (void *va); +/* Underlying functions */ +void *_xvmalloc (size_t size,unsigned int align); +void *_xvzalloc (size_t size,unsigned int align); +void *_xvrealloc (void *va,size_t size,unsigned int align); + +#else + +static inline void xvfree (void *va) +{ +xfree (va); +} + +void *_xvmalloc (size_t size,unsigned int align) +{ +return _xmalloc (size, align); +} + +void *_xvzalloc (size_t size,unsigned int align) +{ +return _xzalloc (size, align); +} +
Quoted 8 lines
xen/include/xen/xvmalloc.h line 75
Quoted 6 lines
xen/include/xen/xvmalloc.h +6
-0+void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif Does this really compile with the wrappers not being static inline ?
wow, yes it is compiling and I’m surprised about that, this was clearly a mistake, I’ll fix
Quoted 3 lines
That aside, could we not do this using conditional aliases, rather than wrapping the functions? It would certainly be shorter, code wise.
I’ll ping you to understand better what you mean here
Quoted 2 lines
~Andrew
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
In reply to Andrew CooperQuoted 49 lines · Andrew Cooper
Quoted 31 lines · Luca Fancellu
xen/include/xen/xvmalloc.h +20
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP ) +/* Free any of the above. */ void xvfree (void *va); +/* Underlying functions */ +void *_xvmalloc (size_t size,unsigned int align); +void *_xvzalloc (size_t size,unsigned int align); +void *_xvrealloc (void *va,size_t size,unsigned int align); + +#else + +static inline void xvfree (void *va) +{ +xfree (va); +} + +void *_xvmalloc (size_t size,unsigned int align) +{ +return _xmalloc (size, align); +} + +void *_xvzalloc (size_t size,unsigned int align)xen/include/xen/xvmalloc.h line 75
Quoted 10 lines
xen/include/xen/xvmalloc.h +10
-0+{ +return _xzalloc (size, align); +} + +void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif Does this really compile with the wrappers not being static inline ?
Quoted 2 lines
That aside, could we not do this using conditional aliases, rather than wrapping the functions? It would certainly be shorter, code wise.
Do you mean something like below?
#define xvfree xfree
#define _xvmalloc _xmalloc
[…]
Quoted 2 lines
~Andrew
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Quoted 47 lines · Luca Fancellu
Quoted 47 lines · Andrew Cooper
Quoted 31 lines · Luca Fancellu
xen/include/xen/xvmalloc.h +20
-0@@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) +#if defined(CONFIG_HAS_VMAP ) +/* Free any of the above. */ void xvfree (void *va); +/* Underlying functions */ +void *_xvmalloc (size_t size,unsigned int align); +void *_xvzalloc (size_t size,unsigned int align); +void *_xvrealloc (void *va,size_t size,unsigned int align); + +#else + +static inline void xvfree (void *va) +{ +xfree (va); +} + +void *_xvmalloc (size_t size,unsigned int align) +{ +return _xmalloc (size, align); +} + +void *_xvzalloc (size_t size,unsigned int align)xen/include/xen/xvmalloc.h line 75
Quoted 10 lines
xen/include/xen/xvmalloc.h +10
-0+{ +return _xzalloc (size, align); +} + +void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif Does this really compile with the wrappers not being static inline ?
Quoted 7 lines
Quoted 2 lines
That aside, could we not do this using conditional aliases, rather than wrapping the functions? It would certainly be shorter, code wise.
Do you mean something like below?
#define xvfree xfree
#define_xvmalloc_xmalloc
[…]
I mean __attribute__((__alias__("")))
There are two examples in tree already. See efi_compat_get_info() being aliased to efi_get_info()
In this case, in the !HAS_VMAP case, we'd just declare _xmalloc() to have an alias called _xvmalloc() too.
This avoids needing to wrap every function in the headers.
~Andrew
Re: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP
Hi Andrew,
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
xen/include/xen/xvmalloc.h line 75
Quoted 7 lines
xen/include/xen/xvmalloc.h +7
-0+ +void *_xvrealloc (void *va,size_t size,unsigned int align) +{ +return _xrealloc (va, size, align); +} + +#endif Does this really compile with the wrappers not being static inline ?
Quoted 7 lines
Quoted 2 lines
That aside, could we not do this using conditional aliases, rather than wrapping the functions? It would certainly be shorter, code wise.
Do you mean something like below?
#define xvfree xfree
#define_xvmalloc_xmalloc
[…]I mean __attribute__((__alias__("")))
Quoted 7 lines
There are two examples in tree already. See
efi_compat_get_info()being aliased toefi_get_info()In this case, in the !HAS_VMAP case, we'd just declare
_xmalloc()to have an alias called_xvmalloc()too.This avoids needing to wrap every function in the headers.
I’m getting:
error: ‘xvfree’ aliased to undefined symbol ‘xfree’
looking into the documentation it says:
“It is an error if the alias target is not defined in the same translation unit as the alias."
So I think I can’t use this one here.
Should I continue to do in the other way? Or using #define?
Quoted 2 lines
~Andrew
PATCH 2/5 arm/setup: Move MMU specific extern declarations to mmu/mm.h
In reply to Luca FancelluMove some extern declarations related to MMU structures and define from asm/setup.h to asm/mm.h, in order to increase encapsulation and allow the MPU part to build, since it has no clue about them.
--- xen/arch/arm/include/asm/mmu/mm.h | 11 +++++++++++ xen/arch/arm/include/asm/setup.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-)
xen/arch/arm/include/asm/mmu/mm.h +11 -0
@@ -12,6 +12,17 @@ extern vaddr_t directmap_virt_start;extern unsigned long directmap_base_pdx;#endif +extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES ]; + +#ifdef CONFIG_ARM_64 +extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES ]; +#endif +extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES *XEN_NR_ENTRIES (2 )]; +extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES ]; +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)/*
xen/arch/arm/include/asm/setup.h +0 -11
@@ -65,17 +65,6 @@ int map_irq_to_domain(struct domain *d, unsigned int irq,int map_range_to_domain (const struct dt_device_node *dev,uint64_t addr,uint64_t len,void *data); -extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES ]; - -#ifdef CONFIG_ARM_64 -extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES ]; -#endif -extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES *XEN_NR_ENTRIES (2 )]; -extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES ]; -/* Find where Xen will be residing at runtime and return a PT entry */ lpae_t pte_of_xenaddr (vaddr_t va);
Signature · 1 line
2.34.1
Re: [PATCH 2/5] arm/setup: Move MMU specific extern declarations to mmu/mm.h
Hi Luca,
Quoted 2 lines · Luca Fancellu
Move some extern declarations related to MMU structures and define from
asm/setup.htoasm/mm.h, in order to increase encapsulation and
You are moving them to asm/mmu/mm.h. But I think I would prefer if they are moved to asm/mmu/setup.h because boot_* are not supposed to be used outside of boot. So it is clearer if they are still defined in a setup.h.
Quoted 41 lines
allow the MPU part to build, since it has no clue about them.
Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/include/asm/mmu/mm.h | 11 +++++++++++ xen/arch/arm/include/asm/setup.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/mmu/mm.h +11
-0@@ -12,6 +12,17 @@ extern vaddr_t directmap_virt_start;extern unsigned long directmap_base_pdx;#endif +extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES ]; + +#ifdef CONFIG_ARM_64 +extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES ]; +#endif +extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES ]; +extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES *XEN_NR_ENTRIES (2 )]; +extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES ]; +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)/* xen/arch/arm/include/asm/setup.h +0
-3@@ -65,17 +65,6 @@ int map_irq_to_domain(struct domain *d, unsigned int irq,int map_range_to_domain (const struct dt_device_node *dev,uint64_t addr,uint64_t len,void *data); -extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES ]; - -#ifdef CONFIG_ARM_64
xen/arch/arm/include/asm/setup.h int map_irq_to_domain(struct domain *d, unsigned int irq, · line 69
Quoted 10 lines
xen/arch/arm/include/asm/setup.h +0
-8-extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES ]; -#endif -extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES ]; -extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES *XEN_NR_ENTRIES (2 )]; -extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES ]; -/* Find where Xen will be residing at runtime and return a PT entry */ lpae_t pte_of_xenaddr (vaddr_t va);
Shouldn't we move this function as well?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/5] arm/setup: Move MMU specific extern declarations to mmu/mm.h
Hi Julien,
Quoted 9 lines · Julien Grall
Hi Luca,
Quoted 2 lines · Luca Fancellu
Move some extern declarations related to MMU structures and define from
asm/setup.htoasm/mm.h, in order to increase encapsulation andYou are moving them to
asm/mmu/mm.h. But I think I would prefer if they are moved toasm/mmu/setup.hbecause boot_* are not supposed to be used outside of boot. So it is clearer if they are still defined in asetup.h.
Sure I’ll move them to arm/mmu/setup.h
Quoted 6 lines
Quoted 4 lines
-
/* Find where Xen will be residing at runtime and return a PT entry */lpae_tpte_of_xenaddr(vaddr_t va);Shouldn't we move this function as well?
This one was not problematic, but I can move this one as well.
Cheers,
Luca
PATCH 3/5 xen/arm: only map the init text section RW in free_init_memory
In reply to Luca FancelluFrom: Penny Zheng <[email protected]>
In free_init_memory, we do not need to map the whole init section RW, as only init text section is mapped RO in boot time.
---
This is this one: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
--- xen/arch/arm/mmu/setup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
xen/arch/arm/mmu/setup.c +5 -3
@@ -7,6 +7,7 @@#include <xen/init.h> #include <xen/libfdt/libfdt.h> +#include <xen/pfn.h> #include <xen/sections.h> #include <xen/sizes.h> #include <xen/vmap.h>
@@ -309,16 +310,17 @@ void *__init arch_vmap_virt_end(void)void free_init_memory (void ) {paddr_t pa =virt_to_maddr (__init_begin); +unsigned long inittext_end =round_pgup ((unsigned long )_einittext);unsigned long len = __init_end - __init_begin;uint32_t insn;unsigned int i, nr = len /sizeof (insn);uint32_t *p;int rc; - rc =modify_xen_mappings ((unsigned long )__init_begin, - (unsigned long )__init_end,PAGE_HYPERVISOR_RW ); + rc =modify_xen_mappings ((unsigned long )__init_begin, inittext_end, +PAGE_HYPERVISOR_RW );if ( rc ) -panic ("Unable to map RW the init section (rc = %d)\n" , rc); +panic ("Unable to map RW the init text section (rc = %d)\n" , rc);/* * From now on, init will not be used for execution anymore,
Signature · 1 line
2.34.1
Re: [PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory
Hi Luca,
Quoted 4 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
In
free_init_memory, we do not need to map the whole init section RW, as only init text section is mapped RO in boot time.
So originally, this was done because the function was generic. But now this is MMU specific, we don't really gain that much during boot but will impair any work that would restrict some init further (for instance .init.rodata could be RO). So is it actually worth it?
Quoted 2 lines
Signed-off-by Luca Fancellu <[email protected]>
Given the link below, why are Penny and Wei's signed-off-by are missing?
Quoted 29 lines
---
This is this one: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/--- xen/arch/arm/mmu/setup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)xen/arch/arm/mmu/setup.c +2
-0@@ -7,6 +7,7 @@#include <xen/init.h> #include <xen/libfdt/libfdt.h> +#include <xen/pfn.h> #include <xen/sections.h> #include <xen/sizes.h> #include <xen/vmap.h> @@ -309,16 +310,17 @@ void *__init arch_vmap_virt_end(void)void free_init_memory (void ) {paddr_t pa =virt_to_maddr (__init_begin); +unsigned long inittext_end =round_pgup ((unsigned long )_einittext);unsigned long len = __init_end - __init_begin;uint32_t insn;unsigned int i, nr = len /sizeof (insn);uint32_t *p;int rc;
xen/arch/arm/mmu/setup.c void *__init arch_vmap_virt_end(void) · line 326
Quoted 10 lines
xen/arch/arm/mmu/setup.c +3
-3- rc =modify_xen_mappings ((unsigned long )__init_begin, - (unsigned long )__init_end,PAGE_HYPERVISOR_RW ); + rc =modify_xen_mappings ((unsigned long )__init_begin, inittext_end, +PAGE_HYPERVISOR_RW );if ( rc ) -panic ("Unable to map RW the init section (rc = %d)\n" , rc); +panic ("Unable to map RW the init text section (rc = %d)\n" , rc);/* * From now on, init will not be used for execution anymore,
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory
Hi Julien,
Quoted 10 lines · Julien Grall
Hi Luca,
Quoted 3 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
Infree_init_memory, we do not need to map the whole init section RW, as only init text section is mapped RO in boot time.So originally, this was done because the function was generic. But now this is MMU specific, we don't really gain that much during boot but will impair any work that would restrict some init further (for instance .init.rodata could be RO). So is it actually worth it?
Probably not, I’ll drop this one.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Luca Fancellu <[email protected]>Given the link below, why are Penny and Wei's signed-off-by are missing?
Internal policy, authorship is preserved though.
Cheers,
Luca
PATCH 4/5 xen/arm: Use vmap_contig instead of __vmap where it's possible
In reply to Luca FancelluCurrently the arm code uses __vmap function in few parts to map physically contiguous pages, vmap_contig was introduced recently and does the same because it's a wrapper for __vmap, so use the latter instead of the direct __vmap function.
--- xen/arch/arm/alternative.c | 3 +-- xen/arch/arm/cpuerrata.c | 5 ++--- xen/arch/arm/kernel.c | 2 +- xen/arch/arm/livepatch.c | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-)
xen/arch/arm/alternative.c +1 -2
@@ -209,8 +209,7 @@ void __init apply_alternatives_all(void)* The text and inittext section are read-only. So re-map Xen to * be able to patch the code. */ - xenmap =__vmap (&xen_mfn,1U << xen_order,1 ,1 ,PAGE_HYPERVISOR , -VMAP_DEFAULT ); + xenmap =vmap_contig (xen_mfn,1U << xen_order);/* Re-mapping Xen is not expected to fail during boot. */ BUG_ON (!xenmap);
xen/arch/arm/cpuerrata.c +2 -3
@@ -61,9 +61,8 @@ static bool copy_hyp_vect_bpi(unsigned int slot, const char *hyp_vec_start,* Vectors are part of the text that are mapped read-only. So re-map * the vector table to be able to update vectors. */ - dst_remapped =__vmap (&dst_mfn, -1UL <<get_order_from_bytes (VECTOR_TABLE_SIZE ), -1 ,1 ,PAGE_HYPERVISOR ,VMAP_DEFAULT ); + dst_remapped =vmap_contig (dst_mfn, +1UL <<get_order_from_bytes (VECTOR_TABLE_SIZE ));if ( !dst_remapped )return false;
xen/arch/arm/kernel.c +1 -1
@@ -211,7 +211,7 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset)return -ENOMEM ; } mfn =page_to_mfn (pages); - output =__vmap (&mfn,1 << kernel_order_out,1 ,1 ,PAGE_HYPERVISOR ,VMAP_DEFAULT ); + output =vmap_contig (mfn,1 << kernel_order_out); rc =perform_gunzip (output, input, size);clean_dcache_va_range (output, output_size);
xen/arch/arm/livepatch.c +1 -2
@@ -39,8 +39,7 @@ int arch_livepatch_quiesce(void)* The text section is read-only. So re-map Xen to be able to patch * the code. */ - vmap_of_xen_text =__vmap (&text_mfn,1U << text_order,1 ,1 ,PAGE_HYPERVISOR , -VMAP_DEFAULT ); + vmap_of_xen_text =vmap_contig (text_mfn,1U << text_order);if ( !vmap_of_xen_text ) {
Signature · 1 line
2.34.1
Re: [PATCH 4/5] xen/arm: Use vmap_contig instead of __vmap where it's possible
Hi Luca,
Quoted 6 lines · Luca Fancellu
Currently the arm code uses
__vmapfunction in few parts to map physically contiguous pages,vmap_contigwas introduced recently and does the same because it's a wrapper for__vmap, so use the latter instead of the direct__vmapfunction.Signed-off-by Luca Fancellu <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH 5/5 xen/arm: do not give memory back to static heap
In reply to Luca FancelluFrom: Penny Zheng <[email protected]>
If Xenheap is statically configured in Device Tree, its size is definite. So, the memory shall not be given back into static heap, like it's normally done in free_init_memory, etc, once the initialization is finished.
Extract static_heap flag from init data bootinfo, as it will be needed after destroying the init data section.
Introduce a new helper xen_is_using_staticheap() to tell whether Xenheap is statically configured in the Device Tree.
---
This is a rebase of this one: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
--- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 3 ++- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 27 ++++++++++++++------------- xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/device-tree/device-tree.c | 3 +++ xen/include/xen/bootfdt.h | 11 ++++++++++- 8 files changed, 39 insertions(+), 21 deletions(-)
xen/arch/arm/arm32/mmu/mm.c +2 -2
@@ -199,7 +199,7 @@ void __init setup_mm(void) total_pages = ram_size >>PAGE_SHIFT ; -if ( bootinfo.static_heap ) +if (xen_is_using_staticheap () ) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem ();
@@ -246,7 +246,7 @@ void __init setup_mm(void) do { - e = bootinfo.static_heap ? + e = xen_is_using_staticheap() ? fit_xenheap_in_static_heap(pfn_to_paddr(xenheap_pages), MB(32)) : consider_modules(ram_start, ram_end, pfn_to_paddr(xenheap_pages),
xen/arch/arm/kernel.c +2 -1
@@ -247,7 +247,8 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset)* Free the original kernel, update the pointers to the * decompressed kernel */ -fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 ); +if ( !xen_is_using_staticheap () ) +fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 );return 0 ; }
xen/arch/arm/mmu/setup.c +6 -2
@@ -343,8 +343,12 @@ void free_init_memory(void)if ( rc )panic ("Unable to remove the init section (rc = %d)\n" , rc); -init_domheap_pages (pa, pa + len); -printk ("Freed %ldkB init memory.\n" , (long )(__init_end-__init_begin)>>10 ); +if ( !xen_is_using_staticheap () ) + { +init_domheap_pages (pa, pa + len); +printk ("Freed %ldkB init memory.\n" , + (long )(__init_end-__init_begin) >>10 ); + } }/**
xen/arch/arm/setup.c +14 -13
@@ -206,24 +206,25 @@ void __init discard_initial_modules(void)struct bootmodules *mi = &bootinfo.modules;int i; -for ( i =0 ; i < mi->nr_mods; i++ ) +if ( !xen_is_using_staticheap () ) { -paddr_t s = mi->module[i].start; -paddr_t e = s +PAGE_ALIGN (mi->module[i].size); - -if ( mi->module[i].kind ==BOOTMOD_XEN ) -continue ; +for ( i =0 ; i < mi->nr_mods; i++ ) + { +paddr_t s = mi->module[i].start; +paddr_t e = s +PAGE_ALIGN (mi->module[i].size); -if ( !mfn_valid (maddr_to_mfn (s)) || - !mfn_valid (maddr_to_mfn (e)) ) -continue ; +if ( mi->module[i].kind ==BOOTMOD_XEN ) +continue ; -fw_unreserved_regions (s, e, init_domheap_pages,0 ); - } +if ( !mfn_valid (maddr_to_mfn (s)) || + !mfn_valid (maddr_to_mfn (e)) ) +continue ; - mi->nr_mods =0 ; +fw_unreserved_regions (s, e, init_domheap_pages,0 ); + } -remove_early_mappings (); + mi->nr_mods =0 ; + } }/* Relocate the FDT in Xen heap */
xen/common/device-tree/bootfdt.c +1 -1
@@ -403,7 +403,7 @@ static int __init process_chosen_node(const void *fdt, int node,if ( rc )return rc; - bootinfo.static_heap = true; + static_heap = true; }printk ("Checking for initrd in /chosen\n" );
xen/common/device-tree/bootinfo.c +1 -1
@@ -386,7 +386,7 @@ void __init populate_boot_allocator(void)const struct membanks *reserved_mem =bootinfo_get_reserved_mem ();paddr_t s, e; -if ( bootinfo.static_heap ) +if (xen_is_using_staticheap () ) {for ( i =0 ; i < reserved_mem->nr_banks; i++ ) {
xen/common/device-tree/device-tree.c +3 -0
@@ -25,6 +25,9 @@#include <asm/setup.h> #include <xen/err.h> +/* Flag saved when Xen is using the static heap feature (xen,static-heap) */ +bool __read_mostly static_heap; +const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;/* Host device tree */
xen/include/xen/bootfdt.h +10 -1
@@ -132,7 +132,6 @@ struct bootinfo {#ifdef CONFIG_STATIC_SHM struct shared_meminfo shmem;#endif -bool static_heap; };#ifdef CONFIG_ACPI
@@ -156,6 +155,7 @@ struct bootinfo { }extern struct bootinfo bootinfo; +extern bool static_heap;bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size);
@@ -206,4 +206,13 @@ static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) }#endif +static inline bool xen_is_using_staticheap (void ) +{ +#ifdef CONFIG_STATIC_MEMORY +return static_heap; +#else +return false; +#endif +} +#endif /* XEN_BOOTFDT_H */
Signature · 1 line
2.34.1
Re: [PATCH 5/5] xen/arm: do not give memory back to static heap
Hi Luca,
Quoted 7 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
If Xenheap is statically configured in Device Tree, its size is definite. So, the memory shall not be given back into static heap, like it's normally done in
free_init_memory, etc, once the initialization is finished.
Quoted 6 lines
Extract
static_heapflag from init data bootinfo, as it will be needed after destroying the init data section.
Introduce a new helperxen_is_using_staticheap()to tell whether Xenheap is statically configured in the Device Tree.Signed-off-by Luca Fancellu <[email protected]>
Similar to a previous patch, why wre Penny and Wei's Signed-off-by removed?
Quoted 40 lines
---
This is a rebase of this one: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/--- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 3 ++- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 27 ++++++++++++++------------- xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/device-tree/device-tree.c | 3 +++ xen/include/xen/bootfdt.h | 11 ++++++++++- 8 files changed, 39 insertions(+), 21 deletions(-)xen/arch/arm/arm32/mmu/mm.c +2
-2@@ -199,7 +199,7 @@ void __init setup_mm(void) total_pages = ram_size >>PAGE_SHIFT ; -if ( bootinfo.static_heap ) +if (xen_is_using_staticheap () ) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem ();@@ -246,7 +246,7 @@ void __init setup_mm(void) do { - e = bootinfo.static_heap ? + e = xen_is_using_staticheap() ? fit_xenheap_in_static_heap(pfn_to_paddr(xenheap_pages), MB(32)) : consider_modules(ram_start, ram_end, pfn_to_paddr(xenheap_pages),xen/arch/arm/kernel.c +0
-0
xen/arch/arm/kernel.c static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset) · line 250
Quoted 5 lines
xen/arch/arm/kernel.c +1
-1@@ -247,7 +247,8 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset)* Free the original kernel, update the pointers to the * decompressed kernel */ -fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 ); +if ( !xen_is_using_staticheap () )
The comment on top needs to be updated.
Quoted 97 lines
xen/arch/arm/kernel.c +1
-0+fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 );return 0 ; }xen/arch/arm/mmu/setup.c +6
-2@@ -343,8 +343,12 @@ void free_init_memory(void)if ( rc )panic ("Unable to remove the init section (rc = %d)\n" , rc); -init_domheap_pages (pa, pa + len); -printk ("Freed %ldkB init memory.\n" , (long )(__init_end-__init_begin)>>10 ); +if ( !xen_is_using_staticheap () ) + { +init_domheap_pages (pa, pa + len); +printk ("Freed %ldkB init memory.\n" , + (long )(__init_end-__init_begin) >>10 ); + } }/** xen/arch/arm/setup.c +14
-13@@ -206,24 +206,25 @@ void __init discard_initial_modules(void)struct bootmodules *mi = &bootinfo.modules;int i; -for ( i =0 ; i < mi->nr_mods; i++ ) +if ( !xen_is_using_staticheap () ) { -paddr_t s = mi->module[i].start; -paddr_t e = s +PAGE_ALIGN (mi->module[i].size); - -if ( mi->module[i].kind ==BOOTMOD_XEN ) -continue ; +for ( i =0 ; i < mi->nr_mods; i++ ) + { +paddr_t s = mi->module[i].start; +paddr_t e = s +PAGE_ALIGN (mi->module[i].size); -if ( !mfn_valid (maddr_to_mfn (s)) || - !mfn_valid (maddr_to_mfn (e)) ) -continue ; +if ( mi->module[i].kind ==BOOTMOD_XEN ) +continue ; -fw_unreserved_regions (s, e, init_domheap_pages,0 ); - } +if ( !mfn_valid (maddr_to_mfn (s)) || + !mfn_valid (maddr_to_mfn (e)) ) +continue ; - mi->nr_mods =0 ; +fw_unreserved_regions (s, e, init_domheap_pages,0 ); + } -remove_early_mappings (); + mi->nr_mods =0 ; + } }/* Relocate the FDT in Xen heap */ xen/common/device-tree/bootfdt.c +1
-1@@ -403,7 +403,7 @@ static int __init process_chosen_node(const void *fdt, int node,if ( rc )return rc; - bootinfo.static_heap = true; + static_heap = true; }printk ("Checking for initrd in /chosen\n" );xen/common/device-tree/bootinfo.c +1
-1@@ -386,7 +386,7 @@ void __init populate_boot_allocator(void)const struct membanks *reserved_mem =bootinfo_get_reserved_mem ();paddr_t s, e; -if ( bootinfo.static_heap ) +if (xen_is_using_staticheap () ) {for ( i =0 ; i < reserved_mem->nr_banks; i++ ) {xen/common/device-tree/device-tree.c +0
-0
xen/common/device-tree/device-tree.c line 29
Quoted 5 lines
xen/common/device-tree/device-tree.c +2
-0@@ -25,6 +25,9 @@#include <asm/setup.h> #include <xen/err.h> +/* Flag saved when Xen is using the static heap feature (xen,static-heap) */ +bool __read_mostly static_heap;
Strictly speaking, static_heap could be used with ACPI (even though there is not binding today). So I think it should not belong to device-tree.c. I think page_alloc.c may be more suitable. Also, I think static_heap will not be touched after init. So this likely wants to be __ro_after_init.
Lastly, shouldn't this be protected by #ifdef? Otherwise...
Quoted 25 lines
xen/common/device-tree/device-tree.c +1
-0+const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;/* Host device tree */ xen/include/xen/bootfdt.h +1
-1@@ -132,7 +132,6 @@ struct bootinfo {#ifdef CONFIG_STATIC_SHM struct shared_meminfo shmem;#endif -bool static_heap; };#ifdef CONFIG_ACPI @@ -156,6 +155,7 @@ struct bootinfo { }extern struct bootinfo bootinfo; +extern bool static_heap;bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size);
xen/include/xen/bootfdt.h static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) · line 209
Quoted 4 lines
xen/include/xen/bootfdt.h +1
-0@@ -206,4 +206,13 @@ static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) }#endif +static inline bool xen_is_using_staticheap (void )
... we could have xen_is_using_staticheap() != static_heap.
xen/include/xen/bootfdt.h static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) · line 218
Quoted 9 lines
xen/include/xen/bootfdt.h +8
-0+{ +#ifdef CONFIG_STATIC_MEMORY +return static_heap; +#else +return false; +#endif +} +#endif /* XEN_BOOTFDT_H */
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 5/5] xen/arm: do not give memory back to static heap
Hi Julien,
Quoted 4 lines
xen/arch/arm/kernel.c static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset) · line 250
Quoted 2 lines
xen/arch/arm/kernel.c +1
-1-fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 ); +if ( !xen_is_using_staticheap () )The comment on top needs to be updated.
I’ll update, is this ok:
/*
* In case Xen is not using the static heap feature, free the original
* kernel, update the pointers to the decompressed kernel */
Quoted 12 lines
xen/common/device-tree/device-tree.c line 28
Quoted 10 lines
xen/common/device-tree/device-tree.c +1
-0@@ -25,6 +25,9 @@#include <asm/setup.h> #include <xen/err.h> +/* Flag saved when Xen is using the static heap feature (xen,static-heap) */ +bool __read_mostly static_heap;Strictly speaking,
static_heapcould be used with ACPI (even though there is not binding today). So I think it should not belong todevice-tree.c. I thinkpage_alloc.cmay be more suitable. Also, I thinkstatic_heapwill not be touched after init. So this likely wants to be__ro_after_init.
Sure, I’ll do the modifications and I’ll move to common/page_alloc.c
Quoted 2 lines
Lastly, shouldn't this be protected by #ifdef? Otherwise...
Could you clarify if I understood correctly?
If I protect static_heap with CONFIG_STATIC_MEMORY, then I have to protect also the code in https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/common/device-tree/bootfdt.c;h=927f59c64b0d64842e2a0fd09562ac919c204e6e;hb=refs/heads/staging#l393,
is this what you are expecting?
And in that case, should it be only to protect the access to the variable or the all block? For example now if CONFIG_STATIC_MEMORY is not set, I think we parse anyway the xen,static-mem, so this tends me to think I should protect only the variable.
Cheers,
Luca