From bb3363c90b5b19c37f8e5b8f512eb00014d2dae4 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Thu, 23 Feb 2017 13:53:51 +0100 Subject: [PATCH] qemu: Use full CPU model expansion on x86 The static CPU model expansion is designed to return only canonical names of all CPU properties. To maintain backwards compatibility libvirt is stuck with different spelling of some of the features, but we need to use the full expansion to get the additional spellings. In addition to returning all spelling variants for all properties the full expansion will contain properties which are not guaranteed to be migration compatible. Thus, we need to combine both expansions. First we need to call the static expansion to limit the result to migratable properties. Then we can use the result of the static expansion as an input to the full expansion to get both canonical names and their aliases. Signed-off-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 15 +- src/qemu/qemu_monitor.h | 2 + src/qemu/qemu_monitor_json.c | 21 +- .../qemu_2.9.0-tcg.x86_64.xml | 2 - .../qemu_2.9.0.x86_64.xml | 3 +- .../caps_2.9.0.x86_64.replies | 480 ++++++++++++++++++ .../caps_2.9.0.x86_64.xml | 182 +++++-- 7 files changed, 667 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 70a2409a36..8554313bbe 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2851,6 +2851,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, { qemuMonitorCPUModelInfoPtr *modelInfo; const char *model; + qemuMonitorCPUModelExpansionType type; if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) return 0; @@ -2863,9 +2864,17 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, model = "host"; } - return qemuMonitorGetCPUModelExpansion(mon, - QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC, - model, modelInfo); + /* Some x86_64 features defined in cpu_map.xml use spelling which differ + * from the one preferred by QEMU. Static expansion would give us only the + * preferred spelling, thus we need to do a full expansion on the result of + * the initial static expansion to get all variants of all features. + */ + if (ARCH_IS_X86(qemuCaps->arch)) + type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL; + else + type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC; + + return qemuMonitorGetCPUModelExpansion(mon, type, model, modelInfo); } struct tpmTypeToCaps { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index f9a9536bb4..847e9458a5 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -954,6 +954,8 @@ struct _qemuMonitorCPUModelInfo { typedef enum { QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC, + QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL, + QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL, } qemuMonitorCPUModelExpansionType; int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 39c04b62fe..3a29f1aa74 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5031,7 +5031,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelInfoPtr *model_info) { int ret = -1; - virJSONValuePtr model; + virJSONValuePtr model = NULL; virJSONValuePtr cmd = NULL; virJSONValuePtr reply = NULL; virJSONValuePtr data; @@ -5049,10 +5049,16 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, if (virJSONValueObjectAppendString(model, "name", model_name) < 0) goto cleanup; + retry: switch (type) { case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC: + case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL: typeStr = "static"; break; + + case QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL: + typeStr = "full"; + break; } if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion", @@ -5089,6 +5095,19 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, goto cleanup; } + /* QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL requests "full" expansion + * on the result of the initial "static" expansion. + */ + if (type == QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL) { + if (!(model = virJSONValueCopy(cpu_model))) + goto cleanup; + + virJSONValueFree(cmd); + virJSONValueFree(reply); + type = QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL; + goto retry; + } + if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-cpu-model-expansion reply data was missing 'name'")); diff --git a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml index 1827b1d6f9..573eb4bb6e 100644 --- a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml +++ b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml @@ -46,9 +46,7 @@ - - diff --git a/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml index a7a2ecdeaf..b361475d7e 100644 --- a/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml +++ b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml @@ -26,11 +26,10 @@ + - - qemu64 diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.replies b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.replies index 70f7df3cf4..f6109513a2 100644 --- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.replies +++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.replies @@ -14539,6 +14539,246 @@ "id": "libvirt-48" } +{ + "return": { + "model": { + "name": "base", + "props": { + "phys-bits": 0, + "core-id": -1, + "xlevel": 2147483656, + "cmov": true, + "ia64": false, + "aes": true, + "mmx": true, + "arat": true, + "rdpid": false, + "pause-filter": false, + "xsavec": true, + "osxsave": false, + "tsc-frequency": 0, + "xd": true, + "hv-vendor-id": "", + "kvm-asyncpf": true, + "kvm_asyncpf": true, + "perfctr_core": false, + "perfctr-core": false, + "mpx": true, + "avx512cd": false, + "decodeassists": false, + "pbe": false, + "sse4_1": true, + "sse4.1": true, + "sse4-1": true, + "family": 6, + "vmware-cpuid-freq": true, + "avx512f": false, + "xcrypt": false, + "hv-runtime": false, + "msr": true, + "mce": true, + "mca": true, + "thread-id": -1, + "min-level": 13, + "xgetbv1": true, + "cid": false, + "hv-relaxed": false, + "fxsr": true, + "ds": false, + "hv-crash": false, + "xsaveopt": true, + "xtpr": false, + "avx512-vpopcntdq": false, + "phe": false, + "avx512vl": false, + "extapic": false, + "3dnowprefetch": true, + "cr8legacy": false, + "cpuid-0xb": true, + "xcrypt-en": false, + "kvm_pv_eoi": true, + "apic-id": 4294967295, + "pn": false, + "dca": false, + "vendor": "GenuineIntel", + "pku": false, + "smx": false, + "cmp-legacy": false, + "cmp_legacy": false, + "avx512-4fmaps": false, + "vmcb-clean": false, + "vmcb_clean": false, + "3dnowext": false, + "hle": true, + "npt": false, + "memory": "/machine/unattached/system[0]", + "clwb": false, + "lbrv": false, + "adx": true, + "ss": true, + "pni": true, + "svm_lock": false, + "svm-lock": false, + "smep": true, + "pfthreshold": false, + "smap": true, + "x2apic": true, + "avx512vbmi": false, + "hv-stimer": false, + "i64": true, + "flushbyasid": false, + "f16c": true, + "ace2-en": false, + "pat": true, + "pae": true, + "sse": true, + "phe-en": false, + "kvm-nopiodelay": true, + "kvm_nopiodelay": true, + "tm": false, + "kvmclock-stable-bit": true, + "hypervisor": true, + "socket-id": -1, + "pcommit": false, + "syscall": true, + "level": 13, + "avx512dq": false, + "svm": false, + "full-cpuid-auto-level": true, + "hv-reset": false, + "invtsc": false, + "sse3": true, + "sse2": true, + "est": false, + "avx512ifma": false, + "tm2": false, + "kvm-pv-eoi": true, + "cx8": true, + "kvm-mmu": false, + "kvm_mmu": false, + "sse4_2": true, + "sse4.2": true, + "sse4-2": true, + "pge": true, + "fill-mtrr-mask": true, + "pdcm": false, + "nodeid_msr": false, + "model": 94, + "movbe": true, + "nrip-save": false, + "nrip_save": false, + "sse4a": false, + "ssse3": true, + "kvm_pv_unhalt": true, + "invpcid": true, + "pdpe1gb": true, + "tsc-deadline": true, + "fma": true, + "cx16": true, + "de": true, + "enforce": false, + "stepping": 3, + "xsave": true, + "clflush": true, + "skinit": false, + "tce": false, + "tsc": true, + "fpu": true, + "ds-cpl": false, + "ds_cpl": false, + "ibs": false, + "host-phys-bits": false, + "fma4": false, + "la57": false, + "osvw": false, + "check": true, + "hv-spinlocks": -1, + "pmm": false, + "apic": true, + "pmu": false, + "min-xlevel2": 0, + "tsc-adjust": true, + "tsc_adjust": true, + "kvm-steal-time": true, + "kvm_steal_time": true, + "kvmclock": true, + "l3-cache": true, + "lwp": false, + "xop": false, + "avx": true, + "ospke": false, + "ace2": false, + "acpi": false, + "avx512bw": false, + "hv-vapic": false, + "fsgsbase": true, + "ht": false, + "nx": true, + "pclmulqdq": true, + "mmxext": false, + "popcnt": true, + "xsaves": true, + "lm": true, + "umip": false, + "avx2": true, + "pse": true, + "sep": true, + "pclmuldq": true, + "nodeid-msr": false, + "kvm": true, + "misalignsse": false, + "min-xlevel": 2147483656, + "bmi2": true, + "bmi1": true, + "kvm-pv-unhalt": true, + "realized": false, + "tsc_scale": false, + "tsc-scale": false, + "topoext": false, + "hv-vpindex": false, + "xlevel2": 0, + "clflushopt": true, + "monitor": false, + "avx512er": false, + "pmm-en": false, + "pcid": true, + "3dnow": false, + "erms": true, + "lahf-lm": true, + "lahf_lm": true, + "xstore": false, + "hv-synic": false, + "fxsr-opt": false, + "fxsr_opt": false, + "rtm": true, + "lmce": true, + "hv-time": false, + "perfctr-nb": false, + "perfctr_nb": false, + "ffxsr": false, + "rdrand": true, + "rdseed": true, + "avx512-4vnniw": false, + "vme": true, + "vmx": true, + "dtes64": false, + "mtrr": true, + "rdtscp": true, + "pse36": true, + "tbm": false, + "wdt": false, + "pause_filter": false, + "model-id": "Intel(R) Xeon(R) CPU E3-1245 v5 @ 3.50GHz", + "sha-ni": false, + "abm": true, + "avx512pf": false, + "xstore-en": false + } + } + }, + "id": "libvirt-49" +} + { "return": { }, @@ -15068,3 +15308,243 @@ }, "id": "libvirt-3" } + +{ + "return": { + "model": { + "name": "base", + "props": { + "phys-bits": 0, + "core-id": -1, + "xlevel": 2147483658, + "cmov": true, + "ia64": false, + "aes": true, + "mmx": true, + "arat": true, + "rdpid": false, + "pause-filter": false, + "xsavec": false, + "osxsave": false, + "tsc-frequency": 0, + "xd": true, + "hv-vendor-id": "", + "kvm-asyncpf": false, + "kvm_asyncpf": false, + "perfctr_core": false, + "perfctr-core": false, + "mpx": true, + "avx512cd": false, + "decodeassists": false, + "pbe": false, + "sse4_1": true, + "sse4.1": true, + "sse4-1": true, + "family": 6, + "vmware-cpuid-freq": true, + "avx512f": false, + "xcrypt": false, + "hv-runtime": false, + "msr": true, + "mce": true, + "mca": true, + "thread-id": -1, + "min-level": 13, + "xgetbv1": true, + "cid": false, + "hv-relaxed": false, + "fxsr": true, + "ds": false, + "hv-crash": false, + "xsaveopt": true, + "xtpr": false, + "avx512-vpopcntdq": false, + "phe": false, + "avx512vl": false, + "extapic": false, + "3dnowprefetch": false, + "cr8legacy": true, + "cpuid-0xb": true, + "xcrypt-en": false, + "kvm_pv_eoi": false, + "apic-id": 4294967295, + "pn": false, + "dca": false, + "vendor": "AuthenticAMD", + "pku": true, + "smx": false, + "cmp-legacy": false, + "cmp_legacy": false, + "avx512-4fmaps": false, + "vmcb-clean": false, + "vmcb_clean": false, + "3dnowext": true, + "hle": false, + "npt": false, + "memory": "/machine/unattached/system[0]", + "clwb": true, + "lbrv": false, + "adx": true, + "ss": true, + "pni": true, + "svm_lock": false, + "svm-lock": false, + "smep": true, + "pfthreshold": false, + "smap": true, + "x2apic": false, + "avx512vbmi": false, + "hv-stimer": false, + "i64": true, + "flushbyasid": false, + "f16c": false, + "ace2-en": false, + "pat": true, + "pae": true, + "sse": true, + "phe-en": false, + "kvm-nopiodelay": false, + "kvm_nopiodelay": false, + "tm": false, + "kvmclock-stable-bit": false, + "hypervisor": true, + "socket-id": -1, + "pcommit": true, + "syscall": true, + "level": 13, + "avx512dq": false, + "svm": true, + "full-cpuid-auto-level": true, + "hv-reset": false, + "invtsc": false, + "sse3": true, + "sse2": true, + "est": false, + "avx512ifma": false, + "tm2": false, + "kvm-pv-eoi": false, + "cx8": true, + "kvm-mmu": false, + "kvm_mmu": false, + "sse4_2": true, + "sse4.2": true, + "sse4-2": true, + "pge": true, + "fill-mtrr-mask": true, + "pdcm": false, + "nodeid_msr": false, + "model": 6, + "movbe": true, + "nrip-save": false, + "nrip_save": false, + "sse4a": true, + "ssse3": true, + "kvm_pv_unhalt": false, + "invpcid": false, + "pdpe1gb": true, + "tsc-deadline": false, + "fma": false, + "cx16": true, + "de": true, + "enforce": false, + "stepping": 3, + "xsave": true, + "clflush": true, + "skinit": false, + "tce": false, + "tsc": true, + "fpu": true, + "ds-cpl": false, + "ds_cpl": false, + "ibs": false, + "host-phys-bits": false, + "fma4": false, + "la57": true, + "osvw": false, + "check": true, + "hv-spinlocks": -1, + "pmm": false, + "apic": true, + "pmu": false, + "min-xlevel2": 0, + "tsc-adjust": false, + "tsc_adjust": false, + "kvm-steal-time": false, + "kvm_steal_time": false, + "kvmclock": false, + "l3-cache": true, + "lwp": false, + "xop": false, + "avx": false, + "ospke": true, + "ace2": false, + "acpi": true, + "avx512bw": false, + "hv-vapic": false, + "fsgsbase": true, + "ht": false, + "nx": true, + "pclmulqdq": true, + "mmxext": true, + "popcnt": true, + "xsaves": false, + "lm": true, + "umip": false, + "avx2": false, + "pse": true, + "sep": true, + "pclmuldq": true, + "nodeid-msr": false, + "kvm": true, + "misalignsse": false, + "min-xlevel": 2147483658, + "bmi2": true, + "bmi1": true, + "kvm-pv-unhalt": false, + "realized": false, + "tsc_scale": false, + "tsc-scale": false, + "topoext": false, + "hv-vpindex": false, + "xlevel2": 0, + "clflushopt": true, + "monitor": true, + "avx512er": false, + "pmm-en": false, + "pcid": false, + "3dnow": true, + "erms": true, + "lahf-lm": true, + "lahf_lm": true, + "xstore": false, + "hv-synic": false, + "fxsr-opt": false, + "fxsr_opt": false, + "rtm": false, + "lmce": false, + "hv-time": false, + "perfctr-nb": false, + "perfctr_nb": false, + "ffxsr": false, + "rdrand": false, + "rdseed": false, + "avx512-4vnniw": false, + "vme": false, + "vmx": false, + "dtes64": false, + "mtrr": true, + "rdtscp": true, + "pse36": true, + "tbm": false, + "wdt": false, + "pause_filter": false, + "model-id": "QEMU TCG CPU version 2.5+", + "sha-ni": false, + "abm": true, + "avx512pf": false, + "xstore-en": false + } + } + }, + "id": "libvirt-4" +} diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml index 44c24b047b..334f8e74bd 100644 --- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml @@ -207,80 +207,110 @@ (v2.8.0-1961-g5b10b94bd5) x86_64 + + + - + + + + + + - + + + + + + - + - + + + - + + + + + - + + + + - + + + - + + + + + + + @@ -288,44 +318,62 @@ + + + + + - + + + + - + + + - + + + + + + + + + - + @@ -335,17 +383,23 @@ - + + + - + + + + + @@ -354,11 +408,17 @@ - + + + + + + + @@ -370,6 +430,7 @@ + @@ -377,80 +438,110 @@ + + + - + + + + + + - + + + + + + - + - + + + - + + + + + - + + + + - + + + - + + + + + + + @@ -458,44 +549,62 @@ + + + + + - + + + + - + + + - + + + + + + + + + - + @@ -505,17 +614,23 @@ - + + + - + + + + + @@ -524,11 +639,17 @@ - + + + + + + + @@ -540,6 +661,7 @@ +