commit 228a26b912287934789023b4132ba76065d9491c upstream.
Future CPUs may implement a clearbhb instruction that is sufficient
to mitigate SpectreBHB. CPUs that implement this instruction, but
not CSV2.3 must be affected by Spectre-BHB.
Add support to use this instruction as the BHB mitigation on CPUs
that support it. The instruction is in the hint space so it will
be treated by a NOP as older CPUs.
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
[ modified for stable: Use a KVM vector template instead of alternatives ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: ed5dec3fae
Git-repo: https://android.googlesource.com/kernel/common/
Change-Id: I78e5a1888e44ef45294ed35226c4cce43f249126
Signed-off-by: Kishor Krishna Bhat <quic_kishkris@quicinc.com>
75 lines
1.8 KiB
C
75 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2022 ARM Ltd.
|
|
*/
|
|
#ifndef __ASM_VECTORS_H
|
|
#define __ASM_VECTORS_H
|
|
|
|
#include <linux/bug.h>
|
|
#include <linux/percpu.h>
|
|
|
|
#include <asm/fixmap.h>
|
|
#include <asm/mmu.h>
|
|
|
|
extern char vectors[];
|
|
extern char tramp_vectors[];
|
|
extern char __bp_harden_el1_vectors[];
|
|
|
|
/*
|
|
* 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,
|
|
|
|
/*
|
|
* Use the ClearBHB instruction, before branching to the canonical
|
|
* vectors.
|
|
*/
|
|
EL1_VECTOR_BHB_CLEAR_INSN,
|
|
#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
|
|
|
|
/*
|
|
* Remap the kernel before branching to the canonical vectors.
|
|
*/
|
|
EL1_VECTOR_KPTI,
|
|
};
|
|
|
|
#ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
|
|
#define EL1_VECTOR_BHB_LOOP -1
|
|
#define EL1_VECTOR_BHB_FW -1
|
|
#define EL1_VECTOR_BHB_CLEAR_INSN -1
|
|
#endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
|
|
|
|
/* 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
|
|
#define TRAMP_VALIAS 0
|
|
#endif
|
|
|
|
static inline const char *
|
|
arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
|
|
{
|
|
if (arm64_kernel_unmapped_at_el0())
|
|
return (char *)TRAMP_VALIAS + SZ_2K * slot;
|
|
|
|
WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
|
|
|
|
return __bp_harden_el1_vectors + SZ_2K * slot;
|
|
}
|
|
|
|
#endif /* __ASM_VECTORS_H */
|