boot allocator: Use arch helper for virt_to_mfn on DIRECTMAP
PATCH v2 1/1 boot allocator: Use arch helper for virt_to_mfn on DIRECTMAP
From: Vijaya Kumar K <[email protected]>
On ARM, virt_to_mfn uses the hardware for address translation. So if the virtual address is not mapped translation fault is raised.On ARM, DIRECTMAP_VIRT region is direct mapped.
On ARM with NUMA, While initializing second memory node, panic is triggered from init_node_heap() when virt_to_mfn() is called for DIRECTMAP_VIRT region address.
Here the check is made to ensure that MFN less than max MFN mapped. The max MFN is found by calling virt_to_mfn of DIRECTMAP_VIRT_END region. Since DIRECMAP_VIRT region is not mapped to any virtual address on ARM, it fails.
In this patch, instead of calling virt_to_mfn(), arch helper arch_mfn_below_directmap_max_mfn() is introduced. On ARM this arch helper will return 1 always and for x86 this helper does virt_to_mfn.
--- xen/common/page_alloc.c | 7 ++----- xen/include/asm-arm/mm.h | 7 +++++++ xen/include/asm-x86/page.h | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-)
xen/common/page_alloc.c +2 -5
@@ -520,9 +520,6 @@ static unsigned long init_node_heap(int node, unsigned long mfn,unsigned long needed = (sizeof (**_heap) +sizeof (**avail) *NR_ZONES +PAGE_SIZE -1 ) >>PAGE_SHIFT ; -#ifdef DIRECTMAP_VIRT_END -unsigned long eva =min (DIRECTMAP_VIRT_END ,HYPERVISOR_VIRT_END ); -#endif int i, j;if ( !first_node_initialised )
@@ -534,7 +531,7 @@ static unsigned long init_node_heap(int node, unsigned long mfn, }#ifdef DIRECTMAP_VIRT_END else if ( *use_tail && nr >= needed && - (mfn + nr) <= (virt_to_mfn(eva - 1) + 1) && + arch_mfn_below_directmap_max_mfn(mfn + nr) && (!xenheap_bits || !((mfn + nr - 1) >> (xenheap_bits - PAGE_SHIFT))) ) {
@@ -543,7 +540,7 @@ static unsigned long init_node_heap(int node, unsigned long mfn,PAGE_SIZE -sizeof (**avail) *NR_ZONES ; }else if ( nr >= needed && - (mfn + needed) <= (virt_to_mfn (eva -1 ) +1 ) && +arch_mfn_below_directmap_max_mfn (mfn + needed) && (!xenheap_bits || !((mfn + needed -1 ) >> (xenheap_bits -PAGE_SHIFT ))) ) {
xen/include/asm-arm/mm.h +7 -0
@@ -260,6 +260,13 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags)#define virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT)#define mfn_to_virt (mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) +/* +* On ARM DIRECTMAP_VIRT region is directly mapped. Hence return true; +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +return 1 ; +}/* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page (const void *v)
xen/include/asm-x86/page.h +16 -0
@@ -18,6 +18,7 @@#ifndef __ASSEMBLY__# include <asm/types.h> # include <xen/lib.h> +# include <xen/kernel.h> #endif #include <asm/x86_64/page.h>
@@ -374,6 +375,21 @@ perms_strictly_increased(uint32_t old_flags, uint32_t new_flags) return ((of | (of ^ nf)) == nf); } +/* +* x86 maps DIRECTMAP_VIRT to physical memory. Get the mfn for directmap +* memory region. +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +#ifdef DIRECTMAP_VIRT_END +unsigned long eva =min (DIRECTMAP_VIRT_END ,HYPERVISOR_VIRT_END ); + +return mfn <= (virt_to_mfn (eva -1 ) +1 ); +#else +return 0 ; +#endif +} +#endif /* !__ASSEMBLY__ */ #define PAGE_ALIGN (x) (((x) + PAGE_SIZE - 1) & PAGE_MASK)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.03.17 at 12:43, <[email protected]> wrote:
xen/include/asm-arm/mm.h static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags) · line 269
Quoted 10 lines
xen/include/asm-arm/mm.h +7
-0@@ -260,6 +260,13 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags)#define virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT)#define mfn_to_virt (mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) +/* +* On ARM DIRECTMAP_VIRT region is directly mapped. Hence return true; +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +return 1 ; +}
bool and true respectively, please (also on the x86 side).
xen/include/asm-x86/page.h line 21
Quoted 7 lines
xen/include/asm-x86/page.h +1
-0@@ -18,6 +18,7 @@#ifndef __ASSEMBLY__# include <asm/types.h> # include <xen/lib.h> +# include <xen/kernel.h>
Why?
xen/include/asm-x86/page.h perms_strictly_increased(uint32_t old_flags, uint32_t new_flags) · line 384
Quoted 11 lines
xen/include/asm-x86/page.h +7
-0@@ -374,6 +375,21 @@ perms_strictly_increased(uint32_t old_flags, uint32_t new_flags)return ((of | (of ^ nf)) == nf); } +/* +* x86 maps DIRECTMAP_VIRT to physical memory. Get the mfn for directmap +* memory region. +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +#ifdef DIRECTMAP_VIRT_END
The symbol is always defined on x86 afaics - no need for the #ifdef.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.03.17 at 12:43, <[email protected]> wrote:
xen/include/asm-arm/mm.h +0
-0@@ -260,6 +260,13 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags)#define virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT)#define mfn_to_virt (mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
Quoted 9 lines
xen/include/asm-arm/mm.h static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags) · line 269
Quoted 7 lines
xen/include/asm-arm/mm.h +7
-0+/* +* On ARM DIRECTMAP_VIRT region is directly mapped. Hence return true; +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +return 1 ; +}bool and true respectively, please (also on the x86 side).
OK
Quoted 10 lines
xen/include/asm-x86/page.h line 21
Quoted 8 lines
xen/include/asm-x86/page.h +1
-0@@ -18,6 +18,7 @@#ifndef __ASSEMBLY__# include <asm/types.h> # include <xen/lib.h> +# include <xen/kernel.h> Why?
Compilation fails saying min() is not defined
Quoted 5 lines
Quoted 5 lines
xen/include/asm-x86/page.h +0
-0@@ -374,6 +375,21 @@ perms_strictly_increased(uint32_t old_flags, uint32_t new_flags)return ((of | (of ^ nf)) == nf); }
Quoted 9 lines
xen/include/asm-x86/page.h perms_strictly_increased(uint32_t old_flags, uint32_t new_flags) · line 384
Quoted 7 lines
xen/include/asm-x86/page.h +7
-0+/* +* x86 maps DIRECTMAP_VIRT to physical memory. Get the mfn for directmap +* memory region. +*/ +static inline bool_t arch_mfn_below_directmap_max_mfn (unsigned long mfn) +{ +#ifdef DIRECTMAP_VIRT_END The symbol is always defined on x86 afaics - no need for the #ifdef.
ok.
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hello Vijay,
Quoted 5 lines · On 13/03/17 11:43, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
On ARM,
virt_to_mfnuses the hardware for address translation. So if the virtual address is not mapped translation fault is raised.On ARM,DIRECTMAP_VIRTregion is direct mapped.
This is not true. As I said before, all the memory will be direct mapped on ARM64 but not on ARM32.
For ARM32, only xenheap will be direct mapped. So you may want to return is_xenheap_mfn(...). Or even return false in all the case. Either is fine by me, but it would need to be explained in the code.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 11 lines · Julien Grall
Hello Vijay,
Quoted 6 lines · On 13/03/17 11:43, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
On ARM,
virt_to_mfnuses the hardware for address translation. So if the virtual address is not mapped translation fault is raised.On ARM,DIRECTMAP_VIRTregion is direct mapped.
Quoted 6 lines
This is not true. As I said before, all the memory will be direct mapped on ARM64 but not on ARM32.
For ARM32, only xenheap will be direct mapped. So you may want to return
is_xenheap_mfn(...). Or even return false in all the case. Either is fine by me, but it would need to be explained in the code.
Is this ok?.
/*
* On ARM64 DIRECTMAP_VIRT region is directly mapped. Hence return true;
* On ARM only xenheap memory is directly mapped. Hence return false. */
static inline bool_t arch_mfn_below_directmap_max_mfn(unsigned long mfn) {
#ifdef CONFIG_ARM_64
return true;
#else
return false;#endif
}
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Vijay,
Quoted 27 lines · Vijay Kilari
Quoted 11 lines · Julien Grall
Hello Vijay,
Quoted 6 lines · On 13/03/17 11:43, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
On ARM,
virt_to_mfnuses the hardware for address translation. So if the virtual address is not mapped translation fault is raised.On ARM,DIRECTMAP_VIRTregion is direct mapped.Quoted 6 lines
This is not true. As I said before, all the memory will be direct mapped on ARM64 but not on ARM32.
For ARM32, only xenheap will be direct mapped. So you may want to return
is_xenheap_mfn(...). Or even return false in all the case. Either is fine by me, but it would need to be explained in the code.Is this ok?.
/*
* On ARM64DIRECTMAP_VIRTregion is directly mapped. Hence return true;
* On ARM only xenheap memory is directly mapped. Hence return false. */
static inlinebool_tarch_mfn_below_directmap_max_mfn(unsigned long mfn){
Quoted 6 lines
#ifdef CONFIG_ARM_64 return true; #else return false;#endif
}
I would implement the helper in {arm32,arm64}/mm.h and avoid the #ifdef in the implementation.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel