From patchwork Fri Dec 28 20:34:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 208569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F2C4C2C00DE for ; Sat, 29 Dec 2012 07:33:01 +1100 (EST) Received: from localhost ([::1]:33894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Togbz-0000n5-TR for incoming@patchwork.ozlabs.org; Fri, 28 Dec 2012 15:32:59 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Togbc-0000en-6m for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TogbX-000446-Fp for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogbX-00043f-6O for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:31 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBSKWU61007658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Dec 2012 15:32:30 -0500 Received: from blackpad.lan.raisama.net (vpn1-6-233.gru2.redhat.com [10.97.6.233]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBSKWUAD018348; Fri, 28 Dec 2012 15:32:30 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 6E5AA203D43; Fri, 28 Dec 2012 18:34:08 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 28 Dec 2012 18:34:06 -0200 Message-Id: <1356726846-10637-10-git-send-email-ehabkost@redhat.com> In-Reply-To: <1356726846-10637-1-git-send-email-ehabkost@redhat.com> References: <1356726846-10637-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC 9/9] target-i386: Unify CPU object creation on x86_cpu_create_from_name() 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 To keep the kvm_enabled() check for "host" working, a 'kvm_required' field was added to X86CPUClass. Signed-off-by: Eduardo Habkost --- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 332916a..fc58f83 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -49,6 +49,7 @@ typedef struct X86CPUClass { /*< public >*/ void (*parent_reset)(CPUState *cpu); + bool kvm_required; } X86CPUClass; /** diff --git a/target-i386/cpu.c b/target-i386/cpu.c index fa7fab0..7beacdf 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1605,23 +1605,24 @@ static X86CPU *x86_cpu_create_from_name(const char *name, Error **errp) { Error *error = NULL; X86CPU *cpu = NULL; + ObjectClass *oc; + X86CPUClass *cc; char *class_name = g_strdup_printf(CPU_CLASS_NAME("%s"), name); + oc = object_class_by_name(class_name); + if (!oc) { + error_setg(&error, "Unable to find CPU definition: %s", name); + goto out; + } - if (kvm_enabled() && name && strcmp(name, "host") == 0) { -#ifdef CONFIG_KVM - cpu = X86_CPU(object_new(TYPE_X86_HOST_CPU)); -#endif - } else { - - if (!object_class_by_name(class_name)) { - error_setg(&error, "Unable to find CPU definition: %s", name); - goto out; - } - - cpu = X86_CPU(object_new(class_name)); + cc = X86_CPU_CLASS(oc); + if (cc->kvm_required && !kvm_enabled()) { + error_setg(&error, "CPU model '%s' requires KVM", name); + goto out; } + cpu = X86_CPU(object_new(class_name)); + out: g_free(class_name); if (error) { @@ -2499,6 +2500,12 @@ static void x86_host_cpu_initfn(Object *obj) } } +static void x86_host_cpu_class_init(ObjectClass *oc, void *data) +{ + X86CPUClass *cc = X86_CPU_CLASS(oc); + cc->kvm_required = true; +} + static const TypeInfo x86_host_cpu_type_info = { .name = TYPE_X86_HOST_CPU, .parent = TYPE_X86_CPU, @@ -2506,6 +2513,7 @@ static const TypeInfo x86_host_cpu_type_info = { .instance_init = x86_host_cpu_initfn, .abstract = false, .class_size = sizeof(X86CPUClass), + .class_init = x86_host_cpu_class_init, }; #endif /* CONFIG_KVM */