| From e36ed61a8ad49548c9b8b2a46162f8663f5b1679 Mon Sep 17 00:00:00 2001 |
| From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= <ville.syrjala@linux.intel.com> |
| Date: Tue, 5 Nov 2019 21:16:48 -0800 |
| Subject: [PATCH] mm/khugepaged: fix might_sleep() warn with CONFIG_HIGHPTE=y |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| commit ec649c9d454ea372dcf16cccf48250994f1d7788 upstream. |
| |
| 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/20191029201513.GG1208@intel.com |
| Fixes: 810e24e009cf71 ("mm/mmu_notifiers: annotate with might_sleep()") |
| Signed-off-by: Ville Syrjl <ville.syrjala@linux.intel.com> |
| Reviewed-by: Andrew Morton <akpm@linux-foundation.org> |
| Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> |
| Cc: Thomas Gleixner <tglx@linutronix.de> |
| Cc: Ingo Molnar <mingo@redhat.com> |
| Cc: Borislav Petkov <bp@alien8.de> |
| Cc: "H. Peter Anvin" <hpa@zytor.com> |
| Cc: Jérôme Glisse <jglisse@redhat.com> |
| Cc: Ralph Campbell <rcampbell@nvidia.com> |
| Cc: Ira Weiny <ira.weiny@intel.com> |
| Cc: Jason Gunthorpe <jgg@mellanox.com> |
| Cc: Daniel Vetter <daniel.vetter@intel.com> |
| Cc: 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> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/mm/khugepaged.c b/mm/khugepaged.c |
| index eaaa21b23215..5ce6d8728e2b 100644 |
| --- a/mm/khugepaged.c |
| +++ b/mm/khugepaged.c |
| @@ -1016,12 +1016,13 @@ static void collapse_huge_page(struct mm_struct *mm, |
| |
| anon_vma_lock_write(vma->anon_vma); |
| |
| - pte = pte_offset_map(pmd, address); |
| - pte_ptl = pte_lockptr(mm, pmd); |
| - |
| mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, NULL, mm, |
| address, address + HPAGE_PMD_SIZE); |
| mmu_notifier_invalidate_range_start(&range); |
| + |
| + pte = pte_offset_map(pmd, address); |
| + pte_ptl = pte_lockptr(mm, pmd); |
| + |
| pmd_ptl = pmd_lock(mm, pmd); /* probably unnecessary */ |
| /* |
| * After this gup_fast can't run anymore. This also removes |
| -- |
| 2.7.4 |
| |