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. [[email protected]: tweak whitespace] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 43e027e ("mm: memory: extend finish_fault() to support large folio") Signed-off-by: Brian Geffon <[email protected]> Suggested-by: Baolin Wang <[email protected]> Reported-by: Marek Maslanka <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Hugh Dickens <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Matthew Wilcow (Oracle) <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Zi Yan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
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)