From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mohammed Gamal Subject: Re: [PATCH 3/4] VMX: Add invalid guest state handler Date: Sun, 17 Aug 2008 16:47:05 +0300 Message-ID: <20080817134705.GA9214@mohd-laptop> References: <20080817134108.GC9077@mohd-laptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: avi@qumranet.com, riel@surriel.com, laurent.vivier@bull.net, guillaume.thouvenin@ext.bull.net To: kvm@vger.kernel.org Return-path: Received: from fk-out-0910.google.com ([209.85.128.185]:50821 "EHLO fk-out-0910.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751693AbYHQNrN (ORCPT ); Sun, 17 Aug 2008 09:47:13 -0400 Received: by fk-out-0910.google.com with SMTP id 18so1815906fkq.5 for ; Sun, 17 Aug 2008 06:47:11 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20080817134108.GC9077@mohd-laptop> Sender: kvm-owner@vger.kernel.org List-ID: [Adding missing sign-offs] This adds the invalid guest state handler function which invokes the x86 emulator until getting the guest to a VMX-friendly state. Signed-off-by: Laurent Vivier Signed-off-by: Guillaume Thouvenin Signed-off-by: Mohammed Gamal --- arch/x86/kvm/vmx.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index c4f1b4a..a09df80 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2892,6 +2892,37 @@ static int handle_nmi_window(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) return 1; } +static void handle_invalid_guest_state(struct kvm_vcpu *vcpu, + struct kvm_run *kvm_run) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + int err; + + while (!guest_state_valid(vcpu)) { + err = emulate_instruction(vcpu, kvm_run, 0, 0, 0); + + switch (err) { + case EMULATE_DONE: + break; + case EMULATE_DO_MMIO: + kvm_report_emulation_failure(vcpu, "mmio"); + /* TODO: Handle MMIO */ + return; + default: + kvm_report_emulation_failure(vcpu, "emulation failure"); + return; + } + + if (signal_pending(current)) + break; + if (need_resched()) + schedule(); + } + + /* Guest state should be valid now, no more emulation should be needed */ + vmx->emulation_required = 0; +} + /* * The exit handlers return 1 if the exit was handled fully and guest execution * may resume. Otherwise they set the kvm_run parameter to indicate what needs -- 1.5.4.3