Skip to content

Commit ec649c9

Browse files
vsyrjalatorvalds
authored andcommitted
mm/khugepaged: fix might_sleep() warn with CONFIG_HIGHPTE=y
I got some khugepaged spew on a 32bit x86: BUG: sleeping function called from invalid context at include/linux/mmu_notifier.h:346 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 25, name: khugepaged INFO: lockdep is turned off. CPU: 1 PID: 25 Comm: khugepaged Not tainted 5.4.0-rc5-elk+ #206 Hardware name: System manufacturer P5Q-EM/P5Q-EM, BIOS 2203 07/08/2009 Call Trace: dump_stack+0x66/0x8e ___might_sleep.cold.96+0x95/0xa6 __might_sleep+0x2e/0x80 collapse_huge_page.isra.51+0x5ac/0x1360 khugepaged+0x9a9/0x20f0 kthread+0xf5/0x110 ret_from_fork+0x2e/0x38 Looks like it's due to CONFIG_HIGHPTE=y pte_offset_map()->kmap_atomic() vs. mmu_notifier_invalidate_range_start(). Let's do the naive approach and just reorder the two operations. Link: http://lkml.kernel.org/r/[email protected] Fixes: 810e24e ("mm/mmu_notifiers: annotate with might_sleep()") Signed-off-by: Ville Syrjl <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Jérôme Glisse <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: Ira Weiny <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 93b3a67 commit ec649c9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/khugepaged.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,13 @@ static void collapse_huge_page(struct mm_struct *mm,
10281028

10291029
anon_vma_lock_write(vma->anon_vma);
10301030

1031-
pte = pte_offset_map(pmd, address);
1032-
pte_ptl = pte_lockptr(mm, pmd);
1033-
10341031
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, NULL, mm,
10351032
address, address + HPAGE_PMD_SIZE);
10361033
mmu_notifier_invalidate_range_start(&range);
1034+
1035+
pte = pte_offset_map(pmd, address);
1036+
pte_ptl = pte_lockptr(mm, pmd);
1037+
10371038
pmd_ptl = pmd_lock(mm, pmd); /* probably unnecessary */
10381039
/*
10391040
* After this gup_fast can't run anymore. This also removes

0 commit comments

Comments
 (0)