Skip to contentSkip to conversation

i386: use better matching family/model/stepping for generic CPUs

PATCH Applied Daniel P. Berrangé 2 participants 7 messages May 7, 2021 – May 26, 2021

lore
Share & tools
lore
#0 lore raw

cover i386: use better matching family/model/stepping for generic CPUs

This is in response to this bug report:

https://gitlab.com/qemu-project/qemu/-/issues/191

The generic 'qemu64' and 'max' CPUs currently defined to report a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

The bug report is fairly limited, but it suggests LLVM looks at the family/model/stepping and decides it to be 32-bit, despite qemu64 reporting it is 64-bit capable. I've not reproduced this myself, however, so I'm largely trusting the original reporter's diagnosis

Of course interpreting the family/model/stepping only makes sense with scoped to the reported vendor ID. Under TCG, the vendor is honoured, but AFAICT, under KVM the vendor defined by the QEMU model model is ignored and the real host vendor passed through. This will make the chosen family/model/stepping non-sensical when run under KVM on an Intel host.

None the less these patches change to report a CPUID with the family, model and stepping taken from a

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs. This is at least more accurate in terms of the static CPU model definition, even if it is still nonsense in the case where KVM overrides the vendor to be non-AMD.

Daniel P. Berrangé (2):
i386: use better matching family/model/stepping for 'qemu64' CPU
i386: use better matching family/model/stepping for 'max' CPU

 hw/i386/pc.c      |  6 +++++-
 target/i386/cpu.c | 12 +++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 i386: use better matching family/model/stepping for 'qemu64' CPU

The 'qemu64' CPUID currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.

This patch changes 'qemu64' to report a CPUID with the family, model and stepping taken from a

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs.

Closes https://gitlab.com/qemu-project/qemu/-/issues/191

---
 hw/i386/pc.c      | 6 +++++-
 target/i386/cpu.c | 6 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc.c +5 -1
index 364816efc9..35d7a8122a 100644
@@ -96,7 +96,11 @@
 #include "trace.h"
 #include CONFIG_DEVICES
 
-GlobalProperty pc_compat_6_0[] = {};
+GlobalProperty pc_compat_6_0[] = {
+    { "qemu64" "-" TYPE_X86_CPU, "family", "6" },
+    { "qemu64" "-" TYPE_X86_CPU, "model", "6" },
+    { "qemu64" "-" TYPE_X86_CPU, "stepping", "3" },
+};
 const size_t pc_compat_6_0_len = G_N_ELEMENTS(pc_compat_6_0);
 
 GlobalProperty pc_compat_5_2[] = {
target/i386/cpu.c +3 -3
index ad99cad0e7..99caa3deae 100644
@@ -1881,9 +1881,9 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .name = "qemu64",
         .level = 0xd,
         .vendor = CPUID_VENDOR_AMD,
-        .family = 6,
-        .model = 6,
-        .stepping = 3,
+        .family = 15,
+        .model = 107,
+        .stepping = 1,
         .features[FEAT_1_EDX] =
             PPRO_FEATURES |
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
Signature · 1 line
2.31.1
#3 lore raw

PATCH 2/2 i386: use better matching family/model/stepping for 'max' CPU

In reply to Daniel P. Berrangé

The 'max' CPU under TCG currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.

This patch changes 'max' to report a CPUID with the family, model and stepping taken from a

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs.

Closes https://gitlab.com/qemu-project/qemu/-/issues/191

---
 target/i386/cpu.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/i386/cpu.c +6 -0
index 99caa3deae..80de5b04eb 100644
@@ -4440,9 +4440,15 @@ static void max_x86_cpu_initfn(Object *obj)
     } else {
         object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
                                 &error_abort);
+#ifdef TARGET_X86_64
+        object_property_set_int(OBJECT(cpu), "family", 15, &error_abort);
+        object_property_set_int(OBJECT(cpu), "model", 107, &error_abort);
+        object_property_set_int(OBJECT(cpu), "stepping", 1, &error_abort);
+#else
         object_property_set_int(OBJECT(cpu), "family", 6, &error_abort);
         object_property_set_int(OBJECT(cpu), "model", 6, &error_abort);
         object_property_set_int(OBJECT(cpu), "stepping", 3, &error_abort);
+#endif
         object_property_set_str(OBJECT(cpu), "model-id",
                                 "QEMU TCG CPU version " QEMU_HW_VERSION,
                                 &error_abort);
Signature · 1 line
2.31.1
#5 lore raw
In reply to Daniel P. Berrangé

ping

Quoted 35 lines · Daniel P. Berrangé

This is in response to this bug report:

   https://gitlab.com/qemu-project/qemu/-/issues/191

The generic 'qemu64' and 'max' CPUs currently defined to report a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

The bug report is fairly limited, but it suggests LLVM looks at the family/model/stepping and decides it to be 32-bit, despite qemu64 reporting it is 64-bit capable. I've not reproduced this myself, however, so I'm largely trusting the original reporter's diagnosis

Of course interpreting the family/model/stepping only makes sense with scoped to the reported vendor ID. Under TCG, the vendor is honoured, but AFAICT, under KVM the vendor defined by the QEMU model model is ignored and the real host vendor passed through. This will make the chosen family/model/stepping non-sensical when run under KVM on an Intel host.

None the less these patches change to report a CPUID with the family, model and stepping taken from a

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs. This is at least more accurate in terms of the static CPU model definition, even if it is still nonsense in the case where KVM overrides the vendor to be non-AMD.

Quoted 12 lines

Daniel P. Berrangé (2):
i386: use better matching family/model/stepping for 'qemu64' CPU
i386: use better matching family/model/stepping for 'max' CPU

 hw/i386/pc.c      |  6 +++++-
 target/i386/cpu.c | 12 +++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.31.1

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] i386: use better matching family/model/stepping for 'qemu64' CPU

In reply to Daniel P. Berrangé
Quoted 30 lines · Daniel P. Berrangé

The 'qemu64' CPUID currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.

This patch changes 'qemu64' to report a CPUID with the family, model and stepping taken from a

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs.

Closes https://gitlab.com/qemu-project/qemu/-/issues/191

---
 hw/i386/pc.c      | 6 +++++-
 target/i386/cpu.c | 6 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc.c +0 -0
index 364816efc9..35d7a8122a 100644

hw/i386/pc.c line 102

Quoted 8 lines
hw/i386/pc.c +4 -1
@@ -96,7 +96,11 @@
 #include "trace.h"
 #include CONFIG_DEVICES
 
-GlobalProperty pc_compat_6_0[] = {};
+GlobalProperty pc_compat_6_0[] = {
+    { "qemu64" "-" TYPE_X86_CPU, "family", "6" },
+    { "qemu64" "-" TYPE_X86_CPU, "model", "6" },
+    { "qemu64" "-" TYPE_X86_CPU, "stepping", "3" },

I wish we could have done this using a new CPU model version, but the new version wouldn't be very useful unless the default CPU model version to CPU_VERSION_LATEST[1], so:

[1] We still can't do that without breaking libvirt expectations about machine types.

Quoted 24 lines
hw/i386/pc.c +1 -0
+};
 const size_t pc_compat_6_0_len = G_N_ELEMENTS(pc_compat_6_0);
 
 GlobalProperty pc_compat_5_2[] = {
target/i386/cpu.c +3 -3
index ad99cad0e7..99caa3deae 100644
@@ -1881,9 +1881,9 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .name = "qemu64",
         .level = 0xd,
         .vendor = CPUID_VENDOR_AMD,
-        .family = 6,
-        .model = 6,
-        .stepping = 3,
+        .family = 15,
+        .model = 107,
+        .stepping = 1,
         .features[FEAT_1_EDX] =
             PPRO_FEATURES |
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
Signature · 1 line
2.31.1
Signature · 1 line
Eduardo
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] i386: use better matching family/model/stepping for 'max' CPU

In reply to Daniel P. Berrangé
Quoted 14 lines · Daniel P. Berrangé

The 'max' CPU under TCG currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target

LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!

It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.

This patch changes 'max' to report a CPUID with the family, model and stepping taken from a

Quoted 6 lines

AMD Athlon(tm) 64 X2 Dual Core Processor 4000+

which is one of the first 64-bit AMD CPUs.

Closes https://gitlab.com/qemu-project/qemu/-/issues/191

Signature · 1 line
Eduardo
#6 lore raw
In reply to Daniel P. Berrangé

On Fri, May 07, 2021 at 02:36:48PM +0100, Daniel P. Berrangé wrote:
[...]

Quoted 3 lines

Daniel P. Berrangé (2):
i386: use better matching family/model/stepping for 'qemu64' CPU
i386: use better matching family/model/stepping for 'max' CPU

Queued, thanks!

Signature · 1 line
Eduardo