1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 24f04d8f0SCatalin Marinas /* 34f04d8f0SCatalin Marinas * Copyright (C) 2012 ARM Ltd. 44f04d8f0SCatalin Marinas */ 54f04d8f0SCatalin Marinas #ifndef __ASM_MMU_H 64f04d8f0SCatalin Marinas #define __ASM_MMU_H 74f04d8f0SCatalin Marinas 8b89d82efSWill Deacon #include <asm/cputype.h> 9b89d82efSWill Deacon 105ce93ab6SYury Norov #define MMCF_AARCH32 0x1 /* mm context flag for AArch32 executables */ 1179e9aa59SJames Morse #define USER_ASID_BIT 48 1279e9aa59SJames Morse #define USER_ASID_FLAG (UL(1) << USER_ASID_BIT) 13b519538dSWill Deacon #define TTBR_ASID_MASK (UL(0xffff) << 48) 145ce93ab6SYury Norov 154205a89bSMarc Zyngier #define BP_HARDEN_EL2_SLOTS 4 166e52aab9SMark Brown #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K) 174205a89bSMarc Zyngier 18fc0e1299SWill Deacon #ifndef __ASSEMBLY__ 19fc0e1299SWill Deacon 204f04d8f0SCatalin Marinas typedef struct { 215aec715dSWill Deacon atomic64_t id; 22*a39060b0SWill Deacon #ifdef CONFIG_COMPAT 23*a39060b0SWill Deacon void *sigpage; 24*a39060b0SWill Deacon #endif 254f04d8f0SCatalin Marinas void *vdso; 2606beb72fSPratyush Anand unsigned long flags; 274f04d8f0SCatalin Marinas } mm_context_t; 284f04d8f0SCatalin Marinas 295aec715dSWill Deacon /* 3090765f74SWill Deacon * This macro is only used by the TLBI and low-level switch_mm() code, 3190765f74SWill Deacon * neither of which can race with an ASID change. We therefore don't 3290765f74SWill Deacon * need to reload the counter using atomic64_read(). 335aec715dSWill Deacon */ 345aec715dSWill Deacon #define ASID(mm) ((mm)->context.id.counter & 0xffff) 354f04d8f0SCatalin Marinas 36fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void) 37fc0e1299SWill Deacon { 38c8355785SWill Deacon return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); 39b89d82efSWill Deacon } 40b89d82efSWill Deacon 410f15adbbSWill Deacon typedef void (*bp_hardening_cb_t)(void); 420f15adbbSWill Deacon 430f15adbbSWill Deacon struct bp_hardening_data { 440f15adbbSWill Deacon int hyp_vectors_slot; 450f15adbbSWill Deacon bp_hardening_cb_t fn; 460f15adbbSWill Deacon }; 470f15adbbSWill Deacon 48dee39247SMarc Zyngier #if (defined(CONFIG_HARDEN_BRANCH_PREDICTOR) || \ 49dee39247SMarc Zyngier defined(CONFIG_HARDEN_EL2_VECTORS)) 506e52aab9SMark Brown 516e52aab9SMark Brown extern char __bp_harden_hyp_vecs[]; 524205a89bSMarc Zyngier extern atomic_t arm64_el2_vector_last_slot; 53dee39247SMarc Zyngier #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR || CONFIG_HARDEN_EL2_VECTORS */ 540f15adbbSWill Deacon 55dee39247SMarc Zyngier #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 560f15adbbSWill Deacon DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 570f15adbbSWill Deacon 580f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 590f15adbbSWill Deacon { 600f15adbbSWill Deacon return this_cpu_ptr(&bp_hardening_data); 610f15adbbSWill Deacon } 620f15adbbSWill Deacon 630f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) 640f15adbbSWill Deacon { 650f15adbbSWill Deacon struct bp_hardening_data *d; 660f15adbbSWill Deacon 670f15adbbSWill Deacon if (!cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR)) 680f15adbbSWill Deacon return; 690f15adbbSWill Deacon 700f15adbbSWill Deacon d = arm64_get_bp_hardening_data(); 710f15adbbSWill Deacon if (d->fn) 720f15adbbSWill Deacon d->fn(); 730f15adbbSWill Deacon } 740f15adbbSWill Deacon #else 750f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 760f15adbbSWill Deacon { 770f15adbbSWill Deacon return NULL; 780f15adbbSWill Deacon } 790f15adbbSWill Deacon 800f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) { } 810f15adbbSWill Deacon #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ 820f15adbbSWill Deacon 8383504032SWill Deacon extern void arm64_memblock_init(void); 844f04d8f0SCatalin Marinas extern void paging_init(void); 853194ac6eSDavid Daney extern void bootmem_init(void); 862475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt); 870bf757c7SMark Salter extern void init_mem_pgprot(void); 888ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, 898ce837ceSArd Biesheuvel unsigned long virt, phys_addr_t size, 90f14c66ceSArd Biesheuvel pgprot_t prot, bool page_mappings_only); 91e112b032SHsin-Yi Wang extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot); 925ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void); 9309e3c22aSMark Brown extern bool kaslr_requires_kpti(void); 944f04d8f0SCatalin Marinas 952b5548b6SJun Yao #define INIT_MM_CONTEXT(name) \ 962b5548b6SJun Yao .pgd = init_pg_dir, 972b5548b6SJun Yao 98fc0e1299SWill Deacon #endif /* !__ASSEMBLY__ */ 994f04d8f0SCatalin Marinas #endif 100