xref: /openbmc/linux/arch/arm64/include/asm/mmu.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
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>
187e04f059SWill Deacon #include <asm/cpufeature.h>
1948118151SJean-Philippe Brucker 
204f04d8f0SCatalin Marinas typedef struct {
215aec715dSWill Deacon 	atomic64_t	id;
22a39060b0SWill Deacon #ifdef CONFIG_COMPAT
23a39060b0SWill Deacon 	void		*sigpage;
24a39060b0SWill Deacon #endif
2548118151SJean-Philippe Brucker 	refcount_t	pinned;
264f04d8f0SCatalin Marinas 	void		*vdso;
2706beb72fSPratyush Anand 	unsigned long	flags;
284f04d8f0SCatalin Marinas } mm_context_t;
294f04d8f0SCatalin Marinas 
305aec715dSWill Deacon /*
315e10f988SWill Deacon  * We use atomic64_read() here because the ASID for an 'mm_struct' can
325e10f988SWill Deacon  * be reallocated when scheduling one of its threads following a
335e10f988SWill Deacon  * rollover event (see new_context() and flush_context()). In this case,
345e10f988SWill Deacon  * a concurrent TLBI (e.g. via try_to_unmap_one() and ptep_clear_flush())
355e10f988SWill Deacon  * may use a stale ASID. This is fine in principle as the new ASID is
365e10f988SWill Deacon  * guaranteed to be clean in the TLB, but the TLBI routines have to take
375e10f988SWill Deacon  * care to handle the following race:
385e10f988SWill Deacon  *
395e10f988SWill Deacon  *    CPU 0                    CPU 1                          CPU 2
405e10f988SWill Deacon  *
415e10f988SWill Deacon  *    // ptep_clear_flush(mm)
425e10f988SWill Deacon  *    xchg_relaxed(pte, 0)
435e10f988SWill Deacon  *    DSB ISHST
445e10f988SWill Deacon  *    old = ASID(mm)
455e10f988SWill Deacon  *         |                                                  <rollover>
465e10f988SWill Deacon  *         |                   new = new_context(mm)
475e10f988SWill Deacon  *         \-----------------> atomic_set(mm->context.id, new)
485e10f988SWill Deacon  *                             cpu_switch_mm(mm)
495e10f988SWill Deacon  *                             // Hardware walk of pte using new ASID
505e10f988SWill Deacon  *    TLBI(old)
515e10f988SWill Deacon  *
525e10f988SWill Deacon  * In this scenario, the barrier on CPU 0 and the dependency on CPU 1
535e10f988SWill Deacon  * ensure that the page-table walker on CPU 1 *must* see the invalid PTE
545e10f988SWill Deacon  * written by CPU 0.
555aec715dSWill Deacon  */
565e10f988SWill Deacon #define ASID(mm)	(atomic64_read(&(mm)->context.id) & 0xffff)
574f04d8f0SCatalin Marinas 
arm64_kernel_unmapped_at_el0(void)58fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void)
59fc0e1299SWill Deacon {
60c8355785SWill Deacon 	return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
61b89d82efSWill Deacon }
62b89d82efSWill Deacon 
6383504032SWill Deacon extern void arm64_memblock_init(void);
644f04d8f0SCatalin Marinas extern void paging_init(void);
653194ac6eSDavid Daney extern void bootmem_init(void);
662475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt);
67*b9754776SMark Rutland extern void create_mapping_noalloc(phys_addr_t phys, unsigned long virt,
68*b9754776SMark Rutland 				   phys_addr_t size, pgprot_t prot);
698ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
708ce837ceSArd Biesheuvel 			       unsigned long virt, phys_addr_t size,
71f14c66ceSArd Biesheuvel 			       pgprot_t prot, bool page_mappings_only);
72e112b032SHsin-Yi Wang extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
735ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void);
7409e3c22aSMark Brown extern bool kaslr_requires_kpti(void);
754f04d8f0SCatalin Marinas 
762b5548b6SJun Yao #define INIT_MM_CONTEXT(name)	\
772b5548b6SJun Yao 	.pgd = init_pg_dir,
782b5548b6SJun Yao 
79fc0e1299SWill Deacon #endif	/* !__ASSEMBLY__ */
804f04d8f0SCatalin Marinas #endif
81