From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URu3X-0006kL-FB for qemu-devel@nongnu.org; Mon, 15 Apr 2013 20:47:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URu3T-0006fI-Lk for qemu-devel@nongnu.org; Mon, 15 Apr 2013 20:47:31 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55478 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URu3T-0006f9-CH for qemu-devel@nongnu.org; Mon, 15 Apr 2013 20:47:27 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 16 Apr 2013 02:46:42 +0200 Message-Id: <1366073209-27119-6-git-send-email-afaerber@suse.de> In-Reply-To: <1366073209-27119-1-git-send-email-afaerber@suse.de> References: <1366073209-27119-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 05/12] target-i386: Split APIC creation from initialization in x86_cpu_realizefn() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Igor Mammedov When APIC is hotplugged during CPU hotplug, device_set_realized() calls device_reset() on it. And if QEMU runs in KVM mode, following call chain will fail: apic_reset_common() -> kvm_apic_vapic_base_update() -> kvm_vcpu_ioctl(cpu->kvm_fd,...) due to cpu->kvm_fd not being initialized yet. cpu->kvm_fd is initialized during qemu_init_vcpu() but x86_cpu_apic_init(= ) can't be moved after it because kvm_init_vcpu() -> kvm_arch_reset_vcpu() relies on APIC to determine if CPU is BSP for setting initial env->mp_sta= te. So split APIC device creation from its initialization and realize APIC after CPU is created, when it's safe to call APIC's reset method. Signed-off-by: Igor Mammedov Reviewed-by: liguang Reviewed-by: Eduardo Habkost Signed-off-by: Andreas F=C3=A4rber --- target-i386/cpu.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 9d45f09..5d05803 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2050,9 +2050,8 @@ static void mce_init(X86CPU *cpu) } =20 #ifndef CONFIG_USER_ONLY -static void x86_cpu_apic_init(X86CPU *cpu, Error **errp) +static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) { - static int apic_mapped; CPUX86State *env =3D &cpu->env; APICCommonState *apic; const char *apic_type =3D "apic"; @@ -2075,6 +2074,16 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error *= *errp) /* TODO: convert to link<> */ apic =3D APIC_COMMON(env->apic_state); apic->cpu =3D cpu; +} + +static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) +{ + CPUX86State *env =3D &cpu->env; + static int apic_mapped; + + if (env->apic_state =3D=3D NULL) { + return; + } =20 if (qdev_init(env->apic_state)) { error_setg(errp, "APIC device '%s' could not be initialized", @@ -2092,6 +2101,10 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error *= *errp) apic_mapped =3D 1; } } +#else +static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) +{ +} #endif =20 static void x86_cpu_realizefn(DeviceState *dev, Error **errp) @@ -2142,7 +2155,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) qemu_register_reset(x86_cpu_machine_reset_cb, cpu); =20 if (cpu->env.cpuid_features & CPUID_APIC || smp_cpus > 1) { - x86_cpu_apic_init(cpu, &local_err); + x86_cpu_apic_create(cpu, &local_err); if (local_err !=3D NULL) { goto out; } @@ -2151,6 +2164,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Er= ror **errp) =20 mce_init(cpu); qemu_init_vcpu(&cpu->env); + + x86_cpu_apic_realize(cpu, &local_err); + if (local_err !=3D NULL) { + goto out; + } cpu_reset(CPU(cpu)); =20 xcc->parent_realize(dev, &local_err); --=20 1.8.1.4