Skip to contentSkip to conversation

xen/arm: mm: Encode existing constraints of the memory layout

PATCH In review Julien Grall 2 participants 3 messages Feb 28, 2022 – Mar 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: mm: Encode existing constraints of the memory layout

From: Julien Grall <[email protected]>

The boot code expects the regions XEN_VIRT_START, FIXMAP_ADDR(0), BOOT_FDT_VIRT_START to use the same 0th (arm64 only) and 1st slot.

Add some BUILD_BUG_ON() to confirm that. This is helpful if one wants to re-order the memory layout.

---
 xen/arch/arm/mm.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/arch/arm/mm.c +16 -0
index 8a17222109c6..40423a70f0ae 100644
@@ -211,6 +211,22 @@ static void __init __maybe_unused build_assertions(void)
 #ifdef CONFIG_DOMAIN_PAGE
     BUILD_BUG_ON(DOMHEAP_VIRT_START & ~FIRST_MASK);
 #endif
+    /*
+     * The boot code expects the regions XEN_VIRT_START, FIXMAP_ADDR(0),
+     * BOOT_FDT_VIRT_START to use the same 0th (arm64 only) and 1st
+     * slot.
+     */
+#define CHECK_SAME_SLOT(level, virt1, virt2) \
+    BUILD_BUG_ON(level##_table_offset(virt1) != level##_table_offset(virt2))
+
+#ifdef CONFIG_ARM_64
+    CHECK_SAME_SLOT(zeroeth, XEN_VIRT_START, FIXMAP_ADDR(0));
+    CHECK_SAME_SLOT(zeroeth, XEN_VIRT_START, BOOT_FDT_VIRT_START);
+#endif
+    CHECK_SAME_SLOT(first, XEN_VIRT_START, FIXMAP_ADDR(0));
+    CHECK_SAME_SLOT(first, XEN_VIRT_START, BOOT_FDT_VIRT_START);
+
+#undef CHECK_SAME_SLOT
 }
 
 void dump_pt_walk(paddr_t ttbr, paddr_t addr,
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Julien,

Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

The boot code expects the regions XEN_VIRT_START, FIXMAP_ADDR(0), BOOT_FDT_VIRT_START to use the same 0th (arm64 only) and 1st slot.

Add some BUILD_BUG_ON() to confirm that. This is helpful if one wants to re-order the memory layout.

Very good idea :-)

Quoted 2 lines

Just a small NIT after if you want to do it on commit...

Quoted 9 lines

---
xen/arch/arm/mm.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
xen/arch/arm/mm.c +0 -0
index 8a17222109c6..40423a70f0ae 100644

xen/arch/arm/mm.c static void __init __maybe_unused build_assertions(void) · line 217

Quoted 7 lines
xen/arch/arm/mm.c +4 -0
@@ -211,6 +211,22 @@ static void __init __maybe_unused build_assertions(void)
 #ifdef CONFIG_DOMAIN_PAGE
    BUILD_BUG_ON(DOMHEAP_VIRT_START & ~FIRST_MASK);
 #endif
+    /*
+     * The boot code expects the regions XEN_VIRT_START, FIXMAP_ADDR(0),
+     * BOOT_FDT_VIRT_START to use the same 0th (arm64 only) and 1st
+     * slot.

NIT: I would just add at the end of the sentence “in the page tables.”

Cheers
Bertrand

Quoted 18 lines
xen/arch/arm/mm.c +12 -0
+     */
+#define CHECK_SAME_SLOT(level, virt1, virt2) \
+    BUILD_BUG_ON(level##_table_offset(virt1) != level##_table_offset(virt2))
+
+#ifdef CONFIG_ARM_64
+    CHECK_SAME_SLOT(zeroeth, XEN_VIRT_START, FIXMAP_ADDR(0));
+    CHECK_SAME_SLOT(zeroeth, XEN_VIRT_START, BOOT_FDT_VIRT_START);
+#endif
+    CHECK_SAME_SLOT(first, XEN_VIRT_START, FIXMAP_ADDR(0));
+    CHECK_SAME_SLOT(first, XEN_VIRT_START, BOOT_FDT_VIRT_START);
+
+#undef CHECK_SAME_SLOT
 }
 
 void dump_pt_walk(paddr_t ttbr, paddr_t addr,
Signature · 1 line
2.32.0
#2 lore raw
Quoted 1 line · Bertrand Marquis

Hi Julien,

Hi Bertrand,

Quoted 11 lines
Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

The boot code expects the regions XEN_VIRT_START, FIXMAP_ADDR(0), BOOT_FDT_VIRT_START to use the same 0th (arm64 only) and 1st slot.

Add some BUILD_BUG_ON() to confirm that. This is helpful if one wants to re-order the memory layout.

Very good idea :-)

I actually hit this issue when trying to re-order the memory layout for testing a patch.

Quoted 7 lines
Quoted 3 lines

Just a small NIT after if you want to do it on commit...

I have update the comment and committed the patch.

Thanks!

Cheers,

Signature · 1 line
Julien Grall