All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>,
	Glauber de Oliveira Costa <gcosta@redhat.com>,
	kvm <kvm@vger.kernel.org>
Subject: Re: [PATCH] qemu-kvm initialize vcpu state after machine initialization
Date: Tue, 15 Dec 2009 14:33:27 +0200	[thread overview]
Message-ID: <20091215123327.GD8031@redhat.com> (raw)
In-Reply-To: <20091215122415.GA9715@amt.cnet>

On Tue, Dec 15, 2009 at 10:24:15AM -0200, Marcelo Tosatti wrote:
> On Tue, Dec 15, 2009 at 01:20:38PM +0200, Gleb Natapov wrote:
> > On Mon, Dec 14, 2009 at 06:36:37PM -0200, Marcelo Tosatti wrote:
> > > 
> > > So that the vcpu state is initialized, from vcpu thread context, after 
> > > machine initialization is settled.
> > > 
> > > This allows to revert apic_init's apic_reset call. apic_reset now
> > > happens through system_reset, similarly to qemu upstream.
> > > 
> > This patch essentially revers commit 898c51c3. This commit fixes two
> > races. First race is like this:
> > 
> >      vcpu0                            vcpu1
> > 
> >    starts running
> >    loads lapic state into kernel 
> >    sends event to vcpu1
> >                                    starts running
> >                                    loads lapic state into kernel
> >                                    overwrites event from vcpu0
> >
> > At the time 898c51c3 was committed the race was easily reproducible
> > by starting VM with 16 cpus + seabios. Sometimes some vcpus lost INIT/SIPI
> > events. Now I am not able to reproduce it even with this patch applied,
> > so something else changed, but it doesn't make the race non existent or
> > acceptable.
> 
> Note qemu_kvm_load_lapic depends on env->created set (kvm_vcpu_inited),
Uhh. What about doing this:

diff --git a/qemu-kvm.c b/qemu-kvm.c
index 44e8b75..fa6db8e 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1920,12 +1920,12 @@ static void *ap_main_loop(void *_env)
     pthread_mutex_lock(&qemu_mutex);
     cpu_single_env = env;
 
+    current_env->created = 1;
     kvm_arch_init_vcpu(env);
 
     kvm_arch_load_regs(env);
 
     /* signal VCPU creation */
-    current_env->created = 1;
     pthread_cond_signal(&qemu_vcpu_cond);
 
     /* and wait for machine initialization */

> so having init_vcpu+load_regs before signalling vcpu creation did not
> fix this one (but yeah, thanks for the reminder on the races).
> 
> > The second race is during machine start after migration. The race is
> > between event loop and vcpu:
> > 
> >     event loop                         vcpu
> > 
> >   starts running
> >   gets RTC timer event
> >   sends interrupt to vcpu
> >                                     starts running
> >                                     loads lapic state into kernel
> >                                     overwrites interrupt from RTC
> > 
> >                                     
> > In short vcpu state that can be influenced by sources outside vcpu thread
> > itself should be uploaded into the kernel before signaling qemu_system_ready
> > condition.
> > 
> > --
> > 			Gleb.
> > --
> > 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.

  parent reply	other threads:[~2009-12-15 12:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09 17:46 qemu-kvm requires apic initialized before vcpu main loop Marcelo Tosatti
2009-12-09 18:23 ` Jan Kiszka
2009-12-09 19:23   ` Gleb Natapov
2009-12-09 20:09     ` Jan Kiszka
2009-12-09 20:13       ` Marcelo Tosatti
2009-12-09 20:21         ` Jan Kiszka
2009-12-09 20:50       ` Gleb Natapov
2009-12-09 21:01         ` Jan Kiszka
2009-12-10  6:36           ` Gleb Natapov
2009-12-10  8:12             ` Jan Kiszka
2009-12-09 20:02   ` Marcelo Tosatti
2009-12-09 20:22   ` Marcelo Tosatti
2009-12-09 18:25 ` Glauber Costa
2009-12-09 19:00   ` Jan Kiszka
2009-12-09 20:21     ` Marcelo Tosatti
2009-12-10 11:06       ` Glauber Costa
2009-12-09 20:09   ` Marcelo Tosatti
2009-12-09 19:20 ` Gleb Natapov
2009-12-09 20:26   ` Marcelo Tosatti
2009-12-10  9:33 ` Avi Kivity
2009-12-10  9:45   ` Avi Kivity
2009-12-14 20:36     ` [PATCH] qemu-kvm initialize vcpu state after machine initialization Marcelo Tosatti
2009-12-15 10:16       ` Avi Kivity
2009-12-15 11:20       ` Gleb Natapov
2009-12-15 12:24         ` Marcelo Tosatti
2009-12-15 12:31           ` Avi Kivity
2009-12-15 12:51             ` Marcelo Tosatti
2009-12-15 12:33           ` Gleb Natapov [this message]
2009-12-16 14:12             ` 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=20091215123327.GD8031@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=gcosta@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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.