Skip to contentSkip to conversation

common dom0less updates

PATCH In review Oleksii Kurochko 3 participants 7 messages Nov 27, 2025 – Nov 28, 2025

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 xen/dom0less: move make_chosen_node() to common code

In reply to Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

---
Changes in v2:
- Rebase the patch on top of current staging:
s/struct bootmodule/struct boot_module s/kinfo->cmdline/kinfo->bd.cmdline s/kinfo->initrd_bootmodule/kinfo->bd.initrd
- Update the comment above make_chosen_node:
... on ACPI systems (on platform where CONFIG_ACPI=y) ...
- Move make_chosen_node() to common/domain-build.c as it could be used not only for dom0less.
- Based on the previous review it should be added:

but I decided not to add it as I've changed a place where make_chosen_node() leaves.
- Link to v1:
https://lore.kernel.org/xen-devel/9c87738225d48bd1ee9bba6e8d4e018dfecabccd.1747145897.git.oleksii.kurochko@gmail.com/

---
 xen/arch/arm/domain_build.c           | 46 ---------------------------
 xen/common/device-tree/domain-build.c | 46 +++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 46 deletions(-)
xen/arch/arm/domain_build.c +0 -46
index fb8fbb1650..6d1c9583b1 100644
@@ -1510,52 +1510,6 @@ int __init make_timer_node(const struct kernel_info *kinfo)
     return res;
 }
 
-/*
- * This function is used as part of the device tree generation for Dom0
- * on ACPI systems, and DomUs started directly from Xen based on device
- * tree information.
- */
-int __init make_chosen_node(const struct kernel_info *kinfo)
-{
-    int res;
-    const char *bootargs = NULL;
-    const struct boot_module *initrd = kinfo->bd.initrd;
-    void *fdt = kinfo->fdt;
-
-    dt_dprintk("Create chosen node\n");
-    res = fdt_begin_node(fdt, "chosen");
-    if ( res )
-        return res;
-
-    if ( kinfo->bd.cmdline && kinfo->bd.cmdline[0] )
-    {
-        bootargs = &kinfo->bd.cmdline[0];
-        res = fdt_property(fdt, "bootargs", bootargs, strlen(bootargs) + 1);
-        if ( res )
-           return res;
-    }
-
-    /*
-     * If the bootloader provides an initrd, we must create a placeholder
-     * for the initrd properties. The values will be replaced later.
-     */
-    if ( initrd && initrd->size )
-    {
-        u64 a = 0;
-        res = fdt_property(kinfo->fdt, "linux,initrd-start", &a, sizeof(a));
-        if ( res )
-            return res;
-
-        res = fdt_property(kinfo->fdt, "linux,initrd-end", &a, sizeof(a));
-        if ( res )
-            return res;
-    }
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
                               struct dt_device_node *node,
                               p2m_type_t p2mt)
xen/common/device-tree/domain-build.c +46 -0

52 lines not on this page · raw message

Signature · 1 line
2.52.0
#0 lore raw

v2 cover common dom0less updates

Move make_chosen_node() and make_memory_node() to common code.

---
Changes in V2:
- Link to prev. patch series: https://lore.kernel.org/xen-devel/[email protected]/
- Drop patches:
- xen: restrict CONFIG_STATIC_MEMORY to ARM
- xen/dom0less: refactor architecture-specific DomU construction
As CONFIG_STATIC_MEMORY stuff was moved to common code.
- Add new patch which also moves make_memory_node() to common code.
- All other changes please look at specific patch.
- CI tests: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2183447857
---

Oleksii Kurochko (2):
xen/dom0less: move make_chosen_node() to common code xen/dom0less: move make_memory_node() to common code

 xen/arch/arm/domain_build.c           | 120 -------------------------
 xen/common/device-tree/domain-build.c | 121 ++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 120 deletions(-)
Signature · 1 line
2.52.0
#4 lore raw

PATCH v2 2/2 xen/dom0less: move make_memory_node() to common code

make_memory_node() does not rely on any Arm-specific functionality and is fully reused by RISC-V, making it a good candidate to move into common code.

---
Changes in v2:
- New patch

---
 xen/arch/arm/domain_build.c           | 74 --------------------------
 xen/common/device-tree/domain-build.c | 75 +++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 74 deletions(-)
xen/arch/arm/domain_build.c +0 -74
index 6d1c9583b1..986a456f17 100644
@@ -646,80 +646,6 @@ static int __init fdt_property_interrupts(const struct kernel_info *kinfo,
     return res;
 }
 
-int __init make_memory_node(const struct kernel_info *kinfo, int addrcells,
-                            int sizecells, const struct membanks *mem)
-{
-    void *fdt = kinfo->fdt;
-    unsigned int i;
-    int res, reg_size = addrcells + sizecells;
-    int nr_cells = 0;
-    __be32 reg[DT_MEM_NODE_REG_RANGE_SIZE];
-    __be32 *cells;
-
-    if ( mem->nr_banks == 0 )
-        return -ENOENT;
-
-    /* find the first memory range that is reserved for device (or firmware) */
-    for ( i = 0; i < mem->nr_banks &&
-                 (mem->bank[i].type != MEMBANK_DEFAULT); i++ )
-        ;
-
-    if ( i == mem->nr_banks )
-        return 0;
-
-    dt_dprintk("Create memory node\n");
-
-    res = domain_fdt_begin_node(fdt, "memory", mem->bank[i].start);
-    if ( res )
-        return res;
-
-    res = fdt_property_string(fdt, "device_type", "memory");
-    if ( res )
-        return res;
-
-    cells = &reg[0];
-    for ( ; i < mem->nr_banks; i++ )
-    {
-        u64 start = mem->bank[i].start;
-        u64 size = mem->bank[i].size;
-
-        if ( (mem->bank[i].type == MEMBANK_STATIC_DOMAIN) ||
-             (mem->bank[i].type == MEMBANK_FDT_RESVMEM) )
-            continue;
-
-        nr_cells += reg_size;
-        BUG_ON(nr_cells >= ARRAY_SIZE(reg));
-        dt_child_set_range(&cells, addrcells, sizecells, start, size);
-    }
-
-    /*
-     * static shared memory banks need to be listed as /memory node, so when
-     * this function is handling the normal memory, add the banks.
-     */
-    if ( mem == kernel_info_get_mem_const(kinfo) )
-        shm_mem_node_fill_reg_range(kinfo, reg, &nr_cells, addrcells,
-                                    sizecells);
-
-    for ( cells = reg, i = 0; cells < reg + nr_cells; i++, cells += reg_size )
-    {
-        uint64_t start = dt_read_number(cells, addrcells);
-        uint64_t size = dt_read_number(cells + addrcells, sizecells);
-
-        dt_dprintk("  Bank %u: %#"PRIx64"->%#"PRIx64"\n",
-                   i, start, start + size);
-    }
-
-    dt_dprintk("(reg size %d, nr cells %d)\n", reg_size, nr_cells);
-
-    res = fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg));
-    if ( res )
-        return res;
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
                            void *data)
 {
xen/common/device-tree/domain-build.c +75 -0

87 lines not on this page · raw message

Signature · 1 line
2.52.0
Reviewed-by Tested-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/dom0less: move make_chosen_node() to common code

In reply to Oleksii Kurochko

Hi Oleksii,

Quoted 6 lines · Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

Quoted 8 lines

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

---

Changes looks good to me!

I’ve also run on arm64 and arm32 on FVP platform.

Cheers,
Luca

Reviewed-by Tested-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] xen/dom0less: move make_memory_node() to common code

In reply to Oleksii Kurochko

Hi Oleksii,

Quoted 24 lines
xen/common/device-tree/domain-build.c +8 -0
index 774790aab3..6708c9dd66 100644
@@ -8,6 +8,7 @@
 #include <xen/mm.h>
 #include <xen/sched.h>
 #include <xen/sizes.h>
+#include <xen/static-shmem.h>
 #include <xen/types.h>
 #include <xen/vmap.h>
 
@@ -451,6 +452,80 @@ int __init make_chosen_node(const struct kernel_info *kinfo)
   return res;
 }
 
+int __init make_memory_node(const struct kernel_info *kinfo, int addrcells,
+                            int sizecells, const struct membanks *mem)
+{
+    void *fdt = kinfo->fdt;
+    unsigned int i;
+    int res, reg_size = addrcells + sizecells;
+    int nr_cells = 0;

xen/common/device-tree/domain-build.c int __init make_chosen_node(const struct kernel_info *kinfo) · line 471

Quoted 10 lines
xen/common/device-tree/domain-build.c +10 -0
+    __be32 reg[DT_MEM_NODE_REG_RANGE_SIZE];
+    __be32 *cells;
+
+    if ( mem->nr_banks == 0 )
+        return -ENOENT;
+
+    /* find the first memory range that is reserved for device (or firmware) */
+    for ( i = 0; i < mem->nr_banks &&
+                 (mem->bank[i].type != MEMBANK_DEFAULT); i++ )
+        ;

NIT: maybe we can fix the code style here, maintainers can give their opinion.

Changes looks good to me, I’ve also tested running on arm64 and arm32 FVP:

Cheers,
Luca

Acked-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] xen/dom0less: move make_chosen_node() to common code

In reply to Oleksii Kurochko
Quoted 11 lines · Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

~Michal

Acked-by
#6 lore raw

Re: [PATCH v2 2/2] xen/dom0less: move make_memory_node() to common code

In reply to Luca Fancellu
Quoted 29 lines · Luca Fancellu

Hi Oleksii,

Quoted 28 lines
xen/common/device-tree/domain-build.c +12 -0
index 774790aab3..6708c9dd66 100644
@@ -8,6 +8,7 @@
 #include <xen/mm.h>
 #include <xen/sched.h>
 #include <xen/sizes.h>
+#include <xen/static-shmem.h>
 #include <xen/types.h>
 #include <xen/vmap.h>
 
@@ -451,6 +452,80 @@ int __init make_chosen_node(const struct kernel_info *kinfo)
   return res;
 }
 
+int __init make_memory_node(const struct kernel_info *kinfo, int addrcells,
+                            int sizecells, const struct membanks *mem)
+{
+    void *fdt = kinfo->fdt;
+    unsigned int i;
+    int res, reg_size = addrcells + sizecells;
+    int nr_cells = 0;
+    __be32 reg[DT_MEM_NODE_REG_RANGE_SIZE];
+    __be32 *cells;
+
+    if ( mem->nr_banks == 0 )
Quoted 8 lines

xen/common/device-tree/domain-build.c int __init make_chosen_node(const struct kernel_info *kinfo) · line 471

Quoted 6 lines
xen/common/device-tree/domain-build.c +6 -0
+        return -ENOENT;
+
+    /* find the first memory range that is reserved for device (or firmware) */
+    for ( i = 0; i < mem->nr_banks &&
+                 (mem->bank[i].type != MEMBANK_DEFAULT); i++ )
+        ;

NIT: maybe we can fix the code style here, maintainers can give their opinion.

I'd prefer to keep the movement clean.

~Michal