From: "Yang, Sheng" <sheng.yang@intel.com>
To: kvm@vger.kernel.org
Cc: Avi Kivity <avi@qumranet.com>
Subject: [PATCH] KVM: Fix QEmu interrupted HLT emulation
Date: Thu, 31 Jul 2008 13:52:10 +0800 [thread overview]
Message-ID: <200807311352.10657.sheng.yang@intel.com> (raw)
In-Reply-To: <200807311247.21350.sheng.yang@intel.com>
[-- Attachment #1: Type: text/plain, Size: 2262 bytes --]
From: Sheng Yang <sheng.yang@intel.com>
Date: Thu, 31 Jul 2008 13:43:58 +0800
Subject: [PATCH] KVM: Fix QEmu interrupted HLT emulation
QEmu can interrupt VCPU from HLT emulation without setting mp_state to
MP_STATE_RUNNABLE, when it 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
(now), 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. Though I also sent a
patch for BIOS, it's necessary to get correct behavior here.
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 | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 94a2165..8219074 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2881,6 +2881,19 @@ again:
clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
kvm_inject_pending_timer_irqs(vcpu);
+ /*
+ * If HLT emulating was interrupted by QEmu, we'd better resume it.
+ * And if QEmu don't interrupt it again, set correct state rather
than
+ * keeping running with STATE_HALTED
+ */
+ if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) {
+ r = kvm_emulate_halt(vcpu);
+ if (!signal_pending(current) &&
+ !kvm_arch_vcpu_runnable(vcpu))
+ vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+ goto next_round;
+ }
+
preempt_disable();
kvm_x86_ops->prepare_guest_switch(vcpu);
@@ -2962,6 +2975,7 @@ again:
r = kvm_x86_ops->handle_exit(kvm_run, vcpu);
+next_round:
if (r > 0) {
if (dm_request_for_irq_injection(vcpu, kvm_run)) {
r = -EINTR;
--
1.5.4.5
[-- Attachment #2: 0001-KVM-Fix-QEmu-interrupted-HLT-emulation.patch --]
[-- Type: text/x-diff, Size: 2391 bytes --]
From ea0a1f70d44590929c9d618ee4bef8af1553b442 Mon Sep 17 00:00:00 2001
From: Sheng Yang <sheng.yang@intel.com>
Date: Thu, 31 Jul 2008 13:43:58 +0800
Subject: [PATCH] KVM: Fix QEmu interrupted HLT emulation
QEmu can interrupt VCPU from HLT emulation without setting mp_state to
MP_STATE_RUNNABLE, when it 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 (now), 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. Though I also sent a patch for BIOS,
it's necessary to get correct behavior here.
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 | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 94a2165..8219074 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2881,6 +2881,19 @@ again:
clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
kvm_inject_pending_timer_irqs(vcpu);
+ /*
+ * If HLT emulating was interrupted by QEmu, we'd better resume it.
+ * And if QEmu don't interrupt it again, set correct state rather than
+ * keeping running with STATE_HALTED
+ */
+ if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) {
+ r = kvm_emulate_halt(vcpu);
+ if (!signal_pending(current) &&
+ !kvm_arch_vcpu_runnable(vcpu))
+ vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+ goto next_round;
+ }
+
preempt_disable();
kvm_x86_ops->prepare_guest_switch(vcpu);
@@ -2962,6 +2975,7 @@ again:
r = kvm_x86_ops->handle_exit(kvm_run, vcpu);
+next_round:
if (r > 0) {
if (dm_request_for_irq_injection(vcpu, kvm_run)) {
r = -EINTR;
--
1.5.4.5
next prev parent reply other threads:[~2008-07-31 5:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Yang, Sheng [this message]
2008-09-11 8:50 ` [PATCH] KVM: Fix QEmu interrupted HLT emulation Avi Kivity
2008-09-11 8:54 ` Yang, Sheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200807311352.10657.sheng.yang@intel.com \
--to=sheng.yang@intel.com \
--cc=avi@qumranet.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.