Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2022 ARM Ltd.
0004  */
0005 #ifndef __ASM_VECTORS_H
0006 #define __ASM_VECTORS_H
0007 
0008 #include <linux/bug.h>
0009 #include <linux/percpu.h>
0010 
0011 #include <asm/fixmap.h>
0012 
0013 extern char vectors[];
0014 extern char tramp_vectors[];
0015 extern char __bp_harden_el1_vectors[];
0016 
0017 /*
0018  * Note: the order of this enum corresponds to two arrays in entry.S:
0019  * tramp_vecs and __bp_harden_el1_vectors. By default the canonical
0020  * 'full fat' vectors are used directly.
0021  */
0022 enum arm64_bp_harden_el1_vectors {
0023 #ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
0024     /*
0025      * Perform the BHB loop mitigation, before branching to the canonical
0026      * vectors.
0027      */
0028     EL1_VECTOR_BHB_LOOP,
0029 
0030     /*
0031      * Make the SMC call for firmware mitigation, before branching to the
0032      * canonical vectors.
0033      */
0034     EL1_VECTOR_BHB_FW,
0035 
0036     /*
0037      * Use the ClearBHB instruction, before branching to the canonical
0038      * vectors.
0039      */
0040     EL1_VECTOR_BHB_CLEAR_INSN,
0041 #endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
0042 
0043     /*
0044      * Remap the kernel before branching to the canonical vectors.
0045      */
0046     EL1_VECTOR_KPTI,
0047 };
0048 
0049 #ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
0050 #define EL1_VECTOR_BHB_LOOP     -1
0051 #define EL1_VECTOR_BHB_FW       -1
0052 #define EL1_VECTOR_BHB_CLEAR_INSN   -1
0053 #endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
0054 
0055 /* The vectors to use on return from EL0. e.g. to remap the kernel */
0056 DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
0057 
0058 #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
0059 #define TRAMP_VALIAS    0ul
0060 #endif
0061 
0062 static inline const char *
0063 arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
0064 {
0065     if (arm64_kernel_unmapped_at_el0())
0066         return (char *)(TRAMP_VALIAS + SZ_2K * slot);
0067 
0068     WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
0069 
0070     return __bp_harden_el1_vectors + SZ_2K * slot;
0071 }
0072 
0073 #endif /* __ASM_VECTORS_H */