From patchwork Tue Jul 14 15:35:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 35564 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 n6EFaN4Y023441 for ; Tue, 14 Jul 2009 15:36:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755196AbZGNPfh (ORCPT ); Tue, 14 Jul 2009 11:35:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755096AbZGNPfh (ORCPT ); Tue, 14 Jul 2009 11:35:37 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59981 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755184AbZGNPfX (ORCPT ); Tue, 14 Jul 2009 11:35:23 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6EFZNC1019371 for ; Tue, 14 Jul 2009 11:35:23 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6EFZMY3009346; Tue, 14 Jul 2009 11:35:22 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6EFZJ3S019321; Tue, 14 Jul 2009 11:35:22 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH v3 7/8] use kvm_upstream sw_breakpoints structure Date: Tue, 14 Jul 2009 11:35:17 -0400 Message-Id: <1247585718-32738-8-git-send-email-glommer@redhat.com> In-Reply-To: <1247585718-32738-7-git-send-email-glommer@redhat.com> References: <1247585718-32738-1-git-send-email-glommer@redhat.com> <1247585718-32738-2-git-send-email-glommer@redhat.com> <1247585718-32738-3-git-send-email-glommer@redhat.com> <1247585718-32738-4-git-send-email-glommer@redhat.com> <1247585718-32738-5-git-send-email-glommer@redhat.com> <1247585718-32738-6-git-send-email-glommer@redhat.com> <1247585718-32738-7-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Glauber Costa --- qemu-kvm-x86.c | 4 ++-- qemu-kvm.c | 27 ++++++++++++++++++--------- qemu-kvm.h | 9 ++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index b531ca4..3bbb9d2 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -1519,7 +1519,7 @@ int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info) break; } } - } else if (kvm_find_sw_breakpoint(arch_info->pc)) + } else if (kvm_find_sw_breakpoint(cpu_single_env, arch_info->pc)) handle = 1; if (!handle) @@ -1542,7 +1542,7 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg) }; int n; - if (!TAILQ_EMPTY(&kvm_sw_breakpoints)) + if (kvm_sw_breakpoints_active(env)) dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP; if (nb_hw_breakpoint > 0) { diff --git a/qemu-kvm.c b/qemu-kvm.c index 6897e3c..b0661b6 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -459,6 +459,10 @@ int kvm_init(int smp_cpus) kvm_context->no_irqchip_creation = 0; kvm_context->no_pit_creation = 0; +#ifdef KVM_CAP_SET_GUEST_DEBUG + TAILQ_INIT(&kvm_state->kvm_sw_breakpoints); +#endif + gsi_count = kvm_get_gsi_count(kvm_context); if (gsi_count > 0) { int gsi_bits, i; @@ -2439,14 +2443,13 @@ int kvm_qemu_init_env(CPUState *cenv) } #ifdef KVM_CAP_SET_GUEST_DEBUG -struct kvm_sw_breakpoint_head kvm_sw_breakpoints = - TAILQ_HEAD_INITIALIZER(kvm_sw_breakpoints); -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(target_ulong pc) +struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, + target_ulong pc) { struct kvm_sw_breakpoint *bp; - TAILQ_FOREACH(bp, &kvm_sw_breakpoints, entry) { + TAILQ_FOREACH(bp, &env->kvm_state->kvm_sw_breakpoints, entry) { if (bp->pc == pc) return bp; } @@ -2481,6 +2484,11 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) return data.err; } +int kvm_sw_breakpoints_active(CPUState *env) +{ + return !TAILQ_EMPTY(&env->kvm_state->kvm_sw_breakpoints); +} + int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, target_ulong len, int type) { @@ -2489,7 +2497,7 @@ int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, int err; if (type == GDB_BREAKPOINT_SW) { - bp = kvm_find_sw_breakpoint(addr); + bp = kvm_find_sw_breakpoint(current_env, addr); if (bp) { bp->use_count++; return 0; @@ -2507,7 +2515,8 @@ int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, return err; } - TAILQ_INSERT_HEAD(&kvm_sw_breakpoints, bp, entry); + TAILQ_INSERT_HEAD(¤t_env->kvm_state->kvm_sw_breakpoints, + bp, entry); } else { err = kvm_arch_insert_hw_breakpoint(addr, len, type); if (err) @@ -2530,7 +2539,7 @@ int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr, int err; if (type == GDB_BREAKPOINT_SW) { - bp = kvm_find_sw_breakpoint(addr); + bp = kvm_find_sw_breakpoint(current_env, addr); if (!bp) return -ENOENT; @@ -2543,7 +2552,7 @@ int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr, if (err) return err; - TAILQ_REMOVE(&kvm_sw_breakpoints, bp, entry); + TAILQ_REMOVE(¤t_env->kvm_state->kvm_sw_breakpoints, bp, entry); qemu_free(bp); } else { err = kvm_arch_remove_hw_breakpoint(addr, len, type); @@ -2564,7 +2573,7 @@ void kvm_remove_all_breakpoints(CPUState *current_env) struct kvm_sw_breakpoint *bp, *next; CPUState *env; - TAILQ_FOREACH_SAFE(bp, &kvm_sw_breakpoints, entry, next) { + TAILQ_FOREACH_SAFE(bp, ¤t_env->kvm_state->kvm_sw_breakpoints, entry, next) { if (kvm_arch_remove_sw_breakpoint(current_env, bp) != 0) { /* Try harder to find a CPU that currently sees the breakpoint. */ for (env = first_cpu; env != NULL; env = env->next_cpu) { diff --git a/qemu-kvm.h b/qemu-kvm.h index fbbbb43..d5291a3 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -1004,12 +1004,12 @@ struct kvm_sw_breakpoint { int use_count; TAILQ_ENTRY(kvm_sw_breakpoint) entry; }; -TAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); -extern struct kvm_sw_breakpoint_head kvm_sw_breakpoints; +TAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info); -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(target_ulong pc); +int kvm_sw_breakpoints_active(CPUState *env); +struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, target_ulong pc); int kvm_arch_insert_sw_breakpoint(CPUState *current_env, struct kvm_sw_breakpoint *bp); int kvm_arch_remove_sw_breakpoint(CPUState *current_env, @@ -1174,6 +1174,9 @@ typedef struct KVMState int coalesced_mmio; int broken_set_mem_region; int migration_log; +#ifdef KVM_CAP_SET_GUEST_DEBUG + struct kvm_sw_breakpoint_head kvm_sw_breakpoints; +#endif struct kvm_context kvm_context; } KVMState;