2021-11-18 21:59:46 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 ARM Ltd.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_VECTORS_H
|
|
|
|
#define __ASM_VECTORS_H
|
|
|
|
|
2021-11-24 02:29:25 +08:00
|
|
|
#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[];
|
|
|
|
|
2021-11-18 21:59:46 +08:00
|
|
|
/*
|
|
|
|
* 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,
|
2021-12-10 22:32:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the ClearBHB instruction, before branching to the canonical
|
|
|
|
* vectors.
|
|
|
|
*/
|
|
|
|
EL1_VECTOR_BHB_CLEAR_INSN,
|
2021-11-18 21:59:46 +08:00
|
|
|
#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remap the kernel before branching to the canonical vectors.
|
|
|
|
*/
|
|
|
|
EL1_VECTOR_KPTI,
|
2021-11-24 02:29:25 +08:00
|
|
|
};
|
|
|
|
|
arm64: Mitigate spectre style branch history side channels
Speculation attacks against some high-performance processors can
make use of branch history to influence future speculation.
When taking an exception from user-space, a sequence of branches
or a firmware call overwrites or invalidates the branch history.
The sequence of branches is added to the vectors, and should appear
before the first indirect branch. For systems using KPTI the sequence
is added to the kpti trampoline where it has a free register as the exit
from the trampoline is via a 'ret'. For systems not using KPTI, the same
register tricks are used to free up a register in the vectors.
For the firmware call, arch-workaround-3 clobbers 4 registers, so
there is no choice but to save them to the EL1 stack. This only happens
for entry from EL0, so if we take an exception due to the stack access,
it will not become re-entrant.
For KVM, the existing branch-predictor-hardening vectors are used.
When a spectre version of these vectors is in use, the firmware call
is sufficient to mitigate against Spectre-BHB. For the non-spectre
versions, the sequence of branches is added to the indirect vector.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
2021-11-10 22:48:00 +08:00
|
|
|
#ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
|
|
|
|
#define EL1_VECTOR_BHB_LOOP -1
|
|
|
|
#define EL1_VECTOR_BHB_FW -1
|
2021-12-10 22:32:56 +08:00
|
|
|
#define EL1_VECTOR_BHB_CLEAR_INSN -1
|
arm64: Mitigate spectre style branch history side channels
Speculation attacks against some high-performance processors can
make use of branch history to influence future speculation.
When taking an exception from user-space, a sequence of branches
or a firmware call overwrites or invalidates the branch history.
The sequence of branches is added to the vectors, and should appear
before the first indirect branch. For systems using KPTI the sequence
is added to the kpti trampoline where it has a free register as the exit
from the trampoline is via a 'ret'. For systems not using KPTI, the same
register tricks are used to free up a register in the vectors.
For the firmware call, arch-workaround-3 clobbers 4 registers, so
there is no choice but to save them to the EL1 stack. This only happens
for entry from EL0, so if we take an exception due to the stack access,
it will not become re-entrant.
For KVM, the existing branch-predictor-hardening vectors are used.
When a spectre version of these vectors is in use, the firmware call
is sufficient to mitigate against Spectre-BHB. For the non-spectre
versions, the sequence of branches is added to the indirect vector.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
2021-11-10 22:48:00 +08:00
|
|
|
#endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
|
|
|
|
|
2021-11-24 02:29:25 +08:00
|
|
|
/* 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
|
2022-03-17 02:38:18 +08:00
|
|
|
#define TRAMP_VALIAS 0ul
|
2021-11-24 02:29:25 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
|
|
|
|
{
|
|
|
|
if (arm64_kernel_unmapped_at_el0())
|
2022-03-17 02:38:18 +08:00
|
|
|
return (char *)(TRAMP_VALIAS + SZ_2K * slot);
|
2021-11-24 02:29:25 +08:00
|
|
|
|
|
|
|
WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
|
|
|
|
|
|
|
|
return __bp_harden_el1_vectors + SZ_2K * slot;
|
|
|
|
}
|
2021-11-18 21:59:46 +08:00
|
|
|
|
|
|
|
#endif /* __ASM_VECTORS_H */
|