KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index
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.
--- arch/arm64/kvm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/arm.c +2 -2
@@ -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
Quoted 23 lines · Oliver Upton
KVM_ARM_VCPU_POWER_OFFis as bit index, _not_ a literal bitmask. Nonetheless, commite3c1c0cae31e("KVM: arm64: Relax invariance ofKVM_ARM_VCPU_POWER_OFF") started using it that way, meaning that powering off a vCPU with theKVM_ARM_VCPU_INITioctl is completely broken.Fix it by using a shifted bit for the bitwise operations instead.
Reported-by Dan Carpenter <[email protected]>Fixes e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF")Signed-off-by Oliver Upton <[email protected]>--- arch/arm64/kvm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm64/kvm/arm.c +0
-0@@ -1250,8 +1250,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(structkvm_vcpu *vcpu, * reflecting it in the finalized feature set, thus limiting itsscope
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...
Oliver Upton
AppliedQuoted 9 lines · Oliver Upton
KVM_ARM_VCPU_POWER_OFFis as bit index, _not_ a literal bitmask. Nonetheless, commite3c1c0cae31e("KVM: arm64: Relax invariance ofKVM_ARM_VCPU_POWER_OFF") started using it that way, meaning that powering off a vCPU with theKVM_ARM_VCPU_INITioctl 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