public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com, Jan Kiszka <jan.kiszka@siemens.com>
Subject: [PATCH v3 8/8] reuse upstream breakpoint code
Date: Tue, 14 Jul 2009 11:35:18 -0400	[thread overview]
Message-ID: <1247585718-32738-9-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1247585718-32738-8-git-send-email-glommer@redhat.com>

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 <glommer@redhat.com>
CC: Jan Kiszka <jan.kiszka@siemens.com>
---
 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(&current_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(&current_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, &current_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
-- 
1.6.2.2


  reply	other threads:[~2009-07-14 15:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 15:35 [PATCH v3 0/8] Move closer to upstream Glauber Costa
2009-07-14 15:35 ` [PATCH v3 1/8] replace USE_KVM with CONFIG_KVM Glauber Costa
2009-07-14 15:35   ` [PATCH v3 2/8] Do not compile qemu-kvm.c and qemu-kvm-x86.c Glauber Costa
2009-07-14 15:35     ` [PATCH v3 3/8] replace malloc with qemu_malloc Glauber Costa
2009-07-14 15:35       ` [PATCH v3 4/8] fold libkvm-all into standard qemu header Glauber Costa
2009-07-14 15:35         ` [PATCH v3 5/8] duplicate KVMState Glauber Costa
2009-07-14 15:35           ` [PATCH v3 6/8] provide env->kvm_fd Glauber Costa
2009-07-14 15:35             ` [PATCH v3 7/8] use kvm_upstream sw_breakpoints structure Glauber Costa
2009-07-14 15:35               ` Glauber Costa [this message]
2009-07-14 20:45                 ` [PATCH v3 8/8] reuse upstream breakpoint code Jan Kiszka
2009-07-14 21:01                   ` Glauber Costa
2009-07-14 21:31                     ` Marcelo Tosatti
2009-07-14 23:20 ` [PATCH v3 0/8] Move closer to upstream Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1247585718-32738-9-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox