[PATCH RFC 05/10] mm/hugetlb: Make walk_hugetlb_range() RCU-safe
From: Peter Xu
Date: Sun Oct 30 2022 - 17:31:43 EST
RCU makes sure the pte_t* won't go away from under us. Please refer to the
comment above huge_pte_offset() for more information.
Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
mm/pagewalk.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 7f1c9b274906..bbc71c750576 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -302,6 +302,9 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end,
const struct mm_walk_ops *ops = walk->ops;
int err = 0;
+ /* For huge_pte_offset() */
+ rcu_read_lock();
+
do {
next = hugetlb_entry_end(h, addr, end);
pte = huge_pte_offset(walk->mm, addr & hmask, sz);
@@ -315,6 +318,8 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end,
break;
} while (addr = next, addr != end);
+ rcu_read_unlock();
+
return err;
}
--
2.37.3