render / rpms / libvirt

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