From patchwork Mon Apr 26 17:58:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 50995 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 996BBB7D4C for ; Tue, 27 Apr 2010 04:26:40 +1000 (EST) Received: from localhost ([127.0.0.1]:42362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6SyT-0005Ax-EM for incoming@patchwork.ozlabs.org; Mon, 26 Apr 2010 14:24:05 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6Sbz-0006KM-Ur for qemu-devel@nongnu.org; Mon, 26 Apr 2010 14:00:52 -0400 Received: from [140.186.70.92] (port=49282 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6Sbt-00068O-5q for qemu-devel@nongnu.org; Mon, 26 Apr 2010 14:00:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6Sbl-0006yM-Od for qemu-devel@nongnu.org; Mon, 26 Apr 2010 14:00:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1808) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6Sbl-0006xu-0Z for qemu-devel@nongnu.org; Mon, 26 Apr 2010 14:00:37 -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 o3QI0ZYZ022032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Apr 2010 14:00:35 -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 o3QI0ZQ1017421; Mon, 26 Apr 2010 14:00:35 -0400 Received: from amt.cnet (vpn-8-113.rdu.redhat.com [10.11.8.113]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o3QI0XO2006758; Mon, 26 Apr 2010 14:00:33 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 9012C68A0C9; Mon, 26 Apr 2010 14:59:57 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o3QHxqwo023708; Mon, 26 Apr 2010 14:59:52 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Mon, 26 Apr 2010 14:58:57 -0300 Message-Id: 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: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 01/10] KVM: x86: Add debug register saving and restoring 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: Jan Kiszka Make use of the new KVM_GET/SET_DEBUGREGS to save/restore the x86 debug registers. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- kvm-all.c | 11 ++++++++++ kvm.h | 1 + target-i386/kvm.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 2ede4b9..d050115 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -64,6 +64,7 @@ struct KVMState int migration_log; int vcpu_events; int robust_singlestep; + int debugregs; #ifdef KVM_CAP_SET_GUEST_DEBUG struct kvm_sw_breakpoint_head kvm_sw_breakpoints; #endif @@ -664,6 +665,11 @@ int kvm_init(int smp_cpus) kvm_check_extension(s, KVM_CAP_X86_ROBUST_SINGLESTEP); #endif + s->debugregs = 0; +#ifdef KVM_CAP_DEBUGREGS + s->debugregs = kvm_check_extension(s, KVM_CAP_DEBUGREGS); +#endif + ret = kvm_arch_init(s, smp_cpus); if (ret < 0) goto err; @@ -939,6 +945,11 @@ int kvm_has_robust_singlestep(void) return kvm_state->robust_singlestep; } +int kvm_has_debugregs(void) +{ + return kvm_state->debugregs; +} + void kvm_setup_guest_memory(void *start, size_t size) { if (!kvm_has_sync_mmu()) { diff --git a/kvm.h b/kvm.h index ae87d85..70bfbf8 100644 --- a/kvm.h +++ b/kvm.h @@ -40,6 +40,7 @@ int kvm_init(int smp_cpus); int kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void); int kvm_has_robust_singlestep(void); +int kvm_has_debugregs(void); #ifdef NEED_CPU_H int kvm_init_vcpu(CPUState *env); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 5513472..bb6dafa 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -874,6 +874,53 @@ static int kvm_guest_debug_workarounds(CPUState *env) return ret; } +static int kvm_put_debugregs(CPUState *env) +{ +#ifdef KVM_CAP_DEBUGREGS + struct kvm_debugregs dbgregs; + int i; + + if (!kvm_has_debugregs()) { + return 0; + } + + for (i = 0; i < 4; i++) { + dbgregs.db[i] = env->dr[i]; + } + dbgregs.dr6 = env->dr[6]; + dbgregs.dr7 = env->dr[7]; + dbgregs.flags = 0; + + return kvm_vcpu_ioctl(env, KVM_SET_DEBUGREGS, &dbgregs); +#else + return 0; +#endif +} + +static int kvm_get_debugregs(CPUState *env) +{ +#ifdef KVM_CAP_DEBUGREGS + struct kvm_debugregs dbgregs; + int i, ret; + + if (!kvm_has_debugregs()) { + return 0; + } + + ret = kvm_vcpu_ioctl(env, KVM_GET_DEBUGREGS, &dbgregs); + if (ret < 0) { + return ret; + } + for (i = 0; i < 4; i++) { + env->dr[i] = dbgregs.db[i]; + } + env->dr[4] = env->dr[6] = dbgregs.dr6; + env->dr[5] = env->dr[7] = dbgregs.dr7; +#endif + + return 0; +} + int kvm_arch_put_registers(CPUState *env, int level) { int ret; @@ -909,6 +956,10 @@ int kvm_arch_put_registers(CPUState *env, int level) if (ret < 0) return ret; + ret = kvm_put_debugregs(env); + if (ret < 0) + return ret; + return 0; } @@ -940,6 +991,10 @@ int kvm_arch_get_registers(CPUState *env) if (ret < 0) return ret; + ret = kvm_get_debugregs(env); + if (ret < 0) + return ret; + return 0; }