Skip to contentSkip to conversation

mm/page_table_check: add explicit pmd_none check in pte_clear_range

PATCH RESEND Applied Ye Liu 2 participants 2 messages Aug 19 – Nov 1

Subsystems (3)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

PATCH RESEND 1/1 mm/page_table_check: add explicit pmd_none check in pte_clear_range

From: Ye Liu <[email protected]>

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.

---
 mm/page_table_check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_table_check.c +1 -1
index 6ffc536359cd..ed3e1a76f266 100644
@@ -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;
 
Signature · 1 line
2.25.1
#1 lore raw
This patch was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Andrew Morton <[email protected]>:

Quoted 8 lines · On Wed, 19 Aug 2026 10:55:15 +0800 you wrote:

From: Ye Liu <[email protected]>

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.

[...]

Here is the summary with links:
- [RESEND] mm/page_table_check: add explicit pmd_none check in pte_clear_range

    https://git.kernel.org/riscv/c/0224133dba05

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html