Skip to contentSkip to conversation

mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message May 21, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack()
has been removed from the -mm tree. Its filename was
mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: David Hildenbrand <[email protected]>
Subject: mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack()
Date: Mon, 12 May 2025 14:34:17 +0200

Let's use our new interface. In remap_pfn_range(), we'll now decide whether we have to track (full VMA covered) or only lookup the cachemode (partial VMA covered).

Remember what we have to untrack by linking it from the VMA. When duplicating VMAs (e.g., splitting, mremap, fork), we'll handle it similar to anon VMA names, and use a kref to share the tracking.

Once the last VMA un-refs our tracking data, we'll do the untracking, which simplifies things a lot and should sort our various issues we saw recently, for example, when partially unmapping/zapping a tracked VMA.

This change implies that we'll keep tracking the original PFN range even after splitting + partially unmapping it: not too bad, because it was not working reliably before. The only thing that kind-of worked before was shrinking such a mapping using mremap(): we managed to adjust the reservation in a hacky way, now we won't adjust the reservation but leave it around until all involved VMAs are gone.

If that ever turns out to be an issue, we could hook into VM splitting code and split the tracking; however, that adds complexity that might not be required, so we'll keep it simple for now.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Betkov <[email protected]>
Cc Dave Airlie <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Jann Horn <[email protected]>
Cc Jonas Lahtinen <[email protected]>
Cc "Masami Hiramatsu (Google)" <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Peter Xu <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleinxer <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Vlastimil Babka <[email protected]>

---

 include/linux/mm_inline.h |    2 
 include/linux/mm_types.h  |   11 ++++
 mm/memory.c               |   82 ++++++++++++++++++++++++++++--------
 mm/mmap.c                 |    5 --
 mm/mremap.c               |    4 -
 mm/vma_init.c             |   50 +++++++++++++++++++++
 6 files changed, 129 insertions(+), 25 deletions(-)
include/linux/mm_inline.h renamed from include/linux/mm_inline.h~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +2 -0
@@ -447,6 +447,8 @@ static inline bool anon_vma_name_eq(stru
 
 #endif  /* CONFIG_ANON_VMA_NAME */
 
+void pfnmap_track_ctx_release(struct kref *ref);
+
 static inline void init_tlb_flush_pending(struct mm_struct *mm)
 {
 	atomic_set(&mm->tlb_flush_pending, 0);
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +11 -0
@@ -763,6 +763,14 @@ struct vma_numab_state {
 	int prev_scan_seq;
 };
 
+#ifdef __HAVE_PFNMAP_TRACKING
+struct pfnmap_track_ctx {
+	struct kref kref;
+	unsigned long pfn;
+	unsigned long size;	/* in bytes */
+};
+#endif
+
 /*
  * Describes a VMA that is about to be mmap()'ed. Drivers may choose to
  * manipulate mutable fields which will cause those fields to be updated in the
@@ -900,6 +908,9 @@ struct vm_area_struct {
 	struct anon_vma_name *anon_name;
 #endif
 	struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
+#ifdef __HAVE_PFNMAP_TRACKING
+	struct pfnmap_track_ctx *pfnmap_track_ctx;
+#endif
 } __randomize_layout;
 
 #ifdef CONFIG_NUMA
mm/memory.c renamed from mm/memory.c~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +66 -16

128 lines not on this page · raw message

mm/mmap.c renamed from mm/mmap.c~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +0 -5
@@ -1784,11 +1784,6 @@ __latent_entropy int dup_mmap(struct mm_
 		tmp = vm_area_dup(mpnt);
 		if (!tmp)
 			goto fail_nomem;
-
-		/* track_pfn_copy() will later take care of copying internal state. */
-		if (unlikely(tmp->vm_flags & VM_PFNMAP))
-			untrack_pfn_clear(tmp);
-
 		retval = vma_dup_policy(mpnt, tmp);
 		if (retval)
 			goto fail_nomem_policy;
mm/mremap.c renamed from mm/mremap.c~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +0 -4
@@ -1191,10 +1191,6 @@ static int copy_vma_and_data(struct vma_
 	if (is_vm_hugetlb_page(vma))
 		clear_vma_resv_huge_pages(vma);
 
-	/* Tell pfnmap has moved from this vma */
-	if (unlikely(vma->vm_flags & VM_PFNMAP))
-		untrack_pfn_clear(vma);
-
 	*new_vma_ptr = new_vma;
 	return err;
 }
mm/vma_init.c renamed from mm/vma_init.c~mm-convert-vm_pfnmap-tracking-to-pfnmap_track-pfnmap_untrack +50 -0

68 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are