mm, thp: preventing hugepage creation for read-write file pages 82/265082/3 accepted/tizen/6.5/unified/20211103.015137 accepted/tizen/unified/20211028.122206 submit/tizen/20211013.042847 submit/tizen/20211027.044930 submit/tizen_6.5/20211027.044719 submit/tizen_6.5/20211101.045952
authorSung-hun Kim <sfoon.kim@samsung.com>
Thu, 7 Oct 2021 07:57:39 +0000 (16:57 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Tue, 12 Oct 2021 05:34:58 +0000 (14:34 +0900)
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 <sfoon.kim@samsung.com>
arch/arm64/mm/finegrained_thp.c
mm/khugepaged.c

index 5ebb4ac..570747c 100644 (file)
@@ -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);
        }
index 692b2fc..21105b0 100644 (file)
@@ -513,7 +513,7 @@ static bool hugepage_vma_check(struct vm_area_struct *vma,
                return true;
        /* Read-only file mappings need to be aligned for THP to work. */
        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)) {
                return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
                                HPAGE_PMD_NR);
        }