linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: fix finish_fault() handling for large folios
@ 2025-02-26 11:48 Brian Geffon
  2025-02-26 14:03 ` Matthew Wilcox
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Brian Geffon @ 2025-02-26 11:48 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Zi Yan, Kefeng Wang, Suren Baghdasaryan, linux-mm, linux-kernel,
	Brian Geffon, stable, Baolin Wang, Hugh Dickins, Marek Maslanka

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 just the pte for the
address that triggered the fault.

Cc: stable@vger.kernel.org
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Fixes: 43e027e41423 ("mm: memory: extend finish_fault() to support large folio")
Reported-by: Marek Maslanka <mmaslanka@google.com>
Signed-off-by: Brian Geffon <bgeffon@google.com>
---
 mm/memory.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index b4d3d4893267..32de626ec1da 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5258,9 +5258,22 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
 		ret = VM_FAULT_NOPAGE;
 		goto unlock;
 	} else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) {
-		update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
-		ret = VM_FAULT_NOPAGE;
-		goto unlock;
+		/*
+		 * We encountered a set pte, let's just try to install the
+		 * pte for the original fault if that pte is still pte none.
+		 */
+		pgoff_t idx = (vmf->address - addr) / PAGE_SIZE;
+
+		if (!pte_none(ptep_get_lockless(vmf->pte + idx))) {
+			update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
+			ret = VM_FAULT_NOPAGE;
+			goto unlock;
+		}
+
+		vmf->pte = vmf->pte + idx;
+		page = folio_page(folio, idx);
+		addr = vmf->address;
+		nr_pages = 1;
 	}
 
 	folio_ref_add(folio, nr_pages - 1);
-- 
2.48.1.711.g2feabab25a-goog



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-02-27 16:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-26 11:48 [PATCH] mm: fix finish_fault() handling for large folios Brian Geffon
2025-02-26 14:03 ` Matthew Wilcox
2025-02-26 14:31   ` Brian Geffon
2025-02-26 15:42   ` David Hildenbrand
2025-02-26 16:28     ` Matthew Wilcox
2025-02-26 16:52       ` David Hildenbrand
2025-02-26 15:17 ` Baolin Wang
2025-02-26 15:46   ` Brian Geffon
2025-02-26 16:23 ` [PATCH v2] " Brian Geffon
2025-02-27  7:34   ` Baolin Wang
2025-02-27 16:47     ` Brian Geffon
2025-02-27 13:32 ` [PATCH v3] " Brian Geffon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox