diff --git a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h index 4d40c536d26a..259d3094d31e 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h @@ -113,6 +113,7 @@ void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm); bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code); bool kvm_handle_pvm_restricted(struct kvm_vcpu *vcpu, u64 *exit_code); +void kvm_init_pvm_id_regs(struct kvm_vcpu *vcpu); void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu); int kvm_check_pvm_sysreg_table(void); diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 4895a418f2ec..885194dc59ba 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -652,6 +652,7 @@ static int init_pkvm_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu, hyp_vcpu->vcpu.arch.debug_ptr = &host_vcpu->arch.vcpu_debug_state; hyp_vcpu->vcpu.arch.hyp_reqs->type = KVM_HYP_LAST_REQ; + kvm_init_pvm_id_regs(&hyp_vcpu->vcpu); kvm_reset_pvm_sys_regs(&hyp_vcpu->vcpu); ret = pkvm_vcpu_init_traps(hyp_vcpu); diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c index 0c4ef4f655ee..de5c34f1b0d5 100644 --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c @@ -614,12 +614,9 @@ static const struct sys_reg_desc_reset pvm_sys_reg_reset_vals[] = { }; /* - * Sets system registers to reset value - * - * This function finds the right entry and sets the registers on the protected - * vcpu to their architecturally defined reset values. + * Initializes feature registers for protected vms. */ -void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu) +void kvm_init_pvm_id_regs(struct kvm_vcpu *vcpu) { /* List of feature registers to reset for protected VMs. */ const u32 pvm_feat_id_regs[] = { @@ -636,13 +633,7 @@ void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu) SYS_ID_AA64DFR0_EL1, }; struct kvm *kvm = vcpu->kvm; - unsigned long i; - - for (i = 0; i < ARRAY_SIZE(pvm_sys_reg_reset_vals); i++) { - const struct sys_reg_desc_reset *r = &pvm_sys_reg_reset_vals[i]; - - r->reset(vcpu, r); - } + int i; if (test_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags)) return; @@ -657,6 +648,24 @@ void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu) set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags); } + +/* + * Sets system registers to reset value + * + * This function finds the right entry and sets the registers on the protected + * vcpu to their architecturally defined reset values. + */ +void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu) +{ + unsigned long i; + + for (i = 0; i < ARRAY_SIZE(pvm_sys_reg_reset_vals); i++) { + const struct sys_reg_desc_reset *r = &pvm_sys_reg_reset_vals[i]; + + r->reset(vcpu, r); + } +} + /* * Checks that the sysreg tables are unique and in-order. *