KVM: arm64: Fixed features for protected VMs
v8 cover KVM: arm64: Fixed features for protected VMs
Hi,
Changes since v7 [1]:
- Fix build warnings
This patch series adds support for restricting CPU features for protected VMs in KVM (pKVM). For more background, please refer to the previous series [2].
This series is based on 5.15-rc4. You can find the applied series here [3].
Cheers,
/fuad
[1] https://lore.kernel.org/kvmarm/[email protected]/
[2] https://lore.kernel.org/kvmarm/[email protected]/
[3] https://android-kvm.googlesource.com/linux/+/refs/heads/tabba/el2_fixed_feature_v8
Fuad Tabba (8):
KVM: arm64: Pass struct kvm to per-EC handlers
KVM: arm64: Add missing field descriptor for MDCR_EL2
KVM: arm64: Simplify masking out MTE in feature id reg
KVM: arm64: Add handlers for protected VM System Registers
KVM: arm64: Initialize trap registers for protected VMs
KVM: arm64: Move sanitized copies of CPU features
KVM: arm64: Trap access to pVM restricted features
KVM: arm64: Handle protected guests at 32 bits
Marc Zyngier (3):
KVM: arm64: Move __get_fault_info() and co into their own include file
KVM: arm64: Don't include switch.h into nvhe/kvm-main.c
KVM: arm64: Move early handlers to per-EC handlers
arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_fixed_config.h | 195 +++++++ arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kvm/arm.c | 13 + arch/arm64/kvm/hyp/include/hyp/fault.h | 75 +++ arch/arm64/kvm/hyp/include/hyp/switch.h | 221 ++++---- arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 29 + .../arm64/kvm/hyp/include/nvhe/trap_handler.h | 2 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 8 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 186 +++++++ arch/arm64/kvm/hyp/nvhe/setup.c | 3 + arch/arm64/kvm/hyp/nvhe/switch.c | 108 ++++ arch/arm64/kvm/hyp/nvhe/sys_regs.c | 500 ++++++++++++++++++ arch/arm64/kvm/hyp/vhe/switch.c | 16 + arch/arm64/kvm/sys_regs.c | 10 +- 19 files changed, 1243 insertions(+), 145 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_fixed_config.h create mode 100644 arch/arm64/kvm/hyp/include/hyp/fault.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/sys_regs.h create mode 100644 arch/arm64/kvm/hyp/nvhe/pkvm.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sys_regs.c
base-commit: 1da38549dd64c7f5dd22427f12dfa8db3d8a722b
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 1/11 KVM: arm64: Move __get_fault_info() and co into their own include file
From: Marc Zyngier <[email protected]>
In order to avoid including the whole of the switching helpers in unrelated files, move the __get_fault_info() and related helpers into their own include file.
--- arch/arm64/kvm/hyp/include/hyp/fault.h | 75 +++++++++++++++++++++++++ arch/arm64/kvm/hyp/include/hyp/switch.h | 61 +------------------- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- 3 files changed, 77 insertions(+), 61 deletions(-) create mode 100644 arch/arm64/kvm/hyp/include/hyp/fault.h
arch/arm64/kvm/hyp/include/hyp/fault.h new file +75 -0
@@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2015 - ARM Ltd +* Author: Marc Zyngier <[email protected]> +*/ + +#ifndef __ARM64_KVM_HYP_FAULT_H__ +#define __ARM64_KVM_HYP_FAULT_H__ + +#include <asm/kvm_asm.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_hyp.h> +#include <asm/kvm_mmu.h> + +static inline bool __translate_far_to_hpfar (u64 far,u64 *hpfar) +{ +u64 par, tmp; + +/* +* Resolve the IPA the hard way using the guest VA. +* +* Stage-1 translation already validated the memory access +* rights. As such, we can use the EL1 translation regime, and +* don't have to distinguish between EL0 and EL1 access. +* +* We do need to save/restore PAR_EL1 though, as we haven't +* saved the guest context yet, and we may return early... +*/ + par =read_sysreg_par (); +if (!__kvm_at ("s1e1r" , far)) + tmp =read_sysreg_par (); +else + tmp =SYS_PAR_EL1_F ;/* back to the guest */ +write_sysreg (par, par_el1); + +if (unlikely (tmp &SYS_PAR_EL1_F )) +return false;/* Translation failed, back to guest */ + +/* Convert PAR to HPFAR format */ + *hpfar =PAR_TO_HPFAR (tmp); +return true; +} + +static inline bool __get_fault_info (u64 esr,struct kvm_vcpu_fault_info *fault) +{ +u64 hpfar, far; + + far =read_sysreg_el2 (SYS_FAR ); + +/* +* The HPFAR can be invalid if the stage 2 fault did not +* happen during a stage 1 page table walk (the ESR_EL2.S1PTW +* bit is clear) and one of the two following cases are true: +* 1. The fault was due to a permission fault +* 2. The processor carries errata 834220 +* +* Therefore, for all non S1PTW faults where we either have a +* permission fault or the errata workaround is enabled, we +* resolve the IPA using the AT instruction. +*/ +if (!(esr & ESR_ELx_S1PTW) && + (cpus_have_final_cap (ARM64_WORKAROUND_834220 ) || + (esr & ESR_ELx_FSC_TYPE) ==FSC_PERM )) { +if (!__translate_far_to_hpfar (far, &hpfar)) +return false; + }else { + hpfar =read_sysreg (hpfar_el2); + } + + fault->far_el2 = far; + fault->hpfar_el2 = hpfar; +return true; +} + +#endif
arch/arm64/kvm/hyp/include/hyp/switch.h +1 -60
73 lines not on this page · raw message
arch/arm64/kvm/hyp/nvhe/mem_protect.c +1 -1
@@ -11,7 +11,7 @@#include <asm/kvm_pgtable.h> #include <asm/stage2_pgtable.h> -#include <hyp/switch.h> +#include <hyp/fault.h> #include <nvhe/gfp.h> #include <nvhe/memory.h>
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 2/11 KVM: arm64: Don't include switch.h into nvhe/kvm-main.c
In reply to Fuad TabbaFrom: Marc Zyngier <[email protected]>
hyp-main.c includes switch.h while it only requires adjust-pc.h. Fix it to remove an unnecessary dependency.
--- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +1 -1
@@ -4,7 +4,7 @@* Author: Andrew Scull <[email protected]> */ -#include <hyp/switch.h> +#include <hyp/adjust_pc.h> #include <asm/pgtable-types.h> #include <asm/kvm_asm.h>
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 3/11 KVM: arm64: Move early handlers to per-EC handlers
In reply to Fuad TabbaFrom: Marc Zyngier <[email protected]>
Simplify the early exception handling by slicing the gigantic decoding tree into a more manageable set of functions, similar to what we have in handle_exit.c.
This will also make the structure reusable for pKVM's own early exit handling.
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 160 ++++++++++++++---------- arch/arm64/kvm/hyp/nvhe/switch.c | 16 +++ arch/arm64/kvm/hyp/vhe/switch.c | 16 +++ 3 files changed, 124 insertions(+), 68 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +92 -68
@@ -136,16 +136,7 @@ static inline void ___deactivate_traps(struct kvm_vcpu *vcpu)static inline bool __populate_fault_info (struct kvm_vcpu *vcpu) { -u8 ec; -u64 esr; - - esr = vcpu->arch.fault.esr_el2; - ec =ESR_ELx_EC (esr); - -if (ec != ESR_ELx_EC_DABT_LOW && ec != ESR_ELx_EC_IABT_LOW) -return true; - -return __get_fault_info (esr, &vcpu->arch.fault); +return __get_fault_info (vcpu->arch.fault.esr_el2, &vcpu->arch.fault); }static inline void __hyp_sve_save_host (struct kvm_vcpu *vcpu)
@@ -166,8 +157,13 @@ static inline void __hyp_sve_restore_guest(struct kvm_vcpu *vcpu)write_sysreg_el1 (__vcpu_sys_reg (vcpu,ZCR_EL1 ),SYS_ZCR ); } -/* Check for an FPSIMD/SVE trap and handle as appropriate */ -static inline bool __hyp_handle_fpsimd (struct kvm_vcpu *vcpu) +/* +* We trap the first access to the FP/SIMD to save the host context and +* restore the guest context lazily. +* If FP/SIMD is not implemented, handle the trap and inject an undefined +* instruction exception to the guest. Similarly for trapped SVE accesses. +*/ +static bool kvm_hyp_handle_fpsimd (struct kvm_vcpu *vcpu,u64 *exit_code) {bool sve_guest, sve_host;u8 esr_ec;
@@ -185,9 +181,6 @@ static inline bool __hyp_handle_fpsimd(struct kvm_vcpu *vcpu) } esr_ec =kvm_vcpu_trap_get_class (vcpu); -if (esr_ec != ESR_ELx_EC_FP_ASIMD && - esr_ec != ESR_ELx_EC_SVE) -return false;/* Don't handle SVE traps for non-SVE vcpus here: */ if (!sve_guest && esr_ec != ESR_ELx_EC_FP_ASIMD)
@@ -325,7 +318,7 @@ static inline bool esr_is_ptrauth_trap(u32 esr) DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); -static inline bool __hyp_handle_ptrauth (struct kvm_vcpu *vcpu) +static bool kvm_hyp_handle_ptrauth (struct kvm_vcpu *vcpu,u64 *exit_code) {struct kvm_cpu_context *ctxt;u64 val;
@@ -350,6 +343,87 @@ static inline bool __hyp_handle_ptrauth(struct kvm_vcpu *vcpu)return true; } +static bool kvm_hyp_handle_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +if (cpus_have_final_cap (ARM64_WORKAROUND_CAVIUM_TX2_219_TVM ) && +handle_tx2_tvm (vcpu)) +return true; + +if (static_branch_unlikely (&vgic_v3_cpuif_trap) && +__vgic_v3_perform_cpuif_access (vcpu) ==1 ) +return true; + +return false; +} + +static bool kvm_hyp_handle_cp15_32 (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +if (static_branch_unlikely (&vgic_v3_cpuif_trap) && +__vgic_v3_perform_cpuif_access (vcpu) ==1 ) +return true; + +return false; +} + +static bool kvm_hyp_handle_iabt_low (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +if (!__populate_fault_info (vcpu)) +return true; + +return false; +} + +static bool kvm_hyp_handle_dabt_low (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +if (!__populate_fault_info (vcpu)) +return true; + +if (static_branch_unlikely (&vgic_v2_cpuif_trap)) { +bool valid; + + valid =kvm_vcpu_trap_get_fault_type (vcpu) ==FSC_FAULT && +kvm_vcpu_dabt_isvalid (vcpu) && + !kvm_vcpu_abt_issea (vcpu) && + !kvm_vcpu_abt_iss1tw (vcpu); + +if (valid) { +int ret =__vgic_v2_perform_cpuif_access (vcpu); + +if (ret ==1 ) +return true; + +/* Promote an illegal access to an SError.*/ +if (ret ==-1 ) + *exit_code =ARM_EXCEPTION_EL1_SERROR ; + } + } + +return false; +} + +typedef bool (*exit_handler_fn )(struct kvm_vcpu *,u64 *); + +static const exit_handler_fn *kvm_get_exit_handler_array (void ); + +/* +* Allow the hypervisor to handle the exit with an exit handler if it has one. +* +* Returns true if the hypervisor handled the exit, and control should go back +* to the guest, or false if it hasn't. +*/ +static inline bool kvm_hyp_handle_exit (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +const exit_handler_fn *handlers =kvm_get_exit_handler_array (); +exit_handler_fn fn; + + fn = handlers[kvm_vcpu_trap_get_class (vcpu)]; + +if (fn) +return fn (vcpu, exit_code); + +return false; +} +/* * Return true when we were able to fixup the guest exit and should return to * the guest, false when we should restore the host state and return to the
@@ -384,59 +458,9 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)if (*exit_code !=ARM_EXCEPTION_TRAP ) goto exit; -if (cpus_have_final_cap (ARM64_WORKAROUND_CAVIUM_TX2_219_TVM ) && -kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_SYS64 && -handle_tx2_tvm (vcpu)) +/* Check if there's an exit handler and allow it to handle the exit. */ +if (kvm_hyp_handle_exit (vcpu, exit_code)) goto guest; - -/* -* We trap the first access to the FP/SIMD to save the host context -* and restore the guest context lazily. -* If FP/SIMD is not implemented, handle the trap and inject an -* undefined instruction exception to the guest. -* Similarly for trapped SVE accesses. -*/ -if (__hyp_handle_fpsimd (vcpu)) - goto guest; - -if (__hyp_handle_ptrauth (vcpu)) - goto guest; - -if (!__populate_fault_info (vcpu)) - goto guest; - -if (static_branch_unlikely (&vgic_v2_cpuif_trap)) { -bool valid; - - valid =kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_DABT_LOW && -kvm_vcpu_trap_get_fault_type (vcpu) ==FSC_FAULT && -kvm_vcpu_dabt_isvalid (vcpu) && - !kvm_vcpu_abt_issea (vcpu) && - !kvm_vcpu_abt_iss1tw (vcpu); - -if (valid) { -int ret =__vgic_v2_perform_cpuif_access (vcpu); - -if (ret ==1 ) - goto guest; - -/* Promote an illegal access to an SError.*/ -if (ret ==-1 ) - *exit_code =ARM_EXCEPTION_EL1_SERROR ; - - goto exit; - } - } - -if (static_branch_unlikely (&vgic_v3_cpuif_trap) && - (kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_SYS64 || -kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_CP15_32)) { -int ret =__vgic_v3_perform_cpuif_access (vcpu); - -if (ret ==1 ) - goto guest; - } - exit:/* Return to the host kernel and handle the exit */ return false;
arch/arm64/kvm/hyp/nvhe/switch.c +16 -0
@@ -158,6 +158,22 @@ static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)write_sysreg (pmu->events_host, pmcntenset_el0); } +static const exit_handler_fn hyp_exit_handlers[] = { + [0 ... ESR_ELx_EC_MAX] =NULL , + [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32, + [ESR_ELx_EC_SYS64] = kvm_hyp_handle_sysreg, + [ESR_ELx_EC_SVE] = kvm_hyp_handle_fpsimd, + [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, + [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, + [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, +}; + +static const exit_handler_fn *kvm_get_exit_handler_array (void ) +{ +return hyp_exit_handlers; +} +/* Switch to the guest for legacy non-VHE systems */ int __kvm_vcpu_run (struct kvm_vcpu *vcpu) {
arch/arm64/kvm/hyp/vhe/switch.c +16 -0
@@ -96,6 +96,22 @@ void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu)__deactivate_traps_common (vcpu); } +static const exit_handler_fn hyp_exit_handlers[] = { + [0 ... ESR_ELx_EC_MAX] =NULL , + [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32, + [ESR_ELx_EC_SYS64] = kvm_hyp_handle_sysreg, + [ESR_ELx_EC_SVE] = kvm_hyp_handle_fpsimd, + [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, + [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, + [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, +}; + +static const exit_handler_fn *kvm_get_exit_handler_array (void ) +{ +return hyp_exit_handlers; +} +/* Switch to the guest for VHE systems running in EL2 */ static int __kvm_vcpu_run_vhe (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 4/11 KVM: arm64: Pass struct kvm to per-EC handlers
In reply to Fuad TabbaWe need struct kvm to check for protected VMs to be able to pick the right handlers for them in subsequent patches.
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
@@ -403,7 +403,7 @@ static bool kvm_hyp_handle_dabt_low(struct kvm_vcpu *vcpu, u64 *exit_code)typedef bool (*exit_handler_fn )(struct kvm_vcpu *,u64 *); -static const exit_handler_fn *kvm_get_exit_handler_array (void ); +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm);/* * Allow the hypervisor to handle the exit with an exit handler if it has one.
@@ -413,7 +413,7 @@ static const exit_handler_fn *kvm_get_exit_handler_array(void);*/ static inline bool kvm_hyp_handle_exit (struct kvm_vcpu *vcpu,u64 *exit_code) { -const exit_handler_fn *handlers =kvm_get_exit_handler_array (); +const exit_handler_fn *handlers =kvm_get_exit_handler_array (kern_hyp_va (vcpu->kvm));exit_handler_fn fn; fn = handlers[kvm_vcpu_trap_get_class (vcpu)];
arch/arm64/kvm/hyp/nvhe/switch.c +1 -1
@@ -169,7 +169,7 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; -static const exit_handler_fn *kvm_get_exit_handler_array (void ) +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm) {return hyp_exit_handlers; }
arch/arm64/kvm/hyp/vhe/switch.c +1 -1
@@ -107,7 +107,7 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; -static const exit_handler_fn *kvm_get_exit_handler_array (void ) +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm) {return hyp_exit_handlers; }
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 5/11 KVM: arm64: Add missing field descriptor for MDCR_EL2
In reply to Fuad TabbaIt's not currently used. Added for completeness.
No functional change intended.
--- arch/arm64/include/asm/kvm_arm.h | 1 + 1 file changed, 1 insertion(+)
arch/arm64/include/asm/kvm_arm.h +1 -0
@@ -295,6 +295,7 @@#define MDCR_EL2_HPMFZO (UL(1) << 29)#define MDCR_EL2_MTPME (UL(1) << 28)#define MDCR_EL2_TDCC (UL(1) << 27) +#define MDCR_EL2_HLP (UL(1) << 26)#define MDCR_EL2_HCCD (UL(1) << 23)#define MDCR_EL2_TTRF (UL(1) << 19)#define MDCR_EL2_HPMD (UL(1) << 17)
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 6/11 KVM: arm64: Simplify masking out MTE in feature id reg
In reply to Fuad TabbaSimplify code for hiding MTE support in feature id register when MTE is not enabled/supported by KVM.
No functional change intended.
--- arch/arm64/kvm/sys_regs.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/arm64/kvm/sys_regs.c +2 -8
@@ -1077,14 +1077,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, val |=FIELD_PREP (ARM64_FEATURE_MASK (ID_AA64PFR0_CSV3 ), (u64 )vcpu->kvm->arch.pfr0_csv3);break ;case SYS_ID_AA64PFR1_EL1 : - val &= ~ARM64_FEATURE_MASK (ID_AA64PFR1_MTE ); -if (kvm_has_mte (vcpu->kvm)) { -u64 pfr, mte; - - pfr =read_sanitised_ftr_reg (SYS_ID_AA64PFR1_EL1 ); - mte =cpuid_feature_extract_unsigned_field (pfr,ID_AA64PFR1_MTE_SHIFT ); - val |=FIELD_PREP (ARM64_FEATURE_MASK (ID_AA64PFR1_MTE ), mte); - } +if (!kvm_has_mte (vcpu->kvm)) + val &= ~ARM64_FEATURE_MASK (ID_AA64PFR1_MTE );break ;case SYS_ID_AA64ISAR1_EL1 :if (!vcpu_has_ptrauth (vcpu))
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 7/11 KVM: arm64: Add handlers for protected VM System Registers
In reply to Fuad TabbaAdd system register handlers for protected VMs. These cover Sys64 registers (including feature id registers), and debug.
No functional change intended as these are not hooked in yet to the guest exit handlers introduced earlier. So when trapping is triggered, the exit handlers let the host handle it, as before.
--- arch/arm64/include/asm/kvm_fixed_config.h | 195 ++++++++ arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kvm/arm.c | 5 + arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 29 ++ arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/setup.c | 3 + arch/arm64/kvm/hyp/nvhe/switch.c | 1 + arch/arm64/kvm/hyp/nvhe/sys_regs.c | 498 +++++++++++++++++++++ 8 files changed, 737 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/kvm_fixed_config.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/sys_regs.h create mode 100644 arch/arm64/kvm/hyp/nvhe/sys_regs.c
arch/arm64/include/asm/kvm_fixed_config.h new file +195 -0
@@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Google LLC +* Author: Fuad Tabba <[email protected]> +*/ + +#ifndef __ARM64_KVM_FIXED_CONFIG_H__ +#define __ARM64_KVM_FIXED_CONFIG_H__ + +#include <asm/sysreg.h> + +/* +* This file contains definitions for features to be allowed or restricted for +* guest virtual machines, depending on the mode KVM is running in and on the +* type of guest that is running. +* +* The ALLOW masks represent a bitmask of feature fields that are allowed +* without any restrictions as long as they are supported by the system. +* +* The RESTRICT_UNSIGNED masks, if present, represent unsigned fields for +* features that are restricted to support at most the specified feature. +* +* If a feature field is not present in either, than it is not supported. +* +* The approach taken for protected VMs is to allow features that are: +* - Needed by common Linux distributions (e.g., floating point) +* - Trivial to support, e.g., supporting the feature does not introduce or +* require tracking of additional state in KVM +* - Cannot be trapped or prevent the guest from using anyway +*/ + +/* +* Allow for protected VMs: +* - Floating-point and Advanced SIMD +* - Data Independent Timing +*/ +#define PVM_ID_AA64PFR0_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64PFR0_FP) | \ + ARM64_FEATURE_MASK(ID_AA64PFR0_ASIMD) | \ + ARM64_FEATURE_MASK(ID_AA64PFR0_DIT) \ + ) + +/* +* Restrict to the following *unsigned* features for protected VMs: +* - AArch64 guests only (no support for AArch32 guests): +* AArch32 adds complexity in trap handling, emulation, condition codes, +* etc... +* - RAS (v1) +* Supported by KVM +*/ +#define PVM_ID_AA64PFR0_RESTRICT_UNSIGNED (\ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL0), ID_AA64PFR0_ELx_64BIT_ONLY) | \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1), ID_AA64PFR0_ELx_64BIT_ONLY) | \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL2), ID_AA64PFR0_ELx_64BIT_ONLY) | \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL3), ID_AA64PFR0_ELx_64BIT_ONLY) | \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_RAS), ID_AA64PFR0_RAS_V1) \ + ) + +/* +* Allow for protected VMs: +* - Branch Target Identification +* - Speculative Store Bypassing +*/ +#define PVM_ID_AA64PFR1_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64PFR1_BT) | \ + ARM64_FEATURE_MASK(ID_AA64PFR1_SSBS) \ + ) + +/* +* Allow for protected VMs: +* - Mixed-endian +* - Distinction between Secure and Non-secure Memory +* - Mixed-endian at EL0 only +* - Non-context synchronizing exception entry and exit +*/ +#define PVM_ID_AA64MMFR0_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64MMFR0_BIGENDEL) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR0_SNSMEM) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR0_BIGENDEL0) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR0_EXS) \ + ) + +/* +* Restrict to the following *unsigned* features for protected VMs: +* - 40-bit IPA +* - 16-bit ASID +*/ +#define PVM_ID_AA64MMFR0_RESTRICT_UNSIGNED (\ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_PARANGE), ID_AA64MMFR0_PARANGE_40) | \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_ASID), ID_AA64MMFR0_ASID_16) \ + ) + +/* +* Allow for protected VMs: +* - Hardware translation table updates to Access flag and Dirty state +* - Number of VMID bits from CPU +* - Hierarchical Permission Disables +* - Privileged Access Never +* - SError interrupt exceptions from speculative reads +* - Enhanced Translation Synchronization +*/ +#define PVM_ID_AA64MMFR1_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64MMFR1_HADBS) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR1_VMIDBITS) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR1_HPD) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR1_PAN) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR1_SPECSEI) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR1_ETS) \ + ) + +/* +* Allow for protected VMs: +* - Common not Private translations +* - User Access Override +* - IESB bit in the SCTLR_ELx registers +* - Unaligned single-copy atomicity and atomic functions +* - ESR_ELx.EC value on an exception by read access to feature ID space +* - TTL field in address operations. +* - Break-before-make sequences when changing translation block size +* - E0PDx mechanism +*/ +#define PVM_ID_AA64MMFR2_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64MMFR2_CNP) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_UAO) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_IESB) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_AT) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_IDS) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_TTL) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_BBM) | \ + ARM64_FEATURE_MASK(ID_AA64MMFR2_E0PD) \ + ) + +/* +* No support for Scalable Vectors for protected VMs: +* Requires additional support from KVM, e.g., context-switching and +* trapping at EL2 +*/ +#define PVM_ID_AA64ZFR0_ALLOW (0ULL) + +/* +* No support for debug, including breakpoints, and watchpoints for protected +* VMs: +* The Arm architecture mandates support for at least the Armv8 debug +* architecture, which would include at least 2 hardware breakpoints and +* watchpoints. Providing that support to protected guests adds +* considerable state and complexity. Therefore, the reserved value of 0 is +* used for debug-related fields. +*/ +#define PVM_ID_AA64DFR0_ALLOW (0ULL) +#define PVM_ID_AA64DFR1_ALLOW (0ULL) + +/* +* No support for implementation defined features. +*/ +#define PVM_ID_AA64AFR0_ALLOW (0ULL) +#define PVM_ID_AA64AFR1_ALLOW (0ULL) + +/* +* No restrictions on instructions implemented in AArch64. +*/ +#define PVM_ID_AA64ISAR0_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64ISAR0_AES) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_SHA1) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_SHA2) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_CRC32) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_ATOMICS) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_RDM) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_SHA3) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_SM3) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_SM4) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_DP) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_FHM) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_TS) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_TLB) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR0_RNDR) \ + ) + +#define PVM_ID_AA64ISAR1_ALLOW (\ + ARM64_FEATURE_MASK(ID_AA64ISAR1_DPB) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_APA) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_API) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_JSCVT) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_FCMA) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_LRCPC) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_GPA) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_GPI) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_FRINTTS) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_SB) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_SPECRES) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_BF16) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_DGH) | \ + ARM64_FEATURE_MASK(ID_AA64ISAR1_I8MM) \ + ) + +#endif /* __ARM64_KVM_FIXED_CONFIG_H__ */
arch/arm64/include/asm/kvm_hyp.h +5 -0
@@ -115,7 +115,12 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,void __noreturn __host_enter (struct kvm_cpu_context *host_ctxt);#endif +extern u64 kvm_nvhe_sym (id_aa64pfr0_el1_sys_val ); +extern u64 kvm_nvhe_sym (id_aa64pfr1_el1_sys_val ); +extern u64 kvm_nvhe_sym (id_aa64isar0_el1_sys_val ); +extern u64 kvm_nvhe_sym (id_aa64isar1_el1_sys_val );extern u64 kvm_nvhe_sym (id_aa64mmfr0_el1_sys_val );extern u64 kvm_nvhe_sym (id_aa64mmfr1_el1_sys_val ); +extern u64 kvm_nvhe_sym (id_aa64mmfr2_el1_sys_val );#endif /* __ARM64_KVM_HYP_H__ */
arch/arm64/kvm/arm.c +5 -0
@@ -1802,8 +1802,13 @@ static int kvm_hyp_init_protection(u32 hyp_va_bits)void *addr =phys_to_virt (hyp_mem_base);int ret; +kvm_nvhe_sym (id_aa64pfr0_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ); +kvm_nvhe_sym (id_aa64pfr1_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64PFR1_EL1 ); +kvm_nvhe_sym (id_aa64isar0_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64ISAR0_EL1 ); +kvm_nvhe_sym (id_aa64isar1_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64ISAR1_EL1 );kvm_nvhe_sym (id_aa64mmfr0_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64MMFR0_EL1 );kvm_nvhe_sym (id_aa64mmfr1_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64MMFR1_EL1 ); +kvm_nvhe_sym (id_aa64mmfr2_el1_sys_val) =read_sanitised_ftr_reg (SYS_ID_AA64MMFR2_EL1 ); ret =create_hyp_mappings (addr, addr + hyp_mem_size,PAGE_HYP );if (ret)
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Google LLC +* Author: Fuad Tabba <[email protected]> +*/ + +#ifndef __ARM64_KVM_NVHE_SYS_REGS_H__ +#define __ARM64_KVM_NVHE_SYS_REGS_H__ + +#include <asm/kvm_host.h> + +u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu); +u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu); + +bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code); +int kvm_check_pvm_sysreg_table (void ); +void inject_undef64 (struct kvm_vcpu *vcpu); + +#endif /* __ARM64_KVM_NVHE_SYS_REGS_H__ */
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -14,7 +14,7 @@ lib-objs := $(addprefix ../../../lib/, $(lib-objs)) obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ hyp-main.o hyp-smp.o psci-relay.o early_alloc.o stub.o page_alloc.o \ - cache.o setup.o mm.o mem_protect.o + cache.o setup.o mm.o mem_protect.o sys_regs.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o obj-y += $(lib-objs)
arch/arm64/kvm/hyp/nvhe/setup.c +3 -0
@@ -14,6 +14,7 @@#include <nvhe/memory.h> #include <nvhe/mem_protect.h> #include <nvhe/mm.h> +#include <nvhe/sys_regs.h> #include <nvhe/trap_handler.h> struct hyp_pool hpool;
@@ -260,6 +261,8 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,void (*fn)(phys_addr_t params_pa,void *finalize_fn_va);int ret; +BUG_ON (kvm_check_pvm_sysreg_table ()); +if (!PAGE_ALIGNED (phys) || !PAGE_ALIGNED (size))return -EINVAL ;
arch/arm64/kvm/hyp/nvhe/switch.c +1 -0
@@ -28,6 +28,7 @@#include <asm/thread_info.h> #include <nvhe/mem_protect.h> +#include <nvhe/sys_regs.h> /* Non-VHE specific context */ DEFINE_PER_CPU(struct kvm_host_data, kvm_host_data);
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +498 -0
498 lines not on this page · raw message
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Marc Zyngier
maintainerRe: [PATCH v8 07/11] KVM: arm64: Add handlers for protected VM System Registers
Quoted 10 lines · Fuad Tabba
Add system register handlers for protected VMs. These cover Sys64 registers (including feature id registers), and debug.
No functional change intended as these are not hooked in yet to the guest exit handlers introduced earlier. So when trapping is triggered, the exit handlers let the host handle it, as before.
Reviewed-by Andrew Jones <[email protected]>Signed-off-by Fuad Tabba <[email protected]>
[...]
Quoted 52 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +52
-0+/* +* Architected system registers. +* Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 +* +* NOTE: Anything not explicitly listed here is *restricted by default*, i.e., +* it will lead to injecting an exception into the guest. +*/ +static const struct sys_reg_desc pvm_sys_reg_descs[] = { +/* Cache maintenance by set/way operations are restricted. */ + +/* Debug and Trace Registers are restricted. */ + +/* AArch64 mappings of the AArch32 ID registers */ +/* CRm=1 */ +AARCH32 (SYS_ID_PFR0_EL1 ), +AARCH32 (SYS_ID_PFR1_EL1 ), +AARCH32 (SYS_ID_DFR0_EL1 ), +AARCH32 (SYS_ID_AFR0_EL1 ), +AARCH32 (SYS_ID_MMFR0_EL1 ), +AARCH32 (SYS_ID_MMFR1_EL1 ), +AARCH32 (SYS_ID_MMFR2_EL1 ), +AARCH32 (SYS_ID_MMFR3_EL1 ), + +/* CRm=2 */ +AARCH32 (SYS_ID_ISAR0_EL1 ), +AARCH32 (SYS_ID_ISAR1_EL1 ), +AARCH32 (SYS_ID_ISAR2_EL1 ), +AARCH32 (SYS_ID_ISAR3_EL1 ), +AARCH32 (SYS_ID_ISAR4_EL1 ), +AARCH32 (SYS_ID_ISAR5_EL1 ), +AARCH32 (SYS_ID_MMFR4_EL1 ), +AARCH32 (SYS_ID_ISAR6_EL1 ), + +/* CRm=3 */ +AARCH32 (SYS_MVFR0_EL1 ), +AARCH32 (SYS_MVFR1_EL1 ), +AARCH32 (SYS_MVFR2_EL1 ), +AARCH32 (SYS_ID_PFR2_EL1 ), +AARCH32 (SYS_ID_DFR1_EL1 ), +AARCH32 (SYS_ID_MMFR5_EL1 ), + +/* AArch64 ID registers */ +/* CRm=4 */ +AARCH64 (SYS_ID_AA64PFR0_EL1 ), +AARCH64 (SYS_ID_AA64PFR1_EL1 ), +AARCH64 (SYS_ID_AA64ZFR0_EL1 ), +AARCH64 (SYS_ID_AA64DFR0_EL1 ), +AARCH64 (SYS_ID_AA64DFR1_EL1 ), +AARCH64 (SYS_ID_AA64AFR0_EL1 ), +AARCH64 (SYS_ID_AA64AFR1_EL1 ), +AARCH64 (SYS_ID_AA64ISAR0_EL1 ), +AARCH64 (SYS_ID_AA64ISAR1_EL1 ),
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 363
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +10
-0+AARCH64 (SYS_ID_AA64MMFR0_EL1 ), +AARCH64 (SYS_ID_AA64MMFR1_EL1 ), +AARCH64 (SYS_ID_AA64MMFR2_EL1 ), + +HOST_HANDLED (SYS_SCTLR_EL1 ), +HOST_HANDLED (SYS_ACTLR_EL1 ), +HOST_HANDLED (SYS_CPACR_EL1 ), + +HOST_HANDLED (SYS_RGSR_EL1 ), + HOST_HANDLED(SYS_GCR_EL1),
What is the expected semantics of this handling? These registers are free to use by the guest unless MTE is disabled. Either the guest accesses them directly (no trap), accesses them while MTE is disabled (trap), or access them when MTE doesn't exist.
The first and last cases are invisible to EL2. For the second case, why should we go back to EL1 rather than injecting an UNDEF directly?
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 369
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +6
-0+ +/* Scalable Vector Registers are restricted. */ + +HOST_HANDLED (SYS_TTBR0_EL1 ), +HOST_HANDLED (SYS_TTBR1_EL1 ), + HOST_HANDLED(SYS_TCR_EL1),
None of these should normally trap unless we are handling an erratum (such as Cavium 219) or that we have HCR_EL2.TVM set. The former is handled at EL2, and I don't expect any Set/Way emulation to require the latter.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 380
Quoted 11 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +11
-0+ +HOST_HANDLED (SYS_APIAKEYLO_EL1 ), +HOST_HANDLED (SYS_APIAKEYHI_EL1 ), +HOST_HANDLED (SYS_APIBKEYLO_EL1 ), +HOST_HANDLED (SYS_APIBKEYHI_EL1 ), +HOST_HANDLED (SYS_APDAKEYLO_EL1 ), +HOST_HANDLED (SYS_APDAKEYHI_EL1 ), +HOST_HANDLED (SYS_APDBKEYLO_EL1 ), +HOST_HANDLED (SYS_APDBKEYHI_EL1 ), +HOST_HANDLED (SYS_APGAKEYLO_EL1 ), + HOST_HANDLED(SYS_APGAKEYHI_EL1),
This is debatable too. If the guest has started using PtrAuth and that we haven't handled things in fixup_guest_exit(), why returning to the host? This should directly UNDEF.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 384
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +4
-0+ +HOST_HANDLED (SYS_AFSR0_EL1 ), +HOST_HANDLED (SYS_AFSR1_EL1 ), + HOST_HANDLED(SYS_ESR_EL1),
Same as TTBR*/TCR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 393
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +9
-0+ +HOST_HANDLED (SYS_ERRIDR_EL1 ), +HOST_HANDLED (SYS_ERRSELR_EL1 ), +HOST_HANDLED (SYS_ERXFR_EL1 ), +HOST_HANDLED (SYS_ERXCTLR_EL1 ), +HOST_HANDLED (SYS_ERXSTATUS_EL1 ), +HOST_HANDLED (SYS_ERXADDR_EL1 ), +HOST_HANDLED (SYS_ERXMISC0_EL1 ), + HOST_HANDLED(SYS_ERXMISC1_EL1),
This really should be handled as RAZ/WI at EL2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 396
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +3
-0+ +HOST_HANDLED (SYS_TFSR_EL1 ), + HOST_HANDLED(SYS_TFSRE0_EL1),
Same as RCSR/GSR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 398
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_FAR_EL1),
Same as TTBR
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 399
Quoted 1 line
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +1
-0+ HOST_HANDLED(SYS_PAR_EL1),
Does not trap in the absence of FGT (which we don't use yet).
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 404
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_MAIR_EL1 ), + HOST_HANDLED(SYS_AMAIR_EL1),
Same as TTBR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 408
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +4
-0+ +/* Limited Ordering Regions Registers are restricted. */ + + HOST_HANDLED(SYS_VBAR_EL1),
Doesn't trap in the absence of FGT.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 409
Quoted 1 line
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +1
-0+ HOST_HANDLED(SYS_DISR_EL1),
If RAS exists, a DISR_EL1 access is routed to VDISR_EL2. If RAS isn't present, this UNDEFs. In any case, there is no trap.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 411
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ +/* GIC CPU Interface registers are restricted. */
Err... Does this include ICC_SGI*R_EL1/ICC_SRE_EL1? Not going to work if you don't let EL1 dealing with this.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 413
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_CONTEXTIDR_EL1),
Same as TTBR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 414
Quoted 1 line
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +1
-0+ HOST_HANDLED(SYS_TPIDR_EL1),
Doesn't trap in the absence of FGT.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 416
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_SCXTNUM_EL1),
Should UNDEF at EL2 until we actually enable FEAT_CSV2_2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 418
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_CNTKCTL_EL1),
Never traps.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 423
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +HOST_HANDLED (SYS_CCSIDR_EL1 ), +HOST_HANDLED (SYS_CLIDR_EL1 ), +HOST_HANDLED (SYS_CSSELR_EL1 ), + HOST_HANDLED(SYS_CTR_EL0),
Eventually, we should expose a synthetic version of these at EL2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 428
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_TPIDR_EL0 ), + HOST_HANDLED(SYS_TPIDRRO_EL0),
Do not trap in the absence of FGT.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 430
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_SCXTNUM_EL0),
Should UNDEF at EL2 until we actually enable FEAT_CSV2_2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 442
Quoted 12 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +12
-0+ +/* Activity Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_CNTP_TVAL_EL0 ), +HOST_HANDLED (SYS_CNTP_CTL_EL0 ), +HOST_HANDLED (SYS_CNTP_CVAL_EL0 ), + +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_DACR32_EL2 ), +HOST_HANDLED (SYS_IFSR32_EL2 ), + HOST_HANDLED(SYS_FPEXC32_EL2),
I don't understand the presence of these registers here. As the name indicates, they are 32bit only.
We need a complete overhaul of this table. I'm going to go through the rest of the patches, and we can then fix this.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v8 07/11] KVM: arm64: Add handlers for protected VM System Registers
Hi Marc,
Quoted 84 lines · Marc Zyngier
Quoted 10 lines · Fuad Tabba
Add system register handlers for protected VMs. These cover Sys64 registers (including feature id registers), and debug.
No functional change intended as these are not hooked in yet to the guest exit handlers introduced earlier. So when trapping is triggered, the exit handlers let the host handle it, as before.
Reviewed-by Andrew Jones <[email protected]>Signed-off-by Fuad Tabba <[email protected]>[...]
Quoted 52 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +52
-0+/* +* Architected system registers. +* Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 +* +* NOTE: Anything not explicitly listed here is *restricted by default*, i.e., +* it will lead to injecting an exception into the guest. +*/ +static const struct sys_reg_desc pvm_sys_reg_descs[] = { +/* Cache maintenance by set/way operations are restricted. */ + +/* Debug and Trace Registers are restricted. */ + +/* AArch64 mappings of the AArch32 ID registers */ +/* CRm=1 */ +AARCH32 (SYS_ID_PFR0_EL1 ), +AARCH32 (SYS_ID_PFR1_EL1 ), +AARCH32 (SYS_ID_DFR0_EL1 ), +AARCH32 (SYS_ID_AFR0_EL1 ), +AARCH32 (SYS_ID_MMFR0_EL1 ), +AARCH32 (SYS_ID_MMFR1_EL1 ), +AARCH32 (SYS_ID_MMFR2_EL1 ), +AARCH32 (SYS_ID_MMFR3_EL1 ), + +/* CRm=2 */ +AARCH32 (SYS_ID_ISAR0_EL1 ), +AARCH32 (SYS_ID_ISAR1_EL1 ), +AARCH32 (SYS_ID_ISAR2_EL1 ), +AARCH32 (SYS_ID_ISAR3_EL1 ), +AARCH32 (SYS_ID_ISAR4_EL1 ), +AARCH32 (SYS_ID_ISAR5_EL1 ), +AARCH32 (SYS_ID_MMFR4_EL1 ), +AARCH32 (SYS_ID_ISAR6_EL1 ), + +/* CRm=3 */ +AARCH32 (SYS_MVFR0_EL1 ), +AARCH32 (SYS_MVFR1_EL1 ), +AARCH32 (SYS_MVFR2_EL1 ), +AARCH32 (SYS_ID_PFR2_EL1 ), +AARCH32 (SYS_ID_DFR1_EL1 ), +AARCH32 (SYS_ID_MMFR5_EL1 ), + +/* AArch64 ID registers */ +/* CRm=4 */ +AARCH64 (SYS_ID_AA64PFR0_EL1 ), +AARCH64 (SYS_ID_AA64PFR1_EL1 ), +AARCH64 (SYS_ID_AA64ZFR0_EL1 ), +AARCH64 (SYS_ID_AA64DFR0_EL1 ), +AARCH64 (SYS_ID_AA64DFR1_EL1 ), +AARCH64 (SYS_ID_AA64AFR0_EL1 ), +AARCH64 (SYS_ID_AA64AFR1_EL1 ), +AARCH64 (SYS_ID_AA64ISAR0_EL1 ), +AARCH64 (SYS_ID_AA64ISAR1_EL1 ),arch/arm64/kvm/hyp/nvhe/sys_regs.c line 363
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +10
-0+AARCH64 (SYS_ID_AA64MMFR0_EL1 ), +AARCH64 (SYS_ID_AA64MMFR1_EL1 ), +AARCH64 (SYS_ID_AA64MMFR2_EL1 ), + +HOST_HANDLED (SYS_SCTLR_EL1 ), +HOST_HANDLED (SYS_ACTLR_EL1 ), +HOST_HANDLED (SYS_CPACR_EL1 ), + +HOST_HANDLED (SYS_RGSR_EL1 ), + HOST_HANDLED(SYS_GCR_EL1),What is the expected semantics of this handling? These registers are free to use by the guest unless MTE is disabled. Either the guest accesses them directly (no trap), accesses them while MTE is disabled (trap), or access them when MTE doesn't exist.
Quoted 2 lines
The first and last cases are invisible to EL2. For the second case, why should we go back to EL1 rather than injecting an UNDEF directly?
In hindsight, my approach to constructing this table was not the right one. I took the one for EL1, and filtered it based on the trapping bits. So yes, you are right that I need to re-examine this table with that in mind.
Thanks,
/fuad
Quoted 153 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 369
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +6
-0+ +/* Scalable Vector Registers are restricted. */ + +HOST_HANDLED (SYS_TTBR0_EL1 ), +HOST_HANDLED (SYS_TTBR1_EL1 ), + HOST_HANDLED(SYS_TCR_EL1),None of these should normally trap unless we are handling an erratum (such as Cavium 219) or that we have HCR_EL2.TVM set. The former is handled at EL2, and I don't expect any Set/Way emulation to require the latter.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 380
Quoted 11 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +11
-0+ +HOST_HANDLED (SYS_APIAKEYLO_EL1 ), +HOST_HANDLED (SYS_APIAKEYHI_EL1 ), +HOST_HANDLED (SYS_APIBKEYLO_EL1 ), +HOST_HANDLED (SYS_APIBKEYHI_EL1 ), +HOST_HANDLED (SYS_APDAKEYLO_EL1 ), +HOST_HANDLED (SYS_APDAKEYHI_EL1 ), +HOST_HANDLED (SYS_APDBKEYLO_EL1 ), +HOST_HANDLED (SYS_APDBKEYHI_EL1 ), +HOST_HANDLED (SYS_APGAKEYLO_EL1 ), + HOST_HANDLED(SYS_APGAKEYHI_EL1),This is debatable too. If the guest has started using PtrAuth and that we haven't handled things in
fixup_guest_exit(), why returning to the host? This should directly UNDEF.arch/arm64/kvm/hyp/nvhe/sys_regs.c line 384
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +4
-0+ +HOST_HANDLED (SYS_AFSR0_EL1 ), +HOST_HANDLED (SYS_AFSR1_EL1 ), + HOST_HANDLED(SYS_ESR_EL1),Same as TTBR*/TCR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 393
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +9
-0+ +HOST_HANDLED (SYS_ERRIDR_EL1 ), +HOST_HANDLED (SYS_ERRSELR_EL1 ), +HOST_HANDLED (SYS_ERXFR_EL1 ), +HOST_HANDLED (SYS_ERXCTLR_EL1 ), +HOST_HANDLED (SYS_ERXSTATUS_EL1 ), +HOST_HANDLED (SYS_ERXADDR_EL1 ), +HOST_HANDLED (SYS_ERXMISC0_EL1 ), + HOST_HANDLED(SYS_ERXMISC1_EL1),This really should be handled as RAZ/WI at EL2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 396
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +3
-0+ +HOST_HANDLED (SYS_TFSR_EL1 ), + HOST_HANDLED(SYS_TFSRE0_EL1),Same as RCSR/GSR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 398
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_FAR_EL1),Same as TTBR
Quoted 1 line
+
HOST_HANDLED(SYS_PAR_EL1),Does not trap in the absence of FGT (which we don't use yet).
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 404
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_MAIR_EL1 ), + HOST_HANDLED(SYS_AMAIR_EL1),Same as TTBR.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 408
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +4
-0+ +/* Limited Ordering Regions Registers are restricted. */ + + HOST_HANDLED(SYS_VBAR_EL1),Doesn't trap in the absence of FGT.
Quoted 1 line
+
HOST_HANDLED(SYS_DISR_EL1),If RAS exists, a
DISR_EL1access is routed toVDISR_EL2. If RAS isn't present, this UNDEFs. In any case, there is no trap.arch/arm64/kvm/hyp/nvhe/sys_regs.c line 411
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ +/* GIC CPU Interface registers are restricted. */ Err... Does this include ICC_SGI*R_EL1/ICC_SRE_EL1? Not going to work if you don't let EL1 dealing with this.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 413
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_CONTEXTIDR_EL1),Same as TTBR.
Quoted 1 line
+
HOST_HANDLED(SYS_TPIDR_EL1),Doesn't trap in the absence of FGT.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 416
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_SCXTNUM_EL1),Should UNDEF at EL2 until we actually enable
FEAT_CSV2_2.arch/arm64/kvm/hyp/nvhe/sys_regs.c line 418
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_CNTKCTL_EL1),Never traps.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 423
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +HOST_HANDLED (SYS_CCSIDR_EL1 ), +HOST_HANDLED (SYS_CLIDR_EL1 ), +HOST_HANDLED (SYS_CSSELR_EL1 ), + HOST_HANDLED(SYS_CTR_EL0),Eventually, we should expose a synthetic version of these at EL2.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 428
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +5
-0+ +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_TPIDR_EL0 ), + HOST_HANDLED(SYS_TPIDRRO_EL0),Do not trap in the absence of FGT.
arch/arm64/kvm/hyp/nvhe/sys_regs.c line 430
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +2
-0+ + HOST_HANDLED(SYS_SCXTNUM_EL0),Should UNDEF at EL2 until we actually enable
FEAT_CSV2_2.arch/arm64/kvm/hyp/nvhe/sys_regs.c line 442
Quoted 12 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c new file +12
-0+ +/* Activity Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_CNTP_TVAL_EL0 ), +HOST_HANDLED (SYS_CNTP_CTL_EL0 ), +HOST_HANDLED (SYS_CNTP_CVAL_EL0 ), + +/* Performance Monitoring Registers are restricted. */ + +HOST_HANDLED (SYS_DACR32_EL2 ), +HOST_HANDLED (SYS_IFSR32_EL2 ), + HOST_HANDLED(SYS_FPEXC32_EL2),I don't understand the presence of these registers here. As the name indicates, they are 32bit only.
We need a complete overhaul of this table. I'm going to go through the rest of the patches, and we can then fix this.
Thanks,
M.--
Without deviation from the norm, progress is not possible.
PATCH v8 8/11 KVM: arm64: Initialize trap registers for protected VMs
In reply to Fuad TabbaProtected VMs have more restricted features that need to be trapped. Moreover, the host should not be trusted to set the appropriate trapping registers and their values.
Initialize the trapping registers, i.e., hcr_el2, mdcr_el2, and cptr_el2 at EL2 for protected guests, based on the values of the guest's feature id registers.
No functional change intended as trap handlers introduced in the previous patch are still not hooked in to the guest exit handlers.
--- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/kvm/arm.c | 8 + .../arm64/kvm/hyp/include/nvhe/trap_handler.h | 2 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 9 + arch/arm64/kvm/hyp/nvhe/pkvm.c | 186 ++++++++++++++++++ 7 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/pkvm.c
arch/arm64/include/asm/kvm_asm.h +1 -0
@@ -64,6 +64,7 @@#define __KVM_HOST_SMCCC_FUNC___pkvm_cpu_set_vector 18#define __KVM_HOST_SMCCC_FUNC___pkvm_prot_finalize 19#define __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc 20 +#define __KVM_HOST_SMCCC_FUNC___pkvm_vcpu_init_traps 21#ifndef __ASSEMBLY__
arch/arm64/include/asm/kvm_host.h +2 -0
@@ -780,6 +780,8 @@ static inline bool kvm_vm_is_protected(struct kvm *kvm)return false; } +void kvm_init_protected_traps (struct kvm_vcpu *vcpu); +int kvm_arm_vcpu_finalize (struct kvm_vcpu *vcpu,int feature);bool kvm_arm_vcpu_is_finalized (struct kvm_vcpu *vcpu);
arch/arm64/kvm/arm.c +8 -0
@@ -620,6 +620,14 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) ret =kvm_arm_pmu_v3_enable (vcpu); +/* +* Initialize traps for protected VMs. +* NOTE: Move to run in EL2 directly, rather than via a hypercall, once +* the code is in place for first run initialization at EL2. +*/ +if (kvm_vm_is_protected (kvm)) +kvm_call_hyp_nvhe (__pkvm_vcpu_init_traps, vcpu); +return ret; }
arch/arm64/kvm/hyp/include/nvhe/trap_handler.h +2 -0
@@ -15,4 +15,6 @@#define DECLARE_REG (type, name, ctxt, reg) \ type name = (type)cpu_reg(ctxt, (reg)) +void __pkvm_vcpu_init_traps (struct kvm_vcpu *vcpu); +#endif /* __ARM64_KVM_NVHE_TRAP_HANDLER_H__ */
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -14,7 +14,7 @@ lib-objs := $(addprefix ../../../lib/, $(lib-objs)) obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ hyp-main.o hyp-smp.o psci-relay.o early_alloc.o stub.o page_alloc.o \ - cache.o setup.o mm.o mem_protect.o sys_regs.o + cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o obj-y += $(lib-objs)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +9 -0
@@ -160,6 +160,14 @@ static void handle___pkvm_prot_finalize(struct kvm_cpu_context *host_ctxt) {cpu_reg (host_ctxt,1 ) =__pkvm_prot_finalize (); } + +static void handle___pkvm_vcpu_init_traps (struct kvm_cpu_context *host_ctxt) +{ + DECLARE_REG(struct kvm_vcpu *, vcpu, host_ctxt, 1); + +__pkvm_vcpu_init_traps (kern_hyp_va (vcpu)); +} +typedef void (*hcall_t )(struct kvm_cpu_context *);#define HANDLE_FUNC (x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x
@@ -185,6 +193,7 @@ static const hcall_t host_hcall[] = {HANDLE_FUNC (__pkvm_host_share_hyp),HANDLE_FUNC (__pkvm_create_private_mapping),HANDLE_FUNC (__pkvm_prot_finalize), + HANDLE_FUNC(__pkvm_vcpu_init_traps), };static void handle_host_hcall (struct kvm_cpu_context *host_ctxt)
arch/arm64/kvm/hyp/nvhe/pkvm.c new file +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 9/11 KVM: arm64: Move sanitized copies of CPU features
In reply to Fuad TabbaMove the sanitized copies of the CPU feature registers to the recently created sys_regs.c. This consolidates all copies in a more relevant file.
No functional change intended.
--- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 ------ arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-)
arch/arm64/kvm/hyp/nvhe/mem_protect.c +0 -6
@@ -25,12 +25,6 @@ struct host_kvm host_kvm;static struct hyp_pool host_s2_pool; -/* -* Copies of the host's CPU features registers holding sanitized values. -*/ -u64 id_aa64mmfr0_el1_sys_val; -u64 id_aa64mmfr1_el1_sys_val; -const u8 pkvm_hyp_id =1 ;static void *host_s2_zalloc_pages_exact (size_t size)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2 -0
@@ -21,6 +21,8 @@ u64 id_aa64pfr0_el1_sys_val;u64 id_aa64pfr1_el1_sys_val;u64 id_aa64isar0_el1_sys_val;u64 id_aa64isar1_el1_sys_val; +u64 id_aa64mmfr0_el1_sys_val; +u64 id_aa64mmfr1_el1_sys_val;u64 id_aa64mmfr2_el1_sys_val;/*
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v8 10/11 KVM: arm64: Trap access to pVM restricted features
In reply to Fuad TabbaTrap accesses to restricted features for VMs running in protected mode.
Access to feature registers are emulated, and only supported features are exposed to protected VMs.
Accesses to restricted registers as well as restricted instructions are trapped, and an undefined exception is injected into the protected guests, i.e., with EC = 0x0 (unknown reason). This EC is the one used, according to the Arm Architecture Reference Manual, for unallocated or undefined system registers or instructions.
Only affects the functionality of protected VMs. Otherwise, should not affect non-protected VMs when KVM is running in protected mode.
--- arch/arm64/kvm/hyp/nvhe/switch.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
arch/arm64/kvm/hyp/nvhe/switch.c +57 -0
@@ -20,6 +20,7 @@#include <asm/kprobes.h> #include <asm/kvm_asm.h> #include <asm/kvm_emulate.h> +#include <asm/kvm_fixed_config.h> #include <asm/kvm_hyp.h> #include <asm/kvm_mmu.h> #include <asm/fpsimd.h>
@@ -159,6 +160,49 @@ static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)write_sysreg (pmu->events_host, pmcntenset_el0); } +/** +* Handler for protected VM restricted exceptions. +* +* Inject an undefined exception into the guest and return true to indicate that +* the hypervisor has handled the exit, and control should go back to the guest. +*/ +static bool kvm_handle_pvm_restricted (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +inject_undef64 (vcpu); +return true; +} + +/** +* Handler for protected VM MSR, MRS or System instruction execution in AArch64. +* +* Returns true if the hypervisor has handled the exit, and control should go +* back to the guest, or false if it hasn't. +*/ +static bool kvm_handle_pvm_sys64 (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +if (kvm_handle_pvm_sysreg (vcpu, exit_code)) +return true; + +return kvm_hyp_handle_sysreg (vcpu, exit_code); +} + +/** +* Handler for protected floating-point and Advanced SIMD accesses. +* +* Returns true if the hypervisor has handled the exit, and control should go +* back to the guest, or false if it hasn't. +*/ +static bool kvm_handle_pvm_fpsimd (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +/* Linux guests assume support for floating-point and Advanced SIMD. */ +BUILD_BUG_ON (!FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_FP ), +PVM_ID_AA64PFR0_ALLOW )); +BUILD_BUG_ON (!FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_ASIMD ), +PVM_ID_AA64PFR0_ALLOW )); + +return kvm_hyp_handle_fpsimd (vcpu, exit_code); +} +static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] =NULL , [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32,
@@ -170,8 +214,21 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; +static const exit_handler_fn pvm_exit_handlers[] = { + [0 ... ESR_ELx_EC_MAX] =NULL , + [ESR_ELx_EC_SYS64] = kvm_handle_pvm_sys64, + [ESR_ELx_EC_SVE] = kvm_handle_pvm_restricted, + [ESR_ELx_EC_FP_ASIMD] = kvm_handle_pvm_fpsimd, + [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, + [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, +}; +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm) { +if (unlikely (kvm_vm_is_protected (kvm))) +return pvm_exit_handlers; +return hyp_exit_handlers; }
Signature · 1 line
2.33.0.882.g93a45727a2-goog
kernel test robot
build botRe: [PATCH v8 10/11] KVM: arm64: Trap access to pVM restricted features
Thank you for the patch! Perhaps something to improve:
Hi Fuad,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 1da38549dd64c7f5dd22427f12dfa8db3d8a722b]
url: https://github.com/0day-ci/linux/commits/Fuad-Tabba/KVM-arm64-Fixed-features-for-protected-VMs/20211010-225842 base: 1da38549dd64c7f5dd22427f12dfa8db3d8a722b config: arm64-randconfig-r016-20211014 (attached as .config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project acb3b187c4c88650a6a717a1bcb234d27d0d7f54)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/6d9b1ae6b6b20f6f4300e46a17bb9d42eadd3a79
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fuad-Tabba/KVM-arm64-Fixed-features-for-protected-VMs/20211010-225842 git checkout 6d9b1ae6b6b20f6f4300e46a17bb9d42eadd3a79
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
arch/arm64/kvm/hyp/nvhe/switch.c:126: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Disable host events, enable guest events
arch/arm64/kvm/hyp/nvhe/switch.c:146: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Disable guest events, enable host events
arch/arm64/kvm/hyp/nvhe/switch.c:164: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Handler for protected VM restricted exceptions.
arch/arm64/kvm/hyp/nvhe/switch.c:176: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Handler for protected VM MSR, MRS or System instruction execution in AArch64.
arch/arm64/kvm/hyp/nvhe/switch.c:196: warning: Function parameter or member 'vcpu' not described in 'kvm_handle_pvm_fpsimd' arch/arm64/kvm/hyp/nvhe/switch.c:196: warning: Function parameter or member 'exit_code' not described in 'kvm_handle_pvm_fpsimd'
>> arch/arm64/kvm/hyp/nvhe/switch.c:196: warning: expecting prototype for Handler for protected floating(). Prototype was for kvm_handle_pvm_fpsimd() instead
vim +196 arch/arm64/kvm/hyp/nvhe/switch.c
188
189 /**
190 * Handler for protected floating-point and Advanced SIMD accesses.
191 *
192 * Returns true if the hypervisor has handled the exit, and control should go
193 * back to the guest, or false if it hasn't.
194 */
195 static bool kvm_handle_pvm_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
> 196 { 197 /* Linux guests assume support for floating-point and Advanced SIMD. */
198 BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_FP),
199 PVM_ID_AA64PFR0_ALLOW));
200 BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_ASIMD),
201 PVM_ID_AA64PFR0_ALLOW));
202
203 return kvm_hyp_handle_fpsimd(vcpu, exit_code);
204 }
205
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v8 11/11 KVM: arm64: Handle protected guests at 32 bits
In reply to Fuad TabbaProtected KVM does not support protected AArch32 guests. However, it is possible for the guest to force run AArch32, potentially causing problems. Add an extra check so that if the hypervisor catches the guest doing that, it can prevent the guest from running again by resetting vcpu->arch.target and returning ARM_EXCEPTION_IL.
If this were to happen, The VMM can try and fix it by re- initializing the vcpu with KVM_ARM_VCPU_INIT, however, this is likely not possible for protected VMs.
Adapted from commit 22f553842b14 ("KVM: arm64: Handle Asymmetric AArch32 systems")
--- arch/arm64/kvm/hyp/nvhe/switch.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
arch/arm64/kvm/hyp/nvhe/switch.c +34 -0
@@ -232,6 +232,37 @@ static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm)return hyp_exit_handlers; } +/* +* Some guests (e.g., protected VMs) are not be allowed to run in AArch32. +* The ARMv8 architecture does not give the hypervisor a mechanism to prevent a +* guest from dropping to AArch32 EL0 if implemented by the CPU. If the +* hypervisor spots a guest in such a state ensure it is handled, and don't +* trust the host to spot or fix it. The check below is based on the one in +* kvm_arch_vcpu_ioctl_run(). +* +* Returns false if the guest ran in AArch32 when it shouldn't have, and +* thus should exit to the host, or true if a the guest run loop can continue. +*/ +static bool handle_aarch32_guest (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +struct kvm *kvm =kern_hyp_va (vcpu->kvm); + +if (kvm_vm_is_protected (kvm) &&vcpu_mode_is_32bit (vcpu)) { +/* +* As we have caught the guest red-handed, decide that it isn't +* fit for purpose anymore by making the vcpu invalid. The VMM +* can try and fix it by re-initializing the vcpu with +* KVM_ARM_VCPU_INIT, however, this is likely not possible for +* protected VMs. +*/ + vcpu->arch.target =-1 ; + *exit_code =ARM_EXCEPTION_IL ; +return false; + } + +return true; +} +/* Switch to the guest for legacy non-VHE systems */ int __kvm_vcpu_run (struct kvm_vcpu *vcpu) {
@@ -294,6 +325,9 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)/* Jump in the fire! */ exit_code =__guest_enter (vcpu); +if (unlikely (!handle_aarch32_guest (vcpu, &exit_code))) +break ; +/* And we're baaack! */ }while (fixup_guest_exit (vcpu, &exit_code));
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Marc Zyngier
maintainerRe: [PATCH v8 11/11] KVM: arm64: Handle protected guests at 32 bits
Quoted 43 lines · Fuad Tabba
Protected KVM does not support protected AArch32 guests. However, it is possible for the guest to force run AArch32, potentially causing problems. Add an extra check so that if the hypervisor catches the guest doing that, it can prevent the guest from running again by resetting
vcpu->arch.targetand returningARM_EXCEPTION_IL.If this were to happen, The VMM can try and fix it by re- initializing the vcpu with
KVM_ARM_VCPU_INIT, however, this is likely not possible for protected VMs.Adapted from commit
22f553842b14("KVM: arm64: Handle Asymmetric AArch32 systems")Signed-off-by Fuad Tabba <[email protected]>--- arch/arm64/kvm/hyp/nvhe/switch.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)arch/arm64/kvm/hyp/nvhe/switch.c +15
-0@@ -232,6 +232,37 @@ static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm)return hyp_exit_handlers; } +/* +* Some guests (e.g., protected VMs) are not be allowed to run in AArch32. +* The ARMv8 architecture does not give the hypervisor a mechanism to prevent a +* guest from dropping to AArch32 EL0 if implemented by the CPU. If the +* hypervisor spots a guest in such a state ensure it is handled, and don't +* trust the host to spot or fix it. The check below is based on the one in +* kvm_arch_vcpu_ioctl_run(). +* +* Returns false if the guest ran in AArch32 when it shouldn't have, and +* thus should exit to the host, or true if a the guest run loop can continue. +*/ +static bool handle_aarch32_guest (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +struct kvm *kvm =kern_hyp_va (vcpu->kvm); +
arch/arm64/kvm/hyp/nvhe/switch.c static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm) · line 259
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/switch.c +10
-0+if (kvm_vm_is_protected (kvm) &&vcpu_mode_is_32bit (vcpu)) { +/* +* As we have caught the guest red-handed, decide that it isn't +* fit for purpose anymore by making the vcpu invalid. The VMM +* can try and fix it by re-initializing the vcpu with +* KVM_ARM_VCPU_INIT, however, this is likely not possible for +* protected VMs. +*/ + vcpu->arch.target =-1 ; + *exit_code =ARM_EXCEPTION_IL ;
Aren't we losing a potential SError here, which the original commit doesn't need to handle? I'd expect something like:
*exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT); *exit_code |= ARM_EXCEPTION_IL;
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/switch.c +6
-0+return false; + } + +return true; +} +/* Switch to the guest for legacy non-VHE systems */ int __kvm_vcpu_run (struct kvm_vcpu *vcpu) {
arch/arm64/kvm/hyp/nvhe/switch.c int __kvm_vcpu_run(struct kvm_vcpu *vcpu) · line 333
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/switch.c +3
-0@@ -294,6 +325,9 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)/* Jump in the fire! */ exit_code =__guest_enter (vcpu); +if (unlikely (!handle_aarch32_guest (vcpu, &exit_code))) +break ; +/* And we're baaack! */ }while (fixup_guest_exit (vcpu, &exit_code));
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v8 11/11] KVM: arm64: Handle protected guests at 32 bits
Hi Marc,
Quoted 60 lines · Marc Zyngier
Quoted 43 lines · Fuad Tabba
Protected KVM does not support protected AArch32 guests. However, it is possible for the guest to force run AArch32, potentially causing problems. Add an extra check so that if the hypervisor catches the guest doing that, it can prevent the guest from running again by resetting
vcpu->arch.targetand returningARM_EXCEPTION_IL.If this were to happen, The VMM can try and fix it by re- initializing the vcpu with
KVM_ARM_VCPU_INIT, however, this is likely not possible for protected VMs.Adapted from commit
22f553842b14("KVM: arm64: Handle Asymmetric AArch32 systems")Signed-off-by Fuad Tabba <[email protected]>--- arch/arm64/kvm/hyp/nvhe/switch.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)arch/arm64/kvm/hyp/nvhe/switch.c +15
-0@@ -232,6 +232,37 @@ static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm)return hyp_exit_handlers; } +/* +* Some guests (e.g., protected VMs) are not be allowed to run in AArch32. +* The ARMv8 architecture does not give the hypervisor a mechanism to prevent a +* guest from dropping to AArch32 EL0 if implemented by the CPU. If the +* hypervisor spots a guest in such a state ensure it is handled, and don't +* trust the host to spot or fix it. The check below is based on the one in +* kvm_arch_vcpu_ioctl_run(). +* +* Returns false if the guest ran in AArch32 when it shouldn't have, and +* thus should exit to the host, or true if a the guest run loop can continue. +*/ +static bool handle_aarch32_guest (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +struct kvm *kvm =kern_hyp_va (vcpu->kvm); +arch/arm64/kvm/hyp/nvhe/switch.c static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm) · line 259
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/switch.c +10
-0+if (kvm_vm_is_protected (kvm) &&vcpu_mode_is_32bit (vcpu)) { +/* +* As we have caught the guest red-handed, decide that it isn't +* fit for purpose anymore by making the vcpu invalid. The VMM +* can try and fix it by re-initializing the vcpu with +* KVM_ARM_VCPU_INIT, however, this is likely not possible for +* protected VMs. +*/ + vcpu->arch.target =-1 ; + *exit_code =ARM_EXCEPTION_IL ;Aren't we losing a potential SError here, which the original commit doesn't need to handle? I'd expect something like:
Quoted 2 lines
*exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT);
*exit_code |= ARM_EXCEPTION_IL;Yes, you're right. That would ensure the SError is preserved.
Thanks,
/fuad
Quoted 26 lines
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/switch.c +6
-0+return false; + } + +return true; +} +/* Switch to the guest for legacy non-VHE systems */ int __kvm_vcpu_run (struct kvm_vcpu *vcpu) {arch/arm64/kvm/hyp/nvhe/switch.c int __kvm_vcpu_run(struct kvm_vcpu *vcpu) · line 333
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/switch.c +3
-0@@ -294,6 +325,9 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)/* Jump in the fire! */ exit_code =__guest_enter (vcpu); +if (unlikely (!handle_aarch32_guest (vcpu, &exit_code))) +break ; +/* And we're baaack! */ }while (fixup_guest_exit (vcpu, &exit_code));Thanks,
M.--
Without deviation from the norm, progress is not possible.
Marc Zyngier
maintainerv9 cover KVM: arm64: Fixed features for protected VMs
In reply to Fuad TabbaThis is an update on Fuad's series[1].
Instead of going going back and forth over a series that has seen a fair few versions, I've opted for simply writing a set of fixes on top, hopefully greatly simplifying the handling of most registers, and moving things around to suit my own taste (just because I can).
I won't be reposting the initial 11 patches, which is why this series in is reply to patch 11.
Thanks,
M.
[1] https://lore.kernel.org/r/[email protected]
Fuad Tabba (8):
KVM: arm64: Pass struct kvm to per-EC handlers
KVM: arm64: Add missing field descriptor for MDCR_EL2
KVM: arm64: Simplify masking out MTE in feature id reg
KVM: arm64: Add handlers for protected VM System Registers
KVM: arm64: Initialize trap registers for protected VMs
KVM: arm64: Move sanitized copies of CPU features
KVM: arm64: Trap access to pVM restricted features
KVM: arm64: Handle protected guests at 32 bits
Marc Zyngier (14):
KVM: arm64: Move __get_fault_info() and co into their own include file
KVM: arm64: Don't include switch.h into nvhe/kvm-main.c
KVM: arm64: Move early handlers to per-EC handlers
KVM: arm64: Fix early exit ptrauth handling
KVM: arm64: pkvm: Use a single function to expose all id-regs
KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
KVM: arm64: pkvm: Drop AArch32-specific registers
KVM: arm64: pkvm: Drop sysregs that should never be routed to the host
KVM: arm64: pkvm: Handle GICv3 traps as required
KVM: arm64: pkvm: Preserve pending SError on exit from AArch32
KVM: arm64: pkvm: Consolidate include files
KVM: arm64: pkvm: Move kvm_handle_pvm_restricted around
KVM: arm64: pkvm: Pass vpcu instead of kvm to
kvm_get_exit_handler_array()
KVM: arm64: pkvm: Give priority to standard traps over pvm handling
arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kvm/arm.c | 13 + arch/arm64/kvm/hyp/include/hyp/fault.h | 75 +++ arch/arm64/kvm/hyp/include/hyp/switch.h | 235 ++++----- .../arm64/kvm/hyp/include/nvhe/fixed_config.h | 200 +++++++ .../arm64/kvm/hyp/include/nvhe/trap_handler.h | 2 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 8 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 185 +++++++ arch/arm64/kvm/hyp/nvhe/setup.c | 3 + arch/arm64/kvm/hyp/nvhe/switch.c | 99 ++++ arch/arm64/kvm/hyp/nvhe/sys_regs.c | 487 ++++++++++++++++++ arch/arm64/kvm/hyp/vhe/switch.c | 16 + arch/arm64/kvm/sys_regs.c | 10 +- 18 files changed, 1200 insertions(+), 155 deletions(-) create mode 100644 arch/arm64/kvm/hyp/include/hyp/fault.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/fixed_config.h create mode 100644 arch/arm64/kvm/hyp/nvhe/pkvm.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sys_regs.c
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 12/22 KVM: arm64: Fix early exit ptrauth handling
The previous rework of the early exit code to provide an EC-based decoding tree missed the fact that we have two trap paths for
ptrauth: the instructions (EC_PAC) and the sysregs (EC_SYS64).
Rework the handlers to call the ptrauth handling code on both paths.
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +4 -10
@@ -282,14 +282,6 @@ static inline bool handle_tx2_tvm(struct kvm_vcpu *vcpu)static inline bool esr_is_ptrauth_trap (u32 esr) { -u32 ec =ESR_ELx_EC (esr); - -if (ec == ESR_ELx_EC_PAC) -return true; - -if (ec != ESR_ELx_EC_SYS64) -return false; -switch (esr_sys64_to_sysreg (esr)) {case SYS_APIAKEYLO_EL1 :case SYS_APIAKEYHI_EL1 :
@@ -323,8 +315,7 @@ static bool kvm_hyp_handle_ptrauth(struct kvm_vcpu *vcpu, u64 *exit_code)struct kvm_cpu_context *ctxt;u64 val; -if (!vcpu_has_ptrauth (vcpu) || - !esr_is_ptrauth_trap (kvm_vcpu_get_esr (vcpu))) +if (!vcpu_has_ptrauth (vcpu))return false; ctxt =this_cpu_ptr (&kvm_hyp_ctxt);
@@ -353,6 +344,9 @@ static bool kvm_hyp_handle_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code) __vgic_v3_perform_cpuif_access(vcpu) == 1)return true; +if (esr_is_ptrauth_trap (kvm_vcpu_get_esr (vcpu))) +return kvm_hyp_handle_ptrauth (vcpu, exit_code); +return false; }
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 13/22 KVM: arm64: pkvm: Use a single function to expose all id-regs
In reply to Marc ZyngierRather than exposing a whole set of helper functions to retrieve individual ID registers, use the existing decoding tree and expose a single helper instead.
This allow a number of functions to be made static, and we now have a single entry point to maintain.
--- arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 14 +------- arch/arm64/kvm/hyp/nvhe/pkvm.c | 10 +++--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 37 ++++++++++++---------- 3 files changed, 26 insertions(+), 35 deletions(-)
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h +1 -13
@@ -9,19 +9,7 @@#include <asm/kvm_host.h> -u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu); - +u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id);bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code);int kvm_check_pvm_sysreg_table (void );void inject_undef64 (struct kvm_vcpu *vcpu);
arch/arm64/kvm/hyp/nvhe/pkvm.c +5 -5
@@ -15,7 +15,7 @@*/ static void pvm_init_traps_aa64pfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64pfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64PFR0_EL1 );u64 hcr_set =HCR_RW ;u64 hcr_clear =0 ;u64 cptr_set =0 ;
@@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64pfr1 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64pfr1 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64PFR1_EL1 );u64 hcr_set =0 ;u64 hcr_clear =0 ;
@@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64dfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64dfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64DFR0_EL1 );u64 mdcr_set =0 ;u64 mdcr_clear =0 ;u64 cptr_set =0 ;
@@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64mmfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64mmfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64MMFR0_EL1 );u64 mdcr_set =0 ;/* Trap Debug Communications Channel registers */
@@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64mmfr1 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64mmfr1 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64MMFR1_EL1 );u64 hcr_set =0 ;/* Trap LOR */
arch/arm64/kvm/hyp/nvhe/sys_regs.c +20 -17
@@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val,* based on allowed features, system features, and KVM support. */ -u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu) {const struct kvm *kvm = (const struct kvm *)kern_hyp_va (vcpu->kvm);u64 set_mask =0 ;
@@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)return (id_aa64pfr0_el1_sys_val & allow_mask) | set_mask; } -u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu) {const struct kvm *kvm = (const struct kvm *)kern_hyp_va (vcpu->kvm);u64 allow_mask =PVM_ID_AA64PFR1_ALLOW ;
@@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)return id_aa64pfr1_el1_sys_val & allow_mask; } -u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu) {/* * No support for Scalable Vectors, therefore, hyp has no sanitized
@@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu) {/* * No support for debug, including breakpoints, and watchpoints,
@@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu) {/* * No support for debug, therefore, hyp has no sanitized copy of the
@@ -144,7 +144,7 @@ u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu) {/* * No support for implementation defined features, therefore, hyp has no
@@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu) {/* * No support for implementation defined features, therefore, hyp has no
@@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu) {return id_aa64isar0_el1_sys_val &PVM_ID_AA64ISAR0_ALLOW ; } -u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu) {u64 allow_mask =PVM_ID_AA64ISAR1_ALLOW ;
@@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)return id_aa64isar1_el1_sys_val & allow_mask; } -u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu) {u64 set_mask;
@@ -192,22 +192,19 @@ u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)return (id_aa64mmfr0_el1_sys_val &PVM_ID_AA64MMFR0_ALLOW ) | set_mask; } -u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu) {return id_aa64mmfr1_el1_sys_val &PVM_ID_AA64MMFR1_ALLOW ; } -u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu) {return id_aa64mmfr2_el1_sys_val &PVM_ID_AA64MMFR2_ALLOW ; } -/* Read a sanitized cpufeature ID register by its sys_reg_desc. */ -static u64 read_id_reg (const struct kvm_vcpu *vcpu, -struct sys_reg_desc const *r) +/* Read a sanitized cpufeature ID register by its encoding */ +u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id) { -u32 id =reg_to_encoding (r); -switch (id) {case SYS_ID_AA64PFR0_EL1 :return get_pvm_id_aa64pfr0 (vcpu);
@@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return 0 ; } +static u64 read_id_reg (const struct kvm_vcpu *vcpu, +struct sys_reg_desc const *r) +{ +return pvm_read_id_reg (vcpu,reg_to_encoding (r)); +} +/* * Accessor for AArch32 feature id registers. *
Signature · 1 line
2.30.2
Re: [PATCH v9 13/22] KVM: arm64: pkvm: Use a single function to expose all id-regs
Quoted 24 lines · Marc Zyngier
Rather than exposing a whole set of helper functions to retrieve individual ID registers, use the existing decoding tree and expose a single helper instead.
This allow a number of functions to be made static, and we now have a single entry point to maintain.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 14 +------- arch/arm64/kvm/hyp/nvhe/pkvm.c | 10 +++--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 37 ++++++++++++---------- 3 files changed, 26 insertions(+), 35 deletions(-)arch/arm64/kvm/hyp/include/nvhe/sys_regs.h +0
-2@@ -9,19 +9,7 @@#include <asm/kvm_host.h> -u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu);
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h line 23
Quoted 10 lines
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h +0
-10-u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu); -u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu);
This is nice.
Quoted 188 lines
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h +1
-1- +u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id);bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code);int kvm_check_pvm_sysreg_table (void );void inject_undef64 (struct kvm_vcpu *vcpu);arch/arm64/kvm/hyp/nvhe/pkvm.c +5
-5@@ -15,7 +15,7 @@*/ static void pvm_init_traps_aa64pfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64pfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64PFR0_EL1 );u64 hcr_set =HCR_RW ;u64 hcr_clear =0 ;u64 cptr_set =0 ;@@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64pfr1 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64pfr1 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64PFR1_EL1 );u64 hcr_set =0 ;u64 hcr_clear =0 ;@@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64dfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64dfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64DFR0_EL1 );u64 mdcr_set =0 ;u64 mdcr_clear =0 ;u64 cptr_set =0 ;@@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64mmfr0 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64mmfr0 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64MMFR0_EL1 );u64 mdcr_set =0 ;/* Trap Debug Communications Channel registers */ @@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)*/ static void pvm_init_traps_aa64mmfr1 (struct kvm_vcpu *vcpu) { -const u64 feature_ids =get_pvm_id_aa64mmfr1 (vcpu); +const u64 feature_ids =pvm_read_id_reg (vcpu,SYS_ID_AA64MMFR1_EL1 );u64 hcr_set =0 ;/* Trap LOR */ arch/arm64/kvm/hyp/nvhe/sys_regs.c +20
-17@@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val,* based on allowed features, system features, and KVM support. */ -u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64pfr0 (const struct kvm_vcpu *vcpu) {const struct kvm *kvm = (const struct kvm *)kern_hyp_va (vcpu->kvm);u64 set_mask =0 ;@@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)return (id_aa64pfr0_el1_sys_val & allow_mask) | set_mask; } -u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64pfr1 (const struct kvm_vcpu *vcpu) {const struct kvm *kvm = (const struct kvm *)kern_hyp_va (vcpu->kvm);u64 allow_mask =PVM_ID_AA64PFR1_ALLOW ;@@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)return id_aa64pfr1_el1_sys_val & allow_mask; } -u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64zfr0 (const struct kvm_vcpu *vcpu) {/* * No support for Scalable Vectors, therefore, hyp has no sanitized @@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64dfr0 (const struct kvm_vcpu *vcpu) {/* * No support for debug, including breakpoints, and watchpoints, @@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64dfr1 (const struct kvm_vcpu *vcpu) {/* * No support for debug, therefore, hyp has no sanitized copy of the @@ -144,7 +144,7 @@ u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64afr0 (const struct kvm_vcpu *vcpu) {/* * No support for implementation defined features, therefore, hyp has no @@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64afr1 (const struct kvm_vcpu *vcpu) {/* * No support for implementation defined features, therefore, hyp has no @@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)return 0 ; } -u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64isar0 (const struct kvm_vcpu *vcpu) {return id_aa64isar0_el1_sys_val &PVM_ID_AA64ISAR0_ALLOW ; } -u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64isar1 (const struct kvm_vcpu *vcpu) {u64 allow_mask =PVM_ID_AA64ISAR1_ALLOW ;@@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)return id_aa64isar1_el1_sys_val & allow_mask; } -u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr0 (const struct kvm_vcpu *vcpu) {u64 set_mask;@@ -192,22 +192,19 @@ u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)return (id_aa64mmfr0_el1_sys_val &PVM_ID_AA64MMFR0_ALLOW ) | set_mask; } -u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr1 (const struct kvm_vcpu *vcpu) {return id_aa64mmfr1_el1_sys_val &PVM_ID_AA64MMFR1_ALLOW ; } -u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu) +static u64 get_pvm_id_aa64mmfr2 (const struct kvm_vcpu *vcpu) {return id_aa64mmfr2_el1_sys_val &PVM_ID_AA64MMFR2_ALLOW ; } -/* Read a sanitized cpufeature ID register by its sys_reg_desc. */ -static u64 read_id_reg (const struct kvm_vcpu *vcpu, -struct sys_reg_desc const *r) +/* Read a sanitized cpufeature ID register by its encoding */ +u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id) { -u32 id =reg_to_encoding (r); -switch (id) {case SYS_ID_AA64PFR0_EL1 :return get_pvm_id_aa64pfr0 (vcpu);@@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return 0 ; } +static u64 read_id_reg (const struct kvm_vcpu *vcpu, +struct sys_reg_desc const *r) +{ +return pvm_read_id_reg (vcpu,reg_to_encoding (r)); +} +/* * Accessor for AArch32 feature id registers. * Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 14/22 KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
In reply to Marc ZyngierThe ERR*/ERX* registers should be handled as RAZ/WI, and there should be no need to involve EL1 for that.
Add a helper that handles such registers, and repaint the sysreg table to declare these registers as RAZ/WI.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +22 -11
@@ -248,6 +248,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return pvm_read_id_reg (vcpu,reg_to_encoding (r)); } +/* Handler to RAZ/WI sysregs */ +static bool pvm_access_raz_wi (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +if (!p->is_write) + p->regval =0 ; + +return true; +} +/* * Accessor for AArch32 feature id registers. *
@@ -270,9 +280,7 @@ static bool pvm_access_id_aarch32(struct kvm_vcpu *vcpu,BUILD_BUG_ON (FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_EL1 ),PVM_ID_AA64PFR0_RESTRICT_UNSIGNED ) > ID_AA64PFR0_ELx_64BIT_ONLY); -/* Use 0 for architecturally "unknown" values. */ - p->regval =0 ; -return true; +return pvm_access_raz_wi (vcpu, p, r); }/*
@@ -301,6 +309,9 @@ static bool pvm_access_id_aarch64(struct kvm_vcpu *vcpu,/* Mark the specified system register as an AArch64 feature id register. */ #define AARCH64 (REG ) { SYS_DESC(REG), .access = pvm_access_id_aarch64 } +/* Mark the specified system register as Read-As-Zero/Write-Ignored */ +#define RAZ_WI (REG ) { SYS_DESC(REG), .access = pvm_access_raz_wi } +/* Mark the specified system register as not being handled in hyp. */ #define HOST_HANDLED (REG ) { SYS_DESC(REG), .access = NULL }
@@ -388,14 +399,14 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {HOST_HANDLED (SYS_AFSR1_EL1 ),HOST_HANDLED (SYS_ESR_EL1 ), -HOST_HANDLED (SYS_ERRIDR_EL1 ), -HOST_HANDLED (SYS_ERRSELR_EL1 ), -HOST_HANDLED (SYS_ERXFR_EL1 ), -HOST_HANDLED (SYS_ERXCTLR_EL1 ), -HOST_HANDLED (SYS_ERXSTATUS_EL1 ), -HOST_HANDLED (SYS_ERXADDR_EL1 ), -HOST_HANDLED (SYS_ERXMISC0_EL1 ), -HOST_HANDLED (SYS_ERXMISC1_EL1 ), +RAZ_WI (SYS_ERRIDR_EL1 ), +RAZ_WI (SYS_ERRSELR_EL1 ), +RAZ_WI (SYS_ERXFR_EL1 ), +RAZ_WI (SYS_ERXCTLR_EL1 ), +RAZ_WI (SYS_ERXSTATUS_EL1 ), +RAZ_WI (SYS_ERXADDR_EL1 ), +RAZ_WI (SYS_ERXMISC0_EL1 ), +RAZ_WI (SYS_ERXMISC1_EL1 ),HOST_HANDLED (SYS_TFSR_EL1 ), HOST_HANDLED(SYS_TFSRE0_EL1),
Signature · 1 line
2.30.2
Re: [PATCH v9 14/22] KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
Quoted 56 lines · Marc Zyngier
The ERR*/ERX* registers should be handled as RAZ/WI, and there should be no need to involve EL1 for that.
Add a helper that handles such registers, and repaint the sysreg table to declare these registers as RAZ/WI.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-)arch/arm64/kvm/hyp/nvhe/sys_regs.c +14
-3@@ -248,6 +248,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return pvm_read_id_reg (vcpu,reg_to_encoding (r)); } +/* Handler to RAZ/WI sysregs */ +static bool pvm_access_raz_wi (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +if (!p->is_write) + p->regval =0 ; + +return true; +} +/* * Accessor for AArch32 feature id registers. * @@ -270,9 +280,7 @@ static bool pvm_access_id_aarch32(struct kvm_vcpu *vcpu,BUILD_BUG_ON (FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_EL1 ),PVM_ID_AA64PFR0_RESTRICT_UNSIGNED ) > ID_AA64PFR0_ELx_64BIT_ONLY); -/* Use 0 for architecturally "unknown" values. */ - p->regval =0 ; -return true; +return pvm_access_raz_wi (vcpu, p, r); }/* @@ -301,6 +309,9 @@ static bool pvm_access_id_aarch64(struct kvm_vcpu *vcpu,/* Mark the specified system register as an AArch64 feature id register. */ #define AARCH64 (REG ) { SYS_DESC(REG), .access = pvm_access_id_aarch64 } +/* Mark the specified system register as Read-As-Zero/Write-Ignored */ +#define RAZ_WI (REG ) { SYS_DESC(REG), .access = pvm_access_raz_wi } +/* Mark the specified system register as not being handled in hyp. */ #define HOST_HANDLED (REG ) { SYS_DESC(REG), .access = NULL }@@ -388,14 +399,14 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {HOST_HANDLED (SYS_AFSR1_EL1 ), HOST_HANDLED(SYS_ESR_EL1),
arch/arm64/kvm/hyp/nvhe/sys_regs.c static const struct sys_reg_desc pvm_sys_reg_descs[] = { · line 402
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c +1
-8-HOST_HANDLED (SYS_ERRIDR_EL1 ), -HOST_HANDLED (SYS_ERRSELR_EL1 ), -HOST_HANDLED (SYS_ERXFR_EL1 ), -HOST_HANDLED (SYS_ERXCTLR_EL1 ), -HOST_HANDLED (SYS_ERXSTATUS_EL1 ), -HOST_HANDLED (SYS_ERXADDR_EL1 ), -HOST_HANDLED (SYS_ERXMISC0_EL1 ), - HOST_HANDLED(SYS_ERXMISC1_EL1), + RAZ_WI(SYS_ERRIDR_EL1),
This is a read-only register. Is write-ignore correct? I'd expect we to inject an exception.
arch/arm64/kvm/hyp/nvhe/sys_regs.c static const struct sys_reg_desc pvm_sys_reg_descs[] = { · line 404
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2
-0+RAZ_WI (SYS_ERRSELR_EL1 ), + RAZ_WI(SYS_ERXFR_EL1),
Another read-only reg.
Quoted 11 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c +5
-0+RAZ_WI (SYS_ERXCTLR_EL1 ), +RAZ_WI (SYS_ERXSTATUS_EL1 ), +RAZ_WI (SYS_ERXADDR_EL1 ), +RAZ_WI (SYS_ERXMISC0_EL1 ), +RAZ_WI (SYS_ERXMISC1_EL1 ),HOST_HANDLED (SYS_TFSR_EL1 ), HOST_HANDLED(SYS_TFSRE0_EL1),Signature · 1 line
2.30.2
Thanks,
drew
Marc Zyngier
maintainerRe: [PATCH v9 14/22] KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
Quoted 59 lines · Andrew Jones
Quoted 57 lines · Marc Zyngier
The ERR*/ERX* registers should be handled as RAZ/WI, and there should be no need to involve EL1 for that.
Add a helper that handles such registers, and repaint the sysreg table to declare these registers as RAZ/WI.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-)arch/arm64/kvm/hyp/nvhe/sys_regs.c +14
-3@@ -248,6 +248,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return pvm_read_id_reg (vcpu,reg_to_encoding (r)); } +/* Handler to RAZ/WI sysregs */ +static bool pvm_access_raz_wi (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +if (!p->is_write) + p->regval =0 ; + +return true; +} +/* * Accessor for AArch32 feature id registers. * @@ -270,9 +280,7 @@ static bool pvm_access_id_aarch32(struct kvm_vcpu *vcpu,BUILD_BUG_ON (FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_EL1 ),PVM_ID_AA64PFR0_RESTRICT_UNSIGNED ) > ID_AA64PFR0_ELx_64BIT_ONLY); -/* Use 0 for architecturally "unknown" values. */ - p->regval =0 ; -return true; +return pvm_access_raz_wi (vcpu, p, r); }/* @@ -301,6 +309,9 @@ static bool pvm_access_id_aarch64(struct kvm_vcpu *vcpu,/* Mark the specified system register as an AArch64 feature id register. */ #define AARCH64 (REG ) { SYS_DESC(REG), .access = pvm_access_id_aarch64 } +/* Mark the specified system register as Read-As-Zero/Write-Ignored */ +#define RAZ_WI (REG ) { SYS_DESC(REG), .access = pvm_access_raz_wi } +/* Mark the specified system register as not being handled in hyp. */ #define HOST_HANDLED (REG ) { SYS_DESC(REG), .access = NULL }@@ -388,14 +399,14 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {HOST_HANDLED (SYS_AFSR1_EL1 ), HOST_HANDLED(SYS_ESR_EL1),
Quoted 12 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c static const struct sys_reg_desc pvm_sys_reg_descs[] = { · line 402
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c +1
-8-HOST_HANDLED (SYS_ERRIDR_EL1 ), -HOST_HANDLED (SYS_ERRSELR_EL1 ), -HOST_HANDLED (SYS_ERXFR_EL1 ), -HOST_HANDLED (SYS_ERXCTLR_EL1 ), -HOST_HANDLED (SYS_ERXSTATUS_EL1 ), -HOST_HANDLED (SYS_ERXADDR_EL1 ), -HOST_HANDLED (SYS_ERXMISC0_EL1 ), - HOST_HANDLED(SYS_ERXMISC1_EL1), + RAZ_WI(SYS_ERRIDR_EL1),This is a read-only register. Is write-ignore correct? I'd expect we to inject an exception.
The HW will do it for us, as the MSR instruction doesn't exist for this register.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v9 14/22] KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
In reply to Marc ZyngierQuoted 79 lines · Marc Zyngier
The ERR*/ERX* registers should be handled as RAZ/WI, and there should be no need to involve EL1 for that.
Add a helper that handles such registers, and repaint the sysreg table to declare these registers as RAZ/WI.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-)arch/arm64/kvm/hyp/nvhe/sys_regs.c +22
-11@@ -248,6 +248,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return pvm_read_id_reg (vcpu,reg_to_encoding (r)); } +/* Handler to RAZ/WI sysregs */ +static bool pvm_access_raz_wi (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +if (!p->is_write) + p->regval =0 ; + +return true; +} +/* * Accessor for AArch32 feature id registers. * @@ -270,9 +280,7 @@ static bool pvm_access_id_aarch32(struct kvm_vcpu *vcpu,BUILD_BUG_ON (FIELD_GET (ARM64_FEATURE_MASK (ID_AA64PFR0_EL1 ),PVM_ID_AA64PFR0_RESTRICT_UNSIGNED ) > ID_AA64PFR0_ELx_64BIT_ONLY); -/* Use 0 for architecturally "unknown" values. */ - p->regval =0 ; -return true; +return pvm_access_raz_wi (vcpu, p, r); }/* @@ -301,6 +309,9 @@ static bool pvm_access_id_aarch64(struct kvm_vcpu *vcpu,/* Mark the specified system register as an AArch64 feature id register. */ #define AARCH64 (REG ) { SYS_DESC(REG), .access = pvm_access_id_aarch64 } +/* Mark the specified system register as Read-As-Zero/Write-Ignored */ +#define RAZ_WI (REG ) { SYS_DESC(REG), .access = pvm_access_raz_wi } +/* Mark the specified system register as not being handled in hyp. */ #define HOST_HANDLED (REG ) { SYS_DESC(REG), .access = NULL }@@ -388,14 +399,14 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {HOST_HANDLED (SYS_AFSR1_EL1 ),HOST_HANDLED (SYS_ESR_EL1 ), -HOST_HANDLED (SYS_ERRIDR_EL1 ), -HOST_HANDLED (SYS_ERRSELR_EL1 ), -HOST_HANDLED (SYS_ERXFR_EL1 ), -HOST_HANDLED (SYS_ERXCTLR_EL1 ), -HOST_HANDLED (SYS_ERXSTATUS_EL1 ), -HOST_HANDLED (SYS_ERXADDR_EL1 ), -HOST_HANDLED (SYS_ERXMISC0_EL1 ), -HOST_HANDLED (SYS_ERXMISC1_EL1 ), +RAZ_WI (SYS_ERRIDR_EL1 ), +RAZ_WI (SYS_ERRSELR_EL1 ), +RAZ_WI (SYS_ERXFR_EL1 ), +RAZ_WI (SYS_ERXCTLR_EL1 ), +RAZ_WI (SYS_ERXSTATUS_EL1 ), +RAZ_WI (SYS_ERXADDR_EL1 ), +RAZ_WI (SYS_ERXMISC0_EL1 ), +RAZ_WI (SYS_ERXMISC1_EL1 ),HOST_HANDLED (SYS_TFSR_EL1 ), HOST_HANDLED(SYS_TFSRE0_EL1),Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 15/22 KVM: arm64: pkvm: Drop AArch32-specific registers
In reply to Marc ZyngierAll the SYS_*32_EL2 registers are AArch32-specific. Since we forbid AArch32, there is no need to handle those in any way.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ---- 1 file changed, 4 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -4
@@ -452,10 +452,6 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = { HOST_HANDLED(SYS_CNTP_CVAL_EL0),/* Performance Monitoring Registers are restricted. */ - -HOST_HANDLED (SYS_DACR32_EL2 ), -HOST_HANDLED (SYS_IFSR32_EL2 ), - HOST_HANDLED(SYS_FPEXC32_EL2), };/*
Signature · 1 line
2.30.2
Re: [PATCH v9 15/22] KVM: arm64: pkvm: Drop AArch32-specific registers
Quoted 26 lines · Marc Zyngier
All the SYS_*32_EL2 registers are AArch32-specific. Since we forbid AArch32, there is no need to handle those in any way.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ---- 1 file changed, 4 deletions(-)arch/arm64/kvm/hyp/nvhe/sys_regs.c +0
-4@@ -452,10 +452,6 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = { HOST_HANDLED(SYS_CNTP_CVAL_EL0),/* Performance Monitoring Registers are restricted. */ - -HOST_HANDLED (SYS_DACR32_EL2 ), -HOST_HANDLED (SYS_IFSR32_EL2 ), - HOST_HANDLED(SYS_FPEXC32_EL2), };/* Signature · 1 line
2.30.2
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH v9 16/22 KVM: arm64: pkvm: Drop sysregs that should never be routed to the host
In reply to Marc ZyngierA bunch of system registers (most of them MM related) should never trap to the host under any circumstance. Keep them close to our chest.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 50 ------------------------------ 1 file changed, 50 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -50
@@ -371,34 +371,8 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {AARCH64 (SYS_ID_AA64MMFR1_EL1 ),AARCH64 (SYS_ID_AA64MMFR2_EL1 ), -HOST_HANDLED (SYS_SCTLR_EL1 ), -HOST_HANDLED (SYS_ACTLR_EL1 ), -HOST_HANDLED (SYS_CPACR_EL1 ), - -HOST_HANDLED (SYS_RGSR_EL1 ), -HOST_HANDLED (SYS_GCR_EL1 ), -/* Scalable Vector Registers are restricted. */ -HOST_HANDLED (SYS_TTBR0_EL1 ), -HOST_HANDLED (SYS_TTBR1_EL1 ), -HOST_HANDLED (SYS_TCR_EL1 ), - -HOST_HANDLED (SYS_APIAKEYLO_EL1 ), -HOST_HANDLED (SYS_APIAKEYHI_EL1 ), -HOST_HANDLED (SYS_APIBKEYLO_EL1 ), -HOST_HANDLED (SYS_APIBKEYHI_EL1 ), -HOST_HANDLED (SYS_APDAKEYLO_EL1 ), -HOST_HANDLED (SYS_APDAKEYHI_EL1 ), -HOST_HANDLED (SYS_APDBKEYLO_EL1 ), -HOST_HANDLED (SYS_APDBKEYHI_EL1 ), -HOST_HANDLED (SYS_APGAKEYLO_EL1 ), -HOST_HANDLED (SYS_APGAKEYHI_EL1 ), - -HOST_HANDLED (SYS_AFSR0_EL1 ), -HOST_HANDLED (SYS_AFSR1_EL1 ), -HOST_HANDLED (SYS_ESR_EL1 ), -RAZ_WI (SYS_ERRIDR_EL1 ),RAZ_WI (SYS_ERRSELR_EL1 ), RAZ_WI(SYS_ERXFR_EL1),
@@ -408,31 +382,12 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {RAZ_WI (SYS_ERXMISC0_EL1 ),RAZ_WI (SYS_ERXMISC1_EL1 ), -HOST_HANDLED (SYS_TFSR_EL1 ), -HOST_HANDLED (SYS_TFSRE0_EL1 ), - -HOST_HANDLED (SYS_FAR_EL1 ), -HOST_HANDLED (SYS_PAR_EL1 ), -/* Performance Monitoring Registers are restricted. */ -HOST_HANDLED (SYS_MAIR_EL1 ), -HOST_HANDLED (SYS_AMAIR_EL1 ), -/* Limited Ordering Regions Registers are restricted. */ -HOST_HANDLED (SYS_VBAR_EL1 ), -HOST_HANDLED (SYS_DISR_EL1 ), -/* GIC CPU Interface registers are restricted. */ -HOST_HANDLED (SYS_CONTEXTIDR_EL1 ), -HOST_HANDLED (SYS_TPIDR_EL1 ), - -HOST_HANDLED (SYS_SCXTNUM_EL1 ), - -HOST_HANDLED (SYS_CNTKCTL_EL1 ), -HOST_HANDLED (SYS_CCSIDR_EL1 ),HOST_HANDLED (SYS_CLIDR_EL1 ), HOST_HANDLED(SYS_CSSELR_EL1),
@@ -440,11 +395,6 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {/* Performance Monitoring Registers are restricted. */ -HOST_HANDLED (SYS_TPIDR_EL0 ), -HOST_HANDLED (SYS_TPIDRRO_EL0 ), - -HOST_HANDLED (SYS_SCXTNUM_EL0 ), -/* Activity Monitoring Registers are restricted. */ HOST_HANDLED(SYS_CNTP_TVAL_EL0),
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 17/22 KVM: arm64: pkvm: Handle GICv3 traps as required
In reply to Marc ZyngierForward accesses to the ICV_*SGI*_EL1 registers to EL1, and emulate ICV_SRE_EL1 by returning a fixed value.
This should be enough to support GICv3 in a protected guest.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +17 -1
@@ -4,6 +4,8 @@* Author: Fuad Tabba <[email protected]> */ +#include <linux/irqchip/arm-gic-v3.h> +#include <asm/kvm_asm.h> #include <asm/kvm_fixed_config.h> #include <asm/kvm_mmu.h>
@@ -303,6 +305,17 @@ static bool pvm_access_id_aarch64(struct kvm_vcpu *vcpu,return true; } +static bool pvm_gic_read_sre (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +/* pVMs only support GICv3. 'nuf said. */ +if (!p->is_write) + p->regval =ICC_SRE_EL1_DIB |ICC_SRE_EL1_DFB |ICC_SRE_EL1_SRE ; + +return true; +} +/* Mark the specified system register as an AArch32 feature id register. */ #define AARCH32 (REG ) { SYS_DESC(REG), .access = pvm_access_id_aarch32 }
@@ -386,7 +399,10 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {/* Limited Ordering Regions Registers are restricted. */ -/* GIC CPU Interface registers are restricted. */ +HOST_HANDLED (SYS_ICC_SGI1R_EL1 ), +HOST_HANDLED (SYS_ICC_ASGI1R_EL1 ), +HOST_HANDLED (SYS_ICC_SGI0R_EL1 ), + { SYS_DESC(SYS_ICC_SRE_EL1), .access = pvm_gic_read_sre, },HOST_HANDLED (SYS_CCSIDR_EL1 ), HOST_HANDLED(SYS_CLIDR_EL1),
Signature · 1 line
2.30.2
Re: [PATCH v9 17/22] KVM: arm64: pkvm: Handle GICv3 traps as required
Quoted 4 lines · Marc Zyngier
Forward accesses to the ICV_*SGI*_EL1 registers to EL1, and emulate
ICV_SRE_EL1by returning a fixed value.This should be enough to support GICv3 in a protected guest.
Out of curiosity, has the RVIC work / plans been dropped?
Thanks,
drew
Marc Zyngier
maintainerRe: [PATCH v9 17/22] KVM: arm64: pkvm: Handle GICv3 traps as required
Quoted 7 lines · Andrew Jones
Quoted 4 lines · Marc Zyngier
Forward accesses to the ICV_*SGI*_EL1 registers to EL1, and emulate
ICV_SRE_EL1by returning a fixed value.This should be enough to support GICv3 in a protected guest.
Out of curiosity, has the RVIC work / plans been dropped?
ARM has dropped the architecture, and it makes no sense to move KVM to support non-architectural stuff.
Which means we will eventually have to harden the guest itself to cope with the fact that it cannot trust the interrupt controller.
Yes, this is crap.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Marc Zyngier
maintainerPATCH v9 18/22 KVM: arm64: pkvm: Preserve pending SError on exit from AArch32
In reply to Marc ZyngierDon't drop a potential SError when a guest gets caught red-handed running AArch32 code.
--- arch/arm64/kvm/hyp/nvhe/switch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/switch.c +2 -1
@@ -256,7 +256,8 @@ static bool handle_aarch32_guest(struct kvm_vcpu *vcpu, u64 *exit_code)* protected VMs. */ vcpu->arch.target =-1 ; - *exit_code =ARM_EXCEPTION_IL ; + *exit_code &=BIT (ARM_EXIT_WITH_SERROR_BIT ); + *exit_code |=ARM_EXCEPTION_IL ;return false; }
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 19/22 KVM: arm64: pkvm: Consolidate include files
In reply to Marc Zyngierkvm_fixed_config.h is pkvm specific, and would be better placed near its users. At the same time, include/nvhe/sys_regs.h is now almost empty.
Merge the two into arch/arm64/kvm/hyp/include/nvhe/fixed_config.h.
---
.../hyp/include/nvhe/fixed_config.h} | 5 +++++
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 17 -----------------
arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 +--
arch/arm64/kvm/hyp/nvhe/setup.c | 2 +-
arch/arm64/kvm/hyp/nvhe/switch.c | 3 +--
arch/arm64/kvm/hyp/nvhe/sys_regs.c | 3 +--
6 files changed, 9 insertions(+), 24 deletions(-)
rename arch/arm64/{include/asm/kvm_fixed_config.h => kvm/hyp/include/nvhe/fixed_config.h} (96%)
delete mode 100644 arch/arm64/kvm/hyp/include/nvhe/sys_regs.harch/arm64/kvm/hyp/include/nvhe/fixed_config.h renamed from arch/arm64/include/asm/kvm_fixed_config.h +5 -0
@@ -192,4 +192,9 @@ ARM64_FEATURE_MASK(ID_AA64ISAR1_I8MM) \ ) +u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id); +bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code); +int kvm_check_pvm_sysreg_table (void ); +void inject_undef64 (struct kvm_vcpu *vcpu); +#endif /* __ARM64_KVM_FIXED_CONFIG_H__ */
arch/arm64/kvm/hyp/include/nvhe/sys_regs.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Copyright (C) 2021 Google LLC -* Author: Fuad Tabba <[email protected]> -*/ - -#ifndef __ARM64_KVM_NVHE_SYS_REGS_H__ -#define __ARM64_KVM_NVHE_SYS_REGS_H__ - -#include <asm/kvm_host.h> - -u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id); -bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code); -int kvm_check_pvm_sysreg_table (void ); -void inject_undef64 (struct kvm_vcpu *vcpu); - -#endif /* __ARM64_KVM_NVHE_SYS_REGS_H__ */
arch/arm64/kvm/hyp/nvhe/pkvm.c +1 -2
@@ -6,8 +6,7 @@#include <linux/kvm_host.h> #include <linux/mm.h> -#include <asm/kvm_fixed_config.h> -#include <nvhe/sys_regs.h> +#include <nvhe/fixed_config.h> #include <nvhe/trap_handler.h> /*
arch/arm64/kvm/hyp/nvhe/setup.c +1 -1
@@ -10,11 +10,11 @@#include <asm/kvm_pgtable.h> #include <nvhe/early_alloc.h> +#include <nvhe/fixed_config.h> #include <nvhe/gfp.h> #include <nvhe/memory.h> #include <nvhe/mem_protect.h> #include <nvhe/mm.h> -#include <nvhe/sys_regs.h> #include <nvhe/trap_handler.h> struct hyp_pool hpool;
arch/arm64/kvm/hyp/nvhe/switch.c +1 -2
@@ -20,7 +20,6 @@#include <asm/kprobes.h> #include <asm/kvm_asm.h> #include <asm/kvm_emulate.h> -#include <asm/kvm_fixed_config.h> #include <asm/kvm_hyp.h> #include <asm/kvm_mmu.h> #include <asm/fpsimd.h>
@@ -28,8 +27,8 @@#include <asm/processor.h> #include <asm/thread_info.h> +#include <nvhe/fixed_config.h> #include <nvhe/mem_protect.h> -#include <nvhe/sys_regs.h> /* Non-VHE specific context */ DEFINE_PER_CPU(struct kvm_host_data, kvm_host_data);
arch/arm64/kvm/hyp/nvhe/sys_regs.c +1 -2
@@ -7,12 +7,11 @@#include <linux/irqchip/arm-gic-v3.h> #include <asm/kvm_asm.h> -#include <asm/kvm_fixed_config.h> #include <asm/kvm_mmu.h> #include <hyp/adjust_pc.h> -#include <nvhe/sys_regs.h> +#include <nvhe/fixed_config.h> #include "../../sys_regs.h"
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 20/22 KVM: arm64: pkvm: Move kvm_handle_pvm_restricted around
In reply to Marc ZyngierPlace kvm_handle_pvm_restricted() next to its little friends such as kvm_handle_pvm_sysreg().
This allows to make inject_undef64() static.
--- arch/arm64/kvm/hyp/include/nvhe/fixed_config.h | 2 +- arch/arm64/kvm/hyp/nvhe/switch.c | 12 ------------ arch/arm64/kvm/hyp/nvhe/sys_regs.c | 14 +++++++++++++- 3 files changed, 14 insertions(+), 14 deletions(-)
arch/arm64/kvm/hyp/include/nvhe/fixed_config.h +1 -1
@@ -194,7 +194,7 @@u64 pvm_read_id_reg (const struct kvm_vcpu *vcpu,u32 id);bool kvm_handle_pvm_sysreg (struct kvm_vcpu *vcpu,u64 *exit_code); +bool kvm_handle_pvm_restricted (struct kvm_vcpu *vcpu,u64 *exit_code);int kvm_check_pvm_sysreg_table (void ); -void inject_undef64 (struct kvm_vcpu *vcpu);#endif /* __ARM64_KVM_FIXED_CONFIG_H__ */
arch/arm64/kvm/hyp/nvhe/switch.c +0 -12
@@ -159,18 +159,6 @@ static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)write_sysreg (pmu->events_host, pmcntenset_el0); } -/** -* Handler for protected VM restricted exceptions. -* -* Inject an undefined exception into the guest and return true to indicate that -* the hypervisor has handled the exit, and control should go back to the guest. -*/ -static bool kvm_handle_pvm_restricted (struct kvm_vcpu *vcpu,u64 *exit_code) -{ -inject_undef64 (vcpu); -return true; -} -/** * Handler for protected VM MSR, MRS or System instruction execution in AArch64. *
arch/arm64/kvm/hyp/nvhe/sys_regs.c +13 -1
@@ -30,7 +30,7 @@ u64 id_aa64mmfr2_el1_sys_val;* Inject an unknown/undefined exception to an AArch64 guest while most of its * sysregs are live. */ -void inject_undef64 (struct kvm_vcpu *vcpu) +static void inject_undef64 (struct kvm_vcpu *vcpu) {u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
@@ -473,3 +473,15 @@ bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code)return true; } + +/** +* Handler for protected VM restricted exceptions. +* +* Inject an undefined exception into the guest and return true to indicate that +* the hypervisor has handled the exit, and control should go back to the guest. +*/ +bool kvm_handle_pvm_restricted (struct kvm_vcpu *vcpu,u64 *exit_code) +{ +inject_undef64 (vcpu); +return true; +}
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 21/22 KVM: arm64: pkvm: Pass vpcu instead of kvm to kvm_get_exit_handler_array()
In reply to Marc ZyngierPassing a VM pointer around is odd, and results in extra work on VHE. Follow the rest of the design that uses the vcpu instead, and let the nVHE code look into the struct kvm as required.
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/switch.c | 4 ++-- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
@@ -397,7 +397,7 @@ static bool kvm_hyp_handle_dabt_low(struct kvm_vcpu *vcpu, u64 *exit_code)typedef bool (*exit_handler_fn )(struct kvm_vcpu *,u64 *); -static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm); +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm_vcpu *vcpu);/* * Allow the hypervisor to handle the exit with an exit handler if it has one.
@@ -407,7 +407,7 @@ static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm *kvm);*/ static inline bool kvm_hyp_handle_exit (struct kvm_vcpu *vcpu,u64 *exit_code) { -const exit_handler_fn *handlers =kvm_get_exit_handler_array (kern_hyp_va (vcpu->kvm)); +const exit_handler_fn *handlers =kvm_get_exit_handler_array (vcpu);exit_handler_fn fn; fn = handlers[kvm_vcpu_trap_get_class (vcpu)];
arch/arm64/kvm/hyp/nvhe/switch.c +2 -2
@@ -211,9 +211,9 @@ static const exit_handler_fn pvm_exit_handlers[] = { [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; -static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm) +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm_vcpu *vcpu) { -if (unlikely (kvm_vm_is_protected (kvm))) +if (unlikely (kvm_vm_is_protected (kern_hyp_va (vcpu->kvm))))return pvm_exit_handlers;return hyp_exit_handlers;
arch/arm64/kvm/hyp/vhe/switch.c +1 -1
@@ -107,7 +107,7 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; -static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm *kvm) +static const exit_handler_fn *kvm_get_exit_handler_array (struct kvm_vcpu *vcpu) {return hyp_exit_handlers; }
Signature · 1 line
2.30.2
Marc Zyngier
maintainerPATCH v9 22/22 KVM: arm64: pkvm: Give priority to standard traps over pvm handling
In reply to Marc ZyngierChecking for pvm handling first means that we cannot handle ptrauth traps or apply any of the workarounds (GICv3 or TX2 #219).
Flip the order around.
--- arch/arm64/kvm/hyp/nvhe/switch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp/nvhe/switch.c +7 -4
@@ -167,10 +167,13 @@ static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)*/ static bool kvm_handle_pvm_sys64 (struct kvm_vcpu *vcpu,u64 *exit_code) { -if (kvm_handle_pvm_sysreg (vcpu, exit_code)) -return true; - -return kvm_hyp_handle_sysreg (vcpu, exit_code); +/* +* Make sure we handle the exit for workarounds and ptrauth +* before the pKVM handling, as the latter could decide to +* UNDEF. +*/ +return (kvm_hyp_handle_sysreg (vcpu, exit_code) || +kvm_handle_pvm_sysreg (vcpu, exit_code)); }/**
Signature · 1 line
2.30.2
Hi Marc,
Quoted 10 lines · Marc Zyngier
This is an update on Fuad's series[1].
Instead of going going back and forth over a series that has seen a fair few versions, I've opted for simply writing a set of fixes on top, hopefully greatly simplifying the handling of most registers, and moving things around to suit my own taste (just because I can).
I won't be reposting the initial 11 patches, which is why this series in is reply to patch 11.
Thanks for this series. I've reviewed, built it, and tested it with a dummy protected VM (since we don't have proper protected VMs yet), which initializes some of the relevant protected VMs metadata as well as its control registers. So fwiw:
And to whatever extent possible at this stage:
Cheers,
/fuad
Quoted 60 lines
Thanks,
M.[1] https://lore.kernel.org/r/[email protected]
Fuad Tabba (8):
KVM: arm64: Pass struct kvm to per-EC handlers
KVM: arm64: Add missing field descriptor forMDCR_EL2
KVM: arm64: Simplify masking out MTE in feature id reg
KVM: arm64: Add handlers for protected VM System Registers
KVM: arm64: Initialize trap registers for protected VMs
KVM: arm64: Move sanitized copies of CPU features
KVM: arm64: Trap access to pVM restricted features
KVM: arm64: Handle protected guests at 32 bitsMarc Zyngier (14):
KVM: arm64: Move__get_fault_info()and co into their own include file
KVM: arm64: Don't includeswitch.hintonvhe/kvm-main.c
KVM: arm64: Move early handlers to per-EC handlers
KVM: arm64: Fix early exit ptrauth handling
KVM: arm64: pkvm: Use a single function to expose all id-regs
KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
KVM: arm64: pkvm: Drop AArch32-specific registers
KVM: arm64: pkvm: Drop sysregs that should never be routed to the host
KVM: arm64: pkvm: Handle GICv3 traps as required
KVM: arm64: pkvm: Preserve pending SError on exit from AArch32
KVM: arm64: pkvm: Consolidate include files
KVM: arm64: pkvm: Movekvm_handle_pvm_restrictedaround
KVM: arm64: pkvm: Pass vpcu instead of kvm to
kvm_get_exit_handler_array()
KVM: arm64: pkvm: Give priority to standard traps over pvm handlingarch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kvm/arm.c | 13 + arch/arm64/kvm/hyp/include/hyp/fault.h | 75 +++ arch/arm64/kvm/hyp/include/hyp/switch.h | 235 ++++----- .../arm64/kvm/hyp/include/nvhe/fixed_config.h | 200 +++++++ .../arm64/kvm/hyp/include/nvhe/trap_handler.h | 2 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 8 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 185 +++++++ arch/arm64/kvm/hyp/nvhe/setup.c | 3 + arch/arm64/kvm/hyp/nvhe/switch.c | 99 ++++ arch/arm64/kvm/hyp/nvhe/sys_regs.c | 487 ++++++++++++++++++ arch/arm64/kvm/hyp/vhe/switch.c | 16 + arch/arm64/kvm/sys_regs.c | 10 +- 18 files changed, 1200 insertions(+), 155 deletions(-) create mode 100644 arch/arm64/kvm/hyp/include/hyp/fault.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/fixed_config.h create mode 100644 arch/arm64/kvm/hyp/nvhe/pkvm.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sys_regs.c--
2.30.2
Quoted 19 lines · Fuad Tabba
Hi Marc,
Quoted 10 lines · Marc Zyngier
This is an update on Fuad's series[1].
Instead of going going back and forth over a series that has seen a fair few versions, I've opted for simply writing a set of fixes on top, hopefully greatly simplifying the handling of most registers, and moving things around to suit my own taste (just because I can).
I won't be reposting the initial 11 patches, which is why this series in is reply to patch 11.
Thanks for this series. I've reviewed, built it, and tested it with a dummy protected VM (since we don't have proper protected VMs yet), which initializes some of the relevant protected VMs metadata as well as its control registers. So fwiw:
Quoted 5 lines
Reviewed-by Fuad Tabba <[email protected]>And to whatever extent possible at this stage:
Tested-by Fuad Tabba <[email protected]>
Hi Fuad,
Out of curiosity, when testing pKVM, what VMM do you use? Also, can you describe what a "dummy pVM" is? Is it a just pVM which is not actually protected? How similar is a pVM to a typical VIRTIO-using VM? Actually, maybe I should just ask if there are instructions for playing with pKVM somewhere that I could get a pointer to.
Thanks,
drew
Hi,
Quoted 27 lines · Andrew Jones
Quoted 19 lines · Fuad Tabba
Hi Marc,
Quoted 10 lines · Marc Zyngier
This is an update on Fuad's series[1].
Instead of going going back and forth over a series that has seen a fair few versions, I've opted for simply writing a set of fixes on top, hopefully greatly simplifying the handling of most registers, and moving things around to suit my own taste (just because I can).
I won't be reposting the initial 11 patches, which is why this series in is reply to patch 11.
Thanks for this series. I've reviewed, built it, and tested it with a dummy protected VM (since we don't have proper protected VMs yet), which initializes some of the relevant protected VMs metadata as well as its control registers. So fwiw:
Quoted 5 lines
Reviewed-by Fuad Tabba <[email protected]>And to whatever extent possible at this stage:
Tested-by Fuad Tabba <[email protected]>
Quoted 7 lines
Hi Fuad,
Out of curiosity, when testing pKVM, what VMM do you use? Also, can you describe what a "dummy pVM" is? Is it a just pVM which is not actually protected? How similar is a pVM to a typical VIRTIO-using VM? Actually, maybe I should just ask if there are instructions for playing with pKVM somewhere that I could get a pointer to.
Considering the WIP state of pKVM, my setup is hacky and not that stable. I use QEMU, along with Will'ls pKVM user ABI patches [*] and a couple of hacks added on top to run a normal VM with the protected codepath applied to it, to be able to do some testing and sanity checking. There isn't really any proper way of playing with protected VMs yet.
Thanks,
/fuad
[*] https://lore.kernel.org/kvmarm/[email protected]/
Quoted 3 lines
Thanks,
drew
Quoted 8 lines · Marc Zyngier
This is an update on Fuad's series[1].
Instead of going going back and forth over a series that has seen a fair few versions, I've opted for simply writing a set of fixes on top, hopefully greatly simplifying the handling of most registers, and moving things around to suit my own taste (just because I can).
[...]
Applied to next, thanks!
[12/22] KVM: arm64: Fix early exit ptrauth handling
commit: 8a049862c38f0c78b0e01ab5d36db1bffc832675
[13/22] KVM: arm64: pkvm: Use a single function to expose all id-regs
commit: ce75916749b8cb5ec795f1157a5c426f6765a48c
[14/22] KVM: arm64: pkvm: Make the ERR/ERX*_EL1 registers RAZ/WI
commit: 8ffb41888334c1247bd9b4d6ff6c092a90e8d0b8
[15/22] KVM: arm64: pkvm: Drop AArch32-specific registers
commit: 3c90cb15e2e66bcc526d25133747b2af747f6cd8
[16/22] KVM: arm64: pkvm: Drop sysregs that should never be routed to the host
commit: f3d5ccabab20c1be5838831f460f320a12e5e2c9
[17/22] KVM: arm64: pkvm: Handle GICv3 traps as required
commit: cbca19738472be8156d854663ed724b01255c932
[18/22] KVM: arm64: pkvm: Preserve pending SError on exit from AArch32
commit: 271b7286058da636ab6f5f47722e098ca3a0478b
[19/22] KVM: arm64: pkvm: Consolidate include files
commit: 3061725d162cad0589b012fc6413c9dd0da8f02a
[20/22] KVM: arm64: pkvm: Move kvm_handle_pvm_restricted around
commit: 746bdeadc53b0d58fddea6442591f5ec3eeabe7d
[21/22] KVM: arm64: pkvm: Pass vpcu instead of kvm to kvm_get_exit_handler_array()
commit: 0c7639cc838263b6e38b3af76755d574f15cdf41
[22/22] KVM: arm64: pkvm: Give priority to standard traps over pvm handling
commit: 07305590114af81817148d181f1eb0af294e40d6Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 9 lines · Fuad Tabba
Changes since v7 [1]:
- Fix build warningsThis patch series adds support for restricting CPU features for protected VMs in KVM (pKVM). For more background, please refer to the previous series [2].
This series is based on 5.15-rc4. You can find the applied series here [3].
[...]
Applied to next, thanks!
[01/11] KVM: arm64: Move __get_fault_info() and co into their own include file
commit: 7dd9b5a157485ae8c48f76f087b1867ace016613
[02/11] KVM: arm64: Don't include switch.h into nvhe/kvm-main.c
commit: cc1e6fdfa92b82902883b70dafa729d3bd427b80
[03/11] KVM: arm64: Move early handlers to per-EC handlers
commit: 8fb2046180a0ad347f2e5bcae760dca67e65aa73
[04/11] KVM: arm64: Pass struct kvm to per-EC handlers
commit: 3b1a690eda0dc1891e8fc93991b122bff6fabf8c
[05/11] KVM: arm64: Add missing field descriptor for MDCR_EL2
commit: 53868390778270f2890621f4498a53587719a3ff
[06/11] KVM: arm64: Simplify masking out MTE in feature id reg
commit: 16dd1fbb12f72effcd3539561c2a94aed3ab6581
[07/11] KVM: arm64: Add handlers for protected VM System Registers
commit: 6c30bfb18d0b7d09593f204c936493cfcd153956
[08/11] KVM: arm64: Initialize trap registers for protected VMs
commit: 2a0c343386ae1a6826e1b9d751bfc14f4711c2de
[09/11] KVM: arm64: Move sanitized copies of CPU features
commit: 72e1be120eaaf82a58c81fcf173cdb1d7a5dcfbb
[10/11] KVM: arm64: Trap access to pVM restricted features
commit: 1423afcb411780c7a6a68f801fdcfb6920ad6f06
[11/11] KVM: arm64: Handle protected guests at 32 bits
commit: 5f39efc42052b042c4d7ba6fd77934e8de43e10cCheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.