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@xxxxxxxxxx> CC: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> --- 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 490024e..8778e6d 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -2424,18 +2424,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; @@ -2464,133 +2452,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 -- 1.6.2.2 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html