Skip to contentSkip to conversation

mm-hugetlb-take-src_mm-write_protect_seq-in-copy_hugetlb_page_range.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message May 10, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled

     Subject: mm/hugetlb: take src_mm->write_protect_seq in copy_hugetlb_page_range()

has been removed from the -mm tree. Its filename was
mm-hugetlb-take-src_mm-write_protect_seq-in-copy_hugetlb_page_range.patch

This patch was dropped because it was merged into mm-stable

------------------------------------------------------
From: David Hildenbrand <[email protected]>
Subject: mm/hugetlb: take src_mm->write_protect_seq in copy_hugetlb_page_range()

Let's do it just like copy_page_range(), taking the seqlock and making sure the mmap_lock is held in write mode.

This allows for add a VM_BUG_ON to page_needs_cow_for_dma() and properly synchronizes concurrent fork() with GUP-fast of hugetlb pages, which will be relevant for further changes.

Cc Andrea Arcangeli <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc David Rientjes <[email protected]>
Cc Don Dutile <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Jan Kara <[email protected]>
Cc Jann Horn <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc John Hubbard <[email protected]>
Cc Khalid Aziz <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Liang Zhang <[email protected]>
Cc "Matthew Wilcox (Oracle)" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Nadav Amit <[email protected]>
Cc Oded Gabbay <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Pedro Demarchi Gomes <[email protected]>
Cc Peter Xu <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Yang Shi <[email protected]>

---

 include/linux/mm.h |    4 ++++
 mm/hugetlb.c       |    8 ++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-hugetlb-take-src_mm-write_protect_seq-in-copy_hugetlb_page_range +4 -0
@@ -1576,6 +1576,8 @@ static inline bool page_maybe_dma_pinned
 /*
  * This should most likely only be called during fork() to see whether we
  * should break the cow immediately for a page on the src mm.
+ *
+ * The caller has to hold the PT lock and the vma->vm_mm->->write_protect_seq.
  */
 static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 					  struct page *page)
@@ -1583,6 +1585,8 @@ static inline bool page_needs_cow_for_dm
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	VM_BUG_ON(!(raw_read_seqcount(&vma->vm_mm->write_protect_seq) & 1));
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/hugetlb.c renamed from mm/hugetlb.c~mm-hugetlb-take-src_mm-write_protect_seq-in-copy_hugetlb_page_range +6 -2
@@ -4735,6 +4735,8 @@ int copy_hugetlb_page_range(struct mm_st
 					vma->vm_start,
 					vma->vm_end);
 		mmu_notifier_invalidate_range_start(&range);
+		mmap_assert_write_locked(src);
+		raw_write_seqcount_begin(&src->write_protect_seq);
 	} else {
 		/*
 		 * For shared mappings i_mmap_rwsem must be held to call
@@ -4867,10 +4869,12 @@ again:
 		spin_unlock(dst_ptl);
 	}
 
-	if (cow)
+	if (cow) {
+		raw_write_seqcount_end(&src->write_protect_seq);
 		mmu_notifier_invalidate_range_end(&range);
-	else
+	} else {
 		i_mmap_unlock_read(mapping);
+	}
 
 	return ret;
 }

_

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