Skip to contentSkip to conversation

KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index

PATCH Applied Oliver Upton 2 participants 3 messages Jun 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index

KVM_ARM_VCPU_POWER_OFF is as bit index, _not_ a literal bitmask. Nonetheless, commit e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF") started using it that way, meaning that powering off a vCPU with the KVM_ARM_VCPU_INIT ioctl is completely broken.

Fix it by using a shifted bit for the bitwise operations instead.

Fixes e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF")
---
 arch/arm64/kvm/arm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/arm.c +2 -2
index 80ca7ec269dc..7d20bfd77e1c 100644
@@ -1250,8 +1250,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
 	 * reflecting it in the finalized feature set, thus limiting its scope
 	 * to a single KVM_ARM_VCPU_INIT call.
 	 */
-	if (init->features[0] & KVM_ARM_VCPU_POWER_OFF) {
-		init->features[0] &= ~KVM_ARM_VCPU_POWER_OFF;
+	if (init->features[0] & (1UL << KVM_ARM_VCPU_POWER_OFF)) {
+		init->features[0] &= ~(1UL << KVM_ARM_VCPU_POWER_OFF);
 		power_off = true;
 	}
 

base-commit: 686672407e6eaf8c874d4a6bf315da798f281045

Signature · 1 line
2.41.0.185.g7c58973941-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Oliver Upton

KVM_ARM_VCPU_POWER_OFF is as bit index, _not_ a literal bitmask. Nonetheless, commit e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF") started using it that way, meaning that powering off a vCPU with the KVM_ARM_VCPU_INIT ioctl is completely broken.

Fix it by using a shifted bit for the bitwise operations instead.

Fixes e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF")
---
 arch/arm64/kvm/arm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/arm.c +0 -0
index 80ca7ec269dc..7d20bfd77e1c 100644
@@ -1250,8 +1250,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct
 kvm_vcpu *vcpu,
 	 * reflecting it in the finalized feature set, thus limiting its 

scope

arch/arm64/kvm/arm.c static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, · line 1256

Quoted 8 lines
arch/arm64/kvm/arm.c +2 -2
 	 * to a single KVM_ARM_VCPU_INIT call.
 	 */
-	if (init->features[0] & KVM_ARM_VCPU_POWER_OFF) {
-		init->features[0] &= ~KVM_ARM_VCPU_POWER_OFF;
+	if (init->features[0] & (1UL << KVM_ARM_VCPU_POWER_OFF)) {
+		init->features[0] &= ~(1UL << KVM_ARM_VCPU_POWER_OFF);
 		power_off = true;
 	}

Huhuh. Maybe use BIT() instead? Otherwise:

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
author Applied
#2 lore raw
In reply to Oliver Upton
Quoted 9 lines · Oliver Upton

KVM_ARM_VCPU_POWER_OFF is as bit index, _not_ a literal bitmask. Nonetheless, commit e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF") started using it that way, meaning that powering off a vCPU with the KVM_ARM_VCPU_INIT ioctl is completely broken.

Fix it by using a shifted bit for the bitwise operations instead.

[...]

Applied, w/ Marc's suggestion to just use BIT() instead.

[1/1] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index

      https://git.kernel.org/kvmarm/kvmarm/c/192df2aa0113

--
Best,
Oliver