Skip to content

Commit 51f4a7c

Browse files
zokeefeopsiff
authored andcommitted
mm/thp: fix "mm: thp: kill __transhuge_page_enabled()"
mainline inclusion from mainline-v6.7-rc1 category: bugfix The 6.0 commits: commit 9fec516 ("mm: thp: kill transparent_hugepage_active()") commit 7da4e2c ("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: 7da4e2c ("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> (cherry picked from commit 7a81751) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent a3a0e6d commit 51f4a7c

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

mm/huge_memory.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags,
8686
return in_pf;
8787

8888
/*
89-
* Special VMA and hugetlb VMA.
89+
* khugepaged special VMA and hugetlb VMA.
9090
* Must be checked after dax since some dax mappings may have
9191
* VM_MIXEDMAP set.
9292
*/
93-
if (vm_flags & VM_NO_KHUGEPAGED)
93+
if (!in_pf && !smaps && (vm_flags & VM_NO_KHUGEPAGED))
9494
return false;
9595

9696
/*
@@ -118,12 +118,18 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags,
118118
!hugepage_flags_always())))
119119
return false;
120120

121-
/* Only regular file is valid */
122-
if (!in_pf && file_thp_enabled(vma))
123-
return true;
124-
125-
if (!vma_is_anonymous(vma))
121+
if (!vma_is_anonymous(vma)) {
122+
/*
123+
* Trust that ->huge_fault() handlers know what they are doing
124+
* in fault path.
125+
*/
126+
if (((in_pf || smaps)) && vma->vm_ops->huge_fault)
127+
return true;
128+
/* Only regular file is valid in collapse path */
129+
if (((!in_pf || smaps)) && file_thp_enabled(vma))
130+
return true;
126131
return false;
132+
}
127133

128134
if (vma_is_temporary_stack(vma))
129135
return false;

0 commit comments

Comments
 (0)