Fix .long's in mm/tlb-radix.c to more meaningful
PATCH 1/3 Fix .long's in mm/tlb-radix.c to more meaningful
From: Balbir Singh <[email protected]>
The .longs with the shifts are harder to read, use more meaningful names for the opcodes. PPC_TLBIE_5 is introduced for the 5 opcode variation of the instruction due to an existing op-code for the 2 opcode variant
--- arch/powerpc/include/asm/ppc-opcode.h | 14 ++++++++++++++ arch/powerpc/mm/tlb-radix.c | 13 +++++-------- 2 files changed, 19 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/ppc-opcode.h +14 -0
@@ -184,6 +184,7 @@#define PPC_INST_STSWX 0x7c00052a#define PPC_INST_STXVD2X 0x7c000798#define PPC_INST_TLBIE 0x7c000264 +#define PPC_INST_TLBIEL 0x7c000224#define PPC_INST_TLBILX 0x7c000024#define PPC_INST_WAIT 0x7c00007c#define PPC_INST_TLBIVAX 0x7c000624
@@ -257,6 +258,9 @@#define ___PPC_RB (b) (((b) & 0x1f) << 11)#define ___PPC_RS (s) (((s) & 0x1f) << 21)#define ___PPC_RT (t) ___PPC_RS(t) +#define ___PPC_R (r) (((r) & 0x1) << 16) +#define ___PPC_PRS (prs) (((prs) & 0x1) << 17) +#define ___PPC_RIC (ric) (((ric) & 0x3) << 18)#define __PPC_RA (a) ___PPC_RA(__REG_##a)#define __PPC_RA0 (a) ___PPC_RA(__REGA0_##a)#define __PPC_RB (b) ___PPC_RB(__REG_##b)
@@ -321,6 +325,16 @@ __PPC_WC(w))#define PPC_TLBIE (lp,a) stringify_in_c(.long PPC_INST_TLBIE | \ ___PPC_RB(a) | ___PPC_RS(lp)) +#define PPC_TLBIE_5 (rb,rs,ric,prs,r) \ + stringify_in_c(.long PPC_INST_TLBIE | \ + ___PPC_RB(rb) | ___PPC_RS(rs) | \ + ___PPC_RIC(ric) | ___PPC_PRS(prs) | \ + ___PPC_R(r)) +#define PPC_TLBIEL (rb,rs,ric,prs,r) \ + stringify_in_c(.long PPC_INST_TLBIEL | \ + ___PPC_RB(rb) | ___PPC_RS(rs) | \ + ___PPC_RIC(ric) | ___PPC_PRS(prs) | \ + ___PPC_R(r))#define PPC_TLBSRX_DOT (a,b) stringify_in_c(.long PPC_INST_TLBSRX_DOT | \ __PPC_RA0(a) | __PPC_RB(b))#define PPC_TLBIVAX (a,b) stringify_in_c(.long PPC_INST_TLBIVAX | \
arch/powerpc/mm/tlb-radix.c +5 -8
@@ -12,6 +12,7 @@#include <linux/mm.h> #include <linux/hugetlb.h> #include <linux/memblock.h> +#include <asm/ppc-opcode.h> #include <asm/tlb.h> #include <asm/tlbflush.h>
@@ -30,8 +31,7 @@ static inline void __tlbiel_pid(unsigned long pid, int set) ric =2 ;/* invalidate all the caches */ asmvolatile ("ptesync" : : :"memory" ); - asmvolatile (".long 0x7c000224 | (%0 << 11) | (%1 << 16) |" -"(%2 << 17) | (%3 << 18) | (%4 << 21)" + asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1) : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory"); asm volatile("ptesync": : :"memory"); }
@@ -60,8 +60,7 @@ static inline void _tlbie_pid(unsigned long pid) ric =2 ;/* invalidate all the caches */ asmvolatile ("ptesync" : : :"memory" ); - asmvolatile (".long 0x7c000264 | (%0 << 11) | (%1 << 16) |" -"(%2 << 17) | (%3 << 18) | (%4 << 21)" + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory"); asm volatile("eieio; tlbsync; ptesync": : :"memory"); }
@@ -79,8 +78,7 @@ static inline void _tlbiel_va(unsigned long va, unsigned long pid, ric =0 ;/* no cluster flush yet */ asmvolatile ("ptesync" : : :"memory" ); - asmvolatile (".long 0x7c000224 | (%0 << 11) | (%1 << 16) |" -"(%2 << 17) | (%3 << 18) | (%4 << 21)" + asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1) : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory"); asm volatile("ptesync": : :"memory"); }
@@ -98,8 +96,7 @@ static inline void _tlbie_va(unsigned long va, unsigned long pid, ric =0 ;/* no cluster flush yet */ asmvolatile ("ptesync" : : :"memory" ); - asmvolatile (".long 0x7c000264 | (%0 << 11) | (%1 << 16) |" -"(%2 << 17) | (%3 << 18) | (%4 << 21)" + asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory"); asm volatile("eieio; tlbsync; ptesync": : :"memory"); }
Signature · 1 line
2.7.4
PATCH 2/3 powerpc/mm/radix: Update to tlb functions ric argument
Radix invalidate control (RIC) is used to control which cache to flush using tlb instructions. When doing a PID flush, we currently flush everything including page walk cache. For address range flush, we flush only the TLB. In the later patch, we add support for flushing only page walk cache.
--- arch/powerpc/mm/tlb-radix.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
arch/powerpc/mm/tlb-radix.c +22 -21
@@ -19,16 +19,20 @@static DEFINE_RAW_SPINLOCK (native_tlbie_lock); -static inline void __tlbiel_pid (unsigned long pid,int set) +#define RIC_FLUSH_TLB 0 +#define RIC_FLUSH_PWC 1 +#define RIC_FLUSH_ALL 2 + +static inline void __tlbiel_pid (unsigned long pid,int set, +unsigned long ric) { -unsigned long rb,rs,ric,prs,r; +unsigned long rb,rs,prs,r; rb =PPC_BIT (53 );/* IS = 1 */ rb |= set <<PPC_BITLSHIFT (51 ); rs = ((unsigned long )pid) <<PPC_BITLSHIFT (31 ); prs =1 ;/* process scoped */ r =1 ;/* raidx format */ - ric =2 ;/* invalidate all the caches */ asmvolatile ("ptesync" : : :"memory" ); asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
@@ -39,25 +43,24 @@ static inline void __tlbiel_pid(unsigned long pid, int set)/* * We use 128 set in radix mode and 256 set in hpt mode. */ -static inline void _tlbiel_pid (unsigned long pid) +static inline void _tlbiel_pid (unsigned long pid,unsigned long ric) {int set;for (set =0 ; set <POWER9_TLB_SETS_RADIX ; set++) { -__tlbiel_pid (pid, set); +__tlbiel_pid (pid, set, ric); }return ; } -static inline void _tlbie_pid (unsigned long pid) +static inline void _tlbie_pid (unsigned long pid,unsigned long ric) { -unsigned long rb,rs,ric,prs,r; +unsigned long rb,rs,prs,r; rb =PPC_BIT (53 );/* IS = 1 */ rs = pid <<PPC_BITLSHIFT (31 ); prs =1 ;/* process scoped */ r =1 ;/* raidx format */ - ric =2 ;/* invalidate all the caches */ asmvolatile ("ptesync" : : :"memory" ); asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
@@ -66,16 +69,15 @@ static inline void _tlbie_pid(unsigned long pid) }static inline void _tlbiel_va (unsigned long va,unsigned long pid, -unsigned long ap) +unsigned long ap,unsigned long ric) { -unsigned long rb,rs,ric,prs,r; +unsigned long rb,rs,prs,r; rb = va & ~(PPC_BITMASK (52 ,63 )); rb |= ap <<PPC_BITLSHIFT (58 ); rs = pid <<PPC_BITLSHIFT (31 ); prs =1 ;/* process scoped */ r =1 ;/* raidx format */ - ric =0 ;/* no cluster flush yet */ asmvolatile ("ptesync" : : :"memory" ); asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
@@ -84,16 +86,15 @@ static inline void _tlbiel_va(unsigned long va, unsigned long pid, }static inline void _tlbie_va (unsigned long va,unsigned long pid, -unsigned long ap) +unsigned long ap,unsigned long ric) { -unsigned long rb,rs,ric,prs,r; +unsigned long rb,rs,prs,r; rb = va & ~(PPC_BITMASK (52 ,63 )); rb |= ap <<PPC_BITLSHIFT (58 ); rs = pid <<PPC_BITLSHIFT (31 ); prs =1 ;/* process scoped */ r =1 ;/* raidx format */ - ric =0 ;/* no cluster flush yet */ asmvolatile ("ptesync" : : :"memory" ); asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
@@ -119,7 +120,7 @@ void radix__local_flush_tlb_mm(struct mm_struct *mm)preempt_disable (); pid = mm->context.id;if (pid !=MMU_NO_CONTEXT ) -_tlbiel_pid (pid); +_tlbiel_pid (pid,RIC_FLUSH_ALL );preempt_enable (); }EXPORT_SYMBOL (radix__local_flush_tlb_mm);
@@ -132,7 +133,7 @@ void radix___local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,preempt_disable (); pid = mm ? mm->context.id :0 ;if (pid !=MMU_NO_CONTEXT ) -_tlbiel_va (vmaddr, pid, ap); +_tlbiel_va (vmaddr, pid, ap,RIC_FLUSH_TLB );preempt_enable (); }
@@ -169,11 +170,11 @@ void radix__flush_tlb_mm(struct mm_struct *mm)if (lock_tlbie)raw_spin_lock (&native_tlbie_lock); -_tlbie_pid (pid); +_tlbie_pid (pid,RIC_FLUSH_ALL );if (lock_tlbie)raw_spin_unlock (&native_tlbie_lock); }else -_tlbiel_pid (pid); +_tlbiel_pid (pid,RIC_FLUSH_ALL ); no_context:preempt_enable (); }
@@ -193,11 +194,11 @@ void radix___flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,if (lock_tlbie)raw_spin_lock (&native_tlbie_lock); -_tlbie_va (vmaddr, pid, ap); +_tlbie_va (vmaddr, pid, ap,RIC_FLUSH_TLB );if (lock_tlbie)raw_spin_unlock (&native_tlbie_lock); }else -_tlbiel_va (vmaddr, pid, ap); +_tlbiel_va (vmaddr, pid, ap,RIC_FLUSH_TLB ); bail:preempt_enable (); }
@@ -221,7 +222,7 @@ void radix__flush_tlb_kernel_range(unsigned long start, unsigned long end)if (lock_tlbie)raw_spin_lock (&native_tlbie_lock); -_tlbie_pid (0 ); +_tlbie_pid (0 ,RIC_FLUSH_ALL );if (lock_tlbie)raw_spin_unlock (&native_tlbie_lock); }
Signature · 1 line
2.7.4
PATCH 3/3 powerpc/mm/radix: Flush page walk cache when freeing page table
In reply to Aneesh Kumar K.VEven though a tlb_flush() does a flush with invalidate all cache, we can end up doing an RCU page table free, before calling tlb_flush(). That means we can have page walk cache entries even after we free the page table pages. This can result in us doing wrong page table walk.
Avoid this by doing pwc flush on every page table free. We can't batch the pwc flush, because the rcu call back function where we free the page table pages doesn't have information of the mmu gather. Thus we have to do a pwc on every page table page freed.
Note: I also removed the dummy tlb_flush_pgtable call functions for hash 32.
--- arch/powerpc/include/asm/book3s/32/pgalloc.h | 1 - arch/powerpc/include/asm/book3s/64/pgalloc.h | 16 ++++++++++- arch/powerpc/include/asm/book3s/64/tlbflush.h | 1 + arch/powerpc/include/asm/book3s/pgalloc.h | 5 ---- arch/powerpc/mm/tlb-radix.c | 39 +++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/book3s/32/pgalloc.h +0 -1
@@ -102,7 +102,6 @@ static inline void pgtable_free_tlb(struct mmu_gather *tlb,static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address) { -tlb_flush_pgtable (tlb, address);pgtable_page_dtor (table);pgtable_free_tlb (tlb,page_address (table),0 ); }
arch/powerpc/include/asm/book3s/64/pgalloc.h +15 -1
@@ -110,6 +110,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)static inline void __pud_free_tlb (struct mmu_gather *tlb,pud_t *pud,unsigned long address) { +/* +* By now all the pud entries should be none entries. So go +* ahead and flush the page walk cache +*/ +flush_tlb_pgtable (tlb, address);pgtable_free_tlb (tlb, pud,PUD_INDEX_SIZE ); }
@@ -127,6 +132,11 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)static inline void __pmd_free_tlb (struct mmu_gather *tlb,pmd_t *pmd,unsigned long address) { +/* +* By now all the pud entries should be none entries. So go +* ahead and flush the page walk cache +*/ +flush_tlb_pgtable (tlb, address);return pgtable_free_tlb (tlb, pmd,PMD_CACHE_INDEX ); }
@@ -198,7 +208,11 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address) { -tlb_flush_pgtable (tlb, address); +/* +* By now all the pud entries should be none entries. So go +* ahead and flush the page walk cache +*/ +flush_tlb_pgtable (tlb, address);pgtable_free_tlb (tlb, table,0 ); }
arch/powerpc/include/asm/book3s/64/tlbflush.h +1 -0
@@ -73,4 +73,5 @@ static inline void flush_tlb_page(struct vm_area_struct *vma,#define flush_tlb_page (vma, addr) local_flush_tlb_page(vma, addr)#endif /* CONFIG_SMP */ +extern void flush_tlb_pgtable (struct mmu_gather *tlb,unsigned long address);#endif /* _ASM_POWERPC_BOOK3S_64_TLBFLUSH_H */
arch/powerpc/include/asm/book3s/pgalloc.h +0 -5
@@ -4,11 +4,6 @@#include <linux/mm.h> extern void tlb_remove_table (struct mmu_gather *tlb,void *table); -static inline void tlb_flush_pgtable (struct mmu_gather *tlb, -unsigned long address) -{ - -}#ifdef CONFIG_PPC64 #include <asm/book3s/64/pgalloc.h>
arch/powerpc/mm/tlb-radix.c +39 -0
@@ -180,6 +180,30 @@ no_context: }EXPORT_SYMBOL (radix__flush_tlb_mm); +void radix__flush_tlb_mm_pwc (struct mm_struct *mm) +{ +unsigned int pid; + +preempt_disable (); + pid = mm->context.id; +if (unlikely (pid ==MMU_NO_CONTEXT )) + goto no_context; + +if (!mm_is_core_local (mm)) { +int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); + +if (lock_tlbie) +raw_spin_lock (&native_tlbie_lock); +_tlbie_pid (pid,RIC_FLUSH_PWC ); +if (lock_tlbie) +raw_spin_unlock (&native_tlbie_lock); + }else +_tlbiel_pid (pid,RIC_FLUSH_PWC ); +no_context: +preempt_enable (); +} +EXPORT_SYMBOL (radix__flush_tlb_mm_pwc); +void radix___flush_tlb_page (struct mm_struct *mm,unsigned long vmaddr,unsigned long ap,int nid) {
@@ -247,3 +271,18 @@ void radix__tlb_flush(struct mmu_gather *tlb)struct mm_struct *mm = tlb->mm;radix__flush_tlb_mm (mm); } +/* +* flush the page walk cache for the address +*/ +void flush_tlb_pgtable (struct mmu_gather *tlb,unsigned long address) +{ +struct mm_struct *mm = tlb->mm; +/* +* flush the page table walk cache on freeing page table. We already +* have marked the upper/higher level page table entry none by now. +* So it is safe to flush PWC here. +*/ +if (!radix_enabled ()) +return ; +radix__flush_tlb_mm_pwc (mm); +}
Signature · 1 line
2.7.4
Re: [PATCH 3/3] powerpc/mm/radix: Flush page walk cache when freeing page table
Quoted 6 lines · Aneesh Kumar K.V
arch/powerpc/mm/tlb-radix.c +4
-0+/* +* flush the page walk cache for the address +*/ +void flush_tlb_pgtable (struct mmu_gather *tlb,unsigned long address)
arch/powerpc/mm/tlb-radix.c void radix__tlb_flush(struct mmu_gather *tlb) · line 287
Quoted 10 lines
arch/powerpc/mm/tlb-radix.c +10
-0+{ + struct mm_struct *mm = tlb->mm; + /* + * flush the page table walk cache on freeing page table. We already + * have marked the upper/higher level page table entry none by now. + * So it is safe to flush PWC here. + */ + if (!radix_enabled()) + return; + radix__flush_tlb_mm_pwc(mm);
That means that on hash, we pay the price of a useless function call and return. Shouldn't we put the radix_enabled() test in the caller instead ?
Cheers,
Ben.
Re: [PATCH 3/3] powerpc/mm/radix: Flush page walk cache when freeing page table
Quoted 12 lines · Benjamin Herrenschmidt
arch/powerpc/mm/tlb-radix.c void radix__tlb_flush(struct mmu_gather *tlb)
Quoted 8 lines · Aneesh Kumar K.V
=20
=20arch/powerpc/mm/tlb-radix.c +6
-0+/* +* flush the page walk cache for the address +*/ +void flush_tlb_pgtable (struct mmu_gather *tlb,unsigned long address) +{ +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct mm_struct *mm =3D tlb-=mm;
Quoted 2 lines
+=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 * flush the page table walk =
cache on freeing page table. We already
Quoted 1 line
Quoted 1 line
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * have marked the upper/high=
er level page table entry none by now.
Quoted 1 line
Quoted 1 line
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * So it is safe to flush PWC=
here.
Quoted 3 lines
Quoted 3 lines
+=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=A0if (!radix_enabled()) +=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=A0return;
Quoted 6 lines
Quoted 1 line
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0radix__flush_tlb_mm_pwc(mm);
That means that on hash, we pay the price of a useless function call and return. Shouldn't we put the
radix_enabled()test in the caller instead ?
I wil convert that to static inline.
-aneesh