From nobody Mon May 6 00:51:38 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 149062628545745.17188432069611; Mon, 27 Mar 2017 07:51:25 -0700 (PDT) Received: from localhost ([::1]:47136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVzQ-0005kk-FE for importer@patchew.org; Mon, 27 Mar 2017 10:51:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVwW-00040x-Kn for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csVwU-0005lh-NS for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33728) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csVwU-0005lI-Ev for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67C733DBC7; Mon, 27 Mar 2017 14:48:21 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id E935B171AF; Mon, 27 Mar 2017 14:48:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 67C733DBC7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 67C733DBC7 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 11:48:14 -0300 Message-Id: <20170327144815.8043-2-ehabkost@redhat.com> In-Reply-To: <20170327144815.8043-1-ehabkost@redhat.com> References: <20170327144815.8043-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 27 Mar 2017 14:48:21 +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 for-2.9 v2 1/2] i386: Replace uint32_t* with FeatureWord on feature getter/setter 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: "Collin L . Walling" , "Jason J . Herne" , Igor Mammedov , Paolo Bonzini , Jiri Denemark , 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 passing a pointer to the feature property getter and setter functions, pass a FeatureWord enum so they can perform other actions related to the feature flag. This will be used to add a new "user_features" field to keep track of features that were explicitly set by the user. Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Tested-by: Jiri Denemark --- target/i386/cpu.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7aa762245a..feefa5b8a4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3692,15 +3692,17 @@ static void x86_cpu_unrealizefn(DeviceState *dev, E= rror **errp) } =20 typedef struct BitProperty { - uint32_t *ptr; + FeatureWord w; uint32_t mask; } BitProperty; =20 static void x86_cpu_get_bit_prop(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + X86CPU *cpu =3D X86_CPU(obj); BitProperty *fp =3D opaque; - bool value =3D (*fp->ptr & fp->mask) =3D=3D fp->mask; + uint32_t f =3D cpu->env.features[fp->w]; + bool value =3D (f & fp->mask) =3D=3D fp->mask; visit_type_bool(v, name, &value, errp); } =20 @@ -3708,6 +3710,7 @@ static void x86_cpu_set_bit_prop(Object *obj, Visitor= *v, const char *name, void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); + X86CPU *cpu =3D X86_CPU(obj); BitProperty *fp =3D opaque; Error *local_err =3D NULL; bool value; @@ -3724,9 +3727,9 @@ static void x86_cpu_set_bit_prop(Object *obj, Visitor= *v, const char *name, } =20 if (value) { - *fp->ptr |=3D fp->mask; + cpu->env.features[fp->w] |=3D fp->mask; } else { - *fp->ptr &=3D ~fp->mask; + cpu->env.features[fp->w] &=3D ~fp->mask; } } =20 @@ -3745,7 +3748,7 @@ static void x86_cpu_release_bit_prop(Object *obj, con= st char *name, */ static void x86_cpu_register_bit_prop(X86CPU *cpu, const char *prop_name, - uint32_t *field, + FeatureWord w, int bitnr) { BitProperty *fp; @@ -3755,11 +3758,11 @@ static void x86_cpu_register_bit_prop(X86CPU *cpu, op =3D object_property_find(OBJECT(cpu), prop_name, NULL); if (op) { fp =3D op->opaque; - assert(fp->ptr =3D=3D field); + assert(fp->w =3D=3D w); fp->mask |=3D mask; } else { fp =3D g_new0(BitProperty, 1); - fp->ptr =3D field; + fp->w =3D w; fp->mask =3D mask; object_property_add(OBJECT(cpu), prop_name, "bool", x86_cpu_get_bit_prop, @@ -3787,7 +3790,7 @@ static void x86_cpu_register_feature_bit_props(X86CPU= *cpu, /* aliases don't use "|" delimiters anymore, they are registered * manually using object_property_add_alias() */ assert(!strchr(name, '|')); - x86_cpu_register_bit_prop(cpu, name, &cpu->env.features[w], bitnr); + x86_cpu_register_bit_prop(cpu, name, w, bitnr); } =20 static GuestPanicInformation *x86_cpu_get_crash_info(CPUState *cs) --=20 2.11.0.259.g40922b1 From nobody Mon May 6 00:51:38 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 149062618060084.18655298711201; Mon, 27 Mar 2017 07:49:40 -0700 (PDT) Received: from localhost ([::1]:47120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVxj-0004b7-Fs for importer@patchew.org; Mon, 27 Mar 2017 10:49:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVwY-000416-8d for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csVwW-0005mW-Kn for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46650) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csVwW-0005lu-By for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:48:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A73F72AE2; Mon, 27 Mar 2017 14:48:23 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEA7518BB8; Mon, 27 Mar 2017 14:48:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A73F72AE2 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4A73F72AE2 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 11:48:15 -0300 Message-Id: <20170327144815.8043-3-ehabkost@redhat.com> In-Reply-To: <20170327144815.8043-1-ehabkost@redhat.com> References: <20170327144815.8043-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 27 Mar 2017 14:48: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] [PATCH for-2.9 v2 2/2] i386: Don't override -cpu options on -cpu host/max 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: "Collin L . Walling" , "Jason J . Herne" , Igor Mammedov , Paolo Bonzini , Jiri Denemark , 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 existing code for "host" and "max" CPU models overrides every single feature in the CPU object at realize time, even the ones that were explicitly enabled or disabled by the user using "feat=3Don" or "feat=3Doff", while features set using +feat/-feat are kept. This means "-cpu host,+invtsc" works as expected, while "-cpu host,invtsc=3Don" doesn't. This was a known bug, already documented in a comment inside x86_cpu_expand_features(). What makes this bug worse now is that libvirt 3.0.0 and newer now use "feat=3Don|off" instead of +feat/-feat when it detects a QEMU version that supports it (see libvirt commit d47db7b16dd5422c7e487c8c8ee5b181a2f9cd66). Change the feature property getter/setter to set a env->user_features field, to keep track of features that were explicitly changed using QOM properties. Then make the max_features code not override user features when handling "-cpu host" and "-cpu max". This will also allow us to remove the plus_features/minus_features hack in the future, but I plan to do that after 2.9.0 is released. Reported-by: Jiri Denemark Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Tested-by: Jiri Denemark --- Changes v1 -> v2: * Don't clear existing bits on env->features (they are already supposed to be all zeroes) (Igor) * Fix typo on comment (Igor) * Moved feature word getter/setter parameter changes to separate patch (Igor) --- target/i386/cpu.h | 2 ++ target/i386/cpu.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 07401ad9fe..c4602ca80d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1147,6 +1147,8 @@ typedef struct CPUX86State { uint32_t cpuid_vendor3; uint32_t cpuid_version; FeatureWordArray features; + /* Features that were explicitly enabled/disabled */ + FeatureWordArray user_features; uint32_t cpuid_model[12]; =20 /* MTRRs */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index feefa5b8a4..13c0985f11 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3373,15 +3373,19 @@ static void x86_cpu_expand_features(X86CPU *cpu, Er= ror **errp) GList *l; Error *local_err =3D NULL; =20 - /*TODO: cpu->max_features incorrectly overwrites features - * set using "feat=3Don|off". Once we fix this, we can convert + /*TODO: Now cpu->max_features doesn't overwrite features + * set using QOM properties, and we can convert * plus_features & minus_features to global properties * inside x86_cpu_parse_featurestr() too. */ 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); + /* Override only features that weren't set explicitly + * by the user. + */ + env->features[w] |=3D + x86_cpu_get_supported_feature_word(w, cpu->migratable) & + ~env->user_features[w]; } } =20 @@ -3731,6 +3735,7 @@ static void x86_cpu_set_bit_prop(Object *obj, Visitor= *v, const char *name, } else { cpu->env.features[fp->w] &=3D ~fp->mask; } + cpu->env.user_features[fp->w] |=3D fp->mask; } =20 static void x86_cpu_release_bit_prop(Object *obj, const char *name, --=20 2.11.0.259.g40922b1