From nobody Sat May 4 13:24:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487789042772401.6500209975518; Wed, 22 Feb 2017 10:44:02 -0800 (PST) Received: from localhost ([::1]:54714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbtR-0003Nd-Fw for importer@patchew.org; Wed, 22 Feb 2017 13:44:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbp1-0007qJ-8J for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgboz-00074o-9G for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgboy-00074i-W8 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:25 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 265F44D69C for ; Wed, 22 Feb 2017 18:39:25 +0000 (UTC) Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MIdNvG029421; Wed, 22 Feb 2017 13:39:24 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 15:39:17 -0300 Message-Id: <20170222183919.11928-2-ehabkost@redhat.com> In-Reply-To: <20170222183919.11928-1-ehabkost@redhat.com> References: <20170222183919.11928-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 22 Feb 2017 18:39:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] i386: Create "max" CPU model X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename the existing "host" CPU model to "max, and set it to kvm_enabled=3Dfalse. The new "max" CPU model will be able to enable all features supported by TCG out of the box, because its logic is based on x86_cpu_get_supported_feature_word(), which already works with TCG. A new KVM-specific "host" class was added, that simply inherits everything from "max" except the 'ordering' and 'description' fields. Signed-off-by: Eduardo Habkost --- Changes v1 -> v2: * Fix build without CONFIG_KVM at lmce_supported() --- target/i386/cpu.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index feb2110872..f7bd59617e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1503,15 +1503,15 @@ void x86_cpu_change_kvm_default(const char *prop, c= onst char *value) static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only); =20 -#ifdef CONFIG_KVM - static bool lmce_supported(void) { - uint64_t mce_cap; + uint64_t mce_cap =3D 0; =20 +#ifdef CONFIG_KVM if (kvm_ioctl(kvm_state, KVM_X86_GET_MCE_CAP_SUPPORTED, &mce_cap) < 0)= { return false; } +#endif =20 return !!(mce_cap & MCG_LMCE_P); } @@ -1533,23 +1533,22 @@ static int cpu_x86_fill_model_id(char *str) =20 static X86CPUDefinition host_cpudef; =20 -static Property host_x86_cpu_properties[] =3D { +static Property max_x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("migratable", X86CPU, migratable, true), DEFINE_PROP_BOOL("host-cache-info", X86CPU, cache_info_passthrough, fa= lse), DEFINE_PROP_END_OF_LIST() }; =20 -/* class_init for the "host" CPU model +/* class_init for the "max" CPU model * * This function may be called before KVM is initialized. */ -static void host_x86_cpu_class_init(ObjectClass *oc, void *data) +static void max_x86_cpu_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); X86CPUClass *xcc =3D X86_CPU_CLASS(oc); uint32_t eax =3D 0, ebx =3D 0, ecx =3D 0, edx =3D 0; =20 - xcc->kvm_required =3D true; xcc->ordering =3D 9; =20 host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); @@ -1564,17 +1563,16 @@ static void host_x86_cpu_class_init(ObjectClass *oc= , void *data) =20 xcc->cpu_def =3D &host_cpudef; xcc->model_description =3D - "KVM processor with all supported host features " - "(only available in KVM mode)"; + "Enables all features supported by the accelerator in the current = host"; =20 /* level, xlevel, xlevel2, and the feature words are initialized on * instance_init, because they require KVM to be initialized. */ =20 - dc->props =3D host_x86_cpu_properties; + dc->props =3D max_x86_cpu_properties; } =20 -static void host_x86_cpu_initfn(Object *obj) +static void max_x86_cpu_initfn(Object *obj) { X86CPU *cpu =3D X86_CPU(obj); CPUX86State *env =3D &cpu->env; @@ -1585,7 +1583,6 @@ static void host_x86_cpu_initfn(Object *obj) */ cpu->max_features =3D true; =20 - /* If KVM is disabled, x86_cpu_realizefn() will report an error later = */ if (kvm_enabled()) { env->cpuid_min_level =3D kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX); @@ -1602,10 +1599,30 @@ static void host_x86_cpu_initfn(Object *obj) object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort); } =20 +static const TypeInfo max_x86_cpu_type_info =3D { + .name =3D X86_CPU_TYPE_NAME("max"), + .parent =3D TYPE_X86_CPU, + .instance_init =3D max_x86_cpu_initfn, + .class_init =3D max_x86_cpu_class_init, +}; + +#ifdef CONFIG_KVM + +static void host_x86_cpu_class_init(ObjectClass *oc, void *data) +{ + X86CPUClass *xcc =3D X86_CPU_CLASS(oc); + + xcc->kvm_required =3D true; + xcc->ordering =3D 8; + + xcc->model_description =3D + "KVM processor with all supported host features " + "(only available in KVM mode)"; +} + static const TypeInfo host_x86_cpu_type_info =3D { .name =3D X86_CPU_TYPE_NAME("host"), - .parent =3D TYPE_X86_CPU, - .instance_init =3D host_x86_cpu_initfn, + .parent =3D X86_CPU_TYPE_NAME("max"), .class_init =3D host_x86_cpu_class_init, }; =20 @@ -3781,6 +3798,7 @@ static void x86_cpu_register_types(void) for (i =3D 0; i < ARRAY_SIZE(builtin_x86_defs); i++) { x86_register_cpudef_type(&builtin_x86_defs[i]); } + type_register_static(&max_x86_cpu_type_info); #ifdef CONFIG_KVM type_register_static(&host_x86_cpu_type_info); #endif --=20 2.11.0.259.g40922b1 From nobody Sat May 4 13:24:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487788874267872.7369001675481; Wed, 22 Feb 2017 10:41:14 -0800 (PST) Received: from localhost ([::1]:54703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbqi-0000J9-19 for importer@patchew.org; Wed, 22 Feb 2017 13:41:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbp2-0007qN-02 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgbp1-000752-0c for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgbp0-00074w-Qh for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:26 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAB5A61D02 for ; Wed, 22 Feb 2017 18:39:26 +0000 (UTC) Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MIdPLD024825; Wed, 22 Feb 2017 13:39:26 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 15:39:18 -0300 Message-Id: <20170222183919.11928-3-ehabkost@redhat.com> In-Reply-To: <20170222183919.11928-1-ehabkost@redhat.com> References: <20170222183919.11928-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 22 Feb 2017 18:39:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] i386: Make "max" model not use any host CPUID info on TCG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of reporting host CPUID data on "max", use the qemu64 CPU model as reference to initialize CPUID vendor/family/model/stepping/model-id. Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f7bd59617e..5164cd9ed5 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1594,6 +1594,15 @@ static void max_x86_cpu_initfn(Object *obj) if (lmce_supported()) { object_property_set_bool(OBJECT(cpu), true, "lmce", &error_abo= rt); } + } else { + object_property_set_str(OBJECT(cpu), CPUID_VENDOR_AMD, + "vendor", &error_abort); + object_property_set_int(OBJECT(cpu), 6, "family", &error_abort); + object_property_set_int(OBJECT(cpu), 6, "model", &error_abort); + object_property_set_int(OBJECT(cpu), 3, "stepping", &error_abort); + object_property_set_str(OBJECT(cpu), + "QEMU TCG CPU version " QEMU_HW_VERSION, + "model-id", &error_abort); } =20 object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort); --=20 2.11.0.259.g40922b1 From nobody Sat May 4 13:24:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487788879717233.10278144521408; Wed, 22 Feb 2017 10:41:19 -0800 (PST) Received: from localhost ([::1]:54704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbqo-0000Mm-Cg for importer@patchew.org; Wed, 22 Feb 2017 13:41:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgbp4-0007rd-HS for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgbp3-000775-Bj for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgbp3-00076v-3J for qemu-devel@nongnu.org; Wed, 22 Feb 2017 13:39:29 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46712804F1 for ; Wed, 22 Feb 2017 18:39:29 +0000 (UTC) Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MIdRNm011039; Wed, 22 Feb 2017 13:39:28 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 15:39:19 -0300 Message-Id: <20170222183919.11928-4-ehabkost@redhat.com> In-Reply-To: <20170222183919.11928-1-ehabkost@redhat.com> References: <20170222183919.11928-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 22 Feb 2017 18:39:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] i386: Don't set CPUClass::cpu_def on "max" model X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Host CPUID info is used by the "max" CPU model only in KVM mode. Move the initialization of CPUID data for "max" from class_init to instance_init, and don't set CPUClass::cpu_def for "max". Signed-off-by: Eduardo Habkost --- target/i386/cpu-qom.h | 4 +++- target/i386/cpu.c | 45 +++++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/target/i386/cpu-qom.h b/target/i386/cpu-qom.h index 14abd0a8c1..f6c704c3a9 100644 --- a/target/i386/cpu-qom.h +++ b/target/i386/cpu-qom.h @@ -60,7 +60,9 @@ typedef struct X86CPUClass { CPUClass parent_class; /*< public >*/ =20 - /* Should be eventually replaced by subclass-specific property default= s. */ + /* CPU definition, automatically loaded by instance_init if not NULL. + * Should be eventually replaced by subclass-specific property default= s. + */ X86CPUDefinition *cpu_def; =20 bool kvm_required; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5164cd9ed5..df0783e39b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1531,47 +1531,27 @@ static int cpu_x86_fill_model_id(char *str) return 0; } =20 -static X86CPUDefinition host_cpudef; - static Property max_x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("migratable", X86CPU, migratable, true), DEFINE_PROP_BOOL("host-cache-info", X86CPU, cache_info_passthrough, fa= lse), DEFINE_PROP_END_OF_LIST() }; =20 -/* class_init for the "max" CPU model - * - * This function may be called before KVM is initialized. - */ static void max_x86_cpu_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); X86CPUClass *xcc =3D X86_CPU_CLASS(oc); - uint32_t eax =3D 0, ebx =3D 0, ecx =3D 0, edx =3D 0; =20 xcc->ordering =3D 9; =20 - host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); - x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx); - - host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); - host_cpudef.family =3D ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); - host_cpudef.model =3D ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); - host_cpudef.stepping =3D eax & 0x0F; - - cpu_x86_fill_model_id(host_cpudef.model_id); - - xcc->cpu_def =3D &host_cpudef; xcc->model_description =3D "Enables all features supported by the accelerator in the current = host"; =20 - /* level, xlevel, xlevel2, and the feature words are initialized on - * instance_init, because they require KVM to be initialized. - */ - dc->props =3D max_x86_cpu_properties; } =20 +static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **e= rrp); + static void max_x86_cpu_initfn(Object *obj) { X86CPU *cpu =3D X86_CPU(obj); @@ -1584,6 +1564,21 @@ static void max_x86_cpu_initfn(Object *obj) cpu->max_features =3D true; =20 if (kvm_enabled()) { + X86CPUDefinition host_cpudef =3D { }; + uint32_t eax =3D 0, ebx =3D 0, ecx =3D 0, edx =3D 0; + + host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); + x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx); + + host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); + host_cpudef.family =3D ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); + host_cpudef.model =3D ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12= ); + host_cpudef.stepping =3D eax & 0x0F; + + cpu_x86_fill_model_id(host_cpudef.model_id); + + x86_cpu_load_def(cpu, &host_cpudef, &error_abort); + env->cpuid_min_level =3D kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX); env->cpuid_min_xlevel =3D @@ -2186,7 +2181,7 @@ static void x86_cpu_list_entry(gpointer data, gpointe= r user_data) CPUListState *s =3D user_data; char *name =3D x86_cpu_class_get_model_name(cc); const char *desc =3D cc->model_description; - if (!desc) { + if (!desc && cc->cpu_def) { desc =3D cc->cpu_def->model_id; } =20 @@ -3644,7 +3639,9 @@ static void x86_cpu_initfn(Object *obj) object_property_add_alias(obj, "sse4_1", obj, "sse4.1", &error_abort); object_property_add_alias(obj, "sse4_2", obj, "sse4.2", &error_abort); =20 - x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort); + if (xcc->cpu_def) { + x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort); + } } =20 static int64_t x86_cpu_get_arch_id(CPUState *cs) --=20 2.11.0.259.g40922b1