* [PATCH] mm/page_table_check: add explicit pmd_none check in pte_clear_range
[not found] <20260805122224.2512983-1-ye.liu@linux.dev>
@ 2026-08-05 12:22 ` Ye Liu
0 siblings, 0 replies; only message in thread
From: Ye Liu @ 2026-08-05 12:22 UTC (permalink / raw)
To: Pasha Tatashin, Andrew Morton, Paul Walmsley, Palmer Dabbelt,
Albert Ou
Cc: Ye Liu, Alexandre Ghiti, linux-mm, linux-kernel, linux-riscv
From: Ye Liu <liuye@kylinos.cn>
In __page_table_check_pte_clear_range(), the condition to determine
whether to iterate over PTEs only checked pmd_bad() and pmd_leaf().
This relies on the implicit assumption that pmd_none() is always a
subset of pmd_bad() on all architectures supporting PAGE_TABLE_CHECK.
While this assumption currently holds for x86_64, arm64, s390, riscv,
and powerpc, it is an architecture-dependent behavior that may not
hold for future architectures. Add an explicit pmd_none() check to
make the intent clear and avoid calling pte_offset_map() on an empty
PMD, which could lead to undefined behavior.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/page_table_check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/page_table_check.c b/mm/page_table_check.c
index 6ffc536359cd..ed3e1a76f266 100644
--- a/mm/page_table_check.c
+++ b/mm/page_table_check.c
@@ -278,7 +278,7 @@ void __page_table_check_pte_clear_range(struct mm_struct *mm,
if (&init_mm == mm)
return;
- if (!pmd_bad(pmd) && !pmd_leaf(pmd)) {
+ if (!pmd_none(pmd) && !pmd_bad(pmd) && !pmd_leaf(pmd)) {
pte_t *ptep = pte_offset_map(&pmd, addr);
unsigned long i;
--
2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] only message in thread