From aa6f643e3f57bd2bf4aba313b2108c10e45e1fa9 Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Thu, 7 Oct 2021 16:57:39 +0900 Subject: [PATCH] mm, thp: preventing hugepage creation for read-write file pages Sometimes, an user process incurs writes on file pages which has VM_DENYWRITE flag in its vma->vm_flags (of course, the vma has VM_WRITE flags too). In this case, the kernel creates a new page by a COW fault, but it is an unexpected behaviour for 64KB file hugepages. This patch disallows scanning of read-write file pages to prevent unexpected buggy behaviours. Change-Id: I28c1da7f7ad4be55be5607316b29a2978896fcb9 Signed-off-by: Sung-hun Kim --- arch/arm64/mm/finegrained_thp.c | 2 +- mm/khugepaged.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/finegrained_thp.c b/arch/arm64/mm/finegrained_thp.c index 5ebb4ac..570747c 100644 --- a/arch/arm64/mm/finegrained_thp.c +++ b/arch/arm64/mm/finegrained_thp.c @@ -17,7 +17,7 @@ bool arm64_hugepage_vma_file_check(struct vm_area_struct *vma, { /* Read-only file mappings need to be aligned for THP to work. */ if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && - (vm_flags & VM_DENYWRITE)) { + (vm_flags & VM_DENYWRITE) && !(vm_flags & VM_WRITE)) { return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, nr_pages); } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 9cb9125..297cee0 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -513,7 +513,7 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return true; /* Only regular file is valid */ else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && - (vm_flags & VM_DENYWRITE)) { + (vm_flags & VM_DENYWRITE) && !(vm_flags & VM_WRITE)) { struct inode *inode = vma->vm_file->f_inode; return S_ISREG(inode->i_mode); -- 2.7.4