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 15fc0e1299SWill Deacon #ifndef __ASSEMBLY__ 16fc0e1299SWill Deacon 1748118151SJean-Philippe Brucker #include <linux/refcount.h> 1848118151SJean-Philippe Brucker 194f04d8f0SCatalin Marinas typedef struct { 205aec715dSWill Deacon atomic64_t id; 21a39060b0SWill Deacon #ifdef CONFIG_COMPAT 22a39060b0SWill Deacon void *sigpage; 23a39060b0SWill Deacon #endif 2448118151SJean-Philippe Brucker refcount_t pinned; 254f04d8f0SCatalin Marinas void *vdso; 2606beb72fSPratyush Anand unsigned long flags; 274f04d8f0SCatalin Marinas } mm_context_t; 284f04d8f0SCatalin Marinas 295aec715dSWill Deacon /* 30*5e10f988SWill Deacon * We use atomic64_read() here because the ASID for an 'mm_struct' can 31*5e10f988SWill Deacon * be reallocated when scheduling one of its threads following a 32*5e10f988SWill Deacon * rollover event (see new_context() and flush_context()). In this case, 33*5e10f988SWill Deacon * a concurrent TLBI (e.g. via try_to_unmap_one() and ptep_clear_flush()) 34*5e10f988SWill Deacon * may use a stale ASID. This is fine in principle as the new ASID is 35*5e10f988SWill Deacon * guaranteed to be clean in the TLB, but the TLBI routines have to take 36*5e10f988SWill Deacon * care to handle the following race: 37*5e10f988SWill Deacon * 38*5e10f988SWill Deacon * CPU 0 CPU 1 CPU 2 39*5e10f988SWill Deacon * 40*5e10f988SWill Deacon * // ptep_clear_flush(mm) 41*5e10f988SWill Deacon * xchg_relaxed(pte, 0) 42*5e10f988SWill Deacon * DSB ISHST 43*5e10f988SWill Deacon * old = ASID(mm) 44*5e10f988SWill Deacon * | <rollover> 45*5e10f988SWill Deacon * | new = new_context(mm) 46*5e10f988SWill Deacon * \-----------------> atomic_set(mm->context.id, new) 47*5e10f988SWill Deacon * cpu_switch_mm(mm) 48*5e10f988SWill Deacon * // Hardware walk of pte using new ASID 49*5e10f988SWill Deacon * TLBI(old) 50*5e10f988SWill Deacon * 51*5e10f988SWill Deacon * In this scenario, the barrier on CPU 0 and the dependency on CPU 1 52*5e10f988SWill Deacon * ensure that the page-table walker on CPU 1 *must* see the invalid PTE 53*5e10f988SWill Deacon * written by CPU 0. 545aec715dSWill Deacon */ 55*5e10f988SWill Deacon #define ASID(mm) (atomic64_read(&(mm)->context.id) & 0xffff) 564f04d8f0SCatalin Marinas 57fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void) 58fc0e1299SWill Deacon { 59c8355785SWill Deacon return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); 60b89d82efSWill Deacon } 61b89d82efSWill Deacon 6283504032SWill Deacon extern void arm64_memblock_init(void); 634f04d8f0SCatalin Marinas extern void paging_init(void); 643194ac6eSDavid Daney extern void bootmem_init(void); 652475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt); 660bf757c7SMark Salter extern void init_mem_pgprot(void); 678ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, 688ce837ceSArd Biesheuvel unsigned long virt, phys_addr_t size, 69f14c66ceSArd Biesheuvel pgprot_t prot, bool page_mappings_only); 70e112b032SHsin-Yi Wang extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot); 715ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void); 7209e3c22aSMark Brown extern bool kaslr_requires_kpti(void); 734f04d8f0SCatalin Marinas 742b5548b6SJun Yao #define INIT_MM_CONTEXT(name) \ 752b5548b6SJun Yao .pgd = init_pg_dir, 762b5548b6SJun Yao 77fc0e1299SWill Deacon #endif /* !__ASSEMBLY__ */ 784f04d8f0SCatalin Marinas #endif 79