All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware
@ 2015-06-22 11:08 Radim Krčmář
  2015-06-29 19:18 ` Eduardo Habkost
  2015-06-29 20:20 ` Eduardo Habkost
  0 siblings, 2 replies; 3+ messages in thread
From: Radim Krčmář @ 2015-06-22 11:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, bsd, ehabkost, rth

W10 insider has a bug where it ignores CPUID level and interprets
CPUID.(EAX=07H, ECX=0H) incorrectly, because CPUID in fact returned
CPUID.(EAX=04H, ECX=0H);  this resulted in execution of unsupported
instructions.

While it's a Windows bug, there is no reason to emulate incorrect level.

I used http://instlatx64.atw.hu/ as a source of CPUID and checked that
it matches Penryn Xeon X5472, Westmere Xeon W3520, SandyBridge i5-2540M,
and Haswell i5-4670T.

kvm64 and qemu64 were bumped to 0xD to allow all available features for
them (and to avoid the same Windows bug).

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 v3: use PC_COMPAT_2_3 array to set old (x)level values [Eduardo]
 v2:
 * maintained compatibility for old (< 2.4) machine types [Paolo]
 * dropped automatic increase to 0xd, for compatibility [Eduardo]

 include/hw/compat.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 target-i386/cpu.c   | 37 +++++++++++++++---------------
 2 files changed, 83 insertions(+), 20 deletions(-)

diff --git a/include/hw/compat.h b/include/hw/compat.h
index 4a43466f0369..ef996be22263 100644
--- a/include/hw/compat.h
+++ b/include/hw/compat.h
@@ -2,7 +2,71 @@
 #define HW_COMPAT_H
 
 #define HW_COMPAT_2_3 \
-        /* empty */
+        {\
+            .driver   = "qemu64" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(4),\
+        },{\
+            .driver   = "kvm64" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(5),\
+        },{\
+            .driver   = "pentium3" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(2),\
+        },{\
+            .driver   = "n270" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(5),\
+        },{\
+            .driver   = "Conroe" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(4),\
+        },{\
+            .driver   = "Penryn" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(4),\
+        },{\
+            .driver   = "Nehalem" "-" TYPE_X86_CPU,\
+            .property = "level",\
+            .value    = stringify(4),\
+        },{\
+            .driver   = "n270" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Penryn" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Nehalem" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Westmere" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "SandyBridge" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Haswell" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Haswell-noTSX" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Broadwell" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },{\
+            .driver   = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
+            .property = "xlevel",\
+            .value    = stringify(0x8000000a),\
+        },
 
 #define HW_COMPAT_2_2 \
         /* empty */
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4e7cdaaaa57e..d392cf46f517 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -677,7 +677,7 @@ struct X86CPUDefinition {
 static X86CPUDefinition builtin_x86_defs[] = {
     {
         .name = "qemu64",
-        .level = 4,
+        .level = 0xd,
         .vendor = CPUID_VENDOR_AMD,
         .family = 6,
         .model = 6,
@@ -753,7 +753,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
     },
     {
         .name = "kvm64",
-        .level = 5,
+        .level = 0xd,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 15,
         .model = 6,
@@ -864,7 +864,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
     },
     {
         .name = "pentium3",
-        .level = 2,
+        .level = 3,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 6,
         .model = 7,
@@ -889,8 +889,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
     },
     {
         .name = "n270",
-        /* original is on level 10 */
-        .level = 5,
+        .level = 10,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 6,
         .model = 28,
@@ -910,12 +909,12 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT2_NX,
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_LAHF_LM,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel(R) Atom(TM) CPU N270   @ 1.60GHz",
     },
     {
         .name = "Conroe",
-        .level = 4,
+        .level = 10,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 6,
         .model = 15,
@@ -932,12 +931,12 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT2_LM | CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_LAHF_LM,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
     },
     {
         .name = "Penryn",
-        .level = 4,
+        .level = 10,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 6,
         .model = 23,
@@ -955,12 +954,12 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT2_LM | CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_LAHF_LM,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
     },
     {
         .name = "Nehalem",
-        .level = 4,
+        .level = 11,
         .vendor = CPUID_VENDOR_INTEL,
         .family = 6,
         .model = 26,
@@ -978,7 +977,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_LAHF_LM,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core i7 9xx (Nehalem Class Core i7)",
     },
     {
@@ -1002,7 +1001,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_LAHF_LM,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
     },
     {
@@ -1031,7 +1030,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT3_LAHF_LM,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Xeon E312xx (Sandy Bridge)",
     },
     {
@@ -1063,7 +1062,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_EXT3_LAHF_LM,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Xeon E3-12xx v2 (Ivy Bridge)",
     },
     {
@@ -1097,7 +1096,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core Processor (Haswell, no TSX)",
     },    {
         .name = "Haswell",
@@ -1131,7 +1130,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EBX_RTM,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core Processor (Haswell)",
     },
     {
@@ -1167,7 +1166,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EBX_SMAP,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core Processor (Broadwell, no TSX)",
     },
     {
@@ -1203,7 +1202,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EBX_SMAP,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
-        .xlevel = 0x8000000A,
+        .xlevel = 0x80000008,
         .model_id = "Intel Core Processor (Broadwell)",
     },
     {
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware
  2015-06-22 11:08 [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware Radim Krčmář
@ 2015-06-29 19:18 ` Eduardo Habkost
  2015-06-29 20:20 ` Eduardo Habkost
  1 sibling, 0 replies; 3+ messages in thread
From: Eduardo Habkost @ 2015-06-29 19:18 UTC (permalink / raw)
  To: Radim Krčmář; +Cc: pbonzini, bsd, qemu-devel, rth

On Mon, Jun 22, 2015 at 01:08:02PM +0200, Radim Krčmář wrote:
> W10 insider has a bug where it ignores CPUID level and interprets
> CPUID.(EAX=07H, ECX=0H) incorrectly, because CPUID in fact returned
> CPUID.(EAX=04H, ECX=0H);  this resulted in execution of unsupported
> instructions.
> 
> While it's a Windows bug, there is no reason to emulate incorrect level.
> 
> I used http://instlatx64.atw.hu/ as a source of CPUID and checked that
> it matches Penryn Xeon X5472, Westmere Xeon W3520, SandyBridge i5-2540M,
> and Haswell i5-4670T.
> 
> kvm64 and qemu64 were bumped to 0xD to allow all available features for
> them (and to avoid the same Windows bug).
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>


Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

Applied to the x86 tree, thanks.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware
  2015-06-22 11:08 [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware Radim Krčmář
  2015-06-29 19:18 ` Eduardo Habkost
@ 2015-06-29 20:20 ` Eduardo Habkost
  1 sibling, 0 replies; 3+ messages in thread
From: Eduardo Habkost @ 2015-06-29 20:20 UTC (permalink / raw)
  To: Radim Krčmář; +Cc: pbonzini, bsd, qemu-devel, rth

On Mon, Jun 22, 2015 at 01:08:02PM +0200, Radim Krčmář wrote:
> W10 insider has a bug where it ignores CPUID level and interprets
> CPUID.(EAX=07H, ECX=0H) incorrectly, because CPUID in fact returned
> CPUID.(EAX=04H, ECX=0H);  this resulted in execution of unsupported
> instructions.
> 
> While it's a Windows bug, there is no reason to emulate incorrect level.
> 
> I used http://instlatx64.atw.hu/ as a source of CPUID and checked that
> it matches Penryn Xeon X5472, Westmere Xeon W3520, SandyBridge i5-2540M,
> and Haswell i5-4670T.
> 
> kvm64 and qemu64 were bumped to 0xD to allow all available features for
> them (and to avoid the same Windows bug).
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> ---
>  v3: use PC_COMPAT_2_3 array to set old (x)level values [Eduardo]
>  v2:
>  * maintained compatibility for old (< 2.4) machine types [Paolo]
>  * dropped automatic increase to 0xd, for compatibility [Eduardo]
> 
>  include/hw/compat.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  target-i386/cpu.c   | 37 +++++++++++++++---------------
>  2 files changed, 83 insertions(+), 20 deletions(-)
> 
> diff --git a/include/hw/compat.h b/include/hw/compat.h
> index 4a43466f0369..ef996be22263 100644
> --- a/include/hw/compat.h
> +++ b/include/hw/compat.h
> @@ -2,7 +2,71 @@
>  #define HW_COMPAT_H
>  
>  #define HW_COMPAT_2_3 \
> -        /* empty */
[...]
> +        },{\
> +            .driver   = "Penryn" "-" TYPE_X86_CPU,\
> +            .property = "xlevel",\
> +            .value    = stringify(0x8000000a),\
> +        },{\

You changed Conroe xlevel, too. This was missing:

        {\
            .driver   = "Conroe" "-" TYPE_X86_CPU,\
            .property = "xlevel",\
            .value    = stringify(0x8000000a),\
        },

I have added it to the patch on the x86 tree.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-29 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 11:08 [Qemu-devel] [PATCH v3] target-i386: emulate CPUID level of real hardware Radim Krčmář
2015-06-29 19:18 ` Eduardo Habkost
2015-06-29 20:20 ` Eduardo Habkost

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.