From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: [PATCH] KVM: Fix exiting from HLT emulation with MP_STATE_HALTED Date: Wed, 30 Jul 2008 21:55:19 +0800 Message-ID: <200807302155.19732.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_HLHkIchXMMll1DP" Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mga11.intel.com ([192.55.52.93]:44480 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753771AbYG3NxM (ORCPT ); Wed, 30 Jul 2008 09:53:12 -0400 Sender: kvm-owner@vger.kernel.org List-ID: --Boundary-00=_HLHkIchXMMll1DP Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =46rom 8019bdd0c7e2933a4d6f7e046d1cc2ded221784e Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Wed, 30 Jul 2008 21:45:58 +0800 Subject: [PATCH] KVM: Fix exiting from HLT emulation with=20 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=20 issues of this behaviour: =46irst, if vcpu exit to QEmu with MP_STATE_HALTED, it would keep in=20 this state later for vcpu_run(), which is eerie... Second, a practical problem: bios load AP boot up code to 0x10000, and=20 AP is running HLT there. But later grub load it's stage2 code to the=20 same address. Then if the halting vcpu was forced exit to QEmu in=20 grub, and come back for vcpu_run later, it can't execute HLT=20 instruction anymore, just because the bios code is not there, and it would follow a piece of code of grub, which would cause=20 completely chaos... The second issue directly lead to guest crash or SMP linux can't boot=20 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 =2D-- 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 =2D-- 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 =3D=3D KVM_MP_STATE_HALTED) { + r =3D kvm_emulate_halt(vcpu); + goto next_around; + } + preempt_disable(); kvm_x86_ops->prepare_guest_switch(vcpu); @@ -2962,6 +2967,7 @@ again: r =3D kvm_x86_ops->handle_exit(kvm_run, vcpu); +next_around: if (r > 0) { if (dm_request_for_irq_injection(vcpu, kvm_run)) { r =3D -EINTR; =2D- 1.5.4.5 --Boundary-00=_HLHkIchXMMll1DP Content-Type: text/x-diff; charset="utf-8"; name="0001-KVM-Fix-exiting-from-HLT-emulation-with-MP_STATE_HA.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-KVM-Fix-exiting-from-HLT-emulation-with-MP_STATE_HA.patch" =46rom 8019bdd0c7e2933a4d6f7e046d1cc2ded221784e Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang 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: =46irst, if vcpu exit to QEmu with MP_STATE_HALTED, it would keep in this s= tate 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= =2E 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 c= haos... 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 =2D-- 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 =2D-- 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); =20 + if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_HALTED) { + r =3D kvm_emulate_halt(vcpu); + goto next_around; + } + preempt_disable(); =20 kvm_x86_ops->prepare_guest_switch(vcpu); @@ -2962,6 +2967,7 @@ again: =20 r =3D kvm_x86_ops->handle_exit(kvm_run, vcpu); =20 +next_around: if (r > 0) { if (dm_request_for_irq_injection(vcpu, kvm_run)) { r =3D -EINTR; =2D-=20 1.5.4.5 --Boundary-00=_HLHkIchXMMll1DP--