]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm/khugepaged: write-lock VMA while collapsing a huge page
authorSuren Baghdasaryan <surenb@google.com>
Mon, 27 Feb 2023 17:36:14 +0000 (09:36 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 5 Apr 2023 23:02:07 +0000 (16:02 -0700)
commit10838a8f22bc0ed254539da993f2da529f20c8ea
tree502fe63ec430e59ad6ac8142ede1039c48eb2fbe
parent228d9dc92fa03d975c9bf14895b8af7a6dfde59d
mm/khugepaged: write-lock VMA while collapsing a huge page

Protect VMA from concurrent page fault handler while collapsing a huge
page.  Page fault handler needs a stable PMD to use PTL and relies on
per-VMA lock to prevent concurrent PMD changes.  pmdp_collapse_flush(),
set_huge_pmd() and collapse_and_free_pmd() can modify a PMD, which will
not be detected by a page fault handler without proper locking.

Before this patch, page tables can be walked under any one of the
mmap_lock, the mapping lock, and the anon_vma lock; so when khugepaged
unlinks and frees page tables, it must ensure that all of those either are
locked or don't exist.  This patch adds a fourth lock under which page
tables can be traversed, and so khugepaged must also lock out that one.

Link: https://lkml.kernel.org/r/20230227173632.3292573-16-surenb@google.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/khugepaged.c
mm/rmap.c