kexec changes for Power ISA 3.0
v2 cover kexec changes for Power ISA 3.0
Add kexec support with radix page table config.
Changes from v1:
* Rebase to latest kernel
* add tlbflush on MMU cleanup
Aneesh Kumar K.V (1):
powerpc/mm: Add radix flush all with IS=3
Benjamin Herrenschmidt (4):
powerpc/64/kexec: NULL check "clear_all" in kexec_sequence powerpc/64/kexec: Fix MMU cleanup on radix powerpc/64/kexec: Copy image with MMU off when possible powerpc/64/kexec: Remove BookE special default_machine_kexec_prepare()
.../powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/include/asm/mmu-book3e.h | 3 + arch/powerpc/include/asm/mmu.h | 4 ++ arch/powerpc/kernel/machine_kexec_64.c | 74 +++++++--------------- arch/powerpc/kernel/misc_64.S | 25 ++++++-- arch/powerpc/mm/pgtable-book3s64.c | 9 +++ arch/powerpc/mm/pgtable-radix.c | 12 ++++ arch/powerpc/mm/tlb-radix.c | 15 +++++ 8 files changed, 84 insertions(+), 59 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/5 powerpc/64/kexec: NULL check "clear_all" in kexec_sequence
From: Benjamin Herrenschmidt <[email protected]>
With Radix, it can be NULL even on !BOOKE these days so replace the ifdef with a NULL check which is cleaner anyway.
--- arch/powerpc/kernel/misc_64.S | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/kernel/misc_64.S +4 -3
@@ -659,7 +659,9 @@ _GLOBAL(kexec_sequence) li r6,1 stw r6,kexec_flag-1b(5) -#ifndef CONFIG_PPC_BOOK3E + cmpdi r27,0 + beq 1f + /* clear out hardware hash page table and tlb */ #ifdef PPC64_ELF_ABI_v1 ld r12,0(r27) /* deref function descriptor */
@@ -668,7 +670,6 @@ _GLOBAL(kexec_sequence) #endif mtctr r12 bctrl /* mmu_hash_ops.hpte_clear_all(void); */ -#endif /* !CONFIG_PPC_BOOK3E */ /* * kexec image calling is:
@@ -695,7 +696,7 @@ _GLOBAL(kexec_sequence) * are the boot cpu ????? * other device tree differences (prop sizes, va vs pa, etc)... */ - mr r3,r25 # my phys cpu +1: mr r3,r25 # my phys cpu mr r4,r30 # start, aka phys mem offset mtlr 4 li r5,0
Signature · 1 line
2.7.4
Re: [PATCH V2 1/5] powerpc/64/kexec: NULL check "clear_all" in kexec_sequence
Quoted 16 lines · Aneesh Kumar K.V
From: Benjamin Herrenschmidt <[email protected]>
With Radix, it can be NULL even on !BOOKE these days so replace the ifdef with a NULL check which is cleaner anyway.
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/kernel/misc_64.S | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)arch/powerpc/kernel/misc_64.S +0
-0
arch/powerpc/kernel/misc_64.S _GLOBAL(kexec_sequence) · line 664
Quoted 7 lines
arch/powerpc/kernel/misc_64.S +3
-1@@ -659,7 +659,9 @@ _GLOBAL(kexec_sequence) li r6,1 stw r6,kexec_flag-1b(5) -#ifndef CONFIG_PPC_BOOK3E + cmpdi r27,0 + beq 1f +
Having a comment inline would help as well. I presume we are not going to tear down the page tables for radix
Balbir Singh
Re: [V2, 1/5] powerpc/64/kexec: NULL check "clear_all" in kexec_sequence
In reply to Aneesh Kumar K.VQuoted 8 lines · Aneesh Kumar K.V
From: Benjamin Herrenschmidt <[email protected]>
With Radix, it can be NULL even on !BOOKE these days so replace the ifdef with a NULL check which is cleaner anyway.
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>Acked-by Balbir Singh <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/fc48bad53142c991a5280940fd
cheers
PATCH v2 2/5 powerpc/mm: Add radix flush all with IS=3
In reply to Aneesh Kumar K.V--- arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/mm/tlb-radix.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +1 -0
@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmadextern void radix__flush_tlb_lpid_va (unsigned long lpid,unsigned long gpa,unsigned long page_size);extern void radix__flush_tlb_lpid (unsigned long lpid); +extern void radix__flush_tlb_all (void );#endif
arch/powerpc/mm/tlb-radix.c +15 -0
@@ -400,3 +400,18 @@ void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,radix__flush_tlb_range_psize (vma->vm_mm, start, end,MMU_PAGE_2M ); }EXPORT_SYMBOL (radix__flush_pmd_tlb_range); + +void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r; +unsigned long ric =RIC_FLUSH_ALL ; + + rb =0x3 <<PPC_BITLSHIFT (53 );/* IS = 3 */ + prs =0 ;/* partition scoped */ + r =1 ;/* raidx format */ + + asmvolatile ("ptesync" : : :"memory" ); + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory"); + asm volatile("eieio; tlbsync; ptesync": : :"memory"); +}
Signature · 1 line
2.7.4
Re: [PATCH V2 2/5] powerpc/mm: Add radix flush all with IS=3
Quoted 6 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>---
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/mm/tlb-radix.c | 15
+++++++++++++++2 files changed, 16 insertions(+)
Don't we need two ? One for partition scoped and one for process scoped ?
Quoted 40 lines
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +0
-0@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct
mm_struct*mm, unsigned long vmad
extern void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
unsigned longpage_size); extern voidradix__flush_tlb_lpid(unsigned long lpid); +extern voidradix__flush_tlb_all(void);
#endifarch/powerpc/mm/tlb- renamed from arch/powerpc/mm/tlb-radix.c +0
-0
radix.c
index48df05ef5231..517feb47ebe4100644arch/powerpc/mm/tlb-radix.c +0
-0@@ -400,3 +400,18 @@ void radix__flush_pmd_tlb_range(structvm_area_struct *vma, radix__flush_tlb_range_psize(vma->vm_mm, start, end,MMU_PAGE_2M );}
EXPORT_SYMBOL(radix__flush_pmd_tlb_range);arch/powerpc/mm/tlb-radix.c +13
-0+ +void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r; +unsigned long ric =RIC_FLUSH_ALL ; + + rb =0x3 <<PPC_BITLSHIFT (53 );/* IS = 3 */ + prs =0 ;/* partition scoped */ + r = 1; /* raidx format */ + + asmvolatile ("ptesync" : : :"memory" ); + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0): "memory");
arch/powerpc/mm/tlb-radix.c +2
-0+ asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +}
Re: [PATCH V2 2/5] powerpc/mm: Add radix flush all with IS=3
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>---
=C2=A0arch/powerpc/include/asm/book3s/64/tlbflush-radix.h |=C2=A0=C2=A01=
+
Quoted 1 line
Quoted 1 line
=C2=A0arch/powerpc/mm/tlb-radix.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| 15
Quoted 5 lines
Quoted 2 lines
+++++++++++++++
=C2=A02 files changed, 16 insertions(+)Don't we need two ? One for partition scoped and one for process scoped ?
With invalid selector value 3 (IS =3D 3), we will invalidate all entries when executed with MSR[HV] =3D 1. I guess that should take out all the translation cache, including implementation dependent one ?
Also note thar PRS =3D 0. ie, we are partition scoped. ie, we are doing invalidate with
PRS =3D0, IS =3D 3 HV =3D 1 RIC =3D 2
Quoted 30 lines
Quoted 30 lines
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +0
-0@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct
mm_struct*mm, unsigned long vmad
=C2=A0extern void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0unsigned longpage_size);
=C2=A0extern voidradix__flush_tlb_lpid(unsigned long lpid); +extern voidradix__flush_tlb_all(void);
=C2=A0#endifarch/powerpc/mm/tlb- renamed from arch/powerpc/mm/tlb-radix.c +0
-0
radix.c
index48df05ef5231..517feb47ebe4100644arch/powerpc/mm/tlb-radix.c +0
-0@@ -400,3 +400,18 @@ void radix__flush_pmd_tlb_range(structvm_area_struct *vma, =C2=A0 radix__flush_tlb_range_psize(vma->vm_mm, start, end,MMU_PAGE_2M );=C2=A0}
=C2=A0EXPORT_SYMBOL(radix__flush_pmd_tlb_range);arch/powerpc/mm/tlb-radix.c +5
-0+ +void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r; + unsigned long ric =3D RIC_FLUSH_ALL;
Quoted 8 lines
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,
Quoted 8 lines
arch/powerpc/mm/tlb-radix.c +8
-0+ + rb =3D 0x3 << PPC_BITLSHIFT(53); /* IS =3D 3 */ + prs =3D 0; /* partition scoped */ + r =3D 1;=C2=A0=C2=A0=C2=A0/* raidx format */ + + asmvolatile ("ptesync" : : :"memory" ); + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0: : "r"(rb), "i"(r), "i"(prs), "i"(ric)=
, "r"(0)
Quoted 3 lines
Quoted 3 lines
: "memory");
arch/powerpc/mm/tlb-radix.c +2
-0+ asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +}
Re: [PATCH V2 2/5] powerpc/mm: Add radix flush all with IS=3
Quoted 10 lines · Aneesh Kumar K.V
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>---
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/mm/tlb-radix.c | 15
+++++++++++++++2 files changed, 16 insertions(+)
Quoted 8 lines
Quoted 2 lines
Don't we need two ? One for partition scoped and one for process scoped ?
With invalid selector value 3 (IS = 3), we will invalidate all entries when executed with MSR[HV] = 1. I guess that should take out all the translation cache, including implementation dependent one ?
I think Ben might be right, we probably need two. We probably want to invlidate the process scoped ones first followed by partition scope. I could not find anything in the documentation that said partition scope flush implied process scope flush.
Quoted 31 lines
Also note thar PRS = 0. ie, we are partition scoped. ie, we are doing invalidate with
PRS =0, IS = 3 HV = 1 RIC = 2
Quoted 26 lines
Quoted 26 lines
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +0
-0@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct
mm_struct*mm, unsigned long vmad
extern void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
unsigned longpage_size); extern voidradix__flush_tlb_lpid(unsigned long lpid); +extern voidradix__flush_tlb_all(void);
#endifarch/powerpc/mm/tlb- renamed from arch/powerpc/mm/tlb-radix.c +0
-0
radix.c
index48df05ef5231..517feb47ebe4100644arch/powerpc/mm/tlb-radix.c +0
-0@@ -400,3 +400,18 @@ void radix__flush_pmd_tlb_range(structvm_area_struct *vma, radix__flush_tlb_range_psize(vma->vm_mm, start, end,MMU_PAGE_2M );}
EXPORT_SYMBOL(radix__flush_pmd_tlb_range);
+
Quoted 8 lines
Quoted 8 lines
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma, · line 411
Quoted 8 lines
arch/powerpc/mm/tlb-radix.c +8
-0+void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r; +unsigned long ric =RIC_FLUSH_ALL ; + + rb =0x3 <<PPC_BITLSHIFT (53 );/* IS = 3 */ + prs =0 ;/* partition scoped */ + r = 1; /* raidx format */
^^ radix
Quoted 8 lines
Quoted 7 lines
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma, · line 417
Quoted 7 lines
arch/powerpc/mm/tlb-radix.c +4
-0+ + asmvolatile ("ptesync" : : :"memory" ); + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0): "memory");
arch/powerpc/mm/tlb-radix.c +2
-0+ asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +}
Balbir Singh.
PATCH v3 1/1 powerpc/mm: Add radix flush all with IS=3
In reply to Aneesh Kumar K.V--- .../powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/mm/tlb-radix.c | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +1 -0
@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmadextern void radix__flush_tlb_lpid_va (unsigned long lpid,unsigned long gpa,unsigned long page_size);extern void radix__flush_tlb_lpid (unsigned long lpid); +extern void radix__flush_tlb_all (void );#endif
arch/powerpc/mm/tlb-radix.c +24 -0
@@ -400,3 +400,27 @@ void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,radix__flush_tlb_range_psize (vma->vm_mm, start, end,MMU_PAGE_2M ); }EXPORT_SYMBOL (radix__flush_pmd_tlb_range); + +void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r,rs; +unsigned long ric =RIC_FLUSH_ALL ; + + rb =0x3 <<PPC_BITLSHIFT (53 );/* IS = 3 */ + prs =0 ;/* partition scoped */ + r =1 ;/* raidx format */ + rs =1 & ((1UL <<32 ) -1 );/* any LPID value to flush guest mappings */ + + asmvolatile ("ptesync" : : :"memory" ); +/* +* now flush guest entries by passing PRS = 1 and LPID != 0 +*/ + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(1), "i"(ric), "r"(rs) : "memory"); +/* +* now flush host entires by passing PRS = 0 and LPID == 0 + */ + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory"); + asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +}
Signature · 1 line
2.7.4
Re: [PATCH V3] powerpc/mm: Add radix flush all with IS=3
Quoted 23 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>--- .../powerpc/include/asm/book3s/64/tlbflush-radix.h | 1 + arch/powerpc/mm/tlb-radix.c | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+)arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +1
-0@@ -41,4 +41,5 @@ extern void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmadextern void radix__flush_tlb_lpid_va (unsigned long lpid,unsigned long gpa,unsigned long page_size);extern void radix__flush_tlb_lpid (unsigned long lpid); +extern void radix__flush_tlb_all (void );#endif arch/powerpc/mm/tlb-radix.c +0
-0@@ -400,3 +400,27 @@ void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,radix__flush_tlb_range_psize (vma->vm_mm, start, end,MMU_PAGE_2M ); }
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma, · line 411
Quoted 10 lines
arch/powerpc/mm/tlb-radix.c +9
-0EXPORT_SYMBOL (radix__flush_pmd_tlb_range); + +void radix__flush_tlb_all (void ) +{ +unsigned long rb,prs,r,rs; +unsigned long ric =RIC_FLUSH_ALL ; + + rb =0x3 <<PPC_BITLSHIFT (53 );/* IS = 3 */ + prs =0 ;/* partition scoped */ + r =1 ;/* raidx format */
^^ typo - radix
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma, · line 413
Quoted 2 lines
arch/powerpc/mm/tlb-radix.c +2
-0+ rs =1 & ((1UL <<32 ) -1 );/* any LPID value to flush guest mappings */ +
For RIC=2 and IS=3, I think RS is ignored.. I don't think we need to set RS to anything other than 0, please double check
Quoted 4 lines
arch/powerpc/mm/tlb-radix.c +3
-0+ asmvolatile ("ptesync" : : :"memory" ); +/* +* now flush guest entries by passing PRS = 1 and LPID != 0
arch/powerpc/mm/tlb-radix.c void radix__flush_pmd_tlb_range(struct vm_area_struct *vma, · line 426
Quoted 10 lines
arch/powerpc/mm/tlb-radix.c +10
-0+*/ + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(1), "i"(ric), "r"(rs) : "memory"); +/* +* now flush host entires by passing PRS = 0 and LPID == 0 + */ + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) + : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory"); + asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +}
Otherwise looks good
Balbir Singh.
Michael Ellerman
AppliedRe: [V3] powerpc/mm: Add radix flush all with IS=3
In reply to Aneesh Kumar K.VQuoted 1 line · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/be34d300597a7a4fb38c6e3f99
cheers
PATCH v2 3/5 powerpc/64/kexec: Fix MMU cleanup on radix
In reply to Aneesh Kumar K.VFrom: Benjamin Herrenschmidt <[email protected]>
Just using the hash ops won't work anymore since radix will have NULL in there. Instead create an mmu_cleanup_all() function which will do the right thing based on the MMU mode.
For Radix, for now I clear UPRT and the PTCR, effectively switching back to Radix with no partition table setup.
Currently set it to NULL on BookE thought it might be a good idea to wipe the TLB there (Scott ?)
--- arch/powerpc/include/asm/mmu-book3e.h | 3 +++ arch/powerpc/include/asm/mmu.h | 4 ++++ arch/powerpc/kernel/machine_kexec_64.c | 13 +++---------- arch/powerpc/mm/pgtable-book3s64.c | 9 +++++++++ arch/powerpc/mm/pgtable-radix.c | 12 ++++++++++++ 5 files changed, 31 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/mmu-book3e.h +3 -0
@@ -313,6 +313,9 @@ extern int book3e_htw_mode;* return 1, indicating that the tlb requires preloading. */ #define HUGETLB_NEED_PRELOAD + +#define mmu_cleanup_all NULL +#endif #endif /* !__ASSEMBLY__ */
arch/powerpc/include/asm/mmu.h +4 -0
@@ -204,6 +204,10 @@ extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;* make it match the size our of bolted TLB area */ extern u64 ppc64_rma_size; + +/* Cleanup function used by kexec */ +extern void mmu_cleanup_all (void ); +extern void radix__mmu_cleanup_all (void );#endif /* CONFIG_PPC64 */ struct mm_struct ;
arch/powerpc/kernel/machine_kexec_64.c +3 -10
@@ -30,6 +30,7 @@#include <asm/smp.h> #include <asm/hw_breakpoint.h> #include <asm/asm-prototypes.h> +#include <asm/firmware.h> #ifdef CONFIG_PPC_BOOK3E int default_machine_kexec_prepare (struct kimage *image)
@@ -55,9 +56,6 @@ int default_machine_kexec_prepare(struct kimage *image)const unsigned long *basep;const unsigned int *sizep; -if (!mmu_hash_ops.hpte_clear_all) -return -ENOENT ; -/* * Since we use the kernel fault handlers and paging code to * handle the virtual mode, we must make sure no destination
@@ -379,13 +377,8 @@ void default_machine_kexec(struct kimage *image)* a toc is easier in C, so pass in what we can. */ kexec_sequence (&kexec_stack, image->start, image, -page_address (image->control_code_page), -#ifdef CONFIG_PPC_STD_MMU - mmu_hash_ops.hpte_clear_all -#else -NULL -#endif - ); +page_address (image->control_code_page), + mmu_cleanup_all);/* NOTREACHED */ }
arch/powerpc/mm/pgtable-book3s64.c +9 -0
@@ -116,3 +116,12 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, return; }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + +/* For use by kexec */ +void mmu_cleanup_all (void ) +{ +if (radix_enabled ()) +radix__mmu_cleanup_all (); +else if (mmu_hash_ops.hpte_clear_all) + mmu_hash_ops.hpte_clear_all (); +}
arch/powerpc/mm/pgtable-radix.c +12 -0
@@ -395,6 +395,18 @@ void radix__early_init_mmu_secondary(void) } } +void radix__mmu_cleanup_all (void ) +{ +unsigned long lpcr; + +if (!firmware_has_feature (FW_FEATURE_LPAR )) { + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr & ~LPCR_UPRT ); +mtspr (SPRN_PTCR ,0 ); +radix__flush_tlb_all (); + } +} +void radix__setup_initial_memory_limit (phys_addr_t first_memblock_base,phys_addr_t first_memblock_size) {
Signature · 1 line
2.7.4
Re: [PATCH V2 3/5] powerpc/64/kexec: Fix MMU cleanup on radix
Quoted 111 lines · Aneesh Kumar K.V
From: Benjamin Herrenschmidt <[email protected]>
Just using the hash ops won't work anymore since radix will have NULL in there. Instead create an
mmu_cleanup_all()function which will do the right thing based on the MMU mode.For Radix, for now I clear UPRT and the PTCR, effectively switching back to Radix with no partition table setup.
Currently set it to NULL on BookE thought it might be a good idea to wipe the TLB there (Scott ?)
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/mmu-book3e.h | 3 +++ arch/powerpc/include/asm/mmu.h | 4 ++++ arch/powerpc/kernel/machine_kexec_64.c | 13 +++---------- arch/powerpc/mm/pgtable-book3s64.c | 9 +++++++++ arch/powerpc/mm/pgtable-radix.c | 12 ++++++++++++ 5 files changed, 31 insertions(+), 10 deletions(-)arch/powerpc/include/asm/mmu-book3e.h +3
-0@@ -313,6 +313,9 @@ extern int book3e_htw_mode;* return 1, indicating that the tlb requires preloading. */ #define HUGETLB_NEED_PRELOAD + +#define mmu_cleanup_all NULL +#endif #endif /* !__ASSEMBLY__ */ arch/powerpc/include/asm/mmu.h +4
-0@@ -204,6 +204,10 @@ extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;* make it match the size our of bolted TLB area */ extern u64 ppc64_rma_size; + +/* Cleanup function used by kexec */ +extern void mmu_cleanup_all (void ); +extern void radix__mmu_cleanup_all (void );#endif /* CONFIG_PPC64 */ struct mm_struct ;arch/powerpc/kernel/machine_kexec_64.c +3
-10@@ -30,6 +30,7 @@#include <asm/smp.h> #include <asm/hw_breakpoint.h> #include <asm/asm-prototypes.h> +#include <asm/firmware.h> #ifdef CONFIG_PPC_BOOK3E int default_machine_kexec_prepare (struct kimage *image)@@ -55,9 +56,6 @@ int default_machine_kexec_prepare(struct kimage *image)const unsigned long *basep;const unsigned int *sizep; -if (!mmu_hash_ops.hpte_clear_all) -return -ENOENT ; -/* * Since we use the kernel fault handlers and paging code to * handle the virtual mode, we must make sure no destination @@ -379,13 +377,8 @@ void default_machine_kexec(struct kimage *image)* a toc is easier in C, so pass in what we can. */ kexec_sequence (&kexec_stack, image->start, image, -page_address (image->control_code_page), -#ifdef CONFIG_PPC_STD_MMU - mmu_hash_ops.hpte_clear_all -#else -NULL -#endif - ); +page_address (image->control_code_page), + mmu_cleanup_all);/* NOTREACHED */ }arch/powerpc/mm/pgtable-book3s64.c +9
-0@@ -116,3 +116,12 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, return; }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + +/* For use by kexec */ +void mmu_cleanup_all (void ) +{ +if (radix_enabled ()) +radix__mmu_cleanup_all (); +else if (mmu_hash_ops.hpte_clear_all) + mmu_hash_ops.hpte_clear_all (); +}arch/powerpc/mm/pgtable-radix.c +0
-0
arch/powerpc/mm/pgtable-radix.c void radix__early_init_mmu_secondary(void) · line 404
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +7
-0@@ -395,6 +395,18 @@ void radix__early_init_mmu_secondary(void) } } +void radix__mmu_cleanup_all (void ) +{ +unsigned long lpcr; + +if (!firmware_has_feature (FW_FEATURE_LPAR )) { + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr & ~LPCR_UPRT );
I suspect the new kernel will do the right thing w.r.t LPCR
arch/powerpc/mm/pgtable-radix.c void radix__early_init_mmu_secondary(void) · line 405
Quoted 1 line
arch/powerpc/mm/pgtable-radix.c +1
-0+mtspr (SPRN_PTCR ,0 );
Do we care to free the partition_tb at this point? Probably not since we are going to reboot soon, but I think it'll help with anyone (read NMMU) holding stray references.
arch/powerpc/mm/pgtable-radix.c void radix__early_init_mmu_secondary(void) · line 412
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c +4
-0+radix__flush_tlb_all (); + } +} +void radix__setup_initial_memory_limit (phys_addr_t first_memblock_base,phys_addr_t first_memblock_size) {
PATCH v2 4/5 powerpc/64/kexec: Copy image with MMU off when possible
In reply to Aneesh Kumar K.VFrom: Benjamin Herrenschmidt <[email protected]>
Currently we turn the MMU off after copying the image, and we make sure there is no overlap between the hash table and the target pages in that case.
That doesn't work for Radix however. In that case, the page tables are scattered and we can't really enforce that the target of the image isn't overlapping one of them.
So instead, let's turn the MMU off before copying the image in radix mode. Thankfully, in radix mode, even under a hypervisor, we know we don't have the same kind of RMA limitations that hash mode has.
While at it, also turn the MMU off early when using hash in non-LPAR mode, that way we can get rid of the collision check completely.
--- arch/powerpc/kernel/machine_kexec_64.c | 47 +++++++++++++++------------------- arch/powerpc/kernel/misc_64.S | 18 ++++++++++--- 2 files changed, 34 insertions(+), 31 deletions(-)
arch/powerpc/kernel/machine_kexec_64.c +20 -27
@@ -65,31 +65,6 @@ int default_machine_kexec_prepare(struct kimage *image)if (image->segment[i].mem <__pa (_end))return -ETXTBSY ; -/* -* For non-LPAR, we absolutely can not overwrite the mmu hash -* table, since we are still using the bolted entries in it to -* do the copy. Check that here. -* -* It is safe if the end is below the start of the blocked -* region (end <= low), or if the beginning is after the -* end of the blocked region (begin >= high). Use the -* boolean identity !(a || b) === (!a && !b). -*/ -#ifdef CONFIG_PPC_STD_MMU_64 -if (htab_address) { - low =__pa (htab_address); - high = low + htab_size_bytes; - -for (i =0 ; i < image->nr_segments; i++) { - begin = image->segment[i].mem; - end = begin + image->segment[i].memsz; - -if ((begin < high) && (end > low)) -return -ETXTBSY ; - } - } -#endif /* CONFIG_PPC_STD_MMU_64 */ -/* We also should not overwrite the tce tables */ for_each_node_by_type (node,"pci" ) { basep =of_get_property (node,"linux,tce-base" ,NULL );
@@ -330,11 +305,14 @@ struct paca_struct kexec_paca;/* Our assembly helper, in misc_64.S */ extern void kexec_sequence (void *newstack,unsigned long start,void *image,void *control, -void (*clear_all)(void ))__noreturn ; +void (*clear_all)(void ), +bool copy_with_mmu_off)__noreturn ;/* too late to fail here */ void default_machine_kexec (struct kimage *image) { +bool copy_with_mmu_off; +/* prepare control code if any */ /*
@@ -372,13 +350,28 @@ void default_machine_kexec(struct kimage *image)/* XXX: If anyone does 'dynamic lppacas' this will also need to be * switched to a static version! */ +/* On Book3S, the copy must happen with the MMU off if we are either +* using Radix page tables or we are not in an LPAR since we can +* overwrite the page tables while copying. +* +* In an LPAR, we keep the MMU on otherwise we can't access beyond +* the RMA. On BookE there is no real MMU off mode, so we have to +* keep it enabled as well (but then we have bolted TLB entries). +*/ +#ifdef CONFIG_PPC_BOOK3E + copy_with_mmu_off = false; +#else + copy_with_mmu_off =radix_enabled () || + !(firmware_has_feature (FW_FEATURE_LPAR ) || +firmware_has_feature (FW_FEATURE_PS3_LV1 )); +#endif /* Some things are best done in assembly. Finding globals with * a toc is easier in C, so pass in what we can. */ kexec_sequence (&kexec_stack, image->start, image,page_address (image->control_code_page), - mmu_cleanup_all); + mmu_cleanup_all, copy_with_mmu_off);/* NOTREACHED */ }
arch/powerpc/kernel/misc_64.S +14 -4
@@ -591,7 +591,8 @@ real_mode: /* assume normal blr return */ #endif /* - * kexec_sequence(newstack, start, image, control, clear_all()) + * kexec_sequence(newstack, start, image, control, clear_all(), + copy_with_mmu_off) * * does the grungy work with stack switching and real mode switches * also does simple calls to other code
@@ -627,7 +628,7 @@ _GLOBAL(kexec_sequence) mr r29,r5 /* image (virt) */ mr r28,r6 /* control, unused */ mr r27,r7 /* clear_all() fn desc */ - mr r26,r8 /* spare */ + mr r26,r8 /* copy_with_mmu_off */ lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */ /* disable interrupts, we are overwriting kernel data next */
@@ -639,15 +640,24 @@ _GLOBAL(kexec_sequence) mtmsrd r3,1 #endif + /* We need to turn the MMU off unless we are in hash mode + * under a hypervisor + */ + cmpdi r26,0 + beq 1f + bl real_mode +1: /* copy dest pages, flush whole dest image */ mr r3,r29 bl kexec_copy_flush /* (image) */ - /* turn off mmu */ + /* turn off mmu now if not done earlier */ + cmpdi r26,0 + bne 1f bl real_mode /* copy 0x100 bytes starting at start to 0 */ - li r3,0 +1: li r3,0 mr r4,r30 /* start, aka phys mem offset */ li r5,0x100 li r6,0
Signature · 1 line
2.7.4
Re: [PATCH V2 4/5] powerpc/64/kexec: Copy image with MMU off when possible
Quoted 14 lines · Aneesh Kumar K.V
From: Benjamin Herrenschmidt <[email protected]>
Currently we turn the MMU off after copying the image, and we make sure there is no overlap between the hash table and the target pages in that case.
That doesn't work for Radix however. In that case, the page tables are scattered and we can't really enforce that the target of the image isn't overlapping one of them.
So instead, let's turn the MMU off before copying the image in radix mode. Thankfully, in radix mode, even under a hypervisor, we know we don't have the same kind of RMA limitations that hash mode has.
Quoted 5 lines
While at it, also turn the MMU off early when using hash in non-LPAR mode, that way we can get rid of the collision check completely.
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
Looks good
PATCH v2 5/5 powerpc/64/kexec: Remove BookE special default_machine_kexec_prepare()
In reply to Aneesh Kumar K.VFrom: Benjamin Herrenschmidt <[email protected]>
The only difference is now the TCE table check which doesn't need to be ifdef'ed out, it will basically do nothing on BookE (it is only useful for ancient IBM machines).
--- arch/powerpc/kernel/machine_kexec_64.c | 16 ---------------- 1 file changed, 16 deletions(-)
arch/powerpc/kernel/machine_kexec_64.c +0 -16
@@ -32,21 +32,6 @@#include <asm/asm-prototypes.h> #include <asm/firmware.h> -#ifdef CONFIG_PPC_BOOK3E -int default_machine_kexec_prepare (struct kimage *image) -{ -int i; -/* -* Since we use the kernel fault handlers and paging code to -* handle the virtual mode, we must make sure no destination -* overlaps kernel static data or bss. -*/ -for (i =0 ; i < image->nr_segments; i++) -if (image->segment[i].mem <__pa (_end)) -return -ETXTBSY ; -return 0 ; -} -#else int default_machine_kexec_prepare (struct kimage *image) {int i;
@@ -86,7 +71,6 @@ int default_machine_kexec_prepare(struct kimage *image)return 0 ; } -#endif /* !CONFIG_PPC_BOOK3E */ static void copy_segments (unsigned long ind) {
Signature · 1 line
2.7.4