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