blob: b2e91c187e2a6442b8777d537a93e4aeaf12842c [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Catalin Marinas4f04d8f2012-03-05 11:49:27 +00002/*
3 * Copyright (C) 2012 ARM Ltd.
Catalin Marinas4f04d8f2012-03-05 11:49:27 +00004 */
5#ifndef __ASM_MMU_H
6#define __ASM_MMU_H
7
Will Deaconb89d82e2019-01-08 16:19:01 +00008#include <asm/cputype.h>
9
Yury Norov5ce93ab62017-08-20 13:20:47 +030010#define MMCF_AARCH32 0x1 /* mm context flag for AArch32 executables */
James Morse79e9aa52018-01-08 15:38:18 +000011#define USER_ASID_BIT 48
12#define USER_ASID_FLAG (UL(1) << USER_ASID_BIT)
Will Deaconb5195382017-12-01 17:33:48 +000013#define TTBR_ASID_MASK (UL(0xffff) << 48)
Yury Norov5ce93ab62017-08-20 13:20:47 +030014
Marc Zyngier4205a892018-03-13 12:40:39 +000015#define BP_HARDEN_EL2_SLOTS 4
Mark Brown6e52aab2020-02-18 19:58:38 +000016#define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K)
Marc Zyngier4205a892018-03-13 12:40:39 +000017
Will Deaconfc0e1292017-11-14 13:58:08 +000018#ifndef __ASSEMBLY__
19
Jean-Philippe Brucker48118152020-09-18 12:18:44 +020020#include <linux/refcount.h>
21
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000022typedef struct {
Will Deacon5aec7152015-10-06 18:46:24 +010023 atomic64_t id;
Will Deacona39060b2020-06-22 12:35:41 +010024#ifdef CONFIG_COMPAT
25 void *sigpage;
26#endif
Jean-Philippe Brucker48118152020-09-18 12:18:44 +020027 refcount_t pinned;
Will Deacon5aec7152015-10-06 18:46:24 +010028 void *vdso;
Pratyush Anand06beb722016-11-02 14:40:45 +053029 unsigned long flags;
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000030} mm_context_t;
31
Will Deacon5aec7152015-10-06 18:46:24 +010032/*
Will Deacon90765f72020-02-28 12:43:55 +000033 * This macro is only used by the TLBI and low-level switch_mm() code,
34 * neither of which can race with an ASID change. We therefore don't
35 * need to reload the counter using atomic64_read().
Will Deacon5aec7152015-10-06 18:46:24 +010036 */
37#define ASID(mm) ((mm)->context.id.counter & 0xffff)
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000038
Will Deaconfc0e1292017-11-14 13:58:08 +000039static inline bool arm64_kernel_unmapped_at_el0(void)
40{
Will Deaconc8355782020-03-18 20:38:29 +000041 return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
Will Deaconb89d82e2019-01-08 16:19:01 +000042}
43
Will Deacon0f15adb2018-01-03 11:17:58 +000044typedef void (*bp_hardening_cb_t)(void);
45
46struct bp_hardening_data {
47 int hyp_vectors_slot;
48 bp_hardening_cb_t fn;
49};
50
Will Deacon0f15adb2018-01-03 11:17:58 +000051DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
52
53static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void)
54{
55 return this_cpu_ptr(&bp_hardening_data);
56}
57
58static inline void arm64_apply_bp_hardening(void)
59{
60 struct bp_hardening_data *d;
61
Will Deacon688f1e42020-09-15 23:00:31 +010062 if (!cpus_have_const_cap(ARM64_SPECTRE_V2))
Will Deacon0f15adb2018-01-03 11:17:58 +000063 return;
64
65 d = arm64_get_bp_hardening_data();
66 if (d->fn)
67 d->fn();
68}
Will Deacon0f15adb2018-01-03 11:17:58 +000069
Will Deacon83504032019-01-14 14:22:24 +000070extern void arm64_memblock_init(void);
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000071extern void paging_init(void);
David Daney3194ac62016-04-08 15:50:26 -070072extern void bootmem_init(void);
Catalin Marinas2475ff92012-10-23 14:55:08 +010073extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt);
Mark Salter0bf757c2014-04-07 15:39:51 -070074extern void init_mem_pgprot(void);
Ard Biesheuvel8ce837c2014-10-20 15:42:07 +020075extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
76 unsigned long virt, phys_addr_t size,
Ard Biesheuvelf14c66c2016-10-21 12:22:57 +010077 pgprot_t prot, bool page_mappings_only);
Hsin-Yi Wange112b032019-08-23 14:24:50 +080078extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
Ard Biesheuvel5ea53062017-03-09 21:52:01 +010079extern void mark_linear_text_alias_ro(void);
Mark Brown09e3c222019-12-09 18:12:17 +000080extern bool kaslr_requires_kpti(void);
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000081
Jun Yao2b5548b2018-09-24 15:47:49 +010082#define INIT_MM_CONTEXT(name) \
83 .pgd = init_pg_dir,
84
Will Deaconfc0e1292017-11-14 13:58:08 +000085#endif /* !__ASSEMBLY__ */
Catalin Marinas4f04d8f2012-03-05 11:49:27 +000086#endif