powerpc/mm: Fix Multi hit ERAT cause by recent THP update
Subsystems (4)
PATCH 1/1 powerpc/mm: Fix Multi hit ERAT cause by recent THP update
With ppc64 we use the deposted pgtable_t to store the hash pte slot information. We should not withdraw the deposited pgtable_t without marking the pmd none. This ensure that low level hash fault handling will skip this huge pte and we will handle them at upper levels. We do take page table lock there and we can serialize against a parallel THP split there. Hence mark the pte none (ie, remove __PAGE_USER) before splitting the huge pmd.
Also make sure we wait for irq disable section in other cpus to finish before flipping a huge pte entry with a regular pmd entry. Code paths like find_linux_pte_or_hugepte depend on irq disable to get a stable pte_t pointer. A parallel thp split need to make sure we don't convert a pmd pte to a regular pmd entry without waiting for the irq disable section to finish.
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++++ arch/powerpc/mm/pgtable_64.c | 36 +++++++++++++++++++++++++++- include/asm-generic/pgtable.h | 8 +++++++ mm/huge_memory.c | 1 + 4 files changed, 48 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +4 -0
@@ -281,6 +281,10 @@ extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);extern void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp); +#define __HAVE_ARCH_PMDP_HUGE_SPLITTING_FLUSH +extern void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp); +#define pmd_move_must_withdraw pmd_move_must_withdrawstruct spinlock ; static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
arch/powerpc/mm/pgtable_64.c +35 -1
@@ -646,6 +646,31 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)return pgtable; } +void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp) +{ +VM_BUG_ON (address & ~HPAGE_PMD_MASK ); + +#ifdef CONFIG_DEBUG_VM +BUG_ON (REGION_ID (address) !=USER_REGION_ID ); +#endif +/* +* We can't mark the pmd none here, because that will cause a race +* against exit_mmap. We need to continue mark pmd TRANS HUGE, while +* we spilt, but at the same time we wan't rest of the ppc64 code +* not to insert hash pte on this, because we will be modifying +* the deposited pgtable in the caller of this function. Hence +* clear the _PAGE_USER so that we move the fault handling to +* higher level function and that will serialize against ptl. +* We need to flush existing hash pte entries here even though, +* the translation is still valid, because we will withdraw +* pgtable_t after this. +*/ +pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_USER,0 ); +return ; +} + +/* * set a new huge pmd. We should not be called for updating * an existing pmd entry. That should go via pmd_hugepage_update.
@@ -663,10 +688,19 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,return set_pte_at (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd)); } +/* +* We use this to invalidate a pmdp entry before switching from a +* hugepte to regular pmd entry. +*/ void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp) { -pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT,0 ); +pmd_hugepage_update (vma->vm_mm, address, pmdp, ~0UL ,0 ); +/* +* This ensures that generic code that rely on IRQ disabling +* to prevent a parallel THP split work as expected. +*/ +kick_all_cpus_sync (); }/*
include/asm-generic/pgtable.h +8 -0
@@ -239,6 +239,14 @@ extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp);#endif +#ifndef __HAVE_ARCH_PMDP_HUGE_SPLITTING_FLUSH +static inline void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp) +{ +return ; +} +#endif +#ifndef __HAVE_ARCH_PTE_SAMEstatic inline int pte_same (pte_t pte_a,pte_t pte_b) {
mm/huge_memory.c +1 -0
@@ -2860,6 +2860,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, young =pmd_young (*pmd); dirty =pmd_dirty (*pmd); +pmdp_huge_splitting_flush (vma, haddr, pmd); pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmd_populate (mm, &_pmd, pgtable);
Signature · 1 line
2.5.0
Quoted 8 lines · Aneesh Kumar K.V
With ppc64 we use the deposted
pgtable_tto store the hash pte slot information. We should not withdraw the depositedpgtable_twithout marking the pmd none. This ensure that low level hash fault handling will skip this huge pte and we will handle them at upper levels. We do take page table lock there and we can serialize against a parallel THP split there. Hence mark the pte none (ie, remove__PAGE_USER) before splitting the huge pmd.
Quoted 8 lines
Also make sure we wait for irq disable section in other cpus to finish before flipping a huge pte entry with a regular pmd entry. Code paths like
find_linux_pte_or_hugeptedepend on irq disable to get a stablepte_tpointer. A parallel thp split need to make sure we don't convert a pmd pte to a regular pmd entry without waiting for the irq disable section to finish.Signed-off-by Aneesh Kumar K.V <[email protected]>
Cc list is too short. At least akpm@ and linux-mm@ should be there. Probably numa balancing folks.
Have you tested it with CONFIG_NUMA_BALANCING disabled?
I would expect some additional changes in this area would be required. pmd_protnone() is always zero without numa balancing compiled in and therefore I don't see where we will get this serialization agians ptl on fault side.
Quoted 12 lines
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++++ arch/powerpc/mm/pgtable_64.c | 36 +++++++++++++++++++++++++++- include/asm-generic/pgtable.h | 8 +++++++ mm/huge_memory.c | 1 + 4 files changed, 48 insertions(+), 1 deletion(-)arch/powerpc/include/asm/book3s/64/pgtable.h +0
-0
arch/powerpc/include/asm/book3s/64/pgtable.h extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); · line 286
Quoted 6 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +3
-0@@ -281,6 +281,10 @@ extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);extern void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp); +#define __HAVE_ARCH_PMDP_HUGE_SPLITTING_FLUSH +extern void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp);
I don't really like the name, but cannot think of anything better.
Quoted 95 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +1
-0+#define pmd_move_must_withdraw pmd_move_must_withdrawstruct spinlock ; static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,arch/powerpc/mm/pgtable_64.c +35
-1@@ -646,6 +646,31 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)return pgtable; } +void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp) +{ +VM_BUG_ON (address & ~HPAGE_PMD_MASK ); + +#ifdef CONFIG_DEBUG_VM +BUG_ON (REGION_ID (address) !=USER_REGION_ID ); +#endif +/* +* We can't mark the pmd none here, because that will cause a race +* against exit_mmap. We need to continue mark pmd TRANS HUGE, while +* we spilt, but at the same time we wan't rest of the ppc64 code +* not to insert hash pte on this, because we will be modifying +* the deposited pgtable in the caller of this function. Hence +* clear the _PAGE_USER so that we move the fault handling to +* higher level function and that will serialize against ptl. +* We need to flush existing hash pte entries here even though, +* the translation is still valid, because we will withdraw +* pgtable_t after this. +*/ +pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_USER,0 ); +return ; +} + +/* * set a new huge pmd. We should not be called for updating * an existing pmd entry. That should go via pmd_hugepage_update. @@ -663,10 +688,19 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,return set_pte_at (mm, addr,pmdp_ptep (pmdp),pmd_pte (pmd)); } +/* +* We use this to invalidate a pmdp entry before switching from a +* hugepte to regular pmd entry. +*/ void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp) { -pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT,0 ); +pmd_hugepage_update (vma->vm_mm, address, pmdp, ~0UL ,0 ); +/* +* This ensures that generic code that rely on IRQ disabling +* to prevent a parallel THP split work as expected. +*/ +kick_all_cpus_sync (); }/* include/asm-generic/pgtable.h +8
-0@@ -239,6 +239,14 @@ extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp);#endif +#ifndef __HAVE_ARCH_PMDP_HUGE_SPLITTING_FLUSH +static inline void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp) +{ +return ; +} +#endif +#ifndef __HAVE_ARCH_PTE_SAMEstatic inline int pte_same (pte_t pte_a,pte_t pte_b) {mm/huge_memory.c +1
-0@@ -2860,6 +2860,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, young =pmd_young (*pmd); dirty =pmd_dirty (*pmd); +pmdp_huge_splitting_flush (vma, haddr, pmd); pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmd_populate (mm, &_pmd, pgtable);Signature · 1 line
2.5.0
Signature · 1 line
Kirill A. Shutemov
Quoted 16 lines · Kirill A. Shutemov
Quoted 15 lines · Aneesh Kumar K.V
With ppc64 we use the deposted
pgtable_tto store the hash pte slot information. We should not withdraw the depositedpgtable_twithout marking the pmd none. This ensure that low level hash fault handling will skip this huge pte and we will handle them at upper levels. We do take page table lock there and we can serialize against a parallel THP split there. Hence mark the pte none (ie, remove__PAGE_USER) before splitting the huge pmd.Also make sure we wait for irq disable section in other cpus to finish before flipping a huge pte entry with a regular pmd entry. Code paths like
find_linux_pte_or_hugeptedepend on irq disable to get a stablepte_tpointer. A parallel thp split need to make sure we don't convert a pmd pte to a regular pmd entry without waiting for the irq disable section to finish.
Quoted 4 lines
Quoted 1 line
Signed-off-by Aneesh Kumar K.V <[email protected]>Cc list is too short. At least akpm@ and linux-mm@ should be there. Probably numa balancing folks.
Will add them in the next iteration.
Quoted 2 lines
Have you tested it with
CONFIG_NUMA_BALANCINGdisabled?
yes.
Quoted 5 lines
I would expect some additional changes in this area would be required.
pmd_protnone()is always zero without numa balancing compiled in and therefore I don't see where we will get this serialization agians ptl on fault side.
I am not really depending on the pmd_protnone definition here. The thing that I am depending with respect to the core code is that after taking ptl, all the code path should check for pmd using pmd_same. If found not matching they should force a retry. All code path within pmd_trans_huge() check seem to do so.
Quoted 16 lines
Quoted 16 lines
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++++ arch/powerpc/mm/pgtable_64.c | 36 +++++++++++++++++++++++++++- include/asm-generic/pgtable.h | 8 +++++++ mm/huge_memory.c | 1 + 4 files changed, 48 insertions(+), 1 deletion(-)arch/powerpc/include/asm/book3s/64/pgtable.h +0
-0@@ -281,6 +281,10 @@ extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);extern void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp);
Quoted 5 lines
arch/powerpc/include/asm/book3s/64/pgtable.h extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); · line 286
Quoted 3 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +3
-0+#define __HAVE_ARCH_PMDP_HUGE_SPLITTING_FLUSH +extern void pmdp_huge_splitting_flush (struct vm_area_struct *vma, +unsigned long address,pmd_t *pmdp);I don't really like the name, but cannot think of anything better.
same here. I will keep this as it is for now. ?
Quoted 12 lines
arch/powerpc/mm/pgtable_64.c pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp) · line 647
Quoted 12 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +1
-0+#define pmd_move_must_withdraw pmd_move_must_withdrawstruct spinlock ; static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,arch/powerpc/mm/pgtable_64.c +0
-0@@ -646,6 +646,31 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)return pgtable; }
-aneesh