From patchwork Fri Jun 11 02:25:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 105479 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5B2QIr7021169 for ; Fri, 11 Jun 2010 02:26:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754825Ab0FKC0P (ORCPT ); Thu, 10 Jun 2010 22:26:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14575 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754499Ab0FKC0O (ORCPT ); Thu, 10 Jun 2010 22:26:14 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5B2QEUe006644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 10 Jun 2010 22:26:14 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5B2QDlG010826 for ; Thu, 10 Jun 2010 22:26:13 -0400 Received: from amt.cnet (vpn-10-242.rdu.redhat.com [10.11.10.242]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o5B2QBDL003117 for ; Thu, 10 Jun 2010 22:26:13 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 9776368A900 for ; Thu, 10 Jun 2010 23:25:57 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o5B2PpA2023572 for kvm@vger.kernel.org; Thu, 10 Jun 2010 23:25:51 -0300 Date: Thu, 10 Jun 2010 23:25:51 -0300 From: Marcelo Tosatti To: kvm Subject: [PATCH RFC] KVM: busy-spin detector Message-ID: <20100611022551.GA16223@amt.cnet> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 11 Jun 2010 02:26:18 +0000 (UTC) Index: kvm/arch/x86/include/asm/kvm_host.h =================================================================== --- kvm.orig/arch/x86/include/asm/kvm_host.h +++ kvm/arch/x86/include/asm/kvm_host.h @@ -301,6 +301,8 @@ struct kvm_vcpu_arch { unsigned long mmu_seq; } update_pte; + unsigned long last_rip; + struct fpu guest_fpu; gva_t mmio_fault_cr2; @@ -653,6 +655,8 @@ void kvm_disable_tdp(void); int complete_pio(struct kvm_vcpu *vcpu); bool kvm_check_iopl(struct kvm_vcpu *vcpu); +void kvm_detect_spin(struct kvm_vcpu *vcpu); + struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn); static inline struct kvm_mmu_page *page_header(hpa_t shadow_page) Index: kvm/arch/x86/kvm/svm.c =================================================================== --- kvm.orig/arch/x86/kvm/svm.c +++ kvm/arch/x86/kvm/svm.c @@ -1558,8 +1558,10 @@ static int nmi_interception(struct vcpu_ static int intr_interception(struct vcpu_svm *svm) { + if (!svm_has(SVM_FEATURE_PAUSE_FILTER)) + kvm_detect_spin(&svm->vcpu); ++svm->vcpu.stat.irq_exits; - return 1; + return 2; } static int nop_on_interception(struct vcpu_svm *svm) Index: kvm/arch/x86/kvm/vmx.c =================================================================== --- kvm.orig/arch/x86/kvm/vmx.c +++ kvm/arch/x86/kvm/vmx.c @@ -3116,7 +3116,9 @@ static int handle_exception(struct kvm_v static int handle_external_interrupt(struct kvm_vcpu *vcpu) { ++vcpu->stat.irq_exits; - return 1; + if (!cpu_has_vmx_ple()) + kvm_detect_spin(vcpu); + return 2; } static int handle_triple_fault(struct kvm_vcpu *vcpu) Index: kvm/arch/x86/kvm/x86.c =================================================================== --- kvm.orig/arch/x86/kvm/x86.c +++ kvm/arch/x86/kvm/x86.c @@ -4523,6 +4523,17 @@ static void inject_pending_event(struct } } +void kvm_detect_spin(struct kvm_vcpu *vcpu) +{ + unsigned long rip = kvm_rip_read(vcpu); + + if (vcpu->arch.last_rip == rip) + kvm_vcpu_on_spin(vcpu); + + vcpu->arch.last_rip = rip; +} +EXPORT_SYMBOL_GPL(kvm_detect_spin); + static int vcpu_enter_guest(struct kvm_vcpu *vcpu) { int r; @@ -4654,6 +4665,8 @@ static int vcpu_enter_guest(struct kvm_v kvm_lapic_sync_from_vapic(vcpu); r = kvm_x86_ops->handle_exit(vcpu); + if (r == 1) + vcpu->arch.last_rip = ~(0UL); out: return r; }