Skip to contentSkip to conversation

Prerequisite patches for Arm64 MPU build

PATCH Superseded Luca Fancellu 3 participants 8 messages Feb 12, 2025 – Feb 13, 2025

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Prerequisite patches for Arm64 MPU build

Hi all,

in order to build Xen for Arm64 with MPU support, there are few changes to support the compilation of Arm code without HAS_PASSTHROUGH and some refactoring around the start_xen for Arm.

Luca Fancellu (2):
xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH xen/arm: Move early mapping operations to new function

 xen/arch/arm/Kconfig                   |  2 +-
 xen/arch/arm/include/asm/grant_table.h |  8 ++++++
 xen/arch/arm/include/asm/mm.h          |  4 +--
 xen/arch/arm/mmu/setup.c               | 35 +++++++++++++++++++++-
 xen/arch/arm/setup.c                   | 30 +------------------
 xen/include/xen/iommu.h                | 40 +++++++++++++++++++++++---
 6 files changed, 82 insertions(+), 37 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH

When Xen is built without HAS_PASSTHROUGH, there are some parts in arm and x86 where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built.

So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support.

---
 xen/arch/arm/include/asm/grant_table.h |  8 ++++++
 xen/include/xen/iommu.h                | 40 +++++++++++++++++++++++---
 2 files changed, 44 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/grant_table.h +8 -0
index d3c518a926b9..e21634b752df 100644
@@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame,
 #define gnttab_status_gfn(d, t, i)                                       \
     page_get_xenheap_gfn(gnttab_status_page(t, i))
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+
 #define gnttab_need_iommu_mapping(d)                    \
     (is_domain_direct_mapped(d) && is_iommu_enabled(d))
 
+#else
+
+#define gnttab_need_iommu_mapping(d) (false)
+
+#endif
+
 #endif /* __ASM_GRANT_TABLE_H__ */
 /*
  * Local variables:
xen/include/xen/iommu.h +36 -4
index b928c67e1995..0ddea755b1c0 100644
@@ -110,6 +110,8 @@ extern int8_t iommu_hwdom_reserved;
 
 extern unsigned int iommu_dev_iotlb_timeout;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+
 int iommu_setup(void);
 int iommu_hardware_setup(void);
 
@@ -122,6 +124,24 @@ int arch_iommu_domain_init(struct domain *d);
 void arch_iommu_check_autotranslated_hwdom(struct domain *d);
 void arch_iommu_hwdom_init(struct domain *d);
 
+#else
+
+static inline int iommu_setup(void)
+{
+    return -ENODEV;
+}
+
+static inline int iommu_domain_init(struct domain *d, unsigned int opts)
+{
+    return 0;
+}
+
+static inline void iommu_hwdom_init(struct domain *d) {}
+
+static inline void iommu_domain_destroy(struct domain *d) {}
+
+#endif /* HAS_PASSTHROUGH */
+
 /*
  * The following flags are passed to map (applicable ones also to unmap)
  * operations, while some are passed back by lookup operations.
@@ -206,7 +226,7 @@ struct msi_msg;
 #define PT_IRQ_TIME_OUT MILLISECS(8)
 #endif /* HAS_PCI */
 
-#ifdef CONFIG_HAS_DEVICE_TREE
+#if defined(CONFIG_HAS_DEVICE_TREE) && defined(CONFIG_HAS_PASSTHROUGH)
 #include <xen/device_tree.h>
 
 int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev);
@@ -238,7 +258,17 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
  */
 int iommu_remove_dt_device(struct dt_device_node *np);
 
-#endif /* HAS_DEVICE_TREE */
+#else
+
+#define iommu_assign_dt_device(d, dev) (-EINVAL)
+#define iommu_add_dt_device(np)        (1)
+
+static inline int iommu_release_dt_devices(struct domain *d)
+{
+    return 0;
+}
+
+#endif /* HAS_DEVICE_TREE && HAS_PASSTHROUGH */
 
 struct page_info;
 
@@ -381,17 +411,19 @@ struct domain_iommu {
 #define iommu_set_feature(d, f)   set_bit(f, dom_iommu(d)->features)
 #define iommu_clear_feature(d, f) clear_bit(f, dom_iommu(d)->features)
 
+/* Does the IOMMU pagetable need to be kept synchronized with the P2M */
+#ifdef CONFIG_HAS_PASSTHROUGH
 /* Are we using the domain P2M table as its IOMMU pagetable? */
 #define iommu_use_hap_pt(d)       (IS_ENABLED(CONFIG_HVM) && \
                                    dom_iommu(d)->hap_pt_share)
 
-/* Does the IOMMU pagetable need to be kept synchronized with the P2M */
-#ifdef CONFIG_HAS_PASSTHROUGH
 #define need_iommu_pt_sync(d)     (dom_iommu(d)->need_sync)
 
 int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
 #else
+#define iommu_use_hap_pt(d)       (false)
+
 #define need_iommu_pt_sync(d)     ({ (void)(d); false; })
 
 static inline int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH

Quoted 21 lines · Luca Fancellu

When Xen is built without HAS_PASSTHROUGH, there are some parts in arm and x86 where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built.

So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support.

---
 xen/arch/arm/include/asm/grant_table.h |  8 ++++++
 xen/include/xen/iommu.h                | 40 +++++++++++++++++++++++---
 2 files changed, 44 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/grant_table.h +0 -0
index d3c518a926b9..e21634b752df 100644
@@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame,
 #define gnttab_status_gfn(d, t, i)                                       \

xen/arch/arm/include/asm/grant_table.h int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, · line 83

Quoted 10 lines
xen/arch/arm/include/asm/grant_table.h +5 -0
     page_get_xenheap_gfn(gnttab_status_page(t, i))
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+
 #define gnttab_need_iommu_mapping(d)                    \
     (is_domain_direct_mapped(d) && is_iommu_enabled(d))
 
+#else
+
+#define gnttab_need_iommu_mapping(d) (false)

This doesn't evaluate d, which can lead to other build problems.

Instead of providing two, you should insert "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing gnttab_need_iommu_mapping().

The same applies to several other hunks too.

~Andrew

#3 lore raw

Re: [PATCH 1/2] xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH

Hi Andrew,

thanks for your review,

Quoted 37 lines · Andrew Cooper
Quoted 21 lines · Luca Fancellu

When Xen is built without HAS_PASSTHROUGH, there are some parts in arm and x86 where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built.

So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support.

---
xen/arch/arm/include/asm/grant_table.h | 8 ++++++
xen/include/xen/iommu.h | 40 +++++++++++++++++++++++---

2 files changed, 44 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/grant_table.h +0 -0
index d3c518a926b9..e21634b752df 100644
@@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame,
 #define gnttab_status_gfn(d, t, i)                                       \

xen/arch/arm/include/asm/grant_table.h int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, · line 83

Quoted 10 lines
xen/arch/arm/include/asm/grant_table.h +5 -0
    page_get_xenheap_gfn(gnttab_status_page(t, i))
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+
 #define gnttab_need_iommu_mapping(d)                    \
    (is_domain_direct_mapped(d) && is_iommu_enabled(d))
 
+#else
+
+#define gnttab_need_iommu_mapping(d) (false)

This doesn't evaluate d, which can lead to other build problems.

Quoted 3 lines

Instead of providing two, you should insert "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing gnttab_need_iommu_mapping().

I’ll do that for this case, I already checked and it works well, just for my knowledge could you explain to me what build problems can happen? Is it something related to the compiler that doesn’t see a usage for d?

Quoted 2 lines

The same applies to several other hunks too.

Are you referring to iommu_use_hap_pt? I have to say that I’ve tried before to insert another IS_ENABLED(…) but it was failing the compilation because without HAS_PASSTHROUGH dom_iommu(d) is (&(d)->iommu), but the iommu field doesn’t exists.

So I’m not sure how to proceed there, do you have any suggestions?

Cheers,
Luca

#4 lore raw

Re: [PATCH 1/2] xen/passthrough: Provide stub functions when !HAS_PASSTHROUGH

Quoted 55 lines · Luca Fancellu

Hi Andrew,

thanks for your review,

Quoted 37 lines · Andrew Cooper
Quoted 21 lines · Luca Fancellu

When Xen is built without HAS_PASSTHROUGH, there are some parts in arm and x86 where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built.

So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support.

---
xen/arch/arm/include/asm/grant_table.h | 8 ++++++
xen/include/xen/iommu.h | 40 +++++++++++++++++++++++---

2 files changed, 44 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/grant_table.h +0 -0
index d3c518a926b9..e21634b752df 100644
@@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame,
 #define gnttab_status_gfn(d, t, i)                                       \

xen/arch/arm/include/asm/grant_table.h int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, · line 83

Quoted 10 lines
xen/arch/arm/include/asm/grant_table.h +5 -0
   page_get_xenheap_gfn(gnttab_status_page(t, i))
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+
 #define gnttab_need_iommu_mapping(d)                    \
   (is_domain_direct_mapped(d) && is_iommu_enabled(d))
 
+#else
+
+#define gnttab_need_iommu_mapping(d) (false)

This doesn't evaluate d, which can lead to other build problems.

Quoted 3 lines

Instead of providing two, you should insert "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing gnttab_need_iommu_mapping().

I’ll do that for this case, I already checked and it works well, just for my knowledge could you explain to me what build problems can happen? Is it something related to the compiler that doesn’t see a usage for d?

Quoted 1 line
Quoted 7 lines
Quoted 1 line

The same applies to several other hunks too.

Are you referring to iommu_use_hap_pt? I have to say that I’ve tried before to insert another IS_ENABLED(…) but it was failing the compilation because without HAS_PASSTHROUGH dom_iommu(d) is (&(d)->iommu), but the iommu field doesn’t exists.

So I’m not sure how to proceed there, do you have any suggestions?

Oh sorry, nevermind this point, I see I can maybe use the same approach as need_iommu_pt_sync(d)

Quoted 3 lines

Cheers,
Luca

#5 lore raw

PATCH 2/2 xen/arm: Move early mapping operations to new function

In reply to Luca Fancellu

Currently start_xen() is performing some early operations using the boot page tables that are configured during early asm boot, before setting up the runtime page tables that might also use the cache coloring feature.

On an MPU system the cache coloring feature is not applicable, also before using any early mapping function, the MPU data structure needs to be initialised.
Another thing that is redundant is mapping the DTB twice, since cache coloring is not applicable.

Because of the above reason, isolate the early mapping code into a function called 'setup_early_mappings' that is defined under the MMU module, an MPU system will need to implement such function to perform the operation needed for early mapping that will be in part different from an MMU system.

Moved the 'HAS_LLC_COLORING' Kconfig symbol into the MMU one, selected only when system is Arm64 and not numa.
Now setup_pagetables() is called only in the mmu/setup.c module, limit its visibility and remove it from mm.h header.

---
 xen/arch/arm/Kconfig          |  2 +-
 xen/arch/arm/include/asm/mm.h |  4 ++--
 xen/arch/arm/mmu/setup.c      | 35 ++++++++++++++++++++++++++++++++++-
 xen/arch/arm/setup.c          | 30 +-----------------------------
 4 files changed, 38 insertions(+), 33 deletions(-)
xen/arch/arm/Kconfig +1 -1
index a26d3e11827c..91f838a32bc6 100644
@@ -8,7 +8,6 @@ config ARM_64
 	depends on !ARM_32
 	select 64BIT
 	select HAS_FAST_MULTIPLY
-	select HAS_LLC_COLORING if !NUMA
 
 config ARM
 	def_bool y
@@ -76,6 +75,7 @@ choice
 
 config MMU
 	bool "MMU"
+	select HAS_LLC_COLORING if !NUMA && ARM64
 	select HAS_PMAP
 	select HAS_VMAP
 	select HAS_PASSTHROUGH
xen/arch/arm/include/asm/mm.h +2 -2
index a0d8e5afe977..d4b6daa85aa0 100644
@@ -203,8 +203,8 @@ extern unsigned long frametable_base_pdx;
 
 #define PDX_GROUP_SHIFT SECOND_SHIFT
 
-/* Boot-time pagetable setup */
-extern void setup_pagetables(void);
+/* Setup early mappings */
+extern void setup_early_mappings(paddr_t fdt_paddr);
 /* Map FDT in boot pagetable */
 extern void *early_fdt_map(paddr_t fdt_paddr);
 /* Remove early mappings */
xen/arch/arm/mmu/setup.c +34 -1
index 30afe9778194..f7862d0bafd3 100644
@@ -354,7 +354,7 @@ static void __init create_llc_coloring_mappings(void)
  * Boot-time pagetable setup.
  * Changes here may need matching changes in head.S
  */
-void __init setup_pagetables(void)
+static void __init setup_pagetables(void)
 {
     uint64_t ttbr;
     lpae_t pte, *p;
@@ -469,6 +469,39 @@ void __init setup_pagetables(void)
     xen_pt_enforce_wnx();
 }
 
+void __init setup_early_mappings(paddr_t fdt_paddr)
+{
+    const char *cmdline;
+    struct bootmodule *xen_bootmodule;
+
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+    if ( !device_tree_flattened )
+        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
+              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
+              "Please check your bootloader.\n",
+              fdt_paddr);
+
+    /* Register Xen's load address as a boot module. */
+    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
+                             virt_to_maddr(_start),
+                             (paddr_t)(uintptr_t)(_end - _start), false);
+    BUG_ON(!xen_bootmodule);
+
+    cmdline = boot_fdt_cmdline(device_tree_flattened);
+    printk("Command line: %s\n", cmdline);
+    cmdline_parse(cmdline);
+
+    llc_coloring_init();
+
+    /*
+     * Page tables must be setup after LLC coloring initialization because
+     * coloring info are required in order to create colored mappings
+     */
+    setup_pagetables();
+    /* Device-tree was mapped in boot page tables, remap it in the new tables */
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+}
+
 void *__init arch_vmap_virt_end(void)
 {
     return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE);
xen/arch/arm/setup.c +1 -29
index c1f2d1b89d43..b2f34ba2a873 100644
@@ -12,7 +12,6 @@
 #include <xen/device_tree.h>
 #include <xen/domain_page.h>
 #include <xen/grant_table.h>
-#include <xen/llc-coloring.h>
 #include <xen/types.h>
 #include <xen/string.h>
 #include <xen/serial.h>
@@ -300,8 +299,6 @@ size_t __read_mostly dcache_line_bytes;
 void asmlinkage __init start_xen(unsigned long fdt_paddr)
 {
     size_t fdt_size;
-    const char *cmdline;
-    struct bootmodule *xen_bootmodule;
     struct domain *d;
     int rc, i;
 
@@ -315,35 +312,10 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
 
     smp_clear_cpu_maps();
 
-    device_tree_flattened = early_fdt_map(fdt_paddr);
-    if ( !device_tree_flattened )
-        panic("Invalid device tree blob at physical address %#lx.\n"
-              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
-              "Please check your bootloader.\n",
-              fdt_paddr);
-
-    /* Register Xen's load address as a boot module. */
-    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
-                             virt_to_maddr(_start),
-                             (paddr_t)(uintptr_t)(_end - _start), false);
-    BUG_ON(!xen_bootmodule);
+    setup_early_mappings(fdt_paddr);
 
     fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);
 
-    cmdline = boot_fdt_cmdline(device_tree_flattened);
-    printk("Command line: %s\n", cmdline);
-    cmdline_parse(cmdline);
-
-    llc_coloring_init();
-
-    /*
-     * Page tables must be setup after LLC coloring initialization because
-     * coloring info are required in order to create colored mappings
-     */
-    setup_pagetables();
-    /* Device-tree was mapped in boot page tables, remap it in the new tables */
-    device_tree_flattened = early_fdt_map(fdt_paddr);
-
     setup_mm();
 
     vm_init();
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 2/2] xen/arm: Move early mapping operations to new function

Hi,

Quoted 89 lines · Luca Fancellu

Currently start_xen() is performing some early operations using the boot page tables that are configured during early asm boot, before setting up the runtime page tables that might also use the cache coloring feature.

On an MPU system the cache coloring feature is not applicable, also before using any early mapping function, the MPU data structure needs to be initialised.
Another thing that is redundant is mapping the DTB twice, since cache coloring is not applicable.

Because of the above reason, isolate the early mapping code into a function called 'setup_early_mappings' that is defined under the MMU module, an MPU system will need to implement such function to perform the operation needed for early mapping that will be in part different from an MMU system.

Moved the 'HAS_LLC_COLORING' Kconfig symbol into the MMU one, selected only when system is Arm64 and not numa.
Now setup_pagetables() is called only in the mmu/setup.c module, limit its visibility and remove it from mm.h header.

---
  xen/arch/arm/Kconfig          |  2 +-
  xen/arch/arm/include/asm/mm.h |  4 ++--
  xen/arch/arm/mmu/setup.c      | 35 ++++++++++++++++++++++++++++++++++-
  xen/arch/arm/setup.c          | 30 +-----------------------------
  4 files changed, 38 insertions(+), 33 deletions(-)
xen/arch/arm/Kconfig +1 -1
index a26d3e11827c..91f838a32bc6 100644
@@ -8,7 +8,6 @@ config ARM_64
  	depends on !ARM_32
  	select 64BIT
  	select HAS_FAST_MULTIPLY
-	select HAS_LLC_COLORING if !NUMA
 
  config ARM
  	def_bool y
@@ -76,6 +75,7 @@ choice
 
  config MMU
  	bool "MMU"
+	select HAS_LLC_COLORING if !NUMA && ARM64
  	select HAS_PMAP
  	select HAS_VMAP
  	select HAS_PASSTHROUGH
xen/arch/arm/include/asm/mm.h +2 -2
index a0d8e5afe977..d4b6daa85aa0 100644
@@ -203,8 +203,8 @@ extern unsigned long frametable_base_pdx;
 
  #define PDX_GROUP_SHIFT SECOND_SHIFT
 
-/* Boot-time pagetable setup */
-extern void setup_pagetables(void);
+/* Setup early mappings */
+extern void setup_early_mappings(paddr_t fdt_paddr);
  /* Map FDT in boot pagetable */
  extern void *early_fdt_map(paddr_t fdt_paddr);
  /* Remove early mappings */
xen/arch/arm/mmu/setup.c +8 -1
index 30afe9778194..f7862d0bafd3 100644
@@ -354,7 +354,7 @@ static void __init create_llc_coloring_mappings(void)
   * Boot-time pagetable setup.
   * Changes here may need matching changes in head.S
   */
-void __init setup_pagetables(void)
+static void __init setup_pagetables(void)
  {
      uint64_t ttbr;
      lpae_t pte, *p;
@@ -469,6 +469,39 @@ void __init setup_pagetables(void)
      xen_pt_enforce_wnx();
  }
 
+void __init setup_early_mappings(paddr_t fdt_paddr)
+{
+    const char *cmdline;
+    struct bootmodule *xen_bootmodule;
+
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+    if ( !device_tree_flattened )

xen/arch/arm/mmu/setup.c void __init setup_pagetables(void) · line 488

Quoted 10 lines
xen/arch/arm/mmu/setup.c +10 -0
+        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
+              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
+              "Please check your bootloader.\n",
+              fdt_paddr);
+
+    /* Register Xen's load address as a boot module. */
+    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
+                             virt_to_maddr(_start),
+                             (paddr_t)(uintptr_t)(_end - _start), false);
+    BUG_ON(!xen_bootmodule);

Don't you need the code above for the MPU?

xen/arch/arm/mmu/setup.c void __init setup_pagetables(void) · line 492

Quoted 4 lines
xen/arch/arm/mmu/setup.c +4 -0
+
+    cmdline = boot_fdt_cmdline(device_tree_flattened);
+    printk("Command line: %s\n", cmdline);
+    cmdline_parse(cmdline);

I find confusing this is part of early mappings. Shouldn't this be part of common code?

Quoted 37 lines
xen/arch/arm/mmu/setup.c +12 -0
+
+    llc_coloring_init();
+
+    /*
+     * Page tables must be setup after LLC coloring initialization because
+     * coloring info are required in order to create colored mappings
+     */
+    setup_pagetables();
+    /* Device-tree was mapped in boot page tables, remap it in the new tables */
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+}
+
  void *__init arch_vmap_virt_end(void)
  {
      return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE);
xen/arch/arm/setup.c +0 -3
index c1f2d1b89d43..b2f34ba2a873 100644
@@ -12,7 +12,6 @@
  #include <xen/device_tree.h>
  #include <xen/domain_page.h>
  #include <xen/grant_table.h>
-#include <xen/llc-coloring.h>
  #include <xen/types.h>
  #include <xen/string.h>
  #include <xen/serial.h>
@@ -300,8 +299,6 @@ size_t __read_mostly dcache_line_bytes;
  void asmlinkage __init start_xen(unsigned long fdt_paddr)
  {
      size_t fdt_size;
-    const char *cmdline;
-    struct bootmodule *xen_bootmodule;
      struct domain *d;
      int rc, i;
 

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 323

Quoted 9 lines
xen/arch/arm/setup.c +0 -6
@@ -315,35 +312,10 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
 
      smp_clear_cpu_maps();
 
-    device_tree_flattened = early_fdt_map(fdt_paddr);
-    if ( !device_tree_flattened )
-        panic("Invalid device tree blob at physical address %#lx.\n"
-              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
-              "Please check your bootloader.\n",
-              fdt_paddr);

I understand why you don't need to call early_fdt_map() twice. But I am a bit surprised why the two calls are moved to the MMU code. I think it would be better if one of the call is kept here and early_fdt_map() is implemented for the MPU.

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 317

Quoted 9 lines
xen/arch/arm/setup.c +1 -6
-
-    /* Register Xen's load address as a boot module. */
-    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
-                             virt_to_maddr(_start),
-                             (paddr_t)(uintptr_t)(_end - _start), false);
-    BUG_ON(!xen_bootmodule);
+    setup_early_mappings(fdt_paddr);
 
      fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);

This function will parse the memory banks. This is required by ...

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 337

Quoted 6 lines
xen/arch/arm/setup.c +0 -5
-    cmdline = boot_fdt_cmdline(device_tree_flattened);
-    printk("Command line: %s\n", cmdline);
-    cmdline_parse(cmdline);
-
-    llc_coloring_init();

... llc_coloring_init(). Yet you move it early. So I think it means the cache coloring code would stop working.

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 321

Quoted 11 lines
xen/arch/arm/setup.c +0 -8
-> -    /*
-     * Page tables must be setup after LLC coloring initialization because
-     * coloring info are required in order to create colored mappings
-     */
-    setup_pagetables();
-    /* Device-tree was mapped in boot page tables, remap it in the new tables */
-    device_tree_flattened = early_fdt_map(fdt_paddr);
-
      setup_mm();
 
      vm_init();

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 2/2] xen/arm: Move early mapping operations to new function

Hi Julien,

thanks for your review.

Quoted 84 lines
Quoted 7 lines

+void __init setup_early_mappings(paddr_t fdt_paddr)

xen/arch/arm/mmu/setup.c +6 -0
+{
+    const char *cmdline;
+    struct bootmodule *xen_bootmodule;
+
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+    if ( !device_tree_flattened )

xen/arch/arm/mmu/setup.c void __init setup_pagetables(void) · line 488

Quoted 10 lines
xen/arch/arm/mmu/setup.c +10 -0
+        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
+              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
+              "Please check your bootloader.\n",
+              fdt_paddr);
+
+    /* Register Xen's load address as a boot module. */
+    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
+                             virt_to_maddr(_start),
+                             (paddr_t)(uintptr_t)(_end - _start), false);
+    BUG_ON(!xen_bootmodule);

Don't you need the code above for the MPU?

xen/arch/arm/mmu/setup.c void __init setup_pagetables(void) · line 492

Quoted 4 lines
xen/arch/arm/mmu/setup.c +4 -0
+
+    cmdline = boot_fdt_cmdline(device_tree_flattened);
+    printk("Command line: %s\n", cmdline);
+    cmdline_parse(cmdline);

I find confusing this is part of early mappings. Shouldn't this be part of common code?

Quoted 38 lines
xen/arch/arm/mmu/setup.c +12 -0
+
+    llc_coloring_init();
+
+    /*
+     * Page tables must be setup after LLC coloring initialization because
+     * coloring info are required in order to create colored mappings
+     */
+    setup_pagetables();
+    /* Device-tree was mapped in boot page tables, remap it in the new tables */
+    device_tree_flattened = early_fdt_map(fdt_paddr);
+}
+
 void *__init arch_vmap_virt_end(void)
 {
     return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE);
xen/arch/arm/setup.c +0 -3
index c1f2d1b89d43..b2f34ba2a873 100644
@@ -12,7 +12,6 @@
 #include <xen/device_tree.h>
 #include <xen/domain_page.h>
 #include <xen/grant_table.h>
-#include <xen/llc-coloring.h>
 #include <xen/types.h>
 #include <xen/string.h>
 #include <xen/serial.h>
@@ -300,8 +299,6 @@ size_t __read_mostly dcache_line_bytes;
 void asmlinkage __init start_xen(unsigned long fdt_paddr)
 {
     size_t fdt_size;
-    const char *cmdline;
-    struct bootmodule *xen_bootmodule;
     struct domain *d;
     int rc, i;
 @@ -315,35 +312,10 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
       smp_clear_cpu_maps();

- device_tree_flattened = early_fdt_map(fdt_paddr);

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 323

Quoted 5 lines
xen/arch/arm/setup.c +0 -5
-    if ( !device_tree_flattened )
-        panic("Invalid device tree blob at physical address %#lx.\n"
-              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
-              "Please check your bootloader.\n",
-              fdt_paddr);

I understand why you don't need to call early_fdt_map() twice. But I am a bit surprised why the two calls are moved to the MMU code. I think it would be better if one of the call is kept here and early_fdt_map() is implemented for the MPU.

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 317

Quoted 8 lines
xen/arch/arm/setup.c +1 -6
-
-    /* Register Xen's load address as a boot module. */
-    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
-                             virt_to_maddr(_start),
-                             (paddr_t)(uintptr_t)(_end - _start), false);
-    BUG_ON(!xen_bootmodule);
+    setup_early_mappings(fdt_paddr);
       fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);

This function will parse the memory banks. This is required by ...

Quoted 7 lines

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 337

Quoted 5 lines

- cmdline = boot_fdt_cmdline(device_tree_flattened);

xen/arch/arm/setup.c +0 -4
-    printk("Command line: %s\n", cmdline);
-    cmdline_parse(cmdline);
-
-    llc_coloring_init();

... llc_coloring_init(). Yet you move it early. So I think it means the cache coloring code would stop working.

woops, I didn’t see boot_fdt_info was parsing the memory banks, sorry I overlooked that, I saw no dependencies on variables and given that I don’t have a working cache coloring setup I didn’t notice. I’ll be more careful next time.

Quoted 12 lines

xen/arch/arm/setup.c void asmlinkage __init start_xen(unsigned long fdt_paddr) · line 321

Quoted 12 lines

-> - /*

xen/arch/arm/setup.c +0 -7
-     * Page tables must be setup after LLC coloring initialization because
-     * coloring info are required in order to create colored mappings
-     */
-    setup_pagetables();
-    /* Device-tree was mapped in boot page tables, remap it in the new tables */
-    device_tree_flattened = early_fdt_map(fdt_paddr);
-
     setup_mm();
       vm_init();

So yes I would have used some duplication for the MPU part doing this:

void __init setup_early_mappings(paddr_t fdt_paddr)

{
    const char *cmdline;
    struct bootmodule *xen_bootmodule;

    <setup_mpu>

    device_tree_flattened = early_fdt_map(fdt_paddr);
    if ( !device_tree_flattened )
        panic("Invalid device tree blob at physical address %#"PRIpaddr".\n"
              "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n"
              "Please check your bootloader.\n",
              fdt_paddr);

    /* Register Xen's load address as a boot module. */
    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
                             virt_to_maddr(_start),
                             (paddr_t)(uintptr_t)(_end - _start), false);
    BUG_ON(!xen_bootmodule);

    cmdline = boot_fdt_cmdline(device_tree_flattened);
    printk("Command line: %s\n", cmdline);
    cmdline_parse(cmdline);
}

I discussed with Michal before and he suggested to setup the MPU from the early ASM code, it sounded a good idea to do that in the mpu enable_boot_cpu_mm, but then I realised my MPU region table sits in .bss.

So I had some choices:
1) place the MPU region table in .data? I would still like it to be zeroed but I could do that in a “setup_mpu()” function. There is still the DT additional early_fdt_map call, but maybe I could move that into setup_pagetables() ? Or I could have a return value from llc_coloring_init() and make the second early_fdt_map call depending on if cache coloring is setup or not?
I would then provide an empty stub for setup_pagetables() on MPU systems.

2) Provide a common function like what I’ve tried to do in this patch, so that different memory management subsystem could provide their implementation. Key differences as we saw are:
a) MMU don’t call anything before early_fdt_map because it has already some data structure in place at this stage
b) MMU needs to call llc_coloring_init, setup_pagetables and an additional early_fdt_map.
Would something like pre_fdt_map(), post_fdt_map() work? pre_fdt_map() would be empty for MMU.

Please let me know your view on this, maybe you have some better design.

Cheers,
Luca