* [Qemu-devel] [PATCH] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags
@ 2016-04-14 20:55 Radim Krčmář
2016-04-15 16:54 ` Eduardo Habkost
0 siblings, 1 reply; 3+ messages in thread
From: Radim Krčmář @ 2016-04-14 20:55 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Richard Henderson, Paolo Bonzini,
Andreas Färber
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ář <rkrcmar@redhat.com>
---
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);
--
2.8.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags
2016-04-14 20:55 [Qemu-devel] [PATCH] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags Radim Krčmář
@ 2016-04-15 16:54 ` Eduardo Habkost
2016-04-15 17:27 ` Radim Krčmář
0 siblings, 1 reply; 3+ messages in thread
From: Eduardo Habkost @ 2016-04-15 16:54 UTC (permalink / raw)
To: Radim Krčmář
Cc: qemu-devel, Richard Henderson, Paolo Bonzini, Andreas Färber
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ář <rkrcmar@redhat.com>
> ---
> 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:
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);
--
Eduardo
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags
2016-04-15 16:54 ` Eduardo Habkost
@ 2016-04-15 17:27 ` Radim Krčmář
0 siblings, 0 replies; 3+ messages in thread
From: Radim Krčmář @ 2016-04-15 17:27 UTC (permalink / raw)
To: Eduardo Habkost
Cc: qemu-devel, Richard Henderson, Paolo Bonzini, Andreas Färber
2016-04-15 13:54-0300, Eduardo Habkost:
> 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ář <rkrcmar@redhat.com>
>> ---
>> target-i386/cpu.c | 40 ++++++++++++++++++++++------------------
>> 1 file changed, 22 insertions(+), 18 deletions(-)
>
> 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:
It is,
Tested-by: Radim Krčmář <rkrcmar@redhat.com>
Thank you.
> 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);
>
>
>
> --
> Eduardo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-15 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-14 20:55 [Qemu-devel] [PATCH] target-i386: add AMD CPUID.1:edx aliases to x86_cpu_get_migratable_flags Radim Krčmář
2016-04-15 16:54 ` Eduardo Habkost
2016-04-15 17:27 ` Radim Krčmář
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).