Skip to content

Commit 34b82f3

Browse files
bgaffakpm00
authored andcommitted
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>
1 parent 3685024 commit 34b82f3

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
@@ -5185,7 +5185,11 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51855185
bool is_cow = (vmf->flags & FAULT_FLAG_WRITE) &&
51865186
!(vma->vm_flags & VM_SHARED);
51875187
int type, nr_pages;
5188-
unsigned long addr = vmf->address;
5188+
unsigned long addr;
5189+
bool needs_fallback = false;
5190+
5191+
fallback:
5192+
addr = vmf->address;
51895193

51905194
/* Did we COW the page? */
51915195
if (is_cow)
@@ -5224,7 +5228,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
52245228
* approach also applies to non-anonymous-shmem faults to avoid
52255229
* inflating the RSS of the process.
52265230
*/
5227-
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma))) {
5231+
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma)) ||
5232+
unlikely(needs_fallback)) {
52285233
nr_pages = 1;
52295234
} else if (nr_pages > 1) {
52305235
pgoff_t idx = folio_page_idx(folio, page);
@@ -5260,9 +5265,9 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
52605265
ret = VM_FAULT_NOPAGE;
52615266
goto unlock;
52625267
} else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) {
5263-
update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
5264-
ret = VM_FAULT_NOPAGE;
5265-
goto unlock;
5268+
needs_fallback = true;
5269+
pte_unmap_unlock(vmf->pte, vmf->ptl);
5270+
goto fallback;
52665271
}
52675272

52685273
folio_ref_add(folio, nr_pages - 1);

0 commit comments

Comments
 (0)