From patchwork Wed Nov 11 19:29:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 59418 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 nABJjXoY004873 for ; Wed, 11 Nov 2009 19:45:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758657AbZKKTpY (ORCPT ); Wed, 11 Nov 2009 14:45:24 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758632AbZKKTpW (ORCPT ); Wed, 11 Nov 2009 14:45:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51901 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758572AbZKKTpS (ORCPT ); Wed, 11 Nov 2009 14:45:18 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjLYN017316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Nov 2009 14:45:21 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjKWk031021; Wed, 11 Nov 2009 14:45:21 -0500 Received: from amt.cnet (vpn-8-242.rdu.redhat.com [10.11.8.242]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjHkj014715; Wed, 11 Nov 2009 14:45:17 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7064E588054; Wed, 11 Nov 2009 17:39:47 -0200 (BRST) Received: (from root@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id nABJdkS0013224; Wed, 11 Nov 2009 17:39:46 -0200 Message-Id: <20091111193837.115825934@localhost.localdomain> References: <20091111192947.348198723@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Wed, 11 Nov 2009 17:29:48 -0200 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: gleb@redhat.com, jan.kiszka@siemens.com, joerg.roedel@amd.com, Jan Kiszka Subject: [patch 1/2] KVM: x86: handle double and triple faults for every exception Content-Disposition: inline; filename=handle-multiple-exceptions X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Index: kvm/arch/x86/kvm/x86.c =================================================================== --- kvm.orig/arch/x86/kvm/x86.c +++ kvm/arch/x86/kvm/x86.c @@ -170,9 +170,21 @@ void kvm_set_apic_base(struct kvm_vcpu * } EXPORT_SYMBOL_GPL(kvm_set_apic_base); +static void handle_multiple_faults(struct kvm_vcpu *vcpu) +{ + if (vcpu->arch.exception.nr != DF_VECTOR) { + vcpu->arch.exception.nr = DF_VECTOR; + vcpu->arch.exception.error_code = 0; + } else + set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); +} + void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr) { - WARN_ON(vcpu->arch.exception.pending); + if (vcpu->arch.exception.pending) { + handle_multiple_faults(vcpu); + return; + } vcpu->arch.exception.pending = true; vcpu->arch.exception.has_error_code = false; vcpu->arch.exception.nr = nr; @@ -184,24 +196,6 @@ void kvm_inject_page_fault(struct kvm_vc { ++vcpu->stat.pf_guest; - if (vcpu->arch.exception.pending) { - switch(vcpu->arch.exception.nr) { - case DF_VECTOR: - /* triple fault -> shutdown */ - set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); - return; - case PF_VECTOR: - vcpu->arch.exception.nr = DF_VECTOR; - vcpu->arch.exception.error_code = 0; - return; - default: - /* replace previous exception with a new one in a hope - that instruction re-execution will regenerate lost - exception */ - vcpu->arch.exception.pending = false; - break; - } - } vcpu->arch.cr2 = addr; kvm_queue_exception_e(vcpu, PF_VECTOR, error_code); } @@ -214,7 +208,10 @@ EXPORT_SYMBOL_GPL(kvm_inject_nmi); void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code) { - WARN_ON(vcpu->arch.exception.pending); + if (vcpu->arch.exception.pending) { + handle_multiple_faults(vcpu); + return; + } vcpu->arch.exception.pending = true; vcpu->arch.exception.has_error_code = true; vcpu->arch.exception.nr = nr;