From 781c40738232ed67014e306e2f44fca3819d2304 Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Thu, 7 Jul 2022 15:51:21 +0100 Subject: [PATCH] Revert "ANDROID: KVM: arm64: pkvm: Rerge get_num_hvc_args into handle_pvm_exit_hvc64" This reverts commit addb3e1f478377899e6ab00cc45e849f6d2bf761. Bug: 233587962 Signed-off-by: Will Deacon Change-Id: Ia08e9c250eb792229249e650f521aa5c9945bd14 --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index c475b6877631..51104a7e6b36 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -251,11 +251,11 @@ static void handle_pvm_exit_sys64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *s } } -static void handle_pvm_exit_hvc64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *shadow_vcpu) +static int get_num_hvc_args(struct kvm_vcpu *vcpu) { - int n, i; + u32 psci_fn = smccc_get_function(vcpu); - switch (smccc_get_function(shadow_vcpu)) { + switch (psci_fn) { /* * CPU_ON takes 3 arguments, however, to wake up the target vcpu the * host only needs to know the target's cpu_id, which is passed as the @@ -263,34 +263,37 @@ static void handle_pvm_exit_hvc64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *s */ case PSCI_0_2_FN_CPU_ON: case PSCI_0_2_FN64_CPU_ON: - n = 2; - break; + return 1; case PSCI_0_2_FN_CPU_OFF: case PSCI_0_2_FN_SYSTEM_OFF: + + /* The KVM implementation of suspend doesn't use any arguments. */ case PSCI_0_2_FN_CPU_SUSPEND: case PSCI_0_2_FN64_CPU_SUSPEND: - n = 1; - break; + return 0; case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID: fallthrough; case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: - n = 4; - break; + return 3; - /* - * The rest are either blocked or handled by HYP, so we should - * really never be here. - */ + /* The rest are either blocked or handled by hyp. */ default: - BUG(); + return -1; } + return -1; +} + +static void handle_pvm_exit_hvc64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *shadow_vcpu) +{ + int i; + host_vcpu->arch.fault.esr_el2 = shadow_vcpu->arch.fault.esr_el2; /* Pass the hvc function id (r0) as well as any potential arguments. */ - for (i = 0; i < n; i++) + for (i = 0; i < get_num_hvc_args(shadow_vcpu) + 1; i++) vcpu_set_reg(host_vcpu, i, vcpu_get_reg(shadow_vcpu, i)); }