From patchwork Tue Sep 1 01:15:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 44973 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 n811G0oX030445 for ; Tue, 1 Sep 2009 01:16:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752361AbZIABPz (ORCPT ); Mon, 31 Aug 2009 21:15:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752265AbZIABPz (ORCPT ); Mon, 31 Aug 2009 21:15:55 -0400 Received: from mail-fx0-f217.google.com ([209.85.220.217]:54452 "EHLO mail-fx0-f217.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751482AbZIABPz (ORCPT ); Mon, 31 Aug 2009 21:15:55 -0400 Received: by fxm17 with SMTP id 17so3177283fxm.37 for ; Mon, 31 Aug 2009 18:15:56 -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=WxBKW1nYSXw9P17PEuk1EK4Oq6DEKlZ26T0mmb5OMl0=; b=jb9feJ3g8u0KwO/4rScyXDnHzHosGnXQIOvwEgLkFT33f5jghBYDlM0I7sxaRLV+dx dBgCVgJwCfaSmuWmfNkCpSpfQimQ+WdlpQr6ICXPthwbHcjLux/NHMdi0/8aKYDwnc4O FrdRuoPvOfMpju3MxtvrlfOX0tLN2yPMs+O7U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=WTeCPE0xcq5x3U/MJOwK1B/HtuWOV0sjp9eGaDO6RhLeMKBMnLt/yVhU2geSaHN8tV LS/jqRUynNIdX7nmyhCl0+RkTLKLdrOXdQoLu9DXEFihpfK5yAk+vYaG8vv1w/JMeRC3 nk/PgJjhEL9WgDmbn9Io1+LVUbpNKkNdevc3k= Received: by 10.102.236.11 with SMTP id j11mr2528755muh.3.1251767756328; Mon, 31 Aug 2009 18:15:56 -0700 (PDT) Received: from localhost ([41.238.115.147]) by mx.google.com with ESMTPS id y37sm2484067mug.51.2009.08.31.18.15.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 31 Aug 2009 18:15:55 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: kvm@vger.kernel.org, mtosatti@redhat.com, Mohammed Gamal Subject: [PATCH v2] VMX: Enhance invalid guest state emulation Date: Tue, 1 Sep 2009 03:15:53 +0200 Message-Id: <1251767753-26881-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 | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 78101dd..34bfd87 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -107,7 +107,6 @@ struct vcpu_vmx { } rmode; int vpid; bool emulation_required; - enum emulation_result invalid_state_emulation_result; /* Support for vnmi-less CPUs */ int soft_vnmi_blocked; @@ -3318,22 +3317,24 @@ 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; - - local_irq_enable(); - preempt_enable(); + int ret = 1; 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; } @@ -3343,10 +3344,7 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu) schedule(); } - preempt_disable(); - local_irq_disable(); - - vmx->invalid_state_emulation_result = err; + return ret; } /* @@ -3405,9 +3403,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)) { + return handle_invalid_guest_state(vcpu); + } else { vmx->emulation_required = 0; - return vmx->invalid_state_emulation_result != EMULATE_DO_MMIO; + return 1; + } } /* Access CR3 don't cause VMExit in paging mode, so we need @@ -3604,10 +3605,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) 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); + if (vmx->emulation_required && emulate_invalid_guest_state) return; - } if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty)) vmcs_writel(GUEST_RSP, vcpu->arch.regs[VCPU_REGS_RSP]);