Skip to content

Commit 9ed33c7

Browse files
bgaffgregkh
authored andcommitted
mm: fix finish_fault() handling for large folios
commit 34b82f3 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 605f53f commit 9ed33c7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

mm/memory.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -5079,7 +5079,11 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
50795079
bool is_cow = (vmf->flags & FAULT_FLAG_WRITE) &&
50805080
!(vma->vm_flags & VM_SHARED);
50815081
int type, nr_pages;
5082-
unsigned long addr = vmf->address;
5082+
unsigned long addr;
5083+
bool needs_fallback = false;
5084+
5085+
fallback:
5086+
addr = vmf->address;
50835087

50845088
/* Did we COW the page? */
50855089
if (is_cow)
@@ -5118,7 +5122,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51185122
* approach also applies to non-anonymous-shmem faults to avoid
51195123
* inflating the RSS of the process.
51205124
*/
5121-
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma))) {
5125+
if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma)) ||
5126+
unlikely(needs_fallback)) {
51225127
nr_pages = 1;
51235128
} else if (nr_pages > 1) {
51245129
pgoff_t idx = folio_page_idx(folio, page);
@@ -5154,9 +5159,9 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
51545159
ret = VM_FAULT_NOPAGE;
51555160
goto unlock;
51565161
} else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) {
5157-
update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
5158-
ret = VM_FAULT_NOPAGE;
5159-
goto unlock;
5162+
needs_fallback = true;
5163+
pte_unmap_unlock(vmf->pte, vmf->ptl);
5164+
goto fallback;
51605165
}
51615166

51625167
folio_ref_add(folio, nr_pages - 1);

0 commit comments

Comments
 (0)