Blob Blame History Raw
From acb2d441abd4b584c40748cbaf4f6f7a376753aa Mon Sep 17 00:00:00 2001
Message-Id: <acb2d441abd4b584c40748cbaf4f6f7a376753aa@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 15 Nov 2019 17:52:32 +0100
Subject: [PATCH] cpu_conf: Pass policy to CPU feature filtering callbacks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 668797dc5cb474585609559dbe610e09517e23e6)

https://bugzilla.redhat.com/show_bug.cgi?id=1749672
https://bugzilla.redhat.com/show_bug.cgi?id=1756156
https://bugzilla.redhat.com/show_bug.cgi?id=1721608

Conflicts:
	src/cpu/cpu_x86.c
	src/qemu/qemu_capabilities.c
            - no glib stuff downstream

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <e35cd40bd84f7304288051c24fa0d4581c3d43cb.1573836581.git.jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/cpu_conf.c          |  6 +++---
 src/conf/cpu_conf.h          |  1 +
 src/cpu/cpu_x86.c            | 13 ++++++++++++-
 src/cpu/cpu_x86.h            |  2 ++
 src/qemu/qemu_capabilities.c |  1 +
 src/qemu/qemu_capabilities.h |  1 +
 6 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 4cccea9981..d4e3c81145 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -135,7 +135,7 @@ virCPUDefCopyModelFilter(virCPUDefPtr dst,
     dst->nfeatures = 0;
 
     for (i = 0; i < src->nfeatures; i++) {
-        if (filter && !filter(src->features[i].name, opaque))
+        if (filter && !filter(src->features[i].name, src->features[i].policy, opaque))
             continue;
 
         n = dst->nfeatures++;
@@ -858,7 +858,7 @@ virCPUDefFilterFeatures(virCPUDefPtr cpu,
     size_t i = 0;
 
     while (i < cpu->nfeatures) {
-        if (filter(cpu->features[i].name, opaque)) {
+        if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
             i++;
             continue;
         }
@@ -893,7 +893,7 @@ virCPUDefCheckFeatures(virCPUDefPtr cpu,
     *features = NULL;
 
     for (i = 0; i < cpu->nfeatures; i++) {
-        if (filter(cpu->features[i].name, opaque)) {
+        if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
             if (virStringListAdd(&list, cpu->features[i].name) < 0)
                 return -1;
             n++;
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index cba0ec7c81..687e1b09d2 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -162,6 +162,7 @@ virCPUDefCopyModel(virCPUDefPtr dst,
  * Returns true if feature @name should copied, false otherwise.
  */
 typedef bool (*virCPUDefFeatureFilter)(const char *name,
+                                       virCPUFeaturePolicy policy,
                                        void *opaque);
 
 int
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 9104bdbf1e..cf5ef442e7 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3260,6 +3260,15 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu)
 }
 
 
+static bool
+x86FeatureFilterMigratable(const char *name,
+                           virCPUFeaturePolicy policy ATTRIBUTE_UNUSED,
+                           void *cpu_map)
+{
+    return x86FeatureIsMigratable(name, cpu_map);
+}
+
+
 static virCPUDefPtr
 virCPUx86CopyMigratable(virCPUDefPtr cpu)
 {
@@ -3273,7 +3282,7 @@ virCPUx86CopyMigratable(virCPUDefPtr cpu)
         return NULL;
 
     if (virCPUDefCopyModelFilter(copy, cpu, false,
-                                 x86FeatureIsMigratable, map) < 0)
+                                 x86FeatureFilterMigratable, map) < 0)
         goto error;
 
     return copy;
@@ -3408,6 +3417,7 @@ virCPUx86FeatureIsMSR(const char *name)
  */
 bool
 virCPUx86FeatureFilterSelectMSR(const char *name,
+                                virCPUFeaturePolicy policy ATTRIBUTE_UNUSED,
                                 void *opaque ATTRIBUTE_UNUSED)
 {
     return virCPUx86FeatureIsMSR(name);
@@ -3424,6 +3434,7 @@ virCPUx86FeatureFilterSelectMSR(const char *name,
  */
 bool
 virCPUx86FeatureFilterDropMSR(const char *name,
+                              virCPUFeaturePolicy policy ATTRIBUTE_UNUSED,
                               void *opaque ATTRIBUTE_UNUSED)
 {
     return !virCPUx86FeatureIsMSR(name);
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 5126679985..866fe17e88 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -46,9 +46,11 @@ int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
                            const char *vendor);
 
 bool virCPUx86FeatureFilterSelectMSR(const char *name,
+                                     virCPUFeaturePolicy policy,
                                      void *opaque);
 
 bool virCPUx86FeatureFilterDropMSR(const char *name,
+                                   virCPUFeaturePolicy policy,
                                    void *opaque);
 
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index fbfe74d45b..c25d8c3e1a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2753,6 +2753,7 @@ virQEMUCapsProbeQMPSEVCapabilities(virQEMUCapsPtr qemuCaps,
 
 bool
 virQEMUCapsCPUFilterFeatures(const char *name,
+                             virCPUFeaturePolicy policy ATTRIBUTE_UNUSED,
                              void *opaque)
 {
     virArch *arch = opaque;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 1767b2ab6c..a4055d5458 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -629,6 +629,7 @@ bool virQEMUCapsGuestIsNative(virArch host,
                               virArch guest);
 
 bool virQEMUCapsCPUFilterFeatures(const char *name,
+                                  virCPUFeaturePolicy policy,
                                   void *opaque);
 
 const char *
-- 
2.24.0