FAILED: patch "[PATCH] mm: huge_memory: add vma_thp_disabled() and" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 963756aac1f011d904ddd9548ae82286d3a91f96
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024101848-lucid-mountain-2cdf@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 963756aac1f011d904ddd9548ae82286d3a91f96 Mon Sep 17 00:00:00 2001
From: Kefeng Wang <[email protected]>
Date: Fri, 11 Oct 2024 12:24:44 +0200
Subject: [PATCH] mm: huge_memory: add vma_thp_disabled() and
thp_disabled_by_hw()
Patch series "mm: don't install PMD mappings when THPs are disabled by the hw/process/vma".
During testing, it was found that we can get PMD mappings in processes where THP (and more precisely, PMD mappings) are supposed to be disabled. While it works as expected for anon+shmem, the pagecache is the problematic bit.
For s390 KVM this currently means that a VM backed by a file located on filesystem with large folio support can crash when KVM tries accessing the problematic page, because the readahead logic might decide to use a PMD-sized THP and faulting it into the page tables will install a PMD mapping, something that s390 KVM cannot tolerate.
This might also be a problem with HW that does not support PMD mappings, but I did not try reproducing it.
Fix it by respecting the ways to disable THPs when deciding whether we can install a PMD mapping. khugepaged should already be taking care of not collapsing if THPs are effectively disabled for the hw/process/vma.
This patch (of 2):
Add vma_thp_disabled() and thp_disabled_by_hw() helpers to be shared by shmem_allowable_huge_orders() and __thp_vma_allowable_orders().
include/linux/huge_mm.h +18 -0
@@ -322,6 +322,24 @@ struct thpsize { (transparent_hugepage_flags & \ (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) +static inline bool vma_thp_disabled (struct vm_area_struct *vma, +unsigned long vm_flags) +{ +/* +* Explicitly disabled through madvise or prctl, or some +* architectures may disable THP for some mappings, for +* example, s390 kvm. +*/ +return (vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags); +} + +static inline bool thp_disabled_by_hw (void ) +{ +/* If the hardware/firmware marked hugepage support disabled. */ +return transparent_hugepage_flags & (1 <<TRANSPARENT_HUGEPAGE_UNSUPPORTED ); +} +unsigned long thp_get_unmapped_area (struct file *filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr,
mm/huge_memory.c +1 -12
@@ -109,18 +109,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,if (!vma->vm_mm)/* vdso */ return 0 ; -/* -* Explicitly disabled through madvise or prctl, or some -* architectures may disable THP for some mappings, for -* example, s390 kvm. -* */ -if ((vm_flags &VM_NOHUGEPAGE ) || -test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) -return 0 ; -/* -* If the hardware/firmware marked hugepage support disabled. -*/ -if (transparent_hugepage_flags & (1 <<TRANSPARENT_HUGEPAGE_UNSUPPORTED )) +if (thp_disabled_by_hw () ||vma_thp_disabled (vma, vm_flags))return 0 ;/* khugepaged doesn't collapse DAX vma, but page fault is fine. */
mm/shmem.c +1 -6
@@ -1664,12 +1664,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,loff_t i_size;int order; -if (vma && ((vm_flags &VM_NOHUGEPAGE ) || -test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags))) -return 0 ; - -/* If the hardware/firmware marked hugepage support disabled. */ -if (transparent_hugepage_flags & (1 <<TRANSPARENT_HUGEPAGE_UNSUPPORTED )) +if (thp_disabled_by_hw () || (vma &&vma_thp_disabled (vma, vm_flags)))return 0 ; global_huge = shmem_huge_global_enabled(inode, index, write_end,