public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* KVM: x86: do not execute guest code if vcpu not runnable
@ 2008-07-19 18:11 Marcelo Tosatti
  2008-07-19 23:41 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Marcelo Tosatti @ 2008-07-19 18:11 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel


If a vcpu has been offlined, or not initialized at all, signals
requesting userspace work to be performed will result in KVM attempting
to re-entry guest mode.

Problem is that the in-kernel irqchip emulation happily executes HALTED
state vcpu's. This breaks "savevm" on Windows SMP installation, for
example.

Also, setting the mpstate to runnable when setting an IRQ via
pic_irq_request / kvm_apic_set_irq is necessary due to this check on
emulate_halt:

                kvm_vcpu_block(vcpu);
                down_read(&vcpu->kvm->slots_lock);
                if (vcpu->arch.mp_state != KVM_MP_STATE_RUNNABLE)
                        return -EINTR;

Otherwise the vcpu will return to userspace needlessly.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index c31164e..44075fa 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -424,8 +424,10 @@ static void pic_irq_request(void *opaque, int level)
 	struct kvm_vcpu *vcpu = kvm->vcpus[0];
 
 	pic_irqchip(kvm)->output = level;
-	if (vcpu)
+	if (vcpu) {
+		vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
 		kvm_vcpu_kick(vcpu);
+	}
 }
 
 struct kvm_pic *kvm_create_pic(struct kvm *kvm)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 9fde0ac..d81976c 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -195,6 +195,7 @@ int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig)
 			apic_set_vector(vec, apic->regs + APIC_TMR);
 		else
 			apic_clear_vector(vec, apic->regs + APIC_TMR);
+		vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
 		kvm_vcpu_kick(apic->vcpu);
 		return 1;
 	}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 07d7ca9..7befd6c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2976,10 +2976,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	if (vcpu->sigset_active)
 		sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
 
-	if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_UNINITIALIZED)) {
+	if (unlikely(!kvm_arch_vcpu_runnable(vcpu))) {
 		kvm_vcpu_block(vcpu);
-		r = -EAGAIN;
-		goto out;
+		if (!kvm_arch_vcpu_runnable(vcpu)) {
+			r = -EAGAIN;
+			goto out;
+		}
 	}
 
 	/* re-sync apic's tpr */

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: KVM: x86: do not execute guest code if vcpu not runnable
  2008-07-19 18:11 KVM: x86: do not execute guest code if vcpu not runnable Marcelo Tosatti
@ 2008-07-19 23:41 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2008-07-19 23:41 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel

On Sat, Jul 19, 2008 at 03:11:44PM -0300, Marcelo Tosatti wrote:
> 
> If a vcpu has been offlined, or not initialized at all, signals
> requesting userspace work to be performed will result in KVM attempting
> to re-entry guest mode.
> 
> Problem is that the in-kernel irqchip emulation happily executes HALTED
> state vcpu's. This breaks "savevm" on Windows SMP installation, for
> example.
> 
> Also, setting the mpstate to runnable when setting an IRQ via
> pic_irq_request / kvm_apic_set_irq is necessary due to this check on
> emulate_halt:
> 
>                 kvm_vcpu_block(vcpu);
>                 down_read(&vcpu->kvm->slots_lock);
>                 if (vcpu->arch.mp_state != KVM_MP_STATE_RUNNABLE)
>                         return -EINTR;
> 
> Otherwise the vcpu will return to userspace needlessly.

Scratch this, burns 100% CPU.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-19 23:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-19 18:11 KVM: x86: do not execute guest code if vcpu not runnable Marcelo Tosatti
2008-07-19 23:41 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox