From patchwork Fri Apr 15 16:54:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 611043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qmkDL4gzlz9t64 for ; Sat, 16 Apr 2016 02:54:58 +1000 (AEST) Received: from localhost ([::1]:37713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar71E-0000NE-K0 for incoming@patchwork.ozlabs.org; Fri, 15 Apr 2016 12:54:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar70s-0008Cq-Lv for qemu-devel@nongnu.org; Fri, 15 Apr 2016 12:54:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar70p-0007td-BO for qemu-devel@nongnu.org; Fri, 15 Apr 2016 12:54:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar70p-0007tU-38 for qemu-devel@nongnu.org; Fri, 15 Apr 2016 12:54:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 2FD761112; Fri, 15 Apr 2016 16:54:30 +0000 (UTC) Received: from localhost (vpn1-5-183.gru2.redhat.com [10.97.5.183]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3FGsSIs004290; Fri, 15 Apr 2016 12:54:29 -0400 Date: Fri, 15 Apr 2016 13:54:27 -0300 From: Eduardo Habkost To: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20160415165427.GI11931@thinpad.lan.raisama.net> References: <1460667307-14819-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1460667307-14819-1-git-send-email-rkrcmar@redhat.com> X-Fnord: you can see the fnord User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [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 , qemu-devel@nongnu.org, Andreas =?iso-8859-1?Q?F=E4rber?= , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" On Thu, Apr 14, 2016 at 10:55:07PM +0200, Radim Krčmář wrote: > 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; I don't think we need that complexity to fix the problem. We even have a similar hack in kvm_arch_get_supported_cpuid() to make sure it handles the alias bits properly. Instead of hacking those functions to copy CPUID[1] data, it's much easier to simply copy the alias bits in realizefn after we call x86_cpu_filter_features(), not before. The following (untested) fix should be sufficient: Tested-by: Radim Krčmář diff --git a/target-i386/cpu.c b/target-i386/cpu.c index ddae932..d0b5b69 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2897,6 +2897,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->cpuid_level = 7; } + 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; + } + /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on * CPUID[1].EDX. */ @@ -2907,14 +2915,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) } - 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; - } - #ifndef CONFIG_USER_ONLY qemu_register_reset(x86_cpu_machine_reset_cb, cpu);