From patchwork Fri Aug 28 14:49:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 44517 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7SEnVFl020117 for ; Fri, 28 Aug 2009 14:49:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751877AbZH1Ot1 (ORCPT ); Fri, 28 Aug 2009 10:49:27 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751864AbZH1Ot1 (ORCPT ); Fri, 28 Aug 2009 10:49:27 -0400 Received: from mail-bw0-f219.google.com ([209.85.218.219]:52408 "EHLO mail-bw0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751858AbZH1Ot0 (ORCPT ); Fri, 28 Aug 2009 10:49:26 -0400 Received: by bwz19 with SMTP id 19so1651238bwz.37 for ; Fri, 28 Aug 2009 07:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=pdZeDoFp0rEu3UW8yDkGDV7xbofxPuSsZ5+lwJHgf/4=; b=UpWJi8uMuvyFP6VVhW8Pc5yDJ5PpmBAsupAfO5CTb320NoN6rknL08J0k0qQiDHjLe Ku/5pZEso3QGlIMKmKKDvD4+qiMZFCaeIYIMR4klRcfWyoykOrVhabSHP9mMfjCcsBg5 HLoxoeNeOqdLE66dRdD+2SMihJdHfcoPRdfoE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=h6NraEdg9m9xm+TLpUIs6EKMfdBJ6PrZCrHuCQSMS5BwlJpyR8Hdu8i/RuSWuqjSr4 HDXM767xvQNK3EpEST+c9woOeBGpVipCDMQLx25D7t1NQdmtBoKCkYUvLc7ia6B4JJ7q dsN6nV8nEX0gkCCPuCDHuTveQkscaq1YMU8KE= Received: by 10.103.125.28 with SMTP id c28mr334925mun.64.1251470967290; Fri, 28 Aug 2009 07:49:27 -0700 (PDT) Received: from localhost ([41.237.159.104]) by mx.google.com with ESMTPS id y6sm6223279mug.10.2009.08.28.07.49.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 28 Aug 2009 07:49:26 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH 3/3] VMX: Enhance invalid guest state emulation Date: Fri, 28 Aug 2009 16:49:23 +0200 Message-Id: <1251470963-14542-1-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.6.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org - Change returned handle_invalid_guest_state() to return relevant exit codes - Move triggering the emulation from vmx_vcpu_run() to vmx_handle_exit() - Return to userspace instead of repeatedly trying to emulate instructions that have already failed Signed-off-by: Mohammed Gamal --- arch/x86/kvm/vmx.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 78101dd..e422470 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3318,10 +3318,11 @@ static int handle_nmi_window(struct kvm_vcpu *vcpu) return 1; } -static void handle_invalid_guest_state(struct kvm_vcpu *vcpu) +static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); enum emulation_result err = EMULATE_DONE; + int ret = 1; local_irq_enable(); preempt_enable(); @@ -3329,11 +3330,16 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu) while (!guest_state_valid(vcpu)) { err = emulate_instruction(vcpu, 0, 0, 0); - if (err == EMULATE_DO_MMIO) + if (err == EMULATE_DO_MMIO) { + ret = 0; break; + } if (err != EMULATE_DONE) { kvm_report_emulation_failure(vcpu, "emulation failure"); + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; + ret = 0; break; } @@ -3347,6 +3353,7 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu) local_irq_disable(); vmx->invalid_state_emulation_result = err; + return ret; } /* @@ -3405,9 +3412,12 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) /* If we need to emulate an MMIO from handle_invalid_guest_state * we just return 0 */ if (vmx->emulation_required && emulate_invalid_guest_state) { - if (guest_state_valid(vcpu)) + if (guest_state_valid(vcpu)) { vmx->emulation_required = 0; - return vmx->invalid_state_emulation_result != EMULATE_DO_MMIO; + return vmx->invalid_state_emulation_result != EMULATE_DO_MMIO; + } else { + return handle_invalid_guest_state(vcpu); + } } /* Access CR3 don't cause VMExit in paging mode, so we need @@ -3603,12 +3613,6 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) vmx->entry_time = ktime_get(); - /* Handle invalid guest state instead of entering VMX */ - if (vmx->emulation_required && emulate_invalid_guest_state) { - handle_invalid_guest_state(vcpu); - return; - } - if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty)) vmcs_writel(GUEST_RSP, vcpu->arch.regs[VCPU_REGS_RSP]); if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))