From patchwork Thu Apr 14 20:55:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 8843021 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD307C0553 for ; Thu, 14 Apr 2016 20:56:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D03C62037C for ; Thu, 14 Apr 2016 20:56:32 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id C3ED820272 for ; Thu, 14 Apr 2016 20:56:31 +0000 (UTC) Received: from localhost ([::1]:46679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqoJS-0005eD-Vu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Apr 2016 16:56:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqoJK-0005Z4-K4 for qemu-devel@nongnu.org; Thu, 14 Apr 2016 16:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqoJH-00080b-D2 for qemu-devel@nongnu.org; Thu, 14 Apr 2016 16:56:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqoJH-00080W-5l for qemu-devel@nongnu.org; Thu, 14 Apr 2016 16:56:19 -0400 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 780FAC08E2BF; Thu, 14 Apr 2016 20:56:17 +0000 (UTC) Received: from potion (dhcp-1-215.brq.redhat.com [10.34.1.215]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u3EKuE3v020451; Thu, 14 Apr 2016 16:56:15 -0400 Received: by potion (sSMTP sendmail emulation); Thu, 14 Apr 2016 22:56:14 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: qemu-devel@nongnu.org Date: Thu, 14 Apr 2016 22:55:07 +0200 Message-Id: <1460667307-14819-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags 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 , Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP QEMU complains about -cpu host on an AMD machine: warning: host doesn't support requested feature: CPUID.80000001H:EDX [bit 0] For bits 0,1,3,4,5,6,7,8,9,12,13,14,15,16,17,23,24. Host does support them, but x86_cpu_get_migratable_flags filters unnamed features and drops these bits without realizing that they are aliases to CPUID.1H:EDX and have their names there. See https://bugzilla.redhat.com/show_bug.cgi?id=1326721 for details. Signed-off-by: Radim Kr?má? --- target-i386/cpu.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index ddae932ee1b4..66bd9d0c4039 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -506,7 +506,7 @@ const char *get_register_name_32(unsigned int reg) * Returns the set of feature flags that are supported and migratable by * QEMU, for a given FeatureWord. */ -static uint32_t x86_cpu_get_migratable_flags(FeatureWord w) +static uint32_t x86_cpu_get_migratable_flags(FeatureWord w, bool is_amd) { FeatureWordInfo *wi = &feature_word_info[w]; uint32_t r = 0; @@ -514,12 +514,18 @@ static uint32_t x86_cpu_get_migratable_flags(FeatureWord w) for (i = 0; i < 32; i++) { uint32_t f = 1U << i; + FeatureWordInfo *effective_wi = wi; + + if (is_amd && w == FEAT_8000_0001_EDX && f & CPUID_EXT2_AMD_ALIASES) { + effective_wi = &feature_word_info[FEAT_1_EDX]; + } + /* If the feature name is unknown, it is not supported by QEMU yet */ - if (!wi->feat_names[i]) { + if (!effective_wi->feat_names[i]) { continue; } /* Skip features known to QEMU, but explicitly marked as unmigratable */ - if (wi->unmigratable_flags & f) { + if (effective_wi->unmigratable_flags & f) { continue; } r |= f; @@ -1423,8 +1429,7 @@ void x86_cpu_change_kvm_default(const char *prop, const char *value) assert(pv->prop); } -static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, - bool migratable_only); +static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, X86CPU *cpu); #ifdef CONFIG_KVM @@ -1974,7 +1979,7 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features, if (cpu->host_features) { for (w = 0; w < FEATURE_WORDS; w++) { env->features[w] = - x86_cpu_get_supported_feature_word(w, cpu->migratable); + x86_cpu_get_supported_feature_word(w, cpu); } } @@ -2050,8 +2055,14 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) return cpu_list; } -static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, - bool migratable_only) +#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3) +#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) + +static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, X86CPU *cpu) { FeatureWordInfo *wi = &feature_word_info[w]; uint32_t r; @@ -2065,8 +2076,8 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, } else { return ~0; } - if (migratable_only) { - r &= x86_cpu_get_migratable_flags(w); + if (cpu->migratable) { + r &= x86_cpu_get_migratable_flags(w, IS_AMD_CPU(&cpu->env)); } return r; } @@ -2084,7 +2095,7 @@ static int x86_cpu_filter_features(X86CPU *cpu) for (w = 0; w < FEATURE_WORDS; w++) { uint32_t host_feat = - x86_cpu_get_supported_feature_word(w, cpu->migratable); + x86_cpu_get_supported_feature_word(w, cpu); uint32_t requested_features = env->features[w]; env->features[w] &= host_feat; cpu->filtered_features[w] = requested_features & ~env->features[w]; @@ -2872,13 +2883,6 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) } #endif - -#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \ - (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \ - (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3) -#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ - (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ - (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev);