Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 144

kvm-83-270.el5_11.src.rpm

From 56abfb382c9c813ce9161b28872de9c8d9485ed5 Mon Sep 17 00:00:00 2001
From: Gleb Natapov <gleb@redhat.com>
Date: Tue, 24 Nov 2009 19:43:08 -0200
Subject: [PATCH 11/11] Fix race between migration and cpu main loop

RH-Author: Gleb Natapov <gleb@redhat.com>
Message-id: <20091122091117.GG3193@redhat.com>
Patchwork-id: 3750
O-Subject: [PATCH] Fix race between migration and cpu main loop
Bugzilla: 533090
RH-Acked-by: Rik van Riel <riel@redhat.com>
RH-Acked-by: Glauber Costa <glommer@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

There is a race between migration and vcpu main loop.  Vcpu main loop
start to run only after migration is completed and one of the things that
is done at the beginning of the loop is syncing if the apic state into
the kernel.  Devices may start to send interrupts before vcpu loop is
entered. Such interrupt will be queued for delivery in apic irr register,
but syncing of the apic state at the beginning of the vcpu loop will
overwrite irr register and interrupt will be lost. The patch moves apic
initialization to vcpu creation time.

This is proposed for z-stream too.

BZ: 533090
Upstream status: Similar fix is already there. Was done for different
                 reason though.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
--
			Gleb.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/qemu-kvm.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 0a5f049..8d79065 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -384,11 +384,6 @@ static int kvm_main_loop_cpu(CPUState *env)
     if (kvm_irqchip_in_kernel(kvm_context))
 	env->halted = 0;
 
-    kvm_qemu_init_env(env);
-#ifdef TARGET_I386
-    kvm_tpr_vcpu_start(env);
-#endif
-
     cpu_single_env = env;
     kvm_load_registers(env);
 
@@ -430,6 +425,11 @@ static void *ap_main_loop(void *_env)
 	on_vcpu(env, kvm_arch_do_ioperm, data);
 #endif
 
+    kvm_qemu_init_env(env);
+#ifdef TARGET_I386
+    kvm_tpr_vcpu_start(env);
+#endif
+
     /* signal VCPU creation */
     pthread_mutex_lock(&qemu_mutex);
     current_env->kvm_cpu_state.created = 1;
-- 
1.6.3.rc4.29.g8146