From patchwork Tue Jul 14 15:35:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 35566 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 n6EFfvdj024082 for ; Tue, 14 Jul 2009 15:41:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753609AbZGNPly (ORCPT ); Tue, 14 Jul 2009 11:41:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752986AbZGNPly (ORCPT ); Tue, 14 Jul 2009 11:41:54 -0400 Received: from mx2.redhat.com ([66.187.237.31]:36677 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752599AbZGNPly (ORCPT ); Tue, 14 Jul 2009 11:41:54 -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 n6EFZOXQ019381; Tue, 14 Jul 2009 11:35:24 -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 n6EFZNWg009352; Tue, 14 Jul 2009 11:35:23 -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 n6EFZJ3T019321; Tue, 14 Jul 2009 11:35:22 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com, Jan Kiszka Subject: [PATCH v3 8/8] reuse upstream breakpoint code Date: Tue, 14 Jul 2009 11:35:18 -0400 Message-Id: <1247585718-32738-9-git-send-email-glommer@redhat.com> In-Reply-To: <1247585718-32738-8-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> <1247585718-32738-8-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 Drop KVM_UPSTREAM around functions we intend to reuse. This allow us to share code in kvm-all.c, that is equal in qemu-kvm.c Signed-off-by: Glauber Costa CC: Jan Kiszka --- kvm-all.c | 5 ++- kvm.h | 1 + qemu-kvm.c | 140 +----------------------------------------------------------- 3 files changed, 6 insertions(+), 140 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index e42b1f6..67908a7 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -873,6 +873,8 @@ void kvm_setup_guest_memory(void *start, size_t size) } } +#endif /* KVM_UPSTREAM */ + #ifdef KVM_CAP_SET_GUEST_DEBUG struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, target_ulong pc) @@ -891,6 +893,7 @@ int kvm_sw_breakpoints_active(CPUState *env) return !TAILQ_EMPTY(&env->kvm_state->kvm_sw_breakpoints); } +#ifdef KVM_UPSTREAM int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) { struct kvm_guest_debug dbg; @@ -904,6 +907,7 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) return kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &dbg); } +#endif int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, target_ulong len, int type) @@ -1028,6 +1032,5 @@ void kvm_remove_all_breakpoints(CPUState *current_env) { } #endif /* !KVM_CAP_SET_GUEST_DEBUG */ -#endif #include "qemu-kvm.c" diff --git a/kvm.h b/kvm.h index e9a43e2..0191752 100644 --- a/kvm.h +++ b/kvm.h @@ -16,6 +16,7 @@ #include "config.h" #include "sys-queue.h" +#include "qemu-kvm.h" #ifdef KVM_UPSTREAM diff --git a/qemu-kvm.c b/qemu-kvm.c index b0661b6..355adf4 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -2444,18 +2444,6 @@ int kvm_qemu_init_env(CPUState *cenv) #ifdef KVM_CAP_SET_GUEST_DEBUG -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, - target_ulong pc) -{ - struct kvm_sw_breakpoint *bp; - - TAILQ_FOREACH(bp, &env->kvm_state->kvm_sw_breakpoints, entry) { - if (bp->pc == pc) - return bp; - } - return NULL; -} - struct kvm_set_guest_debug_data { struct kvm_guest_debug dbg; int err; @@ -2484,133 +2472,7 @@ 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) -{ - struct kvm_sw_breakpoint *bp; - CPUState *env; - int err; - - if (type == GDB_BREAKPOINT_SW) { - bp = kvm_find_sw_breakpoint(current_env, addr); - if (bp) { - bp->use_count++; - return 0; - } - - bp = qemu_malloc(sizeof(struct kvm_sw_breakpoint)); - if (!bp) - return -ENOMEM; - - bp->pc = addr; - bp->use_count = 1; - err = kvm_arch_insert_sw_breakpoint(current_env, bp); - if (err) { - free(bp); - return err; - } - - TAILQ_INSERT_HEAD(¤t_env->kvm_state->kvm_sw_breakpoints, - bp, entry); - } else { - err = kvm_arch_insert_hw_breakpoint(addr, len, type); - if (err) - return err; - } - - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = kvm_update_guest_debug(env, 0); - if (err) - return err; - } - return 0; -} - -int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr, - target_ulong len, int type) -{ - struct kvm_sw_breakpoint *bp; - CPUState *env; - int err; - - if (type == GDB_BREAKPOINT_SW) { - bp = kvm_find_sw_breakpoint(current_env, addr); - if (!bp) - return -ENOENT; - - if (bp->use_count > 1) { - bp->use_count--; - return 0; - } - - err = kvm_arch_remove_sw_breakpoint(current_env, bp); - if (err) - return err; - - TAILQ_REMOVE(¤t_env->kvm_state->kvm_sw_breakpoints, bp, entry); - qemu_free(bp); - } else { - err = kvm_arch_remove_hw_breakpoint(addr, len, type); - if (err) - return err; - } - - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = kvm_update_guest_debug(env, 0); - if (err) - return err; - } - return 0; -} - -void kvm_remove_all_breakpoints(CPUState *current_env) -{ - struct kvm_sw_breakpoint *bp, *next; - CPUState *env; - - 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) { - if (kvm_arch_remove_sw_breakpoint(env, bp) == 0) - break; - } - } - } - kvm_arch_remove_all_hw_breakpoints(); - - for (env = first_cpu; env != NULL; env = env->next_cpu) - kvm_update_guest_debug(env, 0); -} - -#else /* !KVM_CAP_SET_GUEST_DEBUG */ - -int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) -{ - return -EINVAL; -} - -int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, - target_ulong len, int type) -{ - return -EINVAL; -} - -int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr, - target_ulong len, int type) -{ - return -EINVAL; -} - -void kvm_remove_all_breakpoints(CPUState *current_env) -{ -} -#endif /* !KVM_CAP_SET_GUEST_DEBUG */ +#endif /* * dirty pages logging