Skip to contentSkip to conversation

target-i386: emulate CPUID level of real hardware

PATCH Superseded Radim Krčmář 2 participants 3 messages Jun 19, 2015 – Jun 22, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target-i386: emulate CPUID level of real hardware

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 have 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).

---
v2:
* maintained compatibility for old (< 2.4) machine types [Paolo]
* dropped automatic increase to 0xd, for compatibility [Eduardo]

I devote this code to copy&paste.

 hw/i386/pc_piix.c | 18 ++++++++++++++++
 hw/i386/pc_q35.c  | 18 ++++++++++++++++
 target-i386/cpu.c | 63 ++++++++++++++++++++++++++++++++++++++-----------------
 target-i386/cpu.h |  3 +++
 4 files changed, 83 insertions(+), 19 deletions(-)
hw/i386/pc_piix.c +18 -0
index e142f75649d8..c335e230277b 100644
@@ -307,6 +307,24 @@ static void pc_init1(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
     savevm_skip_section_footers();
+
+    x86_cpu_compat_set_level("qemu64",   4);
+    x86_cpu_compat_set_level("kvm64",    5);
+    x86_cpu_compat_set_level("pentium3", 2);
+    x86_cpu_compat_set_level("n270",     5);
+    x86_cpu_compat_set_level("Conroe",   4);
+    x86_cpu_compat_set_level("Penryn",   4);
+    x86_cpu_compat_set_level("Nehalem",  4);
+
+    x86_cpu_compat_set_xlevel("n270",            0x8000000a);
+    x86_cpu_compat_set_xlevel("Penryn",          0x8000000a);
+    x86_cpu_compat_set_xlevel("Nehalem",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Westmere",        0x8000000a);
+    x86_cpu_compat_set_xlevel("SandyBridge",     0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell-noTSX",   0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell",       0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell-noTSX", 0x8000000a);
 }
 
 static void pc_compat_2_2(MachineState *machine)
hw/i386/pc_q35.c +18 -0
index 082cd93bb2d7..99bfd6d6f288 100644
@@ -291,6 +291,24 @@ static void pc_q35_init(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
     savevm_skip_section_footers();
+
+    x86_cpu_compat_set_level("qemu64",   4);
+    x86_cpu_compat_set_level("kvm64",    5);
+    x86_cpu_compat_set_level("pentium3", 2);
+    x86_cpu_compat_set_level("n270",     5);
+    x86_cpu_compat_set_level("Conroe",   4);
+    x86_cpu_compat_set_level("Penryn",   4);
+    x86_cpu_compat_set_level("Nehalem",  4);
+
+    x86_cpu_compat_set_xlevel("n270",            0x8000000a);
+    x86_cpu_compat_set_xlevel("Penryn",          0x8000000a);
+    x86_cpu_compat_set_xlevel("Nehalem",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Westmere",        0x8000000a);
+    x86_cpu_compat_set_xlevel("SandyBridge",     0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell-noTSX",   0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell",       0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell-noTSX", 0x8000000a);
 }
 
 static void pc_compat_2_2(MachineState *machine)
target-i386/cpu.c +44 -19

171 lines not on this page · raw message

target-i386/cpu.h +3 -0
index 603aaf0924e3..b1f16ee6195a 100644
@@ -1331,6 +1331,9 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
 void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
                                  uint32_t feat_add, uint32_t feat_remove);
 
+void x86_cpu_compat_set_level(const char *cpu_model, uint32_t level);
+void x86_cpu_compat_set_xlevel(const char *cpu_model, uint32_t xlevel);
+
 void x86_cpu_compat_kvm_no_autoenable(FeatureWord w, uint32_t features);
 void x86_cpu_compat_kvm_no_autodisable(FeatureWord w, uint32_t features);
 
Signature · 1 line
2.4.4
#1 lore raw

On Fri, Jun 19, 2015 at 01:20:40PM +0200, Radim Krčmář wrote:
[...]

Quoted 16 lines
hw/i386/pc_piix.c +8 -0
index e142f75649d8..c335e230277b 100644
@@ -307,6 +307,24 @@ static void pc_init1(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
     savevm_skip_section_footers();
+
+    x86_cpu_compat_set_level("qemu64",   4);
+    x86_cpu_compat_set_level("kvm64",    5);
+    x86_cpu_compat_set_level("pentium3", 2);
+    x86_cpu_compat_set_level("n270",     5);
+    x86_cpu_compat_set_level("Conroe",   4);
+    x86_cpu_compat_set_level("Penryn",   4);
+    x86_cpu_compat_set_level("Nehalem",  4);

hw/i386/pc_piix.c static void pc_init1(MachineState *machine) · line 327

Quoted 10 lines
hw/i386/pc_piix.c +10 -0
+
+    x86_cpu_compat_set_xlevel("n270",            0x8000000a);
+    x86_cpu_compat_set_xlevel("Penryn",          0x8000000a);
+    x86_cpu_compat_set_xlevel("Nehalem",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Westmere",        0x8000000a);
+    x86_cpu_compat_set_xlevel("SandyBridge",     0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell",         0x8000000a);
+    x86_cpu_compat_set_xlevel("Haswell-noTSX",   0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell",       0x8000000a);
+    x86_cpu_compat_set_xlevel("Broadwell-noTSX", 0x8000000a);

We can simply use set the "level" and "xlevel" properties on PC_COMPAT_2_3, we don't need the x86_cpu_compat_set_*level() functions.

Signature · 1 line
Eduardo
#2 lore raw

2015-06-19 12:52-0300, Eduardo Habkost:

Quoted 9 lines · Radim Krčmář

[...]

hw/i386/pc_piix.c static void pc_init1(MachineState *machine) · line 311

Quoted 7 lines
hw/i386/pc_piix.c +2 -0
@@ -307,6 +307,24 @@ static void pc_init1(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
     savevm_skip_section_footers();
+
+    x86_cpu_compat_set_level("qemu64",   4);

| [...]

Quoted 2 lines

hw/i386/pc_piix.c static void pc_init1(MachineState *machine) · line 313

Quoted 2 lines
hw/i386/pc_piix.c +2 -0
+
+    x86_cpu_compat_set_xlevel("n270",            0x8000000a);

| [...]

Quoted 3 lines

We can simply use set the "level" and "xlevel" properties on PC_COMPAT_2_3, we don't need the x86_cpu_compat_set_*level() functions.

Oops, thanks, I will convert the code and send v3.