Skip to content

Commit 58a84aa

Browse files
youquan-songtorvalds
authored andcommitted
thp: set compound tail page _count to zero
Commit 70b50f9 ("mm: thp: tail page refcounting fix") keeps all page_tail->_count zero at all times. But the current kernel does not set page_tail->_count to zero if a 1GB page is utilized. So when an IOMMU 1GB page is used by KVM, it wil result in a kernel oops because a tail page's _count does not equal zero. kernel BUG at include/linux/mm.h:386! invalid opcode: 0000 [raspberrypi#1] SMP Call Trace: gup_pud_range+0xb8/0x19d get_user_pages_fast+0xcb/0x192 ? trace_hardirqs_off+0xd/0xf hva_to_pfn+0x119/0x2f2 gfn_to_pfn_memslot+0x2c/0x2e kvm_iommu_map_pages+0xfd/0x1c1 kvm_iommu_map_memslots+0x7c/0xbd kvm_iommu_map_guest+0xaa/0xbf kvm_vm_ioctl_assigned_device+0x2ef/0xa47 kvm_vm_ioctl+0x36c/0x3a2 do_vfs_ioctl+0x49e/0x4e4 sys_ioctl+0x5a/0x7c system_call_fastpath+0x16/0x1b RIP gup_huge_pud+0xf2/0x159 Signed-off-by: Youquan Song <youquan.song@intel.com> Reviewed-by: Andrea Arcangeli <aarcange@redhat.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 b6999b1 commit 58a84aa

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

‎mm/hugetlb.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
576576
__SetPageHead(page);
577577
for (i = 1; i < nr_pages; i++, p = mem_map_next(p, page, i)) {
578578
__SetPageTail(p);
579+
set_page_count(p, 0);
579580
p->first_page = page;
580581
}
581582
}

‎mm/page_alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ void prep_compound_page(struct page *page, unsigned long order)
356356
__SetPageHead(page);
357357
for (i = 1; i < nr_pages; i++) {
358358
struct page *p = page + i;
359-
360359
__SetPageTail(p);
360+
set_page_count(p, 0);
361361
p->first_page = page;
362362
}
363363
}

0 commit comments

Comments
 (0)