Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/thp: fix "mm: thp: kill __transhuge_page_enabled()"

The 6.0 commits:

commit 9fec51689ff6 ("mm: thp: kill transparent_hugepage_active()")
commit 7da4e2cb8b1f ("mm: thp: kill __transhuge_page_enabled()")

merged "can we have THPs in this VMA?" logic that was previously done
separately by fault-path, khugepaged, and smaps "THPeligible" checks.

During the process, the semantics of the fault path check changed in two
ways:

1) A VM_NO_KHUGEPAGED check was introduced (also added to smaps path).
2) We no longer checked if non-anonymous memory had a vm_ops->huge_fault
handler that could satisfy the fault. Previously, this check had been
done in create_huge_pud() and create_huge_pmd() routines, but after
the changes, we never reach those routines.

During the review of the above commits, it was determined that in-tree
users weren't affected by the change; most notably, since the only
relevant user (in terms of THP) of VM_MIXEDMAP or ->huge_fault is DAX,
which is explicitly approved early in approval logic. However, this was a
bad assumption to make as it assumes the only reason to support
->huge_fault was for DAX (which is not true in general).

Remove the VM_NO_KHUGEPAGED check when not in collapse path and give any
->huge_fault handler a chance to handle the fault. Note that we don't
validate the file mode or mapping alignment, which is consistent with the
behavior before the aforementioned commits.

Link: https://lkml.kernel.org/r/20230925200110.1979606-1-zokeefe@google.com
Fixes: 7da4e2cb8b1f ("mm: thp: kill __transhuge_page_enabled()")
Reported-by: Saurabh Singh Sengar <ssengar@microsoft.com>
Signed-off-by: Zach O'Keefe <zokeefe@google.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Zach O'Keefe and committed by
Andrew Morton
7a81751f c0dddb7a

+13 -7
+13 -7
mm/huge_memory.c
··· 100 100 return in_pf; 101 101 102 102 /* 103 - * Special VMA and hugetlb VMA. 103 + * khugepaged special VMA and hugetlb VMA. 104 104 * Must be checked after dax since some dax mappings may have 105 105 * VM_MIXEDMAP set. 106 106 */ 107 - if (vm_flags & VM_NO_KHUGEPAGED) 107 + if (!in_pf && !smaps && (vm_flags & VM_NO_KHUGEPAGED)) 108 108 return false; 109 109 110 110 /* ··· 132 132 !hugepage_flags_always()))) 133 133 return false; 134 134 135 - /* Only regular file is valid */ 136 - if (!in_pf && file_thp_enabled(vma)) 137 - return true; 138 - 139 - if (!vma_is_anonymous(vma)) 135 + if (!vma_is_anonymous(vma)) { 136 + /* 137 + * Trust that ->huge_fault() handlers know what they are doing 138 + * in fault path. 139 + */ 140 + if (((in_pf || smaps)) && vma->vm_ops->huge_fault) 141 + return true; 142 + /* Only regular file is valid in collapse path */ 143 + if (((!in_pf || smaps)) && file_thp_enabled(vma)) 144 + return true; 140 145 return false; 146 + } 141 147 142 148 if (vma_is_temporary_stack(vma)) 143 149 return false;