From patchwork Fri Aug 18 10:08:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 9908241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9AFBD600CC for ; Fri, 18 Aug 2017 10:17:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BFD528BA7 for ; Fri, 18 Aug 2017 10:17:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80DA328C83; Fri, 18 Aug 2017 10:17:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A9A3F28BA7 for ; Fri, 18 Aug 2017 10:17:32 +0000 (UTC) Received: from localhost ([::1]:40650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dieLL-0002iu-Gs for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Aug 2017 06:17:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dieDH-0003wa-Bd for qemu-devel@nongnu.org; Fri, 18 Aug 2017 06:09:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dieDF-0000XO-Sz for qemu-devel@nongnu.org; Fri, 18 Aug 2017 06:09:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dieDF-0000X0-KM for qemu-devel@nongnu.org; Fri, 18 Aug 2017 06:09:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACA425D697; Fri, 18 Aug 2017 10:09:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ACA425D697 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60BF15D743; Fri, 18 Aug 2017 10:09:07 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 12:08:37 +0200 Message-Id: <1503050939-227939-6-git-send-email-imammedo@redhat.com> In-Reply-To: <1503050939-227939-1-git-send-email-imammedo@redhat.com> References: <1503050939-227939-1-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 18 Aug 2017 10:09: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] [PATCH for-2.11 05/27] target-i386: cpu: convert plus/minus properties to global properties 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Mark Cave-Ayland , Eduardo Habkost , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Since (commit d4a606b3 i386: Don't override -cpu options on -cpu host/max) it became possible to delete hack where it was necessary to postpone applying plus/minus features to realize time after max_features were applied to keep legacy +-feat override semantics. with above commit it's possible to convert +-feat to a set of GlobalProperty items and keep +-feat override semantics, these properties should be added to global list at the end to override properties that were set with feat=on|off syntax. Signed-off-by: Igor Mammedov --- CC: Richard Henderson CC: Eduardo Habkost CC: Mark Cave-Ayland CC: Artyom Tarasenko CC: Philippe Mathieu-Daudé --- target/i386/cpu.c | 108 ++++++++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 68 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ddc45ab..84f552d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2058,23 +2058,32 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr) return feature_word_info[w].feat_names[bitnr]; } -/* Compatibily hack to maintain legacy +-feat semantic, - * where +-feat overwrites any feature set by - * feat=on|feat even if the later is parsed after +-feat - * (i.e. "-x2apic,x2apic=on" will result in x2apic disabled) - */ -static GList *plus_features, *minus_features; - static gint compare_string(gconstpointer a, gconstpointer b) { return g_strcmp0(a, b); } -/* Parse "+feature,-feature,feature=foo" CPU feature string - */ +static void +cpu_add_feat_as_prop(const char *typename, const char *name, const char *val) +{ + GlobalProperty *prop = g_new0(typeof(*prop), 1); + prop->driver = typename; + prop->property = g_strdup(name); + prop->value = g_strdup(val); + prop->errp = &error_fatal; + qdev_prop_register_global(prop); +} + +/* Parse "+feature,-feature,feature=foo" CPU feature string */ static void x86_cpu_parse_featurestr(const char *typename, char *features, Error **errp) { + /* Compatibily hack to maintain legacy +-feat semantic, + * where +-feat overwrites any feature set by + * feat=on|feat even if the later is parsed after +-feat + * (i.e. "-x2apic,x2apic=on" will result in x2apic disabled) + */ + GList *l, *plus_features = NULL, *minus_features = NULL; char *featurestr; /* Single 'key=value" string being parsed */ static bool cpu_globals_initialized; bool ambiguous = false; @@ -2095,7 +2104,6 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features, const char *val = NULL; char *eq = NULL; char num[32]; - GlobalProperty *prop; /* Compatibility syntax: */ if (featurestr[0] == '+') { @@ -2147,21 +2155,32 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features, name = "tsc-frequency"; } - prop = g_new0(typeof(*prop), 1); - prop->driver = typename; - prop->property = g_strdup(name); - prop->value = g_strdup(val); - prop->errp = &error_fatal; - qdev_prop_register_global(prop); + cpu_add_feat_as_prop(typename, name, val); } if (ambiguous) { warn_report("Compatibility of ambiguous CPU model " "strings won't be kept on future QEMU versions"); } + + for (l = plus_features; l; l = l->next) { + const char *name = l->data; + cpu_add_feat_as_prop(typename, name, "on"); + } + if (plus_features) { + g_list_free_full(plus_features, g_free); + } + + for (l = minus_features; l; l = l->next) { + const char *name = l->data; + cpu_add_feat_as_prop(typename, name, "off"); + } + if (minus_features) { + g_list_free_full(minus_features, g_free); + } } -static void x86_cpu_expand_features(X86CPU *cpu, Error **errp); +static void x86_cpu_expand_features(X86CPU *cpu); static int x86_cpu_filter_features(X86CPU *cpu); /* Check for missing features that may prevent the CPU class from @@ -2172,7 +2191,6 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, { X86CPU *xc; FeatureWord w; - Error *err = NULL; strList **next = missing_feats; if (xcc->kvm_required && !kvm_enabled()) { @@ -2184,18 +2202,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); - x86_cpu_expand_features(xc, &err); - if (err) { - /* 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. - */ - strList *new = g_new0(strList, 1); - new->value = g_strdup("type"); - *next = new; - next = &new->next; - } - + x86_cpu_expand_features(xc); x86_cpu_filter_features(xc); for (w = 0; w < FEATURE_WORDS; w++) { @@ -2559,11 +2566,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) } } - x86_cpu_expand_features(xc, &err); - if (err) { - goto out; - } - + x86_cpu_expand_features(xc); out: if (err) { error_propagate(errp, err); @@ -3453,18 +3456,11 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu) /* Expand CPU configuration data, based on configured features * and host/accelerator capabilities when appropriate. */ -static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) +static void x86_cpu_expand_features(X86CPU *cpu) { CPUX86State *env = &cpu->env; FeatureWord w; - GList *l; - Error *local_err = NULL; - /*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 = 0; w < FEATURE_WORDS; w++) { /* Override only features that weren't set explicitly @@ -3476,22 +3472,6 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } - for (l = plus_features; l; l = l->next) { - const char *prop = l->data; - object_property_set_bool(OBJECT(cpu), true, prop, &local_err); - if (local_err) { - goto out; - } - } - - for (l = minus_features; l; l = l->next) { - const char *prop = l->data; - object_property_set_bool(OBJECT(cpu), false, prop, &local_err); - if (local_err) { - goto out; - } - } - if (!kvm_enabled() || !cpu->expose_kvm) { env->features[FEAT_KVM] = 0; } @@ -3527,11 +3507,6 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) if (env->cpuid_xlevel2 == UINT32_MAX) { env->cpuid_xlevel2 = env->cpuid_min_xlevel2; } - -out: - if (local_err != NULL) { - error_propagate(errp, local_err); - } } /* @@ -3587,10 +3562,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) return; } - x86_cpu_expand_features(cpu, &local_err); - if (local_err) { - goto out; - } + x86_cpu_expand_features(cpu); if (x86_cpu_filter_features(cpu) && (cpu->check_cpuid || cpu->enforce_cpuid)) {