diff mbox series

[RFC,v2,07/12] mm/hugetlb: Use hugetlb walker lock in hugetlb_follow_page_mask()

Message ID 20221118011025.2178986-8-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/hugetlb: Make huge_pte_offset() thread-safe for pmd unshare | expand

Commit Message

Peter Xu Nov. 18, 2022, 1:10 a.m. UTC
Hugetlb walker lock makes sure the pte_t* won't go away from under us.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 mm/hugetlb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5ef883184885..fc49e3ca8acd 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6222,9 +6222,10 @@  struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma,
 	if (WARN_ON_ONCE(flags & FOLL_PIN))
 		return NULL;
 
+	hugetlb_walker_lock();
 	pte = huge_pte_offset(mm, haddr, huge_page_size(h));
 	if (!pte)
-		return NULL;
+		goto out_unlock;
 
 	ptl = huge_pte_lock(h, mm, pte);
 	entry = huge_ptep_get(pte);
@@ -6247,6 +6248,8 @@  struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma,
 	}
 out:
 	spin_unlock(ptl);
+out_unlock:
+	hugetlb_walker_unlock();
 	return page;
 }