target-i386: Split APIC creation from initialization in x86_cpu_realizefn()
commitd3c64d6a1874f94246af91963927fb4d924332f1
authorIgor Mammedov <imammedo@redhat.com>
Fri, 5 Apr 2013 14:36:54 +0000 (5 16:36 +0200)
committerAndreas Färber <afaerber@suse.de>
Mon, 15 Apr 2013 23:19:46 +0000 (16 01:19 +0200)
tree8d96b8839dcfa2eb87375b4b41f1e4fa1090c64b
parent4dc1f449ab22bb79ea3894bd90b154c30d73573e
target-i386: Split APIC creation from initialization in x86_cpu_realizefn()

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_state.

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 <imammedo@redhat.com>
Reviewed-by: liguang <lig.fnst@cn.fujitsu.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
target-i386/cpu.c