Skip to contentSkip to conversation

Early Boot Allocation on Power

PATCH Superseded Shawn Anastasio 6 participants 16 messages Dec 1, 2023 – Dec 15, 2023

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Early Boot Allocation on Power

Hello all,

This series enables the Xen boot time allocator on Power by parsing the available memory regions from the firmware-provided device tree.

The device tree processing and bookkeeping code was adapted from Arm, but it was trimmed down to exclude code for parsing Arm-specific dt nodes.

Additionally, the final patch of the series updates the radix mmu code to use the newly-enabled boot allocator for the Partition and Process tables, instead of statically allocating them like was previously done. Among other things, switching to run-time allocation allows us to allocate a full-sized Process Table instead of the minimal one that was previously used to keep the Xen binary size small.

Thanks,

Shawn Anastasio (3):
xen/ppc: Enable Boot Allocator
xen/ppc: mm-radix: Replace debug printing code with printk xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime

 xen/arch/ppc/Makefile            |   1 +
 xen/arch/ppc/bootfdt.c           | 507 +++++++++++++++++++++++++++++++
 xen/arch/ppc/include/asm/setup.h | 113 +++++++
 xen/arch/ppc/mm-radix.c          | 197 ++++++------
 xen/arch/ppc/setup.c             | 109 ++++++-
 5 files changed, 823 insertions(+), 104 deletions(-)
 create mode 100644 xen/arch/ppc/bootfdt.c

--
2.30.2

#1 lore raw

PATCH 1/3 xen/ppc: Enable Boot Allocator

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

---
 xen/arch/ppc/Makefile            |   1 +
 xen/arch/ppc/bootfdt.c           | 507 +++++++++++++++++++++++++++++++
 xen/arch/ppc/include/asm/setup.h | 113 +++++++
 xen/arch/ppc/setup.c             | 109 ++++++-
 4 files changed, 729 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/ppc/bootfdt.c
xen/arch/ppc/Makefile +1 -0
index 71feb5e2c4..8a2a809c70 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_PPC64) += ppc64/
 
+obj-y += bootfdt.o
 obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o
 obj-y += mm-radix.o
 obj-y += opal.o
xen/arch/ppc/bootfdt.c new file +507 -0

507 lines not on this page · raw message

xen/arch/ppc/include/asm/setup.h +113 -0

117 lines not on this page · raw message

xen/arch/ppc/setup.c +108 -1

141 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Maybe Oleksii has already a version doing that.

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Quoted 10 lines

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

Quoted 5 lines

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Maybe Oleksii has already a version doing that.

Just my $0.02, but wouldn't it make more sense to have the RISC-V port handle the deduplication, seeing as the POWER support came first here? We don't know if/when the RISC-V port will be ready for submission, so I'm not sure why we should be on the hook for this particular work.

Thanks!

#4 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi,

Quoted 14 lines · On 01/12/2023 22:10, [email protected] wrote:
Quoted 14 lines

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Quoted 6 lines
Quoted 1 line

Maybe Oleksii has already a version doing that.

Just my $0.02, but wouldn't it make more sense to have the RISC-V port handle the deduplication, seeing as the POWER support came first here? We don't know if/when the RISC-V port will be ready for submission, so I'm not sure why we should be on the hook for this particular work.

That would have been a valid point if you were writing a brand new implementation. But this was *copied* from Arm.

Looking at the diff between arm/bootfdt.c and ppc/bootfdt.c, you seem to have:
- As well copied some code from arm/setup.c
- Re-order some statement (not clear why)
- Remove some code which you say are Arm specific. Yet some is part
of the Device-Tree spec and I would expect to be used in the future.

So my question here stands. Why are you mainly copying verbatimly the Arm code rather than consolidating in one place?

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

----- Original Message -----

Quoted 43 lines

From: "Julien Grall" <[email protected]>
To: "Timothy Pearson" <[email protected]>
Cc: "Shawn Anastasio" <[email protected]>, "xen-devel" <[email protected]>, "Jan Beulich" <[email protected]>, "Daniel P. Smith" <[email protected]>, "Stefano Stabellini" <[email protected]>, "Bertrand Marquis" <[email protected]>, "Michal Orzel" <[email protected]>, "Oleksii" <[email protected]>
Sent: Friday, December 1, 2023 4:35:55 PM
Subject: Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi,

Quoted 14 lines · On 01/12/2023 22:10, [email protected] wrote:
Quoted 14 lines

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Quoted 6 lines
Quoted 1 line

Maybe Oleksii has already a version doing that.

Just my $0.02, but wouldn't it make more sense to have the RISC-V port handle the deduplication, seeing as the POWER support came first here? We don't know if/when the RISC-V port will be ready for submission, so I'm not sure why we should be on the hook for this particular work.

That would have been a valid point if you were writing a brand new implementation. But this was *copied* from Arm.

Looking at the diff between arm/bootfdt.c and ppc/bootfdt.c, you seem to have:
- As well copied some code from arm/setup.c
- Re-order some statement (not clear why)
- Remove some code which you say are Arm specific. Yet some is part
of the Device-Tree spec and I would expect to be used in the future.

Quoted 2 lines

So my question here stands. Why are you mainly copying verbatimly the Arm code rather than consolidating in one place?

That's fair, with the future RISC-V port removed from the discussion and good reasons still being put forth it makes more sense to deduplicate now. Thank you for clarifying the objection! :)

#6 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi,

Quoted 46 lines · Timothy Pearson

----- Original Message -----

Quoted 43 lines

From: "Julien Grall" <[email protected]>
To: "Timothy Pearson" <[email protected]>
Cc: "Shawn Anastasio" <[email protected]>, "xen-devel" <[email protected]>, "Jan Beulich" <[email protected]>, "Daniel P. Smith" <[email protected]>, "Stefano Stabellini" <[email protected]>, "Bertrand Marquis" <[email protected]>, "Michal Orzel" <[email protected]>, "Oleksii" <[email protected]>
Sent: Friday, December 1, 2023 4:35:55 PM
Subject: Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi,

Quoted 14 lines · On 01/12/2023 22:10, [email protected] wrote:
Quoted 14 lines

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Quoted 6 lines
Quoted 1 line

Maybe Oleksii has already a version doing that.

Just my $0.02, but wouldn't it make more sense to have the RISC-V port handle the deduplication, seeing as the POWER support came first here? We don't know if/when the RISC-V port will be ready for submission, so I'm not sure why we should be on the hook for this particular work.

That would have been a valid point if you were writing a brand new implementation. But this was *copied* from Arm.

Looking at the diff between arm/bootfdt.c and ppc/bootfdt.c, you seem to have:
- As well copied some code from arm/setup.c
- Re-order some statement (not clear why)
- Remove some code which you say are Arm specific. Yet some is part
of the Device-Tree spec and I would expect to be used in the future.

Quoted 4 lines
Quoted 2 lines

So my question here stands. Why are you mainly copying verbatimly the Arm code rather than consolidating in one place?

That's fair, with the future RISC-V port removed from the discussion and good reasons still being put forth it makes more sense to deduplicate now. Thank you for clarifying the objection! :)

I have had a brief look at the differences. I moved some of the functions to bootfdt.c in order to match PPC. Below the diff after that.

Leaving aside some of the clean-up, it sounds like you:
* removed BOOTMOD_{RAMDISK, XSM...}. So how do you plan to pass XSM blob and ramdisk in the future?
* split long prink-messages. For Xen, we keep them in one line even if it is over 80 characters to facilite grepping.
* Remove device_tree_node_is_available(), I believe you still need it because the property is not Arm specific.
* Remove process_multiboot(), how do you plan to handle dom0less domain in the future?
* Likewise for xen,static-mem and boot_fdt_cmdline()?
* fdt_get_mem_rsv_paddr(), this is part of the DT is used to reserve memory. This was superseed to /reserved-memory, but I wonder how widespread this is on PPC?
* You are removing the sorting of the memory bank. We had to do the sorting on Arm because some DT didn't have the banks sorted and this helped will the logic memory subystem logic. I can understand if you don't need it, but it would not hurt.
* If am not mistaken you are adding the Xen module as BOOTMOD_KERNEL, however this is meant to be used for the domain kernel. Xen should be BOOTMOD_XEN.

Overall, it feels to me that nearly (if not all) bootfdt.c can be moved to common (maybe under a new directory common/device-tree?) and #ifdef bits that are dom0less specific (we now have a Kconfig for that). You can do the clean-up as well, but they would belong to separate patches.

I hope that helps.

Cheers,

bootfdt.c renamed from arm/bootfdt.c +17 -58
@@ -1,9 +1,12 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Early Device Tree
+ * Early Device Tree and boot info bookkeeping.
+ * Derived from arch/arm/bootfdt.c and setup.c.
  *
  * Copyright (C) 2012-2014 Citrix Systems, Inc.
+ * Copyright (C) Raptor Engineering LLC
  */
+
 #include <xen/types.h>
 #include <xen/lib.h>
 #include <xen/kernel.h>
@@ -15,7 +18,8 @@
 #include <xen/sort.h>
 #include <xsm/xsm.h>
 #include <asm/setup.h>
-#include <asm/static-shmem.h>
+
+struct bootinfo __initdata bootinfo;
 
 struct bootmodule __init *add_boot_module(bootmodule_kind kind,
                                           paddr_t start, paddr_t size,
@@ -62,10 +66,6 @@
     case BOOTMOD_XEN:     return "Xen";
     case BOOTMOD_FDT:     return "Device Tree";
     case BOOTMOD_KERNEL:  return "Kernel";
-    case BOOTMOD_RAMDISK: return "Ramdisk";
-    case BOOTMOD_XSM:     return "XSM";
-    case BOOTMOD_GUEST_DTB:     return "DTB";
-    case BOOTMOD_UNKNOWN: return "Unknown";
     default: BUG();
     }
 }
@@ -91,8 +91,9 @@
             continue;
         else
         {
-            printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with mod[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n",
-                   region_start, region_end, i, mod_start, mod_end);
+            printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with"
+                   " mod[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", region_start,
+                   region_end, i, mod_start, mod_end);
             return true;
         }
     }
@@ -121,8 +122,9 @@
             continue;
         else
         {
-            printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with bank[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n",
-                   region_start, region_end, i, bank_start, bank_end);
+            printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with"
+                   " bank[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", region_start,
+                   region_end, i, bank_start, bank_end);
             return true;
         }
     }
@@ -149,30 +151,6 @@
                                    region_start, region_size) )
         return true;
 
-#ifdef CONFIG_ACPI
-    /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory */
-    if ( meminfo_overlap_check(&bootinfo.acpi, region_start, region_size) )
-        return true;
-#endif
-
-    return false;
-}
-
-static bool __init device_tree_node_is_available(const void *fdt, int node)
-{
-    const char *status;
-    int len;
-
-    status = fdt_getprop(fdt, node, "status", &len);
-    if ( !status )
-        return true;
-
-    if ( len > 0 )
-    {
-        if ( !strcmp(status, "ok") || !strcmp(status, "okay") )
-            return true;
-    }
-
     return false;
 }
 
@@ -185,33 +163,14 @@
     name = fdt_get_name(fdt, node, NULL);
     match_len = strlen(match);
 
-    /* Match both "match" and "match@..." patterns but not
-       "match-foo". */
+    /*
+     * Match both "match" and "match@..." patterns but not
+     * "match-foo".
+     */
     return strncmp(name, match, match_len) == 0
         && (name[match_len] == '@' || name[match_len] == '\0');
 }
 
-static bool __init device_tree_node_compatible(const void *fdt, int node,
-                                               const char *match)
-{
-    int len, l;
-    const void *prop;
-
-    prop = fdt_getprop(fdt, node, "compatible", &len);
-    if ( prop == NULL )
-        return false;
-
-    while ( len > 0 ) {
-        if ( !dt_compat_cmp(prop, match) )
-            return true;
-        l = strlen(prop) + 1;
-        prop += l;
-        len -= l;
-    }
-
-    return false;
-}
-
 void __init device_tree_get_reg(const __be32 **cell, uint32_t 

address_cells,
uint32_t size_cells, paddr_t *start, paddr_t *size)
@@ -247,19 +206,16 @@

static int __init device_tree_get_meminfo(const void *fdt, int node,
const char *prop_name,
- u32 address_cells, u32 size_cells,
+ uint32_t address_cells, uint32_t size_cells,
void *data, enum
membank_type type)

 {
     const struct fdt_property *prop;
     unsigned int i, banks;
     const __be32 *cell;
-    u32 reg_cells = address_cells + size_cells;
+    uint32_t reg_cells = address_cells + size_cells;
     paddr_t start, size;
     struct meminfo *mem = data;

- if ( !device_tree_node_is_available(fdt, node) )
- return 0;
-

     if ( address_cells < 1 || size_cells < 1 )
     {
         printk("fdt: property `%s': invalid #address-cells or 
#size-cells",
@@ -272,7 +228,7 @@
         return -ENOENT;

     cell = (const __be32 *)prop->data;

- banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32));
+ banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof(uint32_t));

     for ( i = 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ )
     {
@@ -298,13 +254,13 @@
     return 0;

}

-u32 __init device_tree_get_u32(const void *fdt, int node,
- const char *prop_name, u32 dflt)
+uint32_t __init device_tree_get_uint32_t(const void *fdt, int node,
+ const char *prop_name, uint32_t dflt)

 {
     const struct fdt_property *prop;

     prop = fdt_get_property(fdt, node, prop_name, NULL);
-    if ( !prop || prop->len < sizeof(u32) )
+    if ( !prop || prop->len < sizeof(uint32_t) )
         return dflt;

     return fdt32_to_cpu(*(uint32_t*)prop->data);
@@ -332,13 +288,13 @@
      */
     int depth = 0;
     const int first_node = node;
-    u32 address_cells[DEVICE_TREE_MAX_DEPTH];
-    u32 size_cells[DEVICE_TREE_MAX_DEPTH];
+    uint32_t address_cells[DEVICE_TREE_MAX_DEPTH];
+    uint32_t size_cells[DEVICE_TREE_MAX_DEPTH];
     int ret;

     do {
         const char *name = fdt_get_name(fdt, node, NULL);

- u32 as, ss;
+ uint32_t as, ss;

if ( depth >= DEVICE_TREE_MAX_DEPTH ) {
@@ -350,9 +306,9 @@
as = depth > 0 ? address_cells[depth-1] :

DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
         ss = depth > 0 ? size_cells[depth-1] : 

DT_ROOT_NODE_SIZE_CELLS_DEFAULT;

- address_cells[depth] = device_tree_get_u32(fdt, node,
+ address_cells[depth] = device_tree_get_uint32_t(fdt, node,

                                                    "#address-cells", as);
-        size_cells[depth] = device_tree_get_u32(fdt, node,
+        size_cells[depth] = device_tree_get_uint32_t(fdt, node,
                                                 "#size-cells", ss);

         /* skip the first node */

@@ -371,7 +327,7 @@

static int __init process_memory_node(const void *fdt, int node,
const char *name, int depth,
- u32 address_cells, u32 size_cells,
+ uint32_t address_cells, uint32_t size_cells,
void *data)
{
return device_tree_get_meminfo(fdt, node, "reg", address_cells,
size_cells,
@@ -380,13 +336,16 @@

static int __init process_reserved_memory_node(const void *fdt, int node,
const char *name, int
depth,

-                                               u32 address_cells,
-                                               u32 size_cells,
+                                               uint32_t address_cells,
+                                               uint32_t size_cells,

void *data)
{
- int rc = process_memory_node(fdt, node, name, depth, address_cells,
+ int rc;
+
+ rc = process_memory_node(fdt, node, name, depth, address_cells,

                                  size_cells, data);

+
if ( rc == -ENOSPC )
panic("Max number of supported reserved-memory regions

reached.\n");
     else if ( rc != -ENOENT )

@@ -396,124 +355,28 @@

static int __init process_reserved_memory(const void *fdt, int node,
const char *name, int depth,
- u32 address_cells, u32 size_cells)
+ uint32_t address_cells, uint32_t size_cells)
{
return device_tree_for_each_node(fdt, node,
process_reserved_memory_node, &bootinfo.reserved_mem);
}

-static void __init process_multiboot_node(const void *fdt, int node,
- const char *name,
- u32 address_cells, u32 size_cells)
-{

-    static int __initdata kind_guess = 0;
-    const struct fdt_property *prop;
-    const __be32 *cell;
-    bootmodule_kind kind;
-    paddr_t start, size;
-    int len;
-    /* sizeof("/chosen/") + DT_MAX_NAME + '/' + DT_MAX_NAME + '/0' => 92 */
-    char path[92];
-    int parent_node, ret;
-    bool domU;

-
- parent_node = fdt_parent_offset(fdt, node);
- ASSERT(parent_node >= 0);
-

-    /* Check that the node is under "/chosen" (first 7 chars of path) */
-    ret = fdt_get_path(fdt, node, path, sizeof (path));
-    if ( ret != 0 || strncmp(path, "/chosen", 7) )

- return;
-
- prop = fdt_get_property(fdt, node, "reg", &len);
- if ( !prop )
- panic("node %s missing `reg' property\n", name);
-
- if ( len < dt_cells_to_size(address_cells + size_cells) )
- panic("fdt: node %s': reg` property length is too short\n",
- name);
-
- cell = (const __be32 *)prop->data;
- device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
-
- if ( fdt_node_check_compatible(fdt, node, "xen,linux-zimage") == 0 ||
- fdt_node_check_compatible(fdt, node, "multiboot,kernel") == 0 )
- kind = BOOTMOD_KERNEL;
- else if ( fdt_node_check_compatible(fdt, node, "xen,linux-initrd") == 0 ||
- fdt_node_check_compatible(fdt, node, "multiboot,ramdisk") == 0 )
- kind = BOOTMOD_RAMDISK;
- else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 )
- kind = BOOTMOD_XSM;
- else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 )
- kind = BOOTMOD_GUEST_DTB;
- else
- kind = BOOTMOD_UNKNOWN;
-
- /**

-     * Guess the kind of these first two unknowns respectively:
-     * (1) The first unknown must be kernel.
-     * (2) Detect the XSM Magic from the 2nd unknown:
-     *     a. If it's XSM, set the kind as XSM, and that also means we
-     *     won't load ramdisk;
-     *     b. if it's not XSM, set the kind as ramdisk.
-     *     So if user want to load ramdisk, it must be the 2nd unknown.
-     * We also detect the XSM Magic for the following unknowns,
-     * then set its kind according to the return value of has_xsm_magic.
-     */
-    if ( kind == BOOTMOD_UNKNOWN )
-    {
-        switch ( kind_guess++ )
-        {
-        case 0: kind = BOOTMOD_KERNEL; break;
-        case 1: kind = BOOTMOD_RAMDISK; break;
-        default: break;
-        }
-        if ( kind_guess > 1 && has_xsm_magic(start) )

- kind = BOOTMOD_XSM;
- }
-
- domU = fdt_node_check_compatible(fdt, parent_node, "xen,domain") == 0;
- add_boot_module(kind, start, size, domU);
-
- prop = fdt_get_property(fdt, node, "bootargs", &len);
- if ( !prop )
- return;
- add_boot_cmdline(fdt_get_name(fdt, parent_node, &len), prop->data,
- kind, start, domU);
-}
-
static int __init process_chosen_node(const void *fdt, int node,
const char *name,
- u32 address_cells, u32 size_cells)
+ uint32_t address_cells, uint32_t size_cells)

 {
     const struct fdt_property *prop;
     paddr_t start, end;
     int len;

- if ( fdt_get_property(fdt, node, "xen,static-heap", NULL) )
- {
- int rc;
-
- printk("Checking for static heap in /chosen\n");
-
- rc = device_tree_get_meminfo(fdt, node, "xen,static-heap",

-                                     address_cells, size_cells,
-                                     &bootinfo.reserved_mem,
-                                     MEMBANK_STATIC_HEAP);

- if ( rc )
- return rc;
-
- bootinfo.static_heap = true;
- }
-

     printk("Checking for initrd in /chosen\n");

     prop = fdt_get_property(fdt, node, "linux,initrd-start", &len);
     if ( !prop )
         /* No initrd present. */
         return 0;

- if ( len != sizeof(u32) && len != sizeof(u64) )
+ if ( len != sizeof(uint32_t) && len != sizeof(uint64_t) )
{
printk("linux,initrd-start property has invalid length %d\n",

len);
         return -EINVAL;
@@ -526,7 +389,7 @@
         printk("linux,initrd-end not present but -start was\n");
         return -EINVAL;
     }
-    if ( len != sizeof(u32) && len != sizeof(u64) )
+    if ( len != sizeof(uint32_t) && len != sizeof(uint64_t) )
     {
         printk("linux,initrd-end property has invalid length %d\n", len);
         return -EINVAL;
@@ -547,51 +410,21 @@
     return 0;

}

-static int __init process_domain_node(const void *fdt, int node,
- const char *name,
- u32 address_cells, u32 size_cells)
-{
- const struct fdt_property *prop;
-
- printk("Checking for \"xen,static-mem\" in domain node\n");
-
- prop = fdt_get_property(fdt, node, "xen,static-mem", NULL);
- if ( !prop )
- /* No "xen,static-mem" present. */
- return 0;
-
- return device_tree_get_meminfo(fdt, node, "xen,static-mem", address_cells,
- size_cells, &bootinfo.reserved_mem,
- MEMBANK_STATIC_DOMAIN);
-}
-
static int __init early_scan_node(const void *fdt,
int node, const char *name, int depth,
- u32 address_cells, u32 size_cells,
+ uint32_t address_cells, uint32_t size_cells,
void *data)

 {
     int rc = 0;

- /*

-     * If Xen has been booted via UEFI, the memory banks are
-     * populated. So we should skip the parsing.
-     */

- if ( !efi_enabled(EFI_BOOT) &&
- device_tree_node_matches(fdt, node, "memory") )
+ if( device_tree_node_matches(fdt, node, "memory") )
rc = process_memory_node(fdt, node, name, depth,
address_cells, size_cells,

&bootinfo.mem);
     else if ( depth == 1 && !dt_node_cmp(name, "reserved-memory") )
         rc = process_reserved_memory(fdt, node, name, depth,
                                      address_cells, size_cells);
-    else if ( depth <= 3 && (device_tree_node_compatible(fdt, node, "xen,multiboot-module" ) ||
-              device_tree_node_compatible(fdt, node, "multiboot,module" )))
-        process_multiboot_node(fdt, node, name, address_cells, size_cells);
     else if ( depth == 1 && device_tree_node_matches(fdt, node, 

"chosen") )
rc = process_chosen_node(fdt, node, name, address_cells,
size_cells);
- else if ( depth == 2 && device_tree_node_compatible(fdt, node, "xen,domain") )
- rc = process_domain_node(fdt, node, name, address_cells, size_cells);
- else if ( depth <= 3 && device_tree_node_compatible(fdt, node, "xen,domain-shared-memory-v1") )
- rc = process_shm_node(fdt, node, address_cells, size_cells);

     if ( rc < 0 )
         printk("fdt: node `%s': parsing failed\n", name);
@@ -604,7 +437,7 @@
     struct meminfo *mem_resv = &bootinfo.reserved_mem;
     struct bootmodules *mods = &bootinfo.modules;
     struct bootcmdlines *cmds = &bootinfo.cmdlines;

- unsigned int i, j, nr_rsvd;
+ unsigned int i, j;

     for ( i = 0; i < mi->nr_banks; i++ )
         printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
@@ -618,21 +451,9 @@
                 mods->module[i].start + mods->module[i].size,
                 boot_module_kind_as_string(mods->module[i].kind));
-    nr_rsvd = fdt_num_mem_rsv(device_tree_flattened);
-    for ( i = 0; i < nr_rsvd; i++ )
-    {

- paddr_t s, e;
-
- if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &s, &e) < 0 )
- continue;
-

-        /* fdt_get_mem_rsv_paddr returns length */
-        e += s;
-        printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e);
-    }
     for ( j = 0; j < mem_resv->nr_banks; j++, i++ )
     {
-        printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i,
+        printk(" RESVD_[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i,
                mem_resv->bank[j].start,
                mem_resv->bank[j].start + mem_resv->bank[j].size - 1);
     }
@@ -644,89 +465,43 @@
     printk("\n");

}

-/* This function assumes that memory regions are not overlapped */ -static int __init cmp_memory_node(const void *key, const void *elem) -{
- const struct membank *handler0 = key;
- const struct membank *handler1 = elem;
-
- if ( handler0->start < handler1->start )
- return -1;
-
- if ( handler0->start >= (handler1->start + handler1->size) )
- return 1;
-
- return 0;
-}
-
-static void __init swap_memory_node(void *_a, void *_b, size_t size) -{
- struct membank *a = _a, *b = _b;
-
- SWAP(*a, *b);
-}
-
/**
- * boot_fdt_info - initialize bootinfo from a DTB
+ * boot_fdt_init - initialize bootinfo from a DTB
* @fdt: flattened device tree binary
+ * @paddr: physical address of device tree binary
*
* Returns the size of the DTB.
*/
-size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) +size_t __init boot_fdt_init(const void *fdt, paddr_t paddr)

 {
     int ret;

+ paddr_t xen_start, xen_end;

     ret = fdt_check_header(fdt);
     if ( ret < 0 )
         panic("No valid device tree\n");

- add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
-

     device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);

     /*
-     * On Arm64 setup_directmap_mappings() expects to be called with the lowest
-     * bank in memory first. There is no requirement that the DT will provide
-     * the banks sorted in ascending order. So sort them through.
+     * The device tree passed to us may have been allocated by skiboot, in which
+     * case it will exist within a reserved region and this call will fail. This
+     * is fine, however, since either way the allocator will know not to step on
+     * the device tree.
      */

- sort(bootinfo.mem.bank, bootinfo.mem.nr_banks, sizeof(struct membank),
- cmp_memory_node, swap_memory_node);
+ add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
+
+ /*

+     * Xen relocates itself at the ppc64 entrypoint, so we need to manually mark
+     * the kernel module.
+     */
+    xen_start = __pa(_start);
+    xen_end = PAGE_ALIGN(__pa(_end));
+    if ( !add_boot_module(BOOTMOD_KERNEL, xen_start, xen_end, false) )

+ panic("Xen overlaps reserved memory! %016lx - %016lx\n", xen_start,
+ xen_end);

     early_print_info();

     return fdt_totalsize(fdt);

}
-
-const __init char *boot_fdt_cmdline(const void *fdt) -{
- int node;
- const struct fdt_property *prop;
-
- node = fdt_path_offset(fdt, "/chosen");
- if ( node < 0 )
- return NULL;
-

-    prop = fdt_get_property(fdt, node, "xen,xen-bootargs", NULL);
-    if ( prop == NULL )
-    {

- struct bootcmdline *dom0_cmdline =
- boot_cmdline_find_by_kind(BOOTMOD_KERNEL);
-
- if (fdt_get_property(fdt, node, "xen,dom0-bootargs", NULL) ||
- ( dom0_cmdline && dom0_cmdline->cmdline[0] ) )
- prop = fdt_get_property(fdt, node, "bootargs", NULL);
- }
- if ( prop == NULL )
- return NULL;
-
- return prop->data;
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi Julien,

Thank you for the feedback. Most of your points will be addressed by following your suggestion of moving ARM's bootfdt.c to common, but I wanted to respond with a few points of clarification.

Quoted 3 lines · Julien Grall

* fdt_get_mem_rsv_paddr(), this is part of the DT is used to reserve memory. This was superseed to /reserved-memory, but I wonder how widespread this is on PPC?

As far as I can tell, the DT reserve memory map is not used on PPC/PowerNV. This information is instead communicated through reserved-memory nodes in the DT itself, which the existing code handles.

Quoted 3 lines

* If am not mistaken you are adding the Xen module as BOOTMOD_KERNEL, however this is meant to be used for the domain kernel. Xen should be BOOTMOD_XEN.

Thank you for pointing this out -- BOOTMOD_XEN is indeed the correct choice here.

Quoted 4 lines

I hope that helps.

Cheers,

Thanks,
Shawn

#8 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Hi Shawn,

Quoted 7 lines · Shawn Anastasio

Hi Julien,

Thank you for the feedback. Most of your points will be addressed by following your suggestion of moving ARM's bootfdt.c to common, but I wanted to respond with a few points of clarification.

On 12/1/23 5:23 PM, Julien Grall wrote:

Quoted 8 lines
Quoted 3 lines

* fdt_get_mem_rsv_paddr(), this is part of the DT is used to reserve memory. This was superseed to /reserved-memory, but I wonder how widespread this is on PPC?

As far as I can tell, the DT reserve memory map is not used on PPC/PowerNV. This information is instead communicated through reserved-memory nodes in the DT itself, which the existing code handles.

On Arm, there is a mix between using /memreserve (found by Xen via fdt_get_mem_rsv_paddr() and reserved-memory.

Looking at Linux, it seems that it will try to parse /memreserve in PPC and I have found a few DT using it:

42sh> ack memreserve
boot/dts/currituck.dts
13:/memreserve/ 0x01f00000 0x00100000; // spin table

boot/dts/akebono.dts
14:/memreserve/ 0x01f00000 0x00100000; // spin table

boot/dts/iss4xx-mpic.dts
17:/memreserve/ 0x01f00000 0x00100000;

boot/dts/mpc836x_mds.dts
10:/memreserve/ 00000000 1000000;

boot/dts/wii.dts
17: * contiguous RAM range and will BUG() if the memreserve is outside
20:/*/memreserve/ 0x10000000 0x0004000;*/ /* DSP RAM */

I guess we are not targetting any of those hardwares. Even if this is the case, I don't think we can simply ignore the node. If you don't want to handle them, then I would at least suggest to add a check in Xen to confirm the /memreserve/ is empty.

Better to catch such DT early rather than debugging a memory corruption later on :).

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

In reply to Julien Grall

Hi Julien and Shawn,

Quoted 12 lines · Julien Grall

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 6 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot
allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that
was copied.

Quoted 5 lines

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

Maybe Oleksii has already a version doing that.

On RISC-V side I introduced the common bootfdt but probably it should be aligned with the latest version ( my plan was to do that before sending a patch to upstream ) of ARM's bootfdt.c.

https://gitlab.com/xen-project/people/olkur/xen/-/commit/ad2c8766a7d0886df84f6c60823275816c2115f5

I can re-work it this week and send it to the ML but I'll be happy if Shawn can do it or his version as common so I'll be able to reuse it soon.

~ Oleksii

#10 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

In reply to Julien Grall
Quoted 11 lines · Julien Grall

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 4 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot allocator. Routines for parsing arm-specific devicetree nodes (e.g. multiboot) were excluded, reducing the overall footprint of code that was copied.

I expect RISC-V to want similar code. I am not really thrilled in the idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

That is actually 4, Hyperlaunch already did a common version for our usage.

Quoted 4 lines

Maybe Oleksii has already a version doing that.

Cheers,

V/r,
Daniel P. Smith
Apertus Solutions, LLC

#11 lore raw

Re: [PATCH 1/3] xen/ppc: Enable Boot Allocator

Quoted 14 lines · Daniel P. Smith
Quoted 13 lines · Julien Grall

(+ Arm and RISC-V folks)

Hi Shawn,

Quoted 7 lines · Shawn Anastasio

Adapt arm's earlyfdt parsing code to ppc64 and enable Xen's early boot
allocator. Routines for parsing arm-specific devicetree nodes (e.g.
multiboot) were excluded, reducing the overall footprint of code that
was copied.

Quoted 7 lines
Quoted 4 lines

I expect RISC-V to want similar code. I am not really thrilled in the
idea of having 3 similar copy of the parsing. So can we extract the common bits (or harmonize it) so it can be shared?

That is actually 4, Hyperlaunch already did a common version for our usage.

Sounds great. I'll look at and switch RISC-V to it. Thanks.

Quoted 12 lines
Quoted 5 lines

Maybe Oleksii has already a version doing that.

Cheers,

V/r,
Daniel P. Smith
Apertus Solutions, LLC

#12 lore raw

PATCH 2/3 xen/ppc: mm-radix: Replace debug printing code with printk

In reply to Shawn Anastasio

Now that we have common code building, there's no need to keep the old itoa64+debug print function in mm-radix.c

---
 xen/arch/ppc/mm-radix.c | 58 +++++++++--------------------------------
 1 file changed, 12 insertions(+), 46 deletions(-)
xen/arch/ppc/mm-radix.c +12 -46
index daa411a6fa..de181cf6f1 100644
@@ -15,6 +15,12 @@
 
 void enable_mmu(void);
 
+#ifdef NDEBUG
+#define radix_dprintk(...)
+#else
+#define radix_dprintk(msg, ...) printk(XENLOG_DEBUG msg, ## __VA_ARGS__)
+#endif
+
 #define INITIAL_LVL1_PD_COUNT      1
 #define INITIAL_LVL2_LVL3_PD_COUNT 2
 #define INITIAL_LVL4_PT_COUNT      256
@@ -80,45 +86,6 @@ static __init struct lvl4_pt *lvl4_pt_pool_alloc(void)
     return &initial_lvl4_pt_pool[initial_lvl4_pt_pool_used++];
 }
 
-#ifndef NDEBUG
-/* TODO: Remove once we get common/ building */
-static char *__init itoa64_hex(uint64_t val, char *out_buf, size_t buf_len)
-{
-    uint64_t cur;
-    size_t i = buf_len - 1;
-
-    /* Null terminate buffer */
-    out_buf[i] = '\0';
-
-    /* Add digits in reverse */
-    cur = val;
-    while ( cur && i > 0 )
-    {
-        out_buf[--i] = "0123456789ABCDEF"[cur % 16];
-        cur /= 16;
-    }
-
-    /* Pad to 16 digits */
-    while ( i > 0 )
-        out_buf[--i] = '0';
-
-    return out_buf + i;
-}
-#endif
-
-static void __init radix_dprint(uint64_t addr, const char *msg)
-{
-#ifndef NDEBUG
-    char buf[sizeof("DEADBEEFCAFEBABA")];
-    char *addr_s = itoa64_hex(addr, buf, sizeof(buf));
-
-    early_printk("(0x");
-    early_printk(addr_s);
-    early_printk(") ");
-    early_printk(msg);
-#endif
-}
-
 static void __init setup_initial_mapping(struct lvl1_pd *lvl1,
                                          vaddr_t map_start,
                                          vaddr_t map_end,
@@ -186,27 +153,26 @@ static void __init setup_initial_mapping(struct lvl1_pd *lvl1,
             unsigned long paddr = (page_addr - map_start) + phys_base;
             unsigned long flags;
 
-            radix_dprint(paddr, "being mapped to ");
-            radix_dprint(page_addr, "!\n");
+            radix_dprintk("%016lx being mapped to %016lx\n", paddr, page_addr);
             if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr) )
             {
-                radix_dprint(page_addr, "being marked as TEXT (RX)\n");
+                radix_dprintk("%016lx being marked as TEXT (RX)\n", page_addr);
                 flags = PTE_XEN_RX;
             }
             else if ( is_kernel_rodata(page_addr) )
             {
-                radix_dprint(page_addr, "being marked as RODATA (RO)\n");
+                radix_dprintk("%016lx being marked as RODATA (RO)\n", page_addr);
                 flags = PTE_XEN_RO;
             }
             else
             {
-                radix_dprint(page_addr, "being marked as DEFAULT (RW)\n");
+                radix_dprintk("%016lx being marked as DEFAULT (RW)\n", page_addr);
                 flags = PTE_XEN_RW;
             }
 
             *pte = paddr_to_pte(paddr, flags);
-            radix_dprint(paddr_to_pte(paddr, flags).pte,
-                             "is result of PTE map!\n");
+            radix_dprintk("%016lx is the result of PTE map\n",
+                paddr_to_pte(paddr, flags).pte);
         }
         else
         {
Signature · 1 line
2.30.2
#13 lore raw

PATCH 3/3 xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime

In reply to Shawn Anastasio

In the initial mm-radix implementation, the in-memory partition and process tables required to configure the MMU were allocated statically since the boot allocator was not yet available.

Now that it is, allocate these tables at runtime and bump the size of the Process Table to its maximum supported value (on POWER9).

---
 xen/arch/ppc/mm-radix.c | 167 +++++++++++++++++++++++-----------------
 1 file changed, 96 insertions(+), 71 deletions(-)
xen/arch/ppc/mm-radix.c +96 -71
index de181cf6f1..fae5ebfdcc 100644
@@ -34,17 +34,13 @@ static struct lvl2_pd initial_lvl2_lvl3_pd_pool[INITIAL_LVL2_LVL3_PD_COUNT];
 static size_t __initdata initial_lvl4_pt_pool_used;
 static struct lvl4_pt initial_lvl4_pt_pool[INITIAL_LVL4_PT_COUNT];
 
-/* Only reserve minimum Partition and Process tables  */
 #define PATB_SIZE_LOG2 16 /* Only supported partition table size on POWER9 */
 #define PATB_SIZE      (1UL << PATB_SIZE_LOG2)
-#define PRTB_SIZE_LOG2 12
+#define PRTB_SIZE_LOG2 24 /* Maximum process table size on POWER9 */
 #define PRTB_SIZE      (1UL << PRTB_SIZE_LOG2)
 
-static struct patb_entry
-    __aligned(PATB_SIZE) initial_patb[PATB_SIZE / sizeof(struct patb_entry)];
-
-static struct prtb_entry
-    __aligned(PRTB_SIZE) initial_prtb[PRTB_SIZE / sizeof(struct prtb_entry)];
+static struct patb_entry *initial_patb;
+static struct prtb_entry *initial_prtb;
 
 static __init struct lvl1_pd *lvl1_pd_pool_alloc(void)
 {
@@ -86,6 +82,62 @@ static __init struct lvl4_pt *lvl4_pt_pool_alloc(void)
     return &initial_lvl4_pt_pool[initial_lvl4_pt_pool_used++];
 }
 
+static void map_page_initial(struct lvl1_pd *lvl1, vaddr_t virt, paddr_t phys,
+                             unsigned long flags)
+{
+    struct lvl2_pd *lvl2;
+    struct lvl3_pd *lvl3;
+    struct lvl4_pt *lvl4;
+    pde_t *pde;
+    pte_t *pte;
+
+    /* Allocate LVL 2 PD if necessary */
+    pde = pt_entry(lvl1, virt);
+    if ( !pde_is_valid(*pde) )
+    {
+        lvl2 = lvl2_pd_pool_alloc();
+        *pde = paddr_to_pde(__pa(lvl2), PDE_VALID,
+                            XEN_PT_ENTRIES_LOG2_LVL_2);
+    }
+    else
+        lvl2 = __va(pde_to_paddr(*pde));
+
+    /* Allocate LVL 3 PD if necessary */
+    pde = pt_entry(lvl2, virt);
+    if ( !pde_is_valid(*pde) )
+    {
+        lvl3 = lvl3_pd_pool_alloc();
+        *pde = paddr_to_pde(__pa(lvl3), PDE_VALID,
+                            XEN_PT_ENTRIES_LOG2_LVL_3);
+    }
+    else
+        lvl3 = __va(pde_to_paddr(*pde));
+
+    /* Allocate LVL 4 PT if necessary */
+    pde = pt_entry(lvl3, virt);
+    if ( !pde_is_valid(*pde) )
+    {
+        lvl4 = lvl4_pt_pool_alloc();
+        *pde = paddr_to_pde(__pa(lvl4), PDE_VALID,
+                            XEN_PT_ENTRIES_LOG2_LVL_4);
+    }
+    else
+        lvl4 = __va(pde_to_paddr(*pde));
+
+    /* Finally, create PTE in LVL 4 PT */
+    pte = pt_entry(lvl4, virt);
+    if ( !pte_is_valid(*pte) )
+    {
+        radix_dprintk("%016lx being mapped to %016lx\n", phys, virt);
+        *pte = paddr_to_pte(phys, flags);
+    }
+    else
+    {
+        early_printk("BUG: Tried to create PTE for already-mapped page!");
+        die();
+    }
+}
+
 static void __init setup_initial_mapping(struct lvl1_pd *lvl1,
                                          vaddr_t map_start,
                                          vaddr_t map_end,
@@ -105,80 +157,43 @@ static void __init setup_initial_mapping(struct lvl1_pd *lvl1,
         die();
     }
 
+    /* Identity map Xen itself */
     for ( page_addr = map_start; page_addr < map_end; page_addr += PAGE_SIZE )
     {
-        struct lvl2_pd *lvl2;
-        struct lvl3_pd *lvl3;
-        struct lvl4_pt *lvl4;
-        pde_t *pde;
-        pte_t *pte;
-
-        /* Allocate LVL 2 PD if necessary */
-        pde = pt_entry(lvl1, page_addr);
-        if ( !pde_is_valid(*pde) )
-        {
-            lvl2 = lvl2_pd_pool_alloc();
-            *pde = paddr_to_pde(__pa(lvl2), PDE_VALID,
-                                XEN_PT_ENTRIES_LOG2_LVL_2);
-        }
-        else
-            lvl2 = __va(pde_to_paddr(*pde));
+        unsigned long flags;
 
-        /* Allocate LVL 3 PD if necessary */
-        pde = pt_entry(lvl2, page_addr);
-        if ( !pde_is_valid(*pde) )
+        if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr) )
         {
-            lvl3 = lvl3_pd_pool_alloc();
-            *pde = paddr_to_pde(__pa(lvl3), PDE_VALID,
-                                XEN_PT_ENTRIES_LOG2_LVL_3);
+            radix_dprintk("%016lx being marked as TEXT (RX)\n", page_addr);
+            flags = PTE_XEN_RX;
         }
-        else
-            lvl3 = __va(pde_to_paddr(*pde));
-
-        /* Allocate LVL 4 PT if necessary */
-        pde = pt_entry(lvl3, page_addr);
-        if ( !pde_is_valid(*pde) )
-        {
-            lvl4 = lvl4_pt_pool_alloc();
-            *pde = paddr_to_pde(__pa(lvl4), PDE_VALID,
-                                XEN_PT_ENTRIES_LOG2_LVL_4);
-        }
-        else
-            lvl4 = __va(pde_to_paddr(*pde));
-
-        /* Finally, create PTE in LVL 4 PT */
-        pte = pt_entry(lvl4, page_addr);
-        if ( !pte_is_valid(*pte) )
+        else if ( is_kernel_rodata(page_addr) )
         {
-            unsigned long paddr = (page_addr - map_start) + phys_base;
-            unsigned long flags;
-
-            radix_dprintk("%016lx being mapped to %016lx\n", paddr, page_addr);
-            if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr) )
-            {
-                radix_dprintk("%016lx being marked as TEXT (RX)\n", page_addr);
-                flags = PTE_XEN_RX;
-            }
-            else if ( is_kernel_rodata(page_addr) )
-            {
-                radix_dprintk("%016lx being marked as RODATA (RO)\n", page_addr);
-                flags = PTE_XEN_RO;
-            }
-            else
-            {
-                radix_dprintk("%016lx being marked as DEFAULT (RW)\n", page_addr);
-                flags = PTE_XEN_RW;
-            }
-
-            *pte = paddr_to_pte(paddr, flags);
-            radix_dprintk("%016lx is the result of PTE map\n",
-                paddr_to_pte(paddr, flags).pte);
+            radix_dprintk("%016lx being marked as RODATA (RO)\n", page_addr);
+            flags = PTE_XEN_RO;
         }
         else
         {
-            early_printk("BUG: Tried to create PTE for already-mapped page!");
-            die();
+            radix_dprintk("%016lx being marked as DEFAULT (RW)\n", page_addr);
+            flags = PTE_XEN_RW;
         }
+
+        map_page_initial(lvl1, page_addr, (page_addr - map_start) + phys_base, flags);
+    }
+
+    /* Map runtime-allocated PATB, PRTB */
+    for ( page_addr = (uint64_t)initial_patb;
+          page_addr < (uint64_t)initial_patb + PATB_SIZE;
+          page_addr += PAGE_SIZE )
+    {
+        map_page_initial(lvl1, page_addr, __pa(page_addr), PTE_XEN_RW);
+    }
+
+    for ( page_addr = (uint64_t)initial_prtb;
+          page_addr < (uint64_t)initial_prtb + PRTB_SIZE;
+          page_addr += PAGE_SIZE )
+    {
+        map_page_initial(lvl1, page_addr, __pa(page_addr), PTE_XEN_RW);
     }
 }
 
@@ -210,6 +225,16 @@ void __init setup_initial_pagetables(void)
 {
     struct lvl1_pd *root = lvl1_pd_pool_alloc();
     unsigned long lpcr;
+    mfn_t patb_mfn, prtb_mfn;
+
+    /* Allocate mfns for in-memory tables using the boot allocator */
+    prtb_mfn = alloc_boot_pages(PRTB_SIZE / PAGE_SIZE,
+                                max(1, PRTB_SIZE_LOG2 - PAGE_SHIFT));
+    patb_mfn = alloc_boot_pages(PATB_SIZE / PAGE_SIZE,
+                                max(1, PATB_SIZE_LOG2 - PAGE_SHIFT));
+
+    initial_patb = __va(mfn_to_maddr(patb_mfn));
+    initial_prtb = __va(mfn_to_maddr(prtb_mfn));
 
     setup_initial_mapping(root, (vaddr_t)_start, (vaddr_t)_end, __pa(_start));
 
Signature · 1 line
2.30.2
#14 lore raw
In reply to Shawn Anastasio
Quoted 16 lines · Shawn Anastasio

Hello all,

This series enables the Xen boot time allocator on Power by parsing the available memory regions from the firmware-provided device tree.

The device tree processing and bookkeeping code was adapted from Arm, but it was trimmed down to exclude code for parsing Arm-specific dt nodes.

Additionally, the final patch of the series updates the radix mmu code to use the newly-enabled boot allocator for the Partition and Process tables, instead of statically allocating them like was previously done. Among other things, switching to run-time allocation allows us to allocate a full-sized Process Table instead of the minimal one that was previously used to keep the Xen binary size small.

Quoted 4 lines

Thanks,

Shawn Anastasio (3):
xen/ppc: Enable Boot Allocator

A standalone patch with this title was sent earlier. What's their interrelation?

Jan

Quoted 14 lines

xen/ppc: mm-radix: Replace debug printing code with printk xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime

 xen/arch/ppc/Makefile            |   1 +
 xen/arch/ppc/bootfdt.c           | 507 +++++++++++++++++++++++++++++++
 xen/arch/ppc/include/asm/setup.h | 113 +++++++
 xen/arch/ppc/mm-radix.c          | 197 ++++++------
 xen/arch/ppc/setup.c             | 109 ++++++-
 5 files changed, 823 insertions(+), 104 deletions(-)
 create mode 100644 xen/arch/ppc/bootfdt.c

--
2.30.2

#15 lore raw

Hi Jan,

Quoted 3 lines · Jan Beulich

A standalone patch with this title was sent earlier. What's their interrelation?

I had intended to prefix this patch with 'RESEND' to clarify that it is the same as the one previously sent, but seem to have forgotten. My apologies! In any case, this patch will be superseded in v2 of the series.

Quoted 2 lines

Jan

Thanks,
Shawn