1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_PGTABLE_H 3 #define _LINUX_PGTABLE_H 4 5 #include <linux/pfn.h> 6 #include <asm/pgtable.h> 7 8 #ifndef __ASSEMBLY__ 9 #ifdef CONFIG_MMU 10 11 #include <linux/mm_types.h> 12 #include <linux/bug.h> 13 #include <linux/errno.h> 14 #include <asm-generic/pgtable_uffd.h> 15 16 #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \ 17 defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS 18 #error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{P4D,PUD,PMD}_FOLDED 19 #endif 20 21 /* 22 * On almost all architectures and configurations, 0 can be used as the 23 * upper ceiling to free_pgtables(): on many architectures it has the same 24 * effect as using TASK_SIZE. However, there is one configuration which 25 * must impose a more careful limit, to avoid freeing kernel pgtables. 26 */ 27 #ifndef USER_PGTABLES_CEILING 28 #define USER_PGTABLES_CEILING 0UL 29 #endif 30 31 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS 32 extern int ptep_set_access_flags(struct vm_area_struct *vma, 33 unsigned long address, pte_t *ptep, 34 pte_t entry, int dirty); 35 #endif 36 37 #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS 38 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 39 extern int pmdp_set_access_flags(struct vm_area_struct *vma, 40 unsigned long address, pmd_t *pmdp, 41 pmd_t entry, int dirty); 42 extern int pudp_set_access_flags(struct vm_area_struct *vma, 43 unsigned long address, pud_t *pudp, 44 pud_t entry, int dirty); 45 #else 46 static inline int pmdp_set_access_flags(struct vm_area_struct *vma, 47 unsigned long address, pmd_t *pmdp, 48 pmd_t entry, int dirty) 49 { 50 BUILD_BUG(); 51 return 0; 52 } 53 static inline int pudp_set_access_flags(struct vm_area_struct *vma, 54 unsigned long address, pud_t *pudp, 55 pud_t entry, int dirty) 56 { 57 BUILD_BUG(); 58 return 0; 59 } 60 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 61 #endif 62 63 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 64 static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 65 unsigned long address, 66 pte_t *ptep) 67 { 68 pte_t pte = *ptep; 69 int r = 1; 70 if (!pte_young(pte)) 71 r = 0; 72 else 73 set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte)); 74 return r; 75 } 76 #endif 77 78 #ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG 79 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 80 static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma, 81 unsigned long address, 82 pmd_t *pmdp) 83 { 84 pmd_t pmd = *pmdp; 85 int r = 1; 86 if (!pmd_young(pmd)) 87 r = 0; 88 else 89 set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd)); 90 return r; 91 } 92 #else 93 static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma, 94 unsigned long address, 95 pmd_t *pmdp) 96 { 97 BUILD_BUG(); 98 return 0; 99 } 100 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 101 #endif 102 103 #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH 104 int ptep_clear_flush_young(struct vm_area_struct *vma, 105 unsigned long address, pte_t *ptep); 106 #endif 107 108 #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH 109 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 110 extern int pmdp_clear_flush_young(struct vm_area_struct *vma, 111 unsigned long address, pmd_t *pmdp); 112 #else 113 /* 114 * Despite relevant to THP only, this API is called from generic rmap code 115 * under PageTransHuge(), hence needs a dummy implementation for !THP 116 */ 117 static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, 118 unsigned long address, pmd_t *pmdp) 119 { 120 BUILD_BUG(); 121 return 0; 122 } 123 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 124 #endif 125 126 #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR 127 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, 128 unsigned long address, 129 pte_t *ptep) 130 { 131 pte_t pte = *ptep; 132 pte_clear(mm, address, ptep); 133 return pte; 134 } 135 #endif 136 137 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 138 #ifndef __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR 139 static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, 140 unsigned long address, 141 pmd_t *pmdp) 142 { 143 pmd_t pmd = *pmdp; 144 pmd_clear(pmdp); 145 return pmd; 146 } 147 #endif /* __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR */ 148 #ifndef __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR 149 static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, 150 unsigned long address, 151 pud_t *pudp) 152 { 153 pud_t pud = *pudp; 154 155 pud_clear(pudp); 156 return pud; 157 } 158 #endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */ 159 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 160 161 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 162 #ifndef __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR_FULL 163 static inline pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma, 164 unsigned long address, pmd_t *pmdp, 165 int full) 166 { 167 return pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp); 168 } 169 #endif 170 171 #ifndef __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR_FULL 172 static inline pud_t pudp_huge_get_and_clear_full(struct mm_struct *mm, 173 unsigned long address, pud_t *pudp, 174 int full) 175 { 176 return pudp_huge_get_and_clear(mm, address, pudp); 177 } 178 #endif 179 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 180 181 #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL 182 static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, 183 unsigned long address, pte_t *ptep, 184 int full) 185 { 186 pte_t pte; 187 pte = ptep_get_and_clear(mm, address, ptep); 188 return pte; 189 } 190 #endif 191 192 193 /* 194 * If two threads concurrently fault at the same page, the thread that 195 * won the race updates the PTE and its local TLB/Cache. The other thread 196 * gives up, simply does nothing, and continues; on architectures where 197 * software can update TLB, local TLB can be updated here to avoid next page 198 * fault. This function updates TLB only, do nothing with cache or others. 199 * It is the difference with function update_mmu_cache. 200 */ 201 #ifndef __HAVE_ARCH_UPDATE_MMU_TLB 202 static inline void update_mmu_tlb(struct vm_area_struct *vma, 203 unsigned long address, pte_t *ptep) 204 { 205 } 206 #define __HAVE_ARCH_UPDATE_MMU_TLB 207 #endif 208 209 /* 210 * Some architectures may be able to avoid expensive synchronization 211 * primitives when modifications are made to PTE's which are already 212 * not present, or in the process of an address space destruction. 213 */ 214 #ifndef __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL 215 static inline void pte_clear_not_present_full(struct mm_struct *mm, 216 unsigned long address, 217 pte_t *ptep, 218 int full) 219 { 220 pte_clear(mm, address, ptep); 221 } 222 #endif 223 224 #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH 225 extern pte_t ptep_clear_flush(struct vm_area_struct *vma, 226 unsigned long address, 227 pte_t *ptep); 228 #endif 229 230 #ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH 231 extern pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, 232 unsigned long address, 233 pmd_t *pmdp); 234 extern pud_t pudp_huge_clear_flush(struct vm_area_struct *vma, 235 unsigned long address, 236 pud_t *pudp); 237 #endif 238 239 #ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT 240 struct mm_struct; 241 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long address, pte_t *ptep) 242 { 243 pte_t old_pte = *ptep; 244 set_pte_at(mm, address, ptep, pte_wrprotect(old_pte)); 245 } 246 #endif 247 248 /* 249 * On some architectures hardware does not set page access bit when accessing 250 * memory page, it is responsibilty of software setting this bit. It brings 251 * out extra page fault penalty to track page access bit. For optimization page 252 * access bit can be set during all page fault flow on these arches. 253 * To be differentiate with macro pte_mkyoung, this macro is used on platforms 254 * where software maintains page access bit. 255 */ 256 #ifndef pte_sw_mkyoung 257 static inline pte_t pte_sw_mkyoung(pte_t pte) 258 { 259 return pte; 260 } 261 #define pte_sw_mkyoung pte_sw_mkyoung 262 #endif 263 264 #ifndef pte_savedwrite 265 #define pte_savedwrite pte_write 266 #endif 267 268 #ifndef pte_mk_savedwrite 269 #define pte_mk_savedwrite pte_mkwrite 270 #endif 271 272 #ifndef pte_clear_savedwrite 273 #define pte_clear_savedwrite pte_wrprotect 274 #endif 275 276 #ifndef pmd_savedwrite 277 #define pmd_savedwrite pmd_write 278 #endif 279 280 #ifndef pmd_mk_savedwrite 281 #define pmd_mk_savedwrite pmd_mkwrite 282 #endif 283 284 #ifndef pmd_clear_savedwrite 285 #define pmd_clear_savedwrite pmd_wrprotect 286 #endif 287 288 #ifndef __HAVE_ARCH_PMDP_SET_WRPROTECT 289 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 290 static inline void pmdp_set_wrprotect(struct mm_struct *mm, 291 unsigned long address, pmd_t *pmdp) 292 { 293 pmd_t old_pmd = *pmdp; 294 set_pmd_at(mm, address, pmdp, pmd_wrprotect(old_pmd)); 295 } 296 #else 297 static inline void pmdp_set_wrprotect(struct mm_struct *mm, 298 unsigned long address, pmd_t *pmdp) 299 { 300 BUILD_BUG(); 301 } 302 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 303 #endif 304 #ifndef __HAVE_ARCH_PUDP_SET_WRPROTECT 305 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD 306 static inline void pudp_set_wrprotect(struct mm_struct *mm, 307 unsigned long address, pud_t *pudp) 308 { 309 pud_t old_pud = *pudp; 310 311 set_pud_at(mm, address, pudp, pud_wrprotect(old_pud)); 312 } 313 #else 314 static inline void pudp_set_wrprotect(struct mm_struct *mm, 315 unsigned long address, pud_t *pudp) 316 { 317 BUILD_BUG(); 318 } 319 #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ 320 #endif 321 322 #ifndef pmdp_collapse_flush 323 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 324 extern pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, 325 unsigned long address, pmd_t *pmdp); 326 #else 327 static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, 328 unsigned long address, 329 pmd_t *pmdp) 330 { 331 BUILD_BUG(); 332 return *pmdp; 333 } 334 #define pmdp_collapse_flush pmdp_collapse_flush 335 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 336 #endif 337 338 #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT 339 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, 340 pgtable_t pgtable); 341 #endif 342 343 #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW 344 extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); 345 #endif 346 347 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 348 /* 349 * This is an implementation of pmdp_establish() that is only suitable for an 350 * architecture that doesn't have hardware dirty/accessed bits. In this case we 351 * can't race with CPU which sets these bits and non-atomic aproach is fine. 352 */ 353 static inline pmd_t generic_pmdp_establish(struct vm_area_struct *vma, 354 unsigned long address, pmd_t *pmdp, pmd_t pmd) 355 { 356 pmd_t old_pmd = *pmdp; 357 set_pmd_at(vma->vm_mm, address, pmdp, pmd); 358 return old_pmd; 359 } 360 #endif 361 362 #ifndef __HAVE_ARCH_PMDP_INVALIDATE 363 extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, 364 pmd_t *pmdp); 365 #endif 366 367 #ifndef __HAVE_ARCH_PTE_SAME 368 static inline int pte_same(pte_t pte_a, pte_t pte_b) 369 { 370 return pte_val(pte_a) == pte_val(pte_b); 371 } 372 #endif 373 374 #ifndef __HAVE_ARCH_PTE_UNUSED 375 /* 376 * Some architectures provide facilities to virtualization guests 377 * so that they can flag allocated pages as unused. This allows the 378 * host to transparently reclaim unused pages. This function returns 379 * whether the pte's page is unused. 380 */ 381 static inline int pte_unused(pte_t pte) 382 { 383 return 0; 384 } 385 #endif 386 387 #ifndef pte_access_permitted 388 #define pte_access_permitted(pte, write) \ 389 (pte_present(pte) && (!(write) || pte_write(pte))) 390 #endif 391 392 #ifndef pmd_access_permitted 393 #define pmd_access_permitted(pmd, write) \ 394 (pmd_present(pmd) && (!(write) || pmd_write(pmd))) 395 #endif 396 397 #ifndef pud_access_permitted 398 #define pud_access_permitted(pud, write) \ 399 (pud_present(pud) && (!(write) || pud_write(pud))) 400 #endif 401 402 #ifndef p4d_access_permitted 403 #define p4d_access_permitted(p4d, write) \ 404 (p4d_present(p4d) && (!(write) || p4d_write(p4d))) 405 #endif 406 407 #ifndef pgd_access_permitted 408 #define pgd_access_permitted(pgd, write) \ 409 (pgd_present(pgd) && (!(write) || pgd_write(pgd))) 410 #endif 411 412 #ifndef __HAVE_ARCH_PMD_SAME 413 static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b) 414 { 415 return pmd_val(pmd_a) == pmd_val(pmd_b); 416 } 417 418 static inline int pud_same(pud_t pud_a, pud_t pud_b) 419 { 420 return pud_val(pud_a) == pud_val(pud_b); 421 } 422 #endif 423 424 #ifndef __HAVE_ARCH_P4D_SAME 425 static inline int p4d_same(p4d_t p4d_a, p4d_t p4d_b) 426 { 427 return p4d_val(p4d_a) == p4d_val(p4d_b); 428 } 429 #endif 430 431 #ifndef __HAVE_ARCH_PGD_SAME 432 static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) 433 { 434 return pgd_val(pgd_a) == pgd_val(pgd_b); 435 } 436 #endif 437 438 /* 439 * Use set_p*_safe(), and elide TLB flushing, when confident that *no* 440 * TLB flush will be required as a result of the "set". For example, use 441 * in scenarios where it is known ahead of time that the routine is 442 * setting non-present entries, or re-setting an existing entry to the 443 * same value. Otherwise, use the typical "set" helpers and flush the 444 * TLB. 445 */ 446 #define set_pte_safe(ptep, pte) \ 447 ({ \ 448 WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ 449 set_pte(ptep, pte); \ 450 }) 451 452 #define set_pmd_safe(pmdp, pmd) \ 453 ({ \ 454 WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ 455 set_pmd(pmdp, pmd); \ 456 }) 457 458 #define set_pud_safe(pudp, pud) \ 459 ({ \ 460 WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ 461 set_pud(pudp, pud); \ 462 }) 463 464 #define set_p4d_safe(p4dp, p4d) \ 465 ({ \ 466 WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ 467 set_p4d(p4dp, p4d); \ 468 }) 469 470 #define set_pgd_safe(pgdp, pgd) \ 471 ({ \ 472 WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ 473 set_pgd(pgdp, pgd); \ 474 }) 475 476 #ifndef __HAVE_ARCH_DO_SWAP_PAGE 477 /* 478 * Some architectures support metadata associated with a page. When a 479 * page is being swapped out, this metadata must be saved so it can be 480 * restored when the page is swapped back in. SPARC M7 and newer 481 * processors support an ADI (Application Data Integrity) tag for the 482 * page as metadata for the page. arch_do_swap_page() can restore this 483 * metadata when a page is swapped back in. 484 */ 485 static inline void arch_do_swap_page(struct mm_struct *mm, 486 struct vm_area_struct *vma, 487 unsigned long addr, 488 pte_t pte, pte_t oldpte) 489 { 490 491 } 492 #endif 493 494 #ifndef __HAVE_ARCH_UNMAP_ONE 495 /* 496 * Some architectures support metadata associated with a page. When a 497 * page is being swapped out, this metadata must be saved so it can be 498 * restored when the page is swapped back in. SPARC M7 and newer 499 * processors support an ADI (Application Data Integrity) tag for the 500 * page as metadata for the page. arch_unmap_one() can save this 501 * metadata on a swap-out of a page. 502 */ 503 static inline int arch_unmap_one(struct mm_struct *mm, 504 struct vm_area_struct *vma, 505 unsigned long addr, 506 pte_t orig_pte) 507 { 508 return 0; 509 } 510 #endif 511 512 #ifndef __HAVE_ARCH_PGD_OFFSET_GATE 513 #define pgd_offset_gate(mm, addr) pgd_offset(mm, addr) 514 #endif 515 516 #ifndef __HAVE_ARCH_MOVE_PTE 517 #define move_pte(pte, prot, old_addr, new_addr) (pte) 518 #endif 519 520 #ifndef pte_accessible 521 # define pte_accessible(mm, pte) ((void)(pte), 1) 522 #endif 523 524 #ifndef flush_tlb_fix_spurious_fault 525 #define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address) 526 #endif 527 528 #ifndef pgprot_nx 529 #define pgprot_nx(prot) (prot) 530 #endif 531 532 #ifndef pgprot_noncached 533 #define pgprot_noncached(prot) (prot) 534 #endif 535 536 #ifndef pgprot_writecombine 537 #define pgprot_writecombine pgprot_noncached 538 #endif 539 540 #ifndef pgprot_writethrough 541 #define pgprot_writethrough pgprot_noncached 542 #endif 543 544 #ifndef pgprot_device 545 #define pgprot_device pgprot_noncached 546 #endif 547 548 #ifndef pgprot_modify 549 #define pgprot_modify pgprot_modify 550 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) 551 { 552 if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot))) 553 newprot = pgprot_noncached(newprot); 554 if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot))) 555 newprot = pgprot_writecombine(newprot); 556 if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot))) 557 newprot = pgprot_device(newprot); 558 return newprot; 559 } 560 #endif 561 562 /* 563 * When walking page tables, get the address of the next boundary, 564 * or the end address of the range if that comes earlier. Although no 565 * vma end wraps to 0, rounded up __boundary may wrap to 0 throughout. 566 */ 567 568 #define pgd_addr_end(addr, end) \ 569 ({ unsigned long __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \ 570 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 571 }) 572 573 #ifndef p4d_addr_end 574 #define p4d_addr_end(addr, end) \ 575 ({ unsigned long __boundary = ((addr) + P4D_SIZE) & P4D_MASK; \ 576 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 577 }) 578 #endif 579 580 #ifndef pud_addr_end 581 #define pud_addr_end(addr, end) \ 582 ({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \ 583 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 584 }) 585 #endif 586 587 #ifndef pmd_addr_end 588 #define pmd_addr_end(addr, end) \ 589 ({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ 590 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 591 }) 592 #endif 593 594 /* 595 * When walking page tables, we usually want to skip any p?d_none entries; 596 * and any p?d_bad entries - reporting the error before resetting to none. 597 * Do the tests inline, but report and clear the bad entry in mm/memory.c. 598 */ 599 void pgd_clear_bad(pgd_t *); 600 601 #ifndef __PAGETABLE_P4D_FOLDED 602 void p4d_clear_bad(p4d_t *); 603 #else 604 #define p4d_clear_bad(p4d) do { } while (0) 605 #endif 606 607 #ifndef __PAGETABLE_PUD_FOLDED 608 void pud_clear_bad(pud_t *); 609 #else 610 #define pud_clear_bad(p4d) do { } while (0) 611 #endif 612 613 void pmd_clear_bad(pmd_t *); 614 615 static inline int pgd_none_or_clear_bad(pgd_t *pgd) 616 { 617 if (pgd_none(*pgd)) 618 return 1; 619 if (unlikely(pgd_bad(*pgd))) { 620 pgd_clear_bad(pgd); 621 return 1; 622 } 623 return 0; 624 } 625 626 static inline int p4d_none_or_clear_bad(p4d_t *p4d) 627 { 628 if (p4d_none(*p4d)) 629 return 1; 630 if (unlikely(p4d_bad(*p4d))) { 631 p4d_clear_bad(p4d); 632 return 1; 633 } 634 return 0; 635 } 636 637 static inline int pud_none_or_clear_bad(pud_t *pud) 638 { 639 if (pud_none(*pud)) 640 return 1; 641 if (unlikely(pud_bad(*pud))) { 642 pud_clear_bad(pud); 643 return 1; 644 } 645 return 0; 646 } 647 648 static inline int pmd_none_or_clear_bad(pmd_t *pmd) 649 { 650 if (pmd_none(*pmd)) 651 return 1; 652 if (unlikely(pmd_bad(*pmd))) { 653 pmd_clear_bad(pmd); 654 return 1; 655 } 656 return 0; 657 } 658 659 static inline pte_t __ptep_modify_prot_start(struct vm_area_struct *vma, 660 unsigned long addr, 661 pte_t *ptep) 662 { 663 /* 664 * Get the current pte state, but zero it out to make it 665 * non-present, preventing the hardware from asynchronously 666 * updating it. 667 */ 668 return ptep_get_and_clear(vma->vm_mm, addr, ptep); 669 } 670 671 static inline void __ptep_modify_prot_commit(struct vm_area_struct *vma, 672 unsigned long addr, 673 pte_t *ptep, pte_t pte) 674 { 675 /* 676 * The pte is non-present, so there's no hardware state to 677 * preserve. 678 */ 679 set_pte_at(vma->vm_mm, addr, ptep, pte); 680 } 681 682 #ifndef __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION 683 /* 684 * Start a pte protection read-modify-write transaction, which 685 * protects against asynchronous hardware modifications to the pte. 686 * The intention is not to prevent the hardware from making pte 687 * updates, but to prevent any updates it may make from being lost. 688 * 689 * This does not protect against other software modifications of the 690 * pte; the appropriate pte lock must be held over the transation. 691 * 692 * Note that this interface is intended to be batchable, meaning that 693 * ptep_modify_prot_commit may not actually update the pte, but merely 694 * queue the update to be done at some later time. The update must be 695 * actually committed before the pte lock is released, however. 696 */ 697 static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, 698 unsigned long addr, 699 pte_t *ptep) 700 { 701 return __ptep_modify_prot_start(vma, addr, ptep); 702 } 703 704 /* 705 * Commit an update to a pte, leaving any hardware-controlled bits in 706 * the PTE unmodified. 707 */ 708 static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, 709 unsigned long addr, 710 pte_t *ptep, pte_t old_pte, pte_t pte) 711 { 712 __ptep_modify_prot_commit(vma, addr, ptep, pte); 713 } 714 #endif /* __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION */ 715 #endif /* CONFIG_MMU */ 716 717 /* 718 * No-op macros that just return the current protection value. Defined here 719 * because these macros can be used used even if CONFIG_MMU is not defined. 720 */ 721 #ifndef pgprot_encrypted 722 #define pgprot_encrypted(prot) (prot) 723 #endif 724 725 #ifndef pgprot_decrypted 726 #define pgprot_decrypted(prot) (prot) 727 #endif 728 729 /* 730 * A facility to provide lazy MMU batching. This allows PTE updates and 731 * page invalidations to be delayed until a call to leave lazy MMU mode 732 * is issued. Some architectures may benefit from doing this, and it is 733 * beneficial for both shadow and direct mode hypervisors, which may batch 734 * the PTE updates which happen during this window. Note that using this 735 * interface requires that read hazards be removed from the code. A read 736 * hazard could result in the direct mode hypervisor case, since the actual 737 * write to the page tables may not yet have taken place, so reads though 738 * a raw PTE pointer after it has been modified are not guaranteed to be 739 * up to date. This mode can only be entered and left under the protection of 740 * the page table locks for all page tables which may be modified. In the UP 741 * case, this is required so that preemption is disabled, and in the SMP case, 742 * it must synchronize the delayed page table writes properly on other CPUs. 743 */ 744 #ifndef __HAVE_ARCH_ENTER_LAZY_MMU_MODE 745 #define arch_enter_lazy_mmu_mode() do {} while (0) 746 #define arch_leave_lazy_mmu_mode() do {} while (0) 747 #define arch_flush_lazy_mmu_mode() do {} while (0) 748 #endif 749 750 /* 751 * A facility to provide batching of the reload of page tables and 752 * other process state with the actual context switch code for 753 * paravirtualized guests. By convention, only one of the batched 754 * update (lazy) modes (CPU, MMU) should be active at any given time, 755 * entry should never be nested, and entry and exits should always be 756 * paired. This is for sanity of maintaining and reasoning about the 757 * kernel code. In this case, the exit (end of the context switch) is 758 * in architecture-specific code, and so doesn't need a generic 759 * definition. 760 */ 761 #ifndef __HAVE_ARCH_START_CONTEXT_SWITCH 762 #define arch_start_context_switch(prev) do {} while (0) 763 #endif 764 765 #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY 766 #ifndef CONFIG_ARCH_ENABLE_THP_MIGRATION 767 static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd) 768 { 769 return pmd; 770 } 771 772 static inline int pmd_swp_soft_dirty(pmd_t pmd) 773 { 774 return 0; 775 } 776 777 static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd) 778 { 779 return pmd; 780 } 781 #endif 782 #else /* !CONFIG_HAVE_ARCH_SOFT_DIRTY */ 783 static inline int pte_soft_dirty(pte_t pte) 784 { 785 return 0; 786 } 787 788 static inline int pmd_soft_dirty(pmd_t pmd) 789 { 790 return 0; 791 } 792 793 static inline pte_t pte_mksoft_dirty(pte_t pte) 794 { 795 return pte; 796 } 797 798 static inline pmd_t pmd_mksoft_dirty(pmd_t pmd) 799 { 800 return pmd; 801 } 802 803 static inline pte_t pte_clear_soft_dirty(pte_t pte) 804 { 805 return pte; 806 } 807 808 static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd) 809 { 810 return pmd; 811 } 812 813 static inline pte_t pte_swp_mksoft_dirty(pte_t pte) 814 { 815 return pte; 816 } 817 818 static inline int pte_swp_soft_dirty(pte_t pte) 819 { 820 return 0; 821 } 822 823 static inline pte_t pte_swp_clear_soft_dirty(pte_t pte) 824 { 825 return pte; 826 } 827 828 static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd) 829 { 830 return pmd; 831 } 832 833 static inline int pmd_swp_soft_dirty(pmd_t pmd) 834 { 835 return 0; 836 } 837 838 static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd) 839 { 840 return pmd; 841 } 842 #endif 843 844 #ifndef __HAVE_PFNMAP_TRACKING 845 /* 846 * Interfaces that can be used by architecture code to keep track of 847 * memory type of pfn mappings specified by the remap_pfn_range, 848 * vmf_insert_pfn. 849 */ 850 851 /* 852 * track_pfn_remap is called when a _new_ pfn mapping is being established 853 * by remap_pfn_range() for physical range indicated by pfn and size. 854 */ 855 static inline int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot, 856 unsigned long pfn, unsigned long addr, 857 unsigned long size) 858 { 859 return 0; 860 } 861 862 /* 863 * track_pfn_insert is called when a _new_ single pfn is established 864 * by vmf_insert_pfn(). 865 */ 866 static inline void track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot, 867 pfn_t pfn) 868 { 869 } 870 871 /* 872 * track_pfn_copy is called when vma that is covering the pfnmap gets 873 * copied through copy_page_range(). 874 */ 875 static inline int track_pfn_copy(struct vm_area_struct *vma) 876 { 877 return 0; 878 } 879 880 /* 881 * untrack_pfn is called while unmapping a pfnmap for a region. 882 * untrack can be called for a specific region indicated by pfn and size or 883 * can be for the entire vma (in which case pfn, size are zero). 884 */ 885 static inline void untrack_pfn(struct vm_area_struct *vma, 886 unsigned long pfn, unsigned long size) 887 { 888 } 889 890 /* 891 * untrack_pfn_moved is called while mremapping a pfnmap for a new region. 892 */ 893 static inline void untrack_pfn_moved(struct vm_area_struct *vma) 894 { 895 } 896 #else 897 extern int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot, 898 unsigned long pfn, unsigned long addr, 899 unsigned long size); 900 extern void track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot, 901 pfn_t pfn); 902 extern int track_pfn_copy(struct vm_area_struct *vma); 903 extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn, 904 unsigned long size); 905 extern void untrack_pfn_moved(struct vm_area_struct *vma); 906 #endif 907 908 #ifdef __HAVE_COLOR_ZERO_PAGE 909 static inline int is_zero_pfn(unsigned long pfn) 910 { 911 extern unsigned long zero_pfn; 912 unsigned long offset_from_zero_pfn = pfn - zero_pfn; 913 return offset_from_zero_pfn <= (zero_page_mask >> PAGE_SHIFT); 914 } 915 916 #define my_zero_pfn(addr) page_to_pfn(ZERO_PAGE(addr)) 917 918 #else 919 static inline int is_zero_pfn(unsigned long pfn) 920 { 921 extern unsigned long zero_pfn; 922 return pfn == zero_pfn; 923 } 924 925 static inline unsigned long my_zero_pfn(unsigned long addr) 926 { 927 extern unsigned long zero_pfn; 928 return zero_pfn; 929 } 930 #endif 931 932 #ifdef CONFIG_MMU 933 934 #ifndef CONFIG_TRANSPARENT_HUGEPAGE 935 static inline int pmd_trans_huge(pmd_t pmd) 936 { 937 return 0; 938 } 939 #ifndef pmd_write 940 static inline int pmd_write(pmd_t pmd) 941 { 942 BUG(); 943 return 0; 944 } 945 #endif /* pmd_write */ 946 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 947 948 #ifndef pud_write 949 static inline int pud_write(pud_t pud) 950 { 951 BUG(); 952 return 0; 953 } 954 #endif /* pud_write */ 955 956 #if !defined(CONFIG_ARCH_HAS_PTE_DEVMAP) || !defined(CONFIG_TRANSPARENT_HUGEPAGE) 957 static inline int pmd_devmap(pmd_t pmd) 958 { 959 return 0; 960 } 961 static inline int pud_devmap(pud_t pud) 962 { 963 return 0; 964 } 965 static inline int pgd_devmap(pgd_t pgd) 966 { 967 return 0; 968 } 969 #endif 970 971 #if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \ 972 (defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ 973 !defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) 974 static inline int pud_trans_huge(pud_t pud) 975 { 976 return 0; 977 } 978 #endif 979 980 /* See pmd_none_or_trans_huge_or_clear_bad for discussion. */ 981 static inline int pud_none_or_trans_huge_or_dev_or_clear_bad(pud_t *pud) 982 { 983 pud_t pudval = READ_ONCE(*pud); 984 985 if (pud_none(pudval) || pud_trans_huge(pudval) || pud_devmap(pudval)) 986 return 1; 987 if (unlikely(pud_bad(pudval))) { 988 pud_clear_bad(pud); 989 return 1; 990 } 991 return 0; 992 } 993 994 /* See pmd_trans_unstable for discussion. */ 995 static inline int pud_trans_unstable(pud_t *pud) 996 { 997 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ 998 defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) 999 return pud_none_or_trans_huge_or_dev_or_clear_bad(pud); 1000 #else 1001 return 0; 1002 #endif 1003 } 1004 1005 #ifndef pmd_read_atomic 1006 static inline pmd_t pmd_read_atomic(pmd_t *pmdp) 1007 { 1008 /* 1009 * Depend on compiler for an atomic pmd read. NOTE: this is 1010 * only going to work, if the pmdval_t isn't larger than 1011 * an unsigned long. 1012 */ 1013 return *pmdp; 1014 } 1015 #endif 1016 1017 #ifndef arch_needs_pgtable_deposit 1018 #define arch_needs_pgtable_deposit() (false) 1019 #endif 1020 /* 1021 * This function is meant to be used by sites walking pagetables with 1022 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and 1023 * transhuge page faults. MADV_DONTNEED can convert a transhuge pmd 1024 * into a null pmd and the transhuge page fault can convert a null pmd 1025 * into an hugepmd or into a regular pmd (if the hugepage allocation 1026 * fails). While holding the mmap_sem in read mode the pmd becomes 1027 * stable and stops changing under us only if it's not null and not a 1028 * transhuge pmd. When those races occurs and this function makes a 1029 * difference vs the standard pmd_none_or_clear_bad, the result is 1030 * undefined so behaving like if the pmd was none is safe (because it 1031 * can return none anyway). The compiler level barrier() is critically 1032 * important to compute the two checks atomically on the same pmdval. 1033 * 1034 * For 32bit kernels with a 64bit large pmd_t this automatically takes 1035 * care of reading the pmd atomically to avoid SMP race conditions 1036 * against pmd_populate() when the mmap_sem is hold for reading by the 1037 * caller (a special atomic read not done by "gcc" as in the generic 1038 * version above, is also needed when THP is disabled because the page 1039 * fault can populate the pmd from under us). 1040 */ 1041 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd) 1042 { 1043 pmd_t pmdval = pmd_read_atomic(pmd); 1044 /* 1045 * The barrier will stabilize the pmdval in a register or on 1046 * the stack so that it will stop changing under the code. 1047 * 1048 * When CONFIG_TRANSPARENT_HUGEPAGE=y on x86 32bit PAE, 1049 * pmd_read_atomic is allowed to return a not atomic pmdval 1050 * (for example pointing to an hugepage that has never been 1051 * mapped in the pmd). The below checks will only care about 1052 * the low part of the pmd with 32bit PAE x86 anyway, with the 1053 * exception of pmd_none(). So the important thing is that if 1054 * the low part of the pmd is found null, the high part will 1055 * be also null or the pmd_none() check below would be 1056 * confused. 1057 */ 1058 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 1059 barrier(); 1060 #endif 1061 /* 1062 * !pmd_present() checks for pmd migration entries 1063 * 1064 * The complete check uses is_pmd_migration_entry() in linux/swapops.h 1065 * But using that requires moving current function and pmd_trans_unstable() 1066 * to linux/swapops.h to resovle dependency, which is too much code move. 1067 * 1068 * !pmd_present() is equivalent to is_pmd_migration_entry() currently, 1069 * because !pmd_present() pages can only be under migration not swapped 1070 * out. 1071 * 1072 * pmd_none() is preseved for future condition checks on pmd migration 1073 * entries and not confusing with this function name, although it is 1074 * redundant with !pmd_present(). 1075 */ 1076 if (pmd_none(pmdval) || pmd_trans_huge(pmdval) || 1077 (IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION) && !pmd_present(pmdval))) 1078 return 1; 1079 if (unlikely(pmd_bad(pmdval))) { 1080 pmd_clear_bad(pmd); 1081 return 1; 1082 } 1083 return 0; 1084 } 1085 1086 /* 1087 * This is a noop if Transparent Hugepage Support is not built into 1088 * the kernel. Otherwise it is equivalent to 1089 * pmd_none_or_trans_huge_or_clear_bad(), and shall only be called in 1090 * places that already verified the pmd is not none and they want to 1091 * walk ptes while holding the mmap sem in read mode (write mode don't 1092 * need this). If THP is not enabled, the pmd can't go away under the 1093 * code even if MADV_DONTNEED runs, but if THP is enabled we need to 1094 * run a pmd_trans_unstable before walking the ptes after 1095 * split_huge_pmd returns (because it may have run when the pmd become 1096 * null, but then a page fault can map in a THP and not a regular page). 1097 */ 1098 static inline int pmd_trans_unstable(pmd_t *pmd) 1099 { 1100 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 1101 return pmd_none_or_trans_huge_or_clear_bad(pmd); 1102 #else 1103 return 0; 1104 #endif 1105 } 1106 1107 #ifndef CONFIG_NUMA_BALANCING 1108 /* 1109 * Technically a PTE can be PROTNONE even when not doing NUMA balancing but 1110 * the only case the kernel cares is for NUMA balancing and is only ever set 1111 * when the VMA is accessible. For PROT_NONE VMAs, the PTEs are not marked 1112 * _PAGE_PROTNONE so by by default, implement the helper as "always no". It 1113 * is the responsibility of the caller to distinguish between PROT_NONE 1114 * protections and NUMA hinting fault protections. 1115 */ 1116 static inline int pte_protnone(pte_t pte) 1117 { 1118 return 0; 1119 } 1120 1121 static inline int pmd_protnone(pmd_t pmd) 1122 { 1123 return 0; 1124 } 1125 #endif /* CONFIG_NUMA_BALANCING */ 1126 1127 #endif /* CONFIG_MMU */ 1128 1129 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP 1130 1131 #ifndef __PAGETABLE_P4D_FOLDED 1132 int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot); 1133 int p4d_clear_huge(p4d_t *p4d); 1134 #else 1135 static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot) 1136 { 1137 return 0; 1138 } 1139 static inline int p4d_clear_huge(p4d_t *p4d) 1140 { 1141 return 0; 1142 } 1143 #endif /* !__PAGETABLE_P4D_FOLDED */ 1144 1145 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); 1146 int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 1147 int pud_clear_huge(pud_t *pud); 1148 int pmd_clear_huge(pmd_t *pmd); 1149 int p4d_free_pud_page(p4d_t *p4d, unsigned long addr); 1150 int pud_free_pmd_page(pud_t *pud, unsigned long addr); 1151 int pmd_free_pte_page(pmd_t *pmd, unsigned long addr); 1152 #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ 1153 static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot) 1154 { 1155 return 0; 1156 } 1157 static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) 1158 { 1159 return 0; 1160 } 1161 static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) 1162 { 1163 return 0; 1164 } 1165 static inline int p4d_clear_huge(p4d_t *p4d) 1166 { 1167 return 0; 1168 } 1169 static inline int pud_clear_huge(pud_t *pud) 1170 { 1171 return 0; 1172 } 1173 static inline int pmd_clear_huge(pmd_t *pmd) 1174 { 1175 return 0; 1176 } 1177 static inline int p4d_free_pud_page(p4d_t *p4d, unsigned long addr) 1178 { 1179 return 0; 1180 } 1181 static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr) 1182 { 1183 return 0; 1184 } 1185 static inline int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) 1186 { 1187 return 0; 1188 } 1189 #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ 1190 1191 #ifndef __HAVE_ARCH_FLUSH_PMD_TLB_RANGE 1192 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 1193 /* 1194 * ARCHes with special requirements for evicting THP backing TLB entries can 1195 * implement this. Otherwise also, it can help optimize normal TLB flush in 1196 * THP regime. stock flush_tlb_range() typically has optimization to nuke the 1197 * entire TLB TLB if flush span is greater than a threshold, which will 1198 * likely be true for a single huge page. Thus a single thp flush will 1199 * invalidate the entire TLB which is not desitable. 1200 * e.g. see arch/arc: flush_pmd_tlb_range 1201 */ 1202 #define flush_pmd_tlb_range(vma, addr, end) flush_tlb_range(vma, addr, end) 1203 #define flush_pud_tlb_range(vma, addr, end) flush_tlb_range(vma, addr, end) 1204 #else 1205 #define flush_pmd_tlb_range(vma, addr, end) BUILD_BUG() 1206 #define flush_pud_tlb_range(vma, addr, end) BUILD_BUG() 1207 #endif 1208 #endif 1209 1210 struct file; 1211 int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, 1212 unsigned long size, pgprot_t *vma_prot); 1213 1214 #ifndef CONFIG_X86_ESPFIX64 1215 static inline void init_espfix_bsp(void) { } 1216 #endif 1217 1218 extern void __init pgtable_cache_init(void); 1219 1220 #ifndef __HAVE_ARCH_PFN_MODIFY_ALLOWED 1221 static inline bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot) 1222 { 1223 return true; 1224 } 1225 1226 static inline bool arch_has_pfn_modify_check(void) 1227 { 1228 return false; 1229 } 1230 #endif /* !_HAVE_ARCH_PFN_MODIFY_ALLOWED */ 1231 1232 /* 1233 * Architecture PAGE_KERNEL_* fallbacks 1234 * 1235 * Some architectures don't define certain PAGE_KERNEL_* flags. This is either 1236 * because they really don't support them, or the port needs to be updated to 1237 * reflect the required functionality. Below are a set of relatively safe 1238 * fallbacks, as best effort, which we can count on in lieu of the architectures 1239 * not defining them on their own yet. 1240 */ 1241 1242 #ifndef PAGE_KERNEL_RO 1243 # define PAGE_KERNEL_RO PAGE_KERNEL 1244 #endif 1245 1246 #ifndef PAGE_KERNEL_EXEC 1247 # define PAGE_KERNEL_EXEC PAGE_KERNEL 1248 #endif 1249 1250 /* 1251 * Page Table Modification bits for pgtbl_mod_mask. 1252 * 1253 * These are used by the p?d_alloc_track*() set of functions an in the generic 1254 * vmalloc/ioremap code to track at which page-table levels entries have been 1255 * modified. Based on that the code can better decide when vmalloc and ioremap 1256 * mapping changes need to be synchronized to other page-tables in the system. 1257 */ 1258 #define __PGTBL_PGD_MODIFIED 0 1259 #define __PGTBL_P4D_MODIFIED 1 1260 #define __PGTBL_PUD_MODIFIED 2 1261 #define __PGTBL_PMD_MODIFIED 3 1262 #define __PGTBL_PTE_MODIFIED 4 1263 1264 #define PGTBL_PGD_MODIFIED BIT(__PGTBL_PGD_MODIFIED) 1265 #define PGTBL_P4D_MODIFIED BIT(__PGTBL_P4D_MODIFIED) 1266 #define PGTBL_PUD_MODIFIED BIT(__PGTBL_PUD_MODIFIED) 1267 #define PGTBL_PMD_MODIFIED BIT(__PGTBL_PMD_MODIFIED) 1268 #define PGTBL_PTE_MODIFIED BIT(__PGTBL_PTE_MODIFIED) 1269 1270 /* Page-Table Modification Mask */ 1271 typedef unsigned int pgtbl_mod_mask; 1272 1273 #endif /* !__ASSEMBLY__ */ 1274 1275 #ifndef io_remap_pfn_range 1276 #define io_remap_pfn_range remap_pfn_range 1277 #endif 1278 1279 #ifndef has_transparent_hugepage 1280 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 1281 #define has_transparent_hugepage() 1 1282 #else 1283 #define has_transparent_hugepage() 0 1284 #endif 1285 #endif 1286 1287 /* 1288 * On some architectures it depends on the mm if the p4d/pud or pmd 1289 * layer of the page table hierarchy is folded or not. 1290 */ 1291 #ifndef mm_p4d_folded 1292 #define mm_p4d_folded(mm) __is_defined(__PAGETABLE_P4D_FOLDED) 1293 #endif 1294 1295 #ifndef mm_pud_folded 1296 #define mm_pud_folded(mm) __is_defined(__PAGETABLE_PUD_FOLDED) 1297 #endif 1298 1299 #ifndef mm_pmd_folded 1300 #define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED) 1301 #endif 1302 1303 /* 1304 * p?d_leaf() - true if this entry is a final mapping to a physical address. 1305 * This differs from p?d_huge() by the fact that they are always available (if 1306 * the architecture supports large pages at the appropriate level) even 1307 * if CONFIG_HUGETLB_PAGE is not defined. 1308 * Only meaningful when called on a valid entry. 1309 */ 1310 #ifndef pgd_leaf 1311 #define pgd_leaf(x) 0 1312 #endif 1313 #ifndef p4d_leaf 1314 #define p4d_leaf(x) 0 1315 #endif 1316 #ifndef pud_leaf 1317 #define pud_leaf(x) 0 1318 #endif 1319 #ifndef pmd_leaf 1320 #define pmd_leaf(x) 0 1321 #endif 1322 1323 #endif /* _LINUX_PGTABLE_H */ 1324