edecca
From 498389f6b88547c352add4b209d61896a5143c00 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <498389f6b88547c352add4b209d61896a5143c00@dist-git>
edecca
From: Jiri Denemark <jdenemar@redhat.com>
edecca
Date: Fri, 27 Mar 2015 12:48:40 +0100
edecca
Subject: [PATCH] RHEL: Hack around changed Broadwell/Haswell CPUs
edecca
edecca
RHEL-only
edecca
edecca
Upstream tried to solve the change of Broadwell and Haswell CPUs by
edecca
removing rtm and hle features from the corresponding CPU models for new
edecca
machine types. Then they reverted this and introduced new *-noTSX models
edecca
instead. However, the original fix was backported to RHEL.
edecca
edecca
This patch makes sure Broadwell and Haswell will always contain rtm and
edecca
hle features regardless on RHEL version or machine type used.
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1199446
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
---
edecca
 src/qemu/qemu_command.c                       | 29 +++++++++++++++++++
edecca
 tests/qemuxml2argvdata/cpu-Haswell.args       |  2 +-
edecca
 .../qemuxml2argvdata/cpu-host-model-cmt.args  |  3 +-
edecca
 tests/qemuxml2argvdata/cpu-tsc-frequency.args |  2 +-
edecca
 tests/qemuxml2argvdata/q35-acpi-nouefi.args   |  2 +-
edecca
 tests/qemuxml2argvdata/q35-acpi-uefi.args     |  2 +-
edecca
 tests/qemuxml2argvdata/q35-noacpi-nouefi.args |  2 +-
edecca
 7 files changed, 36 insertions(+), 6 deletions(-)
edecca
edecca
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
edecca
index 4fc3176ad3..c1eefca639 100644
edecca
--- a/src/qemu/qemu_command.c
edecca
+++ b/src/qemu/qemu_command.c
edecca
@@ -6677,6 +6677,8 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
edecca
     size_t i;
edecca
     virCapsPtr caps = NULL;
edecca
     virCPUDefPtr cpu = def->cpu;
edecca
+    bool hle = false;
edecca
+    bool rtm = false;
edecca
 
edecca
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
edecca
         goto cleanup;
edecca
@@ -6734,6 +6736,11 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
edecca
         virBufferAsprintf(buf, ",vendor=%s", cpu->vendor_id);
edecca
 
edecca
     for (i = 0; i < cpu->nfeatures; i++) {
edecca
+        if (STREQ("rtm", cpu->features[i].name))
edecca
+            rtm = true;
edecca
+        if (STREQ("hle", cpu->features[i].name))
edecca
+            hle = true;
edecca
+
edecca
         switch ((virCPUFeaturePolicy) cpu->features[i].policy) {
edecca
         case VIR_CPU_FEATURE_FORCE:
edecca
         case VIR_CPU_FEATURE_REQUIRE:
edecca
@@ -6757,6 +6764,28 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
edecca
         }
edecca
     }
edecca
 
edecca
+    /* Some versions of qemu-kvm in RHEL provide Broadwell and Haswell CPU
edecca
+     * models which lack rtm and hle features when used with some machine
edecca
+     * types. Let's make sure Broadwell and Haswell will always have these
edecca
+     * features. But only if the features were not explicitly mentioned in
edecca
+     * the guest CPU definition.
edecca
+     */
edecca
+    if (STREQ_NULLABLE(cpu->model, "Broadwell") ||
edecca
+        STREQ_NULLABLE(cpu->model, "Haswell")) {
edecca
+        if (!rtm) {
edecca
+            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
edecca
+                virBufferAddLit(buf, ",rtm=on");
edecca
+            else
edecca
+                virBufferAddLit(buf, ",+rtm");
edecca
+        }
edecca
+        if (!hle) {
edecca
+            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
edecca
+                virBufferAddLit(buf, ",hle=on");
edecca
+            else
edecca
+                virBufferAddLit(buf, ",+hle");
edecca
+        }
edecca
+    }
edecca
+
edecca
     ret = 0;
edecca
  cleanup:
edecca
     virObjectUnref(caps);
edecca
diff --git a/tests/qemuxml2argvdata/cpu-Haswell.args b/tests/qemuxml2argvdata/cpu-Haswell.args
edecca
index c7ce396d05..6f20359524 100644
edecca
--- a/tests/qemuxml2argvdata/cpu-Haswell.args
edecca
+++ b/tests/qemuxml2argvdata/cpu-Haswell.args
edecca
@@ -8,7 +8,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -name QEMUGuest1 \
edecca
 -S \
edecca
 -machine pc,accel=kvm,usb=off,dump-guest-core=off \
edecca
--cpu Haswell \
edecca
+-cpu Haswell,+rtm,+hle \
edecca
 -m 214 \
edecca
 -smp 6,sockets=6,cores=1,threads=1 \
edecca
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
edecca
diff --git a/tests/qemuxml2argvdata/cpu-host-model-cmt.args b/tests/qemuxml2argvdata/cpu-host-model-cmt.args
edecca
index 8767278d11..d236aa9e09 100644
edecca
--- a/tests/qemuxml2argvdata/cpu-host-model-cmt.args
edecca
+++ b/tests/qemuxml2argvdata/cpu-host-model-cmt.args
edecca
@@ -9,7 +9,8 @@ QEMU_AUDIO_DRV=none \
edecca
 -S \
edecca
 -machine pc,accel=tcg,usb=off,dump-guest-core=off \
edecca
 -cpu Haswell,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+dtes64,+monitor,+ds_cpl,+vmx,\
edecca
-+smx,+est,+tm2,+xtpr,+pdcm,+osxsave,+f16c,+rdrand,+pdpe1gb,+abm,+lahf_lm \
edecca
++smx,+est,+tm2,+xtpr,+pdcm,+osxsave,+f16c,+rdrand,+pdpe1gb,+abm,+lahf_lm,+rtm,\
edecca
++hle \
edecca
 -m 214 \
edecca
 -smp 6,sockets=6,cores=1,threads=1 \
edecca
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
edecca
diff --git a/tests/qemuxml2argvdata/cpu-tsc-frequency.args b/tests/qemuxml2argvdata/cpu-tsc-frequency.args
edecca
index 7824dea96f..216fd43014 100644
edecca
--- a/tests/qemuxml2argvdata/cpu-tsc-frequency.args
edecca
+++ b/tests/qemuxml2argvdata/cpu-tsc-frequency.args
edecca
@@ -10,7 +10,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -machine pc,accel=kvm,usb=off,dump-guest-core=off \
edecca
 -cpu Haswell,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+dtes64,+monitor,+ds_cpl,+vmx,\
edecca
 +smx,+est,+tm2,+xtpr,+pdcm,+osxsave,+f16c,+rdrand,+pdpe1gb,+abm,+lahf_lm,\
edecca
-+invtsc,tsc-frequency=3504000000 \
edecca
++invtsc,+rtm,+hle,tsc-frequency=3504000000 \
edecca
 -m 214 \
edecca
 -smp 1,sockets=1,cores=1,threads=1 \
edecca
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
edecca
diff --git a/tests/qemuxml2argvdata/q35-acpi-nouefi.args b/tests/qemuxml2argvdata/q35-acpi-nouefi.args
edecca
index caef49ea16..a9375a35db 100644
edecca
--- a/tests/qemuxml2argvdata/q35-acpi-nouefi.args
edecca
+++ b/tests/qemuxml2argvdata/q35-acpi-nouefi.args
edecca
@@ -8,7 +8,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -name guest \
edecca
 -S \
edecca
 -machine q35,accel=tcg,usb=off,dump-guest-core=off \
edecca
--cpu Haswell \
edecca
+-cpu Haswell,+rtm,+hle \
edecca
 -m 1024 \
edecca
 -smp 1,sockets=1,cores=1,threads=1 \
edecca
 -uuid 496d7ea8-9739-544b-4ebd-ef08be936e8b \
edecca
diff --git a/tests/qemuxml2argvdata/q35-acpi-uefi.args b/tests/qemuxml2argvdata/q35-acpi-uefi.args
edecca
index a3293aeb9d..8e3368b9e9 100644
edecca
--- a/tests/qemuxml2argvdata/q35-acpi-uefi.args
edecca
+++ b/tests/qemuxml2argvdata/q35-acpi-uefi.args
edecca
@@ -8,7 +8,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -name guest \
edecca
 -S \
edecca
 -machine q35,accel=tcg,usb=off,dump-guest-core=off \
edecca
--cpu Haswell \
edecca
+-cpu Haswell,+rtm,+hle \
edecca
 -drive file=/usr/share/OVMF/OVMF_CODE.fd,if=pflash,format=raw,unit=0,\
edecca
 readonly=on \
edecca
 -drive file=/var/lib/libvirt/qemu/nvram/guest_VARS.fd,if=pflash,format=raw,\
edecca
diff --git a/tests/qemuxml2argvdata/q35-noacpi-nouefi.args b/tests/qemuxml2argvdata/q35-noacpi-nouefi.args
edecca
index fab2a6fcb0..0dd61840ef 100644
edecca
--- a/tests/qemuxml2argvdata/q35-noacpi-nouefi.args
edecca
+++ b/tests/qemuxml2argvdata/q35-noacpi-nouefi.args
edecca
@@ -8,7 +8,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -name guest \
edecca
 -S \
edecca
 -machine q35,accel=tcg,usb=off,dump-guest-core=off \
edecca
--cpu Haswell \
edecca
+-cpu Haswell,+rtm,+hle \
edecca
 -m 1024 \
edecca
 -smp 1,sockets=1,cores=1,threads=1 \
edecca
 -uuid 496d7ea8-9739-544b-4ebd-ef08be936e8b \
edecca
-- 
edecca
2.18.0
edecca