mm: thp: khugepaged: flush tlb range to prevent concurrent memory accesses
authorSung-hun Kim <sfoon.kim@samsung.com>
Fri, 1 Oct 2021 05:15:51 +0000 (14:15 +0900)
committerHoegeun Kwon <hoegeun.kwon@samsung.com>
Mon, 7 Feb 2022 08:01:41 +0000 (17:01 +0900)
When khugepaged creates a hugepage while a user accesses memory,
khugepaged should prohibit current accesses to scanning area
because it can make a race condition.

Before creating a hugepage, khugepaged holds a lock of mm_struct
then flushes tlbs of scanning range. For 64KB hugepage, however,
it does not flush tlbs before it installs a new hugepage into the
page table. In this case, the user can lose their progress because
the user process still have memory map in its TLB entries.

By flushing TLBs right after acquiring mmap_lock, the process can
stall before reusing their memory contents.

Change-Id: I408662d69fa68e6210be8ad0b585943bfb8894e8
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
mm/khugepaged.c

index 806bf60..3399d49 100644 (file)
@@ -1385,7 +1385,7 @@ static void collapse_huge_page(struct mm_struct *mm,
                 * __collapse_huge_page_isolate and __collapse_huge_page_copy
                 * to fail, __collapse_huge_page_copy also clears ptes
                 */
-               ;
+               flush_tlb_range(vma, address, address + HPAGE_CONT_PTE_SIZE);
        else
 #endif /* CONFIG_FINEGRAINED_THP */
                _pmd = pmdp_collapse_flush(vma, address, pmd);