Segment table support
Subsystems (2)
cover Segment table support
Hi,
This series add support for ISA 3.0 memory segment table.
Aneesh Kumar K.V (2):
powerpc/mm: Switch user slb fault handling to translation enabled powerpc/mm: Support segment table for Power9
Documentation/kernel-parameters.txt | 3 + arch/powerpc/include/asm/book3s/64/hash.h | 10 + arch/powerpc/include/asm/book3s/64/mmu-hash.h | 17 ++ arch/powerpc/include/asm/book3s/64/mmu.h | 4 + arch/powerpc/include/asm/mmu.h | 6 +- arch/powerpc/include/asm/mmu_context.h | 5 +- arch/powerpc/kernel/exceptions-64s.S | 55 +++- arch/powerpc/kernel/prom.c | 13 +- arch/powerpc/mm/hash_utils_64.c | 83 +++++- arch/powerpc/mm/mmu_context_book3s64.c | 32 ++- arch/powerpc/mm/slb.c | 359 ++++++++++++++++++++++++++ 11 files changed, 564 insertions(+), 23 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 powerpc/mm: Switch user slb fault handling to translation enabled
We also handle fault with proper stack initialized. This enable us to callout to C in fault handling routines. We don't do this for kernel mapping, because of the possibility of taking recursive fault if kernel stack in not yet mapped by an slb entry.
This enable us to handle Power9 slb fault better. We will add bolted entries for the entire kernel mapping in segment table and user slb entries we take fault and insert on demand. With translation on, we should be able to access segment table from fault handler.
--- arch/powerpc/kernel/exceptions-64s.S | 55 ++++++++++++++++++++++++++++++++---- arch/powerpc/mm/slb.c | 11 ++++++++ 2 files changed, 61 insertions(+), 5 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +50 -5
@@ -794,7 +794,7 @@ data_access_slb_relon_pSeries: mfspr r3,SPRN_DAR mfspr r12,SPRN_SRR1 #ifndef CONFIG_RELOCATABLE - b slb_miss_realmode + b handle_slb_miss_relon #else /* * We can't just use a direct branch to slb_miss_realmode
@@ -803,7 +803,7 @@ data_access_slb_relon_pSeries: */ mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif
@@ -819,11 +819,11 @@ instruction_access_slb_relon_pSeries: mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ mfspr r12,SPRN_SRR1 #ifndef CONFIG_RELOCATABLE - b slb_miss_realmode + b handle_slb_miss_relon #else mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif
@@ -961,7 +961,23 @@ h_data_storage_common: bl unknown_exception b ret_from_except +/* r3 point to DAR */ .align 7 + .globl slb_miss_user +slb_miss_user: + std r3,PACA_EXSLB+EX_DAR(r13) + /* Restore r3 as expected by PROLOG_COMMON below */ + ld r3,PACA_EXSLB+EX_R3(r13) + EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB) + RECONCILE_IRQ_STATE(r10, r11) + ld r4,PACA_EXSLB+EX_DAR(r13) + li r5,0x380 + std r4,_DAR(r1) + addi r3,r1,STACK_FRAME_OVERHEAD + bl handle_slb_miss + b ret_from_except_lite + + .align 7 .globl instruction_access_common instruction_access_common: EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
@@ -1379,11 +1395,17 @@ unrecover_mce: * We assume we aren't going to take any exceptions during this procedure. */ slb_miss_realmode: - mflr r10 #ifdef CONFIG_RELOCATABLE mtctr r11 #endif + /* + * Handle user slb miss with translation enabled + */ + cmpdi r3,0 + bge 3f +slb_miss_kernel: + mflr r10 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
@@ -1429,6 +1451,29 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) mtspr SPRN_SRR1,r10 rfid b . +3: + /* + * Enable IR/DR and handle the fault + */ + EXCEPTION_PROLOG_PSERIES_1(slb_miss_user, EXC_STD) + /* + * handler with relocation on + */ +handle_slb_miss_relon: +#ifdef CONFIG_RELOCATABLE + mtctr r11 +#endif + /* + * Handle user slb miss with stack initialized. + */ + cmpdi r3,0 + bge 4f + /* + * go back to slb_miss_realmode + */ + b slb_miss_kernel +4: + EXCEPTION_RELON_PROLOG_PSERIES_1(slb_miss_user, EXC_STD) unrecov_slb: EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
arch/powerpc/mm/slb.c +11 -0
@@ -25,6 +25,8 @@#include <asm/udbg.h> #include <asm/code-patching.h> +#include <linux/context_tracking.h> +enum slb_index {LINEAR_INDEX =0 ,/* Kernel linear map (0xc000000000000000) */ VMALLOC_INDEX =1 ,/* Kernel virtual map (0xd000000000000000) */
@@ -346,3 +348,12 @@ void slb_initialize(void) asmvolatile ("isync" :::"memory" ); } + +void handle_slb_miss (struct pt_regs *regs, +unsigned long address,unsigned long trap) +{ +enum ctx_state prev_state =exception_enter (); + +slb_allocate (address); +exception_exit (prev_state); +}
Signature · 1 line
2.7.4
PATCH 2/2 powerpc/mm: Support segment table for Power9
In reply to Aneesh Kumar K.VPowerISA 3.0 adds an in memory table for storing segment translation information. In this mode, which is enabled by setting both HOST RADIX and GUEST RADIX bits in partition table to 0 and enabling UPRT to 1, we have a per process segment table. The segment table details are stored in the process table indexed by PID value.
Segment table mode also requires us to map the process table at the beginning of a 1TB segment.
On the linux kernel side we enable this model if we find hash mmu bit (byte 58 bit 0) of ibm,pa-feature device tree node set to 1. If the size of ibm,pa-feature node is less than 58 bytes or if the hash mmu bit is set to 0, we enable the legacy HPT mode using SLB. If radix bit (byte 40 bit 0) is set to 1, we use the radix mode.
With respect to SLB mapping, we bolt mapp the entire kernel range and and only handle user space segment fault.
We also have access to 4 SLB register in software. So we continue to use 3 of that for bolted kernel SLB entries as we use them currently.
--- Documentation/kernel-parameters.txt | 3 + arch/powerpc/include/asm/book3s/64/hash.h | 10 + arch/powerpc/include/asm/book3s/64/mmu-hash.h | 17 ++ arch/powerpc/include/asm/book3s/64/mmu.h | 4 + arch/powerpc/include/asm/mmu.h | 6 +- arch/powerpc/include/asm/mmu_context.h | 5 +- arch/powerpc/kernel/prom.c | 13 +- arch/powerpc/mm/hash_utils_64.c | 83 +++++- arch/powerpc/mm/mmu_context_book3s64.c | 32 ++- arch/powerpc/mm/slb.c | 350 +++++++++++++++++++++++++- 10 files changed, 504 insertions(+), 19 deletions(-)
Documentation/kernel-parameters.txt +3 -0
@@ -932,6 +932,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. disable_radix [PPC] Disable RADIX MMU mode on POWER9 + disable_segment_table [PPC] + Disable Segment Table MMU mode on POWER9 + disable_cpu_apicid= [X86,APIC,SMP] Format: <int> The number of initial APIC ID for the
arch/powerpc/include/asm/book3s/64/hash.h +10 -0
@@ -58,6 +58,16 @@#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)/* +* Process table with ISA 3.0 need to be mapped at the beginning of a 1TB segment +* We put that in the top of VMALLOC region. For each region we can go upto 64TB +* for now. Hence we have space to put process table there. We should not get +* an SLB miss for this address, because the VSID for this is placed in the +* partition table. +*/ +#define H_SEG_PROC_TBL_START ASM_CONST(0xD000200000000000) +#define H_SEG_PROC_TBL_END ASM_CONST(0xD00020ffffffffff) + +/* * Region IDs */ #define REGION_SHIFT 60UL
arch/powerpc/include/asm/book3s/64/mmu-hash.h +17 -0
@@ -103,6 +103,18 @@#define HPTE_V_1TB_SEG ASM_CONST(0x4000000000000000)#define HPTE_V_VRMA_MASK ASM_CONST(0x4001ffffff000000) +/* segment table entry masks/bits */ +/* Upper 64 bit */ +#define STE_VALID ASM_CONST(0x8000000) +/* +* lower 64 bit +* 64th bit become 0 bit +*/ +/* +* Software defined bolted bit +*/ +#define STE_BOLTED ASM_CONST(0x1) +/* Values for PP (assumes Ks=0, Kp=1) */ #define PP_RWXX 0/* Supervisor read/write, User none */ #define PP_RWRX 1/* Supervisor read/write, User read */
@@ -130,6 +142,11 @@ struct hash_pte {__be64 r; }; +struct seg_entry { +__be64 ste_e; +__be64 ste_v; +}; +extern struct hash_pte *htab_address;extern unsigned long htab_size_bytes;extern unsigned long htab_hash_mask;
arch/powerpc/include/asm/book3s/64/mmu.h +4 -0
@@ -76,6 +76,7 @@ extern struct patb_entry *partition_tb;*/ #define PATB_SIZE_SHIFT 16 +extern unsigned long segment_table_initialize (struct prtb_entry *prtb);typedef unsigned long mm_context_id_t ;struct spinlock ;
@@ -105,6 +106,9 @@ typedef struct {#ifdef CONFIG_SPAPR_TCE_IOMMU struct list_head iommu_group_mem_list;#endif +unsigned long seg_table; +struct spinlock *seg_tbl_lock; + } mm_context_t;/*
arch/powerpc/include/asm/mmu.h +5 -1
@@ -24,6 +24,10 @@* Radix page table available */ #define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040) + +/* Seg table only supported for book3s 64 */ +#define MMU_FTR_TYPE_SEG_TABLE ASM_CONST(0x00000080) +/* * individual features */
@@ -129,7 +133,7 @@ enum { MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE | MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |#ifdef CONFIG_PPC_RADIX_MMU -MMU_FTR_TYPE_RADIX | +MMU_FTR_TYPE_RADIX |MMU_FTR_TYPE_SEG_TABLE | #endif 0, };
arch/powerpc/include/asm/mmu_context.h +4 -1
@@ -38,13 +38,16 @@ extern void set_context(unsigned long id, pgd_t *pgd);#ifdef CONFIG_PPC_BOOK3S_64 extern void radix__switch_mmu_context (struct mm_struct *prev, -struct mm_struct *next); +struct mm_struct *next);static inline void switch_mmu_context (struct mm_struct *prev,struct mm_struct *next,struct task_struct *tsk) {if (radix_enabled ())return radix__switch_mmu_context (prev, next); +/* +* switch the pid before flushing the slb +*/ return switch_slb (tsk, next); }
arch/powerpc/kernel/prom.c +12 -1
@@ -169,6 +169,7 @@ static struct ibm_pa_feature { {CPU_FTR_TM_COMP ,0 ,0 , PPC_FEATURE2_HTM_COMP|PPC_FEATURE2_HTM_NOSC_COMP, 22, 0, 0}, {0, MMU_FTR_TYPE_RADIX, 0, 0, 40, 0, 0}, + {0, MMU_FTR_TYPE_SEG_TABLE, 0, 0, 40, 1, 0}, }; static void __init scan_features(unsigned long node, const unsigned char *ftrs,
@@ -653,6 +654,14 @@ static int __init parse_disable_radix(char *p) }early_param ("disable_radix" , parse_disable_radix); +static bool disable_segment_table; +static int __init parse_disable_segment_table (char *p) +{ + disable_segment_table = true; +return 0 ; +} +early_param ("disable_segment_table" , parse_disable_segment_table); +void __init early_init_devtree (void *params) {phys_addr_t limit;
@@ -748,10 +757,12 @@ void __init early_init_devtree(void *params)of_scan_flat_dt (early_init_dt_scan_recoverable_ranges,NULL );#endif /* -* now fixup radix MMU mode based on kernel command line +* now fixup radix/hash MMU mode based on kernel command line */ if (disable_radix) cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX ; +if (disable_segment_table) + cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_SEG_TABLE ;DBG (" <- early_init_devtree()\n" ); }
arch/powerpc/mm/hash_utils_64.c +74 -9
126 lines not on this page · raw message
arch/powerpc/mm/mmu_context_book3s64.c +26 -6
@@ -102,12 +102,8 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) mm->context.id = index;#ifdef CONFIG_PPC_ICSWX mm->context.cop_lockp =kmalloc (sizeof (spinlock_t),GFP_KERNEL ); -if (!mm->context.cop_lockp) { -__destroy_context (index); -subpage_prot_free (mm); - mm->context.id =MMU_NO_CONTEXT ; -return -ENOMEM ; - } +if (!mm->context.cop_lockp) + goto err_out;spin_lock_init (mm->context.cop_lockp);#endif /* CONFIG_PPC_ICSWX */
@@ -117,7 +113,31 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)#ifdef CONFIG_SPAPR_TCE_IOMMU mm_iommu_init (&mm->context);#endif +/* +* Setup segment table and update process table entry +*/ +if (!radix_enabled () &&mmu_has_feature (MMU_FTR_TYPE_SEG_TABLE )) { + mm->context.seg_tbl_lock =kmalloc (sizeof (spinlock_t),GFP_KERNEL ); +if (!mm->context.seg_tbl_lock) + goto err_out_free; +spin_lock_init (mm->context.seg_tbl_lock); + mm->context.seg_table =segment_table_initialize (&process_tb[index]); +if (!mm->context.seg_table) { +kfree (mm->context.seg_tbl_lock); + goto err_out_free; + } + }return 0 ; + +err_out_free: +#ifdef CONFIG_PPC_ICSWX +kfree (mm->context.cop_lockp); +err_out: +#endif +__destroy_context (index); +subpage_prot_free (mm); + mm->context.id =MMU_NO_CONTEXT ; +return -ENOMEM ; }void __destroy_context (int context_id)
arch/powerpc/mm/slb.c +349 -1
372 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 7 lines · Aneesh Kumar K.V
Hi,
This series add support for ISA 3.0 memory segment table.
Aneesh Kumar K.V (2):
powerpc/mm: Switch user slb fault handling to translation enabled powerpc/mm: Support segment table for Power9
The segment table will only be used for the nest MMU, shouldn't we keep that a separate path that we call explictly from fault interrupts coming from NestMMU agents instead ?
Quoted 14 lines
Documentation/kernel-parameters.txt | 3 + arch/powerpc/include/asm/book3s/64/hash.h | 10 +
arch/powerpc/include/asm/book3s/64/mmu-hash.h| 17 ++ arch/powerpc/include/asm/book3s/64/mmu.h | 4 + arch/powerpc/include/asm/mmu.h | 6 +- arch/powerpc/include/asm/mmu_context.h | 5 +- arch/powerpc/kernel/exceptions-64s.S | 55 +++- arch/powerpc/kernel/prom.c | 13 +- arch/powerpc/mm/hash_utils_64.c | 83 +++++- arch/powerpc/mm/mmu_context_book3s64.c | 32 ++- arch/powerpc/mm/slb.c | 359
++++++++++++++++++++++++++11 files changed, 564 insertions(+), 23 deletions(-)
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines · Aneesh Kumar K.V
Hi,
=20
This series add support for ISA 3.0 memory segment table. =20
Aneesh Kumar K.V (2):
=C2=A0 powerpc/mm: Switch user slb fault handling to translation enabled =C2=A0 powerpc/mm: Support segment table for Power9
Quoted 4 lines
The segment table will only be used for the nest MMU, shouldn't we keep that a separate path that we call explictly from fault interrupts coming from NestMMU agents instead ?
I haven't looked at the Nest MMU use of this. This patch is looking at implementing the ISA 3.0 Segment table support for core. We determine whether cpu will support this mode by looking at ibm,pa-features bit value. If ibm,pa-features byte 40 bit 1 is not set, it indicates that Segment table support is not there and hence we fallback to other MMU mode supported by the CPU.
Going foward we may want to look at the possibility of having Nest use segment table without core supporting them. But then that is not done as a part of this patch.
-aneesh
Nicholas Piggin
reviewerRe: [for-4.8, 1/2] powerpc/mm: Switch user slb fault handling to translation enabled
In reply to Aneesh Kumar K.VQuoted 9 lines · On Wed, 13 Jul 2016 15:10:49 +0530 "Aneesh Kumar K.V"…
We also handle fault with proper stack initialized. This enable us to callout to C in fault handling routines. We don't do this for kernel mapping, because of the possibility of taking recursive fault if kernel stack in not yet mapped by an slb entry.
This enable us to handle Power9 slb fault better. We will add bolted entries for the entire kernel mapping in segment table and user slb entries we take fault and insert on demand. With translation on, we should be able to access segment table from fault handler.
What does this cost on P8? Is that a problem? Might need to do feature bits.
Quoted 92 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/kernel/exceptions-64s.S | 55++++++++++++++++++++++++++++++++----
arch/powerpc/mm/slb.c| 11 ++++++++ 2 files changed,
61 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/arch/powerpc/kernel/exceptions-64s.Sindex2747e901fb99..2132bf55573c100644 ---a/arch/powerpc/kernel/exceptions-64s.S+++b/arch/powerpc/kernel/exceptions-64s.S@@ -794,7 +794,7 @@data_access_slb_relon_pSeries: mfspr r3,SPRN_DARarch/powerpc/kernel/exceptions-64s.S +2
-2mfspr r12,SPRN_SRR1 #ifndef CONFIG_RELOCATABLE - b slb_miss_realmode + b handle_slb_miss_relon #else /* * We can't just use a direct branch to slb_miss_realmode@@ -803,7 +803,7 @@ data_access_slb_relon_pSeries: */ mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif@@ -819,11 +819,11 @@ instruction_access_slb_relon_pSeries: mfspr r3,SPRN_SRR0 /* SRR0 is faultingaddress */ mfspr r12,SPRN_SRR1
#ifndefCONFIG_RELOCATABLEarch/powerpc/kernel/exceptions-64s.S +18
-2- b slb_miss_realmode + b handle_slb_miss_relon #else mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif@@ -961,7 +961,23 @@ h_data_storage_common: bl unknown_exception b ret_from_except +/* r3 point to DAR */ .align 7 + .globl slb_miss_user +slb_miss_user: + std r3,PACA_EXSLB+EX_DAR(r13) + /* Restore r3 as expected by PROLOG_COMMON below */ + ld r3,PACA_EXSLB+EX_R3(r13) + EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB) + RECONCILE_IRQ_STATE(r10, r11) + ld r4,PACA_EXSLB+EX_DAR(r13) + li r5,0x380 + std r4,_DAR(r1) + addi r3,r1,STACK_FRAME_OVERHEAD + bl handle_slb_miss + b ret_from_except_lite + + .align 7 .globl instruction_access_common instruction_access_common: EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)@@ -1379,11 +1395,17 @@ unrecover_mce: * We assume we aren't going to take any exceptions during thisprocedure. */
slb_miss_realmode:arch/powerpc/kernel/exceptions-64s.S +7
-1- mflr r10 #ifdef CONFIG_RELOCATABLE mtctr r11 #endif + /* + * Handle user slb miss with translation enabled + */ + cmpdi r3,0 + bge 3f +slb_miss_kernel: + mflr r10 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR inexc. frame */ std r10,PACA_EXSLB+EX_LR(r13) /* save LR
*/(quoted diff) +0
-0@@ -1429,6 +1451,29 @@
ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)mtspr SPRN_SRR1,r10 rfidarch/powerpc/kernel/exceptions-64s.S +2
-0b . +3: + /*
arch/powerpc/kernel/exceptions-64s.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) · line 1465
Quoted 10 lines
arch/powerpc/kernel/exceptions-64s.S +10
-0+ * Enable IR/DR and handle the fault + */ + EXCEPTION_PROLOG_PSERIES_1(slb_miss_user, EXC_STD) + /* + * handler with relocation on + */ +handle_slb_miss_relon: +#ifdef CONFIG_RELOCATABLE + mtctr r11 +#endif
This is turning into a bit of spaghetti. I think it can be improved though.
I have a patch that I think can save a few instructions in the relocatable case for SLB miss. I think that may give enough space inline to branch to the correct handler. I should submit it soon.
arch/powerpc/kernel/exceptions-64s.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) · line 1473
Quoted 8 lines
arch/powerpc/kernel/exceptions-64s.S +8
-0+ /* + * Handle user slb miss with stack initialized. + */ + cmpdi r3,0 + bge 4f + /* + * go back to slb_miss_realmode + */
Are these comments adding much? I think if the names of some of the labels was improved, you might find they're not necessary. Some existing labels like slb_miss_realmode don't help too much either. That handler runs in real and virtual mode, and now the realmode exception can go elsewhere too.
arch/powerpc/kernel/exceptions-64s.S ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) · line 1474
Quoted 1 line
arch/powerpc/kernel/exceptions-64s.S +1
-0+ b slb_miss_kernel
blt slb_miss_kernel?
Quoted 2 lines
+4:
arch/powerpc/kernel/exceptions-64s.S +1
-0+ EXCEPTION_RELON_PROLOG_PSERIES_1(slb_miss_user, EXC_STD)
Re: [for-4.8, 1/2] powerpc/mm: Switch user slb fault handling to translation enabled
Quoted 8 lines · Nicholas Piggin
Quoted 1 line
We also handle fault with proper stack initialized. This enable us
to
Quoted 1 line
callout to C in fault handling routines. We don't do this for
kernel
Quoted 4 lines
mapping, because of the possibility of taking recursive fault if kernel stack in not yet mapped by an slb entry.
This enable us to handle Power9 slb fault better. We will add
Quoted 7 lines
bolted
Quoted 3 lines
entries for the entire kernel mapping in segment table and user slb entries we take fault and insert on demand. With translation on, we should be able to access segment table from fault handler.
What does this cost on P8? Is that a problem? Might need to do feature bits.
Also what is the need ?
The segment table is only for Nest MMU clients, we should probably handle it separately.
Cheers,
Ben.