Blame SOURCES/virt-manager-virtinst-compare-host-and-domain-cpu-models.patch

3d61c0
From 8b2f541cb9d2cff02c5bbb7af2de3cb2b0b05d17 Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <8b2f541cb9d2cff02c5bbb7af2de3cb2b0b05d17@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Wed, 28 Mar 2018 13:45:30 -0600
3d61c0
Subject: [PATCH] virtinst: compare host and domain cpu models
3d61c0
3d61c0
From: Charles Arnold <carnold@suse.com>
3d61c0
3d61c0
Lookup the domain capabilities CPU model and compare with
3d61c0
the host capabilities CPU model and if they are not equal
3d61c0
set the guest's CPU model to None.
3d61c0
3d61c0
(crobinso: compare against 'custom' list not 'host-model', move
3d61c0
 to separate function)
3d61c0
3d61c0
(cherry picked from commit fd6a8154408fb462e5437dc920afe4d80da3c1f8)
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1525337
3d61c0
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
---
3d61c0
 .../compare/virt-install-boot-uefi.xml        |  4 +--
3d61c0
 virtinst/guest.py                             | 32 ++++++++++++++++---
3d61c0
 2 files changed, 29 insertions(+), 7 deletions(-)
3d61c0
3d61c0
diff --git a/tests/cli-test-xml/compare/virt-install-boot-uefi.xml b/tests/cli-test-xml/compare/virt-install-boot-uefi.xml
3d61c0
index 22f31e6b..f46b8f07 100644
3d61c0
--- a/tests/cli-test-xml/compare/virt-install-boot-uefi.xml
3d61c0
+++ b/tests/cli-test-xml/compare/virt-install-boot-uefi.xml
3d61c0
@@ -15,9 +15,7 @@
3d61c0
     <smm state="on"/>
3d61c0
     <vmport state="off"/>
3d61c0
   </features>
3d61c0
-  <cpu mode="custom" match="exact">
3d61c0
-    <model>Opteron_G4</model>
3d61c0
-  </cpu>
3d61c0
+  <cpu mode="custom" match="exact"/>
3d61c0
   <clock offset="utc">
3d61c0
     <timer name="rtc" tickpolicy="catchup"/>
3d61c0
     <timer name="pit" tickpolicy="delay"/>
3d61c0
diff --git a/virtinst/guest.py b/virtinst/guest.py
3d61c0
index 32acd521..6d4aeb26 100644
3d61c0
--- a/virtinst/guest.py
3d61c0
+++ b/virtinst/guest.py
3d61c0
@@ -880,6 +880,33 @@ class Guest(XMLBuilder):
3d61c0
             else:
3d61c0
                 self.emulator = "/usr/lib/xen/bin/qemu-dm"
3d61c0
 
3d61c0
+    def _set_cpu_x86_kvm_default(self):
3d61c0
+        if self.os.arch != self.conn.caps.host.cpu.arch:
3d61c0
+            return
3d61c0
+
3d61c0
+        self.cpu.set_special_mode(self.x86_cpu_default)
3d61c0
+        if self.x86_cpu_default != self.cpu.SPECIAL_MODE_HOST_MODEL_ONLY:
3d61c0
+            return
3d61c0
+        if not self.cpu.model:
3d61c0
+            return
3d61c0
+
3d61c0
+        # It's possible that the value HOST_MODEL_ONLY gets from
3d61c0
+        # <capabilities> is not actually supported by qemu/kvm
3d61c0
+        # combo which will be reported in <domainCapabilities>
3d61c0
+        domcaps = DomainCapabilities.build_from_guest(self)
3d61c0
+        domcaps_mode = domcaps.cpu.get_mode("custom")
3d61c0
+        if not domcaps_mode:
3d61c0
+            return
3d61c0
+
3d61c0
+        cpu_model = domcaps_mode.get_model(self.cpu.model)
3d61c0
+        if cpu_model and cpu_model.usable:
3d61c0
+            return
3d61c0
+
3d61c0
+        logging.debug("Host capabilities CPU '%s' is not supported "
3d61c0
+            "according to domain capabilities. Unsettings CPU model",
3d61c0
+            self.cpu.model)
3d61c0
+        self.cpu.model = None
3d61c0
+
3d61c0
     def _set_cpu_defaults(self):
3d61c0
         self.cpu.set_topology_defaults(self.vcpus)
3d61c0
 
3d61c0
@@ -898,14 +925,11 @@ class Guest(XMLBuilder):
3d61c0
             self.cpu.model = "cortex-a57"
3d61c0
 
3d61c0
         elif self.os.is_x86() and self.type == "kvm":
3d61c0
-            if self.os.arch != self.conn.caps.host.cpu.arch:
3d61c0
-                return
3d61c0
+            self._set_cpu_x86_kvm_default()
3d61c0
 
3d61c0
-            self.cpu.set_special_mode(self.x86_cpu_default)
3d61c0
             if self._os_object.broken_x2apic():
3d61c0
                 self.cpu.add_feature("x2apic", policy="disable")
3d61c0
 
3d61c0
-
3d61c0
     def _hyperv_supported(self):
3d61c0
         if (self.os.loader_type == "pflash" and
3d61c0
             self.os_variant in ("win2k8r2", "win7")):
3d61c0
-- 
3d61c0
2.20.1
3d61c0