xen/ppc: Add early Radix MMU support
v3 cover xen/ppc: Add early Radix MMU support
(v3: Apologies for the noise, but v2 was submitted in error and was missing a few changes to patch 3 that were discussed)
Hello all,
This series adds support for bringing up the Radix MMU with basic identity-mapped page tables.
In order to simplify the memory layout, the series changes XEN_VIRT _START to 0xC000_0000_0000_0000, which has a couple of convenient properties. When the MMU is off, the top 4 address bits are ignored by the hardware, so this is equivalent to physical address 0. When the MMU is enabled, the top 4 address bits are used to select the memory quadrant, and 0xC corresponds to quadrant 3 which is used for kernel memory. Thus, by linking the kernel here and ensuring its physical load address is 0x0, we are able to run at the correct address both before and after the MMU is enabled.
Additionally, as the Radix MMU was only added in ISA 3.0 (POWER9), this series also drops support for POWER8 for now, to avoid having a non-working build configuration in-tree.
Thanks,
Shawn
Shawn Anastasio (3):
xen/ppc: Bump minimum target ISA to 3.0 (POWER9) xen/ppc: Relocate kernel to physical address 0 on boot xen/ppc: Implement initial Radix MMU support
xen/arch/ppc/Kconfig | 7 +- xen/arch/ppc/Makefile | 2 + xen/arch/ppc/arch.mk | 1 - xen/arch/ppc/include/asm/bitops.h | 9 + xen/arch/ppc/include/asm/config.h | 2 +- xen/arch/ppc/include/asm/mm.h | 18 ++ xen/arch/ppc/include/asm/page-bits.h | 3 +- xen/arch/ppc/include/asm/page.h | 179 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 138 ++++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 265 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 42 +++++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 15 files changed, 791 insertions(+), 9 deletions(-) create mode 100644 xen/arch/ppc/include/asm/bitops.h create mode 100644 xen/arch/ppc/include/asm/mm.h create mode 100644 xen/arch/ppc/include/asm/page.h create mode 100644 xen/arch/ppc/include/asm/regs.h create mode 100644 xen/arch/ppc/mm-radix.c create mode 100644 xen/arch/ppc/tlb-radix.c
--
2.30.2
PATCH v3 1/3 xen/ppc: Bump minimum target ISA to 3.0 (POWER9)
In preparation for implementing ISA3+ Radix MMU support, drop ISA 2.07B from the supported ISA list to avoid having a non-working configuration in tree. It can be re-added at a later point when Hash MMU support is added.
---
v3: no changes.
v2: no changes.
xen/arch/ppc/Kconfig | 7 +------ xen/arch/ppc/arch.mk | 1 - 2 files changed, 1 insertion(+), 7 deletions(-)
xen/arch/ppc/Kconfig +1 -6
@@ -20,15 +20,10 @@ menu "ISA Selection" choice prompt "Base ISA" - default POWER_ISA_2_07B + default POWER_ISA_3_00 help This selects the base ISA version that Xen will target. -config POWER_ISA_2_07B - bool "Power ISA 2.07B (POWER8)" - help - Target version 2.07B of the Power ISA (POWER8) or later - config POWER_ISA_3_00 bool "Power ISA 3.00 (POWER9)" help
xen/arch/ppc/arch.mk +0 -1
@@ -1,7 +1,6 @@ ######################################## # Power-specific definitions -ppc-march-$(CONFIG_POWER_ISA_2_07B) := power8 ppc-march-$(CONFIG_POWER_ISA_3_00) := power9 CFLAGS += -m64 -mlittle-endian -mcpu=$(ppc-march-y)
--
2.30.2
PATCH v3 2/3 xen/ppc: Relocate kernel to physical address 0 on boot
In reply to Shawn AnastasioIntroduce a small assembly loop in start to copy the kernel to physical address 0 before continuing. This ensures that the physical address lines up with XEN_VIRT_START (0xc000000000000000) and allows us to identity map the kernel when the MMU is set up in the next patch.
We are also able to start execution at XEN_VIRT_START after the copy since hardware will ignore the top 4 address bits when operating in Real Mode (MMU off).
---
v3: no changes.
v2:
- Fix definition of XEN_VIRT_START macro which incorrectly used _AT instead of _AC.
- Use _start instead of start as symbol referring to beginning of Xen binary
xen/arch/ppc/include/asm/config.h | 2 +- xen/arch/ppc/ppc64/head.S | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)
xen/arch/ppc/include/asm/config.h +1 -1
@@ -39,7 +39,7 @@ name:#endif -#define XEN_VIRT_START _AT(UL, 0xc000000000000000) +#define XEN_VIRT_START _AC(0xc000000000000000, UL)#define SMP_CACHE_BYTES (1 << 6)
xen/arch/ppc/ppc64/head.S +27 -0
@@ -17,6 +17,33 @@ ENTRY(start) addis %r2, %r12, .TOC.-1b@ha addi %r2, %r2, .TOC.-1b@l + /* + * Copy Xen to physical address zero and jump to XEN_VIRT_START + * (0xc000000000000000). This works because the hardware will ignore the top + * four address bits when the MMU is off. + */ + LOAD_REG_ADDR(%r1, _start) + LOAD_IMM64(%r12, XEN_VIRT_START) + + /* If we're at the correct address, skip copy */ + cmpld %r1, %r12 + beq .L_correct_address + + /* Copy bytes until _end */ + LOAD_REG_ADDR(%r11, _end) + addi %r1, %r1, -8 + li %r13, -8 +.L_copy_xen: + ldu %r10, 8(%r1) + stdu %r10, 8(%r13) + cmpld %r1, %r11 + blt .L_copy_xen + + /* Jump to XEN_VIRT_START */ + mtctr %r12 + bctr +.L_correct_address: + /* set up the initial stack */ LOAD_REG_ADDR(%r1, cpu0_boot_stack) li %r11, 0
--
2.30.2
Re: [PATCH v3 2/3] xen/ppc: Relocate kernel to physical address 0 on boot
Quoted 22 lines · Shawn Anastasio
xen/arch/ppc/ppc64/head.S +16
-0@@ -17,6 +17,33 @@ ENTRY(start) addis %r2, %r12, .TOC.-1b@ha addi %r2, %r2, .TOC.-1b@l + /* + * Copy Xen to physical address zero and jump to XEN_VIRT_START + * (0xc000000000000000). This works because the hardware will ignore the top + * four address bits when the MMU is off. + */ + LOAD_REG_ADDR(%r1, _start) + LOAD_IMM64(%r12, XEN_VIRT_START) + + /* If we're at the correct address, skip copy */ + cmpld %r1, %r12 + beq .L_correct_address + + /* Copy bytes until _end */ + LOAD_REG_ADDR(%r11, _end) + addi %r1, %r1, -8 + li %r13, -8
xen/arch/ppc/ppc64/head.S ENTRY(start) · line 45
Quoted 10 lines
xen/arch/ppc/ppc64/head.S +10
-0+.L_copy_xen: + ldu %r10, 8(%r1) + stdu %r10, 8(%r13) + cmpld %r1, %r11 + blt .L_copy_xen + + /* Jump to XEN_VIRT_START */ + mtctr %r12 + bctr +.L_correct_address:
Somewhat related to my earlier remark towards using %sp instead of %r1: Are you intentionally fiddling with the stack pointer here, corrupting any earlier stack that the boot loader might have set? This ...
xen/arch/ppc/ppc64/head.S ENTRY(start) · line 49
Quoted 3 lines
xen/arch/ppc/ppc64/head.S +0
-0/* set up the initial stack */ LOAD_REG_ADDR(%r1, cpu0_boot_stack) li %r11, 0
... is where you actually switch stacks. Using the stack pointer here is likely okay, albeit a bit unusual, the more that you have ample registers available for use.
Jan
Re: [PATCH v3 2/3] xen/ppc: Relocate kernel to physical address 0 on boot
Quoted 39 lines · Jan Beulich
Quoted 22 lines · Shawn Anastasio
xen/arch/ppc/ppc64/head.S +16
-0@@ -17,6 +17,33 @@ ENTRY(start) addis %r2, %r12, .TOC.-1b@ha addi %r2, %r2, .TOC.-1b@l + /* + * Copy Xen to physical address zero and jump to XEN_VIRT_START + * (0xc000000000000000). This works because the hardware will ignore the top + * four address bits when the MMU is off. + */ + LOAD_REG_ADDR(%r1, _start) + LOAD_IMM64(%r12, XEN_VIRT_START) + + /* If we're at the correct address, skip copy */ + cmpld %r1, %r12 + beq .L_correct_address + + /* Copy bytes until _end */ + LOAD_REG_ADDR(%r11, _end) + addi %r1, %r1, -8 + li %r13, -8xen/arch/ppc/ppc64/head.S ENTRY(start) · line 45
Quoted 10 lines
xen/arch/ppc/ppc64/head.S +10
-0+.L_copy_xen: + ldu %r10, 8(%r1) + stdu %r10, 8(%r13) + cmpld %r1, %r11 + blt .L_copy_xen + + /* Jump to XEN_VIRT_START */ + mtctr %r12 + bctr +.L_correct_address:Somewhat related to my earlier remark towards using %sp instead of %r1: Are you intentionally fiddling with the stack pointer here, corrupting any earlier stack that the boot loader might have set? This ...
Quoted 7 lines
xen/arch/ppc/ppc64/head.S ENTRY(start) · line 49
Quoted 3 lines
xen/arch/ppc/ppc64/head.S +0
-0/* set up the initial stack */ LOAD_REG_ADDR(%r1, cpu0_boot_stack) li %r11, 0... is where you actually switch stacks. Using the stack pointer here is likely okay, albeit a bit unusual, the more that you have ample registers available for use.
This was intentional -- I just chose it as a free register to use, since as you point out it preceeds the stack set-up code. I agree it might be a bit confusing though and we do have an ample amount of registers to play with, so I'll change it to something else for clarity's sake.
Quoted 1 line
Jan
Thanks,
Shawn
PATCH v3 3/3 xen/ppc: Implement initial Radix MMU support
In reply to Shawn AnastasioAdd code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
---
v3:
- Add XEN_PT_SIZE_LVL() macro for calculating the size in bytes of a page directory/page table structure.
- Add alignment to struct lvl$N_{pd,pt} types.
- Don't require aligned paddr in paddr_to_{pde,pte}
- Fix RTS_FIELD comment bit numbering
v2:
- Add missing ')' to mm.h/maddr_to_virt definition
- Add missing parens around va argument in XEN_PT_INDEX_LVL
- Drop '&' asm constraint modifier in processor.h/mfmsr()
- Fix asm constraint formatting in processor.h
- Change mtspr,mfspr to functions in processor.h
- Drop unnecessary _Static_assert in mm-radix.c
- Drop unnecessary cast in setup_initial_mapping
- Use __va() to obtain pde/pte addresses in setup_initial_mapping
- Wrap >80col lines in mm-radix.c
- Drop unnecessary parameters in setup_{process,partition}_table
- Add __init to setup_{process,partition}_table
- Drop unnecessary opal.c changes
- Drop manual prototype of setup_initial_pagetables in setup.c in favor of using the one already in asm/mm.h
- Fix formatting of tlbiel asm block in tlb-radix.c
xen/arch/ppc/Makefile | 2 + xen/arch/ppc/include/asm/bitops.h | 9 + xen/arch/ppc/include/asm/mm.h | 18 ++ xen/arch/ppc/include/asm/page-bits.h | 3 +- xen/arch/ppc/include/asm/page.h | 179 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 138 ++++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 265 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 15 ++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 12 files changed, 762 insertions(+), 1 deletion(-) create mode 100644 xen/arch/ppc/include/asm/bitops.h create mode 100644 xen/arch/ppc/include/asm/mm.h create mode 100644 xen/arch/ppc/include/asm/page.h create mode 100644 xen/arch/ppc/include/asm/regs.h create mode 100644 xen/arch/ppc/mm-radix.c create mode 100644 xen/arch/ppc/tlb-radix.c
xen/arch/ppc/Makefile +2 -0
@@ -2,8 +2,10 @@ obj-$(CONFIG_PPC64) += ppc64/ obj-y += boot-of.init.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o +obj-y += mm-radix.o obj-y += opal.o obj-y += setup.o +obj-y += tlb-radix.o $(TARGET): $(TARGET)-syms cp -f $< $@
xen/arch/ppc/include/asm/bitops.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _ASM_PPC_BITOPS_H +#define _ASM_PPC_BITOPS_H + +/* PPC bit number conversion */ +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) +#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +#endif /* _ASM_PPC_BITOPS_H */
xen/arch/ppc/include/asm/mm.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _ASM_PPC_MM_H +#define _ASM_PPC_MM_H + +#include <asm/page-bits.h> + +#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT) +#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) + +#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START)) + +/* Convert between Xen-heap virtual addresses and machine addresses. */ +#define __pa (x) (virt_to_maddr(x)) +#define __va (x) (maddr_to_virt(x)) + +void setup_initial_pagetables (void ); + +#endif /* _ASM_PPC_MM_H */
xen/arch/ppc/include/asm/page-bits.h +2 -1
@@ -2,6 +2,7 @@#define __PPC_PAGE_BITS_H__#define PAGE_SHIFT 16/* 64 KiB Pages */ -#define PADDR_BITS 48 +#define PADDR_BITS 53 +#define VADDR_BITS 52#endif /* __PPC_PAGE_BITS_H__ */
xen/arch/ppc/include/asm/page.h new file +181 -0
181 lines not on this page · raw message
xen/arch/ppc/include/asm/processor.h +34 -0
@@ -133,6 +133,40 @@ struct cpu_user_regsuint32_t entry_vector; }; +static __inline__void sync (void ) +{ + asmvolatile ("sync" ); +} + +static __inline__void isync (void ) +{ + asmvolatile ("isync" ); +} + +static inline unsigned long mfmsr (void ) +{ +unsigned long msr; + asmvolatile ("mfmsr %0" :"=r" (msr) ); +return msr; +} + +static inline void mtmsrd (unsigned long msr) +{ + asmvolatile ("mtmsrd %0" : :"r" (msr) ); +} + +static inline void mtspr (uint16_t spr,unsigned long val) +{ + asmvolatile ("mtspr %0, %1" : :"K" (spr),"r" (val) ); +} + +static inline unsigned long mfspr (uint16_t spr) +{ +unsigned long val; + asmvolatile ("mfspr %0, %1" :"=r" (val) :"K" (spr) ); +return val; +} +/* * panic() isn't available at the moment so an infinite loop will be * used temporarily.
xen/arch/ppc/include/asm/regs.h new file +138 -0
138 lines not on this page · raw message
xen/arch/ppc/include/asm/types.h +1 -0
@@ -4,6 +4,7 @@#define _ASM_PPC_TYPES_Htypedef unsigned long paddr_t ; +typedef unsigned long vaddr_t ;#define INVALID_PADDR (~0UL)#define PRIpaddr "016lx"
xen/arch/ppc/mm-radix.c new file +265 -0
265 lines not on this page · raw message
xen/arch/ppc/ppc64/head.S +15 -0
@@ -2,6 +2,7 @@ #include <asm/asm-defns.h> #include <asm/asm-offsets.h> +#include <asm/msr.h> .section .text.header, "ax", %progbits
@@ -66,3 +67,17 @@ ENTRY(start) .size start, . - start .type start, %function + +ENTRY(enable_mmu) + mflr %r3 + mfmsr %r4 + + /* enable instruction and data relocation (MMU) */ + ori %r4, %r4, (MSR_IR | MSR_DR) + + mtsrr0 %r3 /* return to caller after MMU enable */ + mtsrr1 %r4 + rfid + + .size enable_mmu, . - enable_mmu + .type enable_mmu, %function
xen/arch/ppc/setup.c +3 -0
@@ -2,6 +2,7 @@#include <xen/init.h> #include <asm/boot.h> #include <asm/early_printk.h> +#include <asm/mm.h> #include <asm/processor.h> /* Xen stack for bringing up the first CPU. */
@@ -27,6 +28,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,boot_opal_init ((void *)r3); } +setup_initial_pagetables (); +early_printk ("Hello, ppc64le!\n" );for ( ; ; )
xen/arch/ppc/tlb-radix.c new file +96 -0
96 lines not on this page · raw message
--
2.30.2
Re: [PATCH v3 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 25 lines · Shawn Anastasio
xen/arch/ppc/include/asm/page.h new file +22
-0@@ -0,0 +1,181 @@ +#ifndef _ASM_PPC_PAGE_H +#define _ASM_PPC_PAGE_H + +#include <xen/types.h> + +#include <asm/bitops.h> +#include <asm/byteorder.h> + +#define PDE_VALID PPC_BIT(0) +#define PDE_NLB_MASK 0xfffffffffffffUL +#define PDE_NLB_SHIFT 5UL +#define PDE_NLS_MASK 0x1f + +#define PTE_VALID PPC_BIT(0) +#define PTE_LEAF PPC_BIT(1) +#define PTE_REFERENCE PPC_BIT(55) +#define PTE_CHANGE PPC_BIT(56) + +/* PTE Attributes */ +#define PTE_ATT_SAO PPC_BIT(59)/* Strong Access Ordering */ +#define PTE_ATT_NON_IDEMPOTENT PPC_BIT(58) +#define PTE_ATT_TOLERANT (PPC_BIT(58) | PPC_BIT(59))
xen/arch/ppc/include/asm/page.h line 32
Quoted 10 lines
xen/arch/ppc/include/asm/page.h new file +10
-0+ +/* PTE Encoded Access Authority*/ +#define PTE_EAA_PRIVILEGED PPC_BIT(60) +#define PTE_EAA_READ PPC_BIT(61) +#define PTE_EAA_WRITE PPC_BIT(62) +#define PTE_EAA_EXECUTE PPC_BIT(63) + +/* Field shifts/masks */ +#define PTE_RPN_MASK 0x1fffffffffffUL +#define PTE_RPN_SHIFT 12UL
I still don't understand why you need two constants here. Even more so that now all their uses are as (PTE_RPN_MASK << PTE_RPN_SHIFT). With (only)
#define PTE_RPN_MASK 0x1fffffffffff000UL
instead, as indicated before, you would then (should the need arise) have this usable with MASK_EXTR() / MASK_INSR(). The again you likely know much better than me what further uses are going to appear.
Quoted 8 lines
xen/arch/ppc/include/asm/regs.h new file +5
-0@@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or
xen/arch/ppc/include/asm/regs.h line 15
Quoted 10 lines
xen/arch/ppc/include/asm/regs.h new file +10
-0+* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
There's still an SPDX header and a full license here.
Quoted 22 lines
xen/arch/ppc/mm-radix.c new file +19
-0@@ -0,0 +1,265 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <xen/init.h> +#include <xen/kernel.h> +#include <xen/types.h> +#include <xen/lib.h> + +#include <asm/bitops.h> +#include <asm/byteorder.h> +#include <asm/early_printk.h> +#include <asm/mm.h> +#include <asm/page.h> +#include <asm/processor.h> +#include <asm/regs.h> +#include <asm/msr.h> + +void enable_mmu (void ); + +#define INITIAL_LVL1_PD_COUNT 1 +#define INITIAL_LVL2_LVL3_PD_COUNT 2
xen/arch/ppc/mm-radix.c line 29
Quoted 10 lines
xen/arch/ppc/mm-radix.c new file +10
-0+#define INITIAL_LVL4_PT_COUNT 256 + +static size_t initial_lvl1_pd_pool_used; +static struct lvl1_pd initial_lvl1_pd_pool[INITIAL_LVL1_PD_COUNT ]; + +static size_t initial_lvl2_lvl3_pd_pool_used; +static struct lvl2_pd initial_lvl2_lvl3_pd_pool[INITIAL_LVL2_LVL3_PD_COUNT ]; + +static size_t initial_lvl4_pt_pool_used; +static struct lvl4_pt initial_lvl4_pt_pool[INITIAL_LVL4_PT_COUNT ];
The initial_lvl..._pool_used variables can likely all be __initdata?
Quoted 27 lines
xen/arch/ppc/mm-radix.c new file +27
-0+static void __init setup_initial_mapping (struct lvl1_pd *lvl1, +vaddr_t map_start, +vaddr_t map_end, +paddr_t phys_base) +{ +uint64_t page_addr; + +if ( map_start & ~PAGE_MASK ) + { +early_printk ("Xen _start be aligned to 64k (PAGE_SIZE) boundary\n" ); +die (); + } + +if ( phys_base & ~PAGE_MASK ) + { +early_printk ("Xen should be loaded at 64k (PAGE_SIZE) boundary\n" ); +die (); + } + +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; +
xen/arch/ppc/mm-radix.c line 158
Quoted 10 lines
xen/arch/ppc/mm-radix.c new file +10
-0+/* 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 = (struct lvl2_pd *)__va (pde_to_paddr (*pde));
I don't think the cast here (and similar ones below) is needed.
xen/arch/ppc/mm-radix.c line 228
Quoted 10 lines
xen/arch/ppc/mm-radix.c new file +10
-0+static void __init setup_partition_table (struct lvl1_pd *root) +{ +unsigned long ptcr; + +/* Configure entry for LPID 0 to enable Radix and point to root PD */ +uint64_t patb0 =RTS_FIELD |__pa (root) |XEN_PT_ENTRIES_LOG2_LVL_1 | +PATB0_HR ; +uint64_t patb1 =__pa (initial_prtb) | (PRTB_SIZE_LOG2 -12 ) |PATB1_GR ; + initial_patb[0 ].patb0 =cpu_to_be64 (patb0); + initial_patb[0 ].patb1 =cpu_to_be64 (patb1);
Nit: Blank line please between declaration(s) and statement(s).
xen/arch/ppc/mm-radix.c line 238
Quoted 9 lines
xen/arch/ppc/mm-radix.c new file +9
-0+ ptcr =__pa (initial_patb) | (PATB_SIZE_LOG2 -12 ); +mtspr (SPRN_PTCR , ptcr); +} + +static void __init setup_process_table (struct lvl1_pd *root) +{ +/* Configure entry for PID 0 to point to root PD */ +uint64_t prtb0 =RTS_FIELD |__pa (root) |XEN_PT_ENTRIES_LOG2_LVL_1 ; + initial_prtb[0 ].prtb0 =cpu_to_be64 (prtb0);
Same here then.
Jan
Re: [PATCH v3 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 40 lines · Jan Beulich
Quoted 25 lines · Shawn Anastasio
xen/arch/ppc/include/asm/page.h new file +22
-0@@ -0,0 +1,181 @@ +#ifndef _ASM_PPC_PAGE_H +#define _ASM_PPC_PAGE_H + +#include <xen/types.h> + +#include <asm/bitops.h> +#include <asm/byteorder.h> + +#define PDE_VALID PPC_BIT(0) +#define PDE_NLB_MASK 0xfffffffffffffUL +#define PDE_NLB_SHIFT 5UL +#define PDE_NLS_MASK 0x1f + +#define PTE_VALID PPC_BIT(0) +#define PTE_LEAF PPC_BIT(1) +#define PTE_REFERENCE PPC_BIT(55) +#define PTE_CHANGE PPC_BIT(56) + +/* PTE Attributes */ +#define PTE_ATT_SAO PPC_BIT(59)/* Strong Access Ordering */ +#define PTE_ATT_NON_IDEMPOTENT PPC_BIT(58) +#define PTE_ATT_TOLERANT (PPC_BIT(58) | PPC_BIT(59))xen/arch/ppc/include/asm/page.h line 32
Quoted 10 lines
xen/arch/ppc/include/asm/page.h new file +10
-0+ +/* PTE Encoded Access Authority*/ +#define PTE_EAA_PRIVILEGED PPC_BIT(60) +#define PTE_EAA_READ PPC_BIT(61) +#define PTE_EAA_WRITE PPC_BIT(62) +#define PTE_EAA_EXECUTE PPC_BIT(63) + +/* Field shifts/masks */ +#define PTE_RPN_MASK 0x1fffffffffffUL +#define PTE_RPN_SHIFT 12ULI still don't understand why you need two constants here. Even more so that now all their uses are as (
PTE_RPN_MASK<<PTE_RPN_SHIFT). With (only)
Quoted 5 lines
#define
PTE_RPN_MASK0x1fffffffffff000ULinstead, as indicated before, you would then (should the need arise) have this usable with
MASK_EXTR()/MASK_INSR(). The again you likely know much better than me what further uses are going to appear.
Yes, this patch was submitted before I saw your follow-up comment to my MASK_EXTR/INSR comment, but I agree now that just having a single mask constant with the shift built-in would be perfectly adequate. I'll make that change.
Quoted 13 lines
Quoted 13 lines
xen/arch/ppc/include/asm/regs.h new file +9
-0@@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of
Quoted 9 lines
xen/arch/ppc/include/asm/regs.h line 15
Quoted 6 lines
xen/arch/ppc/include/asm/regs.h new file +6
-0+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. There's still an SPDX header and a full license here.
Will fix.
Quoted 26 lines
Quoted 26 lines
xen/arch/ppc/mm-radix.c new file +23
-0@@ -0,0 +1,265 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <xen/init.h> +#include <xen/kernel.h> +#include <xen/types.h> +#include <xen/lib.h> + +#include <asm/bitops.h> +#include <asm/byteorder.h> +#include <asm/early_printk.h> +#include <asm/mm.h> +#include <asm/page.h> +#include <asm/processor.h> +#include <asm/regs.h> +#include <asm/msr.h> + +void enable_mmu (void ); + +#define INITIAL_LVL1_PD_COUNT 1 +#define INITIAL_LVL2_LVL3_PD_COUNT 2 +#define INITIAL_LVL4_PT_COUNT 256 + +static size_t initial_lvl1_pd_pool_used; +static struct lvl1_pd initial_lvl1_pd_pool[INITIAL_LVL1_PD_COUNT ];
Quoted 9 lines
xen/arch/ppc/mm-radix.c line 29
Quoted 6 lines
xen/arch/ppc/mm-radix.c new file +6
-0+ +static size_t initial_lvl2_lvl3_pd_pool_used; +static struct lvl2_pd initial_lvl2_lvl3_pd_pool[INITIAL_LVL2_LVL3_PD_COUNT ]; + +static size_t initial_lvl4_pt_pool_used; +static struct lvl4_pt initial_lvl4_pt_pool[INITIAL_LVL4_PT_COUNT ];The initial_lvl..._pool_used variables can likely all be
__initdata?
Yes, that's reasonable. I'll do that.
Quoted 31 lines
Quoted 31 lines
xen/arch/ppc/mm-radix.c new file +31
-0+static void __init setup_initial_mapping (struct lvl1_pd *lvl1, +vaddr_t map_start, +vaddr_t map_end, +paddr_t phys_base) +{ +uint64_t page_addr; + +if ( map_start & ~PAGE_MASK ) + { +early_printk ("Xen _start be aligned to 64k (PAGE_SIZE) boundary\n" ); +die (); + } + +if ( phys_base & ~PAGE_MASK ) + { +early_printk ("Xen should be loaded at 64k (PAGE_SIZE) boundary\n" ); +die (); + } + +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) ) + {
Quoted 9 lines
xen/arch/ppc/mm-radix.c line 158
Quoted 6 lines
xen/arch/ppc/mm-radix.c new file +6
-0+ lvl2 =lvl2_pd_pool_alloc (); + *pde =paddr_to_pde (__pa (lvl2),PDE_VALID , +XEN_PT_ENTRIES_LOG2_LVL_2 ); + } +else + lvl2 = (struct lvl2_pd *)__va (pde_to_paddr (*pde));I don't think the cast here (and similar ones below) is needed.
Good catch. Will drop the explicit casts.
Quoted 4 lines
Quoted 4 lines
xen/arch/ppc/mm-radix.c new file +4
-0+static void __init setup_partition_table (struct lvl1_pd *root) +{ +unsigned long ptcr; +
Quoted 9 lines
xen/arch/ppc/mm-radix.c line 228
Quoted 6 lines
xen/arch/ppc/mm-radix.c new file +6
-0+/* Configure entry for LPID 0 to enable Radix and point to root PD */ +uint64_t patb0 =RTS_FIELD |__pa (root) |XEN_PT_ENTRIES_LOG2_LVL_1 | +PATB0_HR ; +uint64_t patb1 =__pa (initial_prtb) | (PRTB_SIZE_LOG2 -12 ) |PATB1_GR ; + initial_patb[0 ].patb0 =cpu_to_be64 (patb0); + initial_patb[0 ].patb1 =cpu_to_be64 (patb1);Nit: Blank line please between declaration(s) and statement(s).
Will fix.
Quoted 12 lines
xen/arch/ppc/mm-radix.c line 238
Quoted 9 lines
xen/arch/ppc/mm-radix.c new file +9
-0+ ptcr =__pa (initial_patb) | (PATB_SIZE_LOG2 -12 ); +mtspr (SPRN_PTCR , ptcr); +} + +static void __init setup_process_table (struct lvl1_pd *root) +{ +/* Configure entry for PID 0 to point to root PD */ +uint64_t prtb0 =RTS_FIELD |__pa (root) |XEN_PT_ENTRIES_LOG2_LVL_1 ; + initial_prtb[0 ].prtb0 =cpu_to_be64 (prtb0);Same here then.
Ditto.
Quoted 1 line
Jan
Thanks,
Shawn