[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221118011025.2178986-10-peterx@redhat.com>
Date: Thu, 17 Nov 2022 20:10:22 -0500
From: Peter Xu <peterx@...hat.com>
To: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc: Rik van Riel <riel@...riel.com>,
Muchun Song <songmuchun@...edance.com>,
Andrew Morton <akpm@...ux-foundation.org>, peterx@...hat.com,
James Houghton <jthoughton@...gle.com>,
Nadav Amit <nadav.amit@...il.com>,
Andrea Arcangeli <aarcange@...hat.com>,
David Hildenbrand <david@...hat.com>,
Miaohe Lin <linmiaohe@...wei.com>,
Mike Kravetz <mike.kravetz@...cle.com>
Subject: [PATCH RFC v2 09/12] mm/hugetlb: Use hugetlb walker lock in hugetlb_vma_maps_page()
Hugetlb walker lock makes sure the pte_t* won't go away from under us.
Signed-off-by: Peter Xu <peterx@...hat.com>
---
fs/hugetlbfs/inode.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index fdb16246f46e..265508981ba1 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -387,21 +387,24 @@ static bool hugetlb_vma_maps_page(struct vm_area_struct *vma,
unsigned long addr, struct page *page)
{
pte_t *ptep, pte;
+ bool result = false;
+ hugetlb_walker_lock();
ptep = huge_pte_offset(vma->vm_mm, addr,
huge_page_size(hstate_vma(vma)));
if (!ptep)
- return false;
+ goto out;
pte = huge_ptep_get(ptep);
if (huge_pte_none(pte) || !pte_present(pte))
- return false;
+ goto out;
if (pte_page(pte) == page)
- return true;
-
- return false;
+ result = true;
+out:
+ hugetlb_walker_unlock();
+ return result;
}
/*
--
2.37.3
Powered by blists - more mailing lists