* [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index
@ 2023-06-22 16:09 Oliver Upton
2023-06-22 16:14 ` Marc Zyngier
2023-06-22 17:17 ` Oliver Upton
0 siblings, 2 replies; 3+ messages in thread
From: Oliver Upton @ 2023-06-22 16:09 UTC (permalink / raw)
To: kvmarm
Cc: Marc Zyngier, James Morse, Suzuki K Poulose, Zenghui Yu,
Oliver Upton, Dan Carpenter
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.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: e3c1c0cae31e ("KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF")
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
arch/arm64/kvm/arm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 80ca7ec269dc..7d20bfd77e1c 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -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
--
2.41.0.185.g7c58973941-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index
2023-06-22 16:09 [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index Oliver Upton
@ 2023-06-22 16:14 ` Marc Zyngier
2023-06-22 17:17 ` Oliver Upton
1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2023-06-22 16:14 UTC (permalink / raw)
To: Oliver Upton
Cc: kvmarm, James Morse, Suzuki K Poulose, Zenghui Yu, Dan Carpenter
On 2023-06-22 17:09, Oliver Upton wrote:
> 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.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: e3c1c0cae31e ("KVM: arm64: Relax invariance of
> KVM_ARM_VCPU_POWER_OFF")
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> arch/arm64/kvm/arm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 80ca7ec269dc..7d20bfd77e1c 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -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;
> }
Huhuh. Maybe use BIT() instead? Otherwise:
Acked-by: Marc Zyngier <maz@kernel.org>
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index
2023-06-22 16:09 [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index Oliver Upton
2023-06-22 16:14 ` Marc Zyngier
@ 2023-06-22 17:17 ` Oliver Upton
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Upton @ 2023-06-22 17:17 UTC (permalink / raw)
To: Oliver Upton, kvmarm
Cc: Dan Carpenter, Zenghui Yu, Suzuki K Poulose, James Morse,
Marc Zyngier
On Thu, 22 Jun 2023 16:09:22 +0000, Oliver Upton wrote:
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-22 17:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-22 16:09 [PATCH] KVM: arm64: Fix misuse of KVM_ARM_VCPU_POWER_OFF bit index Oliver Upton
2023-06-22 16:14 ` Marc Zyngier
2023-06-22 17:17 ` Oliver Upton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox