From nobody Sun Feb 8 13:19:51 2026 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 1488212824377663.1207502787535; Mon, 27 Feb 2017 08:27:04 -0800 (PST) Received: from localhost ([::1]:54126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO8b-0000Z8-VD for importer@patchew.org; Mon, 27 Feb 2017 11:27:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6n-0007nN-J0 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6m-00059w-LS for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6m-00058y-Fr for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:08 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 ACD014E4D6; Mon, 27 Feb 2017 16:25:08 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGP73X022070; Mon, 27 Feb 2017 11:25:08 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:51 -0300 Message-Id: <20170227162501.29280-2-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 27 Feb 2017 16:25:08 +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] [PULL 01/11] i386: Unset cannot_destroy_with_object_finalize_yet on "host" 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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" The class is now safe because the assert(kvm_enabled()) line was removed by commit e435601058e656e6d24e3e87b187e5518f7bf16a. Message-Id: <20170119210449.11991-2-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b6f157dca3..2adee42035 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1571,8 +1571,6 @@ static void host_x86_cpu_class_init(ObjectClass *oc, = void *data) */ =20 dc->props =3D host_x86_cpu_properties; - /* Reason: host_x86_cpu_initfn() dies when !kvm_enabled() */ - dc->cannot_destroy_with_object_finalize_yet =3D true; } =20 static void host_x86_cpu_initfn(Object *obj) --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 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 1488213611335100.15867730368961; Mon, 27 Feb 2017 08:40:11 -0800 (PST) Received: from localhost ([::1]:54191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOLI-0003Y0-3w for importer@patchew.org; Mon, 27 Feb 2017 11:40:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6p-0007rI-Jr for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6o-0005BS-JP for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51744) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6o-0005Al-E6 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:10 -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 982D24A549; Mon, 27 Feb 2017 16:25:10 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGP9nb012508; Mon, 27 Feb 2017 11:25:10 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:52 -0300 Message-Id: <20170227162501.29280-3-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-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.26]); Mon, 27 Feb 2017 16:25:10 +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] [PULL 02/11] i386: Add ordering field to CPUClass 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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 using kvm_enabled to order the "-cpu help" list, use a new "ordering" field for that. Message-Id: <20170119210449.11991-3-ehabkost@redhat.com> Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- target/i386/cpu-qom.h | 2 ++ target/i386/cpu.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu-qom.h b/target/i386/cpu-qom.h index 8cd607e9a2..14abd0a8c1 100644 --- a/target/i386/cpu-qom.h +++ b/target/i386/cpu-qom.h @@ -48,6 +48,7 @@ typedef struct X86CPUDefinition X86CPUDefinition; * X86CPUClass: * @cpu_def: CPU model definition * @kvm_required: Whether CPU model requires KVM to be enabled. + * @ordering: Ordering on the "-cpu help" CPU model list. * @migration_safe: See CpuDefinitionInfo::migration_safe * @parent_realize: The parent class' realize handler. * @parent_reset: The parent class' reset handler. @@ -63,6 +64,7 @@ typedef struct X86CPUClass { X86CPUDefinition *cpu_def; =20 bool kvm_required; + int ordering; bool migration_safe; =20 /* Optional description of CPU model. diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2adee42035..8efe4de89e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1550,6 +1550,7 @@ static void host_x86_cpu_class_init(ObjectClass *oc, = void *data) 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); x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx); @@ -2126,7 +2127,7 @@ static void listflags(FILE *f, fprintf_function print= , const char **featureset) } } =20 -/* Sort alphabetically by type name, listing kvm_required models last. */ +/* Sort alphabetically by type name, respecting X86CPUClass::ordering. */ static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b) { ObjectClass *class_a =3D (ObjectClass *)a; @@ -2135,9 +2136,8 @@ static gint x86_cpu_list_compare(gconstpointer a, gco= nstpointer b) X86CPUClass *cc_b =3D X86_CPU_CLASS(class_b); const char *name_a, *name_b; =20 - if (cc_a->kvm_required !=3D cc_b->kvm_required) { - /* kvm_required items go last */ - return cc_a->kvm_required ? 1 : -1; + if (cc_a->ordering !=3D cc_b->ordering) { + return cc_a->ordering - cc_b->ordering; } else { name_a =3D object_class_get_name(class_a); name_b =3D object_class_get_name(class_b); --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 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 1488213974945324.8842434521648; Mon, 27 Feb 2017 08:46:14 -0800 (PST) Received: from localhost ([::1]:54235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciORB-0000lL-La for importer@patchew.org; Mon, 27 Feb 2017 11:46:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6u-0007wB-Ms for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6q-0005C7-FI for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6q-0005Bt-9Z for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:12 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 74DCAC04B959; Mon, 27 Feb 2017 16:25:12 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPBpa022115; Mon, 27 Feb 2017 11:25:11 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:53 -0300 Message-Id: <20170227162501.29280-4-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Feb 2017 16:25:12 +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] [PULL 03/11] i386: Rename X86CPU::host_features to X86CPU::max_features 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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 field and add a small comment to make its purpose clearer. Message-Id: <20170119210449.11991-4-ehabkost@redhat.com> Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- target/i386/cpu.h | 2 +- target/i386/cpu.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8df124f332..5f75ab1b15 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1211,7 +1211,7 @@ struct X86CPU { bool enforce_cpuid; bool expose_kvm; bool migratable; - bool host_features; + bool max_features; /* Enable all supported features automatically */ uint32_t apic_id; =20 /* Enables publishing of TSC increment and Local APIC bus frequencies = to diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8efe4de89e..87affbfcd6 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1583,7 +1583,7 @@ static void host_x86_cpu_initfn(Object *obj) /* We can't fill the features array here because we don't know yet if * "migratable" is true or false. */ - cpu->host_features =3D true; + cpu->max_features =3D true; =20 /* If KVM is disabled, x86_cpu_realizefn() will report an error later = */ if (kvm_enabled()) { @@ -3101,12 +3101,12 @@ static void x86_cpu_load_features(X86CPU *cpu, Erro= r **errp) GList *l; Error *local_err =3D NULL; =20 - /*TODO: cpu->host_features incorrectly overwrites features + /*TODO: cpu->max_features incorrectly overwrites features * set using "feat=3Don|off". Once we fix this, we can convert * plus_features & minus_features to global properties * inside x86_cpu_parse_featurestr() too. */ - if (cpu->host_features) { + if (cpu->max_features) { for (w =3D 0; w < FEATURE_WORDS; w++) { env->features[w] =3D x86_cpu_get_supported_feature_word(w, cpu->migratable); --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 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 1488213866616556.8535231018406; Mon, 27 Feb 2017 08:44:26 -0800 (PST) Received: from localhost ([::1]:54216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOPQ-0007YX-1C for importer@patchew.org; Mon, 27 Feb 2017 11:44:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6u-0007wE-O2 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6s-0005Cs-Iv for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6s-0005Cf-AF for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:14 -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 72D34C05AA6F; Mon, 27 Feb 2017 16:25:14 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPDHR031829; Mon, 27 Feb 2017 11:25:13 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:54 -0300 Message-Id: <20170227162501.29280-5-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-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.32]); Mon, 27 Feb 2017 16:25:14 +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] [PULL 04/11] i386: Reorganize and document CPUID initialization steps 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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" CPU runnability checks and CPU model expansion have slightly different requirements. Document the steps involved in loading a CPU model and realizing a CPU, so their requirements and purpose are clearly defined. This patch doesn't change any implementation. It just add comments, rename the x86_cpu_load_features() function for clarity (so it won't be confused with x86_cpu_load_def()), and move x86_cpu_filter_features() closer to it. Message-Id: <20170116211124.29245-2-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 102 +++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 87affbfcd6..b614887a61 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2059,7 +2059,7 @@ static void x86_cpu_parse_featurestr(const char *type= name, char *features, } } =20 -static void x86_cpu_load_features(X86CPU *cpu, Error **errp); +static void x86_cpu_expand_features(X86CPU *cpu, Error **errp); static int x86_cpu_filter_features(X86CPU *cpu); =20 /* Check for missing features that may prevent the CPU class from @@ -2082,9 +2082,9 @@ static void x86_cpu_class_check_missing_features(X86C= PUClass *xcc, =20 xc =3D X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); =20 - x86_cpu_load_features(xc, &err); + x86_cpu_expand_features(xc, &err); if (err) { - /* Errors at x86_cpu_load_features should never happen, + /* Errors at x86_cpu_expand_features should never happen, * but in case it does, just report the model as not * runnable at all using the "type" property. */ @@ -2245,31 +2245,6 @@ static uint32_t x86_cpu_get_supported_feature_word(F= eatureWord w, return r; } =20 -/* - * Filters CPU feature words based on host availability of each feature. - * - * Returns: 0 if all flags are supported by the host, non-zero otherwise. - */ -static int x86_cpu_filter_features(X86CPU *cpu) -{ - CPUX86State *env =3D &cpu->env; - FeatureWord w; - int rv =3D 0; - - for (w =3D 0; w < FEATURE_WORDS; w++) { - uint32_t host_feat =3D - x86_cpu_get_supported_feature_word(w, false); - uint32_t requested_features =3D env->features[w]; - env->features[w] &=3D host_feat; - cpu->filtered_features[w] =3D requested_features & ~env->features[= w]; - if (cpu->filtered_features[w]) { - rv =3D 1; - } - } - - return rv; -} - static void x86_cpu_report_filtered_features(X86CPU *cpu) { FeatureWord w; @@ -3093,8 +3068,47 @@ static void x86_cpu_enable_xsave_components(X86CPU *= cpu) env->features[FEAT_XSAVE_COMP_HI] =3D mask >> 32; } =20 -/* Load CPUID data based on configured features */ -static void x86_cpu_load_features(X86CPU *cpu, Error **errp) +/***** Steps involved on loading and filtering CPUID data + * + * When initializing and realizing a CPU object, the steps + * involved in setting up CPUID data are: + * + * 1) Loading CPU model definition (X86CPUDefinition). This is + * implemented by x86_cpu_load_def() and should be completely + * transparent, as it is done automatically by instance_init. + * No code should need to look at X86CPUDefinition structs + * outside instance_init. + * + * 2) CPU expansion. This is done by realize before CPUID + * filtering, and will make sure host/accelerator data is + * loaded for CPU models that depend on host capabilities + * (e.g. "host"). Done by x86_cpu_expand_features(). + * + * 3) CPUID filtering. This initializes extra data related to + * CPUID, and checks if the host supports all capabilities + * required by the CPU. Runnability of a CPU model is + * determined at this step. Done by x86_cpu_filter_features(). + * + * Some operations don't require all steps to be performed. + * More precisely: + * + * - CPU instance creation (instance_init) will run only CPU + * model loading. CPU expansion can't run at instance_init-time + * because host/accelerator data may be not available yet. + * - CPU realization will perform both CPU model expansion and CPUID + * filtering, and return an error in case one of them fails. + * - query-cpu-definitions needs to run all 3 steps. It needs + * to run CPUID filtering, as the 'unavailable-features' + * field is set based on the filtering results. + * - The query-cpu-model-expansion QMP command only needs to run + * CPU model loading and CPU expansion. It should not filter + * any CPUID data based on host capabilities. + */ + +/* Expand CPU configuration data, based on configured features + * and host/accelerator capabilities when appropriate. + */ +static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) { CPUX86State *env =3D &cpu->env; FeatureWord w; @@ -3171,6 +3185,32 @@ out: } } =20 +/* + * Finishes initialization of CPUID data, filters CPU feature + * words based on host availability of each feature. + * + * Returns: 0 if all flags are supported by the host, non-zero otherwise. + */ +static int x86_cpu_filter_features(X86CPU *cpu) +{ + CPUX86State *env =3D &cpu->env; + FeatureWord w; + int rv =3D 0; + + for (w =3D 0; w < FEATURE_WORDS; w++) { + uint32_t host_feat =3D + x86_cpu_get_supported_feature_word(w, false); + uint32_t requested_features =3D env->features[w]; + env->features[w] &=3D host_feat; + cpu->filtered_features[w] =3D requested_features & ~env->features[= w]; + if (cpu->filtered_features[w]) { + rv =3D 1; + } + } + + return rv; +} + #define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_= 1 && \ (env)->cpuid_vendor2 =3D=3D CPUID_VENDOR_INTEL_= 2 && \ (env)->cpuid_vendor3 =3D=3D CPUID_VENDOR_INTEL_= 3) @@ -3198,7 +3238,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) return; } =20 - x86_cpu_load_features(cpu, &local_err); + x86_cpu_expand_features(cpu, &local_err); if (local_err) { goto out; } --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 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 148821307816178.03859213089208; Mon, 27 Feb 2017 08:31:18 -0800 (PST) Received: from localhost ([::1]:54148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOCi-0004VS-TF for importer@patchew.org; Mon, 27 Feb 2017 11:31:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6v-0007xB-LR for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6u-0005DH-EJ for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34144) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6u-0005D4-8V for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:16 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 4E5194E4CF; Mon, 27 Feb 2017 16:25:16 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPFH1022167; Mon, 27 Feb 2017 11:25:15 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:55 -0300 Message-Id: <20170227162501.29280-6-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 27 Feb 2017 16:25:16 +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] [PULL 05/11] qapi-schema: Comment about full expansion of non-migration-safe models 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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" Add a note warning that static expansion may not be 100% accurate when the CPU model is not migration-safe. This will be the case on x86 when expansing the "host" CPU model, because there are "host" features that can't have a migration-safe representation (e.g. "host-cache-info"). Message-Id: <20170116211124.29245-3-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost --- qapi-schema.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 150ee98e9e..2051c46cfc 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4274,6 +4274,15 @@ # migration-safe, but allows tooling to get an insight and work with # model details. # +# Note: When a non-migration-safe CPU model is expanded in static mode, so= me +# features enabled by the CPU model may be omitted, because they can't be +# implemented by a static CPU model definition (e.g. cache info passthroug= h and +# PMU passthrough in x86). If you need an accurate representation of the +# features enabled by a non-migration-safe CPU model, use @full. If you ne= ed a +# static representation that will keep ABI compatibility even when changin= g QEMU +# version or machine-type, use @static (but keep in mind that some feature= s may +# be omitted). +# # Since: 2.8.0 ## { 'enum': 'CpuModelExpansionType', --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 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 1488213361264418.6069047008705; Mon, 27 Feb 2017 08:36:01 -0800 (PST) Received: from localhost ([::1]:54172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOHG-0008Fc-Nd for importer@patchew.org; Mon, 27 Feb 2017 11:35:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6x-0007zR-L2 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6w-0005Dy-9w for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6w-0005Da-1K for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:18 -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 3F3664E4D8; Mon, 27 Feb 2017 16:25:18 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPHwB031876; Mon, 27 Feb 2017 11:25:17 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:56 -0300 Message-Id: <20170227162501.29280-7-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-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.38]); Mon, 27 Feb 2017 16:25:18 +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] [PULL 06/11] 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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. Message-Id: <20170222183919.11928-2-ehabkost@redhat.com> Tested-by: Richard W.M. Jones Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- 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 b614887a61..a53fafa205 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 @@ -3820,6 +3837,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 Sun Feb 8 13:19:51 2026 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 1488214052886727.5280558469273; Mon, 27 Feb 2017 08:47:32 -0800 (PST) Received: from localhost ([::1]:54241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOSR-0001jl-Dq for importer@patchew.org; Mon, 27 Feb 2017 11:47:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO6z-00080q-1m for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO6y-0005Ed-4f for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46772) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6x-0005EL-V8 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:20 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 1FA3783F45; Mon, 27 Feb 2017 16:25:20 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPIj0022206; Mon, 27 Feb 2017 11:25:19 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:57 -0300 Message-Id: <20170227162501.29280-8-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Feb 2017 16:25:20 +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] [PULL 07/11] 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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. Message-Id: <20170222183919.11928-3-ehabkost@redhat.com> Tested-by: Richard W.M. Jones Tested-by: Jiri Denemark 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 a53fafa205..ec22ed41b2 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 Sun Feb 8 13:19:51 2026 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 1488214270209574.679577640165; Mon, 27 Feb 2017 08:51:10 -0800 (PST) Received: from localhost ([::1]:54267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOVv-0004fu-L5 for importer@patchew.org; Mon, 27 Feb 2017 11:51:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO75-00086J-4E for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO70-0005G5-2C for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO6z-0005Fo-PL for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:21 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E951481250; Mon, 27 Feb 2017 16:25:21 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 711942D655; Mon, 27 Feb 2017 16:25:21 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:58 -0300 Message-Id: <20170227162501.29280-9-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Feb 2017 16:25:22 +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] [PULL 08/11] 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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". Message-Id: <20170222183919.11928-4-ehabkost@redhat.com> Tested-by: Richard W.M. Jones Tested-by: Jiri Denemark 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 ec22ed41b2..366253cd4c 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 @@ -2185,7 +2180,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 @@ -3683,7 +3678,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 From nobody Sun Feb 8 13:19:51 2026 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 1488214613694957.3355983779348; Mon, 27 Feb 2017 08:56:53 -0800 (PST) Received: from localhost ([::1]:54299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciObT-0001J9-A6 for importer@patchew.org; Mon, 27 Feb 2017 11:56:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO75-00086H-3Q for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO71-0005Gv-UZ for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO71-0005GS-Le for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:23 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 D0DC87E9D8; Mon, 27 Feb 2017 16:25:23 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPMne022272; Mon, 27 Feb 2017 11:25:23 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:24:59 -0300 Message-Id: <20170227162501.29280-10-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Feb 2017 16:25:23 +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] [PULL 09/11] i386: Define static "base" 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: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson 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" The query-cpu-model-expand QMP command needs at least one static model, to allow the "static" expansion mode to be implemented. Instead of defining static versions of every CPU model, define a "base" CPU model that has absolutely no feature flag enabled. Despite having no CPUID data set at all, "-cpu base" is even a functional CPU: * It can boot a Slackware Linux 1.01 image with a Linux 0.99.12 kernel[1]. * It is even possible to boot[2] a modern Fedora x86_64 guest by manually enabling the following CPU features: -cpu base,+lm,+msr,+pae,+fpu,+cx8,+cmov,+sse,+sse2,+fxsr [1] http://www.qemu-advent-calendar.org/2014/#day-1 [2] This is what can be seen in the guest: [root@localhost ~]# cat /proc/cpuinfo processor : 0 vendor_id : unknown cpu family : 0 model : 0 model name : 00/00 stepping : 0 physical id : 0 siblings : 1 core id : 0 cpu cores : 1 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 1 wp : yes flags : fpu msr pae cx8 cmov fxsr sse sse2 lm nopl bugs : bogomips : 5832.70 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: [root@localhost ~]# x86info -v -a x86info v1.30. Dave Jones 2001-2011 Feedback to . No TSC, MHz calculation cannot be performed. Unknown vendor (0) MP Table: Family: 0 Model: 0 Stepping: 0 CPU Model (x86info's best guess): eax in: 0x00000000, eax =3D 00000001 ebx =3D 00000000 ecx =3D 00000000 = edx =3D 00000000 eax in: 0x00000001, eax =3D 00000000 ebx =3D 00000800 ecx =3D 00000000 = edx =3D 07008161 eax in: 0x80000000, eax =3D 80000001 ebx =3D 00000000 ecx =3D 00000000 = edx =3D 00000000 eax in: 0x80000001, eax =3D 00000000 ebx =3D 00000000 ecx =3D 00000000 = edx =3D 20000000 Feature flags: fpu Onboard FPU msr Model-Specific Registers pae Physical Address Extensions cx8 CMPXCHG8 instruction cmov CMOV instruction fxsr FXSAVE and FXRSTOR instructions sse SSE support sse2 SSE2 support Long NOPs supported: yes Address sizes : 0 bits physical, 0 bits virtual 0MHz processor (estimate). running at an estimated 0MHz [root@localhost ~]# Message-Id: <20170222190029.17243-2-ehabkost@redhat.com> Reviewed-by: David Hildenbrand Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- target/i386/cpu-qom.h | 2 ++ target/i386/cpu.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/target/i386/cpu-qom.h b/target/i386/cpu-qom.h index f6c704c3a9..c2205e6077 100644 --- a/target/i386/cpu-qom.h +++ b/target/i386/cpu-qom.h @@ -50,6 +50,7 @@ typedef struct X86CPUDefinition X86CPUDefinition; * @kvm_required: Whether CPU model requires KVM to be enabled. * @ordering: Ordering on the "-cpu help" CPU model list. * @migration_safe: See CpuDefinitionInfo::migration_safe + * @static_model: See CpuDefinitionInfo::static * @parent_realize: The parent class' realize handler. * @parent_reset: The parent class' reset handler. * @@ -68,6 +69,7 @@ typedef struct X86CPUClass { bool kvm_required; int ordering; bool migration_safe; + bool static_model; =20 /* Optional description of CPU model. * If unavailable, cpu_def->model_id is used */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 366253cd4c..0a71594445 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2229,6 +2229,7 @@ static void x86_cpu_definition_entry(gpointer data, g= pointer user_data) info->q_typename =3D g_strdup(object_class_get_name(oc)); info->migration_safe =3D cc->migration_safe; info->has_migration_safe =3D true; + info->q_static =3D cc->static_model; =20 entry =3D g_malloc0(sizeof(*entry)); entry->value =3D info; @@ -3835,6 +3836,24 @@ static const TypeInfo x86_cpu_type_info =3D { .class_init =3D x86_cpu_common_class_init, }; =20 + +/* "base" CPU model, used by query-cpu-model-expansion */ +static void x86_cpu_base_class_init(ObjectClass *oc, void *data) +{ + X86CPUClass *xcc =3D X86_CPU_CLASS(oc); + + xcc->static_model =3D true; + xcc->migration_safe =3D true; + xcc->model_description =3D "base CPU model type with no features enabl= ed"; + xcc->ordering =3D 8; +} + +static const TypeInfo x86_base_cpu_type_info =3D { + .name =3D X86_CPU_TYPE_NAME("base"), + .parent =3D TYPE_X86_CPU, + .class_init =3D x86_cpu_base_class_init, +}; + static void x86_cpu_register_types(void) { int i; @@ -3844,6 +3863,7 @@ static void x86_cpu_register_types(void) x86_register_cpudef_type(&builtin_x86_defs[i]); } type_register_static(&max_x86_cpu_type_info); + type_register_static(&x86_base_cpu_type_info); #ifdef CONFIG_KVM type_register_static(&host_x86_cpu_type_info); #endif --=20 2.11.0.259.g40922b1 From nobody Sun Feb 8 13:19:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1488212916993820.6024750960347; Mon, 27 Feb 2017 08:28:36 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPQec028327; Mon, 27 Feb 2017 11:25:27 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1RGPPbW019549 for ; Mon, 27 Feb 2017 11:25:25 -0500 Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPOlo022289; Mon, 27 Feb 2017 11:25:25 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:25:00 -0300 Message-Id: <20170227162501.29280-11-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com, Paolo Bonzini , Jiri Denemark , qemu-devel@nongnu.org, Richard Henderson Subject: [libvirt] [PULL 10/11] i386: Implement query-cpu-model-expansion QMP command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Implement query-cpu-model-expansion for target-i386. This should meet all the requirements while being simple. In the case of static expansion, it will use the new "base" CPU model, and in the case of full expansion, it will keep the original CPU model name+props, and append extra properties. A future follow-up should improve the implementation of type=3Dfull, so that it returns more detailed data, including every writable QOM property in the CPU object. Cc: libvir-list@redhat.com Cc: Jiri Denemark Message-Id: <20170222190029.17243-3-ehabkost@redhat.com> Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- monitor.c | 4 +- target/i386/cpu.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 193 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index f8f4a07cfb..b68944d93c 100644 --- a/monitor.c +++ b/monitor.c @@ -984,8 +984,10 @@ static void qmp_unregister_commands_hack(void) #ifndef TARGET_ARM qmp_unregister_command("query-gic-capabilities"); #endif -#if !defined(TARGET_S390X) +#if !defined(TARGET_S390X) && !defined(TARGET_I386) qmp_unregister_command("query-cpu-model-expansion"); +#endif +#if !defined(TARGET_S390X) qmp_unregister_command("query-cpu-model-baseline"); qmp_unregister_command("query-cpu-model-comparison"); #endif diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0a71594445..139b7ea12e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -29,10 +29,16 @@ #include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qbool.h" +#include "qapi/qmp/qint.h" +#include "qapi/qmp/qfloat.h" =20 #include "qapi-types.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "qom/qom-qobject.h" #include "sysemu/arch_init.h" =20 #if defined(CONFIG_KVM) @@ -2288,7 +2294,7 @@ static void x86_cpu_apply_props(X86CPU *cpu, PropValu= e *props) } } =20 -/* Load data from X86CPUDefinition +/* Load data from X86CPUDefinition into a X86CPU object */ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **e= rrp) { @@ -2297,6 +2303,11 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefi= nition *def, Error **errp) char host_vendor[CPUID_VENDOR_SZ + 1]; FeatureWord w; =20 + /*NOTE: any property set by this function should be returned by + * x86_cpu_static_props(), so static expansion of + * query-cpu-model-expansion is always complete. + */ + /* CPU models only set _minimum_ values for level/xlevel: */ object_property_set_int(OBJECT(cpu), def->level, "min-level", errp); object_property_set_int(OBJECT(cpu), def->xlevel, "min-xlevel", errp); @@ -2341,6 +2352,184 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDef= inition *def, Error **errp) =20 } =20 +/* Return a QDict containing keys for all properties that can be included + * in static expansion of CPU models. All properties set by x86_cpu_load_d= ef() + * must be included in the dictionary. + */ +static QDict *x86_cpu_static_props(void) +{ + FeatureWord w; + int i; + static const char *props[] =3D { + "min-level", + "min-xlevel", + "family", + "model", + "stepping", + "model-id", + "vendor", + "lmce", + NULL, + }; + static QDict *d; + + if (d) { + return d; + } + + d =3D qdict_new(); + for (i =3D 0; props[i]; i++) { + qdict_put_obj(d, props[i], qnull()); + } + + for (w =3D 0; w < FEATURE_WORDS; w++) { + FeatureWordInfo *fi =3D &feature_word_info[w]; + int bit; + for (bit =3D 0; bit < 32; bit++) { + if (!fi->feat_names[bit]) { + continue; + } + qdict_put_obj(d, fi->feat_names[bit], qnull()); + } + } + + return d; +} + +/* Add an entry to @props dict, with the value for property. */ +static void x86_cpu_expand_prop(X86CPU *cpu, QDict *props, const char *pro= p) +{ + QObject *value =3D object_property_get_qobject(OBJECT(cpu), prop, + &error_abort); + + qdict_put_obj(props, prop, value); +} + +/* Convert CPU model data from X86CPU object to a property dictionary + * that can recreate exactly the same CPU model. + */ +static void x86_cpu_to_dict(X86CPU *cpu, QDict *props) +{ + QDict *sprops =3D x86_cpu_static_props(); + const QDictEntry *e; + + for (e =3D qdict_first(sprops); e; e =3D qdict_next(sprops, e)) { + const char *prop =3D qdict_entry_key(e); + x86_cpu_expand_prop(cpu, props, prop); + } +} + +static void object_apply_props(Object *obj, QDict *props, Error **errp) +{ + const QDictEntry *prop; + Error *err =3D NULL; + + for (prop =3D qdict_first(props); prop; prop =3D qdict_next(props, pro= p)) { + object_property_set_qobject(obj, qdict_entry_value(prop), + qdict_entry_key(prop), &err); + if (err) { + break; + } + } + + error_propagate(errp, err); +} + +/* Create X86CPU object according to model+props specification */ +static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error *= *errp) +{ + X86CPU *xc =3D NULL; + X86CPUClass *xcc; + Error *err =3D NULL; + + xcc =3D X86_CPU_CLASS(cpu_class_by_name(TYPE_X86_CPU, model)); + if (xcc =3D=3D NULL) { + error_setg(&err, "CPU model '%s' not found", model); + goto out; + } + + xc =3D X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); + if (props) { + object_apply_props(OBJECT(xc), props, &err); + if (err) { + goto out; + } + } + + x86_cpu_expand_features(xc, &err); + if (err) { + goto out; + } + +out: + if (err) { + error_propagate(errp, err); + object_unref(OBJECT(xc)); + xc =3D NULL; + } + return xc; +} + +CpuModelExpansionInfo * +arch_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ + X86CPU *xc =3D NULL; + Error *err =3D NULL; + CpuModelExpansionInfo *ret =3D g_new0(CpuModelExpansionInfo, 1); + QDict *props =3D NULL; + const char *base_name; + + xc =3D x86_cpu_from_model(model->name, + model->has_props ? + qobject_to_qdict(model->props) : + NULL, &err); + if (err) { + goto out; + } + + + switch (type) { + case CPU_MODEL_EXPANSION_TYPE_STATIC: + /* Static expansion will be based on "base" only */ + base_name =3D "base"; + break; + case CPU_MODEL_EXPANSION_TYPE_FULL: + /* As we don't return every single property, full expansion needs + * to keep the original model name+props, and add extra + * properties on top of that. + */ + base_name =3D model->name; + if (model->has_props && model->props) { + props =3D qdict_clone_shallow(qobject_to_qdict(model->props)); + } + break; + default: + error_setg(&err, "Unsupportted expansion type"); + goto out; + } + + if (!props) { + props =3D qdict_new(); + } + x86_cpu_to_dict(xc, props); + + ret->model =3D g_new0(CpuModelInfo, 1); + ret->model->name =3D g_strdup(base_name); + ret->model->props =3D QOBJECT(props); + ret->model->has_props =3D true; + +out: + object_unref(OBJECT(xc)); + if (err) { + error_propagate(errp, err); + qapi_free_CpuModelExpansionInfo(ret); + ret =3D NULL; + } + return ret; +} + X86CPU *cpu_x86_init(const char *cpu_model) { return X86_CPU(cpu_generic_init(TYPE_X86_CPU, cpu_model)); --=20 2.11.0.259.g40922b1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 13:19:52 2026 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 1488214538334343.21588659240683; Mon, 27 Feb 2017 08:55:38 -0800 (PST) Received: from localhost ([::1]:54284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciOaH-0000Dw-2u for importer@patchew.org; Mon, 27 Feb 2017 11:55:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciO76-00087t-Pm for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciO75-0005JM-Nx for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciO75-0005J3-Hk for qemu-devel@nongnu.org; Mon, 27 Feb 2017 11:25:27 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 AA2EE8123E; Mon, 27 Feb 2017 16:25:27 +0000 (UTC) Received: from localhost (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RGPQkl022306; Mon, 27 Feb 2017 11:25:27 -0500 From: Eduardo Habkost To: Peter Maydell Date: Mon, 27 Feb 2017 13:25:01 -0300 Message-Id: <20170227162501.29280-12-ehabkost@redhat.com> In-Reply-To: <20170227162501.29280-1-ehabkost@redhat.com> References: <20170227162501.29280-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Feb 2017 16:25:27 +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] [PULL 11/11] i386: Improve query-cpu-model-expansion full mode 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: , Cc: Paolo Bonzini , Jiri Denemark , qemu-devel@nongnu.org, Richard Henderson 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" This keeps the same results on type=3Dstatic expansion, but make type=3Dfull expansion return every single QOM property on the CPU object that have a different value from the "base' CPU model, plus all the CPU feature flag properties. Cc: Jiri Denemark Message-Id: <20170222190029.17243-4-ehabkost@redhat.com> Tested-by: Jiri Denemark Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 139b7ea12e..89421c893b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2419,6 +2419,34 @@ static void x86_cpu_to_dict(X86CPU *cpu, QDict *prop= s) } } =20 +/* Convert CPU model data from X86CPU object to a property dictionary + * that can recreate exactly the same CPU model, including every + * writeable QOM property. + */ +static void x86_cpu_to_dict_full(X86CPU *cpu, QDict *props) +{ + ObjectPropertyIterator iter; + ObjectProperty *prop; + + object_property_iter_init(&iter, OBJECT(cpu)); + while ((prop =3D object_property_iter_next(&iter))) { + /* skip read-only or write-only properties */ + if (!prop->get || !prop->set) { + continue; + } + + /* "hotplugged" is the only property that is configurable + * on the command-line but will be set differently on CPUs + * created using "-cpu ... -smp ..." and by CPUs created + * on the fly by x86_cpu_from_model() for querying. Skip it. + */ + if (!strcmp(prop->name, "hotplugged")) { + continue; + } + x86_cpu_expand_prop(cpu, props, prop->name); + } +} + static void object_apply_props(Object *obj, QDict *props, Error **errp) { const QDictEntry *prop; @@ -2489,11 +2517,13 @@ arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, goto out; } =20 + props =3D qdict_new(); =20 switch (type) { case CPU_MODEL_EXPANSION_TYPE_STATIC: /* Static expansion will be based on "base" only */ base_name =3D "base"; + x86_cpu_to_dict(xc, props); break; case CPU_MODEL_EXPANSION_TYPE_FULL: /* As we don't return every single property, full expansion needs @@ -2501,9 +2531,7 @@ arch_query_cpu_model_expansion(CpuModelExpansionType = type, * properties on top of that. */ base_name =3D model->name; - if (model->has_props && model->props) { - props =3D qdict_clone_shallow(qobject_to_qdict(model->props)); - } + x86_cpu_to_dict_full(xc, props); break; default: error_setg(&err, "Unsupportted expansion type"); --=20 2.11.0.259.g40922b1