Skip to contentSkip to conversation

FAILED: patch "[PATCH] KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect" failed to apply to 5.4-stable tree

PATCH [email protected] 2 participants 3 messages Jul 13, 2020 – Jul 14, 2020

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 66b7e05dc0239c5817859f261098ba9cc2efbd2b Mon Sep 17 00:00:00 2001
From: Steven Price <[email protected]>
Date: Wed, 17 Jun 2020 11:54:56 +0100
Subject: [PATCH] KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect
with SVE

If SVE is enabled then 'ret' can be assigned the return value of kvm_vcpu_enable_sve() which may be 0 causing future "goto out" sites to erroneously return 0 on failure rather than -EINVAL as expected.

Remove the initialisation of 'ret' and make setting the return value explicit to avoid this situation in the future.

Fixes 9a3cdf26e336 ("KVM: arm64/sve: Allow userspace to enable SVE for vcpus")
arch/arm64/kvm/reset.c +7 -3
index d3b209023727..6ed36be51b4b 100644
@@ -245,7 +245,7 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
  */
 int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 {
-	int ret = -EINVAL;
+	int ret;
 	bool loaded;
 	u32 pstate;
 
@@ -269,15 +269,19 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 
 	if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
 	    test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) {
-		if (kvm_vcpu_enable_ptrauth(vcpu))
+		if (kvm_vcpu_enable_ptrauth(vcpu)) {
+			ret = -EINVAL;
 			goto out;
+		}
 	}
 
 	switch (vcpu->arch.target) {
 	default:
 		if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
-			if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1))
+			if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1)) {
+				ret = -EINVAL;
 				goto out;
+			}
 			pstate = VCPU_RESET_PSTATE_SVC;
 		} else {
 			pstate = VCPU_RESET_PSTATE_EL1;
maintainer
#1 lore raw
Quoted 25 lines · On Mon, Jul 13, 2020 at 06:00:59PM +0200, [email protected] wrote:

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 66b7e05dc0239c5817859f261098ba9cc2efbd2b Mon Sep 17 00:00:00 2001
From: Steven Price <[email protected]>
Date: Wed, 17 Jun 2020 11:54:56 +0100
Subject: [PATCH] KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect with SVE

If SVE is enabled then 'ret' can be assigned the return value of kvm_vcpu_enable_sve() which may be 0 causing future "goto out" sites to erroneously return 0 on failure rather than -EINVAL as expected.

Remove the initialisation of 'ret' and make setting the return value explicit to avoid this situation in the future.

Quoted 6 lines
Fixes 9a3cdf26e336 ("KVM: arm64/sve: Allow userspace to enable SVE for vcpus")

I've worked around not having 540f76d12c66 ("arm64: cpufeature: Add CPU capability for AArch32 EL1 support") in 5.7 and 5.4 and queued this patch.

Signature · 2 lines
Thanks,
Sasha
author maintainer
#2 lore raw
Quoted 33 lines · Sasha Levin
Quoted 25 lines · On Mon, Jul 13, 2020 at 06:00:59PM +0200, [email protected] wrote:

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

Quoted 1 line

From 66b7e05dc0239c5817859f261098ba9cc2efbd2b Mon Sep 17 00:00:00 2001

From: Steven Price <[email protected]>
Date: Wed, 17 Jun 2020 11:54:56 +0100
Subject: [PATCH] KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect with SVE

If SVE is enabled then 'ret' can be assigned the return value of kvm_vcpu_enable_sve() which may be 0 causing future "goto out" sites to erroneously return 0 on failure rather than -EINVAL as expected.

Remove the initialisation of 'ret' and make setting the return value explicit to avoid this situation in the future.

Quoted 6 lines
Fixes 9a3cdf26e336 ("KVM: arm64/sve: Allow userspace to enable SVE for vcpus")
Quoted 3 lines

I've worked around not having 540f76d12c66 ("arm64: cpufeature: Add CPU capability for AArch32 EL1 support") in 5.7 and 5.4 and queued this patch.

Thanks!