From patchwork Wed Feb 3 21:29:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 44424 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 117AEB7D33 for ; Thu, 4 Feb 2010 08:35:39 +1100 (EST) Received: from localhost ([127.0.0.1]:47290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ncmq1-0004on-NI for incoming@patchwork.ozlabs.org; Wed, 03 Feb 2010 16:32:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NcmnL-00044v-Hi for qemu-devel@nongnu.org; Wed, 03 Feb 2010 16:29:55 -0500 Received: from [199.232.76.173] (port=37645 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcmnK-00044d-Df for qemu-devel@nongnu.org; Wed, 03 Feb 2010 16:29:54 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NcmnH-00032z-A9 for qemu-devel@nongnu.org; Wed, 03 Feb 2010 16:29:54 -0500 Received: from david.siemens.de ([192.35.17.14]:24162) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NcmnG-000326-FG for qemu-devel@nongnu.org; Wed, 03 Feb 2010 16:29:51 -0500 Received: from mail2.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id o13LTluC004821; Wed, 3 Feb 2010 22:29:47 +0100 Received: from localhost.localdomain ([139.25.173.3]) by mail2.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id o13LTjGw031176; Wed, 3 Feb 2010 22:29:47 +0100 From: Jan Kiszka To: Anthony Liguori Date: Wed, 3 Feb 2010 22:29:45 +0100 Message-Id: <372238c800e0d57815f472502fdf78e53463bbb6.1265232579.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Avi Kivity Subject: [Qemu-devel] [PATCH 4/4] KVM: Rework of guest debug state writing 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 So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code. Signed-off-by: Jan Kiszka --- kvm-all.c | 12 ++++-------- target-i386/cpu.h | 9 ++++++++- target-i386/kvm.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 67b44b5..f3e09c8 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -938,10 +938,6 @@ static void kvm_invoke_set_guest_debug(void *data) struct kvm_set_guest_debug_data *dbg_data = data; CPUState *env = dbg_data->env; - if (env->kvm_vcpu_dirty) { - kvm_arch_put_registers(env); - env->kvm_vcpu_dirty = 0; - } dbg_data->err = kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &dbg_data->dbg); } @@ -949,12 +945,12 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) { struct kvm_set_guest_debug_data data; - data.dbg.control = 0; - if (env->singlestep_enabled) - data.dbg.control = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP; + data.dbg.control = reinject_trap; + if (env->singlestep_enabled) { + data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP; + } kvm_arch_update_guest_debug(env, &data.dbg); - data.dbg.control |= reinject_trap; data.env = env; on_vcpu(env, kvm_invoke_set_guest_debug, &data); diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 216b00e..dfc4a26 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -21,6 +21,10 @@ #include "config.h" +#ifdef CONFIG_KVM +#include /* for kvm_guest_debug */ +#endif + #ifdef TARGET_X86_64 #define TARGET_LONG_BITS 64 #else @@ -702,7 +706,10 @@ typedef struct CPUX86State { uint8_t has_error_code; uint32_t sipi_vector; uint32_t cpuid_kvm_features; - +#if defined(CONFIG_KVM) && defined(KVM_CAP_SET_GUEST_DEBUG) + struct kvm_guest_debug kvm_guest_debug; +#endif + /* in order to simplify APIC support, we leave this pointer to the user */ struct APICState *apic_state; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index f690b2e..2b3d8f6 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -851,6 +851,15 @@ int kvm_arch_put_registers(CPUState *env) if (ret < 0) return ret; + /* + * Kernels before 2.6.33 overwrote flags.TF injected via SET_GUEST_DEBUG + * while updating GP regs. Work around this by updating the debug state + * once again. + */ + ret = kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &env->kvm_guest_debug); + if (ret < 0) + return ret; + ret = kvm_put_fpu(env); if (ret < 0) return ret; @@ -1147,5 +1156,7 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg) (len_code[hw_breakpoint[n].len] << (18 + n*4)); } } + /* Keep a copy for the writeback workaround in kvm_arch_put_registers */ + memcpy(&env->kvm_guest_debug, dbg, sizeof(env->kvm_guest_debug)); } #endif /* KVM_CAP_SET_GUEST_DEBUG */