xen/ppc: Add early Radix MMU support
v4 cover xen/ppc: Add early Radix MMU support
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 | 180 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 124 +++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 267 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 42 +++++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 15 files changed, 780 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 v4 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.
---
v4: no changes.
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
Re: [PATCH v4 1/3] xen/ppc: Bump minimum target ISA to 3.0 (POWER9)
Quoted 6 lines · Shawn Anastasio
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.
Signed-off-by Shawn Anastasio <[email protected]>
PATCH v4 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).
---
v4:
- Don't re-use stack pointer register (%r1) for non-stack-related purposes in head.S
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(%r14, _start) + LOAD_IMM64(%r12, XEN_VIRT_START) + + /* If we're at the correct address, skip copy */ + cmpld %r14, %r12 + beq .L_correct_address + + /* Copy bytes until _end */ + LOAD_REG_ADDR(%r11, _end) + addi %r14, %r14, -8 + li %r13, -8 +.L_copy_xen: + ldu %r10, 8(%r14) + stdu %r10, 8(%r13) + cmpld %r14, %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 v4 2/3] xen/ppc: Relocate kernel to physical address 0 on boot
Quoted 10 lines · Shawn Anastasio
Introduce a small assembly loop in
startto copy the kernel to physical address 0 before continuing. This ensures that the physical address lines up withXEN_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_STARTafter the copy since hardware will ignore the top 4 address bits when operating in Real Mode (MMU off).Signed-off-by Shawn Anastasio <[email protected]>
PATCH v4 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.
---
v4:
- (page.h) Drop *_SHIFT constants in page.h and include shift directly in corresponding *_MASK constant instead.
- (regs.h) Drop full license text header
- (mm-radix.c) Mark *_pd_pool_used counters as __initdata
- (mm-radix.c) Drop pointer unnecessary casts of __va()'s return value
- (mm-radix.c) Add newline separator between declarations and statements in setup_{partition,process}_table()
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 | 180 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 124 +++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 267 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 15 ++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 12 files changed, 751 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 +180 -0
180 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 +124 -0
124 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 +267 -0
267 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 v4 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 4 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Signed-off-by Shawn Anastasio <[email protected]>
with two nits, which I'll be happy to take care of while committing, so long as you agree:
Quoted 120 lines
xen/arch/ppc/include/asm/page.h new file +117
-0@@ -0,0 +1,180 @@ +#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 0x1ffffffffffffe0UL +#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)) + +/* 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 0x1fffffffffff000UL +#define PTE_ATT_MASK 0x30UL +#define PTE_EAA_MASK 0xfUL + +#define PTE_XEN_BASE (PTE_VALID | PTE_EAA_PRIVILEGED | PTE_REFERENCE) +#define PTE_XEN_RW (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_WRITE | PTE_CHANGE) +#define PTE_XEN_RO (PTE_XEN_BASE | PTE_EAA_READ) +#define PTE_XEN_RX (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_EXECUTE) + +/* + * Radix Tree layout for 64KB pages: + * + * [ L1 (ROOT) PAGE DIRECTORY (8192 * sizeof(pde_t)) ] + * | + * | + * v + * [ L2 PAGE DIRECTORY (512 * sizeof(pde_t)) ] + * | + * | + * v + * [ L3 PAGE DIRECTORY (512 * sizeof(pde_t)) ] + * | + * | + * v + * [ L4 PAGE TABLE (32 * sizeof(pte_t)) ] + * | + * | + * v + * [ PAGE TABLE ENTRY ] + */ + +#define XEN_PT_ENTRIES_LOG2_LVL_1 13 /* 2**13 entries, maps 2**13 * 512GB = 4PB */ +#define XEN_PT_ENTRIES_LOG2_LVL_2 9 /* 2**9 entries, maps 2**9 * 1GB = 512GB */ +#define XEN_PT_ENTRIES_LOG2_LVL_3 9 /* 2**9 entries, maps 2**9 * 1GB = 512GB */ +#define XEN_PT_ENTRIES_LOG2_LVL_4 5 /* 2**5 entries, maps 2**5 * 64K = 2MB */ + +#define XEN_PT_SHIFT_LVL_1 (XEN_PT_SHIFT_LVL_2 + XEN_PT_ENTRIES_LOG2_LVL_2) +#define XEN_PT_SHIFT_LVL_2 (XEN_PT_SHIFT_LVL_3 + XEN_PT_ENTRIES_LOG2_LVL_3) +#define XEN_PT_SHIFT_LVL_3 (XEN_PT_SHIFT_LVL_4 + XEN_PT_ENTRIES_LOG2_LVL_4) +#define XEN_PT_SHIFT_LVL_4 PAGE_SHIFT + +#define XEN_PT_ENTRIES_LOG2_LVL(lvl) (XEN_PT_ENTRIES_LOG2_LVL_##lvl) +#define XEN_PT_SHIFT_LVL(lvl) (XEN_PT_SHIFT_LVL_##lvl) +#define XEN_PT_ENTRIES_LVL(lvl) (1UL << XEN_PT_ENTRIES_LOG2_LVL(lvl)) +#define XEN_PT_SIZE_LVL(lvl) (sizeof(uint64_t) * XEN_PT_ENTRIES_LVL(lvl)) +#define XEN_PT_MASK_LVL(lvl) (XEN_PT_ENTRIES_LVL(lvl) - 1) +#define XEN_PT_INDEX_LVL(lvl, va) (((va) >> XEN_PT_SHIFT_LVL(lvl)) & XEN_PT_MASK_LVL(lvl)) + +/* + * Calculate the index of the provided virtual address in the provided + * page table struct + */ +#define pt_index(pt, va) _Generic((pt), \ + struct lvl1_pd * : XEN_PT_INDEX_LVL(1, (va)), \ + struct lvl2_pd * : XEN_PT_INDEX_LVL(2, (va)), \ + struct lvl3_pd * : XEN_PT_INDEX_LVL(3, (va)), \ + struct lvl4_pt * : XEN_PT_INDEX_LVL(4, (va))) + +#define pt_entry(pt, va) (&((pt)->entries[pt_index((pt), (va))])) + +typedef struct +{ + __be64 pde; +} pde_t; + +typedef struct +{ + __be64 pte; +} pte_t; + +struct lvl1_pd +{ + pde_t entries[XEN_PT_ENTRIES_LVL(1)]; +} __aligned(XEN_PT_SIZE_LVL(1)); + +struct lvl2_pd +{ + pde_t entries[XEN_PT_ENTRIES_LVL(2)]; +} __aligned(XEN_PT_SIZE_LVL(2)); + +struct lvl3_pd +{ + pde_t entries[XEN_PT_ENTRIES_LVL(3)]; +} __aligned(XEN_PT_SIZE_LVL(3)); + +struct lvl4_pt +{ + pte_t entries[XEN_PT_ENTRIES_LVL(4)];
xen/arch/ppc/include/asm/page.h line 127
Quoted 10 lines
xen/arch/ppc/include/asm/page.h new file +10
-0+}__aligned(XEN_PT_SIZE_LVL(4)) ; + +static inline pte_t paddr_to_pte (paddr_t paddr,unsigned long flags) +{ +paddr_t paddr_aligned = paddr &PTE_RPN_MASK ; + +return (pte_t ){ .pte =cpu_to_be64 (paddr_aligned | flags |PTE_LEAF ) }; +} + +static inline pde_t paddr_to_pde (paddr_t paddr,unsigned long flags,unsigned long nls)
Nit: Overlong line.
Quoted 5 lines
xen/arch/ppc/include/asm/processor.h +0
-0@@ -133,6 +133,40 @@ struct cpu_user_regsuint32_t entry_vector; };
xen/arch/ppc/include/asm/processor.h struct cpu_user_regs · line 144
Quoted 10 lines
xen/arch/ppc/include/asm/processor.h +9
-0+static __inline__void sync (void ) +{ + asmvolatile ("sync" ); +} + +static __inline__void isync (void ) +{ + asmvolatile ("isync" ); +}
Why __inline__, not inline, ...
xen/arch/ppc/include/asm/processor.h struct cpu_user_regs · line 146
Quoted 1 line
xen/arch/ppc/include/asm/processor.h +1
-0+static inline unsigned long mfmsr (void )
... as you have here any below?
Jan
Re: [PATCH v4 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 134 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Signed-off-by Shawn Anastasio <[email protected]>Acked-by Jan Beulich <[email protected]>with two nits, which I'll be happy to take care of while committing, so long as you agree:
Quoted 124 lines
xen/arch/ppc/include/asm/page.h new file +121
-0@@ -0,0 +1,180 @@ +#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 0x1ffffffffffffe0UL +#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)) + +/* 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 0x1fffffffffff000UL +#define PTE_ATT_MASK 0x30UL +#define PTE_EAA_MASK 0xfUL + +#define PTE_XEN_BASE (PTE_VALID | PTE_EAA_PRIVILEGED | PTE_REFERENCE) +#define PTE_XEN_RW (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_WRITE | PTE_CHANGE) +#define PTE_XEN_RO (PTE_XEN_BASE | PTE_EAA_READ) +#define PTE_XEN_RX (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_EXECUTE) + +/* +* Radix Tree layout for 64KB pages: +* +* [ L1 (ROOT) PAGE DIRECTORY (8192 * sizeof(pde_t)) ] +* | +* | +* v +* [ L2 PAGE DIRECTORY (512 * sizeof(pde_t)) ] +* | +* | +* v +* [ L3 PAGE DIRECTORY (512 * sizeof(pde_t)) ] +* | +* | +* v +* [ L4 PAGE TABLE (32 * sizeof(pte_t)) ] +* | +* | +* v +* [ PAGE TABLE ENTRY ] +*/ + +#define XEN_PT_ENTRIES_LOG2_LVL_1 13/* 2**13 entries, maps 2**13 * 512GB = 4PB */ +#define XEN_PT_ENTRIES_LOG2_LVL_2 9/* 2**9 entries, maps 2**9 * 1GB = 512GB */ +#define XEN_PT_ENTRIES_LOG2_LVL_3 9/* 2**9 entries, maps 2**9 * 1GB = 512GB */ +#define XEN_PT_ENTRIES_LOG2_LVL_4 5/* 2**5 entries, maps 2**5 * 64K = 2MB */ + +#define XEN_PT_SHIFT_LVL_1 (XEN_PT_SHIFT_LVL_2 + XEN_PT_ENTRIES_LOG2_LVL_2) +#define XEN_PT_SHIFT_LVL_2 (XEN_PT_SHIFT_LVL_3 + XEN_PT_ENTRIES_LOG2_LVL_3) +#define XEN_PT_SHIFT_LVL_3 (XEN_PT_SHIFT_LVL_4 + XEN_PT_ENTRIES_LOG2_LVL_4) +#define XEN_PT_SHIFT_LVL_4 PAGE_SHIFT + +#define XEN_PT_ENTRIES_LOG2_LVL (lvl) (XEN_PT_ENTRIES_LOG2_LVL_##lvl) +#define XEN_PT_SHIFT_LVL (lvl) (XEN_PT_SHIFT_LVL_##lvl) +#define XEN_PT_ENTRIES_LVL (lvl) (1UL << XEN_PT_ENTRIES_LOG2_LVL(lvl)) +#define XEN_PT_SIZE_LVL (lvl) (sizeof(uint64_t) * XEN_PT_ENTRIES_LVL(lvl)) +#define XEN_PT_MASK_LVL (lvl) (XEN_PT_ENTRIES_LVL(lvl) - 1) +#define XEN_PT_INDEX_LVL (lvl, va) (((va) >> XEN_PT_SHIFT_LVL(lvl)) & XEN_PT_MASK_LVL(lvl)) + +/* +* Calculate the index of the provided virtual address in the provided +* page table struct +*/ +#define pt_index (pt, va) _Generic((pt), \ + struct lvl1_pd * : XEN_PT_INDEX_LVL(1, (va)), \ + struct lvl2_pd * : XEN_PT_INDEX_LVL(2, (va)), \ + struct lvl3_pd * : XEN_PT_INDEX_LVL(3, (va)), \ + struct lvl4_pt * : XEN_PT_INDEX_LVL(4, (va))) + +#define pt_entry (pt, va) (&((pt)->entries[pt_index((pt), (va))])) + +typedef struct +{ +__be64 pde; +}pde_t ; + +typedef struct +{ +__be64 pte; +}pte_t ; + +struct lvl1_pd +{ +pde_t entries[XEN_PT_ENTRIES_LVL (1 )]; +}__aligned(XEN_PT_SIZE_LVL(1)) ; + +struct lvl2_pd +{ +pde_t entries[XEN_PT_ENTRIES_LVL (2 )]; +}__aligned(XEN_PT_SIZE_LVL(2)) ; + +struct lvl3_pd +{ +pde_t entries[XEN_PT_ENTRIES_LVL (3 )]; +}__aligned(XEN_PT_SIZE_LVL(3)) ; + +struct lvl4_pt +{ +pte_t entries[XEN_PT_ENTRIES_LVL (4 )]; +}__aligned(XEN_PT_SIZE_LVL(4)) ; + +static inline pte_t paddr_to_pte (paddr_t paddr,unsigned long flags) +{
Quoted 9 lines
xen/arch/ppc/include/asm/page.h line 127
Quoted 6 lines
xen/arch/ppc/include/asm/page.h new file +6
-0+paddr_t paddr_aligned = paddr &PTE_RPN_MASK ; + +return (pte_t ){ .pte =cpu_to_be64 (paddr_aligned | flags |PTE_LEAF ) }; +} + +static inline pde_t paddr_to_pde (paddr_t paddr,unsigned long flags,unsigned long nls)Nit: Overlong line.
My bad -- feel free to fix this.
Quoted 18 lines
Quoted 5 lines
xen/arch/ppc/include/asm/processor.h +0
-0@@ -133,6 +133,40 @@ struct cpu_user_regsuint32_t entry_vector; };xen/arch/ppc/include/asm/processor.h struct cpu_user_regs · line 144
Quoted 10 lines
xen/arch/ppc/include/asm/processor.h +9
-0+static __inline__void sync (void ) +{ + asmvolatile ("sync" ); +} + +static __inline__void isync (void ) +{ + asmvolatile ("isync" ); +}Why
__inline__, not inline, ...
Quoted 4 lines
xen/arch/ppc/include/asm/processor.h struct cpu_user_regs · line 146
Quoted 1 line
xen/arch/ppc/include/asm/processor.h +1
-0+static inline unsigned long mfmsr (void )... as you have here any below?
This was an oversight -- the sync/isync routines were copied from the old Xen port. Feel free to change it to inline.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v4 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 8 lines · Shawn Anastasio
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Signed-off-by Shawn Anastasio <[email protected]>Acked-by Jan Beulich <[email protected]>
Just a quick ping to see if you are still good to merge this patch. If you'd like me to submit a new revision let me know.
Re: [PATCH v4 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 6 lines · Shawn Anastasio
Quoted 5 lines · Shawn Anastasio
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Shawn Anastasio <[email protected]>Acked-by Jan Beulich <[email protected]>Just a quick ping to see if you are still good to merge this patch. If you'd like me to submit a new revision let me know.
Ah, yes, I managed to overlook this (perhaps more than once) because the earlier two went in already. I'll try to remember to include this in the next batch to push out.
Jan
Re: [PATCH v4 3/3] xen/ppc: Implement initial Radix MMU support
In reply to Shawn AnastasioQuoted 4 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Signed-off-by Shawn Anastasio <[email protected]>
Having committed this, something broke in CI. As per the artifacts of
https://gitlab.com/xen-project/xen/-/jobs/5017915681 ...
xen/arch/ppc/mm-radix.c line 253
Quoted 11 lines
xen/arch/ppc/mm-radix.c new file +11
-0+void __init setup_initial_pagetables (void ) +{ +struct lvl1_pd *root =lvl1_pd_pool_alloc (); +unsigned long lpcr; + +setup_initial_mapping (root, (vaddr_t )_start, (vaddr_t )_end,__pa (_start)); + +/* Enable Radix mode in LPCR */ + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT |LPCR_HR ); +early_printk ("Enabled radix in LPCR\n" );
... this is the first message missing; setup_initial_mapping() appears to be completing fine.
Jan
Re: [PATCH v4 3/3] xen/ppc: Implement initial Radix MMU support
Quoted 9 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
Add code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
Signed-off-by Shawn Anastasio <[email protected]>Having committed this, something broke in CI. As per the artifacts of
https://gitlab.com/xen-project/xen/-/jobs/5017915681 ...
Quoted 14 lines
xen/arch/ppc/mm-radix.c line 253
Quoted 11 lines
xen/arch/ppc/mm-radix.c new file +11
-0+void __init setup_initial_pagetables (void ) +{ +struct lvl1_pd *root =lvl1_pd_pool_alloc (); +unsigned long lpcr; + +setup_initial_mapping (root, (vaddr_t )_start, (vaddr_t )_end,__pa (_start)); + +/* Enable Radix mode in LPCR */ + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT |LPCR_HR ); +early_printk ("Enabled radix in LPCR\n" );... this is the first message missing;
setup_initial_mapping()appears to be completing fine.
Ah, yes, this is a side-effect of the CI pipeline using the pseries machine type instead of PowerNV. Setting the LPCR directly as we're doing here has to be done via a hypercall on the paravirtualized pseries platform.
I've given it some thought and I think the best path forward would be to just drop pseries support. I had originally targeted it for the early bringup patches since it has historically been much better supported by QEMU, but that's no longer the case with QEMU git. Outside of testing I don't think there's much practical value in continuing to support pseries.
I'll prepare a series to drop pseries support and update the CI container to use the PowerNV machine type instead, if there are no objections.
Quoted 1 line
Jan
Thanks,
Shawn