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. [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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 605f53f commit 9ed33c7

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
@@ -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)