From 5338d6493b4bfa6af640794f45c4247fe7a18a50 Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Fri, 1 Oct 2021 14:15:51 +0900 Subject: [PATCH] mm: thp: khugepaged: flush tlb range to prevent concurrent memory accesses 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 --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 806bf60..3399d49 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -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); -- 2.7.4