All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>,
	Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH] qemu-kvm: fix guest resetting
Date: Fri, 09 May 2008 13:46:30 -0500	[thread overview]
Message-ID: <48249C06.3060705@codemonkey.ws> (raw)
In-Reply-To: <20080509165935.GA12600@dmt>

Marcelo Tosatti wrote:
> diff --git a/qemu/qemu-kvm-ia64.c b/qemu/qemu-kvm-ia64.c
> index 4d0ddd7..d227d22 100644
> --- a/qemu/qemu-kvm-ia64.c
> +++ b/qemu/qemu-kvm-ia64.c
> @@ -61,3 +61,7 @@ int kvm_arch_try_push_interrupts(void *opaque)
>  void kvm_arch_update_regs_for_sipi(CPUState *env)
>  {
>  }
> +
> +void kvm_arch_cpu_reset(CPUState *env)
> +{
> +}
> diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
> index 14ed945..024b18c 100644
> --- a/qemu/qemu-kvm-powerpc.c
> +++ b/qemu/qemu-kvm-powerpc.c
> @@ -213,3 +213,7 @@ int handle_powerpc_dcr_write(int vcpu, uint32_t dcrn, uint32_t data)
>  
>      return 0; /* XXX ignore failed DCR ops */
>  }
> +
> +void kvm_arch_cpu_reset(CPUState *env)
> +{
> +}
> diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
> index 9a771ff..28eb5c2 100644
> --- a/qemu/qemu-kvm-x86.c
> +++ b/qemu/qemu-kvm-x86.c
> @@ -689,3 +689,19 @@ int handle_tpr_access(void *opaque, int vcpu,
>      kvm_tpr_access_report(cpu_single_env, rip, is_write);
>      return 0;
>  }
> +
> +void kvm_arch_cpu_reset(CPUState *env)
> +{
> +    struct kvm_mp_state mp_state = { .mp_state = KVM_MP_STATE_UNINITIALIZED };
> +
> +    kvm_arch_load_regs(env);
> +    if (env->cpu_index != 0) {
> +	if (kvm_irqchip_in_kernel(kvm_context))
> +	    kvm_set_mpstate(kvm_context, env->cpu_index, &mp_state);
> +	else {
> +	    env->interrupt_request &= ~CPU_INTERRUPT_HARD;
> +	    env->hflags |= HF_HALTED_MASK;
> +	    env->exception_index = EXCP_HLT;
> +	}
> +    }
> +}
> diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
> index 3cc6d8e..1e1f065 100644
> --- a/qemu/qemu-kvm.c
> +++ b/qemu/qemu-kvm.c
> @@ -31,8 +31,6 @@ kvm_context_t kvm_context;
>  
>  extern int smp_cpus;
>  
> -static int qemu_kvm_reset_requested;
> -
>  pthread_mutex_t qemu_mutex = PTHREAD_MUTEX_INITIALIZER;
>  pthread_cond_t qemu_aio_cond = PTHREAD_COND_INITIALIZER;
>  pthread_cond_t qemu_vcpu_cond = PTHREAD_COND_INITIALIZER;
> @@ -52,7 +50,6 @@ struct vcpu_info {
>      int signalled;
>      int stop;
>      int stopped;
> -    int reload_regs;
>      int created;
>  } vcpu_info[256];
>  
> @@ -242,21 +239,29 @@ static void pause_all_threads(void)
>  {
>      int i;
>  
> +    if (cpu_single_env) {
> +        fprintf(stderr, "qemu-kvm: pause_all_threads from vcpu context\n");
> +        exit(0);
> +    }
> +
>      for (i = 0; i < smp_cpus; ++i) {
>  	vcpu_info[i].stop = 1;
>  	pthread_kill(vcpu_info[i].thread, SIG_IPI);
>      }
> -    while (!all_threads_paused()) {
> -	CPUState *env = cpu_single_env;
> +    while (!all_threads_paused())
>  	pthread_cond_wait(&qemu_pause_cond, &qemu_mutex);
> -	cpu_single_env = env;
> -    }
> +    cpu_single_env = NULL;
>  }
>   

Personally, I prefer it the old way.  All of the open-coded 
cpu_single_env's are tough to understand and I believe error-prone.  I 
think a strategy of explicitly preserving cpu_single_env whenever we 
drop qemu_mutex is more robust.  Explicitly setting cpu_single_env = 
NULL happens to work because this is only called from the io thread.  
It's less clear to a casual reader why it's necessary.

In fact, I'd be much more inclined to see a wrapper around 
pthread_cond_wait() so that we never explicitly had to set cpu_single_env.

Regards,

Anthony Liguori

>  }
>  
>  void qemu_system_shutdown_request(void)
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
> Don't miss this year's exciting event. There's still time to save $100. 
> Use priority code J8TL2D2. 
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> kvm-devel mailing list
> kvm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>   


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  reply	other threads:[~2008-05-09 18:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08  8:29 [PATCH] qemu-kvm: fix guest resetting Jan Kiszka
2008-05-08 23:35 ` Marcelo Tosatti
2008-05-09  8:13   ` Jan Kiszka
2008-05-09 16:59     ` Marcelo Tosatti
2008-05-09 18:46       ` Anthony Liguori [this message]
2008-05-10  8:26         ` Jan Kiszka

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=48249C06.3060705@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=mtosatti@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.