arch/powerpc/radix: Fix kernel crash with mremap
PATCH 1/1 arch/powerpc/radix: Fix kernel crash with mremap
With support for split pmd lock, we use pmd page pmd_huge_pte pointer to store the deposited page table. In those config when we move page tables we need to make sure we move the depoisted page table to the right pmd page. Otherwise this can result in crash when we withdraw of deposited page table because we can find the pmd_huge_pte NULL.
c0000000004a1230 __split_huge_pmd+0x1070/0x1940 c0000000004a0ff4 __split_huge_pmd+0xe34/0x1940 (unreliable) c0000000004a4000 vma_adjust_trans_huge+0x110/0x1c0 c00000000042fe04 __vma_adjust+0x2b4/0x9b0 c0000000004316e8 __split_vma+0x1b8/0x280 c00000000043192c __do_munmap+0x13c/0x550 c000000000439390 sys_mremap+0x220/0x7e0 c00000000000b488 system_call+0x5c/0x70
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 22 +++++++------------- arch/powerpc/mm/pgtable-book3s64.c | 22 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +7 -15
@@ -1258,21 +1258,13 @@ extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,#define pmd_move_must_withdraw pmd_move_must_withdrawstruct spinlock ; -static inline int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, -struct spinlock *old_pmd_ptl, -struct vm_area_struct *vma) -{ -if (radix_enabled ()) -return false; -/* -* Archs like ppc64 use pgtable to store per pmd -* specific information. So when we switch the pmd, -* we should also withdraw and deposit the pgtable -*/ -return true; -} - - +extern int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, +struct spinlock *old_pmd_ptl, +struct vm_area_struct *vma); +/* +* Hash translation mode use the deposited table to store hash pte +* slot information. +*/ #define arch_needs_pgtable_deposit arch_needs_pgtable_depositstatic inline bool arch_needs_pgtable_deposit (void ) {
arch/powerpc/mm/pgtable-book3s64.c +22 -0
@@ -425,3 +425,25 @@ void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, ptep, old_pte, pte);set_pte_at (vma->vm_mm, addr, ptep, pte); } + +/* For hash translation mode, we use the deposited table to store +* store hash slot information and they are stored at PTRS_PER_PMD +* offset from related pmd location. Hence a pmd move requires +* deposit and withdraw. + +* For radix translation with split pmd ptl, we store the deposited +* table in the pmd page. Hence if we have different pmd page we need +* to withdraw during pmd move. + +* With hash we use deposited table always irrespective of anon or not. +* With radix we use deposited table only for anonymous mapping. +*/ +int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, +struct spinlock *old_pmd_ptl, +struct vm_area_struct *vma) +{ +if (radix_enabled ()) +return (new_pmd_ptl != old_pmd_ptl) &&vma_is_anonymous (vma); + +return true; +}
Signature · 1 line
2.20.1
Quoted 6 lines · Aneesh Kumar K.V
With support for split pmd lock, we use pmd page
pmd_huge_ptepointer to store the deposited page table. In those config when we move page tables we need to make sure we move the depoisted page table to the right pmd page. Otherwise this can result in crash when we withdraw of deposited page table because we can find thepmd_huge_pteNULL.
Quoted 9 lines
c0000000004a1230__split_huge_pmd+0x1070/0x1940c0000000004a0ff4__split_huge_pmd+0xe34/0x1940(unreliable)c0000000004a4000vma_adjust_trans_huge+0x110/0x1c0c00000000042fe04__vma_adjust+0x2b4/0x9b0c0000000004316e8__split_vma+0x1b8/0x280c00000000043192c__do_munmap+0x13c/0x550c000000000439390sys_mremap+0x220/0x7e0c00000000000b488system_call+0x5c/0x70
This was done on top of "NestMMU pte upgrade workaround for mprotect" series
Quoted 2 lines
Fixes 675d995297d4 ("powerpc/book3s64: Enable split pmd ptlock.")Signed-off-by Aneesh Kumar K.V <[email protected]>
For applying to merge branch you can use the below patch
From 33d28f144d41ecbba074ceefd234983422469e4b Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Mon, 21 Jan 2019 16:43:17 +0530
Subject: [PATCH] arch/powerpc/radix: Fix kernel crash with mremap
With support for split pmd lock, we use pmd page pmd_huge_pte pointer to store the deposited page table. In those config when we move page tables we need to make sure we move the depoisted page table to the right pmd page. Otherwise this can result in crash when we withdraw of deposited page table because we can find the pmd_huge_pte NULL.
c0000000004a1230 __split_huge_pmd+0x1070/0x1940 c0000000004a0ff4 __split_huge_pmd+0xe34/0x1940 (unreliable) c0000000004a4000 vma_adjust_trans_huge+0x110/0x1c0 c00000000042fe04 __vma_adjust+0x2b4/0x9b0 c0000000004316e8 __split_vma+0x1b8/0x280 c00000000043192c __do_munmap+0x13c/0x550 c000000000439390 sys_mremap+0x220/0x7e0 c00000000000b488 system_call+0x5c/0x70
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 22 +++++++------------- arch/powerpc/mm/pgtable-book3s64.c | 22 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +7 -15
@@ -1258,21 +1258,13 @@ extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,#define pmd_move_must_withdraw pmd_move_must_withdrawstruct spinlock ; -static inline int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, -struct spinlock *old_pmd_ptl, -struct vm_area_struct *vma) -{ -if (radix_enabled ()) -return false; -/* -* Archs like ppc64 use pgtable to store per pmd -* specific information. So when we switch the pmd, -* we should also withdraw and deposit the pgtable -*/ -return true; -} - - +extern int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, +struct spinlock *old_pmd_ptl, +struct vm_area_struct *vma); +/* +* Hash translation mode use the deposited table to store hash pte +* slot information. +*/ #define arch_needs_pgtable_deposit arch_needs_pgtable_depositstatic inline bool arch_needs_pgtable_deposit (void ) {
arch/powerpc/mm/pgtable-book3s64.c +22 -0
@@ -400,3 +400,25 @@ void arch_report_meminfo(struct seq_file *m) atomic_long_read(&direct_pages_count[MMU_PAGE_1G]) << 20); }#endif /* CONFIG_PROC_FS */ + +/* For hash translation mode, we use the deposited table to store +* hash slot information and they are stored at PTRS_PER_PMD +* offset from related pmd location. Hence a pmd move requires +* deposit and withdraw. + +* For radix translation with split pmd ptl, we store the deposited +* table in the pmd page. Hence if we have different pmd page we need +* to withdraw during pmd move. + +* With hash we use deposited table always irrespective of anon or not. +* With radix we use deposited table only for anonymous mapping. +*/ +int pmd_move_must_withdraw (struct spinlock *new_pmd_ptl, +struct spinlock *old_pmd_ptl, +struct vm_area_struct *vma) +{ +if (radix_enabled ()) +return (new_pmd_ptl != old_pmd_ptl) &&vma_is_anonymous (vma); + +return true; +}
Signature · 1 line
2.20.1
Michael Ellerman
AppliedQuoted 15 lines · Aneesh Kumar K.V
With support for split pmd lock, we use pmd page
pmd_huge_ptepointer to store the deposited page table. In those config when we move page tables we need to make sure we move the depoisted page table to the right pmd page. Otherwise this can result in crash when we withdraw of deposited page table because we can find thepmd_huge_pteNULL.
c0000000004a1230__split_huge_pmd+0x1070/0x1940c0000000004a0ff4__split_huge_pmd+0xe34/0x1940(unreliable)c0000000004a4000vma_adjust_trans_huge+0x110/0x1c0c00000000042fe04__vma_adjust+0x2b4/0x9b0c0000000004316e8__split_vma+0x1b8/0x280c00000000043192c__do_munmap+0x13c/0x550c000000000439390sys_mremap+0x220/0x7e0c00000000000b488system_call+0x5c/0x70
Quoted 3 lines
Fixes 675d995297d4 ("powerpc/book3s64: Enable split pmd ptlock.")Signed-off-by Aneesh Kumar K.V <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/579b9239c1f38665b21e8d0e6ee83ecc
cheers