From patchwork Wed May 12 21:25:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 52444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 70025B7E0A for ; Thu, 13 May 2010 14:55:25 +1000 (EST) Received: from localhost ([127.0.0.1]:57236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OCPl0-0001SY-54 for incoming@patchwork.ozlabs.org; Thu, 13 May 2010 00:10:46 -0400 Received: from [140.186.70.92] (port=42009 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OCP1q-00011x-Ij for qemu-devel@nongnu.org; Wed, 12 May 2010 23:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OCKYL-0003vi-B8 for qemu-devel@nongnu.org; Wed, 12 May 2010 18:37:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23630) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OCJSO-0000u8-GJ for qemu-devel@nongnu.org; Wed, 12 May 2010 17:27:09 -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 o4CLR6Q2011653 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 12 May 2010 17:27:06 -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 o4CLR5Ke025574; Wed, 12 May 2010 17:27:05 -0400 Received: from amt.cnet (vpn2-10-158.ams2.redhat.com [10.36.10.158]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o4CLR3DL021868; Wed, 12 May 2010 17:27:04 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 0883E656080; Wed, 12 May 2010 18:26:28 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o4CLQNb9028662; Wed, 12 May 2010 18:26:23 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Wed, 12 May 2010 18:25:05 -0300 Message-Id: <4513d9232badcc5039d69dae946054ba2682c258.1273699506.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gleb Natapov , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 11/12] Do not stop VM if emulation failed in userspace. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gleb Natapov Continue vcpu execution in case emulation failure happened while vcpu was in userspace. In this case #UD will be injected into the guest allowing guest OS to kill offending process and continue. Signed-off-by: Gleb Natapov Signed-off-by: Marcelo Tosatti --- kvm-all.c | 2 ++ kvm.h | 2 ++ target-i386/kvm.c | 7 +++++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 5 +++++ 5 files changed, 21 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index d06980c..c238f54 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -764,6 +764,8 @@ static void kvm_handle_internal_error(CPUState *env, struct kvm_run *run) cpu_dump_state(env, stderr, fprintf, 0); if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) { fprintf(stderr, "emulation failure\n"); + if (!kvm_arch_stop_on_emulation_error(env)) + return; } /* FIXME: Should trigger a qmp message to let management know * something went wrong. diff --git a/kvm.h b/kvm.h index 5071a31..a28e7aa 100644 --- a/kvm.h +++ b/kvm.h @@ -140,6 +140,8 @@ void kvm_arch_remove_all_hw_breakpoints(void); void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg); +bool kvm_arch_stop_on_emulation_error(CPUState *env); + int kvm_check_extension(KVMState *s, unsigned int extension); uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, diff --git a/target-i386/kvm.c b/target-i386/kvm.c index bd7a190..676aa60 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1289,3 +1289,10 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg) } } #endif /* KVM_CAP_SET_GUEST_DEBUG */ + +bool kvm_arch_stop_on_emulation_error(CPUState *env) +{ + return !(env->cr[0] & CR0_PE_MASK) || + ((env->segs[R_CS].selector & 3) != 3); +} + diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 91c0963..2625cb8 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -326,3 +326,8 @@ uint32_t kvmppc_get_tbfreq(void) retval = atoi(ns); return retval; } + +bool kvm_arch_stop_on_emulation_error(CPUState *env) +{ + return true; +} diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index a2c00ac..a2d7741 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -485,3 +485,8 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) return ret; } + +bool kvm_arch_stop_on_emulation_error(CPUState *env) +{ + return true; +}