mm: thp: khugepaged: flush tlb range to prevent concurrent memory accesses 80/265080/3
authorSung-hun Kim <sfoon.kim@samsung.com>
Fri, 1 Oct 2021 05:15:51 +0000 (14:15 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Tue, 12 Oct 2021 05:25:39 +0000 (14:25 +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 39ee0fb..0622868 100644 (file)
@@ -1384,7 +1384,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);