Skip to contentSkip to conversation

xen: arm: fixes for initrd and dtb placement

PATCH In review Ian Campbell 3 participants 19 messages Apr 9, 2014 – May 22, 2014

lore
Share & tools
lore
#0 lore raw

cover xen: arm: fixes for initrd and dtb placement

The first patch here should address the regression introduced by 314c9815e2f5 "tools: implement initial ramdisk support for ARM." and should be backported at the same time.

The second two patches make the dom0 placement algorithm the same as the libxc one.

Ian.

#1 lore raw

PATCH 1/3 tools: arm: improve placement of initial modules.

314c9815e2f5 "tools: implement initial ramdisk support for ARM." broke starting guests with <= 128 MB ram by placing the boot modules (dtb and initrd) immediately after the kernel in this case, running the risk of them being overwritten. Instead place the modules at the end of RAM, as the hypervisor does for dom0.

The hypervisor also falls back to placing things before the kernel as a last resort before failing, so add that here too.

Tested with the Debian installer initrd and guests of 96MB, 128MB, 256MB and 1GB. All work, also tested with 64MB but the installer doesn't run with so little RAM (but our placement of the initrd is correct).

---
This should be added to 4.4.1 along with 314c9815e2f5.

---
 tools/libxc/xc_dom_arm.c |   29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
tools/libxc/xc_dom_arm.c +21 -8
index f051515..60ac51a 100644
@@ -253,8 +253,11 @@ int arch_setup_meminit(struct xc_dom_image *dom)
 
     /* Convenient */
     const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-    const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
+    const uint64_t ramsize = dom->total_pages << XC_PAGE_SHIFT;
+    const uint64_t ramend = rambase + ramsize;
+    const uint64_t kernbase = dom->kernel_seg.vstart;
     const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
+    const uint64_t kernsize = kernend - kernbase;
     const uint64_t dtb_size = dom->devicetree_blob ?
         ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
     const uint64_t ramdisk_size = dom->ramdisk_blob ?
@@ -262,6 +265,13 @@ int arch_setup_meminit(struct xc_dom_image *dom)
     const uint64_t modsize = dtb_size + ramdisk_size;
     const uint64_t ram128mb = rambase + (128<<20);
 
+    if ( modsize + kernsize > ramsize )
+    {
+        DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
+                  __FUNCTION__);
+        return -1;
+    }
+
     rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
     if ( rc )
         return rc;
@@ -290,17 +300,20 @@ int arch_setup_meminit(struct xc_dom_image *dom)
             0, 0, &dom->p2m_host[i]);
     }
 
-
     /*
-     * Place boot modules at 128MB into RAM if there is enough RAM and
-     * the kernel does not overlap. Otherwise place them immediately
-     * after the kernel. If there is no space after the kernel then
-     * there is insufficient RAM and we fail.
+     * We try to place dtb+initrd at 128MB or if we have less RAM
+     * as high as possible. If there is no space then fallback to
+     * just before the kernel.
+     *
+     * If changing this then consider
+     * xen/arch/arm/kernel.c:place_modules as well.
      */
     if ( ramend >= ram128mb + modsize && kernend < ram128mb )
         modbase = ram128mb;
-    else if ( ramend >= kernend + modsize )
-        modbase = kernend;
+    else if ( ramend - modsize > kernend )
+        modbase = ramend - modsize;
+    else if (kernbase - rambase > modsize )
+        modbase = kernbase - modsize;
     else
         return -1;
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] tools: arm: improve placement of initial modules.

Hi Ian,

Quoted 7 lines · Ian Campbell

314c9815e2f5 "tools: implement initial ramdisk support for ARM." broke starting guests with <= 128 MB ram by placing the boot modules (dtb and initrd) immediately after the kernel in this case, running the risk of them being overwritten. Instead place the modules at the end of RAM, as the hypervisor does for dom0.

The hypervisor also falls back to placing things before the kernel as a last

Did you mean "falls backs on placing"?

Other than that the patch looks good to me:

Regards,

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 1/3] tools: arm: improve placement of initial modules.

Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 6 lines · Ian Campbell

314c9815e2f5 "tools: implement initial ramdisk support for ARM." broke starting guests with <= 128 MB ram by placing the boot modules (dtb and initrd) immediately after the kernel in this case, running the risk of them being overwritten. Instead place the modules at the end of RAM, as the hypervisor does for dom0.

Quoted 3 lines
Quoted 1 line

The hypervisor also falls back to placing things before the kernel as a last

Did you mean "falls backs on placing"?

"Falls back to X" is also correct, "on" might be but reads strangely to me in this particular context.

Quoted 3 lines

Other than that the patch looks good to me:

Thanks.

Quoted 2 lines

Regards,

author Applied
#4 lore raw

Re: [PATCH 1/3] tools: arm: improve placement of initial modules.

In reply to Julien Grall
Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 6 lines · Ian Campbell

314c9815e2f5 "tools: implement initial ramdisk support for ARM." broke starting guests with <= 128 MB ram by placing the boot modules (dtb and initrd) immediately after the kernel in this case, running the risk of them being overwritten. Instead place the modules at the end of RAM, as the hypervisor does for dom0.

Quoted 7 lines
Quoted 1 line

The hypervisor also falls back to placing things before the kernel as a last

Did you mean "falls backs on placing"?

Other than that the patch looks good to me:

Applied. Ian, please add 6f4ff742a5caa411397fc38233f818e64a0c541c to be backported along with 314c9815e2f5dc8a9fec11e0cf9b49b16ed0e96b.

Ian.

#5 lore raw

Re: [PATCH 1/3] tools: arm: improve placement of initial modules.

Ian Campbell writes ("Re: [PATCH 1/3] tools: arm: improve placement of initial modules."):

Quoted 2 lines

Applied. Ian, please add 6f4ff742a5caa411397fc38233f818e64a0c541c to be backported along with 314c9815e2f5dc8a9fec11e0cf9b49b16ed0e96b.

Queued.

Thanks,
Ian.

#6 lore raw

Re: [PATCH 1/3] tools: arm: improve placement of initial modules.

Ian Jackson writes ("Re: [PATCH 1/3] tools: arm: improve placement of initial modules."):

Quoted 5 lines

Ian Campbell writes ("Re: [PATCH 1/3] tools: arm: improve placement of initial modules."):

Quoted 2 lines

Applied. Ian, please add 6f4ff742a5caa411397fc38233f818e64a0c541c to be backported along with 314c9815e2f5dc8a9fec11e0cf9b49b16ed0e96b.

Queued.

Backported to 4.4.

Ian.

#7 lore raw

PATCH 2/3 xen: arm: use same variables as userspace in dom0 builder place_modules()

In reply to Ian Campbell

The placement algorithm should be effectively the same and using different variable names makes my head hurt when I try to compare.

---
 xen/arch/arm/kernel.c |   34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/arch/arm/kernel.c +17 -17
index ae86772..bc625a4 100644
@@ -65,25 +65,25 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
 }
 
 static void place_modules(struct kernel_info *info,
-                         paddr_t kernel_start,
-                         paddr_t kernel_end)
+                          paddr_t kernbase, paddr_t kernend)
 {
     /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */
     const paddr_t initrd_len =
         ROUNDUP(early_info.modules.module[MOD_INITRD].size, MB(2));
     const paddr_t dtb_len = ROUNDUP(fdt_totalsize(info->fdt), MB(2));
-    const paddr_t total = initrd_len + dtb_len;
+    const paddr_t modsize = initrd_len + dtb_len;
 
     /* Convenient */
-    const paddr_t mem_start = info->mem.bank[0].start;
-    const paddr_t mem_size = info->mem.bank[0].size;
-    const paddr_t mem_end = mem_start + mem_size;
-    const paddr_t kernel_size = kernel_end - kernel_start;
+    const paddr_t rambase = info->mem.bank[0].start;
+    const paddr_t ramsize = info->mem.bank[0].size;
+    const paddr_t ramend = rambase + ramsize;
+    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t ram128mb = rambase + MB(128);
 
-    paddr_t addr;
+    paddr_t modbase;
 
-    if ( total + kernel_size > mem_size )
-        panic("Not enough memory in the first bank for the dtb+initrd");
+    if ( modsize + kernsize > ramsize )
+        panic("Not enough memory in the first bank for the kernel+dtb+initrd");
 
     /*
      * DTB must be loaded such that it does not conflict with the
@@ -100,19 +100,19 @@ static void place_modules(struct kernel_info *info,
      * just after the kernel, if there is room, otherwise just before.
      */
 
-    if ( kernel_end < MIN(mem_start + MB(128), mem_end - total) )
-        addr = MIN(mem_start + MB(128), mem_end - total);
-    else if ( mem_end - ROUNDUP(kernel_end, MB(2)) >= total )
-        addr = ROUNDUP(kernel_end, MB(2));
-    else if ( kernel_start - mem_start >= total )
-        addr = kernel_start - total;
+    if ( kernend < MIN(ram128mb, ramend - modsize) )
+        modbase = MIN(ram128mb, ramend - modsize);
+    else if ( ramend - ROUNDUP(kernend, MB(2)) >= modsize )
+        modbase = ROUNDUP(kernend, MB(2));
+    else if ( kernbase - rambase >= modsize )
+        modbase = kernbase - modsize;
     else
     {
         panic("Unable to find suitable location for dtb+initrd");
         return;
     }
 
-    info->dtb_paddr = addr;
+    info->dtb_paddr = modbase;
     info->initrd_paddr = info->dtb_paddr + dtb_len;
 }
 
Signature · 1 line
1.7.10.4
#8 lore raw

Re: [PATCH 2/3] xen: arm: use same variables as userspace in dom0 builder place_modules()

Quoted 12 lines · Ian Campbell

static void place_modules(struct kernel_info *info,

xen/arch/arm/kernel.c +2 -3
-                         paddr_t kernel_start,
-                         paddr_t kernel_end)
+                          paddr_t kernbase, paddr_t kernend)
 {
     /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */
     const paddr_t initrd_len =
         ROUNDUP(early_info.modules.module[MOD_INITRD].size, MB(2));
     const paddr_t dtb_len = ROUNDUP(fdt_totalsize(info->fdt), MB(2));
-    const paddr_t total = initrd_len + dtb_len;
+    const paddr_t modsize = initrd_len + dtb_len;
 

xen/arch/arm/kernel.c void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) · line 81

Quoted 10 lines
xen/arch/arm/kernel.c +5 -4
     /* Convenient */
-    const paddr_t mem_start = info->mem.bank[0].start;
-    const paddr_t mem_size = info->mem.bank[0].size;
-    const paddr_t mem_end = mem_start + mem_size;
-    const paddr_t kernel_size = kernel_end - kernel_start;
+    const paddr_t rambase = info->mem.bank[0].start;
+    const paddr_t ramsize = info->mem.bank[0].size;
+    const paddr_t ramend = rambase + ramsize;
+    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t ram128mb = rambase + MB(128);

Shall we use ram0base, ram0size, ram0end to show that we are using that the first bank?

Regards,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH 2/3] xen: arm: use same variables as userspace in dom0 builder place_modules()

Quoted 24 lines · Julien Grall
Quoted 12 lines · Ian Campbell

static void place_modules(struct kernel_info *info,

xen/arch/arm/kernel.c +2 -3
-                         paddr_t kernel_start,
-                         paddr_t kernel_end)
+                          paddr_t kernbase, paddr_t kernend)
 {
     /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */
     const paddr_t initrd_len =
         ROUNDUP(early_info.modules.module[MOD_INITRD].size, MB(2));
     const paddr_t dtb_len = ROUNDUP(fdt_totalsize(info->fdt), MB(2));
-    const paddr_t total = initrd_len + dtb_len;
+    const paddr_t modsize = initrd_len + dtb_len;
 

xen/arch/arm/kernel.c void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) · line 81

Quoted 10 lines
xen/arch/arm/kernel.c +5 -4
     /* Convenient */
-    const paddr_t mem_start = info->mem.bank[0].start;
-    const paddr_t mem_size = info->mem.bank[0].size;
-    const paddr_t mem_end = mem_start + mem_size;
-    const paddr_t kernel_size = kernel_end - kernel_start;
+    const paddr_t rambase = info->mem.bank[0].start;
+    const paddr_t ramsize = info->mem.bank[0].size;
+    const paddr_t ramend = rambase + ramsize;
+    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t ram128mb = rambase + MB(128);
Quoted 2 lines

Shall we use ram0base, ram0size, ram0end to show that we are using that the first bank?

I was planning to do that in my 1TB RAM series, but this is different code isn't it. Oops.

I'll change if there is some other reason to repost, but I don't think it is worth reposting just for that.

Ian.

Acked-by
#10 lore raw

Re: [PATCH 2/3] xen: arm: use same variables as userspace in dom0 builder place_modules()

Quoted 25 lines · Ian Campbell
Quoted 24 lines · Julien Grall
Quoted 22 lines · Ian Campbell

static void place_modules(struct kernel_info *info,

xen/arch/arm/kernel.c +7 -7
-                         paddr_t kernel_start,
-                         paddr_t kernel_end)
+                          paddr_t kernbase, paddr_t kernend)
 {
     /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */
     const paddr_t initrd_len =
         ROUNDUP(early_info.modules.module[MOD_INITRD].size, MB(2));
     const paddr_t dtb_len = ROUNDUP(fdt_totalsize(info->fdt), MB(2));
-    const paddr_t total = initrd_len + dtb_len;
+    const paddr_t modsize = initrd_len + dtb_len;
 
     /* Convenient */
-    const paddr_t mem_start = info->mem.bank[0].start;
-    const paddr_t mem_size = info->mem.bank[0].size;
-    const paddr_t mem_end = mem_start + mem_size;
-    const paddr_t kernel_size = kernel_end - kernel_start;
+    const paddr_t rambase = info->mem.bank[0].start;
+    const paddr_t ramsize = info->mem.bank[0].size;
+    const paddr_t ramend = rambase + ramsize;
+    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t ram128mb = rambase + MB(128);
Quoted 8 lines
Quoted 2 lines

Shall we use ram0base, ram0size, ram0end to show that we are using that the first bank?

I was planning to do that in my 1TB RAM series, but this is different code isn't it. Oops.

I'll change if there is some other reason to repost, but I don't think it is worth reposting just for that.

Ok. With or without this change:

Signature · 1 line
Julien Grall
#11 lore raw

PATCH 3/3 xen: arm: rework dom0 initrd and dtb placement

In reply to Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as two cases, rather than combining with MIN. The effect is the same but the code is clearer.

Secondly the attempt to place the mopules right after the kernel is removed, since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
xen/arch/arm/kernel.c +12 -10
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;
     const paddr_t ram128mb = rambase + MB(128);
 
     paddr_t modbase;
@@ -95,16 +95,18 @@ static void place_modules(struct kernel_info *info,
      * If the bootloader provides an initrd, it will be loaded just
      * after the DTB.
      *
-     * We try to place dtb+initrd at 128MB, (or, if we have less RAM,
-     * as high as possible). If there is no space then fallback to
-     * just after the kernel, if there is room, otherwise just before.
+     * We try to place dtb+initrd at 128MB or if we have less RAM
+     * as high as possible. If there is no space then fallback to
+     * just before the kernel.
+     *
+     * If changing this then consider
+     * tools/libxc/xc_dom_arm.c:arch_setup_meminit as well.
      */
-
-    if ( kernend < MIN(ram128mb, ramend - modsize) )
-        modbase = MIN(ram128mb, ramend - modsize);
-    else if ( ramend - ROUNDUP(kernend, MB(2)) >= modsize )
-        modbase = ROUNDUP(kernend, MB(2));
-    else if ( kernbase - rambase >= modsize )
+    if ( ramend >= ram128mb + modsize && kernend < ram128mb )
+        modbase = ram128mb;
+    else if ( ramend - modsize > ROUNDUP(kernend, MB(2)) )
+        modbase = ramend - modsize;
+    else if ( kernbase - rambase > modsize )
         modbase = kernbase - modsize;
     else
     {
Signature · 1 line
1.7.10.4
#12 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/

Quoted 4 lines

two cases, rather than combining with MIN. The effect is the same but the code is clearer.

Secondly the attempt to place the mopules right after the kernel is removed,

s/mopules/modules/

Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Quoted 13 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
xen/arch/arm/kernel.c +0 -0
index bc625a4..1102392 100644

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 5 lines
xen/arch/arm/kernel.c +1 -1
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

Signature · 1 line
Julien Grall
#13 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/
s/mopules/modules/

Gah, fingers not working right today it seems.

Quoted 6 lines
Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Me too.

Quoted 7 lines
Quoted 7 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Quoted 13 lines

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 10 lines
xen/arch/arm/kernel.c +1 -1
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

It's passed as a paramter, and it's not possible to round it before using it here (code before declarations), so I'd have to make kernsize non-const and initialise it after the rounding. I didn't think it was worth it.

Ian.

#14 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 43 lines · Ian Campbell
Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/
s/mopules/modules/

Gah, fingers not working right today it seems.

Quoted 6 lines
Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Me too.

Quoted 7 lines
Quoted 7 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Quoted 13 lines

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 10 lines
xen/arch/arm/kernel.c +1 -1
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

Quoted 4 lines

It's passed as a paramter, and it's not possible to round it before using it here (code before declarations), so I'd have to make kernsize non-const and initialise it after the rounding. I didn't think it was worth it.

In this case I'm lost... You are mixing kernend and ROUNDUP(kernend, MB(2)).

As I understand, we don't need to round up on the second if expression (see code below).

+ if ( ramend >= ram128mb + modsize && kernend < ram128mb )
+ modbase = ram128mb;
+ else if ( ramend - modsize > ROUNDUP(kernend, MB(2)) )
+ modbase = ramend - modsize;
+ else if ( kernbase - rambase > modsize )

Regards,

Signature · 1 line
Julien Grall
#15 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 49 lines · Julien Grall
Quoted 43 lines · Ian Campbell
Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/
s/mopules/modules/

Gah, fingers not working right today it seems.

Quoted 6 lines
Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Me too.

Quoted 7 lines
Quoted 7 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Quoted 13 lines

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 10 lines
xen/arch/arm/kernel.c +1 -1
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

Quoted 4 lines

It's passed as a paramter, and it's not possible to round it before using it here (code before declarations), so I'd have to make kernsize non-const and initialise it after the rounding. I didn't think it was worth it.

Quoted 4 lines

In this case I'm lost... You are mixing kernend and ROUNDUP(kernend, MB(2)).

As I understand, we don't need to round up on the second if expression (see code below).

It ensures that the modules don't start until at least the 2M boundary after the kernel's end. The userspace side does the same.

Whether that's really worthwhile I don't know.

Quoted 9 lines
xen/arch/arm/kernel.c +5 -0
+    if ( ramend >= ram128mb + modsize && kernend < ram128mb )
+        modbase = ram128mb;
+    else if ( ramend - modsize > ROUNDUP(kernend, MB(2)) )
+        modbase = ramend - modsize;
+    else if ( kernbase - rambase > modsize )

Regards,

#16 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 50 lines · Ian Campbell
Quoted 49 lines · Julien Grall
Quoted 47 lines · Ian Campbell
Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/
s/mopules/modules/

Gah, fingers not working right today it seems.

Quoted 6 lines
Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Me too.

Quoted 7 lines
Quoted 7 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Quoted 13 lines

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 10 lines
xen/arch/arm/kernel.c +1 -1
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

It's passed as a paramter, and it's not possible to round it before using it here (code before declarations), so I'd have to make kernsize non-const and initialise it after the rounding. I didn't think it was worth it.

Quoted 7 lines
Quoted 4 lines

In this case I'm lost... You are mixing kernend and ROUNDUP(kernend, MB(2)).

As I understand, we don't need to round up on the second if expression (see code below).

It ensures that the modules don't start until at least the 2M boundary after the kernel's end. The userspace side does the same.

The userspace is consistent with the usage of kernend. It's not the case here. There is no reason to mix the usage of kernend with and without ROUNDUP.

In another point, I don't think 2MB-aligned is enough to ensure the kernel won't decompress on the device tree.

Signature · 1 line
Julien Grall
#17 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 56 lines · Julien Grall
Quoted 55 lines · Ian Campbell
Quoted 53 lines · Julien Grall
Quoted 43 lines · Ian Campbell
Quoted 9 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

This now uses the same decision tree as libxc (which is much easier to test).

The main change is to explictly handle the placement at 128MB or end of RAM as

s/explictly/explicitly/
s/mopules/modules/

Gah, fingers not working right today it seems.

Quoted 6 lines
Quoted 4 lines

since it is redundant with the case where placing them at the end of RAM ends up abutting the kernel.

Also round the kernel size up to a 2MB boundary.

A bit surprised that it was not done before :).

Me too.

Quoted 7 lines
Quoted 7 lines

---
I'm sure to regret playing with this yet again...

---
 xen/arch/arm/kernel.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Quoted 13 lines

xen/arch/arm/kernel.c static void place_modules(struct kernel_info *info, · line 80

Quoted 10 lines
xen/arch/arm/kernel.c +1 -1
index bc625a4..1102392 100644
@@ -77,7 +77,7 @@ static void place_modules(struct kernel_info *info,
     const paddr_t rambase = info->mem.bank[0].start;
     const paddr_t ramsize = info->mem.bank[0].size;
     const paddr_t ramend = rambase + ramsize;
-    const paddr_t kernsize = kernend - kernbase;
+    const paddr_t kernsize = ROUNDUP(kernend, MB(2)) - kernbase;

You are using ROUNDUP(kernend, MB(2)) in few places, why didn't you roundup directly kernend?

Quoted 4 lines

It's passed as a paramter, and it's not possible to round it before using it here (code before declarations), so I'd have to make kernsize non-const and initialise it after the rounding. I didn't think it was worth it.

In this case I'm lost... You are mixing kernend and ROUNDUP(kernend, MB(2)).

As I understand, we don't need to round up on the second if expression (see code below).

Quoted 6 lines
Quoted 2 lines

It ensures that the modules don't start until at least the 2M boundary after the kernel's end. The userspace side does the same.

The userspace is consistent with the usage of kernend. It's not the case here. There is no reason to mix the usage of kernend with and without ROUNDUP.

Ah, you mean the lack of rounding in the first if:

        if ( ramend >= ram128mb + modsize && kernend < ram128mb )

?

Since ram128mb is 2MB aligned it doesn't really matter that kernend isn't.

Quoted 2 lines

In another point, I don't think 2MB-aligned is enough to ensure the kernel won't decompress on the device tree.

Yes, like I say I don't know if it actually worthwhile.

Ian.

Acked-by
#18 lore raw

Re: [PATCH 3/3] xen: arm: rework dom0 initrd and dtb placement

Quoted 7 lines · Ian Campbell

Ah, you mean the lack of rounding in the first if:

        if ( ramend >= ram128mb + modsize && kernend < ram128mb )

?

Since ram128mb is 2MB aligned it doesn't really matter that kernend isn't.

Oh right, I was lost with all the arithmetic.

Quoted 4 lines
Quoted 2 lines

In another point, I don't think 2MB-aligned is enough to ensure the kernel won't decompress on the device tree.

Yes, like I say I don't know if it actually worthwhile.

Ok. Let's stick with this solution and see if someone platform will complain:

Signature · 1 line
Julien Grall