From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH 3/3] KVM: SVM: Short circuit STI; HLT while an interrupt is pending Date: Mon, 14 Feb 2011 16:42:17 +0200 Message-ID: <1297694537-9268-4-git-send-email-avi@redhat.com> References: <1297694537-9268-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:36856 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755535Ab1BNOme (ORCPT ); Mon, 14 Feb 2011 09:42:34 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1EEgY89011614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Feb 2011 09:42:34 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1EEgWhR002951 for ; Mon, 14 Feb 2011 09:42:33 -0500 In-Reply-To: <1297694537-9268-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Short-circuit an STI; HLT sequence while an interrupt is pending: instead of halting, re-entering the guest, and exiting immediately on an interrupt window exit, go directly to the last step. Saves a vmexit on workloads where interrupts are received synchronously; an example is a disk backed by the host page cache where there is no latency (from the guest's point of view) between the request and fulfilment. Signed-off-by: Avi Kivity --- arch/x86/kvm/svm.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 53c5d8a..b70af8b 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -184,6 +184,7 @@ module_param(nested, int, S_IRUGO); static void svm_flush_tlb(struct kvm_vcpu *vcpu); static void svm_complete_interrupts(struct vcpu_svm *svm); +static int interrupt_window_interception(struct vcpu_svm *svm); static int nested_svm_exit_handled(struct vcpu_svm *svm); static int nested_svm_intercept(struct vcpu_svm *svm); @@ -1745,6 +1746,14 @@ static int halt_interception(struct vcpu_svm *svm) { svm->next_rip = kvm_rip_read(&svm->vcpu) + 1; skip_emulated_instruction(&svm->vcpu); + /* + * Short-circuit an STI; HLT sequence while an interrupt is pending: + * instead of halting, re-entering the guest, and exiting immediately + * on an interrupt window exit, go directly to the last step. + */ + if ((svm->vmcb->control.intercept & (1ULL << INTERCEPT_VINTR)) + && (kvm_get_rflags(&svm->vcpu) & X86_EFLAGS_IF)) + return interrupt_window_interception(svm); return kvm_emulate_halt(&svm->vcpu); } -- 1.7.1