Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm: Remove 32bit KVM host support

That's it. Remove all references to KVM itself, and document
that although it is no more, the ABI between SVC and HYP still
exists.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Acked-by: Olof Johansson <olof@lixom.net>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Will Deacon <will@kernel.org>
Acked-by: Vladimir Murzin <vladimir.murzin@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Christoffer Dall <christoffer.dall@arm.com>

+5 -6046
+5
Documentation/virt/kvm/arm/hyp-abi.rst
··· 11 11 hypervisor), or any hypervisor-specific interaction when the kernel is 12 12 used as a host. 13 13 14 + Note: KVM/arm has been removed from the kernel. The API described 15 + here is still valid though, as it allows the kernel to kexec when 16 + booted at HYP. It can also be used by a hypervisor other than KVM 17 + if necessary. 18 + 14 19 On arm and arm64 (without VHE), the kernel doesn't run in hypervisor 15 20 mode, but still needs to interact with it, allowing a built-in 16 21 hypervisor to be either installed or torn down.
-239
arch/arm/include/asm/kvm_arm.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_ARM_H__ 8 - #define __ARM_KVM_ARM_H__ 9 - 10 - #include <linux/const.h> 11 - #include <linux/types.h> 12 - 13 - /* Hyp Configuration Register (HCR) bits */ 14 - #define HCR_TGE (1 << 27) 15 - #define HCR_TVM (1 << 26) 16 - #define HCR_TTLB (1 << 25) 17 - #define HCR_TPU (1 << 24) 18 - #define HCR_TPC (1 << 23) 19 - #define HCR_TSW (1 << 22) 20 - #define HCR_TAC (1 << 21) 21 - #define HCR_TIDCP (1 << 20) 22 - #define HCR_TSC (1 << 19) 23 - #define HCR_TID3 (1 << 18) 24 - #define HCR_TID2 (1 << 17) 25 - #define HCR_TID1 (1 << 16) 26 - #define HCR_TID0 (1 << 15) 27 - #define HCR_TWE (1 << 14) 28 - #define HCR_TWI (1 << 13) 29 - #define HCR_DC (1 << 12) 30 - #define HCR_BSU (3 << 10) 31 - #define HCR_BSU_IS (1 << 10) 32 - #define HCR_FB (1 << 9) 33 - #define HCR_VA (1 << 8) 34 - #define HCR_VI (1 << 7) 35 - #define HCR_VF (1 << 6) 36 - #define HCR_AMO (1 << 5) 37 - #define HCR_IMO (1 << 4) 38 - #define HCR_FMO (1 << 3) 39 - #define HCR_PTW (1 << 2) 40 - #define HCR_SWIO (1 << 1) 41 - #define HCR_VM 1 42 - 43 - /* 44 - * The bits we set in HCR: 45 - * TAC: Trap ACTLR 46 - * TSC: Trap SMC 47 - * TVM: Trap VM ops (until MMU and caches are on) 48 - * TSW: Trap cache operations by set/way 49 - * TWI: Trap WFI 50 - * TWE: Trap WFE 51 - * TIDCP: Trap L2CTLR/L2ECTLR 52 - * BSU_IS: Upgrade barriers to the inner shareable domain 53 - * FB: Force broadcast of all maintainance operations 54 - * AMO: Override CPSR.A and enable signaling with VA 55 - * IMO: Override CPSR.I and enable signaling with VI 56 - * FMO: Override CPSR.F and enable signaling with VF 57 - * SWIO: Turn set/way invalidates into set/way clean+invalidate 58 - */ 59 - #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ 60 - HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ 61 - HCR_TVM | HCR_TWE | HCR_SWIO | HCR_TIDCP) 62 - 63 - /* System Control Register (SCTLR) bits */ 64 - #define SCTLR_TE (1 << 30) 65 - #define SCTLR_EE (1 << 25) 66 - #define SCTLR_V (1 << 13) 67 - 68 - /* Hyp System Control Register (HSCTLR) bits */ 69 - #define HSCTLR_TE (1 << 30) 70 - #define HSCTLR_EE (1 << 25) 71 - #define HSCTLR_FI (1 << 21) 72 - #define HSCTLR_WXN (1 << 19) 73 - #define HSCTLR_I (1 << 12) 74 - #define HSCTLR_C (1 << 2) 75 - #define HSCTLR_A (1 << 1) 76 - #define HSCTLR_M 1 77 - #define HSCTLR_MASK (HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I | \ 78 - HSCTLR_WXN | HSCTLR_FI | HSCTLR_EE | HSCTLR_TE) 79 - 80 - /* TTBCR and HTCR Registers bits */ 81 - #define TTBCR_EAE (1 << 31) 82 - #define TTBCR_IMP (1 << 30) 83 - #define TTBCR_SH1 (3 << 28) 84 - #define TTBCR_ORGN1 (3 << 26) 85 - #define TTBCR_IRGN1 (3 << 24) 86 - #define TTBCR_EPD1 (1 << 23) 87 - #define TTBCR_A1 (1 << 22) 88 - #define TTBCR_T1SZ (7 << 16) 89 - #define TTBCR_SH0 (3 << 12) 90 - #define TTBCR_ORGN0 (3 << 10) 91 - #define TTBCR_IRGN0 (3 << 8) 92 - #define TTBCR_EPD0 (1 << 7) 93 - #define TTBCR_T0SZ (7 << 0) 94 - #define HTCR_MASK (TTBCR_T0SZ | TTBCR_IRGN0 | TTBCR_ORGN0 | TTBCR_SH0) 95 - 96 - /* Hyp System Trap Register */ 97 - #define HSTR_T(x) (1 << x) 98 - #define HSTR_TTEE (1 << 16) 99 - #define HSTR_TJDBX (1 << 17) 100 - 101 - /* Hyp Coprocessor Trap Register */ 102 - #define HCPTR_TCP(x) (1 << x) 103 - #define HCPTR_TCP_MASK (0x3fff) 104 - #define HCPTR_TASE (1 << 15) 105 - #define HCPTR_TTA (1 << 20) 106 - #define HCPTR_TCPAC (1 << 31) 107 - 108 - /* Hyp Debug Configuration Register bits */ 109 - #define HDCR_TDRA (1 << 11) 110 - #define HDCR_TDOSA (1 << 10) 111 - #define HDCR_TDA (1 << 9) 112 - #define HDCR_TDE (1 << 8) 113 - #define HDCR_HPME (1 << 7) 114 - #define HDCR_TPM (1 << 6) 115 - #define HDCR_TPMCR (1 << 5) 116 - #define HDCR_HPMN_MASK (0x1F) 117 - 118 - /* 119 - * The architecture supports 40-bit IPA as input to the 2nd stage translations 120 - * and PTRS_PER_S2_PGD becomes 1024, because each entry covers 1GB of address 121 - * space. 122 - */ 123 - #define KVM_PHYS_SHIFT (40) 124 - 125 - #define PTRS_PER_S2_PGD (_AC(1, ULL) << (KVM_PHYS_SHIFT - 30)) 126 - 127 - /* Virtualization Translation Control Register (VTCR) bits */ 128 - #define VTCR_SH0 (3 << 12) 129 - #define VTCR_ORGN0 (3 << 10) 130 - #define VTCR_IRGN0 (3 << 8) 131 - #define VTCR_SL0 (3 << 6) 132 - #define VTCR_S (1 << 4) 133 - #define VTCR_T0SZ (0xf) 134 - #define VTCR_MASK (VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0 | VTCR_SL0 | \ 135 - VTCR_S | VTCR_T0SZ) 136 - #define VTCR_HTCR_SH (VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0) 137 - #define VTCR_SL_L2 (0 << 6) /* Starting-level: 2 */ 138 - #define VTCR_SL_L1 (1 << 6) /* Starting-level: 1 */ 139 - #define KVM_VTCR_SL0 VTCR_SL_L1 140 - /* stage-2 input address range defined as 2^(32-T0SZ) */ 141 - #define KVM_T0SZ (32 - KVM_PHYS_SHIFT) 142 - #define KVM_VTCR_T0SZ (KVM_T0SZ & VTCR_T0SZ) 143 - #define KVM_VTCR_S ((KVM_VTCR_T0SZ << 1) & VTCR_S) 144 - 145 - /* Virtualization Translation Table Base Register (VTTBR) bits */ 146 - #if KVM_VTCR_SL0 == VTCR_SL_L2 /* see ARM DDI 0406C: B4-1720 */ 147 - #define VTTBR_X (14 - KVM_T0SZ) 148 - #else 149 - #define VTTBR_X (5 - KVM_T0SZ) 150 - #endif 151 - #define VTTBR_CNP_BIT _AC(1, UL) 152 - #define VTTBR_BADDR_MASK (((_AC(1, ULL) << (40 - VTTBR_X)) - 1) << VTTBR_X) 153 - #define VTTBR_VMID_SHIFT _AC(48, ULL) 154 - #define VTTBR_VMID_MASK(size) (_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT) 155 - 156 - /* Hyp Syndrome Register (HSR) bits */ 157 - #define HSR_EC_SHIFT (26) 158 - #define HSR_EC (_AC(0x3f, UL) << HSR_EC_SHIFT) 159 - #define HSR_IL (_AC(1, UL) << 25) 160 - #define HSR_ISS (HSR_IL - 1) 161 - #define HSR_ISV_SHIFT (24) 162 - #define HSR_ISV (_AC(1, UL) << HSR_ISV_SHIFT) 163 - #define HSR_SRT_SHIFT (16) 164 - #define HSR_SRT_MASK (0xf << HSR_SRT_SHIFT) 165 - #define HSR_CM (1 << 8) 166 - #define HSR_FSC (0x3f) 167 - #define HSR_FSC_TYPE (0x3c) 168 - #define HSR_SSE (1 << 21) 169 - #define HSR_WNR (1 << 6) 170 - #define HSR_CV_SHIFT (24) 171 - #define HSR_CV (_AC(1, UL) << HSR_CV_SHIFT) 172 - #define HSR_COND_SHIFT (20) 173 - #define HSR_COND (_AC(0xf, UL) << HSR_COND_SHIFT) 174 - 175 - #define FSC_FAULT (0x04) 176 - #define FSC_ACCESS (0x08) 177 - #define FSC_PERM (0x0c) 178 - #define FSC_SEA (0x10) 179 - #define FSC_SEA_TTW0 (0x14) 180 - #define FSC_SEA_TTW1 (0x15) 181 - #define FSC_SEA_TTW2 (0x16) 182 - #define FSC_SEA_TTW3 (0x17) 183 - #define FSC_SECC (0x18) 184 - #define FSC_SECC_TTW0 (0x1c) 185 - #define FSC_SECC_TTW1 (0x1d) 186 - #define FSC_SECC_TTW2 (0x1e) 187 - #define FSC_SECC_TTW3 (0x1f) 188 - 189 - /* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */ 190 - #define HPFAR_MASK (~0xf) 191 - 192 - #define HSR_EC_UNKNOWN (0x00) 193 - #define HSR_EC_WFI (0x01) 194 - #define HSR_EC_CP15_32 (0x03) 195 - #define HSR_EC_CP15_64 (0x04) 196 - #define HSR_EC_CP14_MR (0x05) 197 - #define HSR_EC_CP14_LS (0x06) 198 - #define HSR_EC_CP_0_13 (0x07) 199 - #define HSR_EC_CP10_ID (0x08) 200 - #define HSR_EC_JAZELLE (0x09) 201 - #define HSR_EC_BXJ (0x0A) 202 - #define HSR_EC_CP14_64 (0x0C) 203 - #define HSR_EC_SVC_HYP (0x11) 204 - #define HSR_EC_HVC (0x12) 205 - #define HSR_EC_SMC (0x13) 206 - #define HSR_EC_IABT (0x20) 207 - #define HSR_EC_IABT_HYP (0x21) 208 - #define HSR_EC_DABT (0x24) 209 - #define HSR_EC_DABT_HYP (0x25) 210 - #define HSR_EC_MAX (0x3f) 211 - 212 - #define HSR_WFI_IS_WFE (_AC(1, UL) << 0) 213 - 214 - #define HSR_HVC_IMM_MASK ((_AC(1, UL) << 16) - 1) 215 - 216 - #define HSR_DABT_S1PTW (_AC(1, UL) << 7) 217 - #define HSR_DABT_CM (_AC(1, UL) << 8) 218 - 219 - #define kvm_arm_exception_type \ 220 - {0, "RESET" }, \ 221 - {1, "UNDEFINED" }, \ 222 - {2, "SOFTWARE" }, \ 223 - {3, "PREF_ABORT" }, \ 224 - {4, "DATA_ABORT" }, \ 225 - {5, "IRQ" }, \ 226 - {6, "FIQ" }, \ 227 - {7, "HVC" } 228 - 229 - #define HSRECN(x) { HSR_EC_##x, #x } 230 - 231 - #define kvm_arm_exception_class \ 232 - HSRECN(UNKNOWN), HSRECN(WFI), HSRECN(CP15_32), HSRECN(CP15_64), \ 233 - HSRECN(CP14_MR), HSRECN(CP14_LS), HSRECN(CP_0_13), HSRECN(CP10_ID), \ 234 - HSRECN(JAZELLE), HSRECN(BXJ), HSRECN(CP14_64), HSRECN(SVC_HYP), \ 235 - HSRECN(HVC), HSRECN(SMC), HSRECN(IABT), HSRECN(IABT_HYP), \ 236 - HSRECN(DABT), HSRECN(DABT_HYP) 237 - 238 - 239 - #endif /* __ARM_KVM_ARM_H__ */
-77
arch/arm/include/asm/kvm_asm.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_ASM_H__ 8 - #define __ARM_KVM_ASM_H__ 9 - 10 - #include <asm/virt.h> 11 - 12 - #define ARM_EXIT_WITH_ABORT_BIT 31 13 - #define ARM_EXCEPTION_CODE(x) ((x) & ~(1U << ARM_EXIT_WITH_ABORT_BIT)) 14 - #define ARM_EXCEPTION_IS_TRAP(x) \ 15 - (ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_PREF_ABORT || \ 16 - ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_DATA_ABORT || \ 17 - ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_HVC) 18 - #define ARM_ABORT_PENDING(x) !!((x) & (1U << ARM_EXIT_WITH_ABORT_BIT)) 19 - 20 - #define ARM_EXCEPTION_RESET 0 21 - #define ARM_EXCEPTION_UNDEFINED 1 22 - #define ARM_EXCEPTION_SOFTWARE 2 23 - #define ARM_EXCEPTION_PREF_ABORT 3 24 - #define ARM_EXCEPTION_DATA_ABORT 4 25 - #define ARM_EXCEPTION_IRQ 5 26 - #define ARM_EXCEPTION_FIQ 6 27 - #define ARM_EXCEPTION_HVC 7 28 - #define ARM_EXCEPTION_HYP_GONE HVC_STUB_ERR 29 - /* 30 - * The rr_lo_hi macro swaps a pair of registers depending on 31 - * current endianness. It is used in conjunction with ldrd and strd 32 - * instructions that load/store a 64-bit value from/to memory to/from 33 - * a pair of registers which are used with the mrrc and mcrr instructions. 34 - * If used with the ldrd/strd instructions, the a1 parameter is the first 35 - * source/destination register and the a2 parameter is the second 36 - * source/destination register. Note that the ldrd/strd instructions 37 - * already swap the bytes within the words correctly according to the 38 - * endianness setting, but the order of the registers need to be effectively 39 - * swapped when used with the mrrc/mcrr instructions. 40 - */ 41 - #ifdef CONFIG_CPU_ENDIAN_BE8 42 - #define rr_lo_hi(a1, a2) a2, a1 43 - #else 44 - #define rr_lo_hi(a1, a2) a1, a2 45 - #endif 46 - 47 - #define kvm_ksym_ref(kva) (kva) 48 - 49 - #ifndef __ASSEMBLY__ 50 - struct kvm; 51 - struct kvm_vcpu; 52 - 53 - extern char __kvm_hyp_init[]; 54 - extern char __kvm_hyp_init_end[]; 55 - 56 - extern void __kvm_flush_vm_context(void); 57 - extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa); 58 - extern void __kvm_tlb_flush_vmid(struct kvm *kvm); 59 - extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu); 60 - 61 - extern void __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high); 62 - 63 - /* no VHE on 32-bit :( */ 64 - static inline int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) { BUG(); return 0; } 65 - 66 - extern int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu); 67 - 68 - extern void __init_stage2_translation(void); 69 - 70 - extern u64 __vgic_v3_get_ich_vtr_el2(void); 71 - extern u64 __vgic_v3_read_vmcr(void); 72 - extern void __vgic_v3_write_vmcr(u32 vmcr); 73 - extern void __vgic_v3_init_lrs(void); 74 - 75 - #endif 76 - 77 - #endif /* __ARM_KVM_ASM_H__ */
-36
arch/arm/include/asm/kvm_coproc.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 Rusty Russell IBM Corporation 4 - */ 5 - 6 - #ifndef __ARM_KVM_COPROC_H__ 7 - #define __ARM_KVM_COPROC_H__ 8 - #include <linux/kvm_host.h> 9 - 10 - void kvm_reset_coprocs(struct kvm_vcpu *vcpu); 11 - 12 - struct kvm_coproc_target_table { 13 - unsigned target; 14 - const struct coproc_reg *table; 15 - size_t num; 16 - }; 17 - void kvm_register_target_coproc_table(struct kvm_coproc_target_table *table); 18 - 19 - int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run); 20 - int kvm_handle_cp_0_13_access(struct kvm_vcpu *vcpu, struct kvm_run *run); 21 - int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu, struct kvm_run *run); 22 - int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run); 23 - int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run); 24 - int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run); 25 - int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run); 26 - 27 - unsigned long kvm_arm_num_guest_msrs(struct kvm_vcpu *vcpu); 28 - int kvm_arm_copy_msrindices(struct kvm_vcpu *vcpu, u64 __user *uindices); 29 - void kvm_coproc_table_init(void); 30 - 31 - struct kvm_one_reg; 32 - int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); 33 - int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 34 - int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 35 - unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu); 36 - #endif /* __ARM_KVM_COPROC_H__ */
-372
arch/arm/include/asm/kvm_emulate.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_EMULATE_H__ 8 - #define __ARM_KVM_EMULATE_H__ 9 - 10 - #include <linux/kvm_host.h> 11 - #include <asm/kvm_asm.h> 12 - #include <asm/kvm_arm.h> 13 - #include <asm/cputype.h> 14 - 15 - /* arm64 compatibility macros */ 16 - #define PSR_AA32_MODE_FIQ FIQ_MODE 17 - #define PSR_AA32_MODE_SVC SVC_MODE 18 - #define PSR_AA32_MODE_ABT ABT_MODE 19 - #define PSR_AA32_MODE_UND UND_MODE 20 - #define PSR_AA32_T_BIT PSR_T_BIT 21 - #define PSR_AA32_F_BIT PSR_F_BIT 22 - #define PSR_AA32_I_BIT PSR_I_BIT 23 - #define PSR_AA32_A_BIT PSR_A_BIT 24 - #define PSR_AA32_E_BIT PSR_E_BIT 25 - #define PSR_AA32_IT_MASK PSR_IT_MASK 26 - #define PSR_AA32_GE_MASK 0x000f0000 27 - #define PSR_AA32_DIT_BIT 0x00200000 28 - #define PSR_AA32_PAN_BIT 0x00400000 29 - #define PSR_AA32_SSBS_BIT 0x00800000 30 - #define PSR_AA32_Q_BIT PSR_Q_BIT 31 - #define PSR_AA32_V_BIT PSR_V_BIT 32 - #define PSR_AA32_C_BIT PSR_C_BIT 33 - #define PSR_AA32_Z_BIT PSR_Z_BIT 34 - #define PSR_AA32_N_BIT PSR_N_BIT 35 - 36 - unsigned long *vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num); 37 - 38 - static inline unsigned long *vcpu_reg32(struct kvm_vcpu *vcpu, u8 reg_num) 39 - { 40 - return vcpu_reg(vcpu, reg_num); 41 - } 42 - 43 - unsigned long *__vcpu_spsr(struct kvm_vcpu *vcpu); 44 - 45 - static inline unsigned long vpcu_read_spsr(struct kvm_vcpu *vcpu) 46 - { 47 - return *__vcpu_spsr(vcpu); 48 - } 49 - 50 - static inline void vcpu_write_spsr(struct kvm_vcpu *vcpu, unsigned long v) 51 - { 52 - *__vcpu_spsr(vcpu) = v; 53 - } 54 - 55 - static inline unsigned long host_spsr_to_spsr32(unsigned long spsr) 56 - { 57 - return spsr; 58 - } 59 - 60 - static inline unsigned long vcpu_get_reg(struct kvm_vcpu *vcpu, 61 - u8 reg_num) 62 - { 63 - return *vcpu_reg(vcpu, reg_num); 64 - } 65 - 66 - static inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num, 67 - unsigned long val) 68 - { 69 - *vcpu_reg(vcpu, reg_num) = val; 70 - } 71 - 72 - bool kvm_condition_valid32(const struct kvm_vcpu *vcpu); 73 - void kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr); 74 - void kvm_inject_undef32(struct kvm_vcpu *vcpu); 75 - void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr); 76 - void kvm_inject_pabt32(struct kvm_vcpu *vcpu, unsigned long addr); 77 - void kvm_inject_vabt(struct kvm_vcpu *vcpu); 78 - 79 - static inline void kvm_inject_undefined(struct kvm_vcpu *vcpu) 80 - { 81 - kvm_inject_undef32(vcpu); 82 - } 83 - 84 - static inline void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr) 85 - { 86 - kvm_inject_dabt32(vcpu, addr); 87 - } 88 - 89 - static inline void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr) 90 - { 91 - kvm_inject_pabt32(vcpu, addr); 92 - } 93 - 94 - static inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu) 95 - { 96 - return kvm_condition_valid32(vcpu); 97 - } 98 - 99 - static inline void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr) 100 - { 101 - kvm_skip_instr32(vcpu, is_wide_instr); 102 - } 103 - 104 - static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) 105 - { 106 - vcpu->arch.hcr = HCR_GUEST_MASK; 107 - } 108 - 109 - static inline unsigned long *vcpu_hcr(const struct kvm_vcpu *vcpu) 110 - { 111 - return (unsigned long *)&vcpu->arch.hcr; 112 - } 113 - 114 - static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu) 115 - { 116 - vcpu->arch.hcr &= ~HCR_TWE; 117 - } 118 - 119 - static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu) 120 - { 121 - vcpu->arch.hcr |= HCR_TWE; 122 - } 123 - 124 - static inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu) 125 - { 126 - return true; 127 - } 128 - 129 - static inline unsigned long *vcpu_pc(struct kvm_vcpu *vcpu) 130 - { 131 - return &vcpu->arch.ctxt.gp_regs.usr_regs.ARM_pc; 132 - } 133 - 134 - static inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu) 135 - { 136 - return (unsigned long *)&vcpu->arch.ctxt.gp_regs.usr_regs.ARM_cpsr; 137 - } 138 - 139 - static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu) 140 - { 141 - *vcpu_cpsr(vcpu) |= PSR_T_BIT; 142 - } 143 - 144 - static inline bool mode_has_spsr(struct kvm_vcpu *vcpu) 145 - { 146 - unsigned long cpsr_mode = vcpu->arch.ctxt.gp_regs.usr_regs.ARM_cpsr & MODE_MASK; 147 - return (cpsr_mode > USR_MODE && cpsr_mode < SYSTEM_MODE); 148 - } 149 - 150 - static inline bool vcpu_mode_priv(struct kvm_vcpu *vcpu) 151 - { 152 - unsigned long cpsr_mode = vcpu->arch.ctxt.gp_regs.usr_regs.ARM_cpsr & MODE_MASK; 153 - return cpsr_mode > USR_MODE; 154 - } 155 - 156 - static inline u32 kvm_vcpu_get_hsr(const struct kvm_vcpu *vcpu) 157 - { 158 - return vcpu->arch.fault.hsr; 159 - } 160 - 161 - static inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu) 162 - { 163 - u32 hsr = kvm_vcpu_get_hsr(vcpu); 164 - 165 - if (hsr & HSR_CV) 166 - return (hsr & HSR_COND) >> HSR_COND_SHIFT; 167 - 168 - return -1; 169 - } 170 - 171 - static inline unsigned long kvm_vcpu_get_hfar(struct kvm_vcpu *vcpu) 172 - { 173 - return vcpu->arch.fault.hxfar; 174 - } 175 - 176 - static inline phys_addr_t kvm_vcpu_get_fault_ipa(struct kvm_vcpu *vcpu) 177 - { 178 - return ((phys_addr_t)vcpu->arch.fault.hpfar & HPFAR_MASK) << 8; 179 - } 180 - 181 - static inline bool kvm_vcpu_dabt_isvalid(struct kvm_vcpu *vcpu) 182 - { 183 - return kvm_vcpu_get_hsr(vcpu) & HSR_ISV; 184 - } 185 - 186 - static inline unsigned long kvm_vcpu_dabt_iss_nisv_sanitized(const struct kvm_vcpu *vcpu) 187 - { 188 - return kvm_vcpu_get_hsr(vcpu) & (HSR_CM | HSR_WNR | HSR_FSC); 189 - } 190 - 191 - static inline bool kvm_vcpu_dabt_iswrite(struct kvm_vcpu *vcpu) 192 - { 193 - return kvm_vcpu_get_hsr(vcpu) & HSR_WNR; 194 - } 195 - 196 - static inline bool kvm_vcpu_dabt_issext(struct kvm_vcpu *vcpu) 197 - { 198 - return kvm_vcpu_get_hsr(vcpu) & HSR_SSE; 199 - } 200 - 201 - static inline bool kvm_vcpu_dabt_issf(const struct kvm_vcpu *vcpu) 202 - { 203 - return false; 204 - } 205 - 206 - static inline int kvm_vcpu_dabt_get_rd(struct kvm_vcpu *vcpu) 207 - { 208 - return (kvm_vcpu_get_hsr(vcpu) & HSR_SRT_MASK) >> HSR_SRT_SHIFT; 209 - } 210 - 211 - static inline bool kvm_vcpu_dabt_iss1tw(struct kvm_vcpu *vcpu) 212 - { 213 - return kvm_vcpu_get_hsr(vcpu) & HSR_DABT_S1PTW; 214 - } 215 - 216 - static inline bool kvm_vcpu_dabt_is_cm(struct kvm_vcpu *vcpu) 217 - { 218 - return !!(kvm_vcpu_get_hsr(vcpu) & HSR_DABT_CM); 219 - } 220 - 221 - /* Get Access Size from a data abort */ 222 - static inline unsigned int kvm_vcpu_dabt_get_as(struct kvm_vcpu *vcpu) 223 - { 224 - switch ((kvm_vcpu_get_hsr(vcpu) >> 22) & 0x3) { 225 - case 0: 226 - return 1; 227 - case 1: 228 - return 2; 229 - case 2: 230 - return 4; 231 - default: 232 - kvm_err("Hardware is weird: SAS 0b11 is reserved\n"); 233 - return 4; 234 - } 235 - } 236 - 237 - /* This one is not specific to Data Abort */ 238 - static inline bool kvm_vcpu_trap_il_is32bit(struct kvm_vcpu *vcpu) 239 - { 240 - return kvm_vcpu_get_hsr(vcpu) & HSR_IL; 241 - } 242 - 243 - static inline u8 kvm_vcpu_trap_get_class(struct kvm_vcpu *vcpu) 244 - { 245 - return kvm_vcpu_get_hsr(vcpu) >> HSR_EC_SHIFT; 246 - } 247 - 248 - static inline bool kvm_vcpu_trap_is_iabt(struct kvm_vcpu *vcpu) 249 - { 250 - return kvm_vcpu_trap_get_class(vcpu) == HSR_EC_IABT; 251 - } 252 - 253 - static inline u8 kvm_vcpu_trap_get_fault(struct kvm_vcpu *vcpu) 254 - { 255 - return kvm_vcpu_get_hsr(vcpu) & HSR_FSC; 256 - } 257 - 258 - static inline u8 kvm_vcpu_trap_get_fault_type(struct kvm_vcpu *vcpu) 259 - { 260 - return kvm_vcpu_get_hsr(vcpu) & HSR_FSC_TYPE; 261 - } 262 - 263 - static inline bool kvm_vcpu_dabt_isextabt(struct kvm_vcpu *vcpu) 264 - { 265 - switch (kvm_vcpu_trap_get_fault(vcpu)) { 266 - case FSC_SEA: 267 - case FSC_SEA_TTW0: 268 - case FSC_SEA_TTW1: 269 - case FSC_SEA_TTW2: 270 - case FSC_SEA_TTW3: 271 - case FSC_SECC: 272 - case FSC_SECC_TTW0: 273 - case FSC_SECC_TTW1: 274 - case FSC_SECC_TTW2: 275 - case FSC_SECC_TTW3: 276 - return true; 277 - default: 278 - return false; 279 - } 280 - } 281 - 282 - static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu) 283 - { 284 - if (kvm_vcpu_trap_is_iabt(vcpu)) 285 - return false; 286 - 287 - return kvm_vcpu_dabt_iswrite(vcpu); 288 - } 289 - 290 - static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu) 291 - { 292 - return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK; 293 - } 294 - 295 - static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu) 296 - { 297 - return vcpu_cp15(vcpu, c0_MPIDR) & MPIDR_HWID_BITMASK; 298 - } 299 - 300 - static inline bool kvm_arm_get_vcpu_workaround_2_flag(struct kvm_vcpu *vcpu) 301 - { 302 - return false; 303 - } 304 - 305 - static inline void kvm_arm_set_vcpu_workaround_2_flag(struct kvm_vcpu *vcpu, 306 - bool flag) 307 - { 308 - } 309 - 310 - static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu) 311 - { 312 - *vcpu_cpsr(vcpu) |= PSR_E_BIT; 313 - } 314 - 315 - static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) 316 - { 317 - return !!(*vcpu_cpsr(vcpu) & PSR_E_BIT); 318 - } 319 - 320 - static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu, 321 - unsigned long data, 322 - unsigned int len) 323 - { 324 - if (kvm_vcpu_is_be(vcpu)) { 325 - switch (len) { 326 - case 1: 327 - return data & 0xff; 328 - case 2: 329 - return be16_to_cpu(data & 0xffff); 330 - default: 331 - return be32_to_cpu(data); 332 - } 333 - } else { 334 - switch (len) { 335 - case 1: 336 - return data & 0xff; 337 - case 2: 338 - return le16_to_cpu(data & 0xffff); 339 - default: 340 - return le32_to_cpu(data); 341 - } 342 - } 343 - } 344 - 345 - static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu, 346 - unsigned long data, 347 - unsigned int len) 348 - { 349 - if (kvm_vcpu_is_be(vcpu)) { 350 - switch (len) { 351 - case 1: 352 - return data & 0xff; 353 - case 2: 354 - return cpu_to_be16(data & 0xffff); 355 - default: 356 - return cpu_to_be32(data); 357 - } 358 - } else { 359 - switch (len) { 360 - case 1: 361 - return data & 0xff; 362 - case 2: 363 - return cpu_to_le16(data & 0xffff); 364 - default: 365 - return cpu_to_le32(data); 366 - } 367 - } 368 - } 369 - 370 - static inline void vcpu_ptrauth_setup_lazy(struct kvm_vcpu *vcpu) {} 371 - 372 - #endif /* __ARM_KVM_EMULATE_H__ */
-456
arch/arm/include/asm/kvm_host.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_HOST_H__ 8 - #define __ARM_KVM_HOST_H__ 9 - 10 - #include <linux/arm-smccc.h> 11 - #include <linux/errno.h> 12 - #include <linux/types.h> 13 - #include <linux/kvm_types.h> 14 - #include <asm/cputype.h> 15 - #include <asm/kvm.h> 16 - #include <asm/kvm_asm.h> 17 - #include <asm/fpstate.h> 18 - #include <kvm/arm_arch_timer.h> 19 - 20 - #define __KVM_HAVE_ARCH_INTC_INITIALIZED 21 - 22 - #define KVM_USER_MEM_SLOTS 32 23 - #define KVM_HAVE_ONE_REG 24 - #define KVM_HALT_POLL_NS_DEFAULT 500000 25 - 26 - #define KVM_VCPU_MAX_FEATURES 2 27 - 28 - #include <kvm/arm_vgic.h> 29 - 30 - 31 - #ifdef CONFIG_ARM_GIC_V3 32 - #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS 33 - #else 34 - #define KVM_MAX_VCPUS VGIC_V2_MAX_CPUS 35 - #endif 36 - 37 - #define KVM_REQ_SLEEP \ 38 - KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) 39 - #define KVM_REQ_IRQ_PENDING KVM_ARCH_REQ(1) 40 - #define KVM_REQ_VCPU_RESET KVM_ARCH_REQ(2) 41 - #define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3) 42 - 43 - DECLARE_STATIC_KEY_FALSE(userspace_irqchip_in_use); 44 - 45 - static inline int kvm_arm_init_sve(void) { return 0; } 46 - 47 - u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode); 48 - int __attribute_const__ kvm_target_cpu(void); 49 - int kvm_reset_vcpu(struct kvm_vcpu *vcpu); 50 - void kvm_reset_coprocs(struct kvm_vcpu *vcpu); 51 - 52 - struct kvm_vmid { 53 - /* The VMID generation used for the virt. memory system */ 54 - u64 vmid_gen; 55 - u32 vmid; 56 - }; 57 - 58 - struct kvm_arch { 59 - /* The last vcpu id that ran on each physical CPU */ 60 - int __percpu *last_vcpu_ran; 61 - 62 - /* 63 - * Anything that is not used directly from assembly code goes 64 - * here. 65 - */ 66 - 67 - /* The VMID generation used for the virt. memory system */ 68 - struct kvm_vmid vmid; 69 - 70 - /* Stage-2 page table */ 71 - pgd_t *pgd; 72 - phys_addr_t pgd_phys; 73 - 74 - /* Interrupt controller */ 75 - struct vgic_dist vgic; 76 - int max_vcpus; 77 - 78 - /* Mandated version of PSCI */ 79 - u32 psci_version; 80 - 81 - /* 82 - * If we encounter a data abort without valid instruction syndrome 83 - * information, report this to user space. User space can (and 84 - * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is 85 - * supported. 86 - */ 87 - bool return_nisv_io_abort_to_user; 88 - }; 89 - 90 - #define KVM_NR_MEM_OBJS 40 91 - 92 - /* 93 - * We don't want allocation failures within the mmu code, so we preallocate 94 - * enough memory for a single page fault in a cache. 95 - */ 96 - struct kvm_mmu_memory_cache { 97 - int nobjs; 98 - void *objects[KVM_NR_MEM_OBJS]; 99 - }; 100 - 101 - struct kvm_vcpu_fault_info { 102 - u32 hsr; /* Hyp Syndrome Register */ 103 - u32 hxfar; /* Hyp Data/Inst. Fault Address Register */ 104 - u32 hpfar; /* Hyp IPA Fault Address Register */ 105 - }; 106 - 107 - /* 108 - * 0 is reserved as an invalid value. 109 - * Order should be kept in sync with the save/restore code. 110 - */ 111 - enum vcpu_sysreg { 112 - __INVALID_SYSREG__, 113 - c0_MPIDR, /* MultiProcessor ID Register */ 114 - c0_CSSELR, /* Cache Size Selection Register */ 115 - c1_SCTLR, /* System Control Register */ 116 - c1_ACTLR, /* Auxiliary Control Register */ 117 - c1_CPACR, /* Coprocessor Access Control */ 118 - c2_TTBR0, /* Translation Table Base Register 0 */ 119 - c2_TTBR0_high, /* TTBR0 top 32 bits */ 120 - c2_TTBR1, /* Translation Table Base Register 1 */ 121 - c2_TTBR1_high, /* TTBR1 top 32 bits */ 122 - c2_TTBCR, /* Translation Table Base Control R. */ 123 - c3_DACR, /* Domain Access Control Register */ 124 - c5_DFSR, /* Data Fault Status Register */ 125 - c5_IFSR, /* Instruction Fault Status Register */ 126 - c5_ADFSR, /* Auxilary Data Fault Status R */ 127 - c5_AIFSR, /* Auxilary Instrunction Fault Status R */ 128 - c6_DFAR, /* Data Fault Address Register */ 129 - c6_IFAR, /* Instruction Fault Address Register */ 130 - c7_PAR, /* Physical Address Register */ 131 - c7_PAR_high, /* PAR top 32 bits */ 132 - c9_L2CTLR, /* Cortex A15/A7 L2 Control Register */ 133 - c10_PRRR, /* Primary Region Remap Register */ 134 - c10_NMRR, /* Normal Memory Remap Register */ 135 - c12_VBAR, /* Vector Base Address Register */ 136 - c13_CID, /* Context ID Register */ 137 - c13_TID_URW, /* Thread ID, User R/W */ 138 - c13_TID_URO, /* Thread ID, User R/O */ 139 - c13_TID_PRIV, /* Thread ID, Privileged */ 140 - c14_CNTKCTL, /* Timer Control Register (PL1) */ 141 - c10_AMAIR0, /* Auxilary Memory Attribute Indirection Reg0 */ 142 - c10_AMAIR1, /* Auxilary Memory Attribute Indirection Reg1 */ 143 - NR_CP15_REGS /* Number of regs (incl. invalid) */ 144 - }; 145 - 146 - struct kvm_cpu_context { 147 - struct kvm_regs gp_regs; 148 - struct vfp_hard_struct vfp; 149 - u32 cp15[NR_CP15_REGS]; 150 - }; 151 - 152 - struct kvm_host_data { 153 - struct kvm_cpu_context host_ctxt; 154 - }; 155 - 156 - typedef struct kvm_host_data kvm_host_data_t; 157 - 158 - static inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt) 159 - { 160 - /* The host's MPIDR is immutable, so let's set it up at boot time */ 161 - cpu_ctxt->cp15[c0_MPIDR] = read_cpuid_mpidr(); 162 - } 163 - 164 - struct vcpu_reset_state { 165 - unsigned long pc; 166 - unsigned long r0; 167 - bool be; 168 - bool reset; 169 - }; 170 - 171 - struct kvm_vcpu_arch { 172 - struct kvm_cpu_context ctxt; 173 - 174 - int target; /* Processor target */ 175 - DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES); 176 - 177 - /* The CPU type we expose to the VM */ 178 - u32 midr; 179 - 180 - /* HYP trapping configuration */ 181 - u32 hcr; 182 - 183 - /* Exception Information */ 184 - struct kvm_vcpu_fault_info fault; 185 - 186 - /* Host FP context */ 187 - struct kvm_cpu_context *host_cpu_context; 188 - 189 - /* VGIC state */ 190 - struct vgic_cpu vgic_cpu; 191 - struct arch_timer_cpu timer_cpu; 192 - 193 - /* 194 - * Anything that is not used directly from assembly code goes 195 - * here. 196 - */ 197 - 198 - /* vcpu power-off state */ 199 - bool power_off; 200 - 201 - /* Don't run the guest (internal implementation need) */ 202 - bool pause; 203 - 204 - /* Cache some mmu pages needed inside spinlock regions */ 205 - struct kvm_mmu_memory_cache mmu_page_cache; 206 - 207 - struct vcpu_reset_state reset_state; 208 - 209 - /* Detect first run of a vcpu */ 210 - bool has_run_once; 211 - }; 212 - 213 - struct kvm_vm_stat { 214 - ulong remote_tlb_flush; 215 - }; 216 - 217 - struct kvm_vcpu_stat { 218 - u64 halt_successful_poll; 219 - u64 halt_attempted_poll; 220 - u64 halt_poll_invalid; 221 - u64 halt_wakeup; 222 - u64 hvc_exit_stat; 223 - u64 wfe_exit_stat; 224 - u64 wfi_exit_stat; 225 - u64 mmio_exit_user; 226 - u64 mmio_exit_kernel; 227 - u64 exits; 228 - }; 229 - 230 - #define vcpu_cp15(v,r) (v)->arch.ctxt.cp15[r] 231 - 232 - int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init); 233 - unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); 234 - int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); 235 - int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 236 - int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 237 - 238 - unsigned long __kvm_call_hyp(void *hypfn, ...); 239 - 240 - /* 241 - * The has_vhe() part doesn't get emitted, but is used for type-checking. 242 - */ 243 - #define kvm_call_hyp(f, ...) \ 244 - do { \ 245 - if (has_vhe()) { \ 246 - f(__VA_ARGS__); \ 247 - } else { \ 248 - __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \ 249 - } \ 250 - } while(0) 251 - 252 - #define kvm_call_hyp_ret(f, ...) \ 253 - ({ \ 254 - typeof(f(__VA_ARGS__)) ret; \ 255 - \ 256 - if (has_vhe()) { \ 257 - ret = f(__VA_ARGS__); \ 258 - } else { \ 259 - ret = __kvm_call_hyp(kvm_ksym_ref(f), \ 260 - ##__VA_ARGS__); \ 261 - } \ 262 - \ 263 - ret; \ 264 - }) 265 - 266 - void force_vm_exit(const cpumask_t *mask); 267 - int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, 268 - struct kvm_vcpu_events *events); 269 - 270 - int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, 271 - struct kvm_vcpu_events *events); 272 - 273 - #define KVM_ARCH_WANT_MMU_NOTIFIER 274 - int kvm_unmap_hva_range(struct kvm *kvm, 275 - unsigned long start, unsigned long end); 276 - int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 277 - 278 - unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); 279 - int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); 280 - int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); 281 - int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); 282 - 283 - void kvm_arm_halt_guest(struct kvm *kvm); 284 - void kvm_arm_resume_guest(struct kvm *kvm); 285 - 286 - int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); 287 - unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu); 288 - int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 289 - int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 290 - 291 - int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, 292 - int exception_index); 293 - 294 - static inline void handle_exit_early(struct kvm_vcpu *vcpu, struct kvm_run *run, 295 - int exception_index) {} 296 - 297 - /* MMIO helpers */ 298 - void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data); 299 - unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len); 300 - 301 - int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run); 302 - int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, 303 - phys_addr_t fault_ipa); 304 - 305 - static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr, 306 - unsigned long hyp_stack_ptr, 307 - unsigned long vector_ptr) 308 - { 309 - /* 310 - * Call initialization code, and switch to the full blown HYP 311 - * code. The init code doesn't need to preserve these 312 - * registers as r0-r3 are already callee saved according to 313 - * the AAPCS. 314 - * Note that we slightly misuse the prototype by casting the 315 - * stack pointer to a void *. 316 - 317 - * The PGDs are always passed as the third argument, in order 318 - * to be passed into r2-r3 to the init code (yes, this is 319 - * compliant with the PCS!). 320 - */ 321 - 322 - __kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr); 323 - } 324 - 325 - static inline void __cpu_init_stage2(void) 326 - { 327 - kvm_call_hyp(__init_stage2_translation); 328 - } 329 - 330 - static inline int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext) 331 - { 332 - return 0; 333 - } 334 - 335 - int kvm_perf_init(void); 336 - int kvm_perf_teardown(void); 337 - 338 - static inline long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu) 339 - { 340 - return SMCCC_RET_NOT_SUPPORTED; 341 - } 342 - 343 - static inline gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu) 344 - { 345 - return GPA_INVALID; 346 - } 347 - 348 - static inline void kvm_update_stolen_time(struct kvm_vcpu *vcpu) 349 - { 350 - } 351 - 352 - static inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch) 353 - { 354 - } 355 - 356 - static inline bool kvm_arm_is_pvtime_enabled(struct kvm_vcpu_arch *vcpu_arch) 357 - { 358 - return false; 359 - } 360 - 361 - void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot); 362 - 363 - struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr); 364 - 365 - static inline bool kvm_arch_requires_vhe(void) { return false; } 366 - static inline void kvm_arch_hardware_unsetup(void) {} 367 - static inline void kvm_arch_sync_events(struct kvm *kvm) {} 368 - static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} 369 - static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} 370 - static inline void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu) {} 371 - 372 - static inline void kvm_arm_init_debug(void) {} 373 - static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {} 374 - static inline void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) {} 375 - static inline void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) {} 376 - 377 - int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, 378 - struct kvm_device_attr *attr); 379 - int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu, 380 - struct kvm_device_attr *attr); 381 - int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, 382 - struct kvm_device_attr *attr); 383 - 384 - /* 385 - * VFP/NEON switching is all done by the hyp switch code, so no need to 386 - * coordinate with host context handling for this state: 387 - */ 388 - static inline void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu) {} 389 - static inline void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu) {} 390 - static inline void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) {} 391 - 392 - static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {} 393 - static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {} 394 - 395 - #define KVM_BP_HARDEN_UNKNOWN -1 396 - #define KVM_BP_HARDEN_WA_NEEDED 0 397 - #define KVM_BP_HARDEN_NOT_REQUIRED 1 398 - 399 - static inline int kvm_arm_harden_branch_predictor(void) 400 - { 401 - switch(read_cpuid_part()) { 402 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 403 - case ARM_CPU_PART_BRAHMA_B15: 404 - case ARM_CPU_PART_CORTEX_A12: 405 - case ARM_CPU_PART_CORTEX_A15: 406 - case ARM_CPU_PART_CORTEX_A17: 407 - return KVM_BP_HARDEN_WA_NEEDED; 408 - #endif 409 - case ARM_CPU_PART_CORTEX_A7: 410 - return KVM_BP_HARDEN_NOT_REQUIRED; 411 - default: 412 - return KVM_BP_HARDEN_UNKNOWN; 413 - } 414 - } 415 - 416 - #define KVM_SSBD_UNKNOWN -1 417 - #define KVM_SSBD_FORCE_DISABLE 0 418 - #define KVM_SSBD_KERNEL 1 419 - #define KVM_SSBD_FORCE_ENABLE 2 420 - #define KVM_SSBD_MITIGATED 3 421 - 422 - static inline int kvm_arm_have_ssbd(void) 423 - { 424 - /* No way to detect it yet, pretend it is not there. */ 425 - return KVM_SSBD_UNKNOWN; 426 - } 427 - 428 - static inline void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) {} 429 - static inline void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) {} 430 - 431 - #define __KVM_HAVE_ARCH_VM_ALLOC 432 - struct kvm *kvm_arch_alloc_vm(void); 433 - void kvm_arch_free_vm(struct kvm *kvm); 434 - 435 - static inline int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type) 436 - { 437 - /* 438 - * On 32bit ARM, VMs get a static 40bit IPA stage2 setup, 439 - * so any non-zero value used as type is illegal. 440 - */ 441 - if (type) 442 - return -EINVAL; 443 - return 0; 444 - } 445 - 446 - static inline int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature) 447 - { 448 - return -EINVAL; 449 - } 450 - 451 - static inline bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu) 452 - { 453 - return true; 454 - } 455 - 456 - #endif /* __ARM_KVM_HOST_H__ */
-127
arch/arm/include/asm/kvm_hyp.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2015 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_HYP_H__ 8 - #define __ARM_KVM_HYP_H__ 9 - 10 - #include <linux/compiler.h> 11 - #include <linux/kvm_host.h> 12 - #include <asm/cp15.h> 13 - #include <asm/kvm_arm.h> 14 - #include <asm/vfp.h> 15 - 16 - #define __hyp_text __section(.hyp.text) notrace 17 - 18 - #define __ACCESS_VFP(CRn) \ 19 - "mrc", "mcr", __stringify(p10, 7, %0, CRn, cr0, 0), u32 20 - 21 - #define write_special(v, r) \ 22 - asm volatile("msr " __stringify(r) ", %0" : : "r" (v)) 23 - #define read_special(r) ({ \ 24 - u32 __val; \ 25 - asm volatile("mrs %0, " __stringify(r) : "=r" (__val)); \ 26 - __val; \ 27 - }) 28 - 29 - #define TTBR0 __ACCESS_CP15_64(0, c2) 30 - #define TTBR1 __ACCESS_CP15_64(1, c2) 31 - #define VTTBR __ACCESS_CP15_64(6, c2) 32 - #define PAR __ACCESS_CP15_64(0, c7) 33 - #define CNTP_CVAL __ACCESS_CP15_64(2, c14) 34 - #define CNTV_CVAL __ACCESS_CP15_64(3, c14) 35 - #define CNTVOFF __ACCESS_CP15_64(4, c14) 36 - 37 - #define MIDR __ACCESS_CP15(c0, 0, c0, 0) 38 - #define CSSELR __ACCESS_CP15(c0, 2, c0, 0) 39 - #define VPIDR __ACCESS_CP15(c0, 4, c0, 0) 40 - #define VMPIDR __ACCESS_CP15(c0, 4, c0, 5) 41 - #define SCTLR __ACCESS_CP15(c1, 0, c0, 0) 42 - #define CPACR __ACCESS_CP15(c1, 0, c0, 2) 43 - #define HCR __ACCESS_CP15(c1, 4, c1, 0) 44 - #define HDCR __ACCESS_CP15(c1, 4, c1, 1) 45 - #define HCPTR __ACCESS_CP15(c1, 4, c1, 2) 46 - #define HSTR __ACCESS_CP15(c1, 4, c1, 3) 47 - #define TTBCR __ACCESS_CP15(c2, 0, c0, 2) 48 - #define HTCR __ACCESS_CP15(c2, 4, c0, 2) 49 - #define VTCR __ACCESS_CP15(c2, 4, c1, 2) 50 - #define DACR __ACCESS_CP15(c3, 0, c0, 0) 51 - #define DFSR __ACCESS_CP15(c5, 0, c0, 0) 52 - #define IFSR __ACCESS_CP15(c5, 0, c0, 1) 53 - #define ADFSR __ACCESS_CP15(c5, 0, c1, 0) 54 - #define AIFSR __ACCESS_CP15(c5, 0, c1, 1) 55 - #define HSR __ACCESS_CP15(c5, 4, c2, 0) 56 - #define DFAR __ACCESS_CP15(c6, 0, c0, 0) 57 - #define IFAR __ACCESS_CP15(c6, 0, c0, 2) 58 - #define HDFAR __ACCESS_CP15(c6, 4, c0, 0) 59 - #define HIFAR __ACCESS_CP15(c6, 4, c0, 2) 60 - #define HPFAR __ACCESS_CP15(c6, 4, c0, 4) 61 - #define ICIALLUIS __ACCESS_CP15(c7, 0, c1, 0) 62 - #define BPIALLIS __ACCESS_CP15(c7, 0, c1, 6) 63 - #define ICIMVAU __ACCESS_CP15(c7, 0, c5, 1) 64 - #define ATS1CPR __ACCESS_CP15(c7, 0, c8, 0) 65 - #define TLBIALLIS __ACCESS_CP15(c8, 0, c3, 0) 66 - #define TLBIALL __ACCESS_CP15(c8, 0, c7, 0) 67 - #define TLBIALLNSNHIS __ACCESS_CP15(c8, 4, c3, 4) 68 - #define PRRR __ACCESS_CP15(c10, 0, c2, 0) 69 - #define NMRR __ACCESS_CP15(c10, 0, c2, 1) 70 - #define AMAIR0 __ACCESS_CP15(c10, 0, c3, 0) 71 - #define AMAIR1 __ACCESS_CP15(c10, 0, c3, 1) 72 - #define VBAR __ACCESS_CP15(c12, 0, c0, 0) 73 - #define CID __ACCESS_CP15(c13, 0, c0, 1) 74 - #define TID_URW __ACCESS_CP15(c13, 0, c0, 2) 75 - #define TID_URO __ACCESS_CP15(c13, 0, c0, 3) 76 - #define TID_PRIV __ACCESS_CP15(c13, 0, c0, 4) 77 - #define HTPIDR __ACCESS_CP15(c13, 4, c0, 2) 78 - #define CNTKCTL __ACCESS_CP15(c14, 0, c1, 0) 79 - #define CNTP_CTL __ACCESS_CP15(c14, 0, c2, 1) 80 - #define CNTV_CTL __ACCESS_CP15(c14, 0, c3, 1) 81 - #define CNTHCTL __ACCESS_CP15(c14, 4, c1, 0) 82 - 83 - #define VFP_FPEXC __ACCESS_VFP(FPEXC) 84 - 85 - /* AArch64 compatibility macros, only for the timer so far */ 86 - #define read_sysreg_el0(r) read_sysreg(r##_EL0) 87 - #define write_sysreg_el0(v, r) write_sysreg(v, r##_EL0) 88 - 89 - #define SYS_CNTP_CTL_EL0 CNTP_CTL 90 - #define SYS_CNTP_CVAL_EL0 CNTP_CVAL 91 - #define SYS_CNTV_CTL_EL0 CNTV_CTL 92 - #define SYS_CNTV_CVAL_EL0 CNTV_CVAL 93 - 94 - #define cntvoff_el2 CNTVOFF 95 - #define cnthctl_el2 CNTHCTL 96 - 97 - void __timer_enable_traps(struct kvm_vcpu *vcpu); 98 - void __timer_disable_traps(struct kvm_vcpu *vcpu); 99 - 100 - void __vgic_v2_save_state(struct kvm_vcpu *vcpu); 101 - void __vgic_v2_restore_state(struct kvm_vcpu *vcpu); 102 - 103 - void __sysreg_save_state(struct kvm_cpu_context *ctxt); 104 - void __sysreg_restore_state(struct kvm_cpu_context *ctxt); 105 - 106 - void __vgic_v3_save_state(struct kvm_vcpu *vcpu); 107 - void __vgic_v3_restore_state(struct kvm_vcpu *vcpu); 108 - void __vgic_v3_activate_traps(struct kvm_vcpu *vcpu); 109 - void __vgic_v3_deactivate_traps(struct kvm_vcpu *vcpu); 110 - void __vgic_v3_save_aprs(struct kvm_vcpu *vcpu); 111 - void __vgic_v3_restore_aprs(struct kvm_vcpu *vcpu); 112 - 113 - asmlinkage void __vfp_save_state(struct vfp_hard_struct *vfp); 114 - asmlinkage void __vfp_restore_state(struct vfp_hard_struct *vfp); 115 - static inline bool __vfp_enabled(void) 116 - { 117 - return !(read_sysreg(HCPTR) & (HCPTR_TCP(11) | HCPTR_TCP(10))); 118 - } 119 - 120 - void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt); 121 - void __hyp_text __banked_restore_state(struct kvm_cpu_context *ctxt); 122 - 123 - asmlinkage int __guest_enter(struct kvm_vcpu *vcpu, 124 - struct kvm_cpu_context *host); 125 - asmlinkage int __hyp_do_panic(const char *, int, u32); 126 - 127 - #endif /* __ARM_KVM_HYP_H__ */
-435
arch/arm/include/asm/kvm_mmu.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_MMU_H__ 8 - #define __ARM_KVM_MMU_H__ 9 - 10 - #include <asm/memory.h> 11 - #include <asm/page.h> 12 - 13 - /* 14 - * We directly use the kernel VA for the HYP, as we can directly share 15 - * the mapping (HTTBR "covers" TTBR1). 16 - */ 17 - #define kern_hyp_va(kva) (kva) 18 - 19 - /* Contrary to arm64, there is no need to generate a PC-relative address */ 20 - #define hyp_symbol_addr(s) \ 21 - ({ \ 22 - typeof(s) *addr = &(s); \ 23 - addr; \ 24 - }) 25 - 26 - #ifndef __ASSEMBLY__ 27 - 28 - #include <linux/highmem.h> 29 - #include <asm/cacheflush.h> 30 - #include <asm/cputype.h> 31 - #include <asm/kvm_arm.h> 32 - #include <asm/kvm_hyp.h> 33 - #include <asm/pgalloc.h> 34 - #include <asm/stage2_pgtable.h> 35 - 36 - /* Ensure compatibility with arm64 */ 37 - #define VA_BITS 32 38 - 39 - #define kvm_phys_shift(kvm) KVM_PHYS_SHIFT 40 - #define kvm_phys_size(kvm) (1ULL << kvm_phys_shift(kvm)) 41 - #define kvm_phys_mask(kvm) (kvm_phys_size(kvm) - 1ULL) 42 - #define kvm_vttbr_baddr_mask(kvm) VTTBR_BADDR_MASK 43 - 44 - #define stage2_pgd_size(kvm) (PTRS_PER_S2_PGD * sizeof(pgd_t)) 45 - 46 - int create_hyp_mappings(void *from, void *to, pgprot_t prot); 47 - int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size, 48 - void __iomem **kaddr, 49 - void __iomem **haddr); 50 - int create_hyp_exec_mappings(phys_addr_t phys_addr, size_t size, 51 - void **haddr); 52 - void free_hyp_pgds(void); 53 - 54 - void stage2_unmap_vm(struct kvm *kvm); 55 - int kvm_alloc_stage2_pgd(struct kvm *kvm); 56 - void kvm_free_stage2_pgd(struct kvm *kvm); 57 - int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, 58 - phys_addr_t pa, unsigned long size, bool writable); 59 - 60 - int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run); 61 - 62 - void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu); 63 - 64 - phys_addr_t kvm_mmu_get_httbr(void); 65 - phys_addr_t kvm_get_idmap_vector(void); 66 - int kvm_mmu_init(void); 67 - void kvm_clear_hyp_idmap(void); 68 - 69 - #define kvm_mk_pmd(ptep) __pmd(__pa(ptep) | PMD_TYPE_TABLE) 70 - #define kvm_mk_pud(pmdp) __pud(__pa(pmdp) | PMD_TYPE_TABLE) 71 - #define kvm_mk_pgd(pudp) ({ BUILD_BUG(); 0; }) 72 - 73 - #define kvm_pfn_pte(pfn, prot) pfn_pte(pfn, prot) 74 - #define kvm_pfn_pmd(pfn, prot) pfn_pmd(pfn, prot) 75 - #define kvm_pfn_pud(pfn, prot) (__pud(0)) 76 - 77 - #define kvm_pud_pfn(pud) ({ WARN_ON(1); 0; }) 78 - 79 - 80 - #define kvm_pmd_mkhuge(pmd) pmd_mkhuge(pmd) 81 - /* No support for pud hugepages */ 82 - #define kvm_pud_mkhuge(pud) ( {WARN_ON(1); pud; }) 83 - 84 - /* 85 - * The following kvm_*pud*() functions are provided strictly to allow 86 - * sharing code with arm64. They should never be called in practice. 87 - */ 88 - static inline void kvm_set_s2pud_readonly(pud_t *pud) 89 - { 90 - WARN_ON(1); 91 - } 92 - 93 - static inline bool kvm_s2pud_readonly(pud_t *pud) 94 - { 95 - WARN_ON(1); 96 - return false; 97 - } 98 - 99 - static inline void kvm_set_pud(pud_t *pud, pud_t new_pud) 100 - { 101 - WARN_ON(1); 102 - } 103 - 104 - static inline pud_t kvm_s2pud_mkwrite(pud_t pud) 105 - { 106 - WARN_ON(1); 107 - return pud; 108 - } 109 - 110 - static inline pud_t kvm_s2pud_mkexec(pud_t pud) 111 - { 112 - WARN_ON(1); 113 - return pud; 114 - } 115 - 116 - static inline bool kvm_s2pud_exec(pud_t *pud) 117 - { 118 - WARN_ON(1); 119 - return false; 120 - } 121 - 122 - static inline pud_t kvm_s2pud_mkyoung(pud_t pud) 123 - { 124 - BUG(); 125 - return pud; 126 - } 127 - 128 - static inline bool kvm_s2pud_young(pud_t pud) 129 - { 130 - WARN_ON(1); 131 - return false; 132 - } 133 - 134 - static inline pte_t kvm_s2pte_mkwrite(pte_t pte) 135 - { 136 - pte_val(pte) |= L_PTE_S2_RDWR; 137 - return pte; 138 - } 139 - 140 - static inline pmd_t kvm_s2pmd_mkwrite(pmd_t pmd) 141 - { 142 - pmd_val(pmd) |= L_PMD_S2_RDWR; 143 - return pmd; 144 - } 145 - 146 - static inline pte_t kvm_s2pte_mkexec(pte_t pte) 147 - { 148 - pte_val(pte) &= ~L_PTE_XN; 149 - return pte; 150 - } 151 - 152 - static inline pmd_t kvm_s2pmd_mkexec(pmd_t pmd) 153 - { 154 - pmd_val(pmd) &= ~PMD_SECT_XN; 155 - return pmd; 156 - } 157 - 158 - static inline void kvm_set_s2pte_readonly(pte_t *pte) 159 - { 160 - pte_val(*pte) = (pte_val(*pte) & ~L_PTE_S2_RDWR) | L_PTE_S2_RDONLY; 161 - } 162 - 163 - static inline bool kvm_s2pte_readonly(pte_t *pte) 164 - { 165 - return (pte_val(*pte) & L_PTE_S2_RDWR) == L_PTE_S2_RDONLY; 166 - } 167 - 168 - static inline bool kvm_s2pte_exec(pte_t *pte) 169 - { 170 - return !(pte_val(*pte) & L_PTE_XN); 171 - } 172 - 173 - static inline void kvm_set_s2pmd_readonly(pmd_t *pmd) 174 - { 175 - pmd_val(*pmd) = (pmd_val(*pmd) & ~L_PMD_S2_RDWR) | L_PMD_S2_RDONLY; 176 - } 177 - 178 - static inline bool kvm_s2pmd_readonly(pmd_t *pmd) 179 - { 180 - return (pmd_val(*pmd) & L_PMD_S2_RDWR) == L_PMD_S2_RDONLY; 181 - } 182 - 183 - static inline bool kvm_s2pmd_exec(pmd_t *pmd) 184 - { 185 - return !(pmd_val(*pmd) & PMD_SECT_XN); 186 - } 187 - 188 - static inline bool kvm_page_empty(void *ptr) 189 - { 190 - struct page *ptr_page = virt_to_page(ptr); 191 - return page_count(ptr_page) == 1; 192 - } 193 - 194 - #define kvm_pte_table_empty(kvm, ptep) kvm_page_empty(ptep) 195 - #define kvm_pmd_table_empty(kvm, pmdp) kvm_page_empty(pmdp) 196 - #define kvm_pud_table_empty(kvm, pudp) false 197 - 198 - #define hyp_pte_table_empty(ptep) kvm_page_empty(ptep) 199 - #define hyp_pmd_table_empty(pmdp) kvm_page_empty(pmdp) 200 - #define hyp_pud_table_empty(pudp) false 201 - 202 - struct kvm; 203 - 204 - #define kvm_flush_dcache_to_poc(a,l) __cpuc_flush_dcache_area((a), (l)) 205 - 206 - static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu) 207 - { 208 - return (vcpu_cp15(vcpu, c1_SCTLR) & 0b101) == 0b101; 209 - } 210 - 211 - static inline void __clean_dcache_guest_page(kvm_pfn_t pfn, unsigned long size) 212 - { 213 - /* 214 - * Clean the dcache to the Point of Coherency. 215 - * 216 - * We need to do this through a kernel mapping (using the 217 - * user-space mapping has proved to be the wrong 218 - * solution). For that, we need to kmap one page at a time, 219 - * and iterate over the range. 220 - */ 221 - 222 - VM_BUG_ON(size & ~PAGE_MASK); 223 - 224 - while (size) { 225 - void *va = kmap_atomic_pfn(pfn); 226 - 227 - kvm_flush_dcache_to_poc(va, PAGE_SIZE); 228 - 229 - size -= PAGE_SIZE; 230 - pfn++; 231 - 232 - kunmap_atomic(va); 233 - } 234 - } 235 - 236 - static inline void __invalidate_icache_guest_page(kvm_pfn_t pfn, 237 - unsigned long size) 238 - { 239 - u32 iclsz; 240 - 241 - /* 242 - * If we are going to insert an instruction page and the icache is 243 - * either VIPT or PIPT, there is a potential problem where the host 244 - * (or another VM) may have used the same page as this guest, and we 245 - * read incorrect data from the icache. If we're using a PIPT cache, 246 - * we can invalidate just that page, but if we are using a VIPT cache 247 - * we need to invalidate the entire icache - damn shame - as written 248 - * in the ARM ARM (DDI 0406C.b - Page B3-1393). 249 - * 250 - * VIVT caches are tagged using both the ASID and the VMID and doesn't 251 - * need any kind of flushing (DDI 0406C.b - Page B3-1392). 252 - */ 253 - 254 - VM_BUG_ON(size & ~PAGE_MASK); 255 - 256 - if (icache_is_vivt_asid_tagged()) 257 - return; 258 - 259 - if (!icache_is_pipt()) { 260 - /* any kind of VIPT cache */ 261 - __flush_icache_all(); 262 - return; 263 - } 264 - 265 - /* 266 - * CTR IminLine contains Log2 of the number of words in the 267 - * cache line, so we can get the number of words as 268 - * 2 << (IminLine - 1). To get the number of bytes, we 269 - * multiply by 4 (the number of bytes in a 32-bit word), and 270 - * get 4 << (IminLine). 271 - */ 272 - iclsz = 4 << (read_cpuid(CPUID_CACHETYPE) & 0xf); 273 - 274 - while (size) { 275 - void *va = kmap_atomic_pfn(pfn); 276 - void *end = va + PAGE_SIZE; 277 - void *addr = va; 278 - 279 - do { 280 - write_sysreg(addr, ICIMVAU); 281 - addr += iclsz; 282 - } while (addr < end); 283 - 284 - dsb(ishst); 285 - isb(); 286 - 287 - size -= PAGE_SIZE; 288 - pfn++; 289 - 290 - kunmap_atomic(va); 291 - } 292 - 293 - /* Check if we need to invalidate the BTB */ 294 - if ((read_cpuid_ext(CPUID_EXT_MMFR1) >> 28) != 4) { 295 - write_sysreg(0, BPIALLIS); 296 - dsb(ishst); 297 - isb(); 298 - } 299 - } 300 - 301 - static inline void __kvm_flush_dcache_pte(pte_t pte) 302 - { 303 - void *va = kmap_atomic(pte_page(pte)); 304 - 305 - kvm_flush_dcache_to_poc(va, PAGE_SIZE); 306 - 307 - kunmap_atomic(va); 308 - } 309 - 310 - static inline void __kvm_flush_dcache_pmd(pmd_t pmd) 311 - { 312 - unsigned long size = PMD_SIZE; 313 - kvm_pfn_t pfn = pmd_pfn(pmd); 314 - 315 - while (size) { 316 - void *va = kmap_atomic_pfn(pfn); 317 - 318 - kvm_flush_dcache_to_poc(va, PAGE_SIZE); 319 - 320 - pfn++; 321 - size -= PAGE_SIZE; 322 - 323 - kunmap_atomic(va); 324 - } 325 - } 326 - 327 - static inline void __kvm_flush_dcache_pud(pud_t pud) 328 - { 329 - } 330 - 331 - #define kvm_virt_to_phys(x) virt_to_idmap((unsigned long)(x)) 332 - 333 - void kvm_set_way_flush(struct kvm_vcpu *vcpu); 334 - void kvm_toggle_cache(struct kvm_vcpu *vcpu, bool was_enabled); 335 - 336 - static inline bool __kvm_cpu_uses_extended_idmap(void) 337 - { 338 - return false; 339 - } 340 - 341 - static inline unsigned long __kvm_idmap_ptrs_per_pgd(void) 342 - { 343 - return PTRS_PER_PGD; 344 - } 345 - 346 - static inline void __kvm_extend_hypmap(pgd_t *boot_hyp_pgd, 347 - pgd_t *hyp_pgd, 348 - pgd_t *merged_hyp_pgd, 349 - unsigned long hyp_idmap_start) { } 350 - 351 - static inline unsigned int kvm_get_vmid_bits(void) 352 - { 353 - return 8; 354 - } 355 - 356 - /* 357 - * We are not in the kvm->srcu critical section most of the time, so we take 358 - * the SRCU read lock here. Since we copy the data from the user page, we 359 - * can immediately drop the lock again. 360 - */ 361 - static inline int kvm_read_guest_lock(struct kvm *kvm, 362 - gpa_t gpa, void *data, unsigned long len) 363 - { 364 - int srcu_idx = srcu_read_lock(&kvm->srcu); 365 - int ret = kvm_read_guest(kvm, gpa, data, len); 366 - 367 - srcu_read_unlock(&kvm->srcu, srcu_idx); 368 - 369 - return ret; 370 - } 371 - 372 - static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa, 373 - const void *data, unsigned long len) 374 - { 375 - int srcu_idx = srcu_read_lock(&kvm->srcu); 376 - int ret = kvm_write_guest(kvm, gpa, data, len); 377 - 378 - srcu_read_unlock(&kvm->srcu, srcu_idx); 379 - 380 - return ret; 381 - } 382 - 383 - static inline void *kvm_get_hyp_vector(void) 384 - { 385 - switch(read_cpuid_part()) { 386 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 387 - case ARM_CPU_PART_CORTEX_A12: 388 - case ARM_CPU_PART_CORTEX_A17: 389 - { 390 - extern char __kvm_hyp_vector_bp_inv[]; 391 - return kvm_ksym_ref(__kvm_hyp_vector_bp_inv); 392 - } 393 - 394 - case ARM_CPU_PART_BRAHMA_B15: 395 - case ARM_CPU_PART_CORTEX_A15: 396 - { 397 - extern char __kvm_hyp_vector_ic_inv[]; 398 - return kvm_ksym_ref(__kvm_hyp_vector_ic_inv); 399 - } 400 - #endif 401 - default: 402 - { 403 - extern char __kvm_hyp_vector[]; 404 - return kvm_ksym_ref(__kvm_hyp_vector); 405 - } 406 - } 407 - } 408 - 409 - static inline int kvm_map_vectors(void) 410 - { 411 - return 0; 412 - } 413 - 414 - static inline int hyp_map_aux_data(void) 415 - { 416 - return 0; 417 - } 418 - 419 - #define kvm_phys_to_vttbr(addr) (addr) 420 - 421 - static inline void kvm_set_ipa_limit(void) {} 422 - 423 - static __always_inline u64 kvm_get_vttbr(struct kvm *kvm) 424 - { 425 - struct kvm_vmid *vmid = &kvm->arch.vmid; 426 - u64 vmid_field, baddr; 427 - 428 - baddr = kvm->arch.pgd_phys; 429 - vmid_field = (u64)vmid->vmid << VTTBR_VMID_SHIFT; 430 - return kvm_phys_to_vttbr(baddr) | vmid_field; 431 - } 432 - 433 - #endif /* !__ASSEMBLY__ */ 434 - 435 - #endif /* __ARM_KVM_MMU_H__ */
-14
arch/arm/include/asm/kvm_ras.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* Copyright (C) 2018 - Arm Ltd */ 3 - 4 - #ifndef __ARM_KVM_RAS_H__ 5 - #define __ARM_KVM_RAS_H__ 6 - 7 - #include <linux/types.h> 8 - 9 - static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) 10 - { 11 - return -1; 12 - } 13 - 14 - #endif /* __ARM_KVM_RAS_H__ */
-75
arch/arm/include/asm/stage2_pgtable.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2016 - ARM Ltd 4 - * 5 - * stage2 page table helpers 6 - */ 7 - 8 - #ifndef __ARM_S2_PGTABLE_H_ 9 - #define __ARM_S2_PGTABLE_H_ 10 - 11 - /* 12 - * kvm_mmu_cache_min_pages() is the number of pages required 13 - * to install a stage-2 translation. We pre-allocate the entry 14 - * level table at VM creation. Since we have a 3 level page-table, 15 - * we need only two pages to add a new mapping. 16 - */ 17 - #define kvm_mmu_cache_min_pages(kvm) 2 18 - 19 - #define stage2_pgd_none(kvm, pgd) pgd_none(pgd) 20 - #define stage2_pgd_clear(kvm, pgd) pgd_clear(pgd) 21 - #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) 22 - #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) 23 - #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) 24 - #define stage2_pud_free(kvm, pud) do { } while (0) 25 - 26 - #define stage2_pud_none(kvm, pud) pud_none(pud) 27 - #define stage2_pud_clear(kvm, pud) pud_clear(pud) 28 - #define stage2_pud_present(kvm, pud) pud_present(pud) 29 - #define stage2_pud_populate(kvm, pud, pmd) pud_populate(NULL, pud, pmd) 30 - #define stage2_pmd_offset(kvm, pud, address) pmd_offset(pud, address) 31 - #define stage2_pmd_free(kvm, pmd) free_page((unsigned long)pmd) 32 - 33 - #define stage2_pud_huge(kvm, pud) pud_huge(pud) 34 - 35 - /* Open coded p*d_addr_end that can deal with 64bit addresses */ 36 - static inline phys_addr_t 37 - stage2_pgd_addr_end(struct kvm *kvm, phys_addr_t addr, phys_addr_t end) 38 - { 39 - phys_addr_t boundary = (addr + PGDIR_SIZE) & PGDIR_MASK; 40 - 41 - return (boundary - 1 < end - 1) ? boundary : end; 42 - } 43 - 44 - #define stage2_pud_addr_end(kvm, addr, end) (end) 45 - 46 - static inline phys_addr_t 47 - stage2_pmd_addr_end(struct kvm *kvm, phys_addr_t addr, phys_addr_t end) 48 - { 49 - phys_addr_t boundary = (addr + PMD_SIZE) & PMD_MASK; 50 - 51 - return (boundary - 1 < end - 1) ? boundary : end; 52 - } 53 - 54 - #define stage2_pgd_index(kvm, addr) pgd_index(addr) 55 - 56 - #define stage2_pte_table_empty(kvm, ptep) kvm_page_empty(ptep) 57 - #define stage2_pmd_table_empty(kvm, pmdp) kvm_page_empty(pmdp) 58 - #define stage2_pud_table_empty(kvm, pudp) false 59 - 60 - static inline bool kvm_stage2_has_pud(struct kvm *kvm) 61 - { 62 - return false; 63 - } 64 - 65 - #define S2_PMD_MASK PMD_MASK 66 - #define S2_PMD_SIZE PMD_SIZE 67 - #define S2_PUD_MASK PUD_MASK 68 - #define S2_PUD_SIZE PUD_SIZE 69 - 70 - static inline bool kvm_stage2_has_pmd(struct kvm *kvm) 71 - { 72 - return true; 73 - } 74 - 75 - #endif /* __ARM_S2_PGTABLE_H_ */
-5
arch/arm/include/asm/virt.h
··· 67 67 return false; 68 68 } 69 69 70 - static inline bool has_vhe(void) 71 - { 72 - return false; 73 - } 74 - 75 70 /* The section containing the hypervisor idmap text */ 76 71 extern char __hyp_idmap_text_start[]; 77 72 extern char __hyp_idmap_text_end[];
-314
arch/arm/include/uapi/asm/kvm.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License, version 2, as 8 - * published by the Free Software Foundation. 9 - * 10 - * This program is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - * GNU General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 - */ 19 - 20 - #ifndef __ARM_KVM_H__ 21 - #define __ARM_KVM_H__ 22 - 23 - #include <linux/types.h> 24 - #include <linux/psci.h> 25 - #include <asm/ptrace.h> 26 - 27 - #define __KVM_HAVE_GUEST_DEBUG 28 - #define __KVM_HAVE_IRQ_LINE 29 - #define __KVM_HAVE_READONLY_MEM 30 - #define __KVM_HAVE_VCPU_EVENTS 31 - 32 - #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 33 - 34 - #define KVM_REG_SIZE(id) \ 35 - (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 36 - 37 - /* Valid for svc_regs, abt_regs, und_regs, irq_regs in struct kvm_regs */ 38 - #define KVM_ARM_SVC_sp svc_regs[0] 39 - #define KVM_ARM_SVC_lr svc_regs[1] 40 - #define KVM_ARM_SVC_spsr svc_regs[2] 41 - #define KVM_ARM_ABT_sp abt_regs[0] 42 - #define KVM_ARM_ABT_lr abt_regs[1] 43 - #define KVM_ARM_ABT_spsr abt_regs[2] 44 - #define KVM_ARM_UND_sp und_regs[0] 45 - #define KVM_ARM_UND_lr und_regs[1] 46 - #define KVM_ARM_UND_spsr und_regs[2] 47 - #define KVM_ARM_IRQ_sp irq_regs[0] 48 - #define KVM_ARM_IRQ_lr irq_regs[1] 49 - #define KVM_ARM_IRQ_spsr irq_regs[2] 50 - 51 - /* Valid only for fiq_regs in struct kvm_regs */ 52 - #define KVM_ARM_FIQ_r8 fiq_regs[0] 53 - #define KVM_ARM_FIQ_r9 fiq_regs[1] 54 - #define KVM_ARM_FIQ_r10 fiq_regs[2] 55 - #define KVM_ARM_FIQ_fp fiq_regs[3] 56 - #define KVM_ARM_FIQ_ip fiq_regs[4] 57 - #define KVM_ARM_FIQ_sp fiq_regs[5] 58 - #define KVM_ARM_FIQ_lr fiq_regs[6] 59 - #define KVM_ARM_FIQ_spsr fiq_regs[7] 60 - 61 - struct kvm_regs { 62 - struct pt_regs usr_regs; /* R0_usr - R14_usr, PC, CPSR */ 63 - unsigned long svc_regs[3]; /* SP_svc, LR_svc, SPSR_svc */ 64 - unsigned long abt_regs[3]; /* SP_abt, LR_abt, SPSR_abt */ 65 - unsigned long und_regs[3]; /* SP_und, LR_und, SPSR_und */ 66 - unsigned long irq_regs[3]; /* SP_irq, LR_irq, SPSR_irq */ 67 - unsigned long fiq_regs[8]; /* R8_fiq - R14_fiq, SPSR_fiq */ 68 - }; 69 - 70 - /* Supported Processor Types */ 71 - #define KVM_ARM_TARGET_CORTEX_A15 0 72 - #define KVM_ARM_TARGET_CORTEX_A7 1 73 - #define KVM_ARM_NUM_TARGETS 2 74 - 75 - /* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ 76 - #define KVM_ARM_DEVICE_TYPE_SHIFT 0 77 - #define KVM_ARM_DEVICE_TYPE_MASK (0xffff << KVM_ARM_DEVICE_TYPE_SHIFT) 78 - #define KVM_ARM_DEVICE_ID_SHIFT 16 79 - #define KVM_ARM_DEVICE_ID_MASK (0xffff << KVM_ARM_DEVICE_ID_SHIFT) 80 - 81 - /* Supported device IDs */ 82 - #define KVM_ARM_DEVICE_VGIC_V2 0 83 - 84 - /* Supported VGIC address types */ 85 - #define KVM_VGIC_V2_ADDR_TYPE_DIST 0 86 - #define KVM_VGIC_V2_ADDR_TYPE_CPU 1 87 - 88 - #define KVM_VGIC_V2_DIST_SIZE 0x1000 89 - #define KVM_VGIC_V2_CPU_SIZE 0x2000 90 - 91 - /* Supported VGICv3 address types */ 92 - #define KVM_VGIC_V3_ADDR_TYPE_DIST 2 93 - #define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 94 - #define KVM_VGIC_ITS_ADDR_TYPE 4 95 - #define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION 5 96 - 97 - #define KVM_VGIC_V3_DIST_SIZE SZ_64K 98 - #define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 99 - #define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) 100 - 101 - #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 102 - #define KVM_ARM_VCPU_PSCI_0_2 1 /* CPU uses PSCI v0.2 */ 103 - 104 - struct kvm_vcpu_init { 105 - __u32 target; 106 - __u32 features[7]; 107 - }; 108 - 109 - struct kvm_sregs { 110 - }; 111 - 112 - struct kvm_fpu { 113 - }; 114 - 115 - struct kvm_guest_debug_arch { 116 - }; 117 - 118 - struct kvm_debug_exit_arch { 119 - }; 120 - 121 - struct kvm_sync_regs { 122 - /* Used with KVM_CAP_ARM_USER_IRQ */ 123 - __u64 device_irq_level; 124 - }; 125 - 126 - struct kvm_arch_memory_slot { 127 - }; 128 - 129 - /* for KVM_GET/SET_VCPU_EVENTS */ 130 - struct kvm_vcpu_events { 131 - struct { 132 - __u8 serror_pending; 133 - __u8 serror_has_esr; 134 - __u8 ext_dabt_pending; 135 - /* Align it to 8 bytes */ 136 - __u8 pad[5]; 137 - __u64 serror_esr; 138 - } exception; 139 - __u32 reserved[12]; 140 - }; 141 - 142 - /* If you need to interpret the index values, here is the key: */ 143 - #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 144 - #define KVM_REG_ARM_COPROC_SHIFT 16 145 - #define KVM_REG_ARM_32_OPC2_MASK 0x0000000000000007 146 - #define KVM_REG_ARM_32_OPC2_SHIFT 0 147 - #define KVM_REG_ARM_OPC1_MASK 0x0000000000000078 148 - #define KVM_REG_ARM_OPC1_SHIFT 3 149 - #define KVM_REG_ARM_CRM_MASK 0x0000000000000780 150 - #define KVM_REG_ARM_CRM_SHIFT 7 151 - #define KVM_REG_ARM_32_CRN_MASK 0x0000000000007800 152 - #define KVM_REG_ARM_32_CRN_SHIFT 11 153 - /* 154 - * For KVM currently all guest registers are nonsecure, but we reserve a bit 155 - * in the encoding to distinguish secure from nonsecure for AArch32 system 156 - * registers that are banked by security. This is 1 for the secure banked 157 - * register, and 0 for the nonsecure banked register or if the register is 158 - * not banked by security. 159 - */ 160 - #define KVM_REG_ARM_SECURE_MASK 0x0000000010000000 161 - #define KVM_REG_ARM_SECURE_SHIFT 28 162 - 163 - #define ARM_CP15_REG_SHIFT_MASK(x,n) \ 164 - (((x) << KVM_REG_ARM_ ## n ## _SHIFT) & KVM_REG_ARM_ ## n ## _MASK) 165 - 166 - #define __ARM_CP15_REG(op1,crn,crm,op2) \ 167 - (KVM_REG_ARM | (15 << KVM_REG_ARM_COPROC_SHIFT) | \ 168 - ARM_CP15_REG_SHIFT_MASK(op1, OPC1) | \ 169 - ARM_CP15_REG_SHIFT_MASK(crn, 32_CRN) | \ 170 - ARM_CP15_REG_SHIFT_MASK(crm, CRM) | \ 171 - ARM_CP15_REG_SHIFT_MASK(op2, 32_OPC2)) 172 - 173 - #define ARM_CP15_REG32(...) (__ARM_CP15_REG(__VA_ARGS__) | KVM_REG_SIZE_U32) 174 - 175 - #define __ARM_CP15_REG64(op1,crm) \ 176 - (__ARM_CP15_REG(op1, 0, crm, 0) | KVM_REG_SIZE_U64) 177 - #define ARM_CP15_REG64(...) __ARM_CP15_REG64(__VA_ARGS__) 178 - 179 - /* PL1 Physical Timer Registers */ 180 - #define KVM_REG_ARM_PTIMER_CTL ARM_CP15_REG32(0, 14, 2, 1) 181 - #define KVM_REG_ARM_PTIMER_CNT ARM_CP15_REG64(0, 14) 182 - #define KVM_REG_ARM_PTIMER_CVAL ARM_CP15_REG64(2, 14) 183 - 184 - /* Virtual Timer Registers */ 185 - #define KVM_REG_ARM_TIMER_CTL ARM_CP15_REG32(0, 14, 3, 1) 186 - #define KVM_REG_ARM_TIMER_CNT ARM_CP15_REG64(1, 14) 187 - #define KVM_REG_ARM_TIMER_CVAL ARM_CP15_REG64(3, 14) 188 - 189 - /* Normal registers are mapped as coprocessor 16. */ 190 - #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT) 191 - #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / 4) 192 - 193 - /* Some registers need more space to represent values. */ 194 - #define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT) 195 - #define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00 196 - #define KVM_REG_ARM_DEMUX_ID_SHIFT 8 197 - #define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT) 198 - #define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF 199 - #define KVM_REG_ARM_DEMUX_VAL_SHIFT 0 200 - 201 - /* VFP registers: we could overload CP10 like ARM does, but that's ugly. */ 202 - #define KVM_REG_ARM_VFP (0x0012 << KVM_REG_ARM_COPROC_SHIFT) 203 - #define KVM_REG_ARM_VFP_MASK 0x000000000000FFFF 204 - #define KVM_REG_ARM_VFP_BASE_REG 0x0 205 - #define KVM_REG_ARM_VFP_FPSID 0x1000 206 - #define KVM_REG_ARM_VFP_FPSCR 0x1001 207 - #define KVM_REG_ARM_VFP_MVFR1 0x1006 208 - #define KVM_REG_ARM_VFP_MVFR0 0x1007 209 - #define KVM_REG_ARM_VFP_FPEXC 0x1008 210 - #define KVM_REG_ARM_VFP_FPINST 0x1009 211 - #define KVM_REG_ARM_VFP_FPINST2 0x100A 212 - 213 - /* KVM-as-firmware specific pseudo-registers */ 214 - #define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT) 215 - #define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM | KVM_REG_SIZE_U64 | \ 216 - KVM_REG_ARM_FW | ((r) & 0xffff)) 217 - #define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) 218 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1 KVM_REG_ARM_FW_REG(1) 219 - /* Higher values mean better protection. */ 220 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL 0 221 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL 1 222 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED 2 223 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2 KVM_REG_ARM_FW_REG(2) 224 - /* Higher values mean better protection. */ 225 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL 0 226 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN 1 227 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL 2 228 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED 3 229 - #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED (1U << 4) 230 - 231 - /* Device Control API: ARM VGIC */ 232 - #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 233 - #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 234 - #define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 235 - #define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 236 - #define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 237 - #define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 238 - #define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ 239 - (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT) 240 - #define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 241 - #define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 242 - #define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff) 243 - #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 244 - #define KVM_DEV_ARM_VGIC_GRP_CTRL 4 245 - #define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 246 - #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 247 - #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 248 - #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 249 - #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 250 - #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ 251 - (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) 252 - #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff 253 - #define VGIC_LEVEL_INFO_LINE_LEVEL 0 254 - 255 - /* Device Control API on vcpu fd */ 256 - #define KVM_ARM_VCPU_PMU_V3_CTRL 0 257 - #define KVM_ARM_VCPU_PMU_V3_IRQ 0 258 - #define KVM_ARM_VCPU_PMU_V3_INIT 1 259 - #define KVM_ARM_VCPU_TIMER_CTRL 1 260 - #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 261 - #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 262 - 263 - #define KVM_DEV_ARM_VGIC_CTRL_INIT 0 264 - #define KVM_DEV_ARM_ITS_SAVE_TABLES 1 265 - #define KVM_DEV_ARM_ITS_RESTORE_TABLES 2 266 - #define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 267 - #define KVM_DEV_ARM_ITS_CTRL_RESET 4 268 - 269 - /* KVM_IRQ_LINE irq field index values */ 270 - #define KVM_ARM_IRQ_VCPU2_SHIFT 28 271 - #define KVM_ARM_IRQ_VCPU2_MASK 0xf 272 - #define KVM_ARM_IRQ_TYPE_SHIFT 24 273 - #define KVM_ARM_IRQ_TYPE_MASK 0xf 274 - #define KVM_ARM_IRQ_VCPU_SHIFT 16 275 - #define KVM_ARM_IRQ_VCPU_MASK 0xff 276 - #define KVM_ARM_IRQ_NUM_SHIFT 0 277 - #define KVM_ARM_IRQ_NUM_MASK 0xffff 278 - 279 - /* irq_type field */ 280 - #define KVM_ARM_IRQ_TYPE_CPU 0 281 - #define KVM_ARM_IRQ_TYPE_SPI 1 282 - #define KVM_ARM_IRQ_TYPE_PPI 2 283 - 284 - /* out-of-kernel GIC cpu interrupt injection irq_number field */ 285 - #define KVM_ARM_IRQ_CPU_IRQ 0 286 - #define KVM_ARM_IRQ_CPU_FIQ 1 287 - 288 - /* 289 - * This used to hold the highest supported SPI, but it is now obsolete 290 - * and only here to provide source code level compatibility with older 291 - * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS. 292 - */ 293 - #ifndef __KERNEL__ 294 - #define KVM_ARM_IRQ_GIC_MAX 127 295 - #endif 296 - 297 - /* One single KVM irqchip, ie. the VGIC */ 298 - #define KVM_NR_IRQCHIPS 1 299 - 300 - /* PSCI interface */ 301 - #define KVM_PSCI_FN_BASE 0x95c1ba5e 302 - #define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n)) 303 - 304 - #define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) 305 - #define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) 306 - #define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) 307 - #define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) 308 - 309 - #define KVM_PSCI_RET_SUCCESS PSCI_RET_SUCCESS 310 - #define KVM_PSCI_RET_NI PSCI_RET_NOT_SUPPORTED 311 - #define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS 312 - #define KVM_PSCI_RET_DENIED PSCI_RET_DENIED 313 - 314 - #endif /* __ARM_KVM_H__ */
-11
arch/arm/kernel/asm-offsets.c
··· 11 11 #include <linux/sched.h> 12 12 #include <linux/mm.h> 13 13 #include <linux/dma-mapping.h> 14 - #ifdef CONFIG_KVM_ARM_HOST 15 - #include <linux/kvm_host.h> 16 - #endif 17 14 #include <asm/cacheflush.h> 18 15 #include <asm/glue-df.h> 19 16 #include <asm/glue-pf.h> ··· 163 166 BLANK(); 164 167 DEFINE(CACHE_WRITEBACK_ORDER, __CACHE_WRITEBACK_ORDER); 165 168 DEFINE(CACHE_WRITEBACK_GRANULE, __CACHE_WRITEBACK_GRANULE); 166 - BLANK(); 167 - #ifdef CONFIG_KVM_ARM_HOST 168 - DEFINE(VCPU_GUEST_CTXT, offsetof(struct kvm_vcpu, arch.ctxt)); 169 - DEFINE(VCPU_HOST_CTXT, offsetof(struct kvm_vcpu, arch.host_cpu_context)); 170 - DEFINE(CPU_CTXT_VFP, offsetof(struct kvm_cpu_context, vfp)); 171 - DEFINE(CPU_CTXT_GP_REGS, offsetof(struct kvm_cpu_context, gp_regs)); 172 - DEFINE(GP_REGS_USR, offsetof(struct kvm_regs, usr_regs)); 173 - #endif 174 169 BLANK(); 175 170 #ifdef CONFIG_VDSO 176 171 DEFINE(VDSO_DATA_SIZE, sizeof(union vdso_data_store));
-59
arch/arm/kvm/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # 3 - # KVM configuration 4 - # 5 - 6 - source "virt/kvm/Kconfig" 7 - source "virt/lib/Kconfig" 8 - 9 - menuconfig VIRTUALIZATION 10 - bool "Virtualization" 11 - ---help--- 12 - Say Y here to get to see options for using your Linux host to run 13 - other operating systems inside virtual machines (guests). 14 - This option alone does not add any kernel code. 15 - 16 - If you say N, all options in this submenu will be skipped and 17 - disabled. 18 - 19 - if VIRTUALIZATION 20 - 21 - config KVM 22 - bool "Kernel-based Virtual Machine (KVM) support" 23 - depends on MMU && OF 24 - select PREEMPT_NOTIFIERS 25 - select ARM_GIC 26 - select ARM_GIC_V3 27 - select ARM_GIC_V3_ITS 28 - select HAVE_KVM_CPU_RELAX_INTERCEPT 29 - select HAVE_KVM_ARCH_TLB_FLUSH_ALL 30 - select KVM_MMIO 31 - select KVM_ARM_HOST 32 - select KVM_GENERIC_DIRTYLOG_READ_PROTECT 33 - select SRCU 34 - select MMU_NOTIFIER 35 - select KVM_VFIO 36 - select HAVE_KVM_EVENTFD 37 - select HAVE_KVM_IRQFD 38 - select HAVE_KVM_IRQCHIP 39 - select HAVE_KVM_IRQ_ROUTING 40 - select HAVE_KVM_MSI 41 - select IRQ_BYPASS_MANAGER 42 - select HAVE_KVM_IRQ_BYPASS 43 - depends on ARM_VIRT_EXT && ARM_LPAE && ARM_ARCH_TIMER 44 - ---help--- 45 - Support hosting virtualized guest machines. 46 - 47 - This module provides access to the hardware capabilities through 48 - a character device node named /dev/kvm. 49 - 50 - If unsure, say N. 51 - 52 - config KVM_ARM_HOST 53 - bool 54 - ---help--- 55 - Provides host support for ARM processors. 56 - 57 - source "drivers/vhost/Kconfig" 58 - 59 - endif # VIRTUALIZATION
-43
arch/arm/kvm/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # 3 - # Makefile for Kernel-based Virtual Machine module 4 - # 5 - 6 - plus_virt := $(call as-instr,.arch_extension virt,+virt) 7 - ifeq ($(plus_virt),+virt) 8 - plus_virt_def := -DREQUIRES_VIRT=1 9 - endif 10 - 11 - KVM := ../../../virt/kvm 12 - 13 - ccflags-y += -I $(srctree)/$(src) -I $(srctree)/virt/kvm/arm/vgic 14 - CFLAGS_$(KVM)/arm/arm.o := $(plus_virt_def) 15 - 16 - AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt) 17 - AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt) 18 - 19 - kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o $(KVM)/vfio.o 20 - 21 - obj-$(CONFIG_KVM_ARM_HOST) += hyp/ 22 - 23 - obj-y += kvm-arm.o init.o interrupts.o 24 - obj-y += handle_exit.o guest.o emulate.o reset.o 25 - obj-y += coproc.o coproc_a15.o coproc_a7.o vgic-v3-coproc.o 26 - obj-y += $(KVM)/arm/arm.o $(KVM)/arm/mmu.o $(KVM)/arm/mmio.o 27 - obj-y += $(KVM)/arm/psci.o $(KVM)/arm/perf.o $(KVM)/arm/hypercalls.o 28 - obj-y += $(KVM)/arm/aarch32.o 29 - 30 - obj-y += $(KVM)/arm/vgic/vgic.o 31 - obj-y += $(KVM)/arm/vgic/vgic-init.o 32 - obj-y += $(KVM)/arm/vgic/vgic-irqfd.o 33 - obj-y += $(KVM)/arm/vgic/vgic-v2.o 34 - obj-y += $(KVM)/arm/vgic/vgic-v3.o 35 - obj-y += $(KVM)/arm/vgic/vgic-v4.o 36 - obj-y += $(KVM)/arm/vgic/vgic-mmio.o 37 - obj-y += $(KVM)/arm/vgic/vgic-mmio-v2.o 38 - obj-y += $(KVM)/arm/vgic/vgic-mmio-v3.o 39 - obj-y += $(KVM)/arm/vgic/vgic-kvm-device.o 40 - obj-y += $(KVM)/arm/vgic/vgic-its.o 41 - obj-y += $(KVM)/arm/vgic/vgic-debug.o 42 - obj-y += $(KVM)/irqchip.o 43 - obj-y += $(KVM)/arm/arch_timer.o
-1455
arch/arm/kvm/coproc.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Authors: Rusty Russell <rusty@rustcorp.com.au> 5 - * Christoffer Dall <c.dall@virtualopensystems.com> 6 - */ 7 - 8 - #include <linux/bsearch.h> 9 - #include <linux/mm.h> 10 - #include <linux/kvm_host.h> 11 - #include <linux/uaccess.h> 12 - #include <asm/kvm_arm.h> 13 - #include <asm/kvm_host.h> 14 - #include <asm/kvm_emulate.h> 15 - #include <asm/kvm_coproc.h> 16 - #include <asm/kvm_mmu.h> 17 - #include <asm/cacheflush.h> 18 - #include <asm/cputype.h> 19 - #include <trace/events/kvm.h> 20 - #include <asm/vfp.h> 21 - #include "../vfp/vfpinstr.h" 22 - 23 - #define CREATE_TRACE_POINTS 24 - #include "trace.h" 25 - #include "coproc.h" 26 - 27 - 28 - /****************************************************************************** 29 - * Co-processor emulation 30 - *****************************************************************************/ 31 - 32 - static bool write_to_read_only(struct kvm_vcpu *vcpu, 33 - const struct coproc_params *params) 34 - { 35 - WARN_ONCE(1, "CP15 write to read-only register\n"); 36 - print_cp_instr(params); 37 - kvm_inject_undefined(vcpu); 38 - return false; 39 - } 40 - 41 - static bool read_from_write_only(struct kvm_vcpu *vcpu, 42 - const struct coproc_params *params) 43 - { 44 - WARN_ONCE(1, "CP15 read to write-only register\n"); 45 - print_cp_instr(params); 46 - kvm_inject_undefined(vcpu); 47 - return false; 48 - } 49 - 50 - /* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */ 51 - static u32 cache_levels; 52 - 53 - /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ 54 - #define CSSELR_MAX 12 55 - 56 - /* 57 - * kvm_vcpu_arch.cp15 holds cp15 registers as an array of u32, but some 58 - * of cp15 registers can be viewed either as couple of two u32 registers 59 - * or one u64 register. Current u64 register encoding is that least 60 - * significant u32 word is followed by most significant u32 word. 61 - */ 62 - static inline void vcpu_cp15_reg64_set(struct kvm_vcpu *vcpu, 63 - const struct coproc_reg *r, 64 - u64 val) 65 - { 66 - vcpu_cp15(vcpu, r->reg) = val & 0xffffffff; 67 - vcpu_cp15(vcpu, r->reg + 1) = val >> 32; 68 - } 69 - 70 - static inline u64 vcpu_cp15_reg64_get(struct kvm_vcpu *vcpu, 71 - const struct coproc_reg *r) 72 - { 73 - u64 val; 74 - 75 - val = vcpu_cp15(vcpu, r->reg + 1); 76 - val = val << 32; 77 - val = val | vcpu_cp15(vcpu, r->reg); 78 - return val; 79 - } 80 - 81 - int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run) 82 - { 83 - kvm_inject_undefined(vcpu); 84 - return 1; 85 - } 86 - 87 - int kvm_handle_cp_0_13_access(struct kvm_vcpu *vcpu, struct kvm_run *run) 88 - { 89 - /* 90 - * We can get here, if the host has been built without VFPv3 support, 91 - * but the guest attempted a floating point operation. 92 - */ 93 - kvm_inject_undefined(vcpu); 94 - return 1; 95 - } 96 - 97 - int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu, struct kvm_run *run) 98 - { 99 - kvm_inject_undefined(vcpu); 100 - return 1; 101 - } 102 - 103 - static void reset_mpidr(struct kvm_vcpu *vcpu, const struct coproc_reg *r) 104 - { 105 - /* 106 - * Compute guest MPIDR. We build a virtual cluster out of the 107 - * vcpu_id, but we read the 'U' bit from the underlying 108 - * hardware directly. 109 - */ 110 - vcpu_cp15(vcpu, c0_MPIDR) = ((read_cpuid_mpidr() & MPIDR_SMP_BITMASK) | 111 - ((vcpu->vcpu_id >> 2) << MPIDR_LEVEL_BITS) | 112 - (vcpu->vcpu_id & 3)); 113 - } 114 - 115 - /* TRM entries A7:4.3.31 A15:4.3.28 - RO WI */ 116 - static bool access_actlr(struct kvm_vcpu *vcpu, 117 - const struct coproc_params *p, 118 - const struct coproc_reg *r) 119 - { 120 - if (p->is_write) 121 - return ignore_write(vcpu, p); 122 - 123 - *vcpu_reg(vcpu, p->Rt1) = vcpu_cp15(vcpu, c1_ACTLR); 124 - return true; 125 - } 126 - 127 - /* TRM entries A7:4.3.56, A15:4.3.60 - R/O. */ 128 - static bool access_cbar(struct kvm_vcpu *vcpu, 129 - const struct coproc_params *p, 130 - const struct coproc_reg *r) 131 - { 132 - if (p->is_write) 133 - return write_to_read_only(vcpu, p); 134 - return read_zero(vcpu, p); 135 - } 136 - 137 - /* TRM entries A7:4.3.49, A15:4.3.48 - R/O WI */ 138 - static bool access_l2ctlr(struct kvm_vcpu *vcpu, 139 - const struct coproc_params *p, 140 - const struct coproc_reg *r) 141 - { 142 - if (p->is_write) 143 - return ignore_write(vcpu, p); 144 - 145 - *vcpu_reg(vcpu, p->Rt1) = vcpu_cp15(vcpu, c9_L2CTLR); 146 - return true; 147 - } 148 - 149 - static void reset_l2ctlr(struct kvm_vcpu *vcpu, const struct coproc_reg *r) 150 - { 151 - u32 l2ctlr, ncores; 152 - 153 - asm volatile("mrc p15, 1, %0, c9, c0, 2\n" : "=r" (l2ctlr)); 154 - l2ctlr &= ~(3 << 24); 155 - ncores = atomic_read(&vcpu->kvm->online_vcpus) - 1; 156 - /* How many cores in the current cluster and the next ones */ 157 - ncores -= (vcpu->vcpu_id & ~3); 158 - /* Cap it to the maximum number of cores in a single cluster */ 159 - ncores = min(ncores, 3U); 160 - l2ctlr |= (ncores & 3) << 24; 161 - 162 - vcpu_cp15(vcpu, c9_L2CTLR) = l2ctlr; 163 - } 164 - 165 - static void reset_actlr(struct kvm_vcpu *vcpu, const struct coproc_reg *r) 166 - { 167 - u32 actlr; 168 - 169 - /* ACTLR contains SMP bit: make sure you create all cpus first! */ 170 - asm volatile("mrc p15, 0, %0, c1, c0, 1\n" : "=r" (actlr)); 171 - /* Make the SMP bit consistent with the guest configuration */ 172 - if (atomic_read(&vcpu->kvm->online_vcpus) > 1) 173 - actlr |= 1U << 6; 174 - else 175 - actlr &= ~(1U << 6); 176 - 177 - vcpu_cp15(vcpu, c1_ACTLR) = actlr; 178 - } 179 - 180 - /* 181 - * TRM entries: A7:4.3.50, A15:4.3.49 182 - * R/O WI (even if NSACR.NS_L2ERR, a write of 1 is ignored). 183 - */ 184 - static bool access_l2ectlr(struct kvm_vcpu *vcpu, 185 - const struct coproc_params *p, 186 - const struct coproc_reg *r) 187 - { 188 - if (p->is_write) 189 - return ignore_write(vcpu, p); 190 - 191 - *vcpu_reg(vcpu, p->Rt1) = 0; 192 - return true; 193 - } 194 - 195 - /* 196 - * See note at ARMv7 ARM B1.14.4 (TL;DR: S/W ops are not easily virtualized). 197 - */ 198 - static bool access_dcsw(struct kvm_vcpu *vcpu, 199 - const struct coproc_params *p, 200 - const struct coproc_reg *r) 201 - { 202 - if (!p->is_write) 203 - return read_from_write_only(vcpu, p); 204 - 205 - kvm_set_way_flush(vcpu); 206 - return true; 207 - } 208 - 209 - /* 210 - * Generic accessor for VM registers. Only called as long as HCR_TVM 211 - * is set. If the guest enables the MMU, we stop trapping the VM 212 - * sys_regs and leave it in complete control of the caches. 213 - * 214 - * Used by the cpu-specific code. 215 - */ 216 - bool access_vm_reg(struct kvm_vcpu *vcpu, 217 - const struct coproc_params *p, 218 - const struct coproc_reg *r) 219 - { 220 - bool was_enabled = vcpu_has_cache_enabled(vcpu); 221 - 222 - BUG_ON(!p->is_write); 223 - 224 - vcpu_cp15(vcpu, r->reg) = *vcpu_reg(vcpu, p->Rt1); 225 - if (p->is_64bit) 226 - vcpu_cp15(vcpu, r->reg + 1) = *vcpu_reg(vcpu, p->Rt2); 227 - 228 - kvm_toggle_cache(vcpu, was_enabled); 229 - return true; 230 - } 231 - 232 - static bool access_gic_sgi(struct kvm_vcpu *vcpu, 233 - const struct coproc_params *p, 234 - const struct coproc_reg *r) 235 - { 236 - u64 reg; 237 - bool g1; 238 - 239 - if (!p->is_write) 240 - return read_from_write_only(vcpu, p); 241 - 242 - reg = (u64)*vcpu_reg(vcpu, p->Rt2) << 32; 243 - reg |= *vcpu_reg(vcpu, p->Rt1) ; 244 - 245 - /* 246 - * In a system where GICD_CTLR.DS=1, a ICC_SGI0R access generates 247 - * Group0 SGIs only, while ICC_SGI1R can generate either group, 248 - * depending on the SGI configuration. ICC_ASGI1R is effectively 249 - * equivalent to ICC_SGI0R, as there is no "alternative" secure 250 - * group. 251 - */ 252 - switch (p->Op1) { 253 - default: /* Keep GCC quiet */ 254 - case 0: /* ICC_SGI1R */ 255 - g1 = true; 256 - break; 257 - case 1: /* ICC_ASGI1R */ 258 - case 2: /* ICC_SGI0R */ 259 - g1 = false; 260 - break; 261 - } 262 - 263 - vgic_v3_dispatch_sgi(vcpu, reg, g1); 264 - 265 - return true; 266 - } 267 - 268 - static bool access_gic_sre(struct kvm_vcpu *vcpu, 269 - const struct coproc_params *p, 270 - const struct coproc_reg *r) 271 - { 272 - if (p->is_write) 273 - return ignore_write(vcpu, p); 274 - 275 - *vcpu_reg(vcpu, p->Rt1) = vcpu->arch.vgic_cpu.vgic_v3.vgic_sre; 276 - 277 - return true; 278 - } 279 - 280 - static bool access_cntp_tval(struct kvm_vcpu *vcpu, 281 - const struct coproc_params *p, 282 - const struct coproc_reg *r) 283 - { 284 - u32 val; 285 - 286 - if (p->is_write) { 287 - val = *vcpu_reg(vcpu, p->Rt1); 288 - kvm_arm_timer_write_sysreg(vcpu, 289 - TIMER_PTIMER, TIMER_REG_TVAL, val); 290 - } else { 291 - val = kvm_arm_timer_read_sysreg(vcpu, 292 - TIMER_PTIMER, TIMER_REG_TVAL); 293 - *vcpu_reg(vcpu, p->Rt1) = val; 294 - } 295 - 296 - return true; 297 - } 298 - 299 - static bool access_cntp_ctl(struct kvm_vcpu *vcpu, 300 - const struct coproc_params *p, 301 - const struct coproc_reg *r) 302 - { 303 - u32 val; 304 - 305 - if (p->is_write) { 306 - val = *vcpu_reg(vcpu, p->Rt1); 307 - kvm_arm_timer_write_sysreg(vcpu, 308 - TIMER_PTIMER, TIMER_REG_CTL, val); 309 - } else { 310 - val = kvm_arm_timer_read_sysreg(vcpu, 311 - TIMER_PTIMER, TIMER_REG_CTL); 312 - *vcpu_reg(vcpu, p->Rt1) = val; 313 - } 314 - 315 - return true; 316 - } 317 - 318 - static bool access_cntp_cval(struct kvm_vcpu *vcpu, 319 - const struct coproc_params *p, 320 - const struct coproc_reg *r) 321 - { 322 - u64 val; 323 - 324 - if (p->is_write) { 325 - val = (u64)*vcpu_reg(vcpu, p->Rt2) << 32; 326 - val |= *vcpu_reg(vcpu, p->Rt1); 327 - kvm_arm_timer_write_sysreg(vcpu, 328 - TIMER_PTIMER, TIMER_REG_CVAL, val); 329 - } else { 330 - val = kvm_arm_timer_read_sysreg(vcpu, 331 - TIMER_PTIMER, TIMER_REG_CVAL); 332 - *vcpu_reg(vcpu, p->Rt1) = val; 333 - *vcpu_reg(vcpu, p->Rt2) = val >> 32; 334 - } 335 - 336 - return true; 337 - } 338 - 339 - /* 340 - * We could trap ID_DFR0 and tell the guest we don't support performance 341 - * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was 342 - * NAKed, so it will read the PMCR anyway. 343 - * 344 - * Therefore we tell the guest we have 0 counters. Unfortunately, we 345 - * must always support PMCCNTR (the cycle counter): we just RAZ/WI for 346 - * all PM registers, which doesn't crash the guest kernel at least. 347 - */ 348 - static bool trap_raz_wi(struct kvm_vcpu *vcpu, 349 - const struct coproc_params *p, 350 - const struct coproc_reg *r) 351 - { 352 - if (p->is_write) 353 - return ignore_write(vcpu, p); 354 - else 355 - return read_zero(vcpu, p); 356 - } 357 - 358 - #define access_pmcr trap_raz_wi 359 - #define access_pmcntenset trap_raz_wi 360 - #define access_pmcntenclr trap_raz_wi 361 - #define access_pmovsr trap_raz_wi 362 - #define access_pmselr trap_raz_wi 363 - #define access_pmceid0 trap_raz_wi 364 - #define access_pmceid1 trap_raz_wi 365 - #define access_pmccntr trap_raz_wi 366 - #define access_pmxevtyper trap_raz_wi 367 - #define access_pmxevcntr trap_raz_wi 368 - #define access_pmuserenr trap_raz_wi 369 - #define access_pmintenset trap_raz_wi 370 - #define access_pmintenclr trap_raz_wi 371 - 372 - /* Architected CP15 registers. 373 - * CRn denotes the primary register number, but is copied to the CRm in the 374 - * user space API for 64-bit register access in line with the terminology used 375 - * in the ARM ARM. 376 - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit 377 - * registers preceding 32-bit ones. 378 - */ 379 - static const struct coproc_reg cp15_regs[] = { 380 - /* MPIDR: we use VMPIDR for guest access. */ 381 - { CRn( 0), CRm( 0), Op1( 0), Op2( 5), is32, 382 - NULL, reset_mpidr, c0_MPIDR }, 383 - 384 - /* CSSELR: swapped by interrupt.S. */ 385 - { CRn( 0), CRm( 0), Op1( 2), Op2( 0), is32, 386 - NULL, reset_unknown, c0_CSSELR }, 387 - 388 - /* ACTLR: trapped by HCR.TAC bit. */ 389 - { CRn( 1), CRm( 0), Op1( 0), Op2( 1), is32, 390 - access_actlr, reset_actlr, c1_ACTLR }, 391 - 392 - /* CPACR: swapped by interrupt.S. */ 393 - { CRn( 1), CRm( 0), Op1( 0), Op2( 2), is32, 394 - NULL, reset_val, c1_CPACR, 0x00000000 }, 395 - 396 - /* TTBR0/TTBR1/TTBCR: swapped by interrupt.S. */ 397 - { CRm64( 2), Op1( 0), is64, access_vm_reg, reset_unknown64, c2_TTBR0 }, 398 - { CRn(2), CRm( 0), Op1( 0), Op2( 0), is32, 399 - access_vm_reg, reset_unknown, c2_TTBR0 }, 400 - { CRn(2), CRm( 0), Op1( 0), Op2( 1), is32, 401 - access_vm_reg, reset_unknown, c2_TTBR1 }, 402 - { CRn( 2), CRm( 0), Op1( 0), Op2( 2), is32, 403 - access_vm_reg, reset_val, c2_TTBCR, 0x00000000 }, 404 - { CRm64( 2), Op1( 1), is64, access_vm_reg, reset_unknown64, c2_TTBR1 }, 405 - 406 - 407 - /* DACR: swapped by interrupt.S. */ 408 - { CRn( 3), CRm( 0), Op1( 0), Op2( 0), is32, 409 - access_vm_reg, reset_unknown, c3_DACR }, 410 - 411 - /* DFSR/IFSR/ADFSR/AIFSR: swapped by interrupt.S. */ 412 - { CRn( 5), CRm( 0), Op1( 0), Op2( 0), is32, 413 - access_vm_reg, reset_unknown, c5_DFSR }, 414 - { CRn( 5), CRm( 0), Op1( 0), Op2( 1), is32, 415 - access_vm_reg, reset_unknown, c5_IFSR }, 416 - { CRn( 5), CRm( 1), Op1( 0), Op2( 0), is32, 417 - access_vm_reg, reset_unknown, c5_ADFSR }, 418 - { CRn( 5), CRm( 1), Op1( 0), Op2( 1), is32, 419 - access_vm_reg, reset_unknown, c5_AIFSR }, 420 - 421 - /* DFAR/IFAR: swapped by interrupt.S. */ 422 - { CRn( 6), CRm( 0), Op1( 0), Op2( 0), is32, 423 - access_vm_reg, reset_unknown, c6_DFAR }, 424 - { CRn( 6), CRm( 0), Op1( 0), Op2( 2), is32, 425 - access_vm_reg, reset_unknown, c6_IFAR }, 426 - 427 - /* PAR swapped by interrupt.S */ 428 - { CRm64( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR }, 429 - 430 - /* 431 - * DC{C,I,CI}SW operations: 432 - */ 433 - { CRn( 7), CRm( 6), Op1( 0), Op2( 2), is32, access_dcsw}, 434 - { CRn( 7), CRm(10), Op1( 0), Op2( 2), is32, access_dcsw}, 435 - { CRn( 7), CRm(14), Op1( 0), Op2( 2), is32, access_dcsw}, 436 - /* 437 - * L2CTLR access (guest wants to know #CPUs). 438 - */ 439 - { CRn( 9), CRm( 0), Op1( 1), Op2( 2), is32, 440 - access_l2ctlr, reset_l2ctlr, c9_L2CTLR }, 441 - { CRn( 9), CRm( 0), Op1( 1), Op2( 3), is32, access_l2ectlr}, 442 - 443 - /* 444 - * Dummy performance monitor implementation. 445 - */ 446 - { CRn( 9), CRm(12), Op1( 0), Op2( 0), is32, access_pmcr}, 447 - { CRn( 9), CRm(12), Op1( 0), Op2( 1), is32, access_pmcntenset}, 448 - { CRn( 9), CRm(12), Op1( 0), Op2( 2), is32, access_pmcntenclr}, 449 - { CRn( 9), CRm(12), Op1( 0), Op2( 3), is32, access_pmovsr}, 450 - { CRn( 9), CRm(12), Op1( 0), Op2( 5), is32, access_pmselr}, 451 - { CRn( 9), CRm(12), Op1( 0), Op2( 6), is32, access_pmceid0}, 452 - { CRn( 9), CRm(12), Op1( 0), Op2( 7), is32, access_pmceid1}, 453 - { CRn( 9), CRm(13), Op1( 0), Op2( 0), is32, access_pmccntr}, 454 - { CRn( 9), CRm(13), Op1( 0), Op2( 1), is32, access_pmxevtyper}, 455 - { CRn( 9), CRm(13), Op1( 0), Op2( 2), is32, access_pmxevcntr}, 456 - { CRn( 9), CRm(14), Op1( 0), Op2( 0), is32, access_pmuserenr}, 457 - { CRn( 9), CRm(14), Op1( 0), Op2( 1), is32, access_pmintenset}, 458 - { CRn( 9), CRm(14), Op1( 0), Op2( 2), is32, access_pmintenclr}, 459 - 460 - /* PRRR/NMRR (aka MAIR0/MAIR1): swapped by interrupt.S. */ 461 - { CRn(10), CRm( 2), Op1( 0), Op2( 0), is32, 462 - access_vm_reg, reset_unknown, c10_PRRR}, 463 - { CRn(10), CRm( 2), Op1( 0), Op2( 1), is32, 464 - access_vm_reg, reset_unknown, c10_NMRR}, 465 - 466 - /* AMAIR0/AMAIR1: swapped by interrupt.S. */ 467 - { CRn(10), CRm( 3), Op1( 0), Op2( 0), is32, 468 - access_vm_reg, reset_unknown, c10_AMAIR0}, 469 - { CRn(10), CRm( 3), Op1( 0), Op2( 1), is32, 470 - access_vm_reg, reset_unknown, c10_AMAIR1}, 471 - 472 - /* ICC_SGI1R */ 473 - { CRm64(12), Op1( 0), is64, access_gic_sgi}, 474 - 475 - /* VBAR: swapped by interrupt.S. */ 476 - { CRn(12), CRm( 0), Op1( 0), Op2( 0), is32, 477 - NULL, reset_val, c12_VBAR, 0x00000000 }, 478 - 479 - /* ICC_ASGI1R */ 480 - { CRm64(12), Op1( 1), is64, access_gic_sgi}, 481 - /* ICC_SGI0R */ 482 - { CRm64(12), Op1( 2), is64, access_gic_sgi}, 483 - /* ICC_SRE */ 484 - { CRn(12), CRm(12), Op1( 0), Op2(5), is32, access_gic_sre }, 485 - 486 - /* CONTEXTIDR/TPIDRURW/TPIDRURO/TPIDRPRW: swapped by interrupt.S. */ 487 - { CRn(13), CRm( 0), Op1( 0), Op2( 1), is32, 488 - access_vm_reg, reset_val, c13_CID, 0x00000000 }, 489 - { CRn(13), CRm( 0), Op1( 0), Op2( 2), is32, 490 - NULL, reset_unknown, c13_TID_URW }, 491 - { CRn(13), CRm( 0), Op1( 0), Op2( 3), is32, 492 - NULL, reset_unknown, c13_TID_URO }, 493 - { CRn(13), CRm( 0), Op1( 0), Op2( 4), is32, 494 - NULL, reset_unknown, c13_TID_PRIV }, 495 - 496 - /* CNTP */ 497 - { CRm64(14), Op1( 2), is64, access_cntp_cval}, 498 - 499 - /* CNTKCTL: swapped by interrupt.S. */ 500 - { CRn(14), CRm( 1), Op1( 0), Op2( 0), is32, 501 - NULL, reset_val, c14_CNTKCTL, 0x00000000 }, 502 - 503 - /* CNTP */ 504 - { CRn(14), CRm( 2), Op1( 0), Op2( 0), is32, access_cntp_tval }, 505 - { CRn(14), CRm( 2), Op1( 0), Op2( 1), is32, access_cntp_ctl }, 506 - 507 - /* The Configuration Base Address Register. */ 508 - { CRn(15), CRm( 0), Op1( 4), Op2( 0), is32, access_cbar}, 509 - }; 510 - 511 - static int check_reg_table(const struct coproc_reg *table, unsigned int n) 512 - { 513 - unsigned int i; 514 - 515 - for (i = 1; i < n; i++) { 516 - if (cmp_reg(&table[i-1], &table[i]) >= 0) { 517 - kvm_err("reg table %p out of order (%d)\n", table, i - 1); 518 - return 1; 519 - } 520 - } 521 - 522 - return 0; 523 - } 524 - 525 - /* Target specific emulation tables */ 526 - static struct kvm_coproc_target_table *target_tables[KVM_ARM_NUM_TARGETS]; 527 - 528 - void kvm_register_target_coproc_table(struct kvm_coproc_target_table *table) 529 - { 530 - BUG_ON(check_reg_table(table->table, table->num)); 531 - target_tables[table->target] = table; 532 - } 533 - 534 - /* Get specific register table for this target. */ 535 - static const struct coproc_reg *get_target_table(unsigned target, size_t *num) 536 - { 537 - struct kvm_coproc_target_table *table; 538 - 539 - table = target_tables[target]; 540 - *num = table->num; 541 - return table->table; 542 - } 543 - 544 - #define reg_to_match_value(x) \ 545 - ({ \ 546 - unsigned long val; \ 547 - val = (x)->CRn << 11; \ 548 - val |= (x)->CRm << 7; \ 549 - val |= (x)->Op1 << 4; \ 550 - val |= (x)->Op2 << 1; \ 551 - val |= !(x)->is_64bit; \ 552 - val; \ 553 - }) 554 - 555 - static int match_reg(const void *key, const void *elt) 556 - { 557 - const unsigned long pval = (unsigned long)key; 558 - const struct coproc_reg *r = elt; 559 - 560 - return pval - reg_to_match_value(r); 561 - } 562 - 563 - static const struct coproc_reg *find_reg(const struct coproc_params *params, 564 - const struct coproc_reg table[], 565 - unsigned int num) 566 - { 567 - unsigned long pval = reg_to_match_value(params); 568 - 569 - return bsearch((void *)pval, table, num, sizeof(table[0]), match_reg); 570 - } 571 - 572 - static int emulate_cp15(struct kvm_vcpu *vcpu, 573 - const struct coproc_params *params) 574 - { 575 - size_t num; 576 - const struct coproc_reg *table, *r; 577 - 578 - trace_kvm_emulate_cp15_imp(params->Op1, params->Rt1, params->CRn, 579 - params->CRm, params->Op2, params->is_write); 580 - 581 - table = get_target_table(vcpu->arch.target, &num); 582 - 583 - /* Search target-specific then generic table. */ 584 - r = find_reg(params, table, num); 585 - if (!r) 586 - r = find_reg(params, cp15_regs, ARRAY_SIZE(cp15_regs)); 587 - 588 - if (likely(r)) { 589 - /* If we don't have an accessor, we should never get here! */ 590 - BUG_ON(!r->access); 591 - 592 - if (likely(r->access(vcpu, params, r))) { 593 - /* Skip instruction, since it was emulated */ 594 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 595 - } 596 - } else { 597 - /* If access function fails, it should complain. */ 598 - kvm_err("Unsupported guest CP15 access at: %08lx [%08lx]\n", 599 - *vcpu_pc(vcpu), *vcpu_cpsr(vcpu)); 600 - print_cp_instr(params); 601 - kvm_inject_undefined(vcpu); 602 - } 603 - 604 - return 1; 605 - } 606 - 607 - static struct coproc_params decode_64bit_hsr(struct kvm_vcpu *vcpu) 608 - { 609 - struct coproc_params params; 610 - 611 - params.CRn = (kvm_vcpu_get_hsr(vcpu) >> 1) & 0xf; 612 - params.Rt1 = (kvm_vcpu_get_hsr(vcpu) >> 5) & 0xf; 613 - params.is_write = ((kvm_vcpu_get_hsr(vcpu) & 1) == 0); 614 - params.is_64bit = true; 615 - 616 - params.Op1 = (kvm_vcpu_get_hsr(vcpu) >> 16) & 0xf; 617 - params.Op2 = 0; 618 - params.Rt2 = (kvm_vcpu_get_hsr(vcpu) >> 10) & 0xf; 619 - params.CRm = 0; 620 - 621 - return params; 622 - } 623 - 624 - /** 625 - * kvm_handle_cp15_64 -- handles a mrrc/mcrr trap on a guest CP15 access 626 - * @vcpu: The VCPU pointer 627 - * @run: The kvm_run struct 628 - */ 629 - int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) 630 - { 631 - struct coproc_params params = decode_64bit_hsr(vcpu); 632 - 633 - return emulate_cp15(vcpu, &params); 634 - } 635 - 636 - /** 637 - * kvm_handle_cp14_64 -- handles a mrrc/mcrr trap on a guest CP14 access 638 - * @vcpu: The VCPU pointer 639 - * @run: The kvm_run struct 640 - */ 641 - int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) 642 - { 643 - struct coproc_params params = decode_64bit_hsr(vcpu); 644 - 645 - /* raz_wi cp14 */ 646 - trap_raz_wi(vcpu, &params, NULL); 647 - 648 - /* handled */ 649 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 650 - return 1; 651 - } 652 - 653 - static void reset_coproc_regs(struct kvm_vcpu *vcpu, 654 - const struct coproc_reg *table, size_t num, 655 - unsigned long *bmap) 656 - { 657 - unsigned long i; 658 - 659 - for (i = 0; i < num; i++) 660 - if (table[i].reset) { 661 - int reg = table[i].reg; 662 - 663 - table[i].reset(vcpu, &table[i]); 664 - if (reg > 0 && reg < NR_CP15_REGS) { 665 - set_bit(reg, bmap); 666 - if (table[i].is_64bit) 667 - set_bit(reg + 1, bmap); 668 - } 669 - } 670 - } 671 - 672 - static struct coproc_params decode_32bit_hsr(struct kvm_vcpu *vcpu) 673 - { 674 - struct coproc_params params; 675 - 676 - params.CRm = (kvm_vcpu_get_hsr(vcpu) >> 1) & 0xf; 677 - params.Rt1 = (kvm_vcpu_get_hsr(vcpu) >> 5) & 0xf; 678 - params.is_write = ((kvm_vcpu_get_hsr(vcpu) & 1) == 0); 679 - params.is_64bit = false; 680 - 681 - params.CRn = (kvm_vcpu_get_hsr(vcpu) >> 10) & 0xf; 682 - params.Op1 = (kvm_vcpu_get_hsr(vcpu) >> 14) & 0x7; 683 - params.Op2 = (kvm_vcpu_get_hsr(vcpu) >> 17) & 0x7; 684 - params.Rt2 = 0; 685 - 686 - return params; 687 - } 688 - 689 - /** 690 - * kvm_handle_cp15_32 -- handles a mrc/mcr trap on a guest CP15 access 691 - * @vcpu: The VCPU pointer 692 - * @run: The kvm_run struct 693 - */ 694 - int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) 695 - { 696 - struct coproc_params params = decode_32bit_hsr(vcpu); 697 - return emulate_cp15(vcpu, &params); 698 - } 699 - 700 - /** 701 - * kvm_handle_cp14_32 -- handles a mrc/mcr trap on a guest CP14 access 702 - * @vcpu: The VCPU pointer 703 - * @run: The kvm_run struct 704 - */ 705 - int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run) 706 - { 707 - struct coproc_params params = decode_32bit_hsr(vcpu); 708 - 709 - /* raz_wi cp14 */ 710 - trap_raz_wi(vcpu, &params, NULL); 711 - 712 - /* handled */ 713 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 714 - return 1; 715 - } 716 - 717 - /****************************************************************************** 718 - * Userspace API 719 - *****************************************************************************/ 720 - 721 - static bool index_to_params(u64 id, struct coproc_params *params) 722 - { 723 - switch (id & KVM_REG_SIZE_MASK) { 724 - case KVM_REG_SIZE_U32: 725 - /* Any unused index bits means it's not valid. */ 726 - if (id & ~(KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK 727 - | KVM_REG_ARM_COPROC_MASK 728 - | KVM_REG_ARM_32_CRN_MASK 729 - | KVM_REG_ARM_CRM_MASK 730 - | KVM_REG_ARM_OPC1_MASK 731 - | KVM_REG_ARM_32_OPC2_MASK)) 732 - return false; 733 - 734 - params->is_64bit = false; 735 - params->CRn = ((id & KVM_REG_ARM_32_CRN_MASK) 736 - >> KVM_REG_ARM_32_CRN_SHIFT); 737 - params->CRm = ((id & KVM_REG_ARM_CRM_MASK) 738 - >> KVM_REG_ARM_CRM_SHIFT); 739 - params->Op1 = ((id & KVM_REG_ARM_OPC1_MASK) 740 - >> KVM_REG_ARM_OPC1_SHIFT); 741 - params->Op2 = ((id & KVM_REG_ARM_32_OPC2_MASK) 742 - >> KVM_REG_ARM_32_OPC2_SHIFT); 743 - return true; 744 - case KVM_REG_SIZE_U64: 745 - /* Any unused index bits means it's not valid. */ 746 - if (id & ~(KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK 747 - | KVM_REG_ARM_COPROC_MASK 748 - | KVM_REG_ARM_CRM_MASK 749 - | KVM_REG_ARM_OPC1_MASK)) 750 - return false; 751 - params->is_64bit = true; 752 - /* CRm to CRn: see cp15_to_index for details */ 753 - params->CRn = ((id & KVM_REG_ARM_CRM_MASK) 754 - >> KVM_REG_ARM_CRM_SHIFT); 755 - params->Op1 = ((id & KVM_REG_ARM_OPC1_MASK) 756 - >> KVM_REG_ARM_OPC1_SHIFT); 757 - params->Op2 = 0; 758 - params->CRm = 0; 759 - return true; 760 - default: 761 - return false; 762 - } 763 - } 764 - 765 - /* Decode an index value, and find the cp15 coproc_reg entry. */ 766 - static const struct coproc_reg *index_to_coproc_reg(struct kvm_vcpu *vcpu, 767 - u64 id) 768 - { 769 - size_t num; 770 - const struct coproc_reg *table, *r; 771 - struct coproc_params params; 772 - 773 - /* We only do cp15 for now. */ 774 - if ((id & KVM_REG_ARM_COPROC_MASK) >> KVM_REG_ARM_COPROC_SHIFT != 15) 775 - return NULL; 776 - 777 - if (!index_to_params(id, &params)) 778 - return NULL; 779 - 780 - table = get_target_table(vcpu->arch.target, &num); 781 - r = find_reg(&params, table, num); 782 - if (!r) 783 - r = find_reg(&params, cp15_regs, ARRAY_SIZE(cp15_regs)); 784 - 785 - /* Not saved in the cp15 array? */ 786 - if (r && !r->reg) 787 - r = NULL; 788 - 789 - return r; 790 - } 791 - 792 - /* 793 - * These are the invariant cp15 registers: we let the guest see the host 794 - * versions of these, so they're part of the guest state. 795 - * 796 - * A future CPU may provide a mechanism to present different values to 797 - * the guest, or a future kvm may trap them. 798 - */ 799 - /* Unfortunately, there's no register-argument for mrc, so generate. */ 800 - #define FUNCTION_FOR32(crn, crm, op1, op2, name) \ 801 - static void get_##name(struct kvm_vcpu *v, \ 802 - const struct coproc_reg *r) \ 803 - { \ 804 - u32 val; \ 805 - \ 806 - asm volatile("mrc p15, " __stringify(op1) \ 807 - ", %0, c" __stringify(crn) \ 808 - ", c" __stringify(crm) \ 809 - ", " __stringify(op2) "\n" : "=r" (val)); \ 810 - ((struct coproc_reg *)r)->val = val; \ 811 - } 812 - 813 - FUNCTION_FOR32(0, 0, 0, 0, MIDR) 814 - FUNCTION_FOR32(0, 0, 0, 1, CTR) 815 - FUNCTION_FOR32(0, 0, 0, 2, TCMTR) 816 - FUNCTION_FOR32(0, 0, 0, 3, TLBTR) 817 - FUNCTION_FOR32(0, 0, 0, 6, REVIDR) 818 - FUNCTION_FOR32(0, 1, 0, 0, ID_PFR0) 819 - FUNCTION_FOR32(0, 1, 0, 1, ID_PFR1) 820 - FUNCTION_FOR32(0, 1, 0, 2, ID_DFR0) 821 - FUNCTION_FOR32(0, 1, 0, 3, ID_AFR0) 822 - FUNCTION_FOR32(0, 1, 0, 4, ID_MMFR0) 823 - FUNCTION_FOR32(0, 1, 0, 5, ID_MMFR1) 824 - FUNCTION_FOR32(0, 1, 0, 6, ID_MMFR2) 825 - FUNCTION_FOR32(0, 1, 0, 7, ID_MMFR3) 826 - FUNCTION_FOR32(0, 2, 0, 0, ID_ISAR0) 827 - FUNCTION_FOR32(0, 2, 0, 1, ID_ISAR1) 828 - FUNCTION_FOR32(0, 2, 0, 2, ID_ISAR2) 829 - FUNCTION_FOR32(0, 2, 0, 3, ID_ISAR3) 830 - FUNCTION_FOR32(0, 2, 0, 4, ID_ISAR4) 831 - FUNCTION_FOR32(0, 2, 0, 5, ID_ISAR5) 832 - FUNCTION_FOR32(0, 0, 1, 1, CLIDR) 833 - FUNCTION_FOR32(0, 0, 1, 7, AIDR) 834 - 835 - /* ->val is filled in by kvm_invariant_coproc_table_init() */ 836 - static struct coproc_reg invariant_cp15[] = { 837 - { CRn( 0), CRm( 0), Op1( 0), Op2( 0), is32, NULL, get_MIDR }, 838 - { CRn( 0), CRm( 0), Op1( 0), Op2( 1), is32, NULL, get_CTR }, 839 - { CRn( 0), CRm( 0), Op1( 0), Op2( 2), is32, NULL, get_TCMTR }, 840 - { CRn( 0), CRm( 0), Op1( 0), Op2( 3), is32, NULL, get_TLBTR }, 841 - { CRn( 0), CRm( 0), Op1( 0), Op2( 6), is32, NULL, get_REVIDR }, 842 - 843 - { CRn( 0), CRm( 0), Op1( 1), Op2( 1), is32, NULL, get_CLIDR }, 844 - { CRn( 0), CRm( 0), Op1( 1), Op2( 7), is32, NULL, get_AIDR }, 845 - 846 - { CRn( 0), CRm( 1), Op1( 0), Op2( 0), is32, NULL, get_ID_PFR0 }, 847 - { CRn( 0), CRm( 1), Op1( 0), Op2( 1), is32, NULL, get_ID_PFR1 }, 848 - { CRn( 0), CRm( 1), Op1( 0), Op2( 2), is32, NULL, get_ID_DFR0 }, 849 - { CRn( 0), CRm( 1), Op1( 0), Op2( 3), is32, NULL, get_ID_AFR0 }, 850 - { CRn( 0), CRm( 1), Op1( 0), Op2( 4), is32, NULL, get_ID_MMFR0 }, 851 - { CRn( 0), CRm( 1), Op1( 0), Op2( 5), is32, NULL, get_ID_MMFR1 }, 852 - { CRn( 0), CRm( 1), Op1( 0), Op2( 6), is32, NULL, get_ID_MMFR2 }, 853 - { CRn( 0), CRm( 1), Op1( 0), Op2( 7), is32, NULL, get_ID_MMFR3 }, 854 - 855 - { CRn( 0), CRm( 2), Op1( 0), Op2( 0), is32, NULL, get_ID_ISAR0 }, 856 - { CRn( 0), CRm( 2), Op1( 0), Op2( 1), is32, NULL, get_ID_ISAR1 }, 857 - { CRn( 0), CRm( 2), Op1( 0), Op2( 2), is32, NULL, get_ID_ISAR2 }, 858 - { CRn( 0), CRm( 2), Op1( 0), Op2( 3), is32, NULL, get_ID_ISAR3 }, 859 - { CRn( 0), CRm( 2), Op1( 0), Op2( 4), is32, NULL, get_ID_ISAR4 }, 860 - { CRn( 0), CRm( 2), Op1( 0), Op2( 5), is32, NULL, get_ID_ISAR5 }, 861 - }; 862 - 863 - /* 864 - * Reads a register value from a userspace address to a kernel 865 - * variable. Make sure that register size matches sizeof(*__val). 866 - */ 867 - static int reg_from_user(void *val, const void __user *uaddr, u64 id) 868 - { 869 - if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0) 870 - return -EFAULT; 871 - return 0; 872 - } 873 - 874 - /* 875 - * Writes a register value to a userspace address from a kernel variable. 876 - * Make sure that register size matches sizeof(*__val). 877 - */ 878 - static int reg_to_user(void __user *uaddr, const void *val, u64 id) 879 - { 880 - if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0) 881 - return -EFAULT; 882 - return 0; 883 - } 884 - 885 - static int get_invariant_cp15(u64 id, void __user *uaddr) 886 - { 887 - struct coproc_params params; 888 - const struct coproc_reg *r; 889 - int ret; 890 - 891 - if (!index_to_params(id, &params)) 892 - return -ENOENT; 893 - 894 - r = find_reg(&params, invariant_cp15, ARRAY_SIZE(invariant_cp15)); 895 - if (!r) 896 - return -ENOENT; 897 - 898 - ret = -ENOENT; 899 - if (KVM_REG_SIZE(id) == 4) { 900 - u32 val = r->val; 901 - 902 - ret = reg_to_user(uaddr, &val, id); 903 - } else if (KVM_REG_SIZE(id) == 8) { 904 - ret = reg_to_user(uaddr, &r->val, id); 905 - } 906 - return ret; 907 - } 908 - 909 - static int set_invariant_cp15(u64 id, void __user *uaddr) 910 - { 911 - struct coproc_params params; 912 - const struct coproc_reg *r; 913 - int err; 914 - u64 val; 915 - 916 - if (!index_to_params(id, &params)) 917 - return -ENOENT; 918 - r = find_reg(&params, invariant_cp15, ARRAY_SIZE(invariant_cp15)); 919 - if (!r) 920 - return -ENOENT; 921 - 922 - err = -ENOENT; 923 - if (KVM_REG_SIZE(id) == 4) { 924 - u32 val32; 925 - 926 - err = reg_from_user(&val32, uaddr, id); 927 - if (!err) 928 - val = val32; 929 - } else if (KVM_REG_SIZE(id) == 8) { 930 - err = reg_from_user(&val, uaddr, id); 931 - } 932 - if (err) 933 - return err; 934 - 935 - /* This is what we mean by invariant: you can't change it. */ 936 - if (r->val != val) 937 - return -EINVAL; 938 - 939 - return 0; 940 - } 941 - 942 - static bool is_valid_cache(u32 val) 943 - { 944 - u32 level, ctype; 945 - 946 - if (val >= CSSELR_MAX) 947 - return false; 948 - 949 - /* Bottom bit is Instruction or Data bit. Next 3 bits are level. */ 950 - level = (val >> 1); 951 - ctype = (cache_levels >> (level * 3)) & 7; 952 - 953 - switch (ctype) { 954 - case 0: /* No cache */ 955 - return false; 956 - case 1: /* Instruction cache only */ 957 - return (val & 1); 958 - case 2: /* Data cache only */ 959 - case 4: /* Unified cache */ 960 - return !(val & 1); 961 - case 3: /* Separate instruction and data caches */ 962 - return true; 963 - default: /* Reserved: we can't know instruction or data. */ 964 - return false; 965 - } 966 - } 967 - 968 - /* Which cache CCSIDR represents depends on CSSELR value. */ 969 - static u32 get_ccsidr(u32 csselr) 970 - { 971 - u32 ccsidr; 972 - 973 - /* Make sure noone else changes CSSELR during this! */ 974 - local_irq_disable(); 975 - /* Put value into CSSELR */ 976 - asm volatile("mcr p15, 2, %0, c0, c0, 0" : : "r" (csselr)); 977 - isb(); 978 - /* Read result out of CCSIDR */ 979 - asm volatile("mrc p15, 1, %0, c0, c0, 0" : "=r" (ccsidr)); 980 - local_irq_enable(); 981 - 982 - return ccsidr; 983 - } 984 - 985 - static int demux_c15_get(u64 id, void __user *uaddr) 986 - { 987 - u32 val; 988 - u32 __user *uval = uaddr; 989 - 990 - /* Fail if we have unknown bits set. */ 991 - if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK 992 - | ((1 << KVM_REG_ARM_COPROC_SHIFT)-1))) 993 - return -ENOENT; 994 - 995 - switch (id & KVM_REG_ARM_DEMUX_ID_MASK) { 996 - case KVM_REG_ARM_DEMUX_ID_CCSIDR: 997 - if (KVM_REG_SIZE(id) != 4) 998 - return -ENOENT; 999 - val = (id & KVM_REG_ARM_DEMUX_VAL_MASK) 1000 - >> KVM_REG_ARM_DEMUX_VAL_SHIFT; 1001 - if (!is_valid_cache(val)) 1002 - return -ENOENT; 1003 - 1004 - return put_user(get_ccsidr(val), uval); 1005 - default: 1006 - return -ENOENT; 1007 - } 1008 - } 1009 - 1010 - static int demux_c15_set(u64 id, void __user *uaddr) 1011 - { 1012 - u32 val, newval; 1013 - u32 __user *uval = uaddr; 1014 - 1015 - /* Fail if we have unknown bits set. */ 1016 - if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK 1017 - | ((1 << KVM_REG_ARM_COPROC_SHIFT)-1))) 1018 - return -ENOENT; 1019 - 1020 - switch (id & KVM_REG_ARM_DEMUX_ID_MASK) { 1021 - case KVM_REG_ARM_DEMUX_ID_CCSIDR: 1022 - if (KVM_REG_SIZE(id) != 4) 1023 - return -ENOENT; 1024 - val = (id & KVM_REG_ARM_DEMUX_VAL_MASK) 1025 - >> KVM_REG_ARM_DEMUX_VAL_SHIFT; 1026 - if (!is_valid_cache(val)) 1027 - return -ENOENT; 1028 - 1029 - if (get_user(newval, uval)) 1030 - return -EFAULT; 1031 - 1032 - /* This is also invariant: you can't change it. */ 1033 - if (newval != get_ccsidr(val)) 1034 - return -EINVAL; 1035 - return 0; 1036 - default: 1037 - return -ENOENT; 1038 - } 1039 - } 1040 - 1041 - #ifdef CONFIG_VFPv3 1042 - static const int vfp_sysregs[] = { KVM_REG_ARM_VFP_FPEXC, 1043 - KVM_REG_ARM_VFP_FPSCR, 1044 - KVM_REG_ARM_VFP_FPINST, 1045 - KVM_REG_ARM_VFP_FPINST2, 1046 - KVM_REG_ARM_VFP_MVFR0, 1047 - KVM_REG_ARM_VFP_MVFR1, 1048 - KVM_REG_ARM_VFP_FPSID }; 1049 - 1050 - static unsigned int num_fp_regs(void) 1051 - { 1052 - if (((fmrx(MVFR0) & MVFR0_A_SIMD_MASK) >> MVFR0_A_SIMD_BIT) == 2) 1053 - return 32; 1054 - else 1055 - return 16; 1056 - } 1057 - 1058 - static unsigned int num_vfp_regs(void) 1059 - { 1060 - /* Normal FP regs + control regs. */ 1061 - return num_fp_regs() + ARRAY_SIZE(vfp_sysregs); 1062 - } 1063 - 1064 - static int copy_vfp_regids(u64 __user *uindices) 1065 - { 1066 - unsigned int i; 1067 - const u64 u32reg = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP; 1068 - const u64 u64reg = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP; 1069 - 1070 - for (i = 0; i < num_fp_regs(); i++) { 1071 - if (put_user((u64reg | KVM_REG_ARM_VFP_BASE_REG) + i, 1072 - uindices)) 1073 - return -EFAULT; 1074 - uindices++; 1075 - } 1076 - 1077 - for (i = 0; i < ARRAY_SIZE(vfp_sysregs); i++) { 1078 - if (put_user(u32reg | vfp_sysregs[i], uindices)) 1079 - return -EFAULT; 1080 - uindices++; 1081 - } 1082 - 1083 - return num_vfp_regs(); 1084 - } 1085 - 1086 - static int vfp_get_reg(const struct kvm_vcpu *vcpu, u64 id, void __user *uaddr) 1087 - { 1088 - u32 vfpid = (id & KVM_REG_ARM_VFP_MASK); 1089 - u32 val; 1090 - 1091 - /* Fail if we have unknown bits set. */ 1092 - if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK 1093 - | ((1 << KVM_REG_ARM_COPROC_SHIFT)-1))) 1094 - return -ENOENT; 1095 - 1096 - if (vfpid < num_fp_regs()) { 1097 - if (KVM_REG_SIZE(id) != 8) 1098 - return -ENOENT; 1099 - return reg_to_user(uaddr, &vcpu->arch.ctxt.vfp.fpregs[vfpid], 1100 - id); 1101 - } 1102 - 1103 - /* FP control registers are all 32 bit. */ 1104 - if (KVM_REG_SIZE(id) != 4) 1105 - return -ENOENT; 1106 - 1107 - switch (vfpid) { 1108 - case KVM_REG_ARM_VFP_FPEXC: 1109 - return reg_to_user(uaddr, &vcpu->arch.ctxt.vfp.fpexc, id); 1110 - case KVM_REG_ARM_VFP_FPSCR: 1111 - return reg_to_user(uaddr, &vcpu->arch.ctxt.vfp.fpscr, id); 1112 - case KVM_REG_ARM_VFP_FPINST: 1113 - return reg_to_user(uaddr, &vcpu->arch.ctxt.vfp.fpinst, id); 1114 - case KVM_REG_ARM_VFP_FPINST2: 1115 - return reg_to_user(uaddr, &vcpu->arch.ctxt.vfp.fpinst2, id); 1116 - case KVM_REG_ARM_VFP_MVFR0: 1117 - val = fmrx(MVFR0); 1118 - return reg_to_user(uaddr, &val, id); 1119 - case KVM_REG_ARM_VFP_MVFR1: 1120 - val = fmrx(MVFR1); 1121 - return reg_to_user(uaddr, &val, id); 1122 - case KVM_REG_ARM_VFP_FPSID: 1123 - val = fmrx(FPSID); 1124 - return reg_to_user(uaddr, &val, id); 1125 - default: 1126 - return -ENOENT; 1127 - } 1128 - } 1129 - 1130 - static int vfp_set_reg(struct kvm_vcpu *vcpu, u64 id, const void __user *uaddr) 1131 - { 1132 - u32 vfpid = (id & KVM_REG_ARM_VFP_MASK); 1133 - u32 val; 1134 - 1135 - /* Fail if we have unknown bits set. */ 1136 - if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK 1137 - | ((1 << KVM_REG_ARM_COPROC_SHIFT)-1))) 1138 - return -ENOENT; 1139 - 1140 - if (vfpid < num_fp_regs()) { 1141 - if (KVM_REG_SIZE(id) != 8) 1142 - return -ENOENT; 1143 - return reg_from_user(&vcpu->arch.ctxt.vfp.fpregs[vfpid], 1144 - uaddr, id); 1145 - } 1146 - 1147 - /* FP control registers are all 32 bit. */ 1148 - if (KVM_REG_SIZE(id) != 4) 1149 - return -ENOENT; 1150 - 1151 - switch (vfpid) { 1152 - case KVM_REG_ARM_VFP_FPEXC: 1153 - return reg_from_user(&vcpu->arch.ctxt.vfp.fpexc, uaddr, id); 1154 - case KVM_REG_ARM_VFP_FPSCR: 1155 - return reg_from_user(&vcpu->arch.ctxt.vfp.fpscr, uaddr, id); 1156 - case KVM_REG_ARM_VFP_FPINST: 1157 - return reg_from_user(&vcpu->arch.ctxt.vfp.fpinst, uaddr, id); 1158 - case KVM_REG_ARM_VFP_FPINST2: 1159 - return reg_from_user(&vcpu->arch.ctxt.vfp.fpinst2, uaddr, id); 1160 - /* These are invariant. */ 1161 - case KVM_REG_ARM_VFP_MVFR0: 1162 - if (reg_from_user(&val, uaddr, id)) 1163 - return -EFAULT; 1164 - if (val != fmrx(MVFR0)) 1165 - return -EINVAL; 1166 - return 0; 1167 - case KVM_REG_ARM_VFP_MVFR1: 1168 - if (reg_from_user(&val, uaddr, id)) 1169 - return -EFAULT; 1170 - if (val != fmrx(MVFR1)) 1171 - return -EINVAL; 1172 - return 0; 1173 - case KVM_REG_ARM_VFP_FPSID: 1174 - if (reg_from_user(&val, uaddr, id)) 1175 - return -EFAULT; 1176 - if (val != fmrx(FPSID)) 1177 - return -EINVAL; 1178 - return 0; 1179 - default: 1180 - return -ENOENT; 1181 - } 1182 - } 1183 - #else /* !CONFIG_VFPv3 */ 1184 - static unsigned int num_vfp_regs(void) 1185 - { 1186 - return 0; 1187 - } 1188 - 1189 - static int copy_vfp_regids(u64 __user *uindices) 1190 - { 1191 - return 0; 1192 - } 1193 - 1194 - static int vfp_get_reg(const struct kvm_vcpu *vcpu, u64 id, void __user *uaddr) 1195 - { 1196 - return -ENOENT; 1197 - } 1198 - 1199 - static int vfp_set_reg(struct kvm_vcpu *vcpu, u64 id, const void __user *uaddr) 1200 - { 1201 - return -ENOENT; 1202 - } 1203 - #endif /* !CONFIG_VFPv3 */ 1204 - 1205 - int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 1206 - { 1207 - const struct coproc_reg *r; 1208 - void __user *uaddr = (void __user *)(long)reg->addr; 1209 - int ret; 1210 - 1211 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX) 1212 - return demux_c15_get(reg->id, uaddr); 1213 - 1214 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_VFP) 1215 - return vfp_get_reg(vcpu, reg->id, uaddr); 1216 - 1217 - r = index_to_coproc_reg(vcpu, reg->id); 1218 - if (!r) 1219 - return get_invariant_cp15(reg->id, uaddr); 1220 - 1221 - ret = -ENOENT; 1222 - if (KVM_REG_SIZE(reg->id) == 8) { 1223 - u64 val; 1224 - 1225 - val = vcpu_cp15_reg64_get(vcpu, r); 1226 - ret = reg_to_user(uaddr, &val, reg->id); 1227 - } else if (KVM_REG_SIZE(reg->id) == 4) { 1228 - ret = reg_to_user(uaddr, &vcpu_cp15(vcpu, r->reg), reg->id); 1229 - } 1230 - 1231 - return ret; 1232 - } 1233 - 1234 - int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 1235 - { 1236 - const struct coproc_reg *r; 1237 - void __user *uaddr = (void __user *)(long)reg->addr; 1238 - int ret; 1239 - 1240 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX) 1241 - return demux_c15_set(reg->id, uaddr); 1242 - 1243 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_VFP) 1244 - return vfp_set_reg(vcpu, reg->id, uaddr); 1245 - 1246 - r = index_to_coproc_reg(vcpu, reg->id); 1247 - if (!r) 1248 - return set_invariant_cp15(reg->id, uaddr); 1249 - 1250 - ret = -ENOENT; 1251 - if (KVM_REG_SIZE(reg->id) == 8) { 1252 - u64 val; 1253 - 1254 - ret = reg_from_user(&val, uaddr, reg->id); 1255 - if (!ret) 1256 - vcpu_cp15_reg64_set(vcpu, r, val); 1257 - } else if (KVM_REG_SIZE(reg->id) == 4) { 1258 - ret = reg_from_user(&vcpu_cp15(vcpu, r->reg), uaddr, reg->id); 1259 - } 1260 - 1261 - return ret; 1262 - } 1263 - 1264 - static unsigned int num_demux_regs(void) 1265 - { 1266 - unsigned int i, count = 0; 1267 - 1268 - for (i = 0; i < CSSELR_MAX; i++) 1269 - if (is_valid_cache(i)) 1270 - count++; 1271 - 1272 - return count; 1273 - } 1274 - 1275 - static int write_demux_regids(u64 __user *uindices) 1276 - { 1277 - u64 val = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX; 1278 - unsigned int i; 1279 - 1280 - val |= KVM_REG_ARM_DEMUX_ID_CCSIDR; 1281 - for (i = 0; i < CSSELR_MAX; i++) { 1282 - if (!is_valid_cache(i)) 1283 - continue; 1284 - if (put_user(val | i, uindices)) 1285 - return -EFAULT; 1286 - uindices++; 1287 - } 1288 - return 0; 1289 - } 1290 - 1291 - static u64 cp15_to_index(const struct coproc_reg *reg) 1292 - { 1293 - u64 val = KVM_REG_ARM | (15 << KVM_REG_ARM_COPROC_SHIFT); 1294 - if (reg->is_64bit) { 1295 - val |= KVM_REG_SIZE_U64; 1296 - val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT); 1297 - /* 1298 - * CRn always denotes the primary coproc. reg. nr. for the 1299 - * in-kernel representation, but the user space API uses the 1300 - * CRm for the encoding, because it is modelled after the 1301 - * MRRC/MCRR instructions: see the ARM ARM rev. c page 1302 - * B3-1445 1303 - */ 1304 - val |= (reg->CRn << KVM_REG_ARM_CRM_SHIFT); 1305 - } else { 1306 - val |= KVM_REG_SIZE_U32; 1307 - val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT); 1308 - val |= (reg->Op2 << KVM_REG_ARM_32_OPC2_SHIFT); 1309 - val |= (reg->CRm << KVM_REG_ARM_CRM_SHIFT); 1310 - val |= (reg->CRn << KVM_REG_ARM_32_CRN_SHIFT); 1311 - } 1312 - return val; 1313 - } 1314 - 1315 - static bool copy_reg_to_user(const struct coproc_reg *reg, u64 __user **uind) 1316 - { 1317 - if (!*uind) 1318 - return true; 1319 - 1320 - if (put_user(cp15_to_index(reg), *uind)) 1321 - return false; 1322 - 1323 - (*uind)++; 1324 - return true; 1325 - } 1326 - 1327 - /* Assumed ordered tables, see kvm_coproc_table_init. */ 1328 - static int walk_cp15(struct kvm_vcpu *vcpu, u64 __user *uind) 1329 - { 1330 - const struct coproc_reg *i1, *i2, *end1, *end2; 1331 - unsigned int total = 0; 1332 - size_t num; 1333 - 1334 - /* We check for duplicates here, to allow arch-specific overrides. */ 1335 - i1 = get_target_table(vcpu->arch.target, &num); 1336 - end1 = i1 + num; 1337 - i2 = cp15_regs; 1338 - end2 = cp15_regs + ARRAY_SIZE(cp15_regs); 1339 - 1340 - BUG_ON(i1 == end1 || i2 == end2); 1341 - 1342 - /* Walk carefully, as both tables may refer to the same register. */ 1343 - while (i1 || i2) { 1344 - int cmp = cmp_reg(i1, i2); 1345 - /* target-specific overrides generic entry. */ 1346 - if (cmp <= 0) { 1347 - /* Ignore registers we trap but don't save. */ 1348 - if (i1->reg) { 1349 - if (!copy_reg_to_user(i1, &uind)) 1350 - return -EFAULT; 1351 - total++; 1352 - } 1353 - } else { 1354 - /* Ignore registers we trap but don't save. */ 1355 - if (i2->reg) { 1356 - if (!copy_reg_to_user(i2, &uind)) 1357 - return -EFAULT; 1358 - total++; 1359 - } 1360 - } 1361 - 1362 - if (cmp <= 0 && ++i1 == end1) 1363 - i1 = NULL; 1364 - if (cmp >= 0 && ++i2 == end2) 1365 - i2 = NULL; 1366 - } 1367 - return total; 1368 - } 1369 - 1370 - unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu) 1371 - { 1372 - return ARRAY_SIZE(invariant_cp15) 1373 - + num_demux_regs() 1374 - + num_vfp_regs() 1375 - + walk_cp15(vcpu, (u64 __user *)NULL); 1376 - } 1377 - 1378 - int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) 1379 - { 1380 - unsigned int i; 1381 - int err; 1382 - 1383 - /* Then give them all the invariant registers' indices. */ 1384 - for (i = 0; i < ARRAY_SIZE(invariant_cp15); i++) { 1385 - if (put_user(cp15_to_index(&invariant_cp15[i]), uindices)) 1386 - return -EFAULT; 1387 - uindices++; 1388 - } 1389 - 1390 - err = walk_cp15(vcpu, uindices); 1391 - if (err < 0) 1392 - return err; 1393 - uindices += err; 1394 - 1395 - err = copy_vfp_regids(uindices); 1396 - if (err < 0) 1397 - return err; 1398 - uindices += err; 1399 - 1400 - return write_demux_regids(uindices); 1401 - } 1402 - 1403 - void kvm_coproc_table_init(void) 1404 - { 1405 - unsigned int i; 1406 - 1407 - /* Make sure tables are unique and in order. */ 1408 - BUG_ON(check_reg_table(cp15_regs, ARRAY_SIZE(cp15_regs))); 1409 - BUG_ON(check_reg_table(invariant_cp15, ARRAY_SIZE(invariant_cp15))); 1410 - 1411 - /* We abuse the reset function to overwrite the table itself. */ 1412 - for (i = 0; i < ARRAY_SIZE(invariant_cp15); i++) 1413 - invariant_cp15[i].reset(NULL, &invariant_cp15[i]); 1414 - 1415 - /* 1416 - * CLIDR format is awkward, so clean it up. See ARM B4.1.20: 1417 - * 1418 - * If software reads the Cache Type fields from Ctype1 1419 - * upwards, once it has seen a value of 0b000, no caches 1420 - * exist at further-out levels of the hierarchy. So, for 1421 - * example, if Ctype3 is the first Cache Type field with a 1422 - * value of 0b000, the values of Ctype4 to Ctype7 must be 1423 - * ignored. 1424 - */ 1425 - asm volatile("mrc p15, 1, %0, c0, c0, 1" : "=r" (cache_levels)); 1426 - for (i = 0; i < 7; i++) 1427 - if (((cache_levels >> (i*3)) & 7) == 0) 1428 - break; 1429 - /* Clear all higher bits. */ 1430 - cache_levels &= (1 << (i*3))-1; 1431 - } 1432 - 1433 - /** 1434 - * kvm_reset_coprocs - sets cp15 registers to reset value 1435 - * @vcpu: The VCPU pointer 1436 - * 1437 - * This function finds the right table above and sets the registers on the 1438 - * virtual CPU struct to their architecturally defined reset values. 1439 - */ 1440 - void kvm_reset_coprocs(struct kvm_vcpu *vcpu) 1441 - { 1442 - size_t num; 1443 - const struct coproc_reg *table; 1444 - DECLARE_BITMAP(bmap, NR_CP15_REGS) = { 0, }; 1445 - 1446 - /* Generic chip reset first (so target could override). */ 1447 - reset_coproc_regs(vcpu, cp15_regs, ARRAY_SIZE(cp15_regs), bmap); 1448 - 1449 - table = get_target_table(vcpu->arch.target, &num); 1450 - reset_coproc_regs(vcpu, table, num, bmap); 1451 - 1452 - for (num = 1; num < NR_CP15_REGS; num++) 1453 - WARN(!test_bit(num, bmap), 1454 - "Didn't reset vcpu_cp15(vcpu, %zi)", num); 1455 - }
-130
arch/arm/kvm/coproc.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Authors: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #ifndef __ARM_KVM_COPROC_LOCAL_H__ 8 - #define __ARM_KVM_COPROC_LOCAL_H__ 9 - 10 - struct coproc_params { 11 - unsigned long CRn; 12 - unsigned long CRm; 13 - unsigned long Op1; 14 - unsigned long Op2; 15 - unsigned long Rt1; 16 - unsigned long Rt2; 17 - bool is_64bit; 18 - bool is_write; 19 - }; 20 - 21 - struct coproc_reg { 22 - /* MRC/MCR/MRRC/MCRR instruction which accesses it. */ 23 - unsigned long CRn; 24 - unsigned long CRm; 25 - unsigned long Op1; 26 - unsigned long Op2; 27 - 28 - bool is_64bit; 29 - 30 - /* Trapped access from guest, if non-NULL. */ 31 - bool (*access)(struct kvm_vcpu *, 32 - const struct coproc_params *, 33 - const struct coproc_reg *); 34 - 35 - /* Initialization for vcpu. */ 36 - void (*reset)(struct kvm_vcpu *, const struct coproc_reg *); 37 - 38 - /* Index into vcpu_cp15(vcpu, ...), or 0 if we don't need to save it. */ 39 - unsigned long reg; 40 - 41 - /* Value (usually reset value) */ 42 - u64 val; 43 - }; 44 - 45 - static inline void print_cp_instr(const struct coproc_params *p) 46 - { 47 - /* Look, we even formatted it for you to paste into the table! */ 48 - if (p->is_64bit) { 49 - kvm_pr_unimpl(" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n", 50 - p->CRn, p->Op1, p->is_write ? "write" : "read"); 51 - } else { 52 - kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32," 53 - " func_%s },\n", 54 - p->CRn, p->CRm, p->Op1, p->Op2, 55 - p->is_write ? "write" : "read"); 56 - } 57 - } 58 - 59 - static inline bool ignore_write(struct kvm_vcpu *vcpu, 60 - const struct coproc_params *p) 61 - { 62 - return true; 63 - } 64 - 65 - static inline bool read_zero(struct kvm_vcpu *vcpu, 66 - const struct coproc_params *p) 67 - { 68 - *vcpu_reg(vcpu, p->Rt1) = 0; 69 - return true; 70 - } 71 - 72 - /* Reset functions */ 73 - static inline void reset_unknown(struct kvm_vcpu *vcpu, 74 - const struct coproc_reg *r) 75 - { 76 - BUG_ON(!r->reg); 77 - BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15)); 78 - vcpu_cp15(vcpu, r->reg) = 0xdecafbad; 79 - } 80 - 81 - static inline void reset_val(struct kvm_vcpu *vcpu, const struct coproc_reg *r) 82 - { 83 - BUG_ON(!r->reg); 84 - BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15)); 85 - vcpu_cp15(vcpu, r->reg) = r->val; 86 - } 87 - 88 - static inline void reset_unknown64(struct kvm_vcpu *vcpu, 89 - const struct coproc_reg *r) 90 - { 91 - BUG_ON(!r->reg); 92 - BUG_ON(r->reg + 1 >= ARRAY_SIZE(vcpu->arch.ctxt.cp15)); 93 - 94 - vcpu_cp15(vcpu, r->reg) = 0xdecafbad; 95 - vcpu_cp15(vcpu, r->reg+1) = 0xd0c0ffee; 96 - } 97 - 98 - static inline int cmp_reg(const struct coproc_reg *i1, 99 - const struct coproc_reg *i2) 100 - { 101 - BUG_ON(i1 == i2); 102 - if (!i1) 103 - return 1; 104 - else if (!i2) 105 - return -1; 106 - if (i1->CRn != i2->CRn) 107 - return i1->CRn - i2->CRn; 108 - if (i1->CRm != i2->CRm) 109 - return i1->CRm - i2->CRm; 110 - if (i1->Op1 != i2->Op1) 111 - return i1->Op1 - i2->Op1; 112 - if (i1->Op2 != i2->Op2) 113 - return i1->Op2 - i2->Op2; 114 - return i2->is_64bit - i1->is_64bit; 115 - } 116 - 117 - 118 - #define CRn(_x) .CRn = _x 119 - #define CRm(_x) .CRm = _x 120 - #define CRm64(_x) .CRn = _x, .CRm = 0 121 - #define Op1(_x) .Op1 = _x 122 - #define Op2(_x) .Op2 = _x 123 - #define is64 .is_64bit = true 124 - #define is32 .is_64bit = false 125 - 126 - bool access_vm_reg(struct kvm_vcpu *vcpu, 127 - const struct coproc_params *p, 128 - const struct coproc_reg *r); 129 - 130 - #endif /* __ARM_KVM_COPROC_LOCAL_H__ */
-39
arch/arm/kvm/coproc_a15.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Authors: Rusty Russell <rusty@rustcorp.au> 5 - * Christoffer Dall <c.dall@virtualopensystems.com> 6 - */ 7 - #include <linux/kvm_host.h> 8 - #include <asm/kvm_coproc.h> 9 - #include <asm/kvm_emulate.h> 10 - #include <linux/init.h> 11 - 12 - #include "coproc.h" 13 - 14 - /* 15 - * A15-specific CP15 registers. 16 - * CRn denotes the primary register number, but is copied to the CRm in the 17 - * user space API for 64-bit register access in line with the terminology used 18 - * in the ARM ARM. 19 - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit 20 - * registers preceding 32-bit ones. 21 - */ 22 - static const struct coproc_reg a15_regs[] = { 23 - /* SCTLR: swapped by interrupt.S. */ 24 - { CRn( 1), CRm( 0), Op1( 0), Op2( 0), is32, 25 - access_vm_reg, reset_val, c1_SCTLR, 0x00C50078 }, 26 - }; 27 - 28 - static struct kvm_coproc_target_table a15_target_table = { 29 - .target = KVM_ARM_TARGET_CORTEX_A15, 30 - .table = a15_regs, 31 - .num = ARRAY_SIZE(a15_regs), 32 - }; 33 - 34 - static int __init coproc_a15_init(void) 35 - { 36 - kvm_register_target_coproc_table(&a15_target_table); 37 - return 0; 38 - } 39 - late_initcall(coproc_a15_init);
-42
arch/arm/kvm/coproc_a7.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Copyright (C) 2013 - ARM Ltd 5 - * 6 - * Authors: Rusty Russell <rusty@rustcorp.au> 7 - * Christoffer Dall <c.dall@virtualopensystems.com> 8 - * Jonathan Austin <jonathan.austin@arm.com> 9 - */ 10 - #include <linux/kvm_host.h> 11 - #include <asm/kvm_coproc.h> 12 - #include <asm/kvm_emulate.h> 13 - #include <linux/init.h> 14 - 15 - #include "coproc.h" 16 - 17 - /* 18 - * Cortex-A7 specific CP15 registers. 19 - * CRn denotes the primary register number, but is copied to the CRm in the 20 - * user space API for 64-bit register access in line with the terminology used 21 - * in the ARM ARM. 22 - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit 23 - * registers preceding 32-bit ones. 24 - */ 25 - static const struct coproc_reg a7_regs[] = { 26 - /* SCTLR: swapped by interrupt.S. */ 27 - { CRn( 1), CRm( 0), Op1( 0), Op2( 0), is32, 28 - access_vm_reg, reset_val, c1_SCTLR, 0x00C50878 }, 29 - }; 30 - 31 - static struct kvm_coproc_target_table a7_target_table = { 32 - .target = KVM_ARM_TARGET_CORTEX_A7, 33 - .table = a7_regs, 34 - .num = ARRAY_SIZE(a7_regs), 35 - }; 36 - 37 - static int __init coproc_a7_init(void) 38 - { 39 - kvm_register_target_coproc_table(&a7_target_table); 40 - return 0; 41 - } 42 - late_initcall(coproc_a7_init);
-166
arch/arm/kvm/emulate.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/mm.h> 8 - #include <linux/kvm_host.h> 9 - #include <asm/kvm_arm.h> 10 - #include <asm/kvm_emulate.h> 11 - #include <asm/opcodes.h> 12 - #include <trace/events/kvm.h> 13 - 14 - #include "trace.h" 15 - 16 - #define VCPU_NR_MODES 6 17 - #define VCPU_REG_OFFSET_USR 0 18 - #define VCPU_REG_OFFSET_FIQ 1 19 - #define VCPU_REG_OFFSET_IRQ 2 20 - #define VCPU_REG_OFFSET_SVC 3 21 - #define VCPU_REG_OFFSET_ABT 4 22 - #define VCPU_REG_OFFSET_UND 5 23 - #define REG_OFFSET(_reg) \ 24 - (offsetof(struct kvm_regs, _reg) / sizeof(u32)) 25 - 26 - #define USR_REG_OFFSET(_num) REG_OFFSET(usr_regs.uregs[_num]) 27 - 28 - static const unsigned long vcpu_reg_offsets[VCPU_NR_MODES][15] = { 29 - /* USR/SYS Registers */ 30 - [VCPU_REG_OFFSET_USR] = { 31 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 32 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 33 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 34 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 35 - USR_REG_OFFSET(12), USR_REG_OFFSET(13), USR_REG_OFFSET(14), 36 - }, 37 - 38 - /* FIQ Registers */ 39 - [VCPU_REG_OFFSET_FIQ] = { 40 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 41 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 42 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), 43 - REG_OFFSET(fiq_regs[0]), /* r8 */ 44 - REG_OFFSET(fiq_regs[1]), /* r9 */ 45 - REG_OFFSET(fiq_regs[2]), /* r10 */ 46 - REG_OFFSET(fiq_regs[3]), /* r11 */ 47 - REG_OFFSET(fiq_regs[4]), /* r12 */ 48 - REG_OFFSET(fiq_regs[5]), /* r13 */ 49 - REG_OFFSET(fiq_regs[6]), /* r14 */ 50 - }, 51 - 52 - /* IRQ Registers */ 53 - [VCPU_REG_OFFSET_IRQ] = { 54 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 55 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 56 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 57 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 58 - USR_REG_OFFSET(12), 59 - REG_OFFSET(irq_regs[0]), /* r13 */ 60 - REG_OFFSET(irq_regs[1]), /* r14 */ 61 - }, 62 - 63 - /* SVC Registers */ 64 - [VCPU_REG_OFFSET_SVC] = { 65 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 66 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 67 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 68 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 69 - USR_REG_OFFSET(12), 70 - REG_OFFSET(svc_regs[0]), /* r13 */ 71 - REG_OFFSET(svc_regs[1]), /* r14 */ 72 - }, 73 - 74 - /* ABT Registers */ 75 - [VCPU_REG_OFFSET_ABT] = { 76 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 77 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 78 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 79 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 80 - USR_REG_OFFSET(12), 81 - REG_OFFSET(abt_regs[0]), /* r13 */ 82 - REG_OFFSET(abt_regs[1]), /* r14 */ 83 - }, 84 - 85 - /* UND Registers */ 86 - [VCPU_REG_OFFSET_UND] = { 87 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 88 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 89 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 90 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 91 - USR_REG_OFFSET(12), 92 - REG_OFFSET(und_regs[0]), /* r13 */ 93 - REG_OFFSET(und_regs[1]), /* r14 */ 94 - }, 95 - }; 96 - 97 - /* 98 - * Return a pointer to the register number valid in the current mode of 99 - * the virtual CPU. 100 - */ 101 - unsigned long *vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num) 102 - { 103 - unsigned long *reg_array = (unsigned long *)&vcpu->arch.ctxt.gp_regs; 104 - unsigned long mode = *vcpu_cpsr(vcpu) & MODE_MASK; 105 - 106 - switch (mode) { 107 - case USR_MODE...SVC_MODE: 108 - mode &= ~MODE32_BIT; /* 0 ... 3 */ 109 - break; 110 - 111 - case ABT_MODE: 112 - mode = VCPU_REG_OFFSET_ABT; 113 - break; 114 - 115 - case UND_MODE: 116 - mode = VCPU_REG_OFFSET_UND; 117 - break; 118 - 119 - case SYSTEM_MODE: 120 - mode = VCPU_REG_OFFSET_USR; 121 - break; 122 - 123 - default: 124 - BUG(); 125 - } 126 - 127 - return reg_array + vcpu_reg_offsets[mode][reg_num]; 128 - } 129 - 130 - /* 131 - * Return the SPSR for the current mode of the virtual CPU. 132 - */ 133 - unsigned long *__vcpu_spsr(struct kvm_vcpu *vcpu) 134 - { 135 - unsigned long mode = *vcpu_cpsr(vcpu) & MODE_MASK; 136 - switch (mode) { 137 - case SVC_MODE: 138 - return &vcpu->arch.ctxt.gp_regs.KVM_ARM_SVC_spsr; 139 - case ABT_MODE: 140 - return &vcpu->arch.ctxt.gp_regs.KVM_ARM_ABT_spsr; 141 - case UND_MODE: 142 - return &vcpu->arch.ctxt.gp_regs.KVM_ARM_UND_spsr; 143 - case IRQ_MODE: 144 - return &vcpu->arch.ctxt.gp_regs.KVM_ARM_IRQ_spsr; 145 - case FIQ_MODE: 146 - return &vcpu->arch.ctxt.gp_regs.KVM_ARM_FIQ_spsr; 147 - default: 148 - BUG(); 149 - } 150 - } 151 - 152 - /****************************************************************************** 153 - * Inject exceptions into the guest 154 - */ 155 - 156 - /** 157 - * kvm_inject_vabt - inject an async abort / SError into the guest 158 - * @vcpu: The VCPU to receive the exception 159 - * 160 - * It is assumed that this code is called from the VCPU thread and that the 161 - * VCPU therefore is not currently executing guest code. 162 - */ 163 - void kvm_inject_vabt(struct kvm_vcpu *vcpu) 164 - { 165 - *vcpu_hcr(vcpu) |= HCR_VA; 166 - }
-387
arch/arm/kvm/guest.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/errno.h> 8 - #include <linux/err.h> 9 - #include <linux/kvm_host.h> 10 - #include <linux/module.h> 11 - #include <linux/vmalloc.h> 12 - #include <linux/fs.h> 13 - #include <kvm/arm_psci.h> 14 - #include <asm/cputype.h> 15 - #include <linux/uaccess.h> 16 - #include <asm/kvm.h> 17 - #include <asm/kvm_emulate.h> 18 - #include <asm/kvm_coproc.h> 19 - 20 - #define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM } 21 - #define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU } 22 - 23 - struct kvm_stats_debugfs_item debugfs_entries[] = { 24 - VCPU_STAT(halt_successful_poll), 25 - VCPU_STAT(halt_attempted_poll), 26 - VCPU_STAT(halt_poll_invalid), 27 - VCPU_STAT(halt_wakeup), 28 - VCPU_STAT(hvc_exit_stat), 29 - VCPU_STAT(wfe_exit_stat), 30 - VCPU_STAT(wfi_exit_stat), 31 - VCPU_STAT(mmio_exit_user), 32 - VCPU_STAT(mmio_exit_kernel), 33 - VCPU_STAT(exits), 34 - { NULL } 35 - }; 36 - 37 - static u64 core_reg_offset_from_id(u64 id) 38 - { 39 - return id & ~(KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK | KVM_REG_ARM_CORE); 40 - } 41 - 42 - static int get_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 43 - { 44 - u32 __user *uaddr = (u32 __user *)(long)reg->addr; 45 - struct kvm_regs *regs = &vcpu->arch.ctxt.gp_regs; 46 - u64 off; 47 - 48 - if (KVM_REG_SIZE(reg->id) != 4) 49 - return -ENOENT; 50 - 51 - /* Our ID is an index into the kvm_regs struct. */ 52 - off = core_reg_offset_from_id(reg->id); 53 - if (off >= sizeof(*regs) / KVM_REG_SIZE(reg->id)) 54 - return -ENOENT; 55 - 56 - return put_user(((u32 *)regs)[off], uaddr); 57 - } 58 - 59 - static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 60 - { 61 - u32 __user *uaddr = (u32 __user *)(long)reg->addr; 62 - struct kvm_regs *regs = &vcpu->arch.ctxt.gp_regs; 63 - u64 off, val; 64 - 65 - if (KVM_REG_SIZE(reg->id) != 4) 66 - return -ENOENT; 67 - 68 - /* Our ID is an index into the kvm_regs struct. */ 69 - off = core_reg_offset_from_id(reg->id); 70 - if (off >= sizeof(*regs) / KVM_REG_SIZE(reg->id)) 71 - return -ENOENT; 72 - 73 - if (get_user(val, uaddr) != 0) 74 - return -EFAULT; 75 - 76 - if (off == KVM_REG_ARM_CORE_REG(usr_regs.ARM_cpsr)) { 77 - unsigned long mode = val & MODE_MASK; 78 - switch (mode) { 79 - case USR_MODE: 80 - case FIQ_MODE: 81 - case IRQ_MODE: 82 - case SVC_MODE: 83 - case ABT_MODE: 84 - case UND_MODE: 85 - break; 86 - default: 87 - return -EINVAL; 88 - } 89 - } 90 - 91 - ((u32 *)regs)[off] = val; 92 - return 0; 93 - } 94 - 95 - int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 96 - { 97 - return -EINVAL; 98 - } 99 - 100 - int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 101 - { 102 - return -EINVAL; 103 - } 104 - 105 - #define NUM_TIMER_REGS 3 106 - 107 - static bool is_timer_reg(u64 index) 108 - { 109 - switch (index) { 110 - case KVM_REG_ARM_TIMER_CTL: 111 - case KVM_REG_ARM_TIMER_CNT: 112 - case KVM_REG_ARM_TIMER_CVAL: 113 - return true; 114 - } 115 - return false; 116 - } 117 - 118 - static int copy_timer_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) 119 - { 120 - if (put_user(KVM_REG_ARM_TIMER_CTL, uindices)) 121 - return -EFAULT; 122 - uindices++; 123 - if (put_user(KVM_REG_ARM_TIMER_CNT, uindices)) 124 - return -EFAULT; 125 - uindices++; 126 - if (put_user(KVM_REG_ARM_TIMER_CVAL, uindices)) 127 - return -EFAULT; 128 - 129 - return 0; 130 - } 131 - 132 - static int set_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 133 - { 134 - void __user *uaddr = (void __user *)(long)reg->addr; 135 - u64 val; 136 - int ret; 137 - 138 - ret = copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id)); 139 - if (ret != 0) 140 - return -EFAULT; 141 - 142 - return kvm_arm_timer_set_reg(vcpu, reg->id, val); 143 - } 144 - 145 - static int get_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 146 - { 147 - void __user *uaddr = (void __user *)(long)reg->addr; 148 - u64 val; 149 - 150 - val = kvm_arm_timer_get_reg(vcpu, reg->id); 151 - return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)) ? -EFAULT : 0; 152 - } 153 - 154 - static unsigned long num_core_regs(void) 155 - { 156 - return sizeof(struct kvm_regs) / sizeof(u32); 157 - } 158 - 159 - /** 160 - * kvm_arm_num_regs - how many registers do we present via KVM_GET_ONE_REG 161 - * 162 - * This is for all registers. 163 - */ 164 - unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu) 165 - { 166 - return num_core_regs() + kvm_arm_num_coproc_regs(vcpu) 167 - + kvm_arm_get_fw_num_regs(vcpu) 168 - + NUM_TIMER_REGS; 169 - } 170 - 171 - /** 172 - * kvm_arm_copy_reg_indices - get indices of all registers. 173 - * 174 - * We do core registers right here, then we append coproc regs. 175 - */ 176 - int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) 177 - { 178 - unsigned int i; 179 - const u64 core_reg = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_CORE; 180 - int ret; 181 - 182 - for (i = 0; i < sizeof(struct kvm_regs)/sizeof(u32); i++) { 183 - if (put_user(core_reg | i, uindices)) 184 - return -EFAULT; 185 - uindices++; 186 - } 187 - 188 - ret = kvm_arm_copy_fw_reg_indices(vcpu, uindices); 189 - if (ret) 190 - return ret; 191 - uindices += kvm_arm_get_fw_num_regs(vcpu); 192 - 193 - ret = copy_timer_indices(vcpu, uindices); 194 - if (ret) 195 - return ret; 196 - uindices += NUM_TIMER_REGS; 197 - 198 - return kvm_arm_copy_coproc_indices(vcpu, uindices); 199 - } 200 - 201 - int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 202 - { 203 - /* We currently use nothing arch-specific in upper 32 bits */ 204 - if ((reg->id & ~KVM_REG_SIZE_MASK) >> 32 != KVM_REG_ARM >> 32) 205 - return -EINVAL; 206 - 207 - /* Register group 16 means we want a core register. */ 208 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE) 209 - return get_core_reg(vcpu, reg); 210 - 211 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW) 212 - return kvm_arm_get_fw_reg(vcpu, reg); 213 - 214 - if (is_timer_reg(reg->id)) 215 - return get_timer_reg(vcpu, reg); 216 - 217 - return kvm_arm_coproc_get_reg(vcpu, reg); 218 - } 219 - 220 - int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 221 - { 222 - /* We currently use nothing arch-specific in upper 32 bits */ 223 - if ((reg->id & ~KVM_REG_SIZE_MASK) >> 32 != KVM_REG_ARM >> 32) 224 - return -EINVAL; 225 - 226 - /* Register group 16 means we set a core register. */ 227 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE) 228 - return set_core_reg(vcpu, reg); 229 - 230 - if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW) 231 - return kvm_arm_set_fw_reg(vcpu, reg); 232 - 233 - if (is_timer_reg(reg->id)) 234 - return set_timer_reg(vcpu, reg); 235 - 236 - return kvm_arm_coproc_set_reg(vcpu, reg); 237 - } 238 - 239 - int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 240 - struct kvm_sregs *sregs) 241 - { 242 - return -EINVAL; 243 - } 244 - 245 - int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 246 - struct kvm_sregs *sregs) 247 - { 248 - return -EINVAL; 249 - } 250 - 251 - 252 - int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, 253 - struct kvm_vcpu_events *events) 254 - { 255 - events->exception.serror_pending = !!(*vcpu_hcr(vcpu) & HCR_VA); 256 - 257 - /* 258 - * We never return a pending ext_dabt here because we deliver it to 259 - * the virtual CPU directly when setting the event and it's no longer 260 - * 'pending' at this point. 261 - */ 262 - 263 - return 0; 264 - } 265 - 266 - int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, 267 - struct kvm_vcpu_events *events) 268 - { 269 - bool serror_pending = events->exception.serror_pending; 270 - bool has_esr = events->exception.serror_has_esr; 271 - bool ext_dabt_pending = events->exception.ext_dabt_pending; 272 - 273 - if (serror_pending && has_esr) 274 - return -EINVAL; 275 - else if (serror_pending) 276 - kvm_inject_vabt(vcpu); 277 - 278 - if (ext_dabt_pending) 279 - kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); 280 - 281 - return 0; 282 - } 283 - 284 - int __attribute_const__ kvm_target_cpu(void) 285 - { 286 - switch (read_cpuid_part()) { 287 - case ARM_CPU_PART_CORTEX_A7: 288 - return KVM_ARM_TARGET_CORTEX_A7; 289 - case ARM_CPU_PART_CORTEX_A15: 290 - return KVM_ARM_TARGET_CORTEX_A15; 291 - default: 292 - return -EINVAL; 293 - } 294 - } 295 - 296 - int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init) 297 - { 298 - int target = kvm_target_cpu(); 299 - 300 - if (target < 0) 301 - return -ENODEV; 302 - 303 - memset(init, 0, sizeof(*init)); 304 - 305 - /* 306 - * For now, we don't return any features. 307 - * In future, we might use features to return target 308 - * specific features available for the preferred 309 - * target type. 310 - */ 311 - init->target = (__u32)target; 312 - 313 - return 0; 314 - } 315 - 316 - int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 317 - { 318 - return -EINVAL; 319 - } 320 - 321 - int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 322 - { 323 - return -EINVAL; 324 - } 325 - 326 - int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 327 - struct kvm_translation *tr) 328 - { 329 - return -EINVAL; 330 - } 331 - 332 - int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 333 - struct kvm_guest_debug *dbg) 334 - { 335 - return -EINVAL; 336 - } 337 - 338 - int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, 339 - struct kvm_device_attr *attr) 340 - { 341 - int ret; 342 - 343 - switch (attr->group) { 344 - case KVM_ARM_VCPU_TIMER_CTRL: 345 - ret = kvm_arm_timer_set_attr(vcpu, attr); 346 - break; 347 - default: 348 - ret = -ENXIO; 349 - break; 350 - } 351 - 352 - return ret; 353 - } 354 - 355 - int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu, 356 - struct kvm_device_attr *attr) 357 - { 358 - int ret; 359 - 360 - switch (attr->group) { 361 - case KVM_ARM_VCPU_TIMER_CTRL: 362 - ret = kvm_arm_timer_get_attr(vcpu, attr); 363 - break; 364 - default: 365 - ret = -ENXIO; 366 - break; 367 - } 368 - 369 - return ret; 370 - } 371 - 372 - int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, 373 - struct kvm_device_attr *attr) 374 - { 375 - int ret; 376 - 377 - switch (attr->group) { 378 - case KVM_ARM_VCPU_TIMER_CTRL: 379 - ret = kvm_arm_timer_has_attr(vcpu, attr); 380 - break; 381 - default: 382 - ret = -ENXIO; 383 - break; 384 - } 385 - 386 - return ret; 387 - }
-175
arch/arm/kvm/handle_exit.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/kvm.h> 8 - #include <linux/kvm_host.h> 9 - #include <asm/kvm_emulate.h> 10 - #include <asm/kvm_coproc.h> 11 - #include <asm/kvm_mmu.h> 12 - #include <kvm/arm_hypercalls.h> 13 - #include <trace/events/kvm.h> 14 - 15 - #include "trace.h" 16 - 17 - typedef int (*exit_handle_fn)(struct kvm_vcpu *, struct kvm_run *); 18 - 19 - static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) 20 - { 21 - int ret; 22 - 23 - trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0), 24 - kvm_vcpu_hvc_get_imm(vcpu)); 25 - vcpu->stat.hvc_exit_stat++; 26 - 27 - ret = kvm_hvc_call_handler(vcpu); 28 - if (ret < 0) { 29 - vcpu_set_reg(vcpu, 0, ~0UL); 30 - return 1; 31 - } 32 - 33 - return ret; 34 - } 35 - 36 - static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) 37 - { 38 - /* 39 - * "If an SMC instruction executed at Non-secure EL1 is 40 - * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a 41 - * Trap exception, not a Secure Monitor Call exception [...]" 42 - * 43 - * We need to advance the PC after the trap, as it would 44 - * otherwise return to the same address... 45 - */ 46 - vcpu_set_reg(vcpu, 0, ~0UL); 47 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 48 - return 1; 49 - } 50 - 51 - /** 52 - * kvm_handle_wfx - handle a WFI or WFE instructions trapped in guests 53 - * @vcpu: the vcpu pointer 54 - * @run: the kvm_run structure pointer 55 - * 56 - * WFE: Yield the CPU and come back to this vcpu when the scheduler 57 - * decides to. 58 - * WFI: Simply call kvm_vcpu_block(), which will halt execution of 59 - * world-switches and schedule other host processes until there is an 60 - * incoming IRQ or FIQ to the VM. 61 - */ 62 - static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) 63 - { 64 - if (kvm_vcpu_get_hsr(vcpu) & HSR_WFI_IS_WFE) { 65 - trace_kvm_wfx(*vcpu_pc(vcpu), true); 66 - vcpu->stat.wfe_exit_stat++; 67 - kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); 68 - } else { 69 - trace_kvm_wfx(*vcpu_pc(vcpu), false); 70 - vcpu->stat.wfi_exit_stat++; 71 - kvm_vcpu_block(vcpu); 72 - kvm_clear_request(KVM_REQ_UNHALT, vcpu); 73 - } 74 - 75 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 76 - 77 - return 1; 78 - } 79 - 80 - static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu, struct kvm_run *run) 81 - { 82 - u32 hsr = kvm_vcpu_get_hsr(vcpu); 83 - 84 - kvm_pr_unimpl("Unknown exception class: hsr: %#08x\n", 85 - hsr); 86 - 87 - kvm_inject_undefined(vcpu); 88 - return 1; 89 - } 90 - 91 - static exit_handle_fn arm_exit_handlers[] = { 92 - [0 ... HSR_EC_MAX] = kvm_handle_unknown_ec, 93 - [HSR_EC_WFI] = kvm_handle_wfx, 94 - [HSR_EC_CP15_32] = kvm_handle_cp15_32, 95 - [HSR_EC_CP15_64] = kvm_handle_cp15_64, 96 - [HSR_EC_CP14_MR] = kvm_handle_cp14_32, 97 - [HSR_EC_CP14_LS] = kvm_handle_cp14_load_store, 98 - [HSR_EC_CP14_64] = kvm_handle_cp14_64, 99 - [HSR_EC_CP_0_13] = kvm_handle_cp_0_13_access, 100 - [HSR_EC_CP10_ID] = kvm_handle_cp10_id, 101 - [HSR_EC_HVC] = handle_hvc, 102 - [HSR_EC_SMC] = handle_smc, 103 - [HSR_EC_IABT] = kvm_handle_guest_abort, 104 - [HSR_EC_DABT] = kvm_handle_guest_abort, 105 - }; 106 - 107 - static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) 108 - { 109 - u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu); 110 - 111 - return arm_exit_handlers[hsr_ec]; 112 - } 113 - 114 - /* 115 - * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on 116 - * proper exit to userspace. 117 - */ 118 - int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, 119 - int exception_index) 120 - { 121 - exit_handle_fn exit_handler; 122 - 123 - if (ARM_ABORT_PENDING(exception_index)) { 124 - u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu); 125 - 126 - /* 127 - * HVC/SMC already have an adjusted PC, which we need 128 - * to correct in order to return to after having 129 - * injected the abort. 130 - */ 131 - if (hsr_ec == HSR_EC_HVC || hsr_ec == HSR_EC_SMC) { 132 - u32 adj = kvm_vcpu_trap_il_is32bit(vcpu) ? 4 : 2; 133 - *vcpu_pc(vcpu) -= adj; 134 - } 135 - 136 - kvm_inject_vabt(vcpu); 137 - return 1; 138 - } 139 - 140 - exception_index = ARM_EXCEPTION_CODE(exception_index); 141 - 142 - switch (exception_index) { 143 - case ARM_EXCEPTION_IRQ: 144 - return 1; 145 - case ARM_EXCEPTION_HVC: 146 - /* 147 - * See ARM ARM B1.14.1: "Hyp traps on instructions 148 - * that fail their condition code check" 149 - */ 150 - if (!kvm_condition_valid(vcpu)) { 151 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 152 - return 1; 153 - } 154 - 155 - exit_handler = kvm_get_exit_handler(vcpu); 156 - 157 - return exit_handler(vcpu, run); 158 - case ARM_EXCEPTION_DATA_ABORT: 159 - kvm_inject_vabt(vcpu); 160 - return 1; 161 - case ARM_EXCEPTION_HYP_GONE: 162 - /* 163 - * HYP has been reset to the hyp-stub. This happens 164 - * when a guest is pre-empted by kvm_reboot()'s 165 - * shutdown call. 166 - */ 167 - run->exit_reason = KVM_EXIT_FAIL_ENTRY; 168 - return 0; 169 - default: 170 - kvm_pr_unimpl("Unsupported exception type: %d", 171 - exception_index); 172 - run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 173 - return 0; 174 - } 175 - }
-34
arch/arm/kvm/hyp/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # 3 - # Makefile for Kernel-based Virtual Machine module, HYP part 4 - # 5 - 6 - ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING 7 - 8 - KVM=../../../../virt/kvm 9 - 10 - CFLAGS_ARMV7VE :=$(call cc-option, -march=armv7ve) 11 - 12 - obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v3-sr.o 13 - obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o 14 - obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/aarch32.o 15 - 16 - obj-$(CONFIG_KVM_ARM_HOST) += tlb.o 17 - obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o 18 - obj-$(CONFIG_KVM_ARM_HOST) += vfp.o 19 - obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o 20 - CFLAGS_banked-sr.o += $(CFLAGS_ARMV7VE) 21 - 22 - obj-$(CONFIG_KVM_ARM_HOST) += entry.o 23 - obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o 24 - obj-$(CONFIG_KVM_ARM_HOST) += switch.o 25 - CFLAGS_switch.o += $(CFLAGS_ARMV7VE) 26 - obj-$(CONFIG_KVM_ARM_HOST) += s2-setup.o 27 - 28 - # KVM code is run at a different exception code with a different map, so 29 - # compiler instrumentation that inserts callbacks or checks into the code may 30 - # cause crashes. Just disable it. 31 - GCOV_PROFILE := n 32 - KASAN_SANITIZE := n 33 - UBSAN_SANITIZE := n 34 - KCOV_INSTRUMENT := n
-70
arch/arm/kvm/hyp/banked-sr.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Original code: 4 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 5 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 6 - * 7 - * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com> 8 - */ 9 - 10 - #include <asm/kvm_hyp.h> 11 - 12 - /* 13 - * gcc before 4.9 doesn't understand -march=armv7ve, so we have to 14 - * trick the assembler. 15 - */ 16 - __asm__(".arch_extension virt"); 17 - 18 - void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt) 19 - { 20 - ctxt->gp_regs.usr_regs.ARM_sp = read_special(SP_usr); 21 - ctxt->gp_regs.usr_regs.ARM_pc = read_special(ELR_hyp); 22 - ctxt->gp_regs.usr_regs.ARM_cpsr = read_special(SPSR); 23 - ctxt->gp_regs.KVM_ARM_SVC_sp = read_special(SP_svc); 24 - ctxt->gp_regs.KVM_ARM_SVC_lr = read_special(LR_svc); 25 - ctxt->gp_regs.KVM_ARM_SVC_spsr = read_special(SPSR_svc); 26 - ctxt->gp_regs.KVM_ARM_ABT_sp = read_special(SP_abt); 27 - ctxt->gp_regs.KVM_ARM_ABT_lr = read_special(LR_abt); 28 - ctxt->gp_regs.KVM_ARM_ABT_spsr = read_special(SPSR_abt); 29 - ctxt->gp_regs.KVM_ARM_UND_sp = read_special(SP_und); 30 - ctxt->gp_regs.KVM_ARM_UND_lr = read_special(LR_und); 31 - ctxt->gp_regs.KVM_ARM_UND_spsr = read_special(SPSR_und); 32 - ctxt->gp_regs.KVM_ARM_IRQ_sp = read_special(SP_irq); 33 - ctxt->gp_regs.KVM_ARM_IRQ_lr = read_special(LR_irq); 34 - ctxt->gp_regs.KVM_ARM_IRQ_spsr = read_special(SPSR_irq); 35 - ctxt->gp_regs.KVM_ARM_FIQ_r8 = read_special(R8_fiq); 36 - ctxt->gp_regs.KVM_ARM_FIQ_r9 = read_special(R9_fiq); 37 - ctxt->gp_regs.KVM_ARM_FIQ_r10 = read_special(R10_fiq); 38 - ctxt->gp_regs.KVM_ARM_FIQ_fp = read_special(R11_fiq); 39 - ctxt->gp_regs.KVM_ARM_FIQ_ip = read_special(R12_fiq); 40 - ctxt->gp_regs.KVM_ARM_FIQ_sp = read_special(SP_fiq); 41 - ctxt->gp_regs.KVM_ARM_FIQ_lr = read_special(LR_fiq); 42 - ctxt->gp_regs.KVM_ARM_FIQ_spsr = read_special(SPSR_fiq); 43 - } 44 - 45 - void __hyp_text __banked_restore_state(struct kvm_cpu_context *ctxt) 46 - { 47 - write_special(ctxt->gp_regs.usr_regs.ARM_sp, SP_usr); 48 - write_special(ctxt->gp_regs.usr_regs.ARM_pc, ELR_hyp); 49 - write_special(ctxt->gp_regs.usr_regs.ARM_cpsr, SPSR_cxsf); 50 - write_special(ctxt->gp_regs.KVM_ARM_SVC_sp, SP_svc); 51 - write_special(ctxt->gp_regs.KVM_ARM_SVC_lr, LR_svc); 52 - write_special(ctxt->gp_regs.KVM_ARM_SVC_spsr, SPSR_svc); 53 - write_special(ctxt->gp_regs.KVM_ARM_ABT_sp, SP_abt); 54 - write_special(ctxt->gp_regs.KVM_ARM_ABT_lr, LR_abt); 55 - write_special(ctxt->gp_regs.KVM_ARM_ABT_spsr, SPSR_abt); 56 - write_special(ctxt->gp_regs.KVM_ARM_UND_sp, SP_und); 57 - write_special(ctxt->gp_regs.KVM_ARM_UND_lr, LR_und); 58 - write_special(ctxt->gp_regs.KVM_ARM_UND_spsr, SPSR_und); 59 - write_special(ctxt->gp_regs.KVM_ARM_IRQ_sp, SP_irq); 60 - write_special(ctxt->gp_regs.KVM_ARM_IRQ_lr, LR_irq); 61 - write_special(ctxt->gp_regs.KVM_ARM_IRQ_spsr, SPSR_irq); 62 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_r8, R8_fiq); 63 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_r9, R9_fiq); 64 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_r10, R10_fiq); 65 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_fp, R11_fiq); 66 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_ip, R12_fiq); 67 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_sp, SP_fiq); 68 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_lr, LR_fiq); 69 - write_special(ctxt->gp_regs.KVM_ARM_FIQ_spsr, SPSR_fiq); 70 - }
-72
arch/arm/kvm/hyp/cp15-sr.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Original code: 4 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 5 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 6 - * 7 - * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com> 8 - */ 9 - 10 - #include <asm/kvm_hyp.h> 11 - 12 - static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx) 13 - { 14 - return (u64 *)(ctxt->cp15 + idx); 15 - } 16 - 17 - void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt) 18 - { 19 - ctxt->cp15[c0_CSSELR] = read_sysreg(CSSELR); 20 - ctxt->cp15[c1_SCTLR] = read_sysreg(SCTLR); 21 - ctxt->cp15[c1_CPACR] = read_sysreg(CPACR); 22 - *cp15_64(ctxt, c2_TTBR0) = read_sysreg(TTBR0); 23 - *cp15_64(ctxt, c2_TTBR1) = read_sysreg(TTBR1); 24 - ctxt->cp15[c2_TTBCR] = read_sysreg(TTBCR); 25 - ctxt->cp15[c3_DACR] = read_sysreg(DACR); 26 - ctxt->cp15[c5_DFSR] = read_sysreg(DFSR); 27 - ctxt->cp15[c5_IFSR] = read_sysreg(IFSR); 28 - ctxt->cp15[c5_ADFSR] = read_sysreg(ADFSR); 29 - ctxt->cp15[c5_AIFSR] = read_sysreg(AIFSR); 30 - ctxt->cp15[c6_DFAR] = read_sysreg(DFAR); 31 - ctxt->cp15[c6_IFAR] = read_sysreg(IFAR); 32 - *cp15_64(ctxt, c7_PAR) = read_sysreg(PAR); 33 - ctxt->cp15[c10_PRRR] = read_sysreg(PRRR); 34 - ctxt->cp15[c10_NMRR] = read_sysreg(NMRR); 35 - ctxt->cp15[c10_AMAIR0] = read_sysreg(AMAIR0); 36 - ctxt->cp15[c10_AMAIR1] = read_sysreg(AMAIR1); 37 - ctxt->cp15[c12_VBAR] = read_sysreg(VBAR); 38 - ctxt->cp15[c13_CID] = read_sysreg(CID); 39 - ctxt->cp15[c13_TID_URW] = read_sysreg(TID_URW); 40 - ctxt->cp15[c13_TID_URO] = read_sysreg(TID_URO); 41 - ctxt->cp15[c13_TID_PRIV] = read_sysreg(TID_PRIV); 42 - ctxt->cp15[c14_CNTKCTL] = read_sysreg(CNTKCTL); 43 - } 44 - 45 - void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt) 46 - { 47 - write_sysreg(ctxt->cp15[c0_MPIDR], VMPIDR); 48 - write_sysreg(ctxt->cp15[c0_CSSELR], CSSELR); 49 - write_sysreg(ctxt->cp15[c1_SCTLR], SCTLR); 50 - write_sysreg(ctxt->cp15[c1_CPACR], CPACR); 51 - write_sysreg(*cp15_64(ctxt, c2_TTBR0), TTBR0); 52 - write_sysreg(*cp15_64(ctxt, c2_TTBR1), TTBR1); 53 - write_sysreg(ctxt->cp15[c2_TTBCR], TTBCR); 54 - write_sysreg(ctxt->cp15[c3_DACR], DACR); 55 - write_sysreg(ctxt->cp15[c5_DFSR], DFSR); 56 - write_sysreg(ctxt->cp15[c5_IFSR], IFSR); 57 - write_sysreg(ctxt->cp15[c5_ADFSR], ADFSR); 58 - write_sysreg(ctxt->cp15[c5_AIFSR], AIFSR); 59 - write_sysreg(ctxt->cp15[c6_DFAR], DFAR); 60 - write_sysreg(ctxt->cp15[c6_IFAR], IFAR); 61 - write_sysreg(*cp15_64(ctxt, c7_PAR), PAR); 62 - write_sysreg(ctxt->cp15[c10_PRRR], PRRR); 63 - write_sysreg(ctxt->cp15[c10_NMRR], NMRR); 64 - write_sysreg(ctxt->cp15[c10_AMAIR0], AMAIR0); 65 - write_sysreg(ctxt->cp15[c10_AMAIR1], AMAIR1); 66 - write_sysreg(ctxt->cp15[c12_VBAR], VBAR); 67 - write_sysreg(ctxt->cp15[c13_CID], CID); 68 - write_sysreg(ctxt->cp15[c13_TID_URW], TID_URW); 69 - write_sysreg(ctxt->cp15[c13_TID_URO], TID_URO); 70 - write_sysreg(ctxt->cp15[c13_TID_PRIV], TID_PRIV); 71 - write_sysreg(ctxt->cp15[c14_CNTKCTL], CNTKCTL); 72 - }
-121
arch/arm/kvm/hyp/entry.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2016 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - */ 6 - 7 - #include <linux/linkage.h> 8 - #include <asm/asm-offsets.h> 9 - #include <asm/kvm_arm.h> 10 - #include <asm/kvm_asm.h> 11 - 12 - .arch_extension virt 13 - 14 - .text 15 - .pushsection .hyp.text, "ax" 16 - 17 - #define USR_REGS_OFFSET (CPU_CTXT_GP_REGS + GP_REGS_USR) 18 - 19 - /* int __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host) */ 20 - ENTRY(__guest_enter) 21 - @ Save host registers 22 - add r1, r1, #(USR_REGS_OFFSET + S_R4) 23 - stm r1!, {r4-r12} 24 - str lr, [r1, #4] @ Skip SP_usr (already saved) 25 - 26 - @ Restore guest registers 27 - add r0, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0) 28 - ldr lr, [r0, #S_LR] 29 - ldm r0, {r0-r12} 30 - 31 - clrex 32 - eret 33 - ENDPROC(__guest_enter) 34 - 35 - ENTRY(__guest_exit) 36 - /* 37 - * return convention: 38 - * guest r0, r1, r2 saved on the stack 39 - * r0: vcpu pointer 40 - * r1: exception code 41 - */ 42 - 43 - add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R3) 44 - stm r2!, {r3-r12} 45 - str lr, [r2, #4] 46 - add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0) 47 - pop {r3, r4, r5} @ r0, r1, r2 48 - stm r2, {r3-r5} 49 - 50 - ldr r0, [r0, #VCPU_HOST_CTXT] 51 - add r0, r0, #(USR_REGS_OFFSET + S_R4) 52 - ldm r0!, {r4-r12} 53 - ldr lr, [r0, #4] 54 - 55 - mov r0, r1 56 - mrs r1, SPSR 57 - mrs r2, ELR_hyp 58 - mrc p15, 4, r3, c5, c2, 0 @ HSR 59 - 60 - /* 61 - * Force loads and stores to complete before unmasking aborts 62 - * and forcing the delivery of the exception. This gives us a 63 - * single instruction window, which the handler will try to 64 - * match. 65 - */ 66 - dsb sy 67 - cpsie a 68 - 69 - .global abort_guest_exit_start 70 - abort_guest_exit_start: 71 - 72 - isb 73 - 74 - .global abort_guest_exit_end 75 - abort_guest_exit_end: 76 - 77 - /* 78 - * If we took an abort, r0[31] will be set, and cmp will set 79 - * the N bit in PSTATE. 80 - */ 81 - cmp r0, #0 82 - msrmi SPSR_cxsf, r1 83 - msrmi ELR_hyp, r2 84 - mcrmi p15, 4, r3, c5, c2, 0 @ HSR 85 - 86 - bx lr 87 - ENDPROC(__guest_exit) 88 - 89 - /* 90 - * If VFPv3 support is not available, then we will not switch the VFP 91 - * registers; however cp10 and cp11 accesses will still trap and fallback 92 - * to the regular coprocessor emulation code, which currently will 93 - * inject an undefined exception to the guest. 94 - */ 95 - #ifdef CONFIG_VFPv3 96 - ENTRY(__vfp_guest_restore) 97 - push {r3, r4, lr} 98 - 99 - @ NEON/VFP used. Turn on VFP access. 100 - mrc p15, 4, r1, c1, c1, 2 @ HCPTR 101 - bic r1, r1, #(HCPTR_TCP(10) | HCPTR_TCP(11)) 102 - mcr p15, 4, r1, c1, c1, 2 @ HCPTR 103 - isb 104 - 105 - @ Switch VFP/NEON hardware state to the guest's 106 - mov r4, r0 107 - ldr r0, [r0, #VCPU_HOST_CTXT] 108 - add r0, r0, #CPU_CTXT_VFP 109 - bl __vfp_save_state 110 - add r0, r4, #(VCPU_GUEST_CTXT + CPU_CTXT_VFP) 111 - bl __vfp_restore_state 112 - 113 - pop {r3, r4, lr} 114 - pop {r0, r1, r2} 115 - clrex 116 - eret 117 - ENDPROC(__vfp_guest_restore) 118 - #endif 119 - 120 - .popsection 121 -
-295
arch/arm/kvm/hyp/hyp-entry.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/arm-smccc.h> 8 - #include <linux/linkage.h> 9 - #include <asm/kvm_arm.h> 10 - #include <asm/kvm_asm.h> 11 - 12 - .arch_extension virt 13 - 14 - .text 15 - .pushsection .hyp.text, "ax" 16 - 17 - .macro load_vcpu reg 18 - mrc p15, 4, \reg, c13, c0, 2 @ HTPIDR 19 - .endm 20 - 21 - /******************************************************************** 22 - * Hypervisor exception vector and handlers 23 - * 24 - * 25 - * The KVM/ARM Hypervisor ABI is defined as follows: 26 - * 27 - * Entry to Hyp mode from the host kernel will happen _only_ when an HVC 28 - * instruction is issued since all traps are disabled when running the host 29 - * kernel as per the Hyp-mode initialization at boot time. 30 - * 31 - * HVC instructions cause a trap to the vector page + offset 0x14 (see hyp_hvc 32 - * below) when the HVC instruction is called from SVC mode (i.e. a guest or the 33 - * host kernel) and they cause a trap to the vector page + offset 0x8 when HVC 34 - * instructions are called from within Hyp-mode. 35 - * 36 - * Hyp-ABI: Calling HYP-mode functions from host (in SVC mode): 37 - * Switching to Hyp mode is done through a simple HVC #0 instruction. The 38 - * exception vector code will check that the HVC comes from VMID==0. 39 - * - r0 contains a pointer to a HYP function 40 - * - r1, r2, and r3 contain arguments to the above function. 41 - * - The HYP function will be called with its arguments in r0, r1 and r2. 42 - * On HYP function return, we return directly to SVC. 43 - * 44 - * Note that the above is used to execute code in Hyp-mode from a host-kernel 45 - * point of view, and is a different concept from performing a world-switch and 46 - * executing guest code SVC mode (with a VMID != 0). 47 - */ 48 - 49 - .align 5 50 - __kvm_hyp_vector: 51 - .global __kvm_hyp_vector 52 - 53 - @ Hyp-mode exception vector 54 - W(b) hyp_reset 55 - W(b) hyp_undef 56 - W(b) hyp_svc 57 - W(b) hyp_pabt 58 - W(b) hyp_dabt 59 - W(b) hyp_hvc 60 - W(b) hyp_irq 61 - W(b) hyp_fiq 62 - 63 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 64 - .align 5 65 - __kvm_hyp_vector_ic_inv: 66 - .global __kvm_hyp_vector_ic_inv 67 - 68 - /* 69 - * We encode the exception entry in the bottom 3 bits of 70 - * SP, and we have to guarantee to be 8 bytes aligned. 71 - */ 72 - W(add) sp, sp, #1 /* Reset 7 */ 73 - W(add) sp, sp, #1 /* Undef 6 */ 74 - W(add) sp, sp, #1 /* Syscall 5 */ 75 - W(add) sp, sp, #1 /* Prefetch abort 4 */ 76 - W(add) sp, sp, #1 /* Data abort 3 */ 77 - W(add) sp, sp, #1 /* HVC 2 */ 78 - W(add) sp, sp, #1 /* IRQ 1 */ 79 - W(nop) /* FIQ 0 */ 80 - 81 - mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */ 82 - isb 83 - 84 - b decode_vectors 85 - 86 - .align 5 87 - __kvm_hyp_vector_bp_inv: 88 - .global __kvm_hyp_vector_bp_inv 89 - 90 - /* 91 - * We encode the exception entry in the bottom 3 bits of 92 - * SP, and we have to guarantee to be 8 bytes aligned. 93 - */ 94 - W(add) sp, sp, #1 /* Reset 7 */ 95 - W(add) sp, sp, #1 /* Undef 6 */ 96 - W(add) sp, sp, #1 /* Syscall 5 */ 97 - W(add) sp, sp, #1 /* Prefetch abort 4 */ 98 - W(add) sp, sp, #1 /* Data abort 3 */ 99 - W(add) sp, sp, #1 /* HVC 2 */ 100 - W(add) sp, sp, #1 /* IRQ 1 */ 101 - W(nop) /* FIQ 0 */ 102 - 103 - mcr p15, 0, r0, c7, c5, 6 /* BPIALL */ 104 - isb 105 - 106 - decode_vectors: 107 - 108 - #ifdef CONFIG_THUMB2_KERNEL 109 - /* 110 - * Yet another silly hack: Use VPIDR as a temp register. 111 - * Thumb2 is really a pain, as SP cannot be used with most 112 - * of the bitwise instructions. The vect_br macro ensures 113 - * things gets cleaned-up. 114 - */ 115 - mcr p15, 4, r0, c0, c0, 0 /* VPIDR */ 116 - mov r0, sp 117 - and r0, r0, #7 118 - sub sp, sp, r0 119 - push {r1, r2} 120 - mov r1, r0 121 - mrc p15, 4, r0, c0, c0, 0 /* VPIDR */ 122 - mrc p15, 0, r2, c0, c0, 0 /* MIDR */ 123 - mcr p15, 4, r2, c0, c0, 0 /* VPIDR */ 124 - #endif 125 - 126 - .macro vect_br val, targ 127 - ARM( eor sp, sp, #\val ) 128 - ARM( tst sp, #7 ) 129 - ARM( eorne sp, sp, #\val ) 130 - 131 - THUMB( cmp r1, #\val ) 132 - THUMB( popeq {r1, r2} ) 133 - 134 - beq \targ 135 - .endm 136 - 137 - vect_br 0, hyp_fiq 138 - vect_br 1, hyp_irq 139 - vect_br 2, hyp_hvc 140 - vect_br 3, hyp_dabt 141 - vect_br 4, hyp_pabt 142 - vect_br 5, hyp_svc 143 - vect_br 6, hyp_undef 144 - vect_br 7, hyp_reset 145 - #endif 146 - 147 - .macro invalid_vector label, cause 148 - .align 149 - \label: mov r0, #\cause 150 - b __hyp_panic 151 - .endm 152 - 153 - invalid_vector hyp_reset ARM_EXCEPTION_RESET 154 - invalid_vector hyp_undef ARM_EXCEPTION_UNDEFINED 155 - invalid_vector hyp_svc ARM_EXCEPTION_SOFTWARE 156 - invalid_vector hyp_pabt ARM_EXCEPTION_PREF_ABORT 157 - invalid_vector hyp_fiq ARM_EXCEPTION_FIQ 158 - 159 - ENTRY(__hyp_do_panic) 160 - mrs lr, cpsr 161 - bic lr, lr, #MODE_MASK 162 - orr lr, lr, #SVC_MODE 163 - THUMB( orr lr, lr, #PSR_T_BIT ) 164 - msr spsr_cxsf, lr 165 - ldr lr, =panic 166 - msr ELR_hyp, lr 167 - ldr lr, =__kvm_call_hyp 168 - clrex 169 - eret 170 - ENDPROC(__hyp_do_panic) 171 - 172 - hyp_hvc: 173 - /* 174 - * Getting here is either because of a trap from a guest, 175 - * or from executing HVC from the host kernel, which means 176 - * "do something in Hyp mode". 177 - */ 178 - push {r0, r1, r2} 179 - 180 - @ Check syndrome register 181 - mrc p15, 4, r1, c5, c2, 0 @ HSR 182 - lsr r0, r1, #HSR_EC_SHIFT 183 - cmp r0, #HSR_EC_HVC 184 - bne guest_trap @ Not HVC instr. 185 - 186 - /* 187 - * Let's check if the HVC came from VMID 0 and allow simple 188 - * switch to Hyp mode 189 - */ 190 - mrrc p15, 6, r0, r2, c2 191 - lsr r2, r2, #16 192 - and r2, r2, #0xff 193 - cmp r2, #0 194 - bne guest_hvc_trap @ Guest called HVC 195 - 196 - /* 197 - * Getting here means host called HVC, we shift parameters and branch 198 - * to Hyp function. 199 - */ 200 - pop {r0, r1, r2} 201 - 202 - /* 203 - * Check if we have a kernel function, which is guaranteed to be 204 - * bigger than the maximum hyp stub hypercall 205 - */ 206 - cmp r0, #HVC_STUB_HCALL_NR 207 - bhs 1f 208 - 209 - /* 210 - * Not a kernel function, treat it as a stub hypercall. 211 - * Compute the physical address for __kvm_handle_stub_hvc 212 - * (as the code lives in the idmaped page) and branch there. 213 - * We hijack ip (r12) as a tmp register. 214 - */ 215 - push {r1} 216 - ldr r1, =kimage_voffset 217 - ldr r1, [r1] 218 - ldr ip, =__kvm_handle_stub_hvc 219 - sub ip, ip, r1 220 - pop {r1} 221 - 222 - bx ip 223 - 224 - 1: 225 - /* 226 - * Pushing r2 here is just a way of keeping the stack aligned to 227 - * 8 bytes on any path that can trigger a HYP exception. Here, 228 - * we may well be about to jump into the guest, and the guest 229 - * exit would otherwise be badly decoded by our fancy 230 - * "decode-exception-without-a-branch" code... 231 - */ 232 - push {r2, lr} 233 - 234 - mov lr, r0 235 - mov r0, r1 236 - mov r1, r2 237 - mov r2, r3 238 - 239 - THUMB( orr lr, #1) 240 - blx lr @ Call the HYP function 241 - 242 - pop {r2, lr} 243 - eret 244 - 245 - guest_hvc_trap: 246 - movw r2, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 247 - movt r2, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 248 - ldr r0, [sp] @ Guest's r0 249 - teq r0, r2 250 - bne guest_trap 251 - add sp, sp, #12 252 - @ Returns: 253 - @ r0 = 0 254 - @ r1 = HSR value (perfectly predictable) 255 - @ r2 = ARM_SMCCC_ARCH_WORKAROUND_1 256 - mov r0, #0 257 - eret 258 - 259 - guest_trap: 260 - load_vcpu r0 @ Load VCPU pointer to r0 261 - 262 - #ifdef CONFIG_VFPv3 263 - @ Check for a VFP access 264 - lsr r1, r1, #HSR_EC_SHIFT 265 - cmp r1, #HSR_EC_CP_0_13 266 - beq __vfp_guest_restore 267 - #endif 268 - 269 - mov r1, #ARM_EXCEPTION_HVC 270 - b __guest_exit 271 - 272 - hyp_irq: 273 - push {r0, r1, r2} 274 - mov r1, #ARM_EXCEPTION_IRQ 275 - load_vcpu r0 @ Load VCPU pointer to r0 276 - b __guest_exit 277 - 278 - hyp_dabt: 279 - push {r0, r1} 280 - mrs r0, ELR_hyp 281 - ldr r1, =abort_guest_exit_start 282 - THUMB( add r1, r1, #1) 283 - cmp r0, r1 284 - ldrne r1, =abort_guest_exit_end 285 - THUMB( addne r1, r1, #1) 286 - cmpne r0, r1 287 - pop {r0, r1} 288 - bne __hyp_panic 289 - 290 - orr r0, r0, #(1 << ARM_EXIT_WITH_ABORT_BIT) 291 - eret 292 - 293 - .ltorg 294 - 295 - .popsection
-22
arch/arm/kvm/hyp/s2-setup.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2016 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - */ 6 - 7 - #include <linux/types.h> 8 - #include <asm/kvm_arm.h> 9 - #include <asm/kvm_asm.h> 10 - #include <asm/kvm_hyp.h> 11 - 12 - void __hyp_text __init_stage2_translation(void) 13 - { 14 - u64 val; 15 - 16 - val = read_sysreg(VTCR) & ~VTCR_MASK; 17 - 18 - val |= read_sysreg(HTCR) & VTCR_HTCR_SH; 19 - val |= KVM_VTCR_SL0 | KVM_VTCR_T0SZ | KVM_VTCR_S; 20 - 21 - write_sysreg(val, VTCR); 22 - }
-242
arch/arm/kvm/hyp/switch.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2015 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - */ 6 - #include <linux/jump_label.h> 7 - 8 - #include <asm/kvm_asm.h> 9 - #include <asm/kvm_hyp.h> 10 - #include <asm/kvm_mmu.h> 11 - 12 - __asm__(".arch_extension virt"); 13 - 14 - /* 15 - * Activate the traps, saving the host's fpexc register before 16 - * overwriting it. We'll restore it on VM exit. 17 - */ 18 - static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu, u32 *fpexc_host) 19 - { 20 - u32 val; 21 - 22 - /* 23 - * We are about to set HCPTR.TCP10/11 to trap all floating point 24 - * register accesses to HYP, however, the ARM ARM clearly states that 25 - * traps are only taken to HYP if the operation would not otherwise 26 - * trap to SVC. Therefore, always make sure that for 32-bit guests, 27 - * we set FPEXC.EN to prevent traps to SVC, when setting the TCP bits. 28 - */ 29 - val = read_sysreg(VFP_FPEXC); 30 - *fpexc_host = val; 31 - if (!(val & FPEXC_EN)) { 32 - write_sysreg(val | FPEXC_EN, VFP_FPEXC); 33 - isb(); 34 - } 35 - 36 - write_sysreg(vcpu->arch.hcr, HCR); 37 - /* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */ 38 - write_sysreg(HSTR_T(15), HSTR); 39 - write_sysreg(HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11), HCPTR); 40 - val = read_sysreg(HDCR); 41 - val |= HDCR_TPM | HDCR_TPMCR; /* trap performance monitors */ 42 - val |= HDCR_TDRA | HDCR_TDOSA | HDCR_TDA; /* trap debug regs */ 43 - write_sysreg(val, HDCR); 44 - } 45 - 46 - static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) 47 - { 48 - u32 val; 49 - 50 - /* 51 - * If we pended a virtual abort, preserve it until it gets 52 - * cleared. See B1.9.9 (Virtual Abort exception) for details, 53 - * but the crucial bit is the zeroing of HCR.VA in the 54 - * pseudocode. 55 - */ 56 - if (vcpu->arch.hcr & HCR_VA) 57 - vcpu->arch.hcr = read_sysreg(HCR); 58 - 59 - write_sysreg(0, HCR); 60 - write_sysreg(0, HSTR); 61 - val = read_sysreg(HDCR); 62 - write_sysreg(val & ~(HDCR_TPM | HDCR_TPMCR), HDCR); 63 - write_sysreg(0, HCPTR); 64 - } 65 - 66 - static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu) 67 - { 68 - struct kvm *kvm = kern_hyp_va(vcpu->kvm); 69 - write_sysreg(kvm_get_vttbr(kvm), VTTBR); 70 - write_sysreg(vcpu->arch.midr, VPIDR); 71 - } 72 - 73 - static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu) 74 - { 75 - write_sysreg(0, VTTBR); 76 - write_sysreg(read_sysreg(MIDR), VPIDR); 77 - } 78 - 79 - 80 - static void __hyp_text __vgic_save_state(struct kvm_vcpu *vcpu) 81 - { 82 - if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) { 83 - __vgic_v3_save_state(vcpu); 84 - __vgic_v3_deactivate_traps(vcpu); 85 - } 86 - } 87 - 88 - static void __hyp_text __vgic_restore_state(struct kvm_vcpu *vcpu) 89 - { 90 - if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) { 91 - __vgic_v3_activate_traps(vcpu); 92 - __vgic_v3_restore_state(vcpu); 93 - } 94 - } 95 - 96 - static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) 97 - { 98 - u32 hsr = read_sysreg(HSR); 99 - u8 ec = hsr >> HSR_EC_SHIFT; 100 - u32 hpfar, far; 101 - 102 - vcpu->arch.fault.hsr = hsr; 103 - 104 - if (ec == HSR_EC_IABT) 105 - far = read_sysreg(HIFAR); 106 - else if (ec == HSR_EC_DABT) 107 - far = read_sysreg(HDFAR); 108 - else 109 - return true; 110 - 111 - /* 112 - * B3.13.5 Reporting exceptions taken to the Non-secure PL2 mode: 113 - * 114 - * Abort on the stage 2 translation for a memory access from a 115 - * Non-secure PL1 or PL0 mode: 116 - * 117 - * For any Access flag fault or Translation fault, and also for any 118 - * Permission fault on the stage 2 translation of a memory access 119 - * made as part of a translation table walk for a stage 1 translation, 120 - * the HPFAR holds the IPA that caused the fault. Otherwise, the HPFAR 121 - * is UNKNOWN. 122 - */ 123 - if (!(hsr & HSR_DABT_S1PTW) && (hsr & HSR_FSC_TYPE) == FSC_PERM) { 124 - u64 par, tmp; 125 - 126 - par = read_sysreg(PAR); 127 - write_sysreg(far, ATS1CPR); 128 - isb(); 129 - 130 - tmp = read_sysreg(PAR); 131 - write_sysreg(par, PAR); 132 - 133 - if (unlikely(tmp & 1)) 134 - return false; /* Translation failed, back to guest */ 135 - 136 - hpfar = ((tmp >> 12) & ((1UL << 28) - 1)) << 4; 137 - } else { 138 - hpfar = read_sysreg(HPFAR); 139 - } 140 - 141 - vcpu->arch.fault.hxfar = far; 142 - vcpu->arch.fault.hpfar = hpfar; 143 - return true; 144 - } 145 - 146 - int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) 147 - { 148 - struct kvm_cpu_context *host_ctxt; 149 - struct kvm_cpu_context *guest_ctxt; 150 - bool fp_enabled; 151 - u64 exit_code; 152 - u32 fpexc; 153 - 154 - vcpu = kern_hyp_va(vcpu); 155 - write_sysreg(vcpu, HTPIDR); 156 - 157 - host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); 158 - guest_ctxt = &vcpu->arch.ctxt; 159 - 160 - __sysreg_save_state(host_ctxt); 161 - __banked_save_state(host_ctxt); 162 - 163 - __activate_traps(vcpu, &fpexc); 164 - __activate_vm(vcpu); 165 - 166 - __vgic_restore_state(vcpu); 167 - __timer_enable_traps(vcpu); 168 - 169 - __sysreg_restore_state(guest_ctxt); 170 - __banked_restore_state(guest_ctxt); 171 - 172 - /* Jump in the fire! */ 173 - again: 174 - exit_code = __guest_enter(vcpu, host_ctxt); 175 - /* And we're baaack! */ 176 - 177 - if (exit_code == ARM_EXCEPTION_HVC && !__populate_fault_info(vcpu)) 178 - goto again; 179 - 180 - fp_enabled = __vfp_enabled(); 181 - 182 - __banked_save_state(guest_ctxt); 183 - __sysreg_save_state(guest_ctxt); 184 - __timer_disable_traps(vcpu); 185 - 186 - __vgic_save_state(vcpu); 187 - 188 - __deactivate_traps(vcpu); 189 - __deactivate_vm(vcpu); 190 - 191 - __banked_restore_state(host_ctxt); 192 - __sysreg_restore_state(host_ctxt); 193 - 194 - if (fp_enabled) { 195 - __vfp_save_state(&guest_ctxt->vfp); 196 - __vfp_restore_state(&host_ctxt->vfp); 197 - } 198 - 199 - write_sysreg(fpexc, VFP_FPEXC); 200 - 201 - return exit_code; 202 - } 203 - 204 - static const char * const __hyp_panic_string[] = { 205 - [ARM_EXCEPTION_RESET] = "\nHYP panic: RST PC:%08x CPSR:%08x", 206 - [ARM_EXCEPTION_UNDEFINED] = "\nHYP panic: UNDEF PC:%08x CPSR:%08x", 207 - [ARM_EXCEPTION_SOFTWARE] = "\nHYP panic: SVC PC:%08x CPSR:%08x", 208 - [ARM_EXCEPTION_PREF_ABORT] = "\nHYP panic: PABRT PC:%08x CPSR:%08x", 209 - [ARM_EXCEPTION_DATA_ABORT] = "\nHYP panic: DABRT PC:%08x ADDR:%08x", 210 - [ARM_EXCEPTION_IRQ] = "\nHYP panic: IRQ PC:%08x CPSR:%08x", 211 - [ARM_EXCEPTION_FIQ] = "\nHYP panic: FIQ PC:%08x CPSR:%08x", 212 - [ARM_EXCEPTION_HVC] = "\nHYP panic: HVC PC:%08x CPSR:%08x", 213 - }; 214 - 215 - void __hyp_text __noreturn __hyp_panic(int cause) 216 - { 217 - u32 elr = read_special(ELR_hyp); 218 - u32 val; 219 - 220 - if (cause == ARM_EXCEPTION_DATA_ABORT) 221 - val = read_sysreg(HDFAR); 222 - else 223 - val = read_special(SPSR); 224 - 225 - if (read_sysreg(VTTBR)) { 226 - struct kvm_vcpu *vcpu; 227 - struct kvm_cpu_context *host_ctxt; 228 - 229 - vcpu = (struct kvm_vcpu *)read_sysreg(HTPIDR); 230 - host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); 231 - __timer_disable_traps(vcpu); 232 - __deactivate_traps(vcpu); 233 - __deactivate_vm(vcpu); 234 - __banked_restore_state(host_ctxt); 235 - __sysreg_restore_state(host_ctxt); 236 - } 237 - 238 - /* Call panic for real */ 239 - __hyp_do_panic(__hyp_panic_string[cause], elr, val); 240 - 241 - unreachable(); 242 - }
-68
arch/arm/kvm/hyp/tlb.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Original code: 4 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 5 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 6 - * 7 - * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com> 8 - */ 9 - 10 - #include <asm/kvm_hyp.h> 11 - #include <asm/kvm_mmu.h> 12 - 13 - /** 14 - * Flush per-VMID TLBs 15 - * 16 - * __kvm_tlb_flush_vmid(struct kvm *kvm); 17 - * 18 - * We rely on the hardware to broadcast the TLB invalidation to all CPUs 19 - * inside the inner-shareable domain (which is the case for all v7 20 - * implementations). If we come across a non-IS SMP implementation, we'll 21 - * have to use an IPI based mechanism. Until then, we stick to the simple 22 - * hardware assisted version. 23 - * 24 - * As v7 does not support flushing per IPA, just nuke the whole TLB 25 - * instead, ignoring the ipa value. 26 - */ 27 - void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) 28 - { 29 - dsb(ishst); 30 - 31 - /* Switch to requested VMID */ 32 - kvm = kern_hyp_va(kvm); 33 - write_sysreg(kvm_get_vttbr(kvm), VTTBR); 34 - isb(); 35 - 36 - write_sysreg(0, TLBIALLIS); 37 - dsb(ish); 38 - isb(); 39 - 40 - write_sysreg(0, VTTBR); 41 - } 42 - 43 - void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) 44 - { 45 - __kvm_tlb_flush_vmid(kvm); 46 - } 47 - 48 - void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) 49 - { 50 - struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm); 51 - 52 - /* Switch to requested VMID */ 53 - write_sysreg(kvm_get_vttbr(kvm), VTTBR); 54 - isb(); 55 - 56 - write_sysreg(0, TLBIALL); 57 - dsb(nsh); 58 - isb(); 59 - 60 - write_sysreg(0, VTTBR); 61 - } 62 - 63 - void __hyp_text __kvm_flush_vm_context(void) 64 - { 65 - write_sysreg(0, TLBIALLNSNHIS); 66 - write_sysreg(0, ICIALLUIS); 67 - dsb(ish); 68 - }
-57
arch/arm/kvm/hyp/vfp.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/linkage.h> 8 - #include <asm/vfpmacros.h> 9 - 10 - .text 11 - .pushsection .hyp.text, "ax" 12 - 13 - /* void __vfp_save_state(struct vfp_hard_struct *vfp); */ 14 - ENTRY(__vfp_save_state) 15 - push {r4, r5} 16 - VFPFMRX r1, FPEXC 17 - 18 - @ Make sure *really* VFP is enabled so we can touch the registers. 19 - orr r5, r1, #FPEXC_EN 20 - tst r5, #FPEXC_EX @ Check for VFP Subarchitecture 21 - bic r5, r5, #FPEXC_EX @ FPEXC_EX disable 22 - VFPFMXR FPEXC, r5 23 - isb 24 - 25 - VFPFMRX r2, FPSCR 26 - beq 1f 27 - 28 - @ If FPEXC_EX is 0, then FPINST/FPINST2 reads are upredictable, so 29 - @ we only need to save them if FPEXC_EX is set. 30 - VFPFMRX r3, FPINST 31 - tst r5, #FPEXC_FP2V 32 - VFPFMRX r4, FPINST2, ne @ vmrsne 33 - 1: 34 - VFPFSTMIA r0, r5 @ Save VFP registers 35 - stm r0, {r1-r4} @ Save FPEXC, FPSCR, FPINST, FPINST2 36 - pop {r4, r5} 37 - bx lr 38 - ENDPROC(__vfp_save_state) 39 - 40 - /* void __vfp_restore_state(struct vfp_hard_struct *vfp); 41 - * Assume FPEXC_EN is on and FPEXC_EX is off */ 42 - ENTRY(__vfp_restore_state) 43 - VFPFLDMIA r0, r1 @ Load VFP registers 44 - ldm r0, {r0-r3} @ Load FPEXC, FPSCR, FPINST, FPINST2 45 - 46 - VFPFMXR FPSCR, r1 47 - tst r0, #FPEXC_EX @ Check for VFP Subarchitecture 48 - beq 1f 49 - VFPFMXR FPINST, r2 50 - tst r0, #FPEXC_FP2V 51 - VFPFMXR FPINST2, r3, ne 52 - 1: 53 - VFPFMXR FPEXC, r0 @ FPEXC (last, in case !EN) 54 - bx lr 55 - ENDPROC(__vfp_restore_state) 56 - 57 - .popsection
-157
arch/arm/kvm/init.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/linkage.h> 8 - #include <asm/assembler.h> 9 - #include <asm/unified.h> 10 - #include <asm/asm-offsets.h> 11 - #include <asm/kvm_asm.h> 12 - #include <asm/kvm_arm.h> 13 - #include <asm/kvm_mmu.h> 14 - #include <asm/virt.h> 15 - 16 - /******************************************************************** 17 - * Hypervisor initialization 18 - * - should be called with: 19 - * r0 = top of Hyp stack (kernel VA) 20 - * r1 = pointer to hyp vectors 21 - * r2,r3 = Hypervisor pgd pointer 22 - * 23 - * The init scenario is: 24 - * - We jump in HYP with 3 parameters: runtime HYP pgd, runtime stack, 25 - * runtime vectors 26 - * - Invalidate TLBs 27 - * - Set stack and vectors 28 - * - Setup the page tables 29 - * - Enable the MMU 30 - * - Profit! (or eret, if you only care about the code). 31 - * 32 - * Another possibility is to get a HYP stub hypercall. 33 - * We discriminate between the two by checking if r0 contains a value 34 - * that is less than HVC_STUB_HCALL_NR. 35 - */ 36 - 37 - .text 38 - .pushsection .hyp.idmap.text,"ax" 39 - .align 5 40 - __kvm_hyp_init: 41 - .globl __kvm_hyp_init 42 - 43 - @ Hyp-mode exception vector 44 - W(b) . 45 - W(b) . 46 - W(b) . 47 - W(b) . 48 - W(b) . 49 - W(b) __do_hyp_init 50 - W(b) . 51 - W(b) . 52 - 53 - __do_hyp_init: 54 - @ Check for a stub hypercall 55 - cmp r0, #HVC_STUB_HCALL_NR 56 - blo __kvm_handle_stub_hvc 57 - 58 - @ Set stack pointer 59 - mov sp, r0 60 - 61 - @ Set HVBAR to point to the HYP vectors 62 - mcr p15, 4, r1, c12, c0, 0 @ HVBAR 63 - 64 - @ Set the HTTBR to point to the hypervisor PGD pointer passed 65 - mcrr p15, 4, rr_lo_hi(r2, r3), c2 66 - 67 - @ Set the HTCR and VTCR to the same shareability and cacheability 68 - @ settings as the non-secure TTBCR and with T0SZ == 0. 69 - mrc p15, 4, r0, c2, c0, 2 @ HTCR 70 - ldr r2, =HTCR_MASK 71 - bic r0, r0, r2 72 - mrc p15, 0, r1, c2, c0, 2 @ TTBCR 73 - and r1, r1, #(HTCR_MASK & ~TTBCR_T0SZ) 74 - orr r0, r0, r1 75 - mcr p15, 4, r0, c2, c0, 2 @ HTCR 76 - 77 - @ Use the same memory attributes for hyp. accesses as the kernel 78 - @ (copy MAIRx ro HMAIRx). 79 - mrc p15, 0, r0, c10, c2, 0 80 - mcr p15, 4, r0, c10, c2, 0 81 - mrc p15, 0, r0, c10, c2, 1 82 - mcr p15, 4, r0, c10, c2, 1 83 - 84 - @ Invalidate the stale TLBs from Bootloader 85 - mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH 86 - dsb ish 87 - 88 - @ Set the HSCTLR to: 89 - @ - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel) 90 - @ - Endianness: Kernel config 91 - @ - Fast Interrupt Features: Kernel config 92 - @ - Write permission implies XN: disabled 93 - @ - Instruction cache: enabled 94 - @ - Data/Unified cache: enabled 95 - @ - MMU: enabled (this code must be run from an identity mapping) 96 - mrc p15, 4, r0, c1, c0, 0 @ HSCR 97 - ldr r2, =HSCTLR_MASK 98 - bic r0, r0, r2 99 - mrc p15, 0, r1, c1, c0, 0 @ SCTLR 100 - ldr r2, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C) 101 - and r1, r1, r2 102 - ARM( ldr r2, =(HSCTLR_M) ) 103 - THUMB( ldr r2, =(HSCTLR_M | HSCTLR_TE) ) 104 - orr r1, r1, r2 105 - orr r0, r0, r1 106 - mcr p15, 4, r0, c1, c0, 0 @ HSCR 107 - isb 108 - 109 - eret 110 - 111 - ENTRY(__kvm_handle_stub_hvc) 112 - cmp r0, #HVC_SOFT_RESTART 113 - bne 1f 114 - 115 - /* The target is expected in r1 */ 116 - msr ELR_hyp, r1 117 - mrs r0, cpsr 118 - bic r0, r0, #MODE_MASK 119 - orr r0, r0, #HYP_MODE 120 - THUMB( orr r0, r0, #PSR_T_BIT ) 121 - msr spsr_cxsf, r0 122 - b reset 123 - 124 - 1: cmp r0, #HVC_RESET_VECTORS 125 - bne 1f 126 - 127 - reset: 128 - /* We're now in idmap, disable MMU */ 129 - mrc p15, 4, r1, c1, c0, 0 @ HSCTLR 130 - ldr r0, =(HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I) 131 - bic r1, r1, r0 132 - mcr p15, 4, r1, c1, c0, 0 @ HSCTLR 133 - 134 - /* 135 - * Install stub vectors, using ardb's VA->PA trick. 136 - */ 137 - 0: adr r0, 0b @ PA(0) 138 - movw r1, #:lower16:__hyp_stub_vectors - 0b @ VA(stub) - VA(0) 139 - movt r1, #:upper16:__hyp_stub_vectors - 0b 140 - add r1, r1, r0 @ PA(stub) 141 - mcr p15, 4, r1, c12, c0, 0 @ HVBAR 142 - b exit 143 - 144 - 1: ldr r0, =HVC_STUB_ERR 145 - eret 146 - 147 - exit: 148 - mov r0, #0 149 - eret 150 - ENDPROC(__kvm_handle_stub_hvc) 151 - 152 - .ltorg 153 - 154 - .globl __kvm_hyp_init_end 155 - __kvm_hyp_init_end: 156 - 157 - .popsection
-36
arch/arm/kvm/interrupts.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - 7 - #include <linux/linkage.h> 8 - 9 - .text 10 - 11 - /******************************************************************** 12 - * Call function in Hyp mode 13 - * 14 - * 15 - * unsigned long kvm_call_hyp(void *hypfn, ...); 16 - * 17 - * This is not really a variadic function in the classic C-way and care must 18 - * be taken when calling this to ensure parameters are passed in registers 19 - * only, since the stack will change between the caller and the callee. 20 - * 21 - * Call the function with the first argument containing a pointer to the 22 - * function you wish to call in Hyp mode, and subsequent arguments will be 23 - * passed as r0, r1, and r2 (a maximum of 3 arguments in addition to the 24 - * function pointer can be passed). The function being called must be mapped 25 - * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are 26 - * passed in r0 (strictly 32bit). 27 - * 28 - * The calling convention follows the standard AAPCS: 29 - * r0 - r3: caller save 30 - * r12: caller save 31 - * rest: callee save 32 - */ 33 - ENTRY(__kvm_call_hyp) 34 - hvc #0 35 - bx lr 36 - ENDPROC(__kvm_call_hyp)
-16
arch/arm/kvm/irq.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * irq.h: in kernel interrupt controller related definitions 4 - * Copyright (c) 2016 Red Hat, Inc. 5 - * 6 - * This header is included by irqchip.c. However, on ARM, interrupt 7 - * controller declarations are located in include/kvm/arm_vgic.h since 8 - * they are mostly shared between arm and arm64. 9 - */ 10 - 11 - #ifndef __IRQ_H 12 - #define __IRQ_H 13 - 14 - #include <kvm/arm_vgic.h> 15 - 16 - #endif
-86
arch/arm/kvm/reset.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 4 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 5 - */ 6 - #include <linux/compiler.h> 7 - #include <linux/errno.h> 8 - #include <linux/sched.h> 9 - #include <linux/kvm_host.h> 10 - #include <linux/kvm.h> 11 - 12 - #include <asm/unified.h> 13 - #include <asm/ptrace.h> 14 - #include <asm/cputype.h> 15 - #include <asm/kvm_arm.h> 16 - #include <asm/kvm_coproc.h> 17 - #include <asm/kvm_emulate.h> 18 - 19 - #include <kvm/arm_arch_timer.h> 20 - 21 - /****************************************************************************** 22 - * Cortex-A15 and Cortex-A7 Reset Values 23 - */ 24 - 25 - static struct kvm_regs cortexa_regs_reset = { 26 - .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, 27 - }; 28 - 29 - 30 - /******************************************************************************* 31 - * Exported reset function 32 - */ 33 - 34 - /** 35 - * kvm_reset_vcpu - sets core registers and cp15 registers to reset value 36 - * @vcpu: The VCPU pointer 37 - * 38 - * This function finds the right table above and sets the registers on the 39 - * virtual CPU struct to their architecturally defined reset values. 40 - */ 41 - int kvm_reset_vcpu(struct kvm_vcpu *vcpu) 42 - { 43 - struct kvm_regs *reset_regs; 44 - 45 - switch (vcpu->arch.target) { 46 - case KVM_ARM_TARGET_CORTEX_A7: 47 - case KVM_ARM_TARGET_CORTEX_A15: 48 - reset_regs = &cortexa_regs_reset; 49 - vcpu->arch.midr = read_cpuid_id(); 50 - break; 51 - default: 52 - return -ENODEV; 53 - } 54 - 55 - /* Reset core registers */ 56 - memcpy(&vcpu->arch.ctxt.gp_regs, reset_regs, sizeof(vcpu->arch.ctxt.gp_regs)); 57 - 58 - /* Reset CP15 registers */ 59 - kvm_reset_coprocs(vcpu); 60 - 61 - /* 62 - * Additional reset state handling that PSCI may have imposed on us. 63 - * Must be done after all the sys_reg reset. 64 - */ 65 - if (READ_ONCE(vcpu->arch.reset_state.reset)) { 66 - unsigned long target_pc = vcpu->arch.reset_state.pc; 67 - 68 - /* Gracefully handle Thumb2 entry point */ 69 - if (target_pc & 1) { 70 - target_pc &= ~1UL; 71 - vcpu_set_thumb(vcpu); 72 - } 73 - 74 - /* Propagate caller endianness */ 75 - if (vcpu->arch.reset_state.be) 76 - kvm_vcpu_set_be(vcpu); 77 - 78 - *vcpu_pc(vcpu) = target_pc; 79 - vcpu_set_reg(vcpu, 0, vcpu->arch.reset_state.r0); 80 - 81 - vcpu->arch.reset_state.reset = false; 82 - } 83 - 84 - /* Reset arch_timer context */ 85 - return kvm_timer_vcpu_reset(vcpu); 86 - }
-86
arch/arm/kvm/trace.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #if !defined(_TRACE_ARM_KVM_H) || defined(TRACE_HEADER_MULTI_READ) 3 - #define _TRACE_ARM_KVM_H 4 - 5 - #include <linux/tracepoint.h> 6 - 7 - #undef TRACE_SYSTEM 8 - #define TRACE_SYSTEM kvm 9 - 10 - /* Architecturally implementation defined CP15 register access */ 11 - TRACE_EVENT(kvm_emulate_cp15_imp, 12 - TP_PROTO(unsigned long Op1, unsigned long Rt1, unsigned long CRn, 13 - unsigned long CRm, unsigned long Op2, bool is_write), 14 - TP_ARGS(Op1, Rt1, CRn, CRm, Op2, is_write), 15 - 16 - TP_STRUCT__entry( 17 - __field( unsigned int, Op1 ) 18 - __field( unsigned int, Rt1 ) 19 - __field( unsigned int, CRn ) 20 - __field( unsigned int, CRm ) 21 - __field( unsigned int, Op2 ) 22 - __field( bool, is_write ) 23 - ), 24 - 25 - TP_fast_assign( 26 - __entry->is_write = is_write; 27 - __entry->Op1 = Op1; 28 - __entry->Rt1 = Rt1; 29 - __entry->CRn = CRn; 30 - __entry->CRm = CRm; 31 - __entry->Op2 = Op2; 32 - ), 33 - 34 - TP_printk("Implementation defined CP15: %s\tp15, %u, r%u, c%u, c%u, %u", 35 - (__entry->is_write) ? "mcr" : "mrc", 36 - __entry->Op1, __entry->Rt1, __entry->CRn, 37 - __entry->CRm, __entry->Op2) 38 - ); 39 - 40 - TRACE_EVENT(kvm_wfx, 41 - TP_PROTO(unsigned long vcpu_pc, bool is_wfe), 42 - TP_ARGS(vcpu_pc, is_wfe), 43 - 44 - TP_STRUCT__entry( 45 - __field( unsigned long, vcpu_pc ) 46 - __field( bool, is_wfe ) 47 - ), 48 - 49 - TP_fast_assign( 50 - __entry->vcpu_pc = vcpu_pc; 51 - __entry->is_wfe = is_wfe; 52 - ), 53 - 54 - TP_printk("guest executed wf%c at: 0x%08lx", 55 - __entry->is_wfe ? 'e' : 'i', __entry->vcpu_pc) 56 - ); 57 - 58 - TRACE_EVENT(kvm_hvc, 59 - TP_PROTO(unsigned long vcpu_pc, unsigned long r0, unsigned long imm), 60 - TP_ARGS(vcpu_pc, r0, imm), 61 - 62 - TP_STRUCT__entry( 63 - __field( unsigned long, vcpu_pc ) 64 - __field( unsigned long, r0 ) 65 - __field( unsigned long, imm ) 66 - ), 67 - 68 - TP_fast_assign( 69 - __entry->vcpu_pc = vcpu_pc; 70 - __entry->r0 = r0; 71 - __entry->imm = imm; 72 - ), 73 - 74 - TP_printk("HVC at 0x%08lx (r0: 0x%08lx, imm: 0x%lx", 75 - __entry->vcpu_pc, __entry->r0, __entry->imm) 76 - ); 77 - 78 - #endif /* _TRACE_ARM_KVM_H */ 79 - 80 - #undef TRACE_INCLUDE_PATH 81 - #define TRACE_INCLUDE_PATH . 82 - #undef TRACE_INCLUDE_FILE 83 - #define TRACE_INCLUDE_FILE trace 84 - 85 - /* This part must be outside protection */ 86 - #include <trace/define_trace.h>
-27
arch/arm/kvm/vgic-v3-coproc.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * VGIC system registers handling functions for AArch32 mode 4 - */ 5 - 6 - #include <linux/kvm.h> 7 - #include <linux/kvm_host.h> 8 - #include <asm/kvm_emulate.h> 9 - #include "vgic.h" 10 - 11 - int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, bool is_write, u64 id, 12 - u64 *reg) 13 - { 14 - /* 15 - * TODO: Implement for AArch32 16 - */ 17 - return -ENXIO; 18 - } 19 - 20 - int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write, u64 id, 21 - u64 *reg) 22 - { 23 - /* 24 - * TODO: Implement for AArch32 25 - */ 26 - return -ENXIO; 27 - }