From patchwork Thu Sep 29 21:14:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9357103 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 39B8B6077A for ; Thu, 29 Sep 2016 21:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26BBA29C39 for ; Thu, 29 Sep 2016 21:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B55629C48; Thu, 29 Sep 2016 21:20:34 +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 B72FB29C39 for ; Thu, 29 Sep 2016 21:20:33 +0000 (UTC) Received: from localhost ([::1]:40362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpikq-0002qL-Qm for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Sep 2016 17:20:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpigv-0007sG-IZ for qemu-devel@nongnu.org; Thu, 29 Sep 2016 17:16:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpigp-0004Rp-QV for qemu-devel@nongnu.org; Thu, 29 Sep 2016 17:16:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpigp-0004Rb-H5 for qemu-devel@nongnu.org; Thu, 29 Sep 2016 17:16:23 -0400 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 1EA86C04B316; Thu, 29 Sep 2016 21:16:23 +0000 (UTC) Received: from localhost (ovpn-116-132.phx2.redhat.com [10.3.116.132]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8TLGMtb026386; Thu, 29 Sep 2016 17:16:22 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 29 Sep 2016 18:14:56 -0300 Message-Id: <1475183699-11646-9-git-send-email-ehabkost@redhat.com> In-Reply-To: <1475183699-11646-1-git-send-email-ehabkost@redhat.com> References: <1475183699-11646-1-git-send-email-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.31]); Thu, 29 Sep 2016 21:16:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 08/11] target-i386: Move warning code outside x86_cpu_filter_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: libvir-list@redhat.com, Markus Armbruster , dahi@linux.vnet.ibm.com, Paolo Bonzini , Igor Mammedov , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP x86_cpu_filter_features() will be reused by code that shouldn't print any warning. Move the warning code to a new x86_cpu_report_filtered_features() function, and call it from x86_cpu_realizefn(). Signed-off-by: Eduardo Habkost --- Changes v3 -> v4: * Made x86_cpu_filter_features() void, make x86_cpu_report_filtered_features() return true if some features were filtered --- target-i386/cpu.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index b36388e..b25657b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2163,14 +2163,11 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, /* * 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) +static void x86_cpu_filter_features(X86CPU *cpu) { CPUX86State *env = &cpu->env; FeatureWord w; - int rv = 0; for (w = 0; w < FEATURE_WORDS; w++) { uint32_t host_feat = @@ -2178,15 +2175,22 @@ static int x86_cpu_filter_features(X86CPU *cpu) uint32_t requested_features = env->features[w]; env->features[w] &= host_feat; cpu->filtered_features[w] = requested_features & ~env->features[w]; - if (cpu->filtered_features[w]) { - if (cpu->check_cpuid || cpu->enforce_cpuid) { - report_unavailable_features(w, cpu->filtered_features[w]); - } - rv = 1; - } } +} - return rv; +/* Report list of filtered features to stderr. + * Returns true if some features were found to be filtered, false otherwise + */ +static bool x86_cpu_report_filtered_features(X86CPU *cpu) +{ + FeatureWord w; + uint32_t filtered = 0; + + for (w = 0; w < FEATURE_WORDS; w++) { + filtered |= cpu->filtered_features[w]; + report_unavailable_features(w, cpu->filtered_features[w]); + } + return filtered; } static void x86_cpu_apply_props(X86CPU *cpu, PropValue *props) @@ -3082,12 +3086,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->cpuid_xlevel2 = env->cpuid_min_xlevel2; } - if (x86_cpu_filter_features(cpu) && cpu->enforce_cpuid) { - error_setg(&local_err, - kvm_enabled() ? - "Host doesn't support requested features" : - "TCG doesn't support requested features"); - goto out; + x86_cpu_filter_features(cpu); + if (cpu->check_cpuid || cpu->enforce_cpuid) { + if (x86_cpu_report_filtered_features(cpu) && cpu->enforce_cpuid) { + error_setg(&local_err, + kvm_enabled() ? + "Host doesn't support requested features" : + "TCG doesn't support requested features"); + goto out; + } } /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on