Skip to content

Commit db110a9

Browse files
kvaneeshtorvalds
authored andcommitted
mm/hugetlb: fix kernel crash with hugetlb mremap
This fixes the below crash: kernel BUG at include/linux/mm.h:2373! cpu 0x5d: Vector: 700 (Program Check) at [c00000003c6e76e0] pc: c000000000581a54: pmd_to_page+0x54/0x80 lr: c00000000058d184: move_hugetlb_page_tables+0x4e4/0x5b0 sp: c00000003c6e7980 msr: 9000000000029033 current = 0xc00000003bd8d980 paca = 0xc000200fff610100 irqmask: 0x03 irq_happened: 0x01 pid = 9349, comm = hugepage-mremap kernel BUG at include/linux/mm.h:2373! move_hugetlb_page_tables+0x4e4/0x5b0 (link register) move_hugetlb_page_tables+0x22c/0x5b0 (unreliable) move_page_tables+0xdbc/0x1010 move_vma+0x254/0x5f0 sys_mremap+0x7c0/0x900 system_call_exception+0x160/0x2c0 the kernel can't use huge_pte_offset before it set the pte entry because a page table lookup check for huge PTE bit in the page table to differentiate between a huge pte entry and a pointer to pte page. A huge_pte_alloc won't mark the page table entry huge and hence kernel should not use huge_pte_offset after a huge_pte_alloc. Link: https://lkml.kernel.org/r/20220211063221.99293-1-aneesh.kumar@linux.ibm.com Fixes: 550a7d6 ("mm, hugepages: add mremap() support for hugepage backed vma") Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Mina Almasry <almasrymina@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bbcf7b0 commit db110a9

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

mm/hugetlb.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,14 +4851,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
48514851
}
48524852

48534853
static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
4854-
unsigned long new_addr, pte_t *src_pte)
4854+
unsigned long new_addr, pte_t *src_pte, pte_t *dst_pte)
48554855
{
48564856
struct hstate *h = hstate_vma(vma);
48574857
struct mm_struct *mm = vma->vm_mm;
4858-
pte_t *dst_pte, pte;
48594858
spinlock_t *src_ptl, *dst_ptl;
4859+
pte_t pte;
48604860

4861-
dst_pte = huge_pte_offset(mm, new_addr, huge_page_size(h));
48624861
dst_ptl = huge_pte_lock(h, mm, dst_pte);
48634862
src_ptl = huge_pte_lockptr(h, mm, src_pte);
48644863

@@ -4917,7 +4916,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
49174916
if (!dst_pte)
49184917
break;
49194918

4920-
move_huge_pte(vma, old_addr, new_addr, src_pte);
4919+
move_huge_pte(vma, old_addr, new_addr, src_pte, dst_pte);
49214920
}
49224921
flush_tlb_range(vma, old_end - len, old_end);
49234922
mmu_notifier_invalidate_range_end(&range);

0 commit comments

Comments
 (0)