From patchwork Wed Feb 3 08:53:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 76647 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 o138smVH012230 for ; Wed, 3 Feb 2010 08:54:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756257Ab0BCIyp (ORCPT ); Wed, 3 Feb 2010 03:54:45 -0500 Received: from thoth.sbs.de ([192.35.17.2]:21184 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755937Ab0BCIy2 (ORCPT ); Wed, 3 Feb 2010 03:54:28 -0500 Received: from mail3.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id o138rrIn025945; Wed, 3 Feb 2010 09:53:53 +0100 Received: from localhost.localdomain ([139.25.173.28]) by mail3.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id o138rkCC012112; Wed, 3 Feb 2010 09:53:53 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, Anthony Liguori , Alexander Graf , Glauber Costa , qemu-devel@nongnu.org Subject: [PATCH v2 11/21] KVM: Rework of guest debug state writing Date: Wed, 3 Feb 2010 09:53:36 +0100 Message-Id: X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: 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]); Wed, 03 Feb 2010 08:54:48 +0000 (UTC) diff --git a/kvm-all.c b/kvm-all.c index 3516f01..9c921cc 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -951,10 +951,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); } @@ -962,12 +958,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 7d0bbd0..7787fb1 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 @@ -718,7 +722,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 8743f32..5ac12a8 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -865,6 +865,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; @@ -1163,6 +1172,8 @@ 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 */ #endif