public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Glauber Costa <glommer@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com, Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH v2 9/9] reuse upstream breakpoint code
Date: Sun, 12 Jul 2009 12:30:56 +0300	[thread overview]
Message-ID: <20090712093056.GX28046@redhat.com> (raw)
In-Reply-To: <1247257080-18549-10-git-send-email-glommer@redhat.com>

On Fri, Jul 10, 2009 at 04:18:00PM -0400, Glauber Costa wrote:
> 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
> 
Can we push on_vcpu() to upstream? Then we will be able to reuse
kvm_update_guest_debug() from upstream too.

> 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 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(&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
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
			Gleb.

  reply	other threads:[~2009-07-12  9:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 20:17 [PATCH v2 0/9] Move closer to upstream Glauber Costa
2009-07-10 20:17 ` [PATCH v2 1/9] replace USE_KVM with CONFIG_KVM Glauber Costa
2009-07-10 20:17   ` [PATCH v2 2/9] Do not compile qemu-kvm.c and qemu-kvm-x86.c Glauber Costa
2009-07-10 20:17     ` [PATCH v2 3/9] replace malloc with qemu_malloc Glauber Costa
2009-07-10 20:17       ` [PATCH v2 4/9] remove leftover: Glauber Costa
2009-07-10 20:17         ` [PATCH v2 5/9] fold libkvm-all into standard qemu header Glauber Costa
2009-07-10 20:17           ` [PATCH v2 6/9] duplicate KVMState Glauber Costa
2009-07-10 20:17             ` [PATCH v2 7/9] provide env->kvm_fd Glauber Costa
2009-07-10 20:17               ` [PATCH v2 8/9] use kvm_upstream sw_breakpoints structure Glauber Costa
2009-07-10 20:18                 ` [PATCH v2 9/9] reuse upstream breakpoint code Glauber Costa
2009-07-12  9:30                   ` Gleb Natapov [this message]
2009-07-12  9:01 ` [PATCH v2 0/9] Move closer to upstream Avi Kivity

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=20090712093056.GX28046@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=glommer@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