X86CPU: "feature-words"/"filtered-features" properties (v12)
cover X86CPU: "feature-words"/"filtered-features" properties (v12)
Resubmitting after a rebase and a few trivial changes.
Changes v11 -> v12:
* Remove unnecessary entries from .gitignore
* Fix indentation of x86_cpu_get_feature_words() declaration
* Rebase on top of qom-cpu-next
(commit bd87d2a - target-i386: Use FeatureWord loop on filter_features_for_kvm())
Git tree for reference:
git://github.com/ehabkost/qemu-hacks.git work/cpu-raw-features.v12
Eduardo Habkost (3):
target-i386: Add "feature-words" property
target-i386: Introduce X86CPU.filtered_features field
target-i386: Add "filtered-features" property to X86CPU
Makefile.objs | 7 ++++- qapi-schema.json | 32 ++++++++++++++++++++ target-i386/cpu-qom.h | 3 ++ target-i386/cpu.c | 82 +++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 108 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/3 target-i386: Add "feature-words" property
This property will be useful for libvirt, as libvirt already has logic based on low-level feature bits (not feature names), so it will be really easy to convert the current libvirt logic to something using the "feature-words" property.
The property will have two main use cases:
- Checking host capabilities, by checking the features of the "host" CPU model
- Checking which features are enabled on each CPU model
Example output:
$ ./QMP/qmp --path=/tmp/m qom-get --path=/machine/unattached/device[1] --property=feature-words item[0].cpuid-register: EDX item[0].cpuid-input-eax: 2147483658 item[0].features: 0 item[1].cpuid-register: EAX item[1].cpuid-input-eax: 1073741825 item[1].features: 0 item[2].cpuid-register: EDX item[2].cpuid-input-eax: 3221225473 item[2].features: 0 item[3].cpuid-register: ECX item[3].cpuid-input-eax: 2147483649 item[3].features: 101 item[4].cpuid-register: EDX item[4].cpuid-input-eax: 2147483649 item[4].features: 563346425 item[5].cpuid-register: EBX item[5].cpuid-input-eax: 7 item[5].features: 0 item[5].cpuid-input-ecx: 0 item[6].cpuid-register: ECX item[6].cpuid-input-eax: 1 item[6].features: 2155880449 item[7].cpuid-register: EDX item[7].cpuid-input-eax: 1 item[7].features: 126614521
---
Changes v11 -> v12:
* Remove unnecessary entries from .gitignore
* Fix indentation of x86_cpu_get_feature_words() declaration
* Rebase on top of qom-cpu-next
(commit bd87d2a - target-i386: Use FeatureWord loop on filter_features_for_kvm())
Changes v1 -> v2 (series marked as v11):
* Merge the non-qapi and qapi patches, to keep series simpler
* Use the feature word array series as base, so we don't have to set the feature word values one-by-one in the code
* Change type name of property from "x86-cpu-feature-words" to "X86CPUFeatureWordInfo"
* Remove cpu-qapi-schema.json and simply add the type definitions to qapi-schema.json, to keep the changes simpler
* This required compiling qapi-types.o and qapi-visit.o into *-user as well
--- Makefile.objs | 7 +++++- qapi-schema.json | 32 +++++++++++++++++++++++++ target-i386/cpu.c | 70 +++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 96 insertions(+), 13 deletions(-)
Makefile.objs +6 -1
@@ -79,10 +79,15 @@ common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y) ###################################################################### # qapi -common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o +common-obj-y += qmp-marshal.o common-obj-y += qmp.o hmp.o endif +###################################################################### +# some qapi visitors are used by both system and user emulation: + +common-obj-y += qapi-visit.o qapi-types.o + ####################################################################### # Target-independent parts used in system and user emulation common-obj-y += qemu-log.o
qapi-schema.json +32 -0
@@ -3587,3 +3587,35 @@ ## {'command': 'query-command-line-options', 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'] } + +## +# @X86CPURegister32 +# +# A X86 32-bit register +# +# Since: 1.5 +## +{ 'enum': 'X86CPURegister32', + 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } + +## +# @X86CPUFeatureWordInfo +# +# Information about a X86 CPU feature word +# +# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word +# +# @cpuid-input-ecx: #optional Input ECX value for CPUID instruction for that +# feature word +# +# @cpuid-register: Output register containing the feature bits +# +# @features: value of output register, containing the feature bits +# +# Since: 1.5 +## +{ 'type': 'X86CPUFeatureWordInfo', + 'data': { 'cpuid-input-eax': 'int', + '*cpuid-input-ecx': 'int', + 'cpuid-register': 'X86CPURegister32', + 'features': 'int' } }
target-i386/cpu.c +58 -12
99 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 2/3 target-i386: Introduce X86CPU.filtered_features field
In reply to Eduardo HabkostThis field will contain the feature bits that were filtered out because of missing host support.
---
Changes v11 -> v12:
* Rebase on top of qom-cpu-next
(commit bd87d2a - target-i386: Use FeatureWord loop on filter_features_for_kvm())
--- target-i386/cpu-qom.h | 3 +++ target-i386/cpu.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
target-i386/cpu-qom.h +3 -0
@@ -65,6 +65,9 @@ typedef struct X86CPU {/*< public >*/ CPUX86State env; + +/* Features that were filtered out because of missing host capabilities */ +uint32_t filtered_features[FEATURE_WORDS ]; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)
target-i386/cpu.c +6 -3
@@ -1698,9 +1698,12 @@ static void filter_features_for_kvm(X86CPU *cpu)for (w =0 ; w <FEATURE_WORDS ; w++) {FeatureWordInfo *wi = &feature_word_info[w]; - env->features[w] &=kvm_arch_get_supported_cpuid (s, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); +uint32_t host_feat =kvm_arch_get_supported_cpuid (s, wi->cpuid_eax, + wi->cpuid_ecx, + wi->cpuid_reg); +uint32_t requested_features = env->features[w]; + env->features[w] &= host_feat; + cpu->filtered_features[w] = requested_features & ~env->features[w]; } }#endif
Signature · 1 line
1.8.1.4
PATCH 3/3 target-i386: Add "filtered-features" property to X86CPU
In reply to Eduardo HabkostThis property will contain all the features that were removed from the CPU because they are not supported by the host.
This way, libvirt or other management tools can emulate the check/enforce behavior by checking if filtered-properties is all zeroes, before starting the guest.
Example output where some features were missing:
$ ./install/bin/qemu-system-x86_64 -enable-kvm -cpu Haswell,check -S -qmp unix:/tmp/m,server,nowait warning: host doesn't support requested feature: CPUID.01H:ECX.fma [bit 12] warning: host doesn't support requested feature: CPUID.01H:ECX.movbe [bit 22] warning: host doesn't support requested feature: CPUID.01H:ECX.tsc-deadline [bit 24] warning: host doesn't support requested feature: CPUID.01H:ECX.xsave [bit 26] warning: host doesn't support requested feature: CPUID.01H:ECX.avx [bit 28] warning: host doesn't support requested feature: CPUID.07H:EBX.fsgsbase [bit 0] warning: host doesn't support requested feature: CPUID.07H:EBX.bmi1 [bit 3] warning: host doesn't support requested feature: CPUID.07H:EBX.hle [bit 4] warning: host doesn't support requested feature: CPUID.07H:EBX.avx2 [bit 5] warning: host doesn't support requested feature: CPUID.07H:EBX.smep [bit 7] warning: host doesn't support requested feature: CPUID.07H:EBX.bmi2 [bit 8] warning: host doesn't support requested feature: CPUID.07H:EBX.erms [bit 9] warning: host doesn't support requested feature: CPUID.07H:EBX.invpcid [bit 10] warning: host doesn't support requested feature: CPUID.07H:EBX.rtm [bit 11] [...] $ ./QMP/qmp --path=/tmp/m qom-get --path=/machine/unattached/device[1] --property=filtered-features item[0].cpuid-register: EDX item[0].cpuid-input-eax: 2147483658 item[0].features: 0 item[1].cpuid-register: EAX item[1].cpuid-input-eax: 1073741825 item[1].features: 0 item[2].cpuid-register: EDX item[2].cpuid-input-eax: 3221225473 item[2].features: 0 item[3].cpuid-register: ECX item[3].cpuid-input-eax: 2147483649 item[3].features: 0 item[4].cpuid-register: EDX item[4].cpuid-input-eax: 2147483649 item[4].features: 0 item[5].cpuid-register: EBX item[5].cpuid-input-eax: 7 item[5].features: 4025 item[5].cpuid-input-ecx: 0 item[6].cpuid-register: ECX item[6].cpuid-input-eax: 1 item[6].features: 356519936 item[7].cpuid-register: EDX item[7].cpuid-input-eax: 1 item[7].features: 0
Example output when no feature is missing:
$ ./install/bin/qemu-system-x86_64 -enable-kvm -cpu Nehalem,enforce -S -qmp unix:/tmp/m,server,nowait [...] $ ./QMP/qmp --path=/tmp/m qom-get --path=/machine/unattached/device[1] --property=filtered-features item[0].cpuid-register: EDX item[0].cpuid-input-eax: 2147483658 item[0].features: 0 item[1].cpuid-register: EAX item[1].cpuid-input-eax: 1073741825 item[1].features: 0 item[2].cpuid-register: EDX item[2].cpuid-input-eax: 3221225473 item[2].features: 0 item[3].cpuid-register: ECX item[3].cpuid-input-eax: 2147483649 item[3].features: 0 item[4].cpuid-register: EDX item[4].cpuid-input-eax: 2147483649 item[4].features: 0 item[5].cpuid-register: EBX item[5].cpuid-input-eax: 7 item[5].features: 0 item[5].cpuid-input-ecx: 0 item[6].cpuid-register: ECX item[6].cpuid-input-eax: 1 item[6].features: 0 item[7].cpuid-register: EDX item[7].cpuid-input-eax: 1 item[7].features: 0
---
Changes v11 -> v12:
* Rebase on top of qom-cpu-next
(commit bd87d2a - target-i386: Use FeatureWord loop on filter_features_for_kvm())
--- target-i386/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target-i386/cpu.c +7 -4
@@ -1418,11 +1418,11 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, cpu->env.cpuid_apic_id = value; } +/* Generic getter for "feature-words" and "filtered-features" properties */ static void x86_cpu_get_feature_words (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) { -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; +uint32_t *array = (uint32_t *)opaque;FeatureWord w;Error *err =NULL ;X86CPUFeatureWordInfo word_infos[FEATURE_WORDS ] = { };
@@ -1436,7 +1436,7 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque, qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; qwi->cpuid_input_ecx = wi->cpuid_ecx; qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; - qwi->features = env->features[w]; + qwi->features = array[w];/* List will be in reverse order, but order shouldn't matter */ list_entries[w].next = list;
@@ -2444,7 +2444,10 @@ static void x86_cpu_initfn(Object *obj) x86_cpuid_set_apic_id, NULL, NULL, NULL);object_property_add (obj,"feature-words" ,"X86CPUFeatureWordInfo" , x86_cpu_get_feature_words, -NULL ,NULL ,NULL ,NULL ); +NULL ,NULL , (void *)env->features,NULL ); +object_property_add (obj,"filtered-features" ,"X86CPUFeatureWordInfo" , + x86_cpu_get_feature_words, +NULL ,NULL , (void *)cpu->filtered_features,NULL ); env->cpuid_apic_id =x86_cpu_apic_id_from_index (cs->cpu_index);
Signature · 1 line
1.8.1.4
Andreas Färber
AppliedAm 06.05.2013 18:20, schrieb Eduardo Habkost:
Quoted 8 lines
Resubmitting after a rebase and a few trivial changes.
Changes v11 -> v12:
* Remove unnecessary entries from .gitignore
* Fix indentation ofx86_cpu_get_feature_words()declaration
* Rebase on top of qom-cpu-next
(commit bd87d2a - target-i386: Use FeatureWord loop onfilter_features_for_kvm())
Quoted 8 lines
Git tree for reference:
git://github.com/ehabkost/qemu-hacks.gitwork/cpu-raw-features.v12Eduardo Habkost (3):
target-i386: Add "feature-words" property
target-i386: Introduce X86CPU.filtered_features field
target-i386: Add "filtered-features" property to X86CPU
Thanks, applied all to qom-cpu (tweaking some commit messages):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu
In particular I have edited the QOM paths to not rely on /machine/unassigned (since those may change, e.g., with QOM realize) and consistently line-broken commands within 76 chars.
Andreas
Quoted 5 lines
Makefile.objs | 7 ++++- qapi-schema.json | 32 ++++++++++++++++++++ target-i386/cpu-qom.h | 3 ++ target-i386/cpu.c | 82 +++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 108 insertions(+), 16 deletions(-)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg