All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
@ 2022-03-09 18:13 ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2022-03-09 18:13 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, Will Deacon, Andrew Walbran, linux-arm-kernel

Commit d43583b890e7 ("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: d43583b890e7 ("KVM: arm64: Expose PSCI SYSTEM_RESET2 call to the guest")
Reported-by: Andrew Walbran <qwandor@google.com>
Signed-off-by: Will Deacon <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 ecb4b74cb12a..b0c920717632 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.35.1.616.g0bdcbb4464-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
@ 2022-03-09 18:13 ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2022-03-09 18:13 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, linux-arm-kernel, Will Deacon, Andrew Walbran

Commit d43583b890e7 ("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: d43583b890e7 ("KVM: arm64: Expose PSCI SYSTEM_RESET2 call to the guest")
Reported-by: Andrew Walbran <qwandor@google.com>
Signed-off-by: Will Deacon <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 ecb4b74cb12a..b0c920717632 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.35.1.616.g0bdcbb4464-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
  2022-03-09 18:13 ` Will Deacon
@ 2022-03-09 18:21   ` Marc Zyngier
  -1 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2022-03-09 18:21 UTC (permalink / raw)
  To: Will Deacon, kvmarm; +Cc: linux-arm-kernel, Andrew Walbran

On Wed, 9 Mar 2022 18:13:08 +0000, Will Deacon wrote:
> Commit d43583b890e7 ("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.

Applied to next, thanks!

[1/1] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
      commit: 9d3e7b7c82fd9d40240867ef4c45388cd05031f3

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
@ 2022-03-09 18:21   ` Marc Zyngier
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2022-03-09 18:21 UTC (permalink / raw)
  To: Will Deacon, kvmarm; +Cc: Andrew Walbran, linux-arm-kernel

On Wed, 9 Mar 2022 18:13:08 +0000, Will Deacon wrote:
> Commit d43583b890e7 ("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.

Applied to next, thanks!

[1/1] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace
      commit: 9d3e7b7c82fd9d40240867ef4c45388cd05031f3

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-09 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-09 18:13 [PATCH] KVM: arm64: Really propagate PSCI SYSTEM_RESET2 arguments to userspace Will Deacon
2022-03-09 18:13 ` Will Deacon
2022-03-09 18:21 ` Marc Zyngier
2022-03-09 18:21   ` Marc Zyngier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.