From patchwork Thu Jul 25 09:49:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 261659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 281722C00BA for ; Thu, 25 Jul 2013 19:51:09 +1000 (EST) Received: from localhost ([::1]:59988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2ICQ-0001xg-S5 for incoming@patchwork.ozlabs.org; Thu, 25 Jul 2013 05:51:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2IBw-0001x2-Gr for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:50:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2IBt-0001Gj-0q for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:50:36 -0400 Received: from [222.73.24.84] (port=59213 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2IBs-0001GD-LX for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:50:32 -0400 X-IronPort-AV: E=Sophos;i="4.89,742,1367942400"; d="scan'208";a="8020170" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 25 Jul 2013 17:47:28 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r6P9oRRd019032; Thu, 25 Jul 2013 17:50:27 +0800 Received: from localhost.localdomain ([10.167.226.78]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013072517482446-123128 ; Thu, 25 Jul 2013 17:48:24 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2013 17:49:11 +0800 Message-Id: <1374745751-16812-1-git-send-email-chen.fan.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/25 17:48:24, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/25 17:48:24, Serialize complete at 2013/07/25 17:48:24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH v2] cpu: Correct cpu-hotplug failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org v1-v2: Change cpu_apic_realize to post_vcpu_init. When useing x86_64-softmmu --enable-kvm boot qemu, cpu-add command fails to add a vcpu, there show (KVM: setting VAPIC address failed). The reason is that we use an uninitialized cpu->kvm-fd to ioctl. so we move realizing apic to the back of qemu_init_vcpu. Signed-off-by: Chen Fan --- include/qom/cpu.h | 2 ++ qom/cpu.c | 13 +++++++++++++ target-i386/cpu.c | 10 ++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index daf1835..4b16385 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -80,6 +80,7 @@ struct TranslationBlock; * @synchronize_from_tb: Callback for synchronizing state from a TCG * #TranslationBlock. * @get_phys_page_debug: Callback for obtaining a physical address. + * @post_vcpu_init: Callback for doing some extra initialization. * @vmsd: State description for migration. * * Represents a CPU family or model. @@ -108,6 +109,7 @@ typedef struct CPUClass { void (*set_pc)(CPUState *cpu, vaddr value); void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb); hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr); + void (*post_vcpu_init)(CPUState *cpu, Error **errp); const struct VMStateDescription *vmsd; int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, diff --git a/qom/cpu.c b/qom/cpu.c index 5c45ab5..28f63b7 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -213,12 +213,25 @@ static ObjectClass *cpu_common_class_by_name(const char *cpu_model) return NULL; } +static void post_vcpu_init(CPUState *cpu, Error **errp) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + if (cc->post_vcpu_init != NULL) { + (*cc->post_vcpu_init)(cpu, errp); + } +} + static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); qemu_init_vcpu(cpu); + post_vcpu_init(cpu, errp); + if (error_is_set(errp)) { + return; + } + if (dev->hotplugged) { cpu_synchronize_post_init(cpu); notifier_list_notify(&cpu_added_notifiers, dev); diff --git a/target-i386/cpu.c b/target-i386/cpu.c index cd350cb..d51ab8b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2311,8 +2311,9 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) apic->cpu = cpu; } -static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) +static void x86_cpu_apic_realize(CPUState *s, Error **errp) { + X86CPU *cpu = X86_CPU(s); CPUX86State *env = &cpu->env; if (env->apic_state == NULL) { @@ -2326,7 +2327,7 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) } } #else -static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) +static void x86_cpu_apic_realize(CPUState *s, Error **errp) { } #endif @@ -2388,10 +2389,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) mce_init(cpu); - x86_cpu_apic_realize(cpu, &local_err); - if (local_err != NULL) { - goto out; - } cpu_reset(CPU(cpu)); xcc->parent_realize(dev, &local_err); @@ -2540,6 +2537,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = x86_cpu_synchronize_from_tb; cc->get_arch_id = x86_cpu_get_arch_id; cc->get_paging_enabled = x86_cpu_get_paging_enabled; + cc->post_vcpu_init = x86_cpu_apic_realize; #ifndef CONFIG_USER_ONLY cc->get_memory_mapping = x86_cpu_get_memory_mapping; cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;