Skip to content

Commit 9ac0bb6

Browse files
committed
mm: fix finish_fault() handling for large folios
JIRA: https://issues.redhat.com/browse/RHEL-83854 Tested: by me commit 34b82f3 Author: Brian Geffon <bgeffon@google.com> Date: Wed Feb 26 11:23:41 2025 -0500 mm: fix finish_fault() handling for large folios When handling faults for anon shmem finish_fault() will attempt to install ptes for the entire folio. Unfortunately if it encounters a single non-pte_none entry in that range it will bail, even if the pte that triggered the fault is still pte_none. When this situation happens the fault will be retried endlessly never making forward progress. This patch fixes this behavior and if it detects that a pte in the range is not pte_none it will fall back to setting a single pte. [bgeffon@google.com: tweak whitespace] Link: https://lkml.kernel.org/r/20250227133236.1296853-1-bgeffon@google.com Link: https://lkml.kernel.org/r/20250226162341.915535-1-bgeffon@google.com Fixes: 43e027e ("mm: memory: extend finish_fault() to support large folio") Signed-off-by: Brian Geffon <bgeffon@google.com> Suggested-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reported-by: Marek Maslanka <mmaslanka@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: David Hildenbrand <david@redhat.com> Cc: Hugh Dickens <hughd@google.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Zi Yan <ziy@nvidia.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
1 parent 88894d4 commit 9ac0bb6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

mm/memory.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5102,7 +5102,11 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51025102
bool is_cow = (vmf->flags & FAULT_FLAG_WRITE) &&
51035103
!(vma->vm_flags & VM_SHARED);
51045104
int type, nr_pages;
5105-
unsigned long addr = vmf->address;
5105+
unsigned long addr;
5106+
bool needs_fallback = false;
5107+
5108+
fallback:
5109+
addr = vmf->address;
51065110

51075111
/* Did we COW the page? */
51085112
if (is_cow)
@@ -5141,7 +5145,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51415145
* approach also applies to non-anonymous-shmem faults to avoid
51425146
* inflating the RSS of the process.
51435147
*/
5144-
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma))) {
5148+
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma)) ||
5149+
unlikely(needs_fallback)) {
51455150
nr_pages = 1;
51465151
} else if (nr_pages > 1) {
51475152
pgoff_t idx = folio_page_idx(folio, page);
@@ -5177,9 +5182,9 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51775182
ret = VM_FAULT_NOPAGE;
51785183
goto unlock;
51795184
} else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) {
5180-
update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
5181-
ret = VM_FAULT_NOPAGE;
5182-
goto unlock;
5185+
needs_fallback = true;
5186+
pte_unmap_unlock(vmf->pte, vmf->ptl);
5187+
goto fallback;
51835188
}
51845189

51855190
folio_ref_add(folio, nr_pages - 1);

0 commit comments

Comments
 (0)