Don't race while creating a VCPU
commit3bfa8c2dcf4ca648ef850b46ff5cddee46e45421
authorAnthony Liguori <aliguori@us.ibm.com>
Mon, 28 Apr 2008 22:30:36 +0000 (28 17:30 -0500)
committerAvi Kivity <avi@qumranet.com>
Tue, 29 Apr 2008 23:29:23 +0000 (30 02:29 +0300)
treea7f8da149ee460f9f42a86ef49c2e680bbceb268
parent6fed011004cc9daea949c751347df83790a56285
Don't race while creating a VCPU

We hold qemu_mutex while machine->init() executes, which issues a VCPU create.
We need to make sure to not return from the VCPU creation until the VCPU
file descriptor is valid to ensure that APIC creation succeeds.

However, we also need to make sure that the VCPU thread doesn't start running
until the machine->init() is complete.  This is addressed today because the
VCPU thread tries to grab the qemu_mutex before doing anything interesting.
If we release qemu_mutex to wait for VCPU creation, then we open a window for
a race to occur.

This patch introduces two wait conditions.  The first lets the VCPU create
code that runs in the IO thread to wait for a VCPU to initialize.  The second
condition lets the VCPU thread wait for the machine to fully initialize before
running.

An added benefit of this patch is it makes the dependencies now explicit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
qemu-kvm.c