Blame SOURCES/virt-manager-DomainCpu-fix-detection-of-CPU-security-features.patch

3d61c0
From a6380fb8faccbd58188d3f5c93553a2e625bf29d Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <a6380fb8faccbd58188d3f5c93553a2e625bf29d@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Tue, 9 Apr 2019 13:13:46 +0200
3d61c0
Subject: [PATCH] DomainCpu: fix detection of CPU security features
3d61c0
3d61c0
VM configured with mode="host-model" will have the CPU definition
3d61c0
expanded once the VM is started.  Libvirt will try to use the closest
3d61c0
CPU model with some features enabled/disabled.
3d61c0
3d61c0
The issue is that there are some models that include spec-ctrl or ibpb
3d61c0
features and they will not appear in the explicit list of features and
3d61c0
virt-manager will not correctly detect if all security features are
3d61c0
enabled or not.  As a workaround we can check the suffix of CPU model to
3d61c0
figure out which security features are enabled by the model itself.
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
(cherry picked from commit 291f2ef21486cb54aadd40f07052aedfebef3792)
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1582667
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
---
3d61c0
 virtinst/cpu.py | 16 +++++++---------
3d61c0
 1 file changed, 7 insertions(+), 9 deletions(-)
3d61c0
3d61c0
diff --git a/virtinst/cpu.py b/virtinst/cpu.py
3d61c0
index c76f06e8..ebe34449 100644
3d61c0
--- a/virtinst/cpu.py
3d61c0
+++ b/virtinst/cpu.py
3d61c0
@@ -157,15 +157,13 @@ class CPU(XMLBuilder):
3d61c0
             self.secure = False
3d61c0
             return
3d61c0
 
3d61c0
-        for feature in features:
3d61c0
-            exists = False
3d61c0
-            for f in self.features:
3d61c0
-                if f.name == feature and f.policy == "require":
3d61c0
-                    exists = True
3d61c0
-                    break
3d61c0
-            if not exists:
3d61c0
-                self.secure = False
3d61c0
-                return
3d61c0
+        guestFeatures = [f.name for f in self.features if f.policy == "require"]
3d61c0
+        if self.model.endswith("IBRS"):
3d61c0
+            guestFeatures.append("spec-ctrl")
3d61c0
+        if self.model.endswith("IBPB"):
3d61c0
+            guestFeatures.append("ibpb")
3d61c0
+
3d61c0
+        self.secure = set(features) <= set(guestFeatures)
3d61c0
 
3d61c0
     def _remove_security_features(self, guest):
3d61c0
         domcaps = guest.lookup_domcaps()
3d61c0
-- 
3d61c0
2.20.1
3d61c0