Skip to content

Commit 8ef5cbd

Browse files
kvaneeshtorvalds
authored andcommitted
arch/powerpc/mm/hugetlb: NestMMU workaround for hugetlb mprotect RW upgrade
NestMMU requires us to mark the pte invalid and flush the tlb when we do a RW upgrade of pte. We fixed a variant of this in the fault path in bd5050e ("powerpc/mm/radix: Change pte relax sequence to handle nest MMU hang"). Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Aneesh Kumar K.V <[email protected]> Reviewed-by: Michael Ellerman <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 023bdd0 commit 8ef5cbd

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

arch/powerpc/include/asm/book3s/64/hugetlb.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
1313
unsigned long len, unsigned long pgoff,
1414
unsigned long flags);
1515

16+
extern void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
17+
unsigned long addr, pte_t *ptep,
18+
pte_t old_pte, pte_t pte);
19+
1620
static inline int hstate_get_psize(struct hstate *hstate)
1721
{
1822
unsigned long shift;
@@ -42,4 +46,12 @@ static inline bool gigantic_page_supported(void)
4246
/* hugepd entry valid bit */
4347
#define HUGEPD_VAL_BITS (0x8000000000000000UL)
4448

49+
#define huge_ptep_modify_prot_start huge_ptep_modify_prot_start
50+
extern pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
51+
unsigned long addr, pte_t *ptep);
52+
53+
#define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
54+
extern void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
55+
unsigned long addr, pte_t *ptep,
56+
pte_t old_pte, pte_t new_pte);
4557
#endif

arch/powerpc/mm/hugetlbpage-hash64.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,28 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
121121
*ptep = __pte(new_pte & ~H_PAGE_BUSY);
122122
return 0;
123123
}
124+
125+
pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
126+
unsigned long addr, pte_t *ptep)
127+
{
128+
unsigned long pte_val;
129+
/*
130+
* Clear the _PAGE_PRESENT so that no hardware parallel update is
131+
* possible. Also keep the pte_present true so that we don't take
132+
* wrong fault.
133+
*/
134+
pte_val = pte_update(vma->vm_mm, addr, ptep,
135+
_PAGE_PRESENT, _PAGE_INVALID, 1);
136+
137+
return __pte(pte_val);
138+
}
139+
140+
void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr,
141+
pte_t *ptep, pte_t old_pte, pte_t pte)
142+
{
143+
144+
if (radix_enabled())
145+
return radix__huge_ptep_modify_prot_commit(vma, addr, ptep,
146+
old_pte, pte);
147+
set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
148+
}

arch/powerpc/mm/hugetlbpage-radix.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9090

9191
return vm_unmapped_area(&info);
9292
}
93+
94+
void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
95+
unsigned long addr, pte_t *ptep,
96+
pte_t old_pte, pte_t pte)
97+
{
98+
struct mm_struct *mm = vma->vm_mm;
99+
100+
/*
101+
* To avoid NMMU hang while relaxing access we need to flush the tlb before
102+
* we set the new value.
103+
*/
104+
if (is_pte_rw_upgrade(pte_val(old_pte), pte_val(pte)) &&
105+
(atomic_read(&mm->context.copros) > 0))
106+
radix__flush_hugetlb_page(vma, addr);
107+
108+
set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
109+
}

0 commit comments

Comments
 (0)