Skip to contentSkip to conversation

xen/arm: Don't call process_shm_chosen() during ACPI boot

PATCH In review Michal Orzel 2 participants 4 messages Apr 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Don't call process_shm_chosen() during ACPI boot

Static shared memory requires device-tree boot. At the moment, booting with ACPI enabled and CONFIG_STATIC_SHM=y results in a data abort when dereferencing node in process_shm() because dt_host is always NULL.

Fixes 09c0a8976acf ("xen/arm: enable statically shared memory on Dom0")
---
 xen/arch/arm/domain_build.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
xen/arch/arm/domain_build.c +6 -3
index 2b5b4331834f..85f423214a44 100644
@@ -2325,9 +2325,12 @@ int __init construct_hwdom(struct kernel_info *kinfo)
     else
         allocate_memory(d, kinfo);
 
-    rc = process_shm_chosen(d, kinfo);
-    if ( rc < 0 )
-        return rc;
+    if ( acpi_disabled )
+    {
+        rc = process_shm_chosen(d, kinfo);
+        if ( rc < 0 )
+            return rc;
+    }
 
     /* Map extra GIC MMIO, irqs and other hw stuffs to dom0. */
     rc = gic_map_hwdom_extra_mappings(d);
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 xen/arm: Drop process_shm_chosen()

There's no benefit in having process_shm_chosen() next to process_shm(). The former is just a helper to pass "/chosen" node to the latter for hwdom case. Drop process_shm_chosen() and instead use process_shm() passing NULL as node parameter, which will result in searching for and using /chosen to find shm node (the DT full path search is done in process_shm() to avoid expensive lookup if !CONFIG_STATIC_SHM). This will simplify future handling of hw/control domain separation.

---
Changes in v2:
- rebase on ACPI fix
- add BUG_ON for !/chosen

---
 xen/arch/arm/domain_build.c             |  2 +-
 xen/arch/arm/include/asm/static-shmem.h | 14 --------------
 xen/arch/arm/static-shmem.c             |  7 +++++++
 3 files changed, 8 insertions(+), 15 deletions(-)
xen/arch/arm/domain_build.c +1 -1
index 85f423214a44..634333cddef3 100644
@@ -2327,7 +2327,7 @@ int __init construct_hwdom(struct kernel_info *kinfo)
 
     if ( acpi_disabled )
     {
-        rc = process_shm_chosen(d, kinfo);
+        rc = process_shm(d, kinfo, NULL);
         if ( rc < 0 )
             return rc;
     }
xen/arch/arm/include/asm/static-shmem.h +0 -14
index fd0867c4f26b..94eaa9d500f9 100644
@@ -18,14 +18,6 @@ int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells,
 int process_shm(struct domain *d, struct kernel_info *kinfo,
                 const struct dt_device_node *node);
 
-static inline int process_shm_chosen(struct domain *d,
-                                     struct kernel_info *kinfo)
-{
-    const struct dt_device_node *node = dt_find_node_by_path("/chosen");
-
-    return process_shm(d, kinfo, node);
-}
-
 int process_shm_node(const void *fdt, int node, uint32_t address_cells,
                      uint32_t size_cells);
 
@@ -74,12 +66,6 @@ static inline int process_shm(struct domain *d, struct kernel_info *kinfo,
     return 0;
 }
 
-static inline int process_shm_chosen(struct domain *d,
-                                     struct kernel_info *kinfo)
-{
-    return 0;
-}
-
 static inline void init_sharedmem_pages(void) {};
 
 static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo,
xen/arch/arm/static-shmem.c +7 -0
index c74fa13d4847..e8d4ca3ba3ff 100644
@@ -297,6 +297,13 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,
 {
     struct dt_device_node *shm_node;
 
+    /* Hwdom case - shm node under /chosen */
+    if ( !node )
+    {
+        node = dt_find_node_by_path("/chosen");
+        BUG_ON(!node);
+    }
+
     dt_for_each_child_node(node, shm_node)
     {
         const struct membank *boot_shm_bank;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2] xen/arm: Drop process_shm_chosen()

Hi Michal,

Quoted 11 lines · Michal Orzel

There's no benefit in having process_shm_chosen() next to process_shm(). The former is just a helper to pass "/chosen" node to the latter for hwdom case. Drop process_shm_chosen() and instead use process_shm() passing NULL as node parameter, which will result in searching for and using /chosen to find shm node (the DT full path search is done in process_shm() to avoid expensive lookup if !CONFIG_STATIC_SHM). This will simplify future handling of hw/control domain separation.

Thanks for the BUG_ON :-)

Cheers
Bertrand

Quoted 76 lines

---
Changes in v2:
- rebase on ACPI fix
- add BUG_ON for !/chosen
---

xen/arch/arm/domain_build.c             |  2 +-
xen/arch/arm/include/asm/static-shmem.h | 14 --------------
xen/arch/arm/static-shmem.c             |  7 +++++++
3 files changed, 8 insertions(+), 15 deletions(-)
xen/arch/arm/domain_build.c +1 -1
index 85f423214a44..634333cddef3 100644
@@ -2327,7 +2327,7 @@ int __init construct_hwdom(struct kernel_info *kinfo)
 
    if ( acpi_disabled )
    {
-        rc = process_shm_chosen(d, kinfo);
+        rc = process_shm(d, kinfo, NULL);
        if ( rc < 0 )
            return rc;
    }
xen/arch/arm/include/asm/static-shmem.h +0 -14
index fd0867c4f26b..94eaa9d500f9 100644
@@ -18,14 +18,6 @@ int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells,
 int process_shm(struct domain *d, struct kernel_info *kinfo,
                const struct dt_device_node *node);
 
-static inline int process_shm_chosen(struct domain *d,
-                                     struct kernel_info *kinfo)
-{
-    const struct dt_device_node *node = dt_find_node_by_path("/chosen");
-
-    return process_shm(d, kinfo, node);
-}
-
 int process_shm_node(const void *fdt, int node, uint32_t address_cells,
                     uint32_t size_cells);
 
@@ -74,12 +66,6 @@ static inline int process_shm(struct domain *d, struct kernel_info *kinfo,
    return 0;
 }
 
-static inline int process_shm_chosen(struct domain *d,
-                                     struct kernel_info *kinfo)
-{
-    return 0;
-}
-
 static inline void init_sharedmem_pages(void) {};
 
 static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo,
xen/arch/arm/static-shmem.c +7 -0
index c74fa13d4847..e8d4ca3ba3ff 100644
@@ -297,6 +297,13 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,
 {
    struct dt_device_node *shm_node;
 
+    /* Hwdom case - shm node under /chosen */
+    if ( !node )
+    {
+        node = dt_find_node_by_path("/chosen");
+        BUG_ON(!node);
+    }
+
    dt_for_each_child_node(node, shm_node)
    {
        const struct membank *boot_shm_bank;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#3 lore raw
In reply to Michal Orzel

Hi Michal,

Quoted 8 lines · Michal Orzel

Static shared memory requires device-tree boot. At the moment, booting with ACPI enabled and CONFIG_STATIC_SHM=y results in a data abort when dereferencing node in process_shm() because dt_host is always NULL.

Fixes 09c0a8976acf ("xen/arm: enable statically shared memory on Dom0")

Cheers
Bertrand

Quoted 27 lines

---
xen/arch/arm/domain_build.c | 9 ++++++---

1 file changed, 6 insertions(+), 3 deletions(-)
xen/arch/arm/domain_build.c +6 -3
index 2b5b4331834f..85f423214a44 100644
@@ -2325,9 +2325,12 @@ int __init construct_hwdom(struct kernel_info *kinfo)
    else
        allocate_memory(d, kinfo);
 
-    rc = process_shm_chosen(d, kinfo);
-    if ( rc < 0 )
-        return rc;
+    if ( acpi_disabled )
+    {
+        rc = process_shm_chosen(d, kinfo);
+        if ( rc < 0 )
+            return rc;
+    }
 
    /* Map extra GIC MMIO, irqs and other hw stuffs to dom0. */
    rc = gic_map_hwdom_extra_mappings(d);
Signature · 1 line
2.25.1