Really revert xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
cover Really revert xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
This required a bit of yak shaving in the first two patches. Tested on arm32 (w/ >4GB) and arm64.
Ian.
PATCH 1/3 xen: arm: refactor struct kernel_info
The kernel_order and kernel_image fields are ELF specific.
Also add a few comments about what things are.
--- xen/arch/arm/kernel.c | 14 +++++++------- xen/arch/arm/kernel.h | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-)
xen/arch/arm/kernel.c +7 -7
@@ -295,7 +295,7 @@ static void kernel_elf_load(struct kernel_info *info)elf_load_binary (&info->elf.elf);printk ("Free temporary kernel buffer\n" ); -free_xenheap_pages (info->kernel_img, info->kernel_order); +free_xenheap_pages (info->elf.kernel_img, info->elf.kernel_order); } static int kernel_try_elf_prepare(struct kernel_info *info,
@@ -305,14 +305,14 @@ static int kernel_try_elf_prepare(struct kernel_info *info,memset (&info->elf.elf,0 ,sizeof (info->elf.elf)); - info->kernel_order =get_order_from_bytes (size); - info->kernel_img =alloc_xenheap_pages (info->kernel_order,0 ); -if ( info->kernel_img ==NULL ) + info->elf.kernel_order =get_order_from_bytes (size); + info->elf.kernel_img =alloc_xenheap_pages (info->elf.kernel_order,0 ); +if ( info->elf.kernel_img ==NULL )panic ("Cannot allocate temporary buffer for kernel" ); -copy_from_paddr (info->kernel_img, addr, size); +copy_from_paddr (info->elf.kernel_img, addr, size); -if ( (rc =elf_init (&info->elf.elf, info->kernel_img, size )) !=0 ) +if ( (rc =elf_init (&info->elf.elf, info->elf.kernel_img, size )) !=0 ) goto err;#ifdef VERBOSE elf_set_verbose (&info->elf.elf);
@@ -351,7 +351,7 @@ err:printk ("Xen: ELF kernel broken: %s\n" ,elf_check_broken (&info->elf.elf)); -free_xenheap_pages (info->kernel_img, info->kernel_order); +free_xenheap_pages (info->elf.kernel_img, info->elf.kernel_order);return rc; }
xen/arch/arm/kernel.h +8 -6
@@ -18,14 +18,16 @@ struct kernel_info {paddr_t unassigned_mem;/* RAM not (yet) assigned to a bank */ struct dt_mem_info mem; -paddr_t dtb_paddr; +/* kernel entry point */ paddr_t entry; +/* boot blob load addresses */ +paddr_t dtb_paddr;paddr_t initrd_paddr; -void *kernel_img; -unsigned kernel_order; - +/* loader to use for this kernel */ +void (*load)(struct kernel_info *info); +/* loader specific state */ union { struct { paddr_t kernel_addr;
@@ -36,10 +38,10 @@ struct kernel_info {struct {struct elf_binary elf;struct elf_dom_parms parms; +unsigned kernel_order; +void *kernel_img; } elf; }; - -void (*load)(struct kernel_info *info); };int kernel_prepare (struct kernel_info *info);
Signature · 1 line
1.7.10.4
Re: [PATCH 1/3] xen: arm: refactor struct kernel_info
Hi Ian,
Quoted 5 lines · Ian Campbell
The
kernel_orderandkernel_imagefields are ELF specific.Also add a few comments about what things are.
Signed-off-by Ian Campbell <[email protected]>
Regards,
Signature · 1 line
Julien Grall
PATCH 2/3 xen: arm: probe the kernel to determine the guest type earlier
In reply to Ian CampbellWe need to know if the kernel is 32- or 64- bit capable sooner so that we know what sort of domain we are building when allocating memory to it (so we can place appropriate limits when allocating RAM to the guest). At the moment kernel_prepare() decides this but it needs the memory to have already been allocated.
Therefore split the probing functionality of kernel_prepare() and call it much earlier. The remainder of kernel_prepare() deals with where to place the kernel in RAM which can be deferred until kernel_load() so do so.
Document the input and output of kernel_probe() and _load().
--- xen/arch/arm/domain_build.c | 10 ++--- xen/arch/arm/kernel.c | 95 ++++++++++++++++++++++++------------------- xen/arch/arm/kernel.h | 26 +++++++++++- 3 files changed, 83 insertions(+), 48 deletions(-)
xen/arch/arm/domain_build.c +5 -5
@@ -1002,9 +1002,7 @@ int construct_dom0(struct domain *d) kinfo.unassigned_mem = dom0_mem; -allocate_memory (d, &kinfo); - - rc =kernel_prepare (&kinfo); + rc =kernel_probe (&kinfo);if ( rc <0 )return rc;
@@ -1012,6 +1010,8 @@ int construct_dom0(struct domain *d) d->arch.type = kinfo.type;#endif +allocate_memory (d, &kinfo); + rc =prepare_dtb (d, &kinfo);if ( rc <0 )return rc;
@@ -1024,8 +1024,8 @@ int construct_dom0(struct domain *d)p2m_restore_state (v);/* -* kernel_load will determine the placement of the initrd & fdt in -* RAM, so call it first. +* kernel_load will determine the placement of the kernel as well +* as the initrd & fdt in RAM, so call it first. */ kernel_load (&kinfo);/* initrd_load will fix up the fdt, so call it before dtb_load */
xen/arch/arm/kernel.c +54 -41
169 lines not on this page · raw message
xen/arch/arm/kernel.h +24 -2
@@ -31,8 +31,11 @@ struct kernel_info {union {struct {paddr_t kernel_addr; -paddr_t load_addr;paddr_t len; +#ifdef CONFIG_ARM_64 +paddr_t text_offset;/* 64-bit Image only */ +#endif +paddr_t start;/* 32-bit zImage only */ } zimage;struct {
@@ -44,7 +47,26 @@ struct kernel_info { }; }; -int kernel_prepare (struct kernel_info *info); +/* +* Probe the kernel to detemine its type and select a loader. +* +* Sets in info: +* ->type +* ->load hook, and sets loader specific variables ->{zimage,elf} +*/ +int kernel_probe (struct kernel_info *info); +/* +* Loads the kernel into guest RAM. +* +* Expects to be set in info when called: +* ->mem +* ->fdt +* +* Sets in info: +* ->entry +* ->dtb_paddr +* ->initrd_paddr +*/ void kernel_load (struct kernel_info *info);#endif /* #ifdef __ARCH_ARM_KERNEL_H__ */
Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] xen: arm: probe the kernel to determine the guest type earlier
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/arch/arm/kernel.c +6
-0+static paddr_t kernel_zimage_place (struct kernel_info *info) +{ +paddr_t load_addr; + +#ifdef CONFIG_ARM_64 +if ( info->type ==DOMAIN_64BIT )
xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 134
Quoted 10 lines
xen/arch/arm/kernel.c +10
-0+return info->mem.bank[0 ].start + info->zimage.text_offset; +#endif + +/* +* If start is zero, the zImage is position independent, in this +* case Documentation/arm/Booting recommends loading below 128MiB +* and above 32MiB. Load it as high as possible within these +* constraints, while also avoiding the DTB. +*/ +if (info->zimage.start ==0 )
if ( ... )
[..]
xen/arch/arm/kernel.h struct kernel_info { · line 57
Quoted 9 lines
xen/arch/arm/kernel.h +8
-1-int kernel_prepare (struct kernel_info *info); +/* +* Probe the kernel to detemine its type and select a loader. +* +* Sets in info: +* ->type +* ->load hook, and sets loader specific variables ->{zimage,elf} +*/ +int kernel_probe (struct kernel_info *info);
I would add a newline here.
With theses 2 minor changes, the code looks good to me:
Regards,
Signature · 1 line
Julien Grall
PATCH 3/3 Revert "xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround"
In reply to Ian CampbellThis reverts commit 6c21cb36e263de2db8716b477157a5b6cd531e1e.
The Linux = issue which this works around was fixed in v3.13 via f52bb722547f "ARM: mm: Correct virt_to_phys patching for 64 bit physical addresses".
This is the second attempt to revert this. Now that we have fixed allocate_memory_11 to allocate accessible memory on 32-bit this is safe to do. This is not quite a straight revert since we need to ensure that for 32-bit domain 0 we do not allocate dom0's memory above 4GB where the domain cannot access it without paging (which is disabled at start of day) and LPAE (which the kernel may not support) enabled.
--- xen/arch/arm/domain_build.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
xen/arch/arm/domain_build.c +9 -7
@@ -69,19 +69,21 @@ static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo) {paddr_t start;paddr_t size; -struct page_info *pg =NULL ; +struct page_info *pg;unsigned int order =get_order_from_bytes (dom0_mem);int res;paddr_t spfn; -unsigned int bits; -for ( bits =PAGE_SHIFT +1 ; bits <PADDR_BITS ; bits++ ) +if (is_32bit_domain (d) ) { - pg =alloc_domheap_pages (d, order,MEMF_bits (bits)); -if ( pg !=NULL ) -break ; +printk ("32 bit domain\n" ); + pg =alloc_domheap_pages (d, order,MEMF_bits (32 )); + } +else + { +printk ("64 bit domain\n" ); + pg =alloc_domheap_pages (d, order,0 ); } -if ( !pg )panic ("Failed to allocate contiguous memory for dom0" );
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] Revert "xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround"
Hi Ian,
Quoted 11 lines · Ian Campbell
This reverts commit
6c21cb36e263de2db8716b477157a5b6cd531e1e.The Linux = issue which this works around was fixed in v3.13 via
f52bb722547f"ARM: mm: Correctvirt_to_physpatching for 64 bit physical addresses".This is the second attempt to revert this. Now that we have fixed
allocate_memory_11to allocate accessible memory on 32-bit this is safe to do. This is not quite a straight revert since we need to ensure that for 32-bit domain 0 we do not allocate dom0's memory above 4GB where the domain cannot access it without paging (which is disabled at start of day) and LPAE (which the kernel may not support) enabled.
When multiple banks will be supported, I guess it will be safe to allocate above 32bits (if dom0 has more than 4G) of RAM.
Anyway, it's not the goal of this patch :).
Quoted 25 lines
xen/arch/arm/domain_build.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)xen/arch/arm/domain_build.c +3
-6@@ -69,19 +69,21 @@ static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo) {paddr_t start;paddr_t size; -struct page_info *pg =NULL ; +struct page_info *pg;unsigned int order =get_order_from_bytes (dom0_mem);int res;paddr_t spfn; -unsigned int bits; -for ( bits =PAGE_SHIFT +1 ; bits <PADDR_BITS ; bits++ ) +if (is_32bit_domain (d) ) { - pg =alloc_domheap_pages (d, order,MEMF_bits (bits)); -if ( pg !=NULL ) -break ; +printk ("32 bit domain\n" );
[..]
Quoted 1 line
+
printk("64 bit domain\n");
Can you be more explicit on both of theses messages? Nothing specify we are allocate memory before them.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH 3/3] Revert "xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround"
Quoted 15 lines · Julien Grall
Hi Ian,
Quoted 11 lines · Ian Campbell
This reverts commit
6c21cb36e263de2db8716b477157a5b6cd531e1e.The Linux = issue which this works around was fixed in v3.13 via
f52bb722547f"ARM: mm: Correctvirt_to_physpatching for 64 bit physical addresses".This is the second attempt to revert this. Now that we have fixed
allocate_memory_11to allocate accessible memory on 32-bit this is safe to do. This is not quite a straight revert since we need to ensure that for 32-bit domain 0 we do not allocate dom0's memory above 4GB where the domain cannot access it without paging (which is disabled at start of day) and LPAE (which the kernel may not support) enabled.
Quoted 2 lines
When multiple banks will be supported, I guess it will be safe to allocate above 32bits (if dom0 has more than 4G) of RAM.
Yes. We should aim for as much of dom0's memory as possible to be below 4GB, but if the user asked for more than that we may as well put it above 4GB and hope that the kernel supports LPAE.
Quoted 1 line
Anyway, it's not the goal of this patch :).
Yes.
Quoted 28 lines
Quoted 25 lines
xen/arch/arm/domain_build.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)xen/arch/arm/domain_build.c +3
-6@@ -69,19 +69,21 @@ static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo) {paddr_t start;paddr_t size; -struct page_info *pg =NULL ; +struct page_info *pg;unsigned int order =get_order_from_bytes (dom0_mem);int res;paddr_t spfn; -unsigned int bits; -for ( bits =PAGE_SHIFT +1 ; bits <PADDR_BITS ; bits++ ) +if (is_32bit_domain (d) ) { - pg =alloc_domheap_pages (d, order,MEMF_bits (bits)); -if ( pg !=NULL ) -break ; +printk ("32 bit domain\n" );[..]
Quoted 4 lines
Quoted 1 line
+
printk("64 bit domain\n");Can you be more explicit on both of theses messages? Nothing specify we are allocate memory before them.
ops, those were debugging which I shuld have removed.
Julien Grall
Acked-byRe: [PATCH 3/3] Revert "xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround"
Quoted 5 lines · Ian Campbell
Quoted 2 lines · Julien Grall
Can you be more explicit on both of theses messages? Nothing specify we are allocate memory before them.
ops, those were debugging which I shuld have removed.
With this change:
Signature · 1 line
Julien Grall
Quoted 2 lines · Ian Campbell
This required a bit of yak shaving in the first two patches. Tested on arm32 (w/ >4GB) and arm64.
Applied with Julien's comments + acks.