#ifndef _ASM_X86_PGTABLE_H
#define _ASM_X86_PGTABLE_H
#include <linux/mem_encrypt.h>
#include <asm/page.h>
#include <asm/pgtable_types.h>
#define pgprot_noncached(prot) …
#ifndef __ASSEMBLY__
#include <linux/spinlock.h>
#include <asm/x86_init.h>
#include <asm/pkru.h>
#include <asm/fpu/api.h>
#include <asm/coco.h>
#include <asm-generic/pgtable_uffd.h>
#include <linux/page_table_check.h>
extern pgd_t early_top_pgt[PTRS_PER_PGD];
bool __init __early_make_pgtable(unsigned long address, pmdval_t pmd);
struct seq_file;
void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm);
void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm,
bool user);
bool ptdump_walk_pgd_level_checkwx(void);
#define ptdump_check_wx …
void ptdump_walk_user_pgd_level_checkwx(void);
#define pgprot_encrypted(prot) …
#define pgprot_decrypted(prot) …
#ifdef CONFIG_DEBUG_WX
#define debug_checkwx_user() …
#else
#define debug_checkwx_user …
#endif
extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
__visible;
#define ZERO_PAGE(vaddr) …
extern spinlock_t pgd_lock;
extern struct list_head pgd_list;
extern struct mm_struct *pgd_page_get_mm(struct page *page);
extern pmdval_t early_pmd_flags;
#ifdef CONFIG_PARAVIRT_XXL
#include <asm/paravirt.h>
#else
#define set_pte …
#define set_pte_atomic …
#define set_pmd …
#ifndef __PAGETABLE_P4D_FOLDED
#define set_pgd …
#define pgd_clear …
#endif
#ifndef set_p4d
#define set_p4d …
#endif
#ifndef __PAGETABLE_PUD_FOLDED
#define p4d_clear …
#endif
#ifndef set_pud
#define set_pud …
#endif
#ifndef __PAGETABLE_PUD_FOLDED
#define pud_clear …
#endif
#define pte_clear …
#define pmd_clear …
#define pgd_val …
#define __pgd …
#ifndef __PAGETABLE_P4D_FOLDED
#define p4d_val …
#define __p4d …
#endif
#ifndef __PAGETABLE_PUD_FOLDED
#define pud_val …
#define __pud …
#endif
#ifndef __PAGETABLE_PMD_FOLDED
#define pmd_val …
#define __pmd …
#endif
#define pte_val …
#define __pte …
#define arch_end_context_switch …
#endif
static inline bool pte_dirty(pte_t pte)
{ … }
static inline bool pte_shstk(pte_t pte)
{ … }
static inline int pte_young(pte_t pte)
{ … }
static inline bool pte_decrypted(pte_t pte)
{ … }
#define pmd_dirty …
static inline bool pmd_dirty(pmd_t pmd)
{ … }
static inline bool pmd_shstk(pmd_t pmd)
{ … }
#define pmd_young …
static inline int pmd_young(pmd_t pmd)
{ … }
static inline bool pud_dirty(pud_t pud)
{ … }
static inline int pud_young(pud_t pud)
{ … }
static inline int pte_write(pte_t pte)
{ … }
#define pmd_write …
static inline int pmd_write(pmd_t pmd)
{ … }
#define pud_write …
static inline int pud_write(pud_t pud)
{ … }
static inline int pte_huge(pte_t pte)
{ … }
static inline int pte_global(pte_t pte)
{ … }
static inline int pte_exec(pte_t pte)
{ … }
static inline int pte_special(pte_t pte)
{ … }
static inline u64 protnone_mask(u64 val);
#define PFN_PTE_SHIFT …
static inline unsigned long pte_pfn(pte_t pte)
{ … }
static inline unsigned long pmd_pfn(pmd_t pmd)
{ … }
#define pud_pfn …
static inline unsigned long pud_pfn(pud_t pud)
{ … }
static inline unsigned long p4d_pfn(p4d_t p4d)
{ … }
static inline unsigned long pgd_pfn(pgd_t pgd)
{ … }
#define p4d_leaf …
static inline bool p4d_leaf(p4d_t p4d)
{ … }
#define pte_page(pte) …
#define pmd_leaf …
static inline bool pmd_leaf(pmd_t pte)
{ … }
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_trans_huge(pmd_t pmd)
{ … }
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
static inline int pud_trans_huge(pud_t pud)
{ … }
#endif
#define has_transparent_hugepage …
static inline int has_transparent_hugepage(void)
{ … }
#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP
static inline int pmd_devmap(pmd_t pmd)
{ … }
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
static inline int pud_devmap(pud_t pud)
{ … }
#else
static inline int pud_devmap(pud_t pud)
{
return 0;
}
#endif
static inline int pgd_devmap(pgd_t pgd)
{ … }
#endif
#endif
static inline pte_t pte_set_flags(pte_t pte, pteval_t set)
{ … }
static inline pte_t pte_clear_flags(pte_t pte, pteval_t clear)
{ … }
static inline pgprotval_t mksaveddirty_shift(pgprotval_t v)
{ … }
static inline pgprotval_t clear_saveddirty_shift(pgprotval_t v)
{ … }
static inline pte_t pte_mksaveddirty(pte_t pte)
{ … }
static inline pte_t pte_clear_saveddirty(pte_t pte)
{ … }
static inline pte_t pte_wrprotect(pte_t pte)
{ … }
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline int pte_uffd_wp(pte_t pte)
{ … }
static inline pte_t pte_mkuffd_wp(pte_t pte)
{ … }
static inline pte_t pte_clear_uffd_wp(pte_t pte)
{ … }
#endif
static inline pte_t pte_mkclean(pte_t pte)
{ … }
static inline pte_t pte_mkold(pte_t pte)
{ … }
static inline pte_t pte_mkexec(pte_t pte)
{ … }
static inline pte_t pte_mkdirty(pte_t pte)
{ … }
static inline pte_t pte_mkwrite_shstk(pte_t pte)
{ … }
static inline pte_t pte_mkyoung(pte_t pte)
{ … }
static inline pte_t pte_mkwrite_novma(pte_t pte)
{ … }
struct vm_area_struct;
pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma);
#define pte_mkwrite …
static inline pte_t pte_mkhuge(pte_t pte)
{ … }
static inline pte_t pte_clrhuge(pte_t pte)
{ … }
static inline pte_t pte_mkglobal(pte_t pte)
{ … }
static inline pte_t pte_clrglobal(pte_t pte)
{ … }
static inline pte_t pte_mkspecial(pte_t pte)
{ … }
static inline pte_t pte_mkdevmap(pte_t pte)
{ … }
static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
{ … }
static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear)
{ … }
static inline pmd_t pmd_mksaveddirty(pmd_t pmd)
{ … }
static inline pmd_t pmd_clear_saveddirty(pmd_t pmd)
{ … }
static inline pmd_t pmd_wrprotect(pmd_t pmd)
{ … }
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline int pmd_uffd_wp(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkuffd_wp(pmd_t pmd)
{ … }
static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd)
{ … }
#endif
static inline pmd_t pmd_mkold(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkclean(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkdirty(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkwrite_shstk(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkdevmap(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkhuge(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkyoung(pmd_t pmd)
{ … }
static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
{ … }
pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
#define pmd_mkwrite …
static inline pud_t pud_set_flags(pud_t pud, pudval_t set)
{ … }
static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear)
{ … }
static inline pud_t pud_mksaveddirty(pud_t pud)
{ … }
static inline pud_t pud_clear_saveddirty(pud_t pud)
{ … }
static inline pud_t pud_mkold(pud_t pud)
{ … }
static inline pud_t pud_mkclean(pud_t pud)
{ … }
static inline pud_t pud_wrprotect(pud_t pud)
{ … }
static inline pud_t pud_mkdirty(pud_t pud)
{ … }
static inline pud_t pud_mkdevmap(pud_t pud)
{ … }
static inline pud_t pud_mkhuge(pud_t pud)
{ … }
static inline pud_t pud_mkyoung(pud_t pud)
{ … }
static inline pud_t pud_mkwrite(pud_t pud)
{ … }
#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
static inline int pte_soft_dirty(pte_t pte)
{ … }
static inline int pmd_soft_dirty(pmd_t pmd)
{ … }
static inline int pud_soft_dirty(pud_t pud)
{ … }
static inline pte_t pte_mksoft_dirty(pte_t pte)
{ … }
static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
{ … }
static inline pud_t pud_mksoft_dirty(pud_t pud)
{ … }
static inline pte_t pte_clear_soft_dirty(pte_t pte)
{ … }
static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
{ … }
static inline pud_t pud_clear_soft_dirty(pud_t pud)
{ … }
#endif
static inline pgprotval_t massage_pgprot(pgprot_t pgprot)
{ … }
static inline pgprotval_t check_pgprot(pgprot_t pgprot)
{ … }
static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
{ … }
static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
{ … }
static inline pud_t pfn_pud(unsigned long page_nr, pgprot_t pgprot)
{ … }
static inline pmd_t pmd_mkinvalid(pmd_t pmd)
{ … }
static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask);
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
{ … }
static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
{ … }
#define pgprot_modify …
static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
{ … }
#define pte_pgprot(x) …
#define pmd_pgprot(x) …
#define pud_pgprot(x) …
#define p4d_pgprot(x) …
#define canon_pgprot(p) …
static inline int is_new_memtype_allowed(u64 paddr, unsigned long size,
enum page_cache_mode pcm,
enum page_cache_mode new_pcm)
{ … }
pmd_t *populate_extra_pmd(unsigned long vaddr);
pte_t *populate_extra_pte(unsigned long vaddr);
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd);
static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd)
{ … }
#else
static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd)
{
return pgd;
}
#endif
#endif
#ifdef CONFIG_X86_32
# include <asm/pgtable_32.h>
#else
# include <asm/pgtable_64.h>
#endif
#ifndef __ASSEMBLY__
#include <linux/mm_types.h>
#include <linux/mmdebug.h>
#include <linux/log2.h>
#include <asm/fixmap.h>
static inline int pte_none(pte_t pte)
{ … }
#define __HAVE_ARCH_PTE_SAME
static inline int pte_same(pte_t a, pte_t b)
{ … }
static inline pte_t pte_advance_pfn(pte_t pte, unsigned long nr)
{ … }
#define pte_advance_pfn …
static inline int pte_present(pte_t a)
{ … }
#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP
static inline int pte_devmap(pte_t a)
{ … }
#endif
#define pte_accessible …
static inline bool pte_accessible(struct mm_struct *mm, pte_t a)
{ … }
static inline int pmd_present(pmd_t pmd)
{ … }
#ifdef CONFIG_NUMA_BALANCING
static inline int pte_protnone(pte_t pte)
{ … }
static inline int pmd_protnone(pmd_t pmd)
{ … }
#endif
static inline int pmd_none(pmd_t pmd)
{ … }
static inline unsigned long pmd_page_vaddr(pmd_t pmd)
{ … }
#define pmd_page(pmd) …
#define mk_pte(page, pgprot) …
static inline int pmd_bad(pmd_t pmd)
{ … }
static inline unsigned long pages_to_mb(unsigned long npg)
{ … }
#if CONFIG_PGTABLE_LEVELS > 2
static inline int pud_none(pud_t pud)
{ … }
static inline int pud_present(pud_t pud)
{ … }
static inline pmd_t *pud_pgtable(pud_t pud)
{ … }
#define pud_page(pud) …
#define pud_leaf …
static inline bool pud_leaf(pud_t pud)
{ … }
static inline int pud_bad(pud_t pud)
{ … }
#endif
#if CONFIG_PGTABLE_LEVELS > 3
static inline int p4d_none(p4d_t p4d)
{ … }
static inline int p4d_present(p4d_t p4d)
{ … }
static inline pud_t *p4d_pgtable(p4d_t p4d)
{ … }
#define p4d_page(p4d) …
static inline int p4d_bad(p4d_t p4d)
{ … }
#endif
static inline unsigned long p4d_index(unsigned long address)
{ … }
#if CONFIG_PGTABLE_LEVELS > 4
static inline int pgd_present(pgd_t pgd)
{ … }
static inline unsigned long pgd_page_vaddr(pgd_t pgd)
{ … }
#define pgd_page(pgd) …
static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
{ … }
static inline int pgd_bad(pgd_t pgd)
{ … }
static inline int pgd_none(pgd_t pgd)
{ … }
#endif
#endif
#define KERNEL_PGD_BOUNDARY …
#define KERNEL_PGD_PTRS …
#ifndef __ASSEMBLY__
extern int direct_gbpages;
void init_mem_mapping(void);
void early_alloc_pgt_buf(void);
void __init poking_init(void);
unsigned long init_memory_mapping(unsigned long start,
unsigned long end, pgprot_t prot);
#ifdef CONFIG_X86_64
extern pgd_t trampoline_pgd_entry;
#endif
static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
{ … }
static inline pmd_t native_local_pmdp_get_and_clear(pmd_t *pmdp)
{ … }
static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp)
{ … }
static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
pmd_t *pmdp, pmd_t pmd)
{ … }
static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
pud_t *pudp, pud_t pud)
{ … }
struct vm_area_struct;
#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
extern int ptep_set_access_flags(struct vm_area_struct *vma,
unsigned long address, pte_t *ptep,
pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep);
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
extern int ptep_clear_flush_young(struct vm_area_struct *vma,
unsigned long address, pte_t *ptep);
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
pte_t *ptep)
{ … }
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
unsigned long addr, pte_t *ptep,
int full)
{ … }
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
static inline void ptep_set_wrprotect(struct mm_struct *mm,
unsigned long addr, pte_t *ptep)
{ … }
#define flush_tlb_fix_spurious_fault(vma, address, ptep) …
#define mk_pmd(page, pgprot) …
#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
extern int pmdp_set_access_flags(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp,
pmd_t entry, int dirty);
extern int pudp_set_access_flags(struct vm_area_struct *vma,
unsigned long address, pud_t *pudp,
pud_t entry, int dirty);
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp);
extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pud_t *pudp);
#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp);
#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr,
pmd_t *pmdp)
{ … }
#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
unsigned long addr, pud_t *pudp)
{ … }
#define __HAVE_ARCH_PMDP_SET_WRPROTECT
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
unsigned long addr, pmd_t *pmdp)
{ … }
#ifndef pmdp_establish
#define pmdp_establish …
static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp, pmd_t pmd)
{ … }
#endif
#define __HAVE_ARCH_PMDP_INVALIDATE_AD
extern pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp);
static inline bool pgdp_maps_userspace(void *__ptr)
{ … }
#define pgd_leaf …
static inline bool pgd_leaf(pgd_t pgd) { … }
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
#define PTI_PGTABLE_SWITCH_BIT …
static inline void *ptr_set_bit(void *ptr, int bit)
{ … }
static inline void *ptr_clear_bit(void *ptr, int bit)
{ … }
static inline pgd_t *kernel_to_user_pgdp(pgd_t *pgdp)
{ … }
static inline pgd_t *user_to_kernel_pgdp(pgd_t *pgdp)
{ … }
static inline p4d_t *kernel_to_user_p4dp(p4d_t *p4dp)
{ … }
static inline p4d_t *user_to_kernel_p4dp(p4d_t *p4dp)
{ … }
#endif
static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
{ … }
#define PTE_SHIFT …
static inline int page_level_shift(enum pg_level level)
{ … }
static inline unsigned long page_level_size(enum pg_level level)
{ … }
static inline unsigned long page_level_mask(enum pg_level level)
{ … }
static inline void update_mmu_cache(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep)
{ … }
static inline void update_mmu_cache_range(struct vm_fault *vmf,
struct vm_area_struct *vma, unsigned long addr,
pte_t *ptep, unsigned int nr)
{ … }
static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmd)
{ … }
static inline void update_mmu_cache_pud(struct vm_area_struct *vma,
unsigned long addr, pud_t *pud)
{ … }
static inline pte_t pte_swp_mkexclusive(pte_t pte)
{ … }
static inline int pte_swp_exclusive(pte_t pte)
{ … }
static inline pte_t pte_swp_clear_exclusive(pte_t pte)
{ … }
#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
{ … }
static inline int pte_swp_soft_dirty(pte_t pte)
{ … }
static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
{ … }
#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
{ … }
static inline int pmd_swp_soft_dirty(pmd_t pmd)
{ … }
static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
{ … }
#endif
#endif
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline pte_t pte_swp_mkuffd_wp(pte_t pte)
{ … }
static inline int pte_swp_uffd_wp(pte_t pte)
{ … }
static inline pte_t pte_swp_clear_uffd_wp(pte_t pte)
{ … }
static inline pmd_t pmd_swp_mkuffd_wp(pmd_t pmd)
{ … }
static inline int pmd_swp_uffd_wp(pmd_t pmd)
{ … }
static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd)
{ … }
#endif
static inline u16 pte_flags_pkey(unsigned long pte_flags)
{ … }
static inline bool __pkru_allows_pkey(u16 pkey, bool write)
{ … }
static inline bool __pte_access_permitted(unsigned long pteval, bool write)
{ … }
#define pte_access_permitted …
static inline bool pte_access_permitted(pte_t pte, bool write)
{ … }
#define pmd_access_permitted …
static inline bool pmd_access_permitted(pmd_t pmd, bool write)
{ … }
#define pud_access_permitted …
static inline bool pud_access_permitted(pud_t pud, bool write)
{ … }
#define __HAVE_ARCH_PFN_MODIFY_ALLOWED …
extern bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot);
static inline bool arch_has_pfn_modify_check(void)
{ … }
#define arch_check_zapped_pte …
void arch_check_zapped_pte(struct vm_area_struct *vma, pte_t pte);
#define arch_check_zapped_pmd …
void arch_check_zapped_pmd(struct vm_area_struct *vma, pmd_t pmd);
#ifdef CONFIG_XEN_PV
#define arch_has_hw_nonleaf_pmd_young …
static inline bool arch_has_hw_nonleaf_pmd_young(void)
{ … }
#endif
#ifdef CONFIG_PAGE_TABLE_CHECK
static inline bool pte_user_accessible_page(pte_t pte)
{ … }
static inline bool pmd_user_accessible_page(pmd_t pmd)
{ … }
static inline bool pud_user_accessible_page(pud_t pud)
{ … }
#endif
#ifdef CONFIG_X86_SGX
int arch_memory_failure(unsigned long pfn, int flags);
#define arch_memory_failure …
bool arch_is_platform_page(u64 paddr);
#define arch_is_platform_page …
#endif
#endif
#endif