Early Boot Allocation on Power
v2 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.
As suggested during review of v1, this is now accomplished by moving Arm's bootfdt.c into xen/common, along with a few modifications to adapt it to Power -- namely to tolerate a device tree with no memory reserve map entries and to tolerate an FDT that overlaps with the a reserved memory region.
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
Shawn Anastasio (7):
xen/asm-generic: Introduce generic static-shmem.h xen/asm-generic: Introduce generic setup.h
xen/common: Move Arm's bootfdt to common xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions xen/ppc: Enable bootfdt and 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/arm/Makefile | 1 -
xen/arch/ppc/include/asm/Makefile | 1 +
xen/arch/ppc/include/asm/setup.h | 117 +++++++
xen/arch/ppc/mm-radix.c | 199 ++++++------
xen/arch/ppc/setup.c | 289 +++++++++++++++++-
xen/common/Makefile | 1 +
xen/common/device-tree/Makefile | 1 +
.../arm => common/device-tree}/bootfdt.c | 45 ++-
xen/include/asm-generic/setup.h | 148 +++++++++
xen/include/asm-generic/static-shmem.h | 12 +
10 files changed, 698 insertions(+), 116 deletions(-)
create mode 100644 xen/common/device-tree/Makefile
rename xen/{arch/arm => common/device-tree}/bootfdt.c (93%)
create mode 100644 xen/include/asm-generic/setup.h
create mode 100644 xen/include/asm-generic/static-shmem.h--
2.30.2
PATCH v2 2/7 xen/asm-generic: Introduce generic setup.h
Introduce setup.h to asm-generic based off of ARM's to define all stubs necessary to compile bootfdt.c
--- xen/arch/ppc/include/asm/Makefile | 1 + xen/arch/ppc/include/asm/setup.h | 6 -- xen/include/asm-generic/setup.h | 148 ++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 6 deletions(-) delete mode 100644 xen/arch/ppc/include/asm/setup.h create mode 100644 xen/include/asm-generic/setup.h
xen/arch/ppc/include/asm/Makefile +1 -0
@@ -6,5 +6,6 @@ generic-y += iocap.h generic-y += paging.h generic-y += percpu.h generic-y += random.h +generic-y += setup.h generic-y += static-shmem.h generic-y += vm_event.h
xen/arch/ppc/include/asm/setup.h deleted +0 -6
@@ -1,6 +0,0 @@ -#ifndef __ASM_PPC_SETUP_H__ -#define __ASM_PPC_SETUP_H__ - -#define max_init_domid (0) - -#endif /* __ASM_PPC_SETUP_H__ */
xen/include/asm-generic/setup.h new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v2 3/7 xen/common: Move Arm's bootfdt to common
In reply to Shawn AnastasioMove Arm's bootfdt.c to xen/common so that it can be used by other device tree architectures like PPC and RISCV. Only a minor change to conditionalize a call to a function only available on EFI-supporting targets was made to the code itself.
---
xen/arch/arm/Makefile | 1 -
xen/common/Makefile | 1 +
xen/common/device-tree/Makefile | 1 +
xen/{arch/arm => common/device-tree}/bootfdt.c | 15 +++++++++------
4 files changed, 11 insertions(+), 7 deletions(-)
create mode 100644 xen/common/device-tree/Makefile
rename xen/{arch/arm => common/device-tree}/bootfdt.c (98%)xen/arch/arm/Makefile +0 -1
@@ -10,7 +10,6 @@ obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o -obj-y += bootfdt.init.o obj-y += cpuerrata.o obj-y += cpufeature.o obj-y += decode.o
xen/common/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_UBSAN) += ubsan/ obj-$(CONFIG_NEEDS_LIBELF) += libelf/ obj-$(CONFIG_HAS_DEVICE_TREE) += libfdt/ +obj-$(CONFIG_HAS_DEVICE_TREE) += device-tree/ CONF_FILE := $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(objtree)/)$(KCONFIG_CONFIG) $(obj)/config.gz: $(CONF_FILE)
xen/common/device-tree/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += bootfdt.init.o
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +9 -6
@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ +if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif rc =process_memory_node (fdt, node, name, depth, address_cells, size_cells, &bootinfo.mem); else if ( depth == 1 && !dt_node_cmp(name, "reserved-memory") )
Signature · 1 line
2.30.2
PATCH v2 1/7 xen/asm-generic: Introduce generic static-shmem.h
In reply to Shawn AnastasioIntroduce static-shmem.h to asm-generic as a prerequisite for moving ARM's bootfdt.c into xen/common.
--- xen/arch/ppc/include/asm/Makefile | 1 + xen/include/asm-generic/static-shmem.h | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 xen/include/asm-generic/static-shmem.h
xen/arch/ppc/include/asm/Makefile +1 -0
@@ -6,4 +6,5 @@ generic-y += iocap.h generic-y += paging.h generic-y += percpu.h generic-y += random.h +generic-y += static-shmem.h generic-y += vm_event.h
xen/include/asm-generic/static-shmem.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_GENERIC_STATIC_SHMEM_H__ +#define __ASM_GENERIC_STATIC_SHMEM_H__ + +static inline int process_shm_node (const void *fdt,int node, +uint32_t address_cells,uint32_t size_cells) +{ +return -EINVAL ; +} + +#endif /* __ASM_GENERIC_STATIC_SHMEM_H__ */
Signature · 1 line
2.30.2
PATCH v2 7/7 xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime
In reply to Shawn AnastasioIn 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). Also bump the number of static LVL2/3 PD frames to tolerate cases where the boot allocator returns an address outside of the range of the LVL2 frame used for Xen.
---
Changes in v2:
- Bump LVL2/3 PD count to 3 to avoid running out in case the boot allocator returns a suitably high address.
xen/arch/ppc/mm-radix.c | 169 +++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 72 deletions(-)
xen/arch/ppc/mm-radix.c +97 -72
@@ -22,7 +22,7 @@ void enable_mmu(void);#endif #define INITIAL_LVL1_PD_COUNT 1 -#define INITIAL_LVL2_LVL3_PD_COUNT 2 +#define INITIAL_LVL2_LVL3_PD_COUNT 3#define INITIAL_LVL4_PT_COUNT 256static size_t __initdata initial_lvl1_pd_pool_used;
@@ -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));
--
2.30.2
PATCH v2 4/7 xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions
In reply to Shawn AnastasioThe early_print_info routine in bootfdt.c incorrectly stores the result of a call to fdt_num_mem_rsv() in an unsigned int, which results in the negative error code being interpreted incorrectly in a subsequent loop in the case where the device tree does not contain any memory reserve map entries.
--- xen/common/device-tree/bootfdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/common/device-tree/bootfdt.c +3 -2
@@ -466,7 +466,8 @@ static void __init early_print_info(void)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; +int nr_rsvd;for ( i =0 ; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
@@ -481,7 +482,7 @@ static void __init early_print_info(void) 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++ ) +for ( i =0 ; nr_rsvd >0 && i < nr_rsvd; i++ ) {paddr_t s, e;
Signature · 1 line
2.30.2
PATCH v2 6/7 xen/ppc: mm-radix: Replace debug printing code with printk
In reply to Shawn AnastasioNow 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
@@ -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
PATCH v2 5/7 xen/ppc: Enable bootfdt and boot allocator
In reply to Shawn AnastasioMove PPC off the asm-generic setup.h and enable usage of bootfdt for populating the boot info struct from the firmware-provided device tree. Also enable the Xen boot page allocator.
Includes minor changes to bootfdt.c's boot_fdt_info() to tolerate the scenario in which the FDT overlaps a reserved memory region, as is the case on PPC when booted directly from skiboot. Also includes a minor change to record Xen's correct position on PPC where Xen relocates itself to at the entrypoint.
--- xen/arch/ppc/include/asm/Makefile | 1 - xen/arch/ppc/include/asm/setup.h | 123 +++++++++++++ xen/arch/ppc/setup.c | 289 +++++++++++++++++++++++++++++- xen/common/device-tree/bootfdt.c | 25 ++- 4 files changed, 434 insertions(+), 4 deletions(-) create mode 100644 xen/arch/ppc/include/asm/setup.h
xen/arch/ppc/include/asm/Makefile +0 -1
@@ -6,6 +6,5 @@ generic-y += iocap.h generic-y += paging.h generic-y += percpu.h generic-y += random.h -generic-y += setup.h generic-y += static-shmem.h generic-y += vm_event.h
xen/arch/ppc/include/asm/setup.h new file +123 -0
123 lines not on this page · raw message
xen/arch/ppc/setup.c +288 -1
321 lines not on this page · raw message
xen/common/device-tree/bootfdt.c +23 -2
@@ -543,12 +543,33 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)if ( ret <0 )panic ("No valid device tree\n" ); -add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false); - ret =device_tree_for_each_node ((void *)fdt,0 , early_scan_node,NULL );if ( ret )panic ("Early FDT parsing failed (%d)\n" , ret); +/* +* Add module for the FDT itself after the device tree has been parsed. This +* is required on ppc64le where the device tree passed to Xen 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. +*/ +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. +*/ +if (IS_ENABLED (CONFIG_PPC64 ) ) { +paddr_t xen_start, xen_end; + + xen_start =__pa (_start); + xen_end =PAGE_ALIGN (__pa (_end)); +if ( !add_boot_module (BOOTMOD_XEN , xen_start, xen_end, false) ) +panic ("Xen overlaps reserved memory! %016lx - %016lx\n" , xen_start, + xen_end); + } +/* * 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
Signature · 1 line
2.30.2
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Shawn AnastasioQuoted 7 lines · Shawn Anastasio
Move Arm's
bootfdt.cto xen/common so that it can be used by other device tree architectures like PPC and RISCV. Only a minor change to conditionalize a call to a function only available on EFI-supporting targets was made to the code itself.Suggested-by Julien Grall <[email protected]>Signed-off-by Shawn Anastasio <[email protected]>
Quoted 8 lines
---
xen/arch/arm/Makefile | 1 -
xen/common/Makefile | 1 +
xen/common/device-tree/Makefile | 1 +
xen/{arch/arm => common/device-tree}/bootfdt.c | 15 +++++++++------
4 files changed, 11 insertions(+), 7 deletions(-)
create mode 100644 xen/common/device-tree/Makefile
rename xen/{arch/arm => common/device-tree}/bootfdt.c (98%)I think this wants to come with an update to ./MAINTAINERS, such that the file doesn't change maintainership.
Quoted 11 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +0
-5@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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) &&
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 10 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +9
-1- device_tree_node_matches(fdt, node, "memory") ) + if ( device_tree_node_matches(fdt, node, "memory") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ +if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif
I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Jan
Re: [PATCH v2 1/7] xen/asm-generic: Introduce generic static-shmem.h
In reply to Shawn Anastasioxen/include/asm-generic/static-shmem.h line 10
Quoted 13 lines · Shawn Anastasio
xen/include/asm-generic/static-shmem.h new file +10
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_GENERIC_STATIC_SHMEM_H__ +#define __ASM_GENERIC_STATIC_SHMEM_H__ + +static inline int process_shm_node (const void *fdt,int node, +uint32_t address_cells,uint32_t size_cells) +{ +return -EINVAL ; +}
This talking of fdt and cells doesn't look very generic to me, I'm afraid. Plus if such a header was introduced, I'd kind of expect it to also be used by Arm's !CONFIG_STATIC_SHM section - no need to duplicate anything.
Jan
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Jan BeulichHi Jan,
Quoted 38 lines · Jan Beulich
Quoted 7 lines · Shawn Anastasio
Move Arm's
bootfdt.cto xen/common so that it can be used by other device tree architectures like PPC and RISCV. Only a minor change to conditionalize a call to a function only available on EFI-supporting targets was made to the code itself.Suggested-by Julien Grall <[email protected]>Signed-off-by Shawn Anastasio <[email protected]>Quoted 8 lines
--- xen/arch/arm/Makefile | 1 - xen/common/Makefile | 1 + xen/common/device-tree/Makefile | 1 + xen/{arch/arm => common/device-tree}/bootfdt.c | 15 +++++++++------ 4 files changed, 11 insertions(+), 7 deletions(-)create mode 100644 xen/common/device-tree/Makefile rename xen/{arch/arm =>
common/device-tree}/bootfdt.c(98%)I think this wants to come with an update to ./MAINTAINERS, such that the file doesn't change maintainership.
Quoted 18 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/
Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
However, we don't have a CONFIG_EFI option. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 2/7] xen/asm-generic: Introduce generic setup.h
In reply to Shawn AnastasioQuoted 2 lines · Shawn Anastasio
Introduce
setup.hto asm-generic based off of ARM's to define all stubs necessary to compilebootfdt.c
And - I'm sorry to ask - how's that "generic"? I'm also not convinced at all that a generic header can validly use BUG() in the way you propose. Some of these go far beyond what presently we have in e.g. altp2m_vcpu_idx().
Jan
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Julien GrallQuoted 29 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Quoted 6 lines
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
However, we don't have a
CONFIG_EFIoption. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.
Right, hence why I also wasn't suggesting to go that route right away. efi/common-stub.c already has a stub for efi_enabled(). Using that file may be too involved to arrange for in PPC, but supplying such a stub elsewhere for the time being looks like it wouldn't too much effort (and would eliminate the need for any #ifdef here afaict). Shawn?
Jan
Re: [PATCH v2 2/7] xen/asm-generic: Introduce generic setup.h
In reply to Shawn AnastasioQuoted 17 lines · Shawn Anastasio
Introduce
setup.hto asm-generic based off of ARM's to define all stubs necessary to compilebootfdt.cSigned-off-by Shawn Anastasio <[email protected]>--- xen/arch/ppc/include/asm/Makefile | 1 + xen/arch/ppc/include/asm/setup.h | 6 -- xen/include/asm-generic/setup.h | 148 ++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 6 deletions(-) delete mode 100644 xen/arch/ppc/include/asm/setup.h create mode 100644 xen/include/asm-generic/setup.hxen/arch/ppc/include/asm/Makefile +0
-0
xen/arch/ppc/include/asm/Makefile generic-y += iocap.h · line 11
Quoted 6 lines
xen/arch/ppc/include/asm/Makefile +1
-0@@ -6,5 +6,6 @@ generic-y += iocap.h generic-y += paging.h generic-y += percpu.h generic-y += random.h +generic-y += setup.h generic-y += static-shmem.h generic-y += vm_event.h
Looking at patch 5, you undo this there. Why introduce it in the first place then? And why leave a stale (unused) file around there?
Jan
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Shawn AnastasioQuoted 61 lines · Shawn Anastasio
xen/arch/ppc/include/asm/setup.h new file +58
-0@@ -0,0 +1,123 @@ +#ifndef __ASM_PPC_SETUP_H__ +#define __ASM_PPC_SETUP_H__ + +#define max_init_domid (0) + +#include <public/version.h> +#include <asm/p2m.h> +#include <xen/device_tree.h> + +#define MIN_FDT_ALIGN 8 +#define MAX_FDT_SIZE SZ_2M + +#define NR_MEM_BANKS 256 + +#define MAX_MODULES 32 /* Current maximum useful modules */ + +typedef enum { + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_GUEST_DTB, + BOOTMOD_UNKNOWN +} bootmodule_kind; + +enum membank_type { + /* + * The MEMBANK_DEFAULT type refers to either reserved memory for the + * device/firmware (when the bank is in 'reserved_mem') or any RAM (when + * the bank is in 'mem'). + */ + MEMBANK_DEFAULT, + /* + * The MEMBANK_STATIC_DOMAIN type is used to indicate whether the memory + * bank is bound to a static Xen domain. It is only valid when the bank + * is in reserved_mem. + */ + MEMBANK_STATIC_DOMAIN, + /* + * The MEMBANK_STATIC_HEAP type is used to indicate whether the memory + * bank is reserved as static heap. It is only valid when the bank is + * in reserved_mem. + */ + MEMBANK_STATIC_HEAP, +}; + +/* Indicates the maximum number of characters(\0 included) for shm_id */ +#define MAX_SHM_ID_LENGTH 16 + +struct membank { + paddr_t start; + paddr_t size; + enum membank_type type; +}; + +struct meminfo { + unsigned int nr_banks;
xen/arch/ppc/include/asm/setup.h line 68
Quoted 10 lines
xen/arch/ppc/include/asm/setup.h new file +10
-0+struct membank bank[NR_MEM_BANKS ]; +}; + +/* +* The domU flag is set for kernels and ramdisks of "xen,domain" nodes. +* The purpose of the domU flag is to avoid getting confused in +* kernel_probe, where we try to guess which is the dom0 kernel and +* initrd to be compatible with all versions of the multiboot spec. +*/ +#define BOOTMOD_MAX_CMDLINE 1024
Why does this live here, rather than ...
xen/arch/ppc/include/asm/setup.h line 77
Quoted 9 lines
xen/arch/ppc/include/asm/setup.h new file +9
-0+struct bootmodule { +bootmodule_kind kind; +bool domU; +paddr_t start; +paddr_t size; +}; + +/* DT_MAX_NAME is the node name max length according the DT spec */ +#define DT_MAX_NAME 41
... next to this?
Quoted 14 lines
xen/arch/ppc/include/asm/setup.h new file +14
-0+struct bootcmdline { +bootmodule_kind kind; +bool domU; +paddr_t start; +char dt_name[DT_MAX_NAME ]; +char cmdline[BOOTMOD_MAX_CMDLINE ]; +}; + +struct bootmodules { +int nr_mods; +struct bootmodule module[MAX_MODULES ]; +}; + +struct bootcmdlines {
xen/arch/ppc/include/asm/setup.h line 101
Quoted 10 lines
xen/arch/ppc/include/asm/setup.h new file +10
-0+unsigned int nr_mods; +struct bootcmdline cmdline[MAX_MODULES ]; +}; + +struct bootinfo { +struct meminfo mem; +struct meminfo reserved_mem; +struct bootmodules modules; +struct bootcmdlines cmdlines; +bool static_heap;
Unused field?
Quoted 5 lines
xen/arch/ppc/include/asm/setup.h new file +5
-0+}; + +extern struct bootinfo bootinfo; + +/*
xen/arch/ppc/include/asm/setup.h line 116
Quoted 10 lines
xen/arch/ppc/include/asm/setup.h new file +10
-0+* setup.c +*/ + +bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size); +struct bootmodule *add_boot_module (bootmodule_kind kind, +paddr_t start,paddr_t size,bool domU); +void add_boot_cmdline (const char *name,const char *cmdline, +bootmodule_kind kind,paddr_t start,bool domU); +const char *boot_module_kind_as_string (bootmodule_kind kind); +struct bootcmdline *__init boot_cmdline_find_by_kind (bootmodule_kind kind);
No __init please on declarations; section placement attributes make sense only on definitions (with pretty narrow exceptions).
Quoted 60 lines
xen/arch/ppc/setup.c +44
-0@@ -1,16 +1,296 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <xen/init.h> #include <xen/lib.h> +#include <xen/libfdt/libfdt.h> #include <xen/mm.h> #include <public/version.h> #include <asm/boot.h> #include <asm/early_printk.h> #include <asm/mm.h> #include <asm/processor.h> +#include <asm/setup.h> /* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]__aligned(STACK_SIZE) ; +struct bootinfo __initdata bootinfo; + +void __init add_boot_cmdline (const char *name,const char *cmdline, +bootmodule_kind kind,paddr_t start,bool domU) +{ +struct bootcmdlines *cmds = &bootinfo.cmdlines; +struct bootcmdline *cmd; + +if ( cmds->nr_mods ==MAX_MODULES ) + { +printk ("Ignoring %s cmdline (too many)\n" , name); +return ; + } + + cmd = &cmds->cmdline[cmds->nr_mods++]; + cmd->kind = kind; + cmd->domU = domU; + cmd->start = start; + +ASSERT (strlen (name) <=DT_MAX_NAME ); +safe_strcpy (cmd->dt_name, name); + +if (strlen (cmdline) >BOOTMOD_MAX_CMDLINE ) +panic ("module %s command line too long\n" , name); +safe_strcpy (cmd->cmdline, cmdline); +} + +struct bootmodule __init *add_boot_module (bootmodule_kind kind, +paddr_t start,paddr_t size, +bool domU) +{ +struct bootmodules *mods = &bootinfo.modules; +struct bootmodule *mod; +unsigned int i; + +if ( mods->nr_mods ==MAX_MODULES ) + { +printk ("Ignoring %s boot module at %" PRIpaddr"-%" PRIpaddr" (too many)\n" , +boot_module_kind_as_string (kind), start, start + size); +return NULL ; + } +
xen/arch/ppc/setup.c line 67
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+if (check_reserved_regions_overlap (start, size) ) +return NULL ; + +for ( i =0 ; i < mods->nr_mods ; i++ ) + { + mod = &mods->module[i]; +if ( mod->kind == kind && mod->start == start ) + { +if ( !domU ) + mod->domU = false;
What's the intention behind this (negative) accumulation of "domU"?
xen/arch/ppc/setup.c line 70
Quoted 3 lines
xen/arch/ppc/setup.c +3
-0+return mod; + } + }
And what's the intention behind checking existing modules here (but not existing command lines higher up in add_boot_cmdline())?
Quoted 19 lines
xen/arch/ppc/setup.c +19
-0+ mod = &mods->module[mods->nr_mods++]; + mod->kind = kind; + mod->start = start; + mod->size = size; + mod->domU = domU; + +return mod; +} + +const char *__init boot_module_kind_as_string (bootmodule_kind kind) +{ +switch ( kind ) + { +case BOOTMOD_XEN :return "Xen" ; +case BOOTMOD_FDT :return "Device Tree" ; +case BOOTMOD_KERNEL :return "Kernel" ; +default :BUG (); + } +}
xen/arch/ppc/setup.c line 100
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+ +/* +* TODO: '*_end' could be 0 if the module/region is at the end of the physical +* address space. This is for now not handled as it requires more rework. +*/ +static bool __init bootmodules_overlap_check (struct bootmodules *bootmodules, +paddr_t region_start, +paddr_t region_size) +{ +paddr_t mod_start =INVALID_PADDR , mod_end =0 ;
Pointless initializers? (The variables might benefit from moving into the more narrow scope anyway.)
xen/arch/ppc/setup.c line 111
Quoted 11 lines
xen/arch/ppc/setup.c +11
-0+paddr_t region_end = region_start + region_size; +unsigned int i, mod_num = bootmodules->nr_mods; + +for ( i =0 ; i < mod_num; i++ ) + { + mod_start = bootmodules->module[i].start; + mod_end = mod_start + bootmodules->module[i].size; + +if ( region_end <= mod_start || region_start >= mod_end ) +continue ; +else
I for one consider such an "else" misleading.
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+ { +printk ("Region: [%#" PRIpaddr", %#" PRIpaddr") overlapping with" +" mod[%u]: [%#" PRIpaddr", %#" PRIpaddr")\n" , region_start, + region_end, i, mod_start, mod_end); +return true; + } + } + +return false; +}
xen/arch/ppc/setup.c line 131
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+ +/* +* TODO: '*_end' could be 0 if the bank/region is at the end of the physical +* address space. This is for now not handled as it requires more rework. +*/ +static bool __init meminfo_overlap_check (struct meminfo *meminfo, +paddr_t region_start, +paddr_t region_size) +{ +paddr_t bank_start =INVALID_PADDR , bank_end =0 ;
As above: Pointless initializers? (The variables might benefit from moving into the more narrow scope anyway.)
Quoted 5 lines
xen/arch/ppc/setup.c +5
-0+paddr_t region_end = region_start + region_size; +unsigned int i, bank_num = meminfo->nr_banks; + +for ( i =0 ; i < bank_num; i++ ) + {
xen/arch/ppc/setup.c line 146
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+ bank_start = meminfo->bank[i].start; + bank_end = bank_start + meminfo->bank[i].size; + +if ( region_end <= bank_start || region_start >= bank_end ) +continue ; +else + { +printk ("Region: [%#" PRIpaddr", %#" PRIpaddr") overlapping with" +" bank[%u]: [%#" PRIpaddr", %#" PRIpaddr")\n" , region_start, + region_end, i, bank_start, bank_end);
I think this is confusing to read: When the format string already needs wrapping, I don't think the next argument should be put on the same line. I was almost going to complain that arguments don't fit the format string.
Quoted 22 lines
xen/arch/ppc/setup.c +22
-0+return true; + } + } + +return false; +} + +/* +* Given an input physical address range, check if this range is overlapping +* with the existing reserved memory regions defined in bootinfo. +* Return true if the input physical address range is overlapping with any +* existing reserved memory regions, otherwise false. +*/ +bool __init check_reserved_regions_overlap (paddr_t region_start, +paddr_t region_size) +{ +/* Check if input region is overlapping with bootinfo.reserved_mem banks */ +if (meminfo_overlap_check (&bootinfo.reserved_mem, + region_start, region_size) ) +return true; + +/* Check if input region is overlapping with bootmodules */
xen/arch/ppc/setup.c line 178
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+if (bootmodules_overlap_check (&bootinfo.modules, + region_start, region_size) ) +return true; + +return false; +} + +/* +* Return the end of the non-module region starting at s. In other +* words return s the start of the next modules after s.
Stray " s" after "return"?
xen/arch/ppc/setup.c line 186
Quoted 7 lines
xen/arch/ppc/setup.c +7
-0+* On input *end is the end of the region which should be considered +* and it is updated to reflect the end of the module, clipped to the +* end of the region if it would run over. +*/ +static paddr_t __init next_module (paddr_t s,paddr_t *end) +{ +struct bootmodules *mi = &bootinfo.modules;
const?
xen/arch/ppc/setup.c line 186
Quoted 2 lines
xen/arch/ppc/setup.c +2
-0+paddr_t lowest = ~(paddr_t )0 ; +int i;
unsigned int?
Quoted 25 lines
xen/arch/ppc/setup.c +25
-0+for ( i =0 ; i < mi->nr_mods; i++ ) + { +paddr_t mod_s = mi->module[i].start; +paddr_t mod_e = mod_s + mi->module[i].size; + +if ( !mi->module[i].size ) +continue ; + +if ( mod_s < s ) +continue ; +if ( mod_s > lowest ) +continue ; +if ( mod_s > *end ) +continue ; + lowest = mod_s; + *end =min (*end, mod_e); + } +return lowest; +} + +static void __init dt_unreserved_regions (paddr_t s,paddr_t e, +void (*cb)(paddr_t ps,paddr_t pe), +unsigned int first) +{ +unsigned int i;
xen/arch/ppc/setup.c line 224
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+ +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +paddr_t r_s = bootinfo.reserved_mem.bank[i].start; +paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i].size; + +if ( s < r_e && r_s < e ) + { +dt_unreserved_regions (r_e, e, cb, i +1 ); +dt_unreserved_regions (s, r_s, cb, i +1 );
What's the reason for this recursion? Can there be overlapping regions? If so, is there a guaranteed depth limit (seeing in particular that you're not using the last function parameter)?
xen/arch/ppc/setup.c line 237
Quoted 13 lines
xen/arch/ppc/setup.c +13
-0+return ; + } + } + +cb (s, e); +} + +/* +* boot_cmdline_find_by_kind can only be used to return Xen modules (e.g +* XSM, DTB) or Dom0 modules. This is not suitable for looking up guest +* modules. +*/ +struct bootcmdline *__init boot_cmdline_find_by_kind (bootmodule_kind kind)
This function looks to be unused?
xen/arch/ppc/setup.c line 241
Quoted 4 lines
xen/arch/ppc/setup.c +4
-0+{ +struct bootcmdlines *cmds = &bootinfo.cmdlines; +struct bootcmdline *cmd; +int i;
unsigned int?
Quoted 16 lines
xen/arch/ppc/setup.c +16
-0+for ( i =0 ; i < cmds->nr_mods ; i++ ) + { + cmd = &cmds->cmdline[i]; +if ( cmd->kind == kind && !cmd->domU ) +return cmd; + } +return NULL ; +} + +/* +* Populate the boot allocator. Based on arch/arm/setup.c's +* populate_boot_allocator. +* All RAM but the following regions will be added to the boot allocator: +* - Modules (e.g., Xen, Kernel) +* - Reserved regions +*/
xen/arch/ppc/setup.c line 268
Quoted 10 lines
xen/arch/ppc/setup.c +10
-0+static void __init populate_boot_allocator (void ) +{ +unsigned int i; +const struct meminfo *banks = &bootinfo.mem; +paddr_t s, e; + +for ( i =0 ; i < banks->nr_banks; i++ ) + { +const struct membank *bank = &banks->bank[i]; +paddr_t bank_end = bank->start + bank->size;
Since you already make use of inner scope variables, and reason not to put s here and ...
xen/arch/ppc/setup.c line 273
Quoted 4 lines
xen/arch/ppc/setup.c +4
-0+ s = bank->start; +while ( s < bank_end ) + { +paddr_t n = bank_end;
... e even here (each then gaining an initializer as well)?
xen/arch/ppc/setup.c line 282
Quoted 8 lines
xen/arch/ppc/setup.c +8
-0+ e =next_module (s, &n); + +if ( e == ~(paddr_t )0 ) + e = n = bank_end; + +/* +* Module in a RAM bank other than the one which we are +* not dealing with here.
Nit: "not"?
Quoted 15 lines
xen/arch/ppc/setup.c +11
-0+*/ +if ( e > bank_end ) + e = bank_end; + +dt_unreserved_regions (s, e, init_boot_pages,0 ); + + s = n; + } + } +} +void setup_exceptions (void ) {unsigned long lpcr;
xen/arch/ppc/setup.c void __init noreturn start_xen(unsigned long r3, unsigned long r4, · line 307
Quoted 4 lines
xen/arch/ppc/setup.c +1
-0@@ -24,6 +304,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6, unsigned long r7) { + void *boot_fdt;
const?
xen/arch/ppc/setup.c void __init noreturn start_xen(unsigned long r3, unsigned long r4, · line 317
Quoted 6 lines
xen/arch/ppc/setup.c +1
-1@@ -32,11 +314,16 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,else {/* kexec boot protocol */ -boot_opal_init ((void *)r3); + boot_fdt = (void *)r3;
And then here as well, to avoid Misra complaints.
Quoted 28 lines
xen/arch/ppc/setup.c +5
-0+boot_opal_init (boot_fdt); }setup_exceptions (); +boot_fdt_info (boot_fdt, r3); + +populate_boot_allocator (); +setup_initial_pagetables ();early_printk ("Hello, ppc64le!\n" );xen/common/device-tree/bootfdt.c +4
-2@@ -543,12 +543,33 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)if ( ret <0 )panic ("No valid device tree\n" ); -add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false); - ret =device_tree_for_each_node ((void *)fdt,0 , early_scan_node,NULL );if ( ret )panic ("Early FDT parsing failed (%d)\n" , ret); +/* +* Add module for the FDT itself after the device tree has been parsed. This +* is required on ppc64le where the device tree passed to Xen may have been +* allocated by skiboot, in which case it will exist within a reserved
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 563
Quoted 10 lines
xen/common/device-tree/bootfdt.c +10
-0+* region and this call will fail. This is fine, however, since either way +* the allocator will know not to step on the device tree. +*/ +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. +*/ +if (IS_ENABLED (CONFIG_PPC64 ) ) {
Nit (style): Brace placement.
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 571
Quoted 8 lines
xen/common/device-tree/bootfdt.c +8
-0+paddr_t xen_start, xen_end; + + xen_start =__pa (_start); + xen_end =PAGE_ALIGN (__pa (_end)); +if ( !add_boot_module (BOOTMOD_XEN , xen_start, xen_end, false) ) +panic ("Xen overlaps reserved memory! %016lx - %016lx\n" , xen_start, + xen_end); + }
I'll need to leave commenting on this to the DT maintainers.
Jan
Re: [PATCH v2 6/7] xen/ppc: mm-radix: Replace debug printing code with printk
In reply to Shawn AnastasioQuoted 4 lines · Shawn Anastasio
Now that we have common code building, there's no need to keep the old itoa64+debug print function in
mm-radix.cSigned-off-by Shawn Anastasio <[email protected]>
Looks okay, just one question:
xen/arch/ppc/mm-radix.c line 22
Quoted 11 lines
xen/arch/ppc/mm-radix.c +5
-0@@ -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
Do you really mean NDEBUG here, and not CONFIG_DEBUG? NDEBUG is generally supposed to only control ASSERT() behavior.
Jan
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Shawn AnastasioHi,
Quoted 10 lines · Shawn Anastasio
Move PPC off the asm-generic
setup.hand enable usage of bootfdt for populating the boot info struct from the firmware-provided device tree. Also enable the Xen boot page allocator.Includes minor changes to bootfdt.c's
boot_fdt_info()to tolerate the scenario in which the FDT overlaps a reserved memory region, as is the case on PPC when booted directly from skiboot. Also includes a minor change to record Xen's correct position on PPC where Xen relocates itself to at the entrypoint.
Quoted 5 lines
Signed-off-by Shawn Anastasio <[email protected]>--- xen/arch/ppc/include/asm/Makefile | 1 - xen/arch/ppc/include/asm/setup.h | 123 +++++++++++++ xen/arch/ppc/setup.c | 289 +++++++++++++++++++++++++++++-
I might be missing something. But isn't most of the code you add is the same as Arm? And if so, shouldn't this be consolidated?
I would also expect RISC-V to need the same.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Shawn AnastasioHi,
Quoted 12 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c +0
-2@@ -543,12 +543,33 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)if ( ret <0 )panic ("No valid device tree\n" ); -add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false); - ret =device_tree_for_each_node ((void *)fdt,0 , early_scan_node,NULL );if ( ret )
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 557
Quoted 10 lines
xen/common/device-tree/bootfdt.c +8
-0panic ("Early FDT parsing failed (%d)\n" , ret); +/* +* Add module for the FDT itself after the device tree has been parsed. This +* is required on ppc64le where the device tree passed to Xen 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. +*/ +add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false);
The consequence is BOOTMOD_FDT will not be added. AFAICT, Arm doesn't try to access BOOTMOD_FDT, but I think it would be worth to print message.
Quoted 4 lines
xen/common/device-tree/bootfdt.c +4
-0+ +/* +* Xen relocates itself at the ppc64 entrypoint, so we need to manually mark +* the kernel module.
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 571
Quoted 10 lines
xen/common/device-tree/bootfdt.c +10
-0+*/ +if (IS_ENABLED (CONFIG_PPC64 ) ) { +paddr_t xen_start, xen_end; + + xen_start =__pa (_start); + xen_end =PAGE_ALIGN (__pa (_end)); +if ( !add_boot_module (BOOTMOD_XEN , xen_start, xen_end, false) ) +panic ("Xen overlaps reserved memory! %016lx - %016lx\n" , xen_start, + xen_end); + }
Can you explain why this is added here rather than in the caller of boot_fdt_info()? Either before or after?
If after, I guess it is because of early_print_info(). In which case, I would suggest to move off early_print_info() to caller on each architecture.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Shawn AnastasioHi Shawn,
Quoted 6 lines · Shawn Anastasio
Move Arm's
bootfdt.cto xen/common so that it can be used by other device tree architectures like PPC and RISCV. Only a minor change to conditionalize a call to a function only available on EFI-supporting targets was made to the code itself. >Suggested-by Julien Grall <[email protected]>Signed-off-by Shawn Anastasio <[email protected]>
With the MAINTAINERS file updated (I would add under DEVICE TREE) and one note below:
Quoted 4 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +0
-0@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 435
Quoted 10 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +2
-6int 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") ) +#if defined(CONFIG_ARM_EFI )
As discussed in a separate subthread, I would be ok with any of the options proposed. So feel free ot keep my Acked-by once this is settled.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Julien GrallHi Shawn,
Quoted 13 lines · Julien Grall
Hi,
Quoted 10 lines · Shawn Anastasio
Move PPC off the asm-generic
setup.hand enable usage of bootfdt for populating the boot info struct from the firmware-provided device tree. Also enable the Xen boot page allocator.Includes minor changes to bootfdt.c's
boot_fdt_info()to tolerate the scenario in which the FDT overlaps a reserved memory region, as is the case on PPC when booted directly from skiboot. Also includes a minor change to record Xen's correct position on PPC where Xen relocates itself to at the entrypoint.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Shawn Anastasio <[email protected]>---
xen/arch/ppc/include/asm/Makefile | 1 - xen/arch/ppc/include/asm/setup.h | 123 +++++++++++++ xen/arch/ppc/setup.c | 289 +++++++++++++++++++++++++++++-I might be missing something. But isn't most of the code you add is the same as Arm? And if so, shouldn't this be consolidated?
So I have create a new file and move the PPC functions I think should be the same. Then I replace with the Arm code. Below the diff.
Looking through it, I can't see why the code cannot be shared in except part of populate_boot_allocator() (which could be split).
I forsee that some of the code you remove will be necessary (e.g. BOOTMOD_RAMDISK, BOOTMOD_XSM). And some of the style change doesn't match what we do in Xen (messages are not split).
If there are common bits with other architectures, then I would really like if they are shared rather than duplicated. I am more than happy to help finding a good split because it will reduce maintenance effort for everyone in the longer run.
Cheers,
xen/common/device-tree/setup.c +14 -6
@@ -70,6 +70,10 @@ const char * __init boot_module_kind_as_string(bootmodule_kind kind)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 (); } }
@@ -95,9 +99,8 @@ static bool __init bootmodules_overlap_check(struct bootmodules *bootmodules,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; } }
@@ -126,9 +129,8 @@ static bool __init meminfo_overlap_check(struct meminfo *meminfo,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; } }
@@ -155,6 +157,12 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, 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; }
@@ -196,12 +204,47 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, void (*cb)(paddr_t ps,
paddr_t pe),
unsigned int first)
{
- unsigned int i; + unsigned int i, nr; + int rc;
+
+ rc = fdt_num_mem_rsv(device_tree_flattened);
+ if ( rc < 0 )
+ panic("Unable to retrieve the number of reserved regions (rc=%d)\n",
+ rc);
- for ( i = 0 ; i < bootinfo.reserved_mem.nr_banks; i++ )
+ nr = rc;
+
+ for ( i = first; i < nr ; i++ )
{
- paddr_t r_s = bootinfo.reserved_mem.bank[i].start;
- paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i].size;
+ paddr_t r_s, r_e;+
+ if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &r_s, &r_e ) < 0 )
+ /* If we can't read it, pretend it doesn't exist... */
+ continue;
+
+ r_e += r_s; /* fdt_get_mem_rsv_paddr returns length */
+
+ if ( s < r_e && r_s < e )
+ {
+ dt_unreserved_regions(r_e, e, cb, i+1); + dt_unreserved_regions(s, r_s, cb, i+1); + return;
+ }
+ }
+
+ /*
+ * i is the current bootmodule we are evaluating across all possible + * kinds. + * + * When retrieving the corresponding reserved-memory addresses + * below, we need to index the bootinfo.reserved_mem bank starting + * from 0, and only counting the reserved-memory modules. Hence, + * we need to use i - nr. + */
+ for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ )
+ {
+ paddr_t r_s = bootinfo.reserved_mem.bank[i - nr].start;
+ paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i - nr].size;
if ( s < r_e && r_s < e )
{
@@ -214,6 +257,16 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e,
cb(s, e);}
+void __init fw_unreserved_regions(paddr_t s, paddr_t e,
+ void (*cb)(paddr_t ps, paddr_t pe),
+ unsigned int first)
+{
+ if ( acpi_disabled )
+ dt_unreserved_regions(s, e, cb, first);
+ else
+ cb(s, e);
+}
+
/*
* boot_cmdline_find_by_kind can only be used to return Xen modules (e.g
* XSM, DTB) or Dom0 modules. This is not suitable for looking up guest
@@ -235,18 +288,47 @@ struct bootcmdline * __init boot_cmdline_find_by_kind(bootmodule_kind kind)
}
/*
- * Populate the boot allocator. Based on arch/arm/setup.c's
- * populate_boot_allocator.
- * All RAM but the following regions will be added to the boot allocator:
+ * Populate the boot allocator.
+ * If a static heap was not provided by the admin, all the RAM but the
+ * following regions will be added:
* - Modules (e.g., Xen, Kernel) * - Reserved regions + * - Xenheap (arm32 only)
+ * If a static heap was provided by the admin, populate the boot
+ * allocator with the corresponding regions only, but with Xenheap excluded
+ * on arm32.
*/
-static void __init populate_boot_allocator(void)
+void __init populate_boot_allocator(void)
{
unsigned int i;
const struct meminfo *banks = &bootinfo.mem;
paddr_t s, e;+ if ( bootinfo.static_heap )
+ {
+ for ( i = 0 ; i < bootinfo.reserved_mem.nr_banks; i++ )
+ {
+ if ( bootinfo.reserved_mem.bank[i].type != MEMBANK_STATIC_HEAP )
+ continue;
+
+ s = bootinfo.reserved_mem.bank[i].start;
+ e = s + bootinfo.reserved_mem.bank[i].size;
+#ifdef CONFIG_ARM_32
+ /* Avoid the xenheap, note that the xenheap cannot across a bank */
+ if ( s <= mfn_to_maddr(directmap_mfn_start) &&
+ e >= mfn_to_maddr(directmap_mfn_end) )
+ {
+ init_boot_pages(s, mfn_to_maddr(directmap_mfn_start));
+ init_boot_pages(mfn_to_maddr(directmap_mfn_end), e);
+ }
+ else
+#endif
+ init_boot_pages(s, e);
+ }
+
+ return;
+ }
+
for ( i = 0; i < banks->nr_banks; i++ )
{
const struct membank *bank = &banks->bank[i];@@ -269,11 +351,18 @@ static void __init populate_boot_allocator(void)
if ( e > bank_end )
e = bank_end;
- dt_unreserved_regions(s, e, init_boot_pages, 0);
-
+#ifdef CONFIG_ARM_32
+ /* Avoid the xenheap */
+ if ( s < mfn_to_maddr(directmap_mfn_end) &&
+ mfn_to_maddr(directmap_mfn_start) < e )
+ {
+ e = mfn_to_maddr(directmap_mfn_start);
+ n = mfn_to_maddr(directmap_mfn_end);
+ }
+#endif
+
+ fw_unreserved_regions(s, e, init_boot_pages, 0);
s = n;
}
} }
-
-
Quoted 5 lines
I would also expect RISC-V to need the same.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 2/7] xen/asm-generic: Introduce generic setup.h
In reply to Jan BeulichHi Jan,
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Shawn Anastasio
Introduce
setup.hto asm-generic based off of ARM's to define all stubs necessary to compilebootfdt.cSigned-off-by Shawn Anastasio <[email protected]>--- xen/arch/ppc/include/asm/Makefile | 1 + xen/arch/ppc/include/asm/setup.h | 6 -- xen/include/asm-generic/setup.h | 148 ++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 6 deletions(-) delete mode 100644 xen/arch/ppc/include/asm/setup.h create mode 100644 xen/include/asm-generic/setup.h
Quoted 15 lines
xen/arch/ppc/include/asm/Makefile generic-y += iocap.h · line 11
Quoted 11 lines
xen/arch/ppc/include/asm/Makefile +1
-0@@ -6,5 +6,6 @@ generic-y += iocap.h generic-y += paging.h generic-y += percpu.h generic-y += random.h +generic-y += setup.h generic-y += static-shmem.h generic-y += vm_event.hLooking at patch 5, you undo this there. Why introduce it in the first place then? And why leave a stale (unused) file around there?
The intent was to leave the file around for RISC-V, since now xen/common won't build when CONFIG_HAS_DEVICE tree is set unless these headers are available with sufficient definitions.
Given your earlier comment about these not being exactly generic (which I agree with, they are closer to stubs if anything), I suppose I'll just drop both of these headers going forward and let RISC-V handle the new changes required to get common/ building.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Jan BeulichQuoted 34 lines · Jan Beulich
Quoted 33 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
Quoted 9 lines
Quoted 2 lines
However, we don't have a
CONFIG_EFIoption. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.Right, hence why I also wasn't suggesting to go that route right away.
efi/common-stub.calready has a stub forefi_enabled(). Using that file may be too involved to arrange for in PPC, but supplying such a stub elsewhere for the time being looks like it wouldn't too much effort (and would eliminate the need for any #ifdef here afaict). Shawn?
To clarify, you're suggesting we add an efi_enabled stub somewhere in arch/ppc? I'm not against that, though it does seem a little silly to have to define EFI-specific functions on an architecture that will never support EFI.
Stil, if you think it's preferable to adding the ifdef here then I'm not against it.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
Hi,
Quoted 45 lines · Shawn Anastasio
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
Quoted 9 lines
Quoted 2 lines
However, we don't have a
CONFIG_EFIoption. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.Right, hence why I also wasn't suggesting to go that route right away.
efi/common-stub.calready has a stub forefi_enabled(). Using that file may be too involved to arrange for in PPC, but supplying such a stub elsewhere for the time being looks like it wouldn't too much effort (and would eliminate the need for any #ifdef here afaict). Shawn?
Quoted 4 lines
To clarify, you're suggesting we add an
efi_enabledstub somewhere inarch/ppc? I'm not against that, though it does seem a little silly to have to define EFI-specific functions on an architecture that will never support EFI.
(This is not an argument for adding efi_enabled in arch/ppc)
I am curious to know why you think that. This is just software and therefore doesn't seem to be technically impossible. I mean who originally thought that ACPI would come to Arm? :) And yet we now have HWs (mainly servers) which provides only ACPI + UEFI.
And before, I got asked where is the support in Xen. Yes, the work is still on-going :).
Anyway, back to the original ask, one option would be to introduce efi_enabled stub in an common header. Maybe xen/efi.h?
But I would also be ok with the existing #ifdef for now.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
----- Original Message -----
Quoted 59 lines
From: "Julien Grall" <[email protected]>
To: "Shawn Anastasio" <[email protected]>, "Jan Beulich" <[email protected]>
Cc: "Timothy Pearson" <[email protected]>, "xen-devel" <[email protected]>
Sent: Wednesday, December 20, 2023 4:08:30 PM
Subject: Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to commonHi,
Quoted 45 lines · Shawn Anastasio
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
Quoted 9 lines
Quoted 2 lines
However, we don't have a
CONFIG_EFIoption. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.Right, hence why I also wasn't suggesting to go that route right away.
efi/common-stub.calready has a stub forefi_enabled(). Using that file may be too involved to arrange for in PPC, but supplying such a stub elsewhere for the time being looks like it wouldn't too much effort (and would eliminate the need for any #ifdef here afaict). Shawn?Quoted 4 lines
To clarify, you're suggesting we add an
efi_enabledstub somewhere inarch/ppc? I'm not against that, though it does seem a little silly to have to define EFI-specific functions on an architecture that will never support EFI.
Quoted 6 lines
(This is not an argument for adding
efi_enabledinarch/ppc)I am curious to know why you think that. This is just software and therefore doesn't seem to be technically impossible. I mean who originally thought that ACPI would come to Arm? :) And yet we now have HWs (mainly servers) which provides only ACPI + UEFI.
It's not a technical restriction, it's an architecture specifiction and compatibility (standardization) restriction. POWER has its own interfaces (OPAL etc.) that provide the functionality ACPI provides on x86/ARM, and fragmenting the ecosystem across two interface standards is not something that any of the key stakeholders are currently willing to do.
Just some background, I have no comment on the actual technical implementation in the patch. :)
Thanks!
Re: [PATCH v2 7/7] xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime
In reply to Shawn AnastasioQuoted 9 lines · 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). Also bump the number of static LVL2/3 PD frames to tolerate cases where the boot allocator returns an address outside of the range of the LVL2 frame used for Xen.
Don't you need to bump to 4, in case PATB and PRTB end up sufficiently far apart? Or even further, considering that you may need distinct L2 and L3 for each of Xen, PATB, and PRTB?
However, with there being memory to allocate now, is there a reason you still reserve (perhaps more than necessary) static memory for the page tables, rather than allocating those dynamically as well?
Quoted 85 lines
xen/arch/ppc/mm-radix.c +8
-64@@ -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 ();
xen/arch/ppc/mm-radix.c static void __init setup_initial_mapping(struct lvl1_pd *lvl1, · line 186
Quoted 10 lines
xen/arch/ppc/mm-radix.c +9
-0+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;
While technically not an issue, casting pointers to fixed width types is generally bogus. page_addr itself would likely better also be of a different type (unsigned long, uintptr_t, or vaddr_t; the latter only if that's meant to represent hypervisor virtual addresses, not guest ones).
xen/arch/ppc/mm-radix.c static void __init setup_initial_mapping(struct lvl1_pd *lvl1, · line 197
Quoted 11 lines
xen/arch/ppc/mm-radix.c +10
-0+ 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 ); }
Just as a remark (you're the maintainer) - in cases like these we generally prefer to omit the braces.
Quoted 4 lines
xen/arch/ppc/mm-radix.c +0
-0@@ -210,6 +225,16 @@ void __init setup_initial_pagetables(void) {struct lvl1_pd *root =lvl1_pd_pool_alloc ();unsigned long lpcr;
xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 237
Quoted 10 lines
xen/arch/ppc/mm-radix.c +10
-0+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));
Overall, what's the plan wrt directmap: Are you meaning to not have one covering all memory? If you do, I wonder if you wouldn't be better off mapping memory as you pass it to the boot allocator, such that you won't need to map things piecemeal like you're doing here.
Jan
Re: [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common
In reply to Julien GrallQuoted 60 lines · Julien Grall
Hi,
Quoted 45 lines · Shawn Anastasio
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +6
-6@@ -431,12 +431,15 @@ static int __init early_scan_node(const void *fdt, {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") ) +#if defined(CONFIG_ARM_EFI ) +/* +* If Xen has been booted via UEFI, the memory banks are +* populated. So we should skip the parsing. +*/ Quoted 8 lines
xen/common/device-tree/bootfdt.c static int __init early_scan_node(const void *fdt, · line 442
Quoted 3 lines
xen/common/device-tree/bootfdt.c renamed from xen/arch/arm/bootfdt.c +3
-0+if (efi_enabled (EFI_BOOT ) ) +return rc; +#endif I'm not a DT maintainer, but I don't like this kind of #ifdef, the more that maybe PPC and quite likely RISC-V are likely to also want to support EFI boot. But of course there may be something inherently Arm-specific here that I'm unaware of.
Right now, I can't think how this is Arm specific. If you are using UEFI, then you are expected to use the UEFI memory map rather than the content of the device-tree.
Quoted 9 lines
Quoted 2 lines
However, we don't have a
CONFIG_EFIoption. It would be nice to introduce one but I am not sure I would introduce it just for this #ifdef.Right, hence why I also wasn't suggesting to go that route right away.
efi/common-stub.calready has a stub forefi_enabled(). Using that file may be too involved to arrange for in PPC, but supplying such a stub elsewhere for the time being looks like it wouldn't too much effort (and would eliminate the need for any #ifdef here afaict). Shawn?Quoted 4 lines
To clarify, you're suggesting we add an
efi_enabledstub somewhere inarch/ppc? I'm not against that, though it does seem a little silly to have to define EFI-specific functions on an architecture that will never support EFI.(This is not an argument for adding
efi_enabledinarch/ppc)I am curious to know why you think that. This is just software and therefore doesn't seem to be technically impossible. I mean who originally thought that ACPI would come to Arm? :) And yet we now have HWs (mainly servers) which provides only ACPI + UEFI.
Quoted 5 lines
And before, I got asked where is the support in Xen. Yes, the work is still on-going :).
Anyway, back to the original ask, one option would be to introduce
efi_enabledstub in an common header. Maybexen/efi.h?
Right, and having a somewhat odd #ifdef there (covering for the lack of CONFIG_EFI) would imo be preferable to having it in a random .c file.
Jan
Re: [PATCH v2 4/7] xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions
In reply to Shawn Anastasio(+ Stefano)
Hi Shawn,
Quoted 5 lines · Shawn Anastasio
The
early_print_inforoutine inbootfdt.cincorrectly stores the result of a call tofdt_num_mem_rsv()in an unsigned int, which results in the negative error code being interpreted incorrectly in a subsequent loop in the case where the device tree does not contain any memory reserve map entries.
I have some trouble to reconciliate the code with your explanation. Looking at the implementation fdt_num_mem_rsv() should return 0 if there are no reserved regions. A negative value would only be returned if the device-tree is malformated.
Do you have a Device-Tree where the issue occurs?
That said, I agree that the code could be hardened.
Quoted 21 lines
Signed-off-by Shawn Anastasio <[email protected]>--- xen/common/device-tree/bootfdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/common/device-tree/bootfdt.c +2
-1@@ -466,7 +466,8 @@ static void __init early_print_info(void)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; +int nr_rsvd;for ( i =0 ; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
xen/common/device-tree/bootfdt.c static void __init early_print_info(void) · line 484
Quoted 3 lines
xen/common/device-tree/bootfdt.c +0
-0@@ -481,7 +482,7 @@ static void __init early_print_info(void) boot_module_kind_as_string(mods->module[i].kind)); nr_rsvd =fdt_num_mem_rsv (device_tree_flattened);
If I am correct above, then I think we should panic() rather than trying to continue with a buggy DT.
xen/common/device-tree/bootfdt.c static void __init early_print_info(void) · line 488
Quoted 5 lines
xen/common/device-tree/bootfdt.c +1
-1-for ( i =0 ; i < nr_rsvd; i++ ) +for ( i =0 ; nr_rsvd >0 && i < nr_rsvd; i++ ) {paddr_t s, e;
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/7] xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions
Quoted 13 lines · Julien Grall
(+ Stefano)
Hi Shawn,
Quoted 5 lines · Shawn Anastasio
The
early_print_inforoutine inbootfdt.cincorrectly stores the result of a call tofdt_num_mem_rsv()in an unsigned int, which results in the negative error code being interpreted incorrectly in a subsequent loop in the case where the device tree does not contain any memory reserve map entries.
Quoted 4 lines
I have some trouble to reconciliate the code with your explanation. Looking at the implementation
fdt_num_mem_rsv()should return 0 if there are no reserved regions. A negative value would only be returned if the device-tree is malformated.
I agree with Julien. The function takes an offset to reserve map and grabs blocks of type fdt_reserve_entry from there. In case of no regions, there will be one entry with addr/size 0 which always acts as a termination region. The only way to return < 0 is when you have a buggy FDT.
Quoted 28 lines
Do you have a Device-Tree where the issue occurs?
That said, I agree that the code could be hardened.
Quoted 23 lines
Signed-off-by Shawn Anastasio <[email protected]>--- xen/common/device-tree/bootfdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/common/device-tree/bootfdt.c +2
-1@@ -466,7 +466,8 @@ static void __init early_print_info(void)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; +int nr_rsvd;for ( i =0 ; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",@@ -481,7 +482,7 @@ static void __init early_print_info(void) boot_module_kind_as_string(mods->module[i].kind));
Quoted 4 lines
xen/common/device-tree/bootfdt.c static void __init early_print_info(void) · line 484
Quoted 1 line
xen/common/device-tree/bootfdt.c +0
-0nr_rsvd =fdt_num_mem_rsv (device_tree_flattened);If I am correct above, then I think we should
panic()rather than trying to continue with a buggy DT.
+1. Furthermore, we already call panic in such case in dt_unreserved_regions().
Quoted 7 lines
xen/common/device-tree/bootfdt.c static void __init early_print_info(void) · line 488
Quoted 6 lines
xen/common/device-tree/bootfdt.c +1
-1-for ( i =0 ; i < nr_rsvd; i++ ) +for ( i =0 ; nr_rsvd >0 && i < nr_rsvd; i++ ) {paddr_t s, e;
Quoted 5 lines
Cheers,
--
Julien Grall
~Michal
Re: [PATCH v2 4/7] xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions
In reply to Julien GrallHi Julien
Quoted 11 lines · Julien Grall
(+ Stefano)
Hi Shawn,
Quoted 5 lines · Shawn Anastasio
The
early_print_inforoutine inbootfdt.cincorrectly stores the result of a call tofdt_num_mem_rsv()in an unsigned int, which results in the negative error code being interpreted incorrectly in a subsequent loop in the case where the device tree does not contain any memory reserve map entries.
Quoted 9 lines
I have some trouble to reconciliate the code with your explanation. Looking at the implementation
fdt_num_mem_rsv()should return 0 if there are no reserved regions. A negative value would only be returned if the device-tree is malformated.Do you have a Device-Tree where the issue occurs?
That said, I agree that the code could be hardened.
After reading your comment, I looked into it again and it appears you're right. It turns out that I was hitting this issue not because my device tree had 0 entries or was corrupt, but because the function was being called with an invalid device tree pointer to begin with!
Specifically, bootfdt.c:early_print_info calls fdt_num_mem_rsv using the global device_tree_flattened variable which PPC's setup.c did not properly initialize:
nr_rsvd = fdt_num_mem_rsv(device_tree_flattened);
Thanks for the sanity check. I'll fix this in the next revision of the patchset.
Despite my misunderstanding of how the bug was triggered in my case, it definitely is still something that should be fixed. Following yours and Michal's suggestion, I'll change the patch to panic() instead and submit a follow-up (likely standalone and not as a part of this series).
Quoted 1 line
Cheers,
Thanks,
Shawn
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Julien GrallHi Julien,
Quoted 25 lines · Julien Grall
Hi,
Quoted 22 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c +1
-1@@ -543,12 +543,33 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)if ( ret <0 )panic ("No valid device tree\n" ); -add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false); - ret =device_tree_for_each_node ((void *)fdt,0 , early_scan_node,NULL );if ( ret )panic ("Early FDT parsing failed (%d)\n" , ret); + /* +* Add module for the FDT itself after the device tree has been parsed. This
+ * is required on ppc64le where the device tree passed to Xen may
have been
+ * allocated by skiboot, in which case it will exist within a
reserved
Quoted 9 lines
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 557
Quoted 5 lines
+ * region and this call will fail. This is fine, however, since
either wayxen/common/device-tree/bootfdt.c +3
-0+* the allocator will know not to step on the device tree. +*/ +add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false);The consequence is
BOOTMOD_FDTwill not be added. AFAICT, Arm doesn't try to accessBOOTMOD_FDT, but I think it would be worth to print message.
A message will already be printed by meminfo_overlap_check in setup.c when this condition is hit, like this:
(XEN) Region: [0x0000003076e9b0, 0x00000030775215) overlapping with bank[3]: [0x00000030600000, 0x00000031000000)
If you'd like me to add another more descriptive message here to let the user know that BOOTMOD_FDT wasn't added I could do that, though.
Quoted 20 lines
Quoted 14 lines
xen/common/device-tree/bootfdt.c +3
-0+ +/* +* Xen relocates itself at the ppc64 entrypoint, so we need to manually mark
xen/common/device-tree/bootfdt.c +9
-0+* the kernel module. +*/ +if (IS_ENABLED (CONFIG_PPC64 ) ) { +paddr_t xen_start, xen_end; + + xen_start =__pa (_start); + xen_end =PAGE_ALIGN (__pa (_end)); +if ( !add_boot_module (BOOTMOD_XEN , xen_start, xen_end, false) ) + panic("Xen overlaps reserved memory! %016lx - %016lx\n",
xen_start,xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 571
Quoted 2 lines
xen/common/device-tree/bootfdt.c +2
-0+ xen_end); + }Can you explain why this is added here rather than in the caller of
boot_fdt_info()? Either before or after?
Quoted 4 lines
If after, I guess it is because of
early_print_info(). In which case, I would suggest to move offearly_print_info()to caller on each architecture.
Right, it can't be after due to the early_print_info() call, but doing it before actually works fine. Thank you for pointing that out -- I'll change this in the next revision.
Quoted 2 lines
Cheers,
Thanks,
Shawn
Re: [PATCH v2 6/7] xen/ppc: mm-radix: Replace debug printing code with printk
In reply to Jan BeulichHi Jan,
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
Now that we have common code building, there's no need to keep the old itoa64+debug print function in
mm-radix.cSigned-off-by Shawn Anastasio <[email protected]>Looks okay, just one question:
Quoted 6 lines
xen/arch/ppc/mm-radix.c +0
-0@@ -15,6 +15,12 @@void enable_mmu (void );
Quoted 9 lines
xen/arch/ppc/mm-radix.c line 22
Quoted 5 lines
xen/arch/ppc/mm-radix.c +5
-0+#ifdef NDEBUG +#define radix_dprintk (...) +#else +#define radix_dprintk (msg, ...) printk(XENLOG_DEBUG msg, ## __VA_ARGS__) +#endif Do you really mean NDEBUG here, and not
CONFIG_DEBUG? NDEBUG is generally supposed to only controlASSERT()behavior.
Thanks for pointing this out. CONFIG_DEBUG does indeed seem to be a better fit here. Will change in v3.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator
In reply to Shawn AnastasioHi Shawn,
Quoted 38 lines · Shawn Anastasio
Hi Julien,
Quoted 25 lines · Julien Grall
Hi,
Quoted 22 lines · Shawn Anastasio
xen/common/device-tree/bootfdt.c +1
-1@@ -543,12 +543,33 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)if ( ret <0 )panic ("No valid device tree\n" ); -add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false); - ret =device_tree_for_each_node ((void *)fdt,0 , early_scan_node,NULL );if ( ret )panic ("Early FDT parsing failed (%d)\n" , ret); + /* +* Add module for the FDT itself after the device tree has been parsed. This
+ * is required on ppc64le where the device tree passed to Xen may
have been
+ * allocated by skiboot, in which case it will exist within a
reservedQuoted 9 lines
xen/common/device-tree/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 557
Quoted 5 lines
+ * region and this call will fail. This is fine, however, since
either wayxen/common/device-tree/bootfdt.c +3
-0+* the allocator will know not to step on the device tree. +*/ +add_boot_module (BOOTMOD_FDT , paddr,fdt_totalsize (fdt), false);The consequence is
BOOTMOD_FDTwill not be added. AFAICT, Arm doesn't try to accessBOOTMOD_FDT, but I think it would be worth to print message.
Quoted 5 lines
A message will already be printed by
meminfo_overlap_checkinsetup.cwhen this condition is hit, like this:(XEN) Region: [
0x0000003076e9b0,0x00000030775215) overlapping with bank[3]: [0x00000030600000,0x00000031000000)
This is somewhat non-descriptive. IOW it doesn't tell me that the overlap was with the FDT. But I guess this can be improved (this is not a request for you to send another patch).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 7/7] xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime
In reply to Jan BeulichHi Jan,
I'm revisiting this series in preparation for a v3 and had some follow-up comments.
Quoted 11 lines · Jan Beulich
Quoted 9 lines · 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). Also bump the number of static LVL2/3 PD frames to tolerate cases where the boot allocator returns an address outside of the range of the LVL2 frame used for Xen.
Quoted 4 lines
Don't you need to bump to 4, in case PATB and PRTB end up sufficiently far apart? Or even further, considering that you may need distinct L2 and L3 for each of Xen, PATB, and PRTB?
In practice this won't happen since the boot allocator will start from the top of free address space and move downwards, while the PowerNV firmware allocates all of its memory towards the bottom of the physical address space. I see your point though, and will likely end up scrapping the static page table allocation entirely (see below).
Quoted 4 lines
However, with there being memory to allocate now, is there a reason you still reserve (perhaps more than necessary) static memory for the page tables, rather than allocating those dynamically as well?
Initially I had avoided doing this to simplify the identity mapping of the paging structures themselves, since dynamically allocating them would (obviously) mean that their location wouldn't be known ahead of time and that would complicate the process of mapping them.
On second thought though, this can be trivially solved by keeping track of the maximum and minimum addresses returned by all calls to alloc_boot_pages() in this early paging code and then simply identity mapping that entire region, and I think that this is worth doing to avoid these wasteful static allocations.
Quoted 92 lines
Quoted 92 lines
xen/arch/ppc/mm-radix.c +14
-64@@ -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); + } +
Quoted 9 lines
xen/arch/ppc/mm-radix.c static void __init setup_initial_mapping(struct lvl1_pd *lvl1, · line 186
Quoted 3 lines
xen/arch/ppc/mm-radix.c +3
-0+/* Map runtime-allocated PATB, PRTB */ + for ( page_addr = (uint64_t)initial_patb; + page_addr < (uint64_t)initial_patb + PATB_SIZE;While technically not an issue, casting pointers to fixed width types is generally bogus.
page_addritself would likely better also be of a different type (unsigned long,uintptr_t, orvaddr_t; the latter only if that's meant to represent hypervisor virtual addresses, not guest ones).
Noted. I'll go with one of the other types you suggested.
Quoted 12 lines
xen/arch/ppc/mm-radix.c static void __init setup_initial_mapping(struct lvl1_pd *lvl1, · line 197
Quoted 11 lines
xen/arch/ppc/mm-radix.c +10
-0+ 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 ); }
Quoted 3 lines
Just as a remark (you're the maintainer) - in cases like these we generally prefer to omit the braces.
Noted. In this case I feel pretty strongly that the braces aid readability so I'm inclined to keep them.
Quoted 11 lines
Quoted 11 lines
xen/arch/ppc/mm-radix.c +7
-0@@ -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 ));
Quoted 9 lines
xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 237
Quoted 3 lines
xen/arch/ppc/mm-radix.c +3
-0+ + initial_patb =__va (mfn_to_maddr (patb_mfn)); + initial_prtb =__va (mfn_to_maddr (prtb_mfn));Overall, what's the plan wrt directmap: Are you meaning to not have one covering all memory? If you do, I wonder if you wouldn't be better off mapping memory as you pass it to the boot allocator, such that you won't need to map things piecemeal like you're doing here.
This isn't a design decision that I've made yet, but I'm inclined to think that having a directmap would be a reasonable decision. Mapping memory as it is passed to the boot allocator seems reasonable in theory, but unless I'm missing something, doing so would create a chicken-and-egg problem since the act of mapping pages requires allocating page frames for the paging structures, and per your prior suggestion I'm planning to do that using the boot allocator itself.
This is probably something I'd want to revisit once the PPC mm code is more fleshed out.
Quoted 1 line
Jan
Thanks,
Shawn