Skip to content

Commit 27634d6

Browse files
Anshuman Khandualgregkh
authored andcommitted
mm/debug_vm_pgtable/basic: add validation for dirtiness after write protect
[ Upstream commit bb5c47c ] Patch series "mm/debug_vm_pgtable: Some minor updates", v3. This series contains some cleanups and new test suggestions from Catalin from an earlier discussion. https://lore.kernel.org/linux-mm/20201123142237.GF17833@gaia/ This patch (of 2): This adds validation tests for dirtiness after write protect conversion for each page table level. There are two new separate test types involved here. The first test ensures that a given page table entry does not become dirty after pxx_wrprotect(). This is important for platforms like arm64 which transfers and drops the hardware dirty bit (!PTE_RDONLY) to the software dirty bit while making it an write protected one. This test ensures that no fresh page table entry could be created with hardware dirty bit set. The second test ensures that a given page table entry always preserve the dirty information across pxx_wrprotect(). This adds two previously missing PUD level basic tests and while here fixes pxx_wrprotect() related typos in the documentation file. Link: https://lkml.kernel.org/r/1611137241-26220-1-git-send-email-anshuman.khandual@arm.com Link: https://lkml.kernel.org/r/1611137241-26220-2-git-send-email-anshuman.khandual@arm.com Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Suggested-by: Catalin Marinas <catalin.marinas@arm.com> Tested-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> [s390] Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Steven Price <steven.price@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c872674 commit 27634d6

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎Documentation/vm/arch_pgtable_helpers.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PTE Page Table Helpers
5050
+---------------------------+--------------------------------------------------+
5151
| pte_mkwrite | Creates a writable PTE |
5252
+---------------------------+--------------------------------------------------+
53-
| pte_mkwrprotect | Creates a write protected PTE |
53+
| pte_wrprotect | Creates a write protected PTE |
5454
+---------------------------+--------------------------------------------------+
5555
| pte_mkspecial | Creates a special PTE |
5656
+---------------------------+--------------------------------------------------+
@@ -120,7 +120,7 @@ PMD Page Table Helpers
120120
+---------------------------+--------------------------------------------------+
121121
| pmd_mkwrite | Creates a writable PMD |
122122
+---------------------------+--------------------------------------------------+
123-
| pmd_mkwrprotect | Creates a write protected PMD |
123+
| pmd_wrprotect | Creates a write protected PMD |
124124
+---------------------------+--------------------------------------------------+
125125
| pmd_mkspecial | Creates a special PMD |
126126
+---------------------------+--------------------------------------------------+
@@ -186,7 +186,7 @@ PUD Page Table Helpers
186186
+---------------------------+--------------------------------------------------+
187187
| pud_mkwrite | Creates a writable PUD |
188188
+---------------------------+--------------------------------------------------+
189-
| pud_mkwrprotect | Creates a write protected PUD |
189+
| pud_wrprotect | Creates a write protected PUD |
190190
+---------------------------+--------------------------------------------------+
191191
| pud_mkdevmap | Creates a ZONE_DEVICE mapped PUD |
192192
+---------------------------+--------------------------------------------------+
@@ -224,7 +224,7 @@ HugeTLB Page Table Helpers
224224
+---------------------------+--------------------------------------------------+
225225
| huge_pte_mkwrite | Creates a writable HugeTLB |
226226
+---------------------------+--------------------------------------------------+
227-
| huge_pte_mkwrprotect | Creates a write protected HugeTLB |
227+
| huge_pte_wrprotect | Creates a write protected HugeTLB |
228228
+---------------------------+--------------------------------------------------+
229229
| huge_ptep_get_and_clear | Clears a HugeTLB |
230230
+---------------------------+--------------------------------------------------+

‎mm/debug_vm_pgtable.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,25 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
6363
pte_t pte = pfn_pte(pfn, prot);
6464

6565
pr_debug("Validating PTE basic\n");
66+
67+
/*
68+
* This test needs to be executed after the given page table entry
69+
* is created with pfn_pte() to make sure that protection_map[idx]
70+
* does not have the dirty bit enabled from the beginning. This is
71+
* important for platforms like arm64 where (!PTE_RDONLY) indicate
72+
* dirty bit being set.
73+
*/
74+
WARN_ON(pte_dirty(pte_wrprotect(pte)));
75+
6676
WARN_ON(!pte_same(pte, pte));
6777
WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte))));
6878
WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte))));
6979
WARN_ON(!pte_write(pte_mkwrite(pte_wrprotect(pte))));
7080
WARN_ON(pte_young(pte_mkold(pte_mkyoung(pte))));
7181
WARN_ON(pte_dirty(pte_mkclean(pte_mkdirty(pte))));
7282
WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte))));
83+
WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
84+
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
7385
}
7486

7587
static void __init pte_advanced_tests(struct mm_struct *mm,
@@ -137,13 +149,26 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
137149
return;
138150

139151
pr_debug("Validating PMD basic\n");
152+
153+
/*
154+
* This test needs to be executed after the given page table entry
155+
* is created with pfn_pmd() to make sure that protection_map[idx]
156+
* does not have the dirty bit enabled from the beginning. This is
157+
* important for platforms like arm64 where (!PTE_RDONLY) indicate
158+
* dirty bit being set.
159+
*/
160+
WARN_ON(pmd_dirty(pmd_wrprotect(pmd)));
161+
162+
140163
WARN_ON(!pmd_same(pmd, pmd));
141164
WARN_ON(!pmd_young(pmd_mkyoung(pmd_mkold(pmd))));
142165
WARN_ON(!pmd_dirty(pmd_mkdirty(pmd_mkclean(pmd))));
143166
WARN_ON(!pmd_write(pmd_mkwrite(pmd_wrprotect(pmd))));
144167
WARN_ON(pmd_young(pmd_mkold(pmd_mkyoung(pmd))));
145168
WARN_ON(pmd_dirty(pmd_mkclean(pmd_mkdirty(pmd))));
146169
WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd))));
170+
WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd))));
171+
WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd))));
147172
/*
148173
* A huge page does not point to next level page table
149174
* entry. Hence this must qualify as pmd_bad().
@@ -257,11 +282,25 @@ static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)
257282
return;
258283

259284
pr_debug("Validating PUD basic\n");
285+
286+
/*
287+
* This test needs to be executed after the given page table entry
288+
* is created with pfn_pud() to make sure that protection_map[idx]
289+
* does not have the dirty bit enabled from the beginning. This is
290+
* important for platforms like arm64 where (!PTE_RDONLY) indicate
291+
* dirty bit being set.
292+
*/
293+
WARN_ON(pud_dirty(pud_wrprotect(pud)));
294+
260295
WARN_ON(!pud_same(pud, pud));
261296
WARN_ON(!pud_young(pud_mkyoung(pud_mkold(pud))));
297+
WARN_ON(!pud_dirty(pud_mkdirty(pud_mkclean(pud))));
298+
WARN_ON(pud_dirty(pud_mkclean(pud_mkdirty(pud))));
262299
WARN_ON(!pud_write(pud_mkwrite(pud_wrprotect(pud))));
263300
WARN_ON(pud_write(pud_wrprotect(pud_mkwrite(pud))));
264301
WARN_ON(pud_young(pud_mkold(pud_mkyoung(pud))));
302+
WARN_ON(pud_dirty(pud_wrprotect(pud_mkclean(pud))));
303+
WARN_ON(!pud_dirty(pud_wrprotect(pud_mkdirty(pud))));
265304

266305
if (mm_pmd_folded(mm))
267306
return;

0 commit comments

Comments
 (0)