[PATCH v3 1/3] mm: ptdump should use ptep_get_lockless()

From: Ryan Roberts
Date: Mon Jun 12 2023 - 11:16:14 EST


The page table dumper uses walk_page_range_novma() to walk the page
tables, which does not lock the PTL before calling the pte_entry()
callback. Therefore, the page table dumper's callback must use
ptep_get_lockless() rather than ptep_get() to ensure that the pte it
reads is not torn or otherwise corrupt when racing with writers.

Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx>
---
mm/ptdump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/ptdump.c b/mm/ptdump.c
index 8adab455a68b..03c1bdae4a43 100644
--- a/mm/ptdump.c
+++ b/mm/ptdump.c
@@ -119,7 +119,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr,
unsigned long next, struct mm_walk *walk)
{
struct ptdump_state *st = walk->private;
- pte_t val = ptep_get(pte);
+ pte_t val = ptep_get_lockless(pte);

if (st->effective_prot)
st->effective_prot(st, 4, pte_val(val));
--
2.25.1