Skip to contentSkip to conversation

libxc/arm: align to page size the base address of the device tree

PATCH Applied Julien Grall 2 participants 8 messages Nov 19, 2013 – Nov 21, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc/arm: align to page size the base address of the device tree

xc_dom_alloc_segment requires start address to be page align.

---
 tools/libxc/xc_dom_arm.c |    2 ++
 1 file changed, 2 insertions(+)
tools/libxc/xc_dom_arm.c +2 -0
index ffe575b..366061d 100644
@@ -290,6 +290,8 @@ int arch_setup_meminit(struct xc_dom_image *dom)
         else /* otherwise at top of RAM */
             dom->devicetree_seg.vstart = ramend - dtbsize;
 
+        dom->devicetree_seg.vstart &= XC_PAGE_MASK;
+
         dom->devicetree_seg.vend =
             dom->devicetree_seg.vstart + dom->devicetree_size;
         DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

8>------------------

Quoted 1 line

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
 tools/libxc/xc_dom_arm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +1 -1
index ffe575b..a40e04d 100644
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
     {
         const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
         const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);
 
         /* Place at 128MB if there is sufficient RAM */
         if ( ramend >= rambase + 128*1024*1024 + dtbsize )
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 10 lines · Ian Campbell
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

Sounds good to me. I wrote my patch in the other way because I though RAM size can be non-page aligned.

Quoted 21 lines

8>------------------

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
  tools/libxc/xc_dom_arm.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +0 -0
index ffe575b..a40e04d 100644

tools/libxc/xc_dom_arm.c int arch_setup_meminit(struct xc_dom_image *dom) · line 285

Quoted 5 lines
tools/libxc/xc_dom_arm.c +1 -1
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
      {
          const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
          const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);

XC_PAGE_SHIFT only contains the shift. You should use XC_PAGE_SIZE.

Even better, XC_DOM_PAGE_SIZE(dom), so we don't hardcode the size.

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 9 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

Quoted 6 lines
Quoted 3 lines

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

Sounds good to me. I wrote my patch in the other way because I though RAM size can be non-page aligned.

That would be concern except the sizes are defined immediately above as shifts based on page numbers.

Quoted 17 lines
Quoted 17 lines

8>------------------

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
  tools/libxc/xc_dom_arm.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

tools/libxc/xc_dom_arm.c int arch_setup_meminit(struct xc_dom_image *dom) · line 285

Quoted 10 lines
tools/libxc/xc_dom_arm.c +1 -1
index ffe575b..a40e04d 100644
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
      {
          const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
          const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);

XC_PAGE_SHIFT only contains the shift. You should use XC_PAGE_SIZE.

That's not how ROUNDUP is defined in libxc:
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))

so it expects _w (width?) to be the shift.

Ian.

#4 lore raw
Quoted 50 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

Quoted 6 lines
Quoted 3 lines

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

Sounds good to me. I wrote my patch in the other way because I though RAM size can be non-page aligned.

That would be concern except the sizes are defined immediately above as shifts based on page numbers.

Quoted 17 lines
Quoted 17 lines

8>------------------

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
   tools/libxc/xc_dom_arm.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

tools/libxc/xc_dom_arm.c int arch_setup_meminit(struct xc_dom_image *dom) · line 285

Quoted 10 lines
tools/libxc/xc_dom_arm.c +1 -1
index ffe575b..a40e04d 100644
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
       {
           const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
           const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);

XC_PAGE_SHIFT only contains the shift. You should use XC_PAGE_SIZE.

Quoted 4 lines

That's not how ROUNDUP is defined in libxc:
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))

so it expects _w (width?) to be the shift.

Oh right, I though it was defined as in xen. In any case, I think you should use XC_DOM_PAGE_SHIFT(dom).

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 52 lines · Julien Grall
Quoted 50 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

Quoted 6 lines
Quoted 3 lines

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

Sounds good to me. I wrote my patch in the other way because I though RAM size can be non-page aligned.

That would be concern except the sizes are defined immediately above as shifts based on page numbers.

Quoted 29 lines
Quoted 22 lines

8>------------------

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
   tools/libxc/xc_dom_arm.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +0 -0
index ffe575b..a40e04d 100644

tools/libxc/xc_dom_arm.c int arch_setup_meminit(struct xc_dom_image *dom) · line 285

Quoted 5 lines
tools/libxc/xc_dom_arm.c +1 -1
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
       {
           const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
           const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);

XC_PAGE_SHIFT only contains the shift. You should use XC_PAGE_SIZE.

Quoted 7 lines
Quoted 4 lines

That's not how ROUNDUP is defined in libxc:
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))

so it expects _w (width?) to be the shift.

Oh right, I though it was defined as in xen. In any case, I think you should use XC_DOM_PAGE_SHIFT(dom).

Those macros are almost unused in libxc. I suspect they are leftovers from ia64 support, that being the only platform which we've supported which had the possibility of non-4k pages.

Ian.

author Acked-by
#6 lore raw
Quoted 56 lines · Ian Campbell
Quoted 55 lines · Julien Grall
Quoted 53 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 1 line · Julien Grall

xc_dom_alloc_segment requires start address to be page align.

I wonder why I didn't see this? It seems very unlikely that my dtb would be exactly page sized, yet it works... Ah, I have >128M of RAM in my guest so the base would be 128M. Well spotted.

Quoted 6 lines
Quoted 3 lines

I think it would be slightly preferable to round dtbsize up to a page. e.g. the following. What do you think?

Sounds good to me. I wrote my patch in the other way because I though RAM size can be non-page aligned.

That would be concern except the sizes are defined immediately above as shifts based on page numbers.

Quoted 17 lines
Quoted 17 lines

8>------------------

From 079a2815d86567de1cbb541541d08a0b9ac3d18d Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 20 Nov 2013 09:45:32 +0000
Subject: [PATCH] libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page aligned, rounding up the DTB is sufficient.

---
   tools/libxc/xc_dom_arm.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

tools/libxc/xc_dom_arm.c int arch_setup_meminit(struct xc_dom_image *dom) · line 285

Quoted 10 lines
tools/libxc/xc_dom_arm.c +1 -1
index ffe575b..a40e04d 100644
@@ -282,7 +282,7 @@ int arch_setup_meminit(struct xc_dom_image *dom)
       {
           const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
           const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT );
-        const uint64_t dtbsize = ( dom->devicetree_size + 3 ) & ~0x3;
+        const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);

XC_PAGE_SHIFT only contains the shift. You should use XC_PAGE_SIZE.

That's not how ROUNDUP is defined in libxc:
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

so it expects _w (width?) to be the shift.

Oh right, I though it was defined as in xen. In any case, I think you should use XC_DOM_PAGE_SHIFT(dom).

Those macros are almost unused in libxc. I suspect they are leftovers from ia64 support, that being the only platform which we've supported which had the possibility of non-4k pages.

Sorry, I have only checked xc_dom_core.c

For your patch:

Signature · 1 line
Julien Grall