Skip to contentSkip to conversation

mm/debug_vm_pgtable: Add [pte|pmd]_mkwrite_novma() tests

PATCH Superseded Anshuman Khandual 3 participants 8 messages Oct 22, 2025 – Oct 23, 2025 Memory management

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/debug_vm_pgtable: Add [pte|pmd]_mkwrite_novma() tests

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +12 -0
index 830107b6dd08..def344bb4a32 100644
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));
+	WARN_ON(!pte_write(pte_mkwrite_novma(pte_wrprotect(pte))));
+	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite_novma(pte))));
 }
 
 static void __init pte_advanced_tests(struct pgtable_debug_args *args)
@@ -195,6 +201,12 @@ static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd, args->vma))));
 	WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd))));
 	WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd))));
+
+	WARN_ON(pmd_dirty(pmd_mkwrite_novma(pmd_mkclean(pmd))));
+	WARN_ON(!pmd_write(pmd_mkdirty(pmd_mkwrite_novma(pmd))));
+	WARN_ON(!pmd_write(pmd_mkwrite_novma(pmd_wrprotect(pmd))));
+	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite_novma(pmd))));
+
 	/*
 	 * A huge page does not point to next level page table
 	 * entry. Hence this must qualify as pmd_bad().
Signature · 1 line
2.30.2
#1 lore raw
Quoted 30 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +0 -0
index 830107b6dd08..def344bb4a32 100644

mm/debug_vm_pgtable.c static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx) · line 108

Quoted 7 lines
mm/debug_vm_pgtable.c +4 -0
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));

Why do you use

pte_mkwrite_novma(pte)

instead of

pte_mkwrite(pte, args->vma)

?

Quoted 8 lines
mm/debug_vm_pgtable.c +2 -0
+	WARN_ON(!pte_write(pte_mkwrite_novma(pte_wrprotect(pte))));
+	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite_novma(pte))));
 }
 
 static void __init pte_advanced_tests(struct pgtable_debug_args *args)
@@ -195,6 +201,12 @@ static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd, args->vma))));
 	WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd))));

mm/debug_vm_pgtable.c static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx) · line 212

Quoted 10 lines
mm/debug_vm_pgtable.c +6 -0
 	WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd))));
+
+	WARN_ON(pmd_dirty(pmd_mkwrite_novma(pmd_mkclean(pmd))));
+	WARN_ON(!pmd_write(pmd_mkdirty(pmd_mkwrite_novma(pmd))));
+	WARN_ON(!pmd_write(pmd_mkwrite_novma(pmd_wrprotect(pmd))));
+	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite_novma(pmd))));
+
 	/*
 	 * A huge page does not point to next level page table
 	 * entry. Hence this must qualify as pmd_bad().

---
Best Regards,
Huang, Ying

#2 lore raw
Quoted 42 lines · Ying
Quoted 30 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +0 -0
index 830107b6dd08..def344bb4a32 100644

mm/debug_vm_pgtable.c static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx) · line 108

Quoted 7 lines
mm/debug_vm_pgtable.c +4 -0
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));

Why do you use

Quoted 5 lines

pte_mkwrite_novma(pte)

instead of

pte_mkwrite(pte, args->vma)

Just wanted to have more coverage for pte_mkwrite_novma() helper which was missing till now in this test. But just wondering is there a specific reason for replacing this with pte_mkwrite() helper instead here ? Also we could probably add tests for both these helper variations if that is preferred.

#3 lore raw
Quoted 45 lines · Anshuman Khandual
Quoted 44 lines · Ying
Quoted 30 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +0 -0
index 830107b6dd08..def344bb4a32 100644

mm/debug_vm_pgtable.c static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx) · line 108

Quoted 7 lines
mm/debug_vm_pgtable.c +4 -0
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));

Why do you use

pte_mkwrite_novma(pte)

Quoted 7 lines
Quoted 3 lines

instead of

pte_mkwrite(pte, args->vma)

Just wanted to have more coverage for pte_mkwrite_novma() helper which was missing till now in this test. But just wondering is there a specific reason for replacing this with pte_mkwrite() helper instead here ? Also we could probably add tests for both these helper variations if that is preferred.

IIUC, pte_mkwrite() is a more formal interface. pte_mkwrite_novma() is used to implement pte_mkwrite(). So, IMHO, we should use the more formal pte_mkwrite() interface if possible.

---
Best Regards,
Huang, Ying

#4 lore raw
Quoted 50 lines · Ying
Quoted 48 lines · Anshuman Khandual
Quoted 47 lines · Ying
Quoted 30 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

  mm/debug_vm_pgtable.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +0 -0
index 830107b6dd08..def344bb4a32 100644

mm/debug_vm_pgtable.c static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx) · line 108

Quoted 7 lines
mm/debug_vm_pgtable.c +4 -0
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
  	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
  	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
  	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));

Why do you use

pte_mkwrite_novma(pte)

instead of

pte_mkwrite(pte, args->vma)

Quoted 8 lines
Quoted 4 lines

Just wanted to have more coverage for pte_mkwrite_novma() helper which was missing till now in this test. But just wondering is there a specific reason for replacing this with pte_mkwrite() helper instead here ? Also we could probably add tests for both these helper variations if that is preferred.

IIUC, pte_mkwrite() is a more formal interface. pte_mkwrite_novma() is used to implement pte_mkwrite(). So, IMHO, we should use the more formal pte_mkwrite() interface if possible.

pte_mkwrite() does different things based on VMA flags on some archs (e.g., x86). So to test the "interesting" stuff one would have to craft a special VMA.

Without any special flags pte_mkwrite() really is just pte_mkwrite_novma().

Signature · 3 lines
Cheers

David / dhildenb
#5 lore raw
Quoted 60 lines · David Hildenbrand
Quoted 50 lines · Ying
Quoted 48 lines · Anshuman Khandual
Quoted 47 lines · Ying
Quoted 30 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

  mm/debug_vm_pgtable.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +0 -0
index 830107b6dd08..def344bb4a32 100644

mm/debug_vm_pgtable.c static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx) · line 108

Quoted 7 lines
mm/debug_vm_pgtable.c +4 -0
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
  	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
  	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
  	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));

Why do you use

pte_mkwrite_novma(pte)

instead of

pte_mkwrite(pte, args->vma)

Quoted 8 lines
Quoted 4 lines

Just wanted to have more coverage for pte_mkwrite_novma() helper which was missing till now in this test. But just wondering is there a specific reason for replacing this with pte_mkwrite() helper instead here ? Also we could probably add tests for both these helper variations if that is preferred.

IIUC, pte_mkwrite() is a more formal interface. pte_mkwrite_novma() is
used to implement pte_mkwrite(). So, IMHO, we should use the more formal pte_mkwrite() interface if possible.

Quoted 5 lines

pte_mkwrite() does different things based on VMA flags on some archs (e.g., x86). So to test the "interesting" stuff one would have to craft a special VMA.

Without any special flags pte_mkwrite() really is just pte_mkwrite_novma().

Thanks for explanation. If so, I'm fine to use pte_mkwrite_novma() in the tests.

---
Best Regards,
Huang, Ying

#6 lore raw
In reply to Anshuman Khandual
Quoted 43 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +6 -0
index 830107b6dd08..def344bb4a32 100644
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));
+	WARN_ON(!pte_write(pte_mkwrite_novma(pte_wrprotect(pte))));
+	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite_novma(pte))));
 }
 
 static void __init pte_advanced_tests(struct pgtable_debug_args *args)

mm/debug_vm_pgtable.c static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx) · line 208

Quoted 8 lines
mm/debug_vm_pgtable.c +5 -0
@@ -195,6 +201,12 @@ static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd, args->vma))));
 	WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd))));
 	WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd))));
+
+	WARN_ON(pmd_dirty(pmd_mkwrite_novma(pmd_mkclean(pmd))));
+	WARN_ON(!pmd_write(pmd_mkdirty(pmd_mkwrite_novma(pmd))));
+	WARN_ON(!pmd_write(pmd_mkwrite_novma(pmd_wrprotect(pmd))));
+	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite_novma(pmd))));

Why not add

        WARN_ON(!pmd_dirty(pmd_mkwrite_novma(pmd_mkdirty(pte))));

too?

---
Best Regards,
Huang, Ying

Quoted 4 lines
mm/debug_vm_pgtable.c +1 -0
+
 	/*
 	 * A huge page does not point to next level page table
 	 * entry. Hence this must qualify as pmd_bad().
#7 lore raw
Quoted 56 lines · Ying
Quoted 43 lines · Anshuman Khandual

Add some [pte|pmd]_mkwrite_novma() relevant tests.

---
These tests clear on arm64 platform after the following recent patch.

https://lore.kernel.org/all/[email protected]/

Changes in V2:

- Added a new test combination per Huang

Changes in V1:

https://lore.kernel.org/all/[email protected]/

 mm/debug_vm_pgtable.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/debug_vm_pgtable.c +6 -0
index 830107b6dd08..def344bb4a32 100644
@@ -102,6 +102,12 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
 	WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
 	WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
+
+	WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
+	WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));
+	WARN_ON(!pte_write(pte_mkwrite_novma(pte_wrprotect(pte))));
+	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite_novma(pte))));
 }
 
 static void __init pte_advanced_tests(struct pgtable_debug_args *args)

mm/debug_vm_pgtable.c static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx) · line 208

Quoted 8 lines
mm/debug_vm_pgtable.c +5 -0
@@ -195,6 +201,12 @@ static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx)
 	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd, args->vma))));
 	WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd))));
 	WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd))));
+
+	WARN_ON(pmd_dirty(pmd_mkwrite_novma(pmd_mkclean(pmd))));
+	WARN_ON(!pmd_write(pmd_mkdirty(pmd_mkwrite_novma(pmd))));
+	WARN_ON(!pmd_write(pmd_mkwrite_novma(pmd_wrprotect(pmd))));
+	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite_novma(pmd))));

Why not add

Quoted 3 lines
        WARN_ON(!pmd_dirty(pmd_mkwrite_novma(pmd_mkdirty(pte))));

too?

Sure will add the above test which will also be symmetrical with a similar PTE test being proposed here.