vectors.h 1.7 KB
Newer Older
1 2 3 4 5 6 7
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2022 ARM Ltd.
 */
#ifndef __ASM_VECTORS_H
#define __ASM_VECTORS_H

J
James Morse 已提交
8 9 10 11 12 13 14 15 16
#include <linux/bug.h>
#include <linux/percpu.h>

#include <asm/fixmap.h>

extern char vectors[];
extern char tramp_vectors[];
extern char __bp_harden_el1_vectors[];

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Note: the order of this enum corresponds to two arrays in entry.S:
 * tramp_vecs and __bp_harden_el1_vectors. By default the canonical
 * 'full fat' vectors are used directly.
 */
enum arm64_bp_harden_el1_vectors {
#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
	/*
	 * Perform the BHB loop mitigation, before branching to the canonical
	 * vectors.
	 */
	EL1_VECTOR_BHB_LOOP,

	/*
	 * Make the SMC call for firmware mitigation, before branching to the
	 * canonical vectors.
	 */
	EL1_VECTOR_BHB_FW,
35 36 37 38 39 40

	/*
	 * Use the ClearBHB instruction, before branching to the canonical
	 * vectors.
	 */
	EL1_VECTOR_BHB_CLEAR_INSN,
41 42 43 44 45 46
#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */

	/*
	 * Remap the kernel before branching to the canonical vectors.
	 */
	EL1_VECTOR_KPTI,
J
James Morse 已提交
47 48
};

49 50 51
#ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
#define EL1_VECTOR_BHB_LOOP		-1
#define EL1_VECTOR_BHB_FW		-1
52
#define EL1_VECTOR_BHB_CLEAR_INSN	-1
53 54
#endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */

J
James Morse 已提交
55 56 57 58
/* The vectors to use on return from EL0. e.g. to remap the kernel */
DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);

#ifndef CONFIG_UNMAP_KERNEL_AT_EL0
59
#define TRAMP_VALIAS	0ul
J
James Morse 已提交
60 61 62 63 64 65
#endif

static inline const char *
arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
{
	if (arm64_kernel_unmapped_at_el0())
66
		return (char *)(TRAMP_VALIAS + SZ_2K * slot);
J
James Morse 已提交
67 68 69 70 71

	WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);

	return __bp_harden_el1_vectors + SZ_2K * slot;
}
72 73

#endif /* __ASM_VECTORS_H */