From eb11b8659d064cba0eb36ac19c0323ac286ae62d Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Wed, 9 Mar 2022 18:13:08 +0000 Subject: [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace Commit ed47efd863d9 ("KVM: arm64: Expose PSCI SYSTEM_RESET2 call to the guest") hooked up the SYSTEM_RESET2 PSCI call for guests but failed to preserve its arguments for userspace, instead overwriting them with zeroes via smccc_set_retval(). As Linux only passes zeroes for these arguments, this appeared to be working for Linux guests. Oh well. Don't call smccc_set_retval() for a SYSTEM_RESET2 heading to userspace and instead set X0 (and only X0) explicitly to PSCI_RET_INTERNAL_FAILURE just in case the vCPU re-enters the guest. Fixes: ed47efd863d9 ("KVM: arm64: Expose PSCI SYSTEM_RESET2 call to the guest") Reported-by: Andrew Walbran Signed-off-by: Will Deacon Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20220309181308.982-1-will@kernel.org --- arch/arm64/kvm/psci.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 0d48d1e7291d5..3e007d6982af0 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -367,14 +367,14 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) if (minor >= 1) { arg = smccc_get_arg1(vcpu); - if (arg > PSCI_1_1_RESET_TYPE_SYSTEM_WARM_RESET && - arg < PSCI_1_1_RESET_TYPE_VENDOR_START) { - val = PSCI_RET_INVALID_PARAMS; - } else { + if (arg <= PSCI_1_1_RESET_TYPE_SYSTEM_WARM_RESET || + arg >= PSCI_1_1_RESET_TYPE_VENDOR_START) { kvm_psci_system_reset2(vcpu); - val = PSCI_RET_INTERNAL_FAILURE; - ret = 0; + vcpu_set_reg(vcpu, 0, PSCI_RET_INTERNAL_FAILURE); + return 0; } + + val = PSCI_RET_INVALID_PARAMS; break; } fallthrough; -- 2.39.5