Skip to content

Commit e3c1c0c

Browse files
committed
KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF
Allow the value of KVM_ARM_VCPU_POWER_OFF to differ between calls to KVM_ARM_VCPU_INIT. Userspace can already change the state of the vCPU through the KVM_SET_MP_STATE ioctl, so making the bit invariant seems needlessly restrictive. Link: https://lore.kernel.org/r/20230609190054.1542113-3-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent a7a2c72 commit e3c1c0c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

arch/arm64/kvm/arm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,19 @@ static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
12361236
static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
12371237
struct kvm_vcpu_init *init)
12381238
{
1239+
bool power_off = false;
12391240
int ret;
12401241

1242+
/*
1243+
* Treat the power-off vCPU feature as ephemeral. Clear the bit to avoid
1244+
* reflecting it in the finalized feature set, thus limiting its scope
1245+
* to a single KVM_ARM_VCPU_INIT call.
1246+
*/
1247+
if (init->features[0] & KVM_ARM_VCPU_POWER_OFF) {
1248+
init->features[0] &= ~KVM_ARM_VCPU_POWER_OFF;
1249+
power_off = true;
1250+
}
1251+
12411252
ret = kvm_vcpu_set_target(vcpu, init);
12421253
if (ret)
12431254
return ret;
@@ -1266,7 +1277,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
12661277
*/
12671278
spin_lock(&vcpu->arch.mp_state_lock);
12681279

1269-
if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
1280+
if (power_off)
12701281
__kvm_arm_vcpu_power_off(vcpu);
12711282
else
12721283
WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);

0 commit comments

Comments
 (0)