c313de
From cb2374042f3e998b90e6ea025dadfae9333b49cd Mon Sep 17 00:00:00 2001
c313de
Message-Id: <cb2374042f3e998b90e6ea025dadfae9333b49cd@dist-git>
c313de
From: Jiri Denemark <jdenemar@redhat.com>
c313de
Date: Fri, 21 Jun 2019 09:25:51 +0200
c313de
Subject: [PATCH] qemu: Add APIs for translating CPU features
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
So far we always used libvirt's name of each CPU feature relying on
c313de
backward compatible aliases in QEMU. The new translation table can be
c313de
used whenever QEMU mandates or prefers canonical feature names.
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 61ee757e2002507d711c195628619b9eff38b57a)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Message-Id: <5b080656d143733a77780affc6dd0d322216d6e7.1561068591.git.jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/qemu/qemu_capabilities.c | 64 ++++++++++++++++++++++++++++++++++++
c313de
 src/qemu/qemu_capabilities.h |  8 +++++
c313de
 2 files changed, 72 insertions(+)
c313de
c313de
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c313de
index 851cb73cfc..d2a2f7418a 100644
c313de
--- a/src/qemu/qemu_capabilities.c
c313de
+++ b/src/qemu/qemu_capabilities.c
c313de
@@ -2755,6 +2755,70 @@ virQEMUCapsCPUFilterFeatures(const char *name,
c313de
 }
c313de
 
c313de
 
c313de
+typedef struct _virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeatureTranslationTable;
c313de
+typedef virQEMUCapsCPUFeatureTranslationTable *virQEMUCapsCPUFeatureTranslationTablePtr;
c313de
+struct _virQEMUCapsCPUFeatureTranslationTable {
c313de
+    const char *libvirt;
c313de
+    const char *qemu;
c313de
+};
c313de
+
c313de
+virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeaturesX86[] = {
c313de
+    {"cmp_legacy", "cmp-legacy"},
c313de
+    {"ds_cpl", "ds-cpl"},
c313de
+    {"fxsr_opt", "fxsr-opt"},
c313de
+    {"kvm_pv_eoi", "kvm-pv-eoi"},
c313de
+    {"kvm_pv_unhalt", "kvm-pv-unhalt"},
c313de
+    {"lahf_lm", "lahf-lm"},
c313de
+    {"nodeid_msr", "nodeid-msr"},
c313de
+    {"pclmuldq", "pclmulqdq"},
c313de
+    {"perfctr_core", "perfctr-core"},
c313de
+    {"perfctr_nb", "perfctr-nb"},
c313de
+    {"tsc_adjust", "tsc-adjust"},
c313de
+    {NULL, NULL}
c313de
+};
c313de
+
c313de
+
c313de
+static const char *
c313de
+virQEMUCapsCPUFeatureTranslate(virQEMUCapsPtr qemuCaps,
c313de
+                               const char *feature,
c313de
+                               bool reversed)
c313de
+{
c313de
+    virQEMUCapsCPUFeatureTranslationTablePtr table = NULL;
c313de
+    virQEMUCapsCPUFeatureTranslationTablePtr entry;
c313de
+
c313de
+    if (ARCH_IS_X86(qemuCaps->arch))
c313de
+        table = virQEMUCapsCPUFeaturesX86;
c313de
+
c313de
+    if (!table || !feature)
c313de
+        return feature;
c313de
+
c313de
+    for (entry = table; entry->libvirt; entry++) {
c313de
+        const char *key = reversed ? entry->qemu : entry->libvirt;
c313de
+
c313de
+        if (STREQ(feature, key))
c313de
+            return reversed ? entry->libvirt : entry->qemu;
c313de
+    }
c313de
+
c313de
+    return feature;
c313de
+}
c313de
+
c313de
+
c313de
+const char *
c313de
+virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
c313de
+                            const char *feature)
c313de
+{
c313de
+    return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, false);
c313de
+}
c313de
+
c313de
+
c313de
+const char *
c313de
+virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
c313de
+                              const char *feature)
c313de
+{
c313de
+    return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, true);
c313de
+}
c313de
+
c313de
+
c313de
 /**
c313de
  * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
c313de
  *          1 when the caller should fall back to using virCapsPtr->host.cpu,
c313de
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
c313de
index bea4767f3c..8a27acd8a4 100644
c313de
--- a/src/qemu/qemu_capabilities.h
c313de
+++ b/src/qemu/qemu_capabilities.h
c313de
@@ -628,6 +628,14 @@ bool virQEMUCapsGuestIsNative(virArch host,
c313de
 bool virQEMUCapsCPUFilterFeatures(const char *name,
c313de
                                   void *opaque);
c313de
 
c313de
+const char *
c313de
+virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
c313de
+                            const char *feature);
c313de
+
c313de
+const char *
c313de
+virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
c313de
+                              const char *feature);
c313de
+
c313de
 virSEVCapabilityPtr
c313de
 virQEMUCapsGetSEVCapabilities(virQEMUCapsPtr qemuCaps);
c313de
 
c313de
-- 
c313de
2.22.0
c313de