Commit 2b8250ae authored by Jan Kiszka's avatar Jan Kiszka

x86/ipipe: kvm: Only put vcpu if it is active

We may leave kvm_arch_vcpu_put with the ipipe notifier still registered
in case shared MSRs are still active. If a VM preemption will hit us
after that point but before the user return notifier fired, we may run
kvm_arch_vcpu_put again from __ipipe_handle_vm_preemption. Do not rely
on this being harmless and rather use a flag to decide if the run is
Signed-off-by: Jan Kiszka's avatarJan Kiszka <>
parent 22b8cb0d
...@@ -2787,8 +2787,11 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) ...@@ -2787,8 +2787,11 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
*/ */
set_debugreg(0, 6); set_debugreg(0, 6);
vcpu->ipipe_put_vcpu = false;
if (!smsr->dirty) if (!smsr->dirty)
__ipipe_exit_vm(); __ipipe_exit_vm();
hard_cond_local_irq_restore(flags); hard_cond_local_irq_restore(flags);
} }
...@@ -2802,7 +2805,8 @@ void __ipipe_handle_vm_preemption(struct ipipe_vm_notifier *nfy) ...@@ -2802,7 +2805,8 @@ void __ipipe_handle_vm_preemption(struct ipipe_vm_notifier *nfy)
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
vcpu = container_of(nfy, struct kvm_vcpu, ipipe_notifier); vcpu = container_of(nfy, struct kvm_vcpu, ipipe_notifier);
kvm_arch_vcpu_put(vcpu); if (vcpu->ipipe_put_vcpu)
kvm_restore_shared_msrs(smsr); kvm_restore_shared_msrs(smsr);
__ipipe_exit_vm(); __ipipe_exit_vm();
} }
...@@ -6621,7 +6625,10 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) ...@@ -6621,7 +6625,10 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
local_irq_disable(); local_irq_disable();
hard_cond_local_irq_disable(); hard_cond_local_irq_disable();
__ipipe_enter_vm(&vcpu->ipipe_notifier); __ipipe_enter_vm(&vcpu->ipipe_notifier);
vcpu->ipipe_put_vcpu = true;
kvm_x86_ops->prepare_guest_switch(vcpu); kvm_x86_ops->prepare_guest_switch(vcpu);
if (vcpu->fpu_active) if (vcpu->fpu_active)
...@@ -229,6 +229,7 @@ struct kvm_vcpu { ...@@ -229,6 +229,7 @@ struct kvm_vcpu {
#endif #endif
struct ipipe_vm_notifier ipipe_notifier; struct ipipe_vm_notifier ipipe_notifier;
bool ipipe_put_vcpu;
#endif #endif
int cpu; int cpu;
int vcpu_id; int vcpu_id;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment