Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * This kernel test validates architecture page table helpers and |
| 4 | * accessors and helps in verifying their continued compliance with |
| 5 | * expected generic MM semantics. |
| 6 | * |
| 7 | * Copyright (C) 2019 ARM Ltd. |
| 8 | * |
| 9 | * Author: Anshuman Khandual <anshuman.khandual@arm.com> |
| 10 | */ |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 11 | #define pr_fmt(fmt) "debug_vm_pgtable: [%-25s]: " fmt, __func__ |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 12 | |
| 13 | #include <linux/gfp.h> |
| 14 | #include <linux/highmem.h> |
| 15 | #include <linux/hugetlb.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/kconfig.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/mman.h> |
| 20 | #include <linux/mm_types.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/pfn_t.h> |
| 23 | #include <linux/printk.h> |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 24 | #include <linux/pgtable.h> |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 25 | #include <linux/random.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/swap.h> |
| 28 | #include <linux/swapops.h> |
| 29 | #include <linux/start_kernel.h> |
| 30 | #include <linux/sched/mm.h> |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 31 | #include <linux/io.h> |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 32 | #include <asm/pgalloc.h> |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 33 | #include <asm/tlbflush.h> |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 34 | |
Anshuman Khandual | b1d0000 | 2020-08-06 23:19:28 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Please refer Documentation/vm/arch_pgtable_helpers.rst for the semantics |
| 37 | * expectations that are being validated here. All future changes in here |
| 38 | * or the documentation need to be in sync. |
| 39 | */ |
| 40 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 41 | #define VMFLAGS (VM_READ|VM_WRITE|VM_EXEC) |
| 42 | |
| 43 | /* |
| 44 | * On s390 platform, the lower 4 bits are used to identify given page table |
| 45 | * entry type. But these bits might affect the ability to clear entries with |
| 46 | * pxx_clear() because of how dynamic page table folding works on s390. So |
| 47 | * while loading up the entries do not change the lower 4 bits. It does not |
Aneesh Kumar K.V | cfc5bbc | 2020-10-15 20:04:33 -0700 | [diff] [blame] | 48 | * have affect any other platform. Also avoid the 62nd bit on ppc64 that is |
| 49 | * used to mark a pte entry. |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 50 | */ |
Aneesh Kumar K.V | cfc5bbc | 2020-10-15 20:04:33 -0700 | [diff] [blame] | 51 | #define S390_SKIP_MASK GENMASK(3, 0) |
| 52 | #if __BITS_PER_LONG == 64 |
| 53 | #define PPC64_SKIP_MASK GENMASK(62, 62) |
| 54 | #else |
| 55 | #define PPC64_SKIP_MASK 0x0 |
| 56 | #endif |
| 57 | #define ARCH_SKIP_MASK (S390_SKIP_MASK | PPC64_SKIP_MASK) |
| 58 | #define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK) |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 59 | #define RANDOM_NZVALUE GENMASK(7, 0) |
| 60 | |
| 61 | static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) |
| 62 | { |
| 63 | pte_t pte = pfn_pte(pfn, prot); |
| 64 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 65 | pr_debug("Validating PTE basic\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 66 | WARN_ON(!pte_same(pte, pte)); |
| 67 | WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte)))); |
| 68 | WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte)))); |
| 69 | WARN_ON(!pte_write(pte_mkwrite(pte_wrprotect(pte)))); |
| 70 | WARN_ON(pte_young(pte_mkold(pte_mkyoung(pte)))); |
| 71 | WARN_ON(pte_dirty(pte_mkclean(pte_mkdirty(pte)))); |
| 72 | WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte)))); |
| 73 | } |
| 74 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 75 | static void __init pte_advanced_tests(struct mm_struct *mm, |
| 76 | struct vm_area_struct *vma, pte_t *ptep, |
| 77 | unsigned long pfn, unsigned long vaddr, |
| 78 | pgprot_t prot) |
| 79 | { |
| 80 | pte_t pte = pfn_pte(pfn, prot); |
| 81 | |
Aneesh Kumar K.V | c3824e1 | 2020-10-15 20:04:46 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Architectures optimize set_pte_at by avoiding TLB flush. |
| 84 | * This requires set_pte_at to be not used to update an |
| 85 | * existing pte entry. Clear pte before we do set_pte_at |
| 86 | */ |
| 87 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 88 | pr_debug("Validating PTE advanced\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 89 | pte = pfn_pte(pfn, prot); |
| 90 | set_pte_at(mm, vaddr, ptep, pte); |
| 91 | ptep_set_wrprotect(mm, vaddr, ptep); |
| 92 | pte = ptep_get(ptep); |
| 93 | WARN_ON(pte_write(pte)); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 94 | ptep_get_and_clear(mm, vaddr, ptep); |
| 95 | pte = ptep_get(ptep); |
| 96 | WARN_ON(!pte_none(pte)); |
| 97 | |
| 98 | pte = pfn_pte(pfn, prot); |
| 99 | pte = pte_wrprotect(pte); |
| 100 | pte = pte_mkclean(pte); |
| 101 | set_pte_at(mm, vaddr, ptep, pte); |
| 102 | pte = pte_mkwrite(pte); |
| 103 | pte = pte_mkdirty(pte); |
| 104 | ptep_set_access_flags(vma, vaddr, ptep, pte, 1); |
| 105 | pte = ptep_get(ptep); |
| 106 | WARN_ON(!(pte_write(pte) && pte_dirty(pte))); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 107 | ptep_get_and_clear_full(mm, vaddr, ptep, 1); |
| 108 | pte = ptep_get(ptep); |
| 109 | WARN_ON(!pte_none(pte)); |
| 110 | |
Aneesh Kumar K.V | c3824e1 | 2020-10-15 20:04:46 -0700 | [diff] [blame] | 111 | pte = pfn_pte(pfn, prot); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 112 | pte = pte_mkyoung(pte); |
| 113 | set_pte_at(mm, vaddr, ptep, pte); |
| 114 | ptep_test_and_clear_young(vma, vaddr, ptep); |
| 115 | pte = ptep_get(ptep); |
| 116 | WARN_ON(pte_young(pte)); |
| 117 | } |
| 118 | |
| 119 | static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot) |
| 120 | { |
| 121 | pte_t pte = pfn_pte(pfn, prot); |
| 122 | |
Aneesh Kumar K.V | 4200605 | 2020-10-15 20:04:40 -0700 | [diff] [blame] | 123 | if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) |
| 124 | return; |
| 125 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 126 | pr_debug("Validating PTE saved write\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 127 | WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte)))); |
| 128 | WARN_ON(pte_savedwrite(pte_clear_savedwrite(pte_mk_savedwrite(pte)))); |
| 129 | } |
Aneesh Kumar K.V | 4200605 | 2020-10-15 20:04:40 -0700 | [diff] [blame] | 130 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 131 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 132 | static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot) |
| 133 | { |
| 134 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 135 | |
Aneesh Kumar K.V | 787d563 | 2020-06-10 18:41:44 -0700 | [diff] [blame] | 136 | if (!has_transparent_hugepage()) |
| 137 | return; |
| 138 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 139 | pr_debug("Validating PMD basic\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 140 | WARN_ON(!pmd_same(pmd, pmd)); |
| 141 | WARN_ON(!pmd_young(pmd_mkyoung(pmd_mkold(pmd)))); |
| 142 | WARN_ON(!pmd_dirty(pmd_mkdirty(pmd_mkclean(pmd)))); |
| 143 | WARN_ON(!pmd_write(pmd_mkwrite(pmd_wrprotect(pmd)))); |
| 144 | WARN_ON(pmd_young(pmd_mkold(pmd_mkyoung(pmd)))); |
| 145 | WARN_ON(pmd_dirty(pmd_mkclean(pmd_mkdirty(pmd)))); |
| 146 | WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd)))); |
| 147 | /* |
| 148 | * A huge page does not point to next level page table |
| 149 | * entry. Hence this must qualify as pmd_bad(). |
| 150 | */ |
| 151 | WARN_ON(!pmd_bad(pmd_mkhuge(pmd))); |
| 152 | } |
| 153 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 154 | static void __init pmd_advanced_tests(struct mm_struct *mm, |
| 155 | struct vm_area_struct *vma, pmd_t *pmdp, |
| 156 | unsigned long pfn, unsigned long vaddr, |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 157 | pgprot_t prot, pgtable_t pgtable) |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 158 | { |
| 159 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 160 | |
| 161 | if (!has_transparent_hugepage()) |
| 162 | return; |
| 163 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 164 | pr_debug("Validating PMD advanced\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 165 | /* Align the address wrt HPAGE_PMD_SIZE */ |
| 166 | vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE; |
| 167 | |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 168 | pgtable_trans_huge_deposit(mm, pmdp, pgtable); |
| 169 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 170 | pmd = pfn_pmd(pfn, prot); |
| 171 | set_pmd_at(mm, vaddr, pmdp, pmd); |
| 172 | pmdp_set_wrprotect(mm, vaddr, pmdp); |
| 173 | pmd = READ_ONCE(*pmdp); |
| 174 | WARN_ON(pmd_write(pmd)); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 175 | pmdp_huge_get_and_clear(mm, vaddr, pmdp); |
| 176 | pmd = READ_ONCE(*pmdp); |
| 177 | WARN_ON(!pmd_none(pmd)); |
| 178 | |
| 179 | pmd = pfn_pmd(pfn, prot); |
| 180 | pmd = pmd_wrprotect(pmd); |
| 181 | pmd = pmd_mkclean(pmd); |
| 182 | set_pmd_at(mm, vaddr, pmdp, pmd); |
| 183 | pmd = pmd_mkwrite(pmd); |
| 184 | pmd = pmd_mkdirty(pmd); |
| 185 | pmdp_set_access_flags(vma, vaddr, pmdp, pmd, 1); |
| 186 | pmd = READ_ONCE(*pmdp); |
| 187 | WARN_ON(!(pmd_write(pmd) && pmd_dirty(pmd))); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 188 | pmdp_huge_get_and_clear_full(vma, vaddr, pmdp, 1); |
| 189 | pmd = READ_ONCE(*pmdp); |
| 190 | WARN_ON(!pmd_none(pmd)); |
| 191 | |
Aneesh Kumar K.V | c3824e1 | 2020-10-15 20:04:46 -0700 | [diff] [blame] | 192 | pmd = pmd_mkhuge(pfn_pmd(pfn, prot)); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 193 | pmd = pmd_mkyoung(pmd); |
| 194 | set_pmd_at(mm, vaddr, pmdp, pmd); |
| 195 | pmdp_test_and_clear_young(vma, vaddr, pmdp); |
| 196 | pmd = READ_ONCE(*pmdp); |
| 197 | WARN_ON(pmd_young(pmd)); |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 198 | |
Aneesh Kumar K.V | 13af050 | 2020-10-15 20:04:59 -0700 | [diff] [blame^] | 199 | /* Clear the pte entries */ |
| 200 | pmdp_huge_get_and_clear(mm, vaddr, pmdp); |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 201 | pgtable = pgtable_trans_huge_withdraw(mm, pmdp); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) |
| 205 | { |
| 206 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 207 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 208 | pr_debug("Validating PMD leaf\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 209 | /* |
| 210 | * PMD based THP is a leaf entry. |
| 211 | */ |
| 212 | pmd = pmd_mkhuge(pmd); |
| 213 | WARN_ON(!pmd_leaf(pmd)); |
| 214 | } |
| 215 | |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 216 | #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 217 | static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) |
| 218 | { |
| 219 | pmd_t pmd; |
| 220 | |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 221 | if (!arch_ioremap_pmd_supported()) |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 222 | return; |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 223 | |
| 224 | pr_debug("Validating PMD huge\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 225 | /* |
| 226 | * X86 defined pmd_set_huge() verifies that the given |
| 227 | * PMD is not a populated non-leaf entry. |
| 228 | */ |
| 229 | WRITE_ONCE(*pmdp, __pmd(0)); |
| 230 | WARN_ON(!pmd_set_huge(pmdp, __pfn_to_phys(pfn), prot)); |
| 231 | WARN_ON(!pmd_clear_huge(pmdp)); |
| 232 | pmd = READ_ONCE(*pmdp); |
| 233 | WARN_ON(!pmd_none(pmd)); |
| 234 | } |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 235 | #else /* CONFIG_HAVE_ARCH_HUGE_VMAP */ |
| 236 | static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) { } |
| 237 | #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 238 | |
| 239 | static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) |
| 240 | { |
| 241 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 242 | |
Aneesh Kumar K.V | 4200605 | 2020-10-15 20:04:40 -0700 | [diff] [blame] | 243 | if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) |
| 244 | return; |
| 245 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 246 | pr_debug("Validating PMD saved write\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 247 | WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd)))); |
| 248 | WARN_ON(pmd_savedwrite(pmd_clear_savedwrite(pmd_mk_savedwrite(pmd)))); |
| 249 | } |
| 250 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 251 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD |
| 252 | static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) |
| 253 | { |
| 254 | pud_t pud = pfn_pud(pfn, prot); |
| 255 | |
Aneesh Kumar K.V | 787d563 | 2020-06-10 18:41:44 -0700 | [diff] [blame] | 256 | if (!has_transparent_hugepage()) |
| 257 | return; |
| 258 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 259 | pr_debug("Validating PUD basic\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 260 | WARN_ON(!pud_same(pud, pud)); |
| 261 | WARN_ON(!pud_young(pud_mkyoung(pud_mkold(pud)))); |
| 262 | WARN_ON(!pud_write(pud_mkwrite(pud_wrprotect(pud)))); |
| 263 | WARN_ON(pud_write(pud_wrprotect(pud_mkwrite(pud)))); |
| 264 | WARN_ON(pud_young(pud_mkold(pud_mkyoung(pud)))); |
| 265 | |
| 266 | if (mm_pmd_folded(mm)) |
| 267 | return; |
| 268 | |
| 269 | /* |
| 270 | * A huge page does not point to next level page table |
| 271 | * entry. Hence this must qualify as pud_bad(). |
| 272 | */ |
| 273 | WARN_ON(!pud_bad(pud_mkhuge(pud))); |
| 274 | } |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 275 | |
| 276 | static void __init pud_advanced_tests(struct mm_struct *mm, |
| 277 | struct vm_area_struct *vma, pud_t *pudp, |
| 278 | unsigned long pfn, unsigned long vaddr, |
| 279 | pgprot_t prot) |
| 280 | { |
| 281 | pud_t pud = pfn_pud(pfn, prot); |
| 282 | |
| 283 | if (!has_transparent_hugepage()) |
| 284 | return; |
| 285 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 286 | pr_debug("Validating PUD advanced\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 287 | /* Align the address wrt HPAGE_PUD_SIZE */ |
| 288 | vaddr = (vaddr & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE; |
| 289 | |
| 290 | set_pud_at(mm, vaddr, pudp, pud); |
| 291 | pudp_set_wrprotect(mm, vaddr, pudp); |
| 292 | pud = READ_ONCE(*pudp); |
| 293 | WARN_ON(pud_write(pud)); |
| 294 | |
| 295 | #ifndef __PAGETABLE_PMD_FOLDED |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 296 | pudp_huge_get_and_clear(mm, vaddr, pudp); |
| 297 | pud = READ_ONCE(*pudp); |
| 298 | WARN_ON(!pud_none(pud)); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 299 | #endif /* __PAGETABLE_PMD_FOLDED */ |
| 300 | pud = pfn_pud(pfn, prot); |
| 301 | pud = pud_wrprotect(pud); |
| 302 | pud = pud_mkclean(pud); |
| 303 | set_pud_at(mm, vaddr, pudp, pud); |
| 304 | pud = pud_mkwrite(pud); |
| 305 | pud = pud_mkdirty(pud); |
| 306 | pudp_set_access_flags(vma, vaddr, pudp, pud, 1); |
| 307 | pud = READ_ONCE(*pudp); |
| 308 | WARN_ON(!(pud_write(pud) && pud_dirty(pud))); |
| 309 | |
Aneesh Kumar K.V | c3824e1 | 2020-10-15 20:04:46 -0700 | [diff] [blame] | 310 | #ifndef __PAGETABLE_PMD_FOLDED |
| 311 | pudp_huge_get_and_clear_full(mm, vaddr, pudp, 1); |
| 312 | pud = READ_ONCE(*pudp); |
| 313 | WARN_ON(!pud_none(pud)); |
| 314 | #endif /* __PAGETABLE_PMD_FOLDED */ |
| 315 | |
| 316 | pud = pfn_pud(pfn, prot); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 317 | pud = pud_mkyoung(pud); |
| 318 | set_pud_at(mm, vaddr, pudp, pud); |
| 319 | pudp_test_and_clear_young(vma, vaddr, pudp); |
| 320 | pud = READ_ONCE(*pudp); |
| 321 | WARN_ON(pud_young(pud)); |
Aneesh Kumar K.V | 13af050 | 2020-10-15 20:04:59 -0700 | [diff] [blame^] | 322 | |
| 323 | pudp_huge_get_and_clear(mm, vaddr, pudp); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) |
| 327 | { |
| 328 | pud_t pud = pfn_pud(pfn, prot); |
| 329 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 330 | pr_debug("Validating PUD leaf\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 331 | /* |
| 332 | * PUD based THP is a leaf entry. |
| 333 | */ |
| 334 | pud = pud_mkhuge(pud); |
| 335 | WARN_ON(!pud_leaf(pud)); |
| 336 | } |
| 337 | |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 338 | #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 339 | static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) |
| 340 | { |
| 341 | pud_t pud; |
| 342 | |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 343 | if (!arch_ioremap_pud_supported()) |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 344 | return; |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 345 | |
| 346 | pr_debug("Validating PUD huge\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 347 | /* |
| 348 | * X86 defined pud_set_huge() verifies that the given |
| 349 | * PUD is not a populated non-leaf entry. |
| 350 | */ |
| 351 | WRITE_ONCE(*pudp, __pud(0)); |
| 352 | WARN_ON(!pud_set_huge(pudp, __pfn_to_phys(pfn), prot)); |
| 353 | WARN_ON(!pud_clear_huge(pudp)); |
| 354 | pud = READ_ONCE(*pudp); |
| 355 | WARN_ON(!pud_none(pud)); |
| 356 | } |
Aneesh Kumar K.V | 85a1446 | 2020-10-15 20:04:36 -0700 | [diff] [blame] | 357 | #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ |
| 358 | static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) { } |
| 359 | #endif /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ |
| 360 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 361 | #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 362 | static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) { } |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 363 | static void __init pud_advanced_tests(struct mm_struct *mm, |
| 364 | struct vm_area_struct *vma, pud_t *pudp, |
| 365 | unsigned long pfn, unsigned long vaddr, |
| 366 | pgprot_t prot) |
| 367 | { |
| 368 | } |
| 369 | static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) { } |
| 370 | static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) |
| 371 | { |
| 372 | } |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 373 | #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 374 | #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ |
| 375 | static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot) { } |
| 376 | static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) { } |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 377 | static void __init pmd_advanced_tests(struct mm_struct *mm, |
| 378 | struct vm_area_struct *vma, pmd_t *pmdp, |
| 379 | unsigned long pfn, unsigned long vaddr, |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 380 | pgprot_t prot, pgtable_t pgtable) |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 381 | { |
| 382 | } |
| 383 | static void __init pud_advanced_tests(struct mm_struct *mm, |
| 384 | struct vm_area_struct *vma, pud_t *pudp, |
| 385 | unsigned long pfn, unsigned long vaddr, |
| 386 | pgprot_t prot) |
| 387 | { |
| 388 | } |
| 389 | static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) { } |
| 390 | static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) { } |
| 391 | static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) |
| 392 | { |
| 393 | } |
| 394 | static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) |
| 395 | { |
| 396 | } |
| 397 | static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) { } |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 398 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 399 | |
| 400 | static void __init p4d_basic_tests(unsigned long pfn, pgprot_t prot) |
| 401 | { |
| 402 | p4d_t p4d; |
| 403 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 404 | pr_debug("Validating P4D basic\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 405 | memset(&p4d, RANDOM_NZVALUE, sizeof(p4d_t)); |
| 406 | WARN_ON(!p4d_same(p4d, p4d)); |
| 407 | } |
| 408 | |
| 409 | static void __init pgd_basic_tests(unsigned long pfn, pgprot_t prot) |
| 410 | { |
| 411 | pgd_t pgd; |
| 412 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 413 | pr_debug("Validating PGD basic\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 414 | memset(&pgd, RANDOM_NZVALUE, sizeof(pgd_t)); |
| 415 | WARN_ON(!pgd_same(pgd, pgd)); |
| 416 | } |
| 417 | |
| 418 | #ifndef __PAGETABLE_PUD_FOLDED |
| 419 | static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) |
| 420 | { |
| 421 | pud_t pud = READ_ONCE(*pudp); |
| 422 | |
| 423 | if (mm_pmd_folded(mm)) |
| 424 | return; |
| 425 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 426 | pr_debug("Validating PUD clear\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 427 | pud = __pud(pud_val(pud) | RANDOM_ORVALUE); |
| 428 | WRITE_ONCE(*pudp, pud); |
| 429 | pud_clear(pudp); |
| 430 | pud = READ_ONCE(*pudp); |
| 431 | WARN_ON(!pud_none(pud)); |
| 432 | } |
| 433 | |
| 434 | static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, |
| 435 | pmd_t *pmdp) |
| 436 | { |
| 437 | pud_t pud; |
| 438 | |
| 439 | if (mm_pmd_folded(mm)) |
| 440 | return; |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 441 | |
| 442 | pr_debug("Validating PUD populate\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 443 | /* |
| 444 | * This entry points to next level page table page. |
| 445 | * Hence this must not qualify as pud_bad(). |
| 446 | */ |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 447 | pud_populate(mm, pudp, pmdp); |
| 448 | pud = READ_ONCE(*pudp); |
| 449 | WARN_ON(pud_bad(pud)); |
| 450 | } |
| 451 | #else /* !__PAGETABLE_PUD_FOLDED */ |
| 452 | static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) { } |
| 453 | static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, |
| 454 | pmd_t *pmdp) |
| 455 | { |
| 456 | } |
| 457 | #endif /* PAGETABLE_PUD_FOLDED */ |
| 458 | |
| 459 | #ifndef __PAGETABLE_P4D_FOLDED |
| 460 | static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) |
| 461 | { |
| 462 | p4d_t p4d = READ_ONCE(*p4dp); |
| 463 | |
| 464 | if (mm_pud_folded(mm)) |
| 465 | return; |
| 466 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 467 | pr_debug("Validating P4D clear\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 468 | p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE); |
| 469 | WRITE_ONCE(*p4dp, p4d); |
| 470 | p4d_clear(p4dp); |
| 471 | p4d = READ_ONCE(*p4dp); |
| 472 | WARN_ON(!p4d_none(p4d)); |
| 473 | } |
| 474 | |
| 475 | static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp, |
| 476 | pud_t *pudp) |
| 477 | { |
| 478 | p4d_t p4d; |
| 479 | |
| 480 | if (mm_pud_folded(mm)) |
| 481 | return; |
| 482 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 483 | pr_debug("Validating P4D populate\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 484 | /* |
| 485 | * This entry points to next level page table page. |
| 486 | * Hence this must not qualify as p4d_bad(). |
| 487 | */ |
| 488 | pud_clear(pudp); |
| 489 | p4d_clear(p4dp); |
| 490 | p4d_populate(mm, p4dp, pudp); |
| 491 | p4d = READ_ONCE(*p4dp); |
| 492 | WARN_ON(p4d_bad(p4d)); |
| 493 | } |
| 494 | |
| 495 | static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) |
| 496 | { |
| 497 | pgd_t pgd = READ_ONCE(*pgdp); |
| 498 | |
| 499 | if (mm_p4d_folded(mm)) |
| 500 | return; |
| 501 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 502 | pr_debug("Validating PGD clear\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 503 | pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE); |
| 504 | WRITE_ONCE(*pgdp, pgd); |
| 505 | pgd_clear(pgdp); |
| 506 | pgd = READ_ONCE(*pgdp); |
| 507 | WARN_ON(!pgd_none(pgd)); |
| 508 | } |
| 509 | |
| 510 | static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, |
| 511 | p4d_t *p4dp) |
| 512 | { |
| 513 | pgd_t pgd; |
| 514 | |
| 515 | if (mm_p4d_folded(mm)) |
| 516 | return; |
| 517 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 518 | pr_debug("Validating PGD populate\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 519 | /* |
| 520 | * This entry points to next level page table page. |
| 521 | * Hence this must not qualify as pgd_bad(). |
| 522 | */ |
| 523 | p4d_clear(p4dp); |
| 524 | pgd_clear(pgdp); |
| 525 | pgd_populate(mm, pgdp, p4dp); |
| 526 | pgd = READ_ONCE(*pgdp); |
| 527 | WARN_ON(pgd_bad(pgd)); |
| 528 | } |
| 529 | #else /* !__PAGETABLE_P4D_FOLDED */ |
| 530 | static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) { } |
| 531 | static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) { } |
| 532 | static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp, |
| 533 | pud_t *pudp) |
| 534 | { |
| 535 | } |
| 536 | static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, |
| 537 | p4d_t *p4dp) |
| 538 | { |
| 539 | } |
| 540 | #endif /* PAGETABLE_P4D_FOLDED */ |
| 541 | |
| 542 | static void __init pte_clear_tests(struct mm_struct *mm, pte_t *ptep, |
| 543 | unsigned long vaddr) |
| 544 | { |
Christophe Leroy | 9449c9c | 2020-06-25 20:30:04 -0700 | [diff] [blame] | 545 | pte_t pte = ptep_get(ptep); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 546 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 547 | pr_debug("Validating PTE clear\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 548 | pte = __pte(pte_val(pte) | RANDOM_ORVALUE); |
| 549 | set_pte_at(mm, vaddr, ptep, pte); |
| 550 | barrier(); |
| 551 | pte_clear(mm, vaddr, ptep); |
Christophe Leroy | 9449c9c | 2020-06-25 20:30:04 -0700 | [diff] [blame] | 552 | pte = ptep_get(ptep); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 553 | WARN_ON(!pte_none(pte)); |
| 554 | } |
| 555 | |
| 556 | static void __init pmd_clear_tests(struct mm_struct *mm, pmd_t *pmdp) |
| 557 | { |
| 558 | pmd_t pmd = READ_ONCE(*pmdp); |
| 559 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 560 | pr_debug("Validating PMD clear\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 561 | pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE); |
| 562 | WRITE_ONCE(*pmdp, pmd); |
| 563 | pmd_clear(pmdp); |
| 564 | pmd = READ_ONCE(*pmdp); |
| 565 | WARN_ON(!pmd_none(pmd)); |
| 566 | } |
| 567 | |
| 568 | static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, |
| 569 | pgtable_t pgtable) |
| 570 | { |
| 571 | pmd_t pmd; |
| 572 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 573 | pr_debug("Validating PMD populate\n"); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 574 | /* |
| 575 | * This entry points to next level page table page. |
| 576 | * Hence this must not qualify as pmd_bad(). |
| 577 | */ |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 578 | pmd_populate(mm, pmdp, pgtable); |
| 579 | pmd = READ_ONCE(*pmdp); |
| 580 | WARN_ON(pmd_bad(pmd)); |
| 581 | } |
| 582 | |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 583 | static void __init pte_special_tests(unsigned long pfn, pgprot_t prot) |
| 584 | { |
| 585 | pte_t pte = pfn_pte(pfn, prot); |
| 586 | |
| 587 | if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL)) |
| 588 | return; |
| 589 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 590 | pr_debug("Validating PTE special\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 591 | WARN_ON(!pte_special(pte_mkspecial(pte))); |
| 592 | } |
| 593 | |
| 594 | static void __init pte_protnone_tests(unsigned long pfn, pgprot_t prot) |
| 595 | { |
| 596 | pte_t pte = pfn_pte(pfn, prot); |
| 597 | |
| 598 | if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) |
| 599 | return; |
| 600 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 601 | pr_debug("Validating PTE protnone\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 602 | WARN_ON(!pte_protnone(pte)); |
| 603 | WARN_ON(!pte_present(pte)); |
| 604 | } |
| 605 | |
| 606 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 607 | static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) |
| 608 | { |
| 609 | pmd_t pmd = pmd_mkhuge(pfn_pmd(pfn, prot)); |
| 610 | |
| 611 | if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) |
| 612 | return; |
| 613 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 614 | pr_debug("Validating PMD protnone\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 615 | WARN_ON(!pmd_protnone(pmd)); |
| 616 | WARN_ON(!pmd_present(pmd)); |
| 617 | } |
| 618 | #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ |
| 619 | static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) { } |
| 620 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 621 | |
| 622 | #ifdef CONFIG_ARCH_HAS_PTE_DEVMAP |
| 623 | static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot) |
| 624 | { |
| 625 | pte_t pte = pfn_pte(pfn, prot); |
| 626 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 627 | pr_debug("Validating PTE devmap\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 628 | WARN_ON(!pte_devmap(pte_mkdevmap(pte))); |
| 629 | } |
| 630 | |
| 631 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 632 | static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) |
| 633 | { |
| 634 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 635 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 636 | pr_debug("Validating PMD devmap\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 637 | WARN_ON(!pmd_devmap(pmd_mkdevmap(pmd))); |
| 638 | } |
| 639 | |
| 640 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD |
| 641 | static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) |
| 642 | { |
| 643 | pud_t pud = pfn_pud(pfn, prot); |
| 644 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 645 | pr_debug("Validating PUD devmap\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 646 | WARN_ON(!pud_devmap(pud_mkdevmap(pud))); |
| 647 | } |
| 648 | #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 649 | static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 650 | #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 651 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 652 | static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 653 | static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 654 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 655 | #else |
| 656 | static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 657 | static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 658 | static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } |
| 659 | #endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ |
| 660 | |
| 661 | static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot) |
| 662 | { |
| 663 | pte_t pte = pfn_pte(pfn, prot); |
| 664 | |
| 665 | if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) |
| 666 | return; |
| 667 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 668 | pr_debug("Validating PTE soft dirty\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 669 | WARN_ON(!pte_soft_dirty(pte_mksoft_dirty(pte))); |
| 670 | WARN_ON(pte_soft_dirty(pte_clear_soft_dirty(pte))); |
| 671 | } |
| 672 | |
| 673 | static void __init pte_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) |
| 674 | { |
| 675 | pte_t pte = pfn_pte(pfn, prot); |
| 676 | |
| 677 | if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) |
| 678 | return; |
| 679 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 680 | pr_debug("Validating PTE swap soft dirty\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 681 | WARN_ON(!pte_swp_soft_dirty(pte_swp_mksoft_dirty(pte))); |
| 682 | WARN_ON(pte_swp_soft_dirty(pte_swp_clear_soft_dirty(pte))); |
| 683 | } |
| 684 | |
| 685 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 686 | static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot) |
| 687 | { |
| 688 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 689 | |
| 690 | if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) |
| 691 | return; |
| 692 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 693 | pr_debug("Validating PMD soft dirty\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 694 | WARN_ON(!pmd_soft_dirty(pmd_mksoft_dirty(pmd))); |
| 695 | WARN_ON(pmd_soft_dirty(pmd_clear_soft_dirty(pmd))); |
| 696 | } |
| 697 | |
| 698 | static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) |
| 699 | { |
| 700 | pmd_t pmd = pfn_pmd(pfn, prot); |
| 701 | |
| 702 | if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) || |
| 703 | !IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION)) |
| 704 | return; |
| 705 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 706 | pr_debug("Validating PMD swap soft dirty\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 707 | WARN_ON(!pmd_swp_soft_dirty(pmd_swp_mksoft_dirty(pmd))); |
| 708 | WARN_ON(pmd_swp_soft_dirty(pmd_swp_clear_soft_dirty(pmd))); |
| 709 | } |
| 710 | #else /* !CONFIG_ARCH_HAS_PTE_DEVMAP */ |
| 711 | static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot) { } |
| 712 | static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) |
| 713 | { |
| 714 | } |
| 715 | #endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ |
| 716 | |
| 717 | static void __init pte_swap_tests(unsigned long pfn, pgprot_t prot) |
| 718 | { |
| 719 | swp_entry_t swp; |
| 720 | pte_t pte; |
| 721 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 722 | pr_debug("Validating PTE swap\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 723 | pte = pfn_pte(pfn, prot); |
| 724 | swp = __pte_to_swp_entry(pte); |
| 725 | pte = __swp_entry_to_pte(swp); |
| 726 | WARN_ON(pfn != pte_pfn(pte)); |
| 727 | } |
| 728 | |
| 729 | #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION |
| 730 | static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot) |
| 731 | { |
| 732 | swp_entry_t swp; |
| 733 | pmd_t pmd; |
| 734 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 735 | pr_debug("Validating PMD swap\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 736 | pmd = pfn_pmd(pfn, prot); |
| 737 | swp = __pmd_to_swp_entry(pmd); |
| 738 | pmd = __swp_entry_to_pmd(swp); |
| 739 | WARN_ON(pfn != pmd_pfn(pmd)); |
| 740 | } |
| 741 | #else /* !CONFIG_ARCH_ENABLE_THP_MIGRATION */ |
| 742 | static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot) { } |
| 743 | #endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ |
| 744 | |
| 745 | static void __init swap_migration_tests(void) |
| 746 | { |
| 747 | struct page *page; |
| 748 | swp_entry_t swp; |
| 749 | |
| 750 | if (!IS_ENABLED(CONFIG_MIGRATION)) |
| 751 | return; |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 752 | |
| 753 | pr_debug("Validating swap migration\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 754 | /* |
| 755 | * swap_migration_tests() requires a dedicated page as it needs to |
| 756 | * be locked before creating a migration entry from it. Locking the |
| 757 | * page that actually maps kernel text ('start_kernel') can be real |
| 758 | * problematic. Lets allocate a dedicated page explicitly for this |
| 759 | * purpose that will be freed subsequently. |
| 760 | */ |
| 761 | page = alloc_page(GFP_KERNEL); |
| 762 | if (!page) { |
| 763 | pr_err("page allocation failed\n"); |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * make_migration_entry() expects given page to be |
| 769 | * locked, otherwise it stumbles upon a BUG_ON(). |
| 770 | */ |
| 771 | __SetPageLocked(page); |
| 772 | swp = make_migration_entry(page, 1); |
| 773 | WARN_ON(!is_migration_entry(swp)); |
| 774 | WARN_ON(!is_write_migration_entry(swp)); |
| 775 | |
| 776 | make_migration_entry_read(&swp); |
| 777 | WARN_ON(!is_migration_entry(swp)); |
| 778 | WARN_ON(is_write_migration_entry(swp)); |
| 779 | |
| 780 | swp = make_migration_entry(page, 0); |
| 781 | WARN_ON(!is_migration_entry(swp)); |
| 782 | WARN_ON(is_write_migration_entry(swp)); |
| 783 | __ClearPageLocked(page); |
| 784 | __free_page(page); |
| 785 | } |
| 786 | |
| 787 | #ifdef CONFIG_HUGETLB_PAGE |
| 788 | static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) |
| 789 | { |
| 790 | struct page *page; |
| 791 | pte_t pte; |
| 792 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 793 | pr_debug("Validating HugeTLB basic\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 794 | /* |
| 795 | * Accessing the page associated with the pfn is safe here, |
| 796 | * as it was previously derived from a real kernel symbol. |
| 797 | */ |
| 798 | page = pfn_to_page(pfn); |
| 799 | pte = mk_huge_pte(page, prot); |
| 800 | |
| 801 | WARN_ON(!huge_pte_dirty(huge_pte_mkdirty(pte))); |
| 802 | WARN_ON(!huge_pte_write(huge_pte_mkwrite(huge_pte_wrprotect(pte)))); |
| 803 | WARN_ON(huge_pte_write(huge_pte_wrprotect(huge_pte_mkwrite(pte)))); |
| 804 | |
| 805 | #ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB |
| 806 | pte = pfn_pte(pfn, prot); |
| 807 | |
| 808 | WARN_ON(!pte_huge(pte_mkhuge(pte))); |
| 809 | #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ |
| 810 | } |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 811 | |
| 812 | static void __init hugetlb_advanced_tests(struct mm_struct *mm, |
| 813 | struct vm_area_struct *vma, |
| 814 | pte_t *ptep, unsigned long pfn, |
| 815 | unsigned long vaddr, pgprot_t prot) |
| 816 | { |
| 817 | struct page *page = pfn_to_page(pfn); |
| 818 | pte_t pte = ptep_get(ptep); |
| 819 | unsigned long paddr = __pfn_to_phys(pfn) & PMD_MASK; |
| 820 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 821 | pr_debug("Validating HugeTLB advanced\n"); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 822 | pte = pte_mkhuge(mk_pte(pfn_to_page(PHYS_PFN(paddr)), prot)); |
| 823 | set_huge_pte_at(mm, vaddr, ptep, pte); |
| 824 | barrier(); |
| 825 | WARN_ON(!pte_same(pte, huge_ptep_get(ptep))); |
| 826 | huge_pte_clear(mm, vaddr, ptep, PMD_SIZE); |
| 827 | pte = huge_ptep_get(ptep); |
| 828 | WARN_ON(!huge_pte_none(pte)); |
| 829 | |
| 830 | pte = mk_huge_pte(page, prot); |
| 831 | set_huge_pte_at(mm, vaddr, ptep, pte); |
| 832 | barrier(); |
| 833 | huge_ptep_set_wrprotect(mm, vaddr, ptep); |
| 834 | pte = huge_ptep_get(ptep); |
| 835 | WARN_ON(huge_pte_write(pte)); |
| 836 | |
| 837 | pte = mk_huge_pte(page, prot); |
| 838 | set_huge_pte_at(mm, vaddr, ptep, pte); |
| 839 | barrier(); |
| 840 | huge_ptep_get_and_clear(mm, vaddr, ptep); |
| 841 | pte = huge_ptep_get(ptep); |
| 842 | WARN_ON(!huge_pte_none(pte)); |
| 843 | |
| 844 | pte = mk_huge_pte(page, prot); |
| 845 | pte = huge_pte_wrprotect(pte); |
| 846 | set_huge_pte_at(mm, vaddr, ptep, pte); |
| 847 | barrier(); |
| 848 | pte = huge_pte_mkwrite(pte); |
| 849 | pte = huge_pte_mkdirty(pte); |
| 850 | huge_ptep_set_access_flags(vma, vaddr, ptep, pte, 1); |
| 851 | pte = huge_ptep_get(ptep); |
| 852 | WARN_ON(!(huge_pte_write(pte) && huge_pte_dirty(pte))); |
| 853 | } |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 854 | #else /* !CONFIG_HUGETLB_PAGE */ |
| 855 | static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { } |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 856 | static void __init hugetlb_advanced_tests(struct mm_struct *mm, |
| 857 | struct vm_area_struct *vma, |
| 858 | pte_t *ptep, unsigned long pfn, |
| 859 | unsigned long vaddr, pgprot_t prot) |
| 860 | { |
| 861 | } |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 862 | #endif /* CONFIG_HUGETLB_PAGE */ |
| 863 | |
| 864 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 865 | static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) |
| 866 | { |
| 867 | pmd_t pmd; |
| 868 | |
| 869 | if (!has_transparent_hugepage()) |
| 870 | return; |
| 871 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 872 | pr_debug("Validating PMD based THP\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 873 | /* |
| 874 | * pmd_trans_huge() and pmd_present() must return positive after |
| 875 | * MMU invalidation with pmd_mkinvalid(). This behavior is an |
| 876 | * optimization for transparent huge page. pmd_trans_huge() must |
| 877 | * be true if pmd_page() returns a valid THP to avoid taking the |
| 878 | * pmd_lock when others walk over non transhuge pmds (i.e. there |
| 879 | * are no THP allocated). Especially when splitting a THP and |
| 880 | * removing the present bit from the pmd, pmd_trans_huge() still |
| 881 | * needs to return true. pmd_present() should be true whenever |
| 882 | * pmd_trans_huge() returns true. |
| 883 | */ |
| 884 | pmd = pfn_pmd(pfn, prot); |
| 885 | WARN_ON(!pmd_trans_huge(pmd_mkhuge(pmd))); |
| 886 | |
| 887 | #ifndef __HAVE_ARCH_PMDP_INVALIDATE |
| 888 | WARN_ON(!pmd_trans_huge(pmd_mkinvalid(pmd_mkhuge(pmd)))); |
| 889 | WARN_ON(!pmd_present(pmd_mkinvalid(pmd_mkhuge(pmd)))); |
| 890 | #endif /* __HAVE_ARCH_PMDP_INVALIDATE */ |
| 891 | } |
| 892 | |
| 893 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD |
| 894 | static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) |
| 895 | { |
| 896 | pud_t pud; |
| 897 | |
| 898 | if (!has_transparent_hugepage()) |
| 899 | return; |
| 900 | |
Anshuman Khandual | 6315df4 | 2020-08-06 23:19:25 -0700 | [diff] [blame] | 901 | pr_debug("Validating PUD based THP\n"); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 902 | pud = pfn_pud(pfn, prot); |
| 903 | WARN_ON(!pud_trans_huge(pud_mkhuge(pud))); |
| 904 | |
| 905 | /* |
| 906 | * pud_mkinvalid() has been dropped for now. Enable back |
| 907 | * these tests when it comes back with a modified pud_present(). |
| 908 | * |
| 909 | * WARN_ON(!pud_trans_huge(pud_mkinvalid(pud_mkhuge(pud)))); |
| 910 | * WARN_ON(!pud_present(pud_mkinvalid(pud_mkhuge(pud)))); |
| 911 | */ |
| 912 | } |
| 913 | #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 914 | static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) { } |
| 915 | #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 916 | #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ |
| 917 | static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) { } |
| 918 | static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) { } |
| 919 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 920 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 921 | static unsigned long __init get_random_vaddr(void) |
| 922 | { |
| 923 | unsigned long random_vaddr, random_pages, total_user_pages; |
| 924 | |
| 925 | total_user_pages = (TASK_SIZE - FIRST_USER_ADDRESS) / PAGE_SIZE; |
| 926 | |
| 927 | random_pages = get_random_long() % total_user_pages; |
| 928 | random_vaddr = FIRST_USER_ADDRESS + random_pages * PAGE_SIZE; |
| 929 | |
| 930 | return random_vaddr; |
| 931 | } |
| 932 | |
| 933 | static int __init debug_vm_pgtable(void) |
| 934 | { |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 935 | struct vm_area_struct *vma; |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 936 | struct mm_struct *mm; |
| 937 | pgd_t *pgdp; |
| 938 | p4d_t *p4dp, *saved_p4dp; |
| 939 | pud_t *pudp, *saved_pudp; |
| 940 | pmd_t *pmdp, *saved_pmdp, pmd; |
| 941 | pte_t *ptep; |
| 942 | pgtable_t saved_ptep; |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 943 | pgprot_t prot, protnone; |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 944 | phys_addr_t paddr; |
| 945 | unsigned long vaddr, pte_aligned, pmd_aligned; |
| 946 | unsigned long pud_aligned, p4d_aligned, pgd_aligned; |
Kees Cook | fea1120 | 2020-06-03 13:28:45 -0700 | [diff] [blame] | 947 | spinlock_t *ptl = NULL; |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 948 | |
| 949 | pr_info("Validating architecture page table helpers\n"); |
| 950 | prot = vm_get_page_prot(VMFLAGS); |
| 951 | vaddr = get_random_vaddr(); |
| 952 | mm = mm_alloc(); |
| 953 | if (!mm) { |
| 954 | pr_err("mm_struct allocation failed\n"); |
| 955 | return 1; |
| 956 | } |
| 957 | |
| 958 | /* |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 959 | * __P000 (or even __S000) will help create page table entries with |
| 960 | * PROT_NONE permission as required for pxx_protnone_tests(). |
| 961 | */ |
| 962 | protnone = __P000; |
| 963 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 964 | vma = vm_area_alloc(mm); |
| 965 | if (!vma) { |
| 966 | pr_err("vma allocation failed\n"); |
| 967 | return 1; |
| 968 | } |
| 969 | |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 970 | /* |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 971 | * PFN for mapping at PTE level is determined from a standard kernel |
| 972 | * text symbol. But pfns for higher page table levels are derived by |
| 973 | * masking lower bits of this real pfn. These derived pfns might not |
| 974 | * exist on the platform but that does not really matter as pfn_pxx() |
| 975 | * helpers will still create appropriate entries for the test. This |
| 976 | * helps avoid large memory block allocations to be used for mapping |
| 977 | * at higher page table levels. |
| 978 | */ |
| 979 | paddr = __pa_symbol(&start_kernel); |
| 980 | |
| 981 | pte_aligned = (paddr & PAGE_MASK) >> PAGE_SHIFT; |
| 982 | pmd_aligned = (paddr & PMD_MASK) >> PAGE_SHIFT; |
| 983 | pud_aligned = (paddr & PUD_MASK) >> PAGE_SHIFT; |
| 984 | p4d_aligned = (paddr & P4D_MASK) >> PAGE_SHIFT; |
| 985 | pgd_aligned = (paddr & PGDIR_MASK) >> PAGE_SHIFT; |
| 986 | WARN_ON(!pfn_valid(pte_aligned)); |
| 987 | |
| 988 | pgdp = pgd_offset(mm, vaddr); |
| 989 | p4dp = p4d_alloc(mm, pgdp, vaddr); |
| 990 | pudp = pud_alloc(mm, p4dp, vaddr); |
| 991 | pmdp = pmd_alloc(mm, pudp, vaddr); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 992 | ptep = pte_alloc_map(mm, pmdp, vaddr); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * Save all the page table page addresses as the page table |
| 996 | * entries will be used for testing with random or garbage |
| 997 | * values. These saved addresses will be used for freeing |
| 998 | * page table pages. |
| 999 | */ |
| 1000 | pmd = READ_ONCE(*pmdp); |
| 1001 | saved_p4dp = p4d_offset(pgdp, 0UL); |
| 1002 | saved_pudp = pud_offset(p4dp, 0UL); |
| 1003 | saved_pmdp = pmd_offset(pudp, 0UL); |
| 1004 | saved_ptep = pmd_pgtable(pmd); |
| 1005 | |
| 1006 | pte_basic_tests(pte_aligned, prot); |
| 1007 | pmd_basic_tests(pmd_aligned, prot); |
| 1008 | pud_basic_tests(pud_aligned, prot); |
| 1009 | p4d_basic_tests(p4d_aligned, prot); |
| 1010 | pgd_basic_tests(pgd_aligned, prot); |
| 1011 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 1012 | pmd_leaf_tests(pmd_aligned, prot); |
| 1013 | pud_leaf_tests(pud_aligned, prot); |
| 1014 | |
Aneesh Kumar K.V | 4200605 | 2020-10-15 20:04:40 -0700 | [diff] [blame] | 1015 | pte_savedwrite_tests(pte_aligned, protnone); |
| 1016 | pmd_savedwrite_tests(pmd_aligned, protnone); |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 1017 | |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 1018 | pte_special_tests(pte_aligned, prot); |
| 1019 | pte_protnone_tests(pte_aligned, protnone); |
| 1020 | pmd_protnone_tests(pmd_aligned, protnone); |
| 1021 | |
| 1022 | pte_devmap_tests(pte_aligned, prot); |
| 1023 | pmd_devmap_tests(pmd_aligned, prot); |
| 1024 | pud_devmap_tests(pud_aligned, prot); |
| 1025 | |
| 1026 | pte_soft_dirty_tests(pte_aligned, prot); |
| 1027 | pmd_soft_dirty_tests(pmd_aligned, prot); |
| 1028 | pte_swap_soft_dirty_tests(pte_aligned, prot); |
| 1029 | pmd_swap_soft_dirty_tests(pmd_aligned, prot); |
| 1030 | |
| 1031 | pte_swap_tests(pte_aligned, prot); |
| 1032 | pmd_swap_tests(pmd_aligned, prot); |
| 1033 | |
| 1034 | swap_migration_tests(); |
Anshuman Khandual | 0528940 | 2020-08-06 23:19:16 -0700 | [diff] [blame] | 1035 | |
| 1036 | pmd_thp_tests(pmd_aligned, prot); |
| 1037 | pud_thp_tests(pud_aligned, prot); |
| 1038 | |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1039 | hugetlb_basic_tests(pte_aligned, prot); |
| 1040 | |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1041 | /* |
| 1042 | * Page table modifying tests. They need to hold |
| 1043 | * proper page table lock. |
| 1044 | */ |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1045 | |
| 1046 | ptl = pte_lockptr(mm, pmdp); |
| 1047 | spin_lock(ptl); |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1048 | pte_clear_tests(mm, ptep, vaddr); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1049 | pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1050 | pte_unmap_unlock(ptep, ptl); |
| 1051 | |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1052 | ptl = pmd_lock(mm, pmdp); |
| 1053 | pmd_clear_tests(mm, pmdp); |
Aneesh Kumar K.V | 87f3498 | 2020-10-15 20:04:56 -0700 | [diff] [blame] | 1054 | pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep); |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1055 | pmd_huge_tests(pmdp, pmd_aligned, prot); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1056 | pmd_populate_tests(mm, pmdp, saved_ptep); |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1057 | spin_unlock(ptl); |
| 1058 | |
| 1059 | ptl = pud_lock(mm, pudp); |
| 1060 | pud_clear_tests(mm, pudp); |
| 1061 | pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot); |
| 1062 | pud_huge_tests(pudp, pud_aligned, prot); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1063 | pud_populate_tests(mm, pudp, saved_pmdp); |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1064 | spin_unlock(ptl); |
| 1065 | |
| 1066 | hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot); |
| 1067 | |
| 1068 | spin_lock(&mm->page_table_lock); |
| 1069 | p4d_clear_tests(mm, p4dp); |
| 1070 | pgd_clear_tests(mm, pgdp); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1071 | p4d_populate_tests(mm, p4dp, saved_pudp); |
| 1072 | pgd_populate_tests(mm, pgdp, saved_p4dp); |
Aneesh Kumar K.V | 6f302e27 | 2020-10-15 20:04:53 -0700 | [diff] [blame] | 1073 | spin_unlock(&mm->page_table_lock); |
Aneesh Kumar K.V | e8edf0a | 2020-10-15 20:04:49 -0700 | [diff] [blame] | 1074 | |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 1075 | p4d_free(mm, saved_p4dp); |
| 1076 | pud_free(mm, saved_pudp); |
| 1077 | pmd_free(mm, saved_pmdp); |
| 1078 | pte_free(mm, saved_ptep); |
| 1079 | |
Anshuman Khandual | a5c3b9f | 2020-08-06 23:19:20 -0700 | [diff] [blame] | 1080 | vm_area_free(vma); |
Anshuman Khandual | 399145f | 2020-06-04 16:47:15 -0700 | [diff] [blame] | 1081 | mm_dec_nr_puds(mm); |
| 1082 | mm_dec_nr_pmds(mm); |
| 1083 | mm_dec_nr_ptes(mm); |
| 1084 | mmdrop(mm); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | late_initcall(debug_vm_pgtable); |