powerpc/mm/radix: Move functions from radix.h to pgtable-radix.c
PATCH 1/2 powerpc/mm/radix: Move functions from radix.h to pgtable-radix.c
In later patch we will update them which require them to be moved to pgtable-radix.c Doing the move in separate patch helps in review.
No function change in this patch. Only code movement.
--- arch/powerpc/include/asm/book3s/64/radix.h | 63 +++------------------- arch/powerpc/mm/pgtable-radix.c | 48 +++++++++++++++++ 2 files changed, 54 insertions(+), 57 deletions(-)
arch/powerpc/include/asm/book3s/64/radix.h +6 -57
@@ -124,6 +124,12 @@ extern void radix__mark_rodata_ro(void);extern void radix__mark_initmem_nx (void );#endif +extern unsigned long radix__pte_update (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long clr, +unsigned long set,int huge); +extern void radix__ptep_set_access_flags (struct mm_struct *mm,pte_t *ptep, +pte_t entry,unsigned long address); +static inline unsigned long __radix_pte_update (pte_t *ptep,unsigned long clr,unsigned long set) {
@@ -140,35 +146,6 @@ static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr,return old_pte; } - -static inline unsigned long radix__pte_update (struct mm_struct *mm, -unsigned long addr, -pte_t *ptep,unsigned long clr, -unsigned long set, -int huge) -{ -unsigned long old_pte; - -if (cpu_has_feature (CPU_FTR_POWER9_DD1 )) { - -unsigned long new_pte; - - old_pte =__radix_pte_update (ptep, ~0ul ,0 ); -/* -* new value of pte -*/ - new_pte = (old_pte | set) & ~clr; -radix__flush_tlb_pte_p9_dd1 (old_pte, mm, addr); -if (new_pte) -__radix_pte_update (ptep,0 , new_pte); - }else - old_pte =__radix_pte_update (ptep, clr, set); -if (!huge) -assert_pte_locked (mm, addr); - -return old_pte; -} -static inline pte_t radix__ptep_get_and_clear_full (struct mm_struct *mm,unsigned long addr,pte_t *ptep,int full)
@@ -190,34 +167,6 @@ static inline pte_t radix__ptep_get_and_clear_full(struct mm_struct *mm,return __pte (old_pte); } -/* -* Set the dirty and/or accessed bits atomically in a linux PTE, this -* function doesn't need to invalidate tlb. -*/ -static inline void radix__ptep_set_access_flags (struct mm_struct *mm, -pte_t *ptep,pte_t entry, -unsigned long address) -{ - -unsigned long set =pte_val (entry) & (_PAGE_DIRTY | _PAGE_ACCESSED | - _PAGE_RW | _PAGE_EXEC); - -if (cpu_has_feature (CPU_FTR_POWER9_DD1 )) { - -unsigned long old_pte, new_pte; - - old_pte =__radix_pte_update (ptep, ~0 ,0 ); -/* -* new value of pte -*/ - new_pte = old_pte | set; -radix__flush_tlb_pte_p9_dd1 (old_pte, mm, address); -__radix_pte_update (ptep,0 , new_pte); - }else -__radix_pte_update (ptep,0 , set); - asmvolatile ("ptesync" : : :"memory" ); -} -static inline int radix__pte_same (pte_t pte_a,pte_t pte_b) {return ((pte_raw (pte_a) ^pte_raw (pte_b)) ==0 );
arch/powerpc/mm/pgtable-radix.c +48 -0
51 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 2/2 powerpc/mm/radix: Change pte relax sequence to handle nest MMU hang
When relaxing access (read -> read_write update), pte need to be marked invalid to handle a nest MMU bug. We also need to do a tlb flush after the pte is marked invalid before updating the pte with new access bits.
We also move tlb flush to platform specific __ptep_set_access_flags. This will help us to gerid of unnecessary tlb flush on BOOK3S 64 later. We don't do that in this patch. This also helps in avoiding multiple tlbies with coprocessor attached.
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 8 ++++++-- arch/powerpc/include/asm/book3s/64/pgtable.h | 8 +++++--- arch/powerpc/include/asm/book3s/64/radix.h | 5 +++-- arch/powerpc/include/asm/nohash/32/pgtable.h | 7 +++++-- arch/powerpc/include/asm/nohash/64/pgtable.h | 7 +++++-- arch/powerpc/mm/pgtable-book3s64.c | 9 ++++++--- arch/powerpc/mm/pgtable-radix.c | 20 +++++++++++++------- arch/powerpc/mm/pgtable.c | 11 ++++++----- 8 files changed, 49 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +6 -2
@@ -235,15 +235,19 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, } -static inline void __ptep_set_access_flags (struct mm_struct *mm, +static inline void __ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep,pte_t entry, -unsigned long address) +unsigned long address, +int psize) {unsigned long set =pte_val (entry) & (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);unsigned long clr = ~pte_val (entry) & _PAGE_RO;pte_update (ptep, clr, set); + +flush_tlb_page (vma, address); + }#define __HAVE_ARCH_PTE_SAME
arch/powerpc/include/asm/book3s/64/pgtable.h +5 -3
@@ -767,12 +767,14 @@ static inline bool check_pte_access(unsigned long access, unsigned long ptev)* Generic functions with hash/radix callbacks */ -static inline void __ptep_set_access_flags (struct mm_struct *mm, +static inline void __ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep,pte_t entry, -unsigned long address) +unsigned long address, +int psize) {if (radix_enabled ()) -return radix__ptep_set_access_flags (mm, ptep, entry, address); +return radix__ptep_set_access_flags (vma, ptep, entry, + address, psize);return hash__ptep_set_access_flags (ptep, entry); }
arch/powerpc/include/asm/book3s/64/radix.h +3 -2
@@ -127,8 +127,9 @@ extern void radix__mark_initmem_nx(void);extern unsigned long radix__pte_update (struct mm_struct *mm,unsigned long addr,pte_t *ptep,unsigned long clr,unsigned long set,int huge); -extern void radix__ptep_set_access_flags (struct mm_struct *mm,pte_t *ptep, -pte_t entry,unsigned long address); +extern void radix__ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep, +pte_t entry,unsigned long address, +int psize);static inline unsigned long __radix_pte_update (pte_t *ptep,unsigned long clr,unsigned long set)
arch/powerpc/include/asm/nohash/32/pgtable.h +5 -2
@@ -256,15 +256,18 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, } -static inline void __ptep_set_access_flags (struct mm_struct *mm, +static inline void __ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep,pte_t entry, -unsigned long address) +unsigned long address, +int psize) {unsigned long set =pte_val (entry) & (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);unsigned long clr = ~pte_val (entry) & (_PAGE_RO | _PAGE_NA);pte_update (ptep, clr, set); + +flush_tlb_page (vma, address); }static inline int pte_young (pte_t pte)
arch/powerpc/include/asm/nohash/64/pgtable.h +5 -2
@@ -281,9 +281,10 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr,/* Set the dirty and/or accessed bits atomically in a linux PTE, this * function doesn't need to flush the hash entry */ -static inline void __ptep_set_access_flags (struct mm_struct *mm, +static inline void __ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep,pte_t entry, -unsigned long address) +unsigned long address, +int psize) {unsigned long bits =pte_val (entry) & (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
@@ -303,6 +304,8 @@ static inline void __ptep_set_access_flags(struct mm_struct *mm,unsigned long old =pte_val (*ptep); *ptep =__pte (old | bits);#endif + +flush_tlb_page (vma, address); }#define __HAVE_ARCH_PTE_SAME
arch/powerpc/mm/pgtable-book3s64.c +6 -3
@@ -46,9 +46,12 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address,#endif changed = !pmd_same (*(pmdp), entry);if (changed) { -__ptep_set_access_flags (vma->vm_mm,pmdp_ptep (pmdp), -pmd_pte (entry), address); -flush_pmd_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); +/* +* We can use MMU_PAGE_2M here, because only radix +* path look at the psize. +*/ +__ptep_set_access_flags (vma,pmdp_ptep (pmdp), +pmd_pte (entry), address,MMU_PAGE_2M ); }return changed; }
arch/powerpc/mm/pgtable-radix.c +13 -7
@@ -1111,14 +1111,18 @@ unsigned long radix__pte_update(struct mm_struct *mm, unsigned long addr,return old_pte; } -void radix__ptep_set_access_flags (struct mm_struct *mm, -pte_t *ptep,pte_t entry, -unsigned long address) +void radix__ptep_set_access_flags (struct vm_area_struct *vma,pte_t *ptep, +pte_t entry,unsigned long address,int psize) { +struct mm_struct *mm = vma->vm_mm;unsigned long set =pte_val (entry) & (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC); - -if (cpu_has_feature (CPU_FTR_POWER9_DD1 )) { +/* +* To avoid NMMU hang while relaxing access, we need mark +* the pte invalid in between. +*/ +if (cpu_has_feature (CPU_FTR_POWER9_DD1 ) || +atomic_read (&mm->context.copros) >0 ) {unsigned long old_pte, new_pte; old_pte =__radix_pte_update (ptep, ~0 ,0 );
@@ -1126,9 +1130,11 @@ void radix__ptep_set_access_flags(struct mm_struct *mm,* new value of pte */ new_pte = old_pte | set; -radix__flush_tlb_pte_p9_dd1 (old_pte, mm, address); +radix__flush_tlb_page_psize (mm, address, psize);__radix_pte_update (ptep,0 , new_pte); - }else + }else {__radix_pte_update (ptep,0 , set); +radix__flush_tlb_page_psize (mm, address, psize); + } asmvolatile ("ptesync" : : :"memory" ); }
arch/powerpc/mm/pgtable.c +6 -5
@@ -222,8 +222,8 @@ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, changed = !pte_same (*(ptep), entry);if (changed) {assert_pte_locked (vma->vm_mm, address); -__ptep_set_access_flags (vma->vm_mm, ptep, entry, address); -flush_tlb_page (vma, address); +__ptep_set_access_flags (vma, ptep, entry, + address, mmu_virtual_psize); }return changed; }
@@ -242,7 +242,8 @@ extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,ptep_set_access_flags (vma, addr, ptep, pte, dirty);return 1 ;#else -int changed; +int changed, psize; +struct hstate *hstate =hstate_file (vma->vm_file); pte =set_access_flags_filter (pte, vma, dirty); changed = !pte_same (*(ptep), pte);
@@ -250,8 +251,8 @@ extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,#ifdef CONFIG_DEBUG_VM assert_spin_locked (&vma->vm_mm->page_table_lock);#endif -__ptep_set_access_flags (vma->vm_mm, ptep, pte, addr); - flush_hugetlb_page(vma, addr); + psize =hstate_get_psize (hstate); + __ptep_set_access_flags(vma, ptep, pte, addr, psize); }return changed;#endif
Signature · 1 line
2.17.0
Nicholas Piggin
reviewerRe: [PATCH 2/2] powerpc/mm/radix: Change pte relax sequence to handle nest MMU hang
Quoted 10 lines · On Fri, 25 May 2018 21:19:17 +0530 "Aneesh Kumar K.V"…
When relaxing access (read ->
read_writeupdate), pte need to be marked invalid to handle a nest MMU bug. We also need to do a tlb flush after the pte is marked invalid before updating the pte with new access bits.We also move tlb flush to platform specific
__ptep_set_access_flags. This will help us to gerid of unnecessary tlb flush on BOOK3S 64 later. We don't do that in this patch. This also helps in avoiding multiple tlbies with coprocessor attached.Signed-off-by Aneesh Kumar K.V <[email protected]>
I think these look good to me, but same comment: can you split the API change from the NMMU fix? The fix is just a couple of lines, and the rest of the API change should leave generated code almost unchanged, so it would be easier to review if these are split.
Thanks,
Nick