All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Fix exiting from HLT emulation with MP_STATE_HALTED
@ 2008-07-30 13:55 Yang, Sheng
  2008-07-31  4:47 ` Yang, Sheng
  0 siblings, 1 reply; 5+ messages in thread
From: Yang, Sheng @ 2008-07-30 13:55 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

From 8019bdd0c7e2933a4d6f7e046d1cc2ded221784e Mon Sep 17 00:00:00 2001
From: Sheng Yang <sheng.yang@intel.com>
Date: Wed, 30 Jul 2008 21:45:58 +0800
Subject: [PATCH] KVM: Fix exiting from HLT emulation with 
MP_STATE_HALTED

VCPU can be forced exit from HLT emulation without setting mp_state to
MP_STATE_RUNNABLE, it's due to QEmu can kick vcpus which are doing HLT
emulation to do something like "stop" or "info cpus". Here are two 
issues of this behaviour:

First, if vcpu exit to QEmu with MP_STATE_HALTED, it would keep in 
this state later for vcpu_run(), which is eerie...

Second, a practical problem: bios load AP boot up code to 0x10000, and 
AP is running HLT there. But later grub load it's stage2 code to the 
same address. Then if the halting vcpu was forced exit to QEmu in 
grub, and come back for vcpu_run later, it can't execute HLT 
instruction anymore, just because the bios code is not there,
and it would follow a piece of code of grub, which would cause 
completely chaos...

The second issue directly lead to guest crash or SMP linux can't boot 
up AP later if we "stop" or "info cpus" in grub.

The patch resumes the HLT emulation after interrupt by QEmu to fix it.

Signed-off-by: Sheng Yang <sheng.yang@intel.com>
---
 arch/x86/kvm/x86.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 94a2165..3b31959 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2881,6 +2881,11 @@ again:
 	clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
 	kvm_inject_pending_timer_irqs(vcpu);

+	if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) {
+		r = kvm_emulate_halt(vcpu);
+		goto next_around;
+	}
+
 	preempt_disable();

 	kvm_x86_ops->prepare_guest_switch(vcpu);
@@ -2962,6 +2967,7 @@ again:

 	r = kvm_x86_ops->handle_exit(kvm_run, vcpu);

+next_around:
 	if (r > 0) {
 		if (dm_request_for_irq_injection(vcpu, kvm_run)) {
 			r = -EINTR;
--
1.5.4.5


[-- Attachment #2: 0001-KVM-Fix-exiting-from-HLT-emulation-with-MP_STATE_HA.patch --]
[-- Type: text/x-diff, Size: 2003 bytes --]

From 8019bdd0c7e2933a4d6f7e046d1cc2ded221784e Mon Sep 17 00:00:00 2001
From: Sheng Yang <sheng.yang@intel.com>
Date: Wed, 30 Jul 2008 21:45:58 +0800
Subject: [PATCH] KVM: Fix exiting from HLT emulation with MP_STATE_HALTED

VCPU can be forced exit from HLT emulation without setting mp_state to
MP_STATE_RUNNABLE, it's due to QEmu can kick vcpus which are doing HLT
emulation to do something like "stop" or "info cpus". Here are two issues of
this behaviour:

First, if vcpu exit to QEmu with MP_STATE_HALTED, it would keep in this state
later for vcpu_run(), which is eerie...

Second, a practical problem: bios load AP boot up code to 0x10000, and AP is
running HLT there. But later grub load it's stage2 code to the same address. Then
if the halting vcpu was forced exit to QEmu in grub, and come back for vcpu_run later,
it can't execute HLT instruction anymore, just because the bios code is not there,
and it would follow a piece of code of grub, which would cause completely chaos...

The second issue directly lead to guest crash or SMP linux can't boot up AP
later if we "stop" or "info cpus" in grub.

The patch resumes the HLT emulation after interrupt by QEmu to fix it.

Signed-off-by: Sheng Yang <sheng.yang@intel.com>
---
 arch/x86/kvm/x86.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 94a2165..3b31959 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2881,6 +2881,11 @@ again:
 	clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
 	kvm_inject_pending_timer_irqs(vcpu);
 
+	if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) {
+		r = kvm_emulate_halt(vcpu);
+		goto next_around;
+	}
+
 	preempt_disable();
 
 	kvm_x86_ops->prepare_guest_switch(vcpu);
@@ -2962,6 +2967,7 @@ again:
 
 	r = kvm_x86_ops->handle_exit(kvm_run, vcpu);
 
+next_around:
 	if (r > 0) {
 		if (dm_request_for_irq_injection(vcpu, kvm_run)) {
 			r = -EINTR;
-- 
1.5.4.5


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

end of thread, other threads:[~2008-09-11  8:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-30 13:55 [PATCH] KVM: Fix exiting from HLT emulation with MP_STATE_HALTED Yang, Sheng
2008-07-31  4:47 ` Yang, Sheng
2008-07-31  5:52   ` [PATCH] KVM: Fix QEmu interrupted HLT emulation Yang, Sheng
2008-09-11  8:50     ` Avi Kivity
2008-09-11  8:54       ` Yang, Sheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.