powerpc: Fix random application crashes with NUMA_BALANCING enabled
Subsystems (5)
cover powerpc: Fix random application crashes with NUMA_BALANCING enabled
Hello,
This patch series fix random application crashes observed on ppc64 with numa balancing enabled. Without the patch we see crashes like
anacron[14551]: unhandled signal 11 at 0000000000000041 nip 000000003cfd54b4 lr 000000003cfd5464 code 30001 anacron[14599]: unhandled signal 11 at 0000000000000041 nip 000000003efc54b4 lr 000000003efc5464 code 30001
-aneesh
PATCH 1/3 powerpc: mm: Add new set flag argument to pte/pmd update function
From: "Aneesh Kumar K.V" <[email protected]>
We will use this later to set the _PAGE_NUMA bit.
--- arch/powerpc/include/asm/hugetlb.h | 2 +- arch/powerpc/include/asm/pgtable-ppc64.h | 26 +++++++++++++++----------- arch/powerpc/mm/pgtable_64.c | 12 +++++++----- arch/powerpc/mm/subpage-prot.c | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/hugetlb.h +1 -1
@@ -127,7 +127,7 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { #ifdef CONFIG_PPC64 - return __pte(pte_update(mm, addr, ptep, ~0UL, 1)); + return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));#else return __pte (pte_update (ptep, ~0UL ,0 ));#endif
arch/powerpc/include/asm/pgtable-ppc64.h +15 -11
@@ -195,6 +195,7 @@ extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,static inline unsigned long pte_update (struct mm_struct *mm,unsigned long addr,pte_t *ptep,unsigned long clr, +unsigned long set,int huge) {#ifdef PTE_ATOMIC_UPDATES
@@ -205,14 +206,15 @@ static inline unsigned long pte_update(struct mm_struct *mm, andi. %1,%0,%6\n\ bne- 1b \n\ andc %1,%0,%4 \n\ + or %1,%1,%7\n\ stdcx. %1,0,%3 \n\ bne- 1b" : "=&r" (old), "=&r" (tmp), "=m" (*ptep) - : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY) + : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY), "r" (set) : "cc" );#else unsigned long old =pte_val (*ptep); - *ptep =__pte (old & ~clr); + *ptep =__pte ((old & ~clr) | set);#endif /* huge pages use the old page table lock */ if (!huge)
@@ -231,9 +233,9 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm, {unsigned long old; -if ((pte_val (*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 ) +if ((pte_val (*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 )return 0 ; - old =pte_update (mm, addr, ptep, _PAGE_ACCESSED,0 ); + old =pte_update (mm, addr, ptep, _PAGE_ACCESSED,0 ,0 );return (old & _PAGE_ACCESSED) !=0 ; }#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
@@ -252,7 +254,7 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,if ((pte_val (*ptep) & _PAGE_RW) ==0 )return ; -pte_update (mm, addr, ptep, _PAGE_RW,0 ); +pte_update (mm, addr, ptep, _PAGE_RW,0 ,0 ); } static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
@@ -261,7 +263,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,if ((pte_val (*ptep) & _PAGE_RW) ==0 )return ; -pte_update (mm, addr, ptep, _PAGE_RW,1 ); +pte_update (mm, addr, ptep, _PAGE_RW,0 ,1 ); }/*
@@ -284,14 +286,14 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) { -unsigned long old =pte_update (mm, addr, ptep, ~0UL ,0 ); +unsigned long old =pte_update (mm, addr, ptep, ~0UL ,0 ,0 );return __pte (old); }static inline void pte_clear (struct mm_struct *mm,unsigned long addr,pte_t * ptep) { -pte_update (mm, addr, ptep, ~0UL ,0 ); +pte_update (mm, addr, ptep, ~0UL ,0 ,0 ); }
@@ -506,7 +508,9 @@ extern int pmdp_set_access_flags(struct vm_area_struct *vma,extern unsigned long pmd_hugepage_update (struct mm_struct *mm,unsigned long addr, -pmd_t *pmdp,unsigned long clr); +pmd_t *pmdp, +unsigned long clr, +unsigned long set);static inline int __pmdp_test_and_clear_young (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp)
@@ -515,7 +519,7 @@ static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,if ((pmd_val (*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 )return 0 ; - old =pmd_hugepage_update (mm, addr, pmdp, _PAGE_ACCESSED); + old =pmd_hugepage_update (mm, addr, pmdp, _PAGE_ACCESSED,0 );return ((old & _PAGE_ACCESSED) !=0 ); }
@@ -542,7 +546,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr,if ((pmd_val (*pmdp) & _PAGE_RW) ==0 )return ; -pmd_hugepage_update (mm, addr, pmdp, _PAGE_RW); +pmd_hugepage_update (mm, addr, pmdp, _PAGE_RW,0 ); }#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
arch/powerpc/mm/pgtable_64.c +7 -5
@@ -510,7 +510,8 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, }unsigned long pmd_hugepage_update (struct mm_struct *mm,unsigned long addr, -pmd_t *pmdp,unsigned long clr) +pmd_t *pmdp,unsigned long clr, +unsigned long set) {unsigned long old, tmp;
@@ -526,14 +527,15 @@ unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, andi. %1,%0,%6\n\ bne- 1b \n\ andc %1,%0,%4 \n\ + or %1,%1,%7\n\ stdcx. %1,0,%3 \n\ bne- 1b" : "=&r" (old), "=&r" (tmp), "=m" (*pmdp) - : "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY) + : "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY), "r" (set) : "cc" );#else old =pmd_val (*pmdp); - *pmdp =__pmd (old & ~clr); + *pmdp =__pmd ((old & ~clr) | set);#endif if (old & _PAGE_HASHPTE)hpte_do_hugepage_flush (mm, addr, pmdp);
@@ -708,7 +710,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp) { -pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT); +pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT,0 ); }/*
@@ -835,7 +837,7 @@ pmd_t pmdp_get_and_clear(struct mm_struct *mm,unsigned long old;pgtable_t *pgtable_slot; - old =pmd_hugepage_update (mm, addr, pmdp, ~0UL ); + old =pmd_hugepage_update (mm, addr, pmdp, ~0UL ,0 ); old_pmd =__pmd (old);/* * We have pmd == none and we are holding page_table_lock.
arch/powerpc/mm/subpage-prot.c +1 -1
@@ -78,7 +78,7 @@ static void hpte_flush_range(struct mm_struct *mm, unsigned long addr, pte =pte_offset_map_lock (mm, pmd, addr, &ptl);arch_enter_lazy_mmu_mode ();for (; npages >0 ; --npages) { -pte_update (mm, addr, pte,0 ,0 ); +pte_update (mm, addr, pte,0 ,0 ,0 ); addr +=PAGE_SIZE ; ++pte; }
Signature · 1 line
1.8.3.2
Re: [PATCH 1/3] powerpc: mm: Add new set flag argument to pte/pmd update function
Quoted 5 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We will use this later to set the
_PAGE_NUMAbit.Signed-off-by Aneesh Kumar K.V <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/3] powerpc: mm: Add new set flag argument to pte/pmd update function
In reply to Aneesh Kumar K.VQuoted 5 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We will use this later to set the
_PAGE_NUMAbit.Signed-off-by Aneesh Kumar K.V <[email protected]>
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 mm: dirty accountable change only apply to non prot numa case
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
So move it within the if loop
--- mm/mprotect.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
mm/mprotect.c +7 -14
@@ -58,6 +58,13 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,if (pte_numa (ptent)) ptent =pte_mknonnuma (ptent); ptent =pte_modify (ptent, newprot); +/* +* Avoid taking write faults for pages we +* know to be dirty. +*/ +if (dirty_accountable &&pte_dirty (ptent)) + ptent =pte_mkwrite (ptent); +ptep_modify_prot_commit (mm, addr, pte, ptent); updated = true; }else {struct page *page;
@@ -72,22 +79,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, } } } - -/* -* Avoid taking write faults for pages we know to be -* dirty. -*/ -if (dirty_accountable &&pte_dirty (ptent)) { - ptent =pte_mkwrite (ptent); - updated = true; - } -if (updated) pages++; - -/* Only !prot_numa always clears the pte */ -if (!prot_numa) -ptep_modify_prot_commit (mm, addr, pte, ptent); }else if (IS_ENABLED (CONFIG_MIGRATION ) && !pte_file (oldpte)) {swp_entry_t entry =pte_to_swp_entry (oldpte);
Signature · 1 line
1.8.3.2
Re: [PATCH 2/3] mm: dirty accountable change only apply to non prot numa case
Quoted 5 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
So move it within the if loop
Signed-off-by Aneesh Kumar K.V <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] mm: dirty accountable change only apply to non prot numa case
In reply to Aneesh Kumar K.VQuoted 5 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
So move it within the if loop
Signed-off-by Aneesh Kumar K.V <[email protected]>
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 mm: Use ptep/pmdp_set_numa for updating _PAGE_NUMA bit
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Archs like ppc64 doesn't do tlb flush in set_pte/pmd functions. ppc64 also doesn't implement flush_tlb_range. ppc64 require the tlb flushing to be batched within ptl locks. The reason to do that is to ensure that the hash page table is in sync with linux page table. We track the hpte index in linux pte and if we clear them without flushing hash and drop the ptl lock, we can have another cpu update the pte and can end up with double hash. We also want to keep set_pte_at simpler by not requiring them to do hash flush for performance reason. Hence cannot use them while updating _PAGE_NUMA bit. Add new functions for marking pte/pmd numa
--- arch/powerpc/include/asm/pgtable.h | 22 ++++++++++++++++++++++ include/asm-generic/pgtable.h | 24 ++++++++++++++++++++++++ mm/huge_memory.c | 9 ++------- mm/mprotect.c | 4 +--- 4 files changed, 49 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/pgtable.h +22 -0
@@ -75,12 +75,34 @@ static inline pte_t pte_mknuma(pte_t pte)return pte; } +#define ptep_set_numa ptep_set_numa +static inline void ptep_set_numa (struct mm_struct *mm,unsigned long addr, +pte_t *ptep) +{ +if ((pte_val (*ptep) & _PAGE_PRESENT) ==0 ) +VM_BUG_ON (1 ); + +pte_update (mm, addr, ptep, _PAGE_PRESENT, _PAGE_NUMA,0 ); +return ; +} +#define pmd_numa pmd_numastatic inline int pmd_numa (pmd_t pmd) {return pte_numa (pmd_pte (pmd)); } +#define pmdp_set_numa pmdp_set_numa +static inline void pmdp_set_numa (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp) +{ +if ((pmd_val (*pmdp) & _PAGE_PRESENT) ==0 ) +VM_BUG_ON (1 ); + +pmd_hugepage_update (mm, addr, pmdp, _PAGE_PRESENT, _PAGE_NUMA); +return ; +} +#define pmd_mknonnuma pmd_mknonnumastatic inline pmd_t pmd_mknonnuma (pmd_t pmd) {
include/asm-generic/pgtable.h +24 -0
@@ -669,6 +669,18 @@ static inline int pmd_numa(pmd_t pmd) }#endif +#ifndef pmdp_set_numa +static inline void pmdp_set_numa (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp) +{ +pmd_t pmd = *pmdp; + + pmd =pmd_mknuma (entry); +set_pmd_at (mm, addr, pmdp, pmd); +return ; +} +#endif +/* * pte/pmd_mknuma sets the _PAGE_ACCESSED bitflag automatically * because they're called by the NUMA hinting minor page fault. If we
@@ -701,6 +713,18 @@ static inline pte_t pte_mknuma(pte_t pte) }#endif +#ifndef ptep_set_numa +static inline void ptep_set_numa (struct mm_struct *mm,unsigned long addr, +pte_t *ptep) +{ +pte_t ptent = *ptep; + + ptent =pte_mknuma (ptent); +set_pte_at (mm, addr, ptep, ptent); +return ; +} +#endif +#ifndef pmd_mknumastatic inline pmd_t pmd_mknuma (pmd_t pmd) {
mm/huge_memory.c +2 -7
@@ -1545,6 +1545,7 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, entry =pmd_mknonnuma (entry); entry =pmd_modify (entry, newprot); ret =HPAGE_PMD_NR ; +set_pmd_at (mm, addr, pmd, entry);BUG_ON (pmd_write (entry)); }else {struct page *page =pmd_page (*pmd);
@@ -1557,16 +1558,10 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,*/ if (!is_huge_zero_page (page) && !pmd_numa (*pmd)) { - entry = *pmd; - entry =pmd_mknuma (entry); +pmdp_set_numa (mm, addr, pmd); ret =HPAGE_PMD_NR ; } } - -/* Set PMD if cleared earlier */ -if (ret ==HPAGE_PMD_NR ) -set_pmd_at (mm, addr, pmd, entry); -spin_unlock (ptl); }
mm/mprotect.c +1 -3
@@ -69,12 +69,10 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, }else {struct page *page; - ptent = *pte; page =vm_normal_page (vma, addr, oldpte);if (page && !PageKsm (page)) {if (!pte_numa (oldpte)) { - ptent =pte_mknuma (ptent); -set_pte_at (mm, addr, pte, ptent); +ptep_set_numa (mm, addr, pte); updated = true; } }
Signature · 1 line
1.8.3.2
Re: [PATCH 3/3] mm: Use ptep/pmdp_set_numa for updating _PAGE_NUMA bit
Quoted 11 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Archs like ppc64 doesn't do tlb flush in set_pte/pmd functions. ppc64 also doesn't implement
flush_tlb_range. ppc64 require the tlb flushing to be batched within ptl locks. The reason to do that is to ensure that the hash page table is in sync with linux page table. We track the hpte index in linux pte and if we clear them without flushing hash and drop the ptl lock, we can have another cpu update the pte and can end up with double hash. We also want to keepset_pte_atsimpler by not requiring them to do hash flush for performance reason. Hence cannot use them while updating_PAGE_NUMAbit. Add new functions for marking pte/pmd numaSigned-off-by Aneesh Kumar K.V <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] mm: Use ptep/pmdp_set_numa for updating _PAGE_NUMA bit
In reply to Aneesh Kumar K.VQuoted 11 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Archs like ppc64 doesn't do tlb flush in set_pte/pmd functions. ppc64 also doesn't implement
flush_tlb_range. ppc64 require the tlb flushing to be batched within ptl locks. The reason to do that is to ensure that the hash page table is in sync with linux page table. We track the hpte index in linux pte and if we clear them without flushing hash and drop the ptl lock, we can have another cpu update the pte and can end up with double hash. We also want to keepset_pte_atsimpler by not requiring them to do hash flush for performance reason. Hence cannot use them while updating_PAGE_NUMAbit. Add new functions for marking pte/pmd numaSigned-off-by Aneesh Kumar K.V <[email protected]>
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] mm: Use ptep/pmdp_set_numa for updating _PAGE_NUMA bit
Quoted 11 lines · Mel Gorman
Quoted 10 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Archs like ppc64 doesn't do tlb flush in set_pte/pmd functions. ppc64 also doesn't implement
flush_tlb_range. ppc64 require the tlb flushing to be batched within ptl locks. The reason to do that is to ensure that the hash page table is in sync with linux page table. We track the hpte index in linux pte and if we clear them without flushing hash and drop the ptl lock, we can have another cpu update the pte and can end up with double hash. We also want to keepset_pte_atsimpler by not requiring them to do hash flush for performance reason. Hence cannot use them while updating_PAGE_NUMAbit. Add new functions for marking pte/pmd numa
Quoted 4 lines
Quoted 1 line
Signed-off-by Aneesh Kumar K.V <[email protected]>Acked-by Mel Gorman <[email protected]>
How do you guys want me to proceed ? Will you (or Andrew) send these to Linus or should I do it myself ?
Cheers,
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>