target-i386: convert CPU features into properties
v5 cover target-i386: convert CPU features into properties
v5:
- Use static properties instead of dynamic ones
- Compile in KVM CPUID features only if CONFIG_KVM is defined
- Add "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID feature names
- Some qdev hacking to:
- allow iterate over Property[] before object instance exists
- find a static bit property definition by specifying bit number and field's offset
- Replace error_set() with error_setg() where patches touch it.
git tree for testing:
https://github.com/imammedo/qemu/tree/x86-cpu-properties.v5
Depends on "CPU as Device" series:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02776.html
Reference to a previous version:
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg00210.html
Igor Mammedov (37):
target-i386: return Error from cpu_x86_find_by_name()
target-i386: cpu_x86_register(): report error from property setter
target-i386: if x86_cpu_realize() failed report error and do cleanup
target-i386: filter out not TCG features if running without kvm at
realize time
target-i386: move out CPU features initialization in separate func add visitor for parsing hz[KMG] input string
target-i386: use visit_type_hz to parse tsc_freq property value
target-i386: define static properties for cpuid features
qdev: export qdev_prop_find() and allow it to be used with
DeviceClass instead of Object
target-i386: parse cpu_model string into set of stringified
properties
target-i386: introduce vendor-override static property
target-i386: convert "xlevel" to static property
target-i386: convert "level" to static property
target-i386: postpone cpuid_level update to realize time
target-i386: set default value of "hypervisor" feature using static
property
target-i386: set kvm CPUID default feature values using static
properties
target-i386: make 'f-kvmclock' compatible with legacy behaviour
target-i386: add stubs for
hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
qdev: add DEFINE_ABSTRACT_PROP() helper
target-i386: convert 'hv_spinlocks' to static property
target-i386: convert 'hv_relaxed' to static property
target-i386: convert 'hv_vapic' to static property
target-i386: convert 'check' and 'enforce' to static properties
target-i386: use define for cpuid vendor string size
target-i386: replace uint32_t vendor fields by vendor string in
x86_def_t
target-i386: convert "vendor" property to static property
target-i386: convert "tsc-frequency" to static property
target-i386: convert "model-id" to static property
target-i386: convert "stepping" to static property
target-i386: convert "model" to static property
target-i386: convert "family" to static property
target-i386: use static properties for setting cpuid features
qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREACH
qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit()
target-i386: use static properties in check_features_against_host()
to print CPUID feature names
target-i386: use static properties to list CPUID features
target-i386: cleanup cpu_x86_find_by_name(), only fill x86_def_t in
it
hw/qdev-properties.h | 26 +- qapi/qapi-visit-core.c | 11 + qapi/qapi-visit-core.h | 2 + qapi/string-input-visitor.c | 22 + qom/qdev-core.c | 10 +- qom/qdev-properties.c | 50 +- target-i386/cpu.c | 1667 +++++++++++++++++++++++-------------------- target-i386/cpu.h | 12 +- target-i386/helper.c | 9 +- target-i386/hyperv.h | 9 +- 10 files changed, 992 insertions(+), 826 deletions(-)
Signature · 1 line
1.7.11.7
PATCH v5 1/37 target-i386: return Error from cpu_x86_find_by_name()
it will allow to use property setters there later.
--
v2:
- style change, add braces (requested by Blue Swirl)
- removed unused error_is_set(errp) in properties set loop
v3:
- removed unnecessary whitespace change
--- target-i386/cpu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
target-i386/cpu.c +11 -3
@@ -1097,7 +1097,8 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = value /1000 ; } -static int cpu_x86_find_by_name (x86_def_t *x86_cpu_def,const char *cpu_model) +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def, +const char *cpu_model,Error **errp) {unsigned int i;x86_def_t *def;
@@ -1282,6 +1283,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) error:g_free (s); +if (!error_is_set (errp)) { +error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); + }return -1 ; }
@@ -1368,8 +1372,10 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)memset (def,0 ,sizeof (*def)); -if (cpu_x86_find_by_name (def, cpu_model) <0 ) -return -1 ; +if (cpu_x86_find_by_name (cpu, def, cpu_model, &error) <0 ) { + goto out; + } +if (def->vendor1) { env->cpuid_vendor1 = def->vendor1; env->cpuid_vendor2 = def->vendor2;
@@ -1419,6 +1425,8 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) env->cpuid_svm_features &=TCG_SVM_FEATURES ; }object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , &error); + +out:if (error_is_set (&error)) {error_free (error);return -1 ;
Signature · 1 line
1.7.11.7
PATCH v5 2/37 target-i386: cpu_x86_register(): report error from property setter
In reply to Igor Mammedov---
v2:
- replace "if (error_is_set(&error))" with "if (error)"
--- target-i386/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target-i386/cpu.c +2 -1
@@ -1427,7 +1427,8 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , &error); out: -if (error_is_set (&error)) { +if (error) { +fprintf (stderr,"%s\n" ,error_get_pretty (error));error_free (error);return -1 ; }
Signature · 1 line
1.7.11.7
PATCH v5 3/37 target-i386: if x86_cpu_realize() failed report error and do cleanup
In reply to Igor Mammedov---
v2:
- replaced "if (error_is_set(&error))" with "if (error)"
--- target-i386/helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target-i386/helper.c +7 -2
@@ -1243,6 +1243,7 @@ X86CPU *cpu_x86_init(const char *cpu_model) {X86CPU *cpu;CPUX86State *env; +Error *error =NULL ; cpu =X86_CPU (object_new (TYPE_X86_CPU )); env = &cpu->env;
@@ -1253,8 +1254,12 @@ X86CPU *cpu_x86_init(const char *cpu_model)return NULL ; } -x86_cpu_realize (OBJECT (cpu),NULL ); - +x86_cpu_realize (OBJECT (cpu), &error); +if (error) { +error_free (error); +object_delete (OBJECT (cpu)); +return NULL ; + }return cpu; }
Signature · 1 line
1.7.11.7
PATCH v5 4/37 target-i386: filter out not TCG features if running without kvm at realize time
In reply to Igor Mammedov--- target-i386/cpu.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
target-i386/cpu.c +14 -11
@@ -1413,17 +1413,7 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) env->cpuid_ext2_features |= (def->features &CPUID_EXT2_AMD_ALIASES ); } -if (!kvm_enabled ()) { - env->cpuid_features &=TCG_FEATURES ; - env->cpuid_ext_features &=TCG_EXT_FEATURES ; - env->cpuid_ext2_features &= (TCG_EXT2_FEATURES -#ifdef TARGET_X86_64 - |CPUID_EXT2_SYSCALL |CPUID_EXT2_LM -#endif - ); - env->cpuid_ext3_features &=TCG_EXT3_FEATURES ; - env->cpuid_svm_features &=TCG_SVM_FEATURES ; - } +object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , &error); out:
@@ -1882,6 +1872,19 @@ static void mce_init(X86CPU *cpu)void x86_cpu_realize (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; + +if (!kvm_enabled ()) { + env->cpuid_features &=TCG_FEATURES ; + env->cpuid_ext_features &=TCG_EXT_FEATURES ; + env->cpuid_ext2_features &= (TCG_EXT2_FEATURES +#ifdef TARGET_X86_64 + |CPUID_EXT2_SYSCALL |CPUID_EXT2_LM +#endif + ); + env->cpuid_ext3_features &=TCG_EXT3_FEATURES ; + env->cpuid_svm_features &=TCG_SVM_FEATURES ; + }#ifndef CONFIG_USER_ONLY qemu_register_reset (x86_cpu_machine_reset_cb, cpu);
Signature · 1 line
1.7.11.7
PATCH v5 5/37 target-i386: move out CPU features initialization in separate func
In reply to Igor Mammedovlater it could be used in cpu_x86_find_by_name() to init CPU from found cpu_def
--
v2:
- rebased on top of "i386: cpu: remove duplicate feature names"
http://www.mail-archive.com/[email protected]/msg129458.html --- target-i386/cpu.c | 84 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 40 deletions(-)
target-i386/cpu.c +44 -40
@@ -1097,6 +1097,49 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = value /1000 ; } +static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) +{ +CPUX86State *env = &cpu->env; + +if (def->vendor1) { + env->cpuid_vendor1 = def->vendor1; + env->cpuid_vendor2 = def->vendor2; + env->cpuid_vendor3 = def->vendor3; + }else { + env->cpuid_vendor1 =CPUID_VENDOR_INTEL_1 ; + env->cpuid_vendor2 =CPUID_VENDOR_INTEL_2 ; + env->cpuid_vendor3 =CPUID_VENDOR_INTEL_3 ; + } + env->cpuid_vendor_override = def->vendor_override; +object_property_set_int (OBJECT (cpu), def->level,"level" , errp); +object_property_set_int (OBJECT (cpu), def->family,"family" , errp); +object_property_set_int (OBJECT (cpu), def->model,"model" , errp); +object_property_set_int (OBJECT (cpu), def->stepping,"stepping" , errp); +object_property_set_int (OBJECT (cpu), def->xlevel,"xlevel" , errp); +object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , errp); +object_property_set_int (OBJECT (cpu), (int64_t )def->tsc_khz *1000 , +"tsc-frequency" , errp); + env->cpuid_features = def->features; + env->cpuid_ext_features = def->ext_features; + env->cpuid_ext2_features = def->ext2_features; + env->cpuid_ext3_features = def->ext3_features; + env->cpuid_kvm_features = def->kvm_features; + env->cpuid_svm_features = def->svm_features; + env->cpuid_ext4_features = def->ext4_features; + env->cpuid_7_0_ebx_features = def->cpuid_7_0_ebx_features; + env->cpuid_xlevel2 = def->xlevel2; + +/* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on +* CPUID[1].EDX. +*/ +if (env->cpuid_vendor1 ==CPUID_VENDOR_AMD_1 && + env->cpuid_vendor2 ==CPUID_VENDOR_AMD_2 && + env->cpuid_vendor3 ==CPUID_VENDOR_AMD_3 ) { + env->cpuid_ext2_features &= ~CPUID_EXT2_AMD_ALIASES ; + env->cpuid_ext2_features |= (def->features &CPUID_EXT2_AMD_ALIASES ); + } +} +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) {
@@ -1366,7 +1409,6 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)int cpu_x86_register (X86CPU *cpu,const char *cpu_model) { -CPUX86State *env = &cpu->env;x86_def_t def1, *def = &def1;Error *error =NULL ;
@@ -1376,45 +1418,7 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) goto out; } -if (def->vendor1) { - env->cpuid_vendor1 = def->vendor1; - env->cpuid_vendor2 = def->vendor2; - env->cpuid_vendor3 = def->vendor3; - }else { - env->cpuid_vendor1 =CPUID_VENDOR_INTEL_1 ; - env->cpuid_vendor2 =CPUID_VENDOR_INTEL_2 ; - env->cpuid_vendor3 =CPUID_VENDOR_INTEL_3 ; - } - env->cpuid_vendor_override = def->vendor_override; -object_property_set_int (OBJECT (cpu), def->level,"level" , &error); -object_property_set_int (OBJECT (cpu), def->family,"family" , &error); -object_property_set_int (OBJECT (cpu), def->model,"model" , &error); -object_property_set_int (OBJECT (cpu), def->stepping,"stepping" , &error); - env->cpuid_features = def->features; - env->cpuid_ext_features = def->ext_features; - env->cpuid_ext2_features = def->ext2_features; - env->cpuid_ext3_features = def->ext3_features; -object_property_set_int (OBJECT (cpu), def->xlevel,"xlevel" , &error); - env->cpuid_kvm_features = def->kvm_features; - env->cpuid_svm_features = def->svm_features; - env->cpuid_ext4_features = def->ext4_features; - env->cpuid_7_0_ebx_features = def->cpuid_7_0_ebx_features; - env->cpuid_xlevel2 = def->xlevel2; -object_property_set_int (OBJECT (cpu), (int64_t )def->tsc_khz *1000 , -"tsc-frequency" , &error); - -/* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on -* CPUID[1].EDX. -*/ -if (env->cpuid_vendor1 ==CPUID_VENDOR_AMD_1 && - env->cpuid_vendor2 ==CPUID_VENDOR_AMD_2 && - env->cpuid_vendor3 ==CPUID_VENDOR_AMD_3 ) { - env->cpuid_ext2_features &= ~CPUID_EXT2_AMD_ALIASES ; - env->cpuid_ext2_features |= (def->features &CPUID_EXT2_AMD_ALIASES ); - } - - -object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , &error); +cpudef_2_x86_cpu (cpu, def, &error); out:if (error) {
Signature · 1 line
1.7.11.7
PATCH v5 6/37 add visitor for parsing hz[KMG] input string
In reply to Igor Mammedov---
v2:
* replaced _hz suffix for frequency visitor by _freq suffix
suggested-by: Andreas Färber
* fixed typo & extra space spotted-by: Andreas Färber
* initialize val, due to a silly CentOS6 compiler warning, that breakes build when -Werror is set. suggested-by: Don Slutz
--- qapi/qapi-visit-core.c | 11 +++++++++++ qapi/qapi-visit-core.h | 2 ++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+)
qapi/qapi-visit-core.c +11 -0
@@ -311,3 +311,14 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_type_freq (Visitor *v,int64_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { +if (v->type_freq) { + v->type_freq (v, obj, name, errp); + }else { + v->type_int (v, obj, name, errp); + } + } +}
qapi/qapi-visit-core.h +2 -0
@@ -62,6 +62,7 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_freq)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -91,5 +92,6 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_type_freq (Visitor *v,int64_t *obj,const char *name,Error **errp);#endif
qapi/string-input-visitor.c +22 -0
@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_freq (Visitor *v,int64_t *obj,const char *name, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + + errno =0 ; +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B ,1000 ); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" ); +return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;
@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_freq = parse_type_freq; v->string = str;return v;
Signature · 1 line
1.7.11.7
PATCH v5 7/37 target-i386: use visit_type_hz to parse tsc_freq property value
In reply to Igor Mammedov---
v2:
* use visit_type_freq() which replaced visit_type_hz()
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -1084,7 +1084,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value; -visit_type_int (v, &value, name, errp); +visit_type_freq (v, &value, name, errp);if (error_is_set (errp)) {return ; }
Signature · 1 line
1.7.11.7
PATCH v5 8/37 target-i386: define static properties for cpuid features
In reply to Igor Mammedov- static properties names of CPUID features are changed to have "f-" prefix, so that it would be easy to distinguish them from other properties.
- use X86CPU as a type to count of offset correctly, because env field isn't starting at CPUstate begining, but located after it.
--- target-i386/cpu.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
target-i386/cpu.c +112 -0
@@ -33,6 +33,7 @@#include "hyperv.h" #include "hw/hw.h" +#include "hw/qdev-properties.h" #if defined(CONFIG_KVM )#include <linux/kvm_para.h> #endif
@@ -111,6 +112,115 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +static Property cpu_x86_properties[] = { +DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false), +DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false), +DEFINE_PROP_BIT ("f-de" ,X86CPU , env.cpuid_features,2 , false), +DEFINE_PROP_BIT ("f-pse" ,X86CPU , env.cpuid_features,3 , false), +DEFINE_PROP_BIT ("f-tsc" ,X86CPU , env.cpuid_features,4 , false), +DEFINE_PROP_BIT ("f-msr" ,X86CPU , env.cpuid_features,5 , false), +DEFINE_PROP_BIT ("f-pae" ,X86CPU , env.cpuid_features,6 , false), +DEFINE_PROP_BIT ("f-mce" ,X86CPU , env.cpuid_features,7 , false), +DEFINE_PROP_BIT ("f-cx8" ,X86CPU , env.cpuid_features,8 , false), +DEFINE_PROP_BIT ("f-apic" ,X86CPU , env.cpuid_features,9 , false), +DEFINE_PROP_BIT ("f-sep" ,X86CPU , env.cpuid_features,11 , false), +DEFINE_PROP_BIT ("f-mtrr" ,X86CPU , env.cpuid_features,12 , false), +DEFINE_PROP_BIT ("f-pge" ,X86CPU , env.cpuid_features,13 , false), +DEFINE_PROP_BIT ("f-mca" ,X86CPU , env.cpuid_features,14 , false), +DEFINE_PROP_BIT ("f-cmov" ,X86CPU , env.cpuid_features,15 , false), +DEFINE_PROP_BIT ("f-pat" ,X86CPU , env.cpuid_features,16 , false), +DEFINE_PROP_BIT ("f-pse36" ,X86CPU , env.cpuid_features,17 , false), +DEFINE_PROP_BIT ("f-pn" /* Intel psn */ ,X86CPU , env.cpuid_features,18 , false), +DEFINE_PROP_BIT ("f-clflush" /* Intel clfsh */ ,X86CPU , env.cpuid_features,19 , false), +DEFINE_PROP_BIT ("f-ds" /* Intel dts */ ,X86CPU , env.cpuid_features,21 , false), +DEFINE_PROP_BIT ("f-acpi" ,X86CPU , env.cpuid_features,22 , false), +DEFINE_PROP_BIT ("f-mmx" ,X86CPU , env.cpuid_features,23 , false), +DEFINE_PROP_BIT ("f-fxsr" ,X86CPU , env.cpuid_features,24 , false), +DEFINE_PROP_BIT ("f-sse" ,X86CPU , env.cpuid_features,25 , false), +DEFINE_PROP_BIT ("f-sse2" ,X86CPU , env.cpuid_features,26 , false), +DEFINE_PROP_BIT ("f-ss" ,X86CPU , env.cpuid_features,27 , false), +DEFINE_PROP_BIT ("f-ht" /* Intel htt */ ,X86CPU , env.cpuid_features,28 , false), +DEFINE_PROP_BIT ("f-tm" ,X86CPU , env.cpuid_features,29 , false), +DEFINE_PROP_BIT ("f-ia64" ,X86CPU , env.cpuid_features,30 , false), +DEFINE_PROP_BIT ("f-pbe" ,X86CPU , env.cpuid_features,31 , false), +DEFINE_PROP_BIT ("f-pni" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-sse3" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-pclmulqdq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-pclmuldq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-dtes64" ,X86CPU , env.cpuid_ext_features,2 , false), +DEFINE_PROP_BIT ("f-monitor" ,X86CPU , env.cpuid_ext_features,3 , false), +DEFINE_PROP_BIT ("f-ds_cpl" ,X86CPU , env.cpuid_ext_features,4 , false), +DEFINE_PROP_BIT ("f-vmx" ,X86CPU , env.cpuid_ext_features,5 , false), +DEFINE_PROP_BIT ("f-smx" ,X86CPU , env.cpuid_ext_features,6 , false), +DEFINE_PROP_BIT ("f-est" ,X86CPU , env.cpuid_ext_features,7 , false), +DEFINE_PROP_BIT ("f-tm2" ,X86CPU , env.cpuid_ext_features,8 , false), +DEFINE_PROP_BIT ("f-ssse3" ,X86CPU , env.cpuid_ext_features,9 , false), +DEFINE_PROP_BIT ("f-cid" ,X86CPU , env.cpuid_ext_features,10 , false), +DEFINE_PROP_BIT ("f-fma" ,X86CPU , env.cpuid_ext_features,12 , false), +DEFINE_PROP_BIT ("f-cx16" ,X86CPU , env.cpuid_ext_features,13 , false), +DEFINE_PROP_BIT ("f-xtpr" ,X86CPU , env.cpuid_ext_features,14 , false), +DEFINE_PROP_BIT ("f-pdcm" ,X86CPU , env.cpuid_ext_features,15 , false), +DEFINE_PROP_BIT ("f-pcid" ,X86CPU , env.cpuid_ext_features,17 , false), +DEFINE_PROP_BIT ("f-dca" ,X86CPU , env.cpuid_ext_features,18 , false), +DEFINE_PROP_BIT ("f-sse4.1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4.2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-sse4_1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4_2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-x2apic" ,X86CPU , env.cpuid_ext_features,21 , false), +DEFINE_PROP_BIT ("f-movbe" ,X86CPU , env.cpuid_ext_features,22 , false), +DEFINE_PROP_BIT ("f-popcnt" ,X86CPU , env.cpuid_ext_features,23 , false), +DEFINE_PROP_BIT ("f-tsc-deadline" ,X86CPU , env.cpuid_ext_features,24 , false), +DEFINE_PROP_BIT ("f-aes" ,X86CPU , env.cpuid_ext_features,25 , false), +DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false), +DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false), +DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false), +DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-xd" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-mmxext" ,X86CPU , env.cpuid_ext2_features,22 , false), +DEFINE_PROP_BIT ("f-fxsr_opt" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-ffxsr" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-pdpe1gb" /* AMD Page1GB */ ,X86CPU , env.cpuid_ext2_features,26 , false), +DEFINE_PROP_BIT ("f-rdtscp" ,X86CPU , env.cpuid_ext2_features,27 , false), +DEFINE_PROP_BIT ("f-lahf_lm" /* AMD LahfSahf */ ,X86CPU , env.cpuid_ext3_features,0 , false), +DEFINE_PROP_BIT ("f-cmp_legacy" ,X86CPU , env.cpuid_ext3_features,1 , false), +DEFINE_PROP_BIT ("f-svm" ,X86CPU , env.cpuid_ext3_features,2 , false), +DEFINE_PROP_BIT ("f-extapic" /* AMD ExtApicSpace */ ,X86CPU , env.cpuid_ext3_features,3 , false), +DEFINE_PROP_BIT ("f-cr8legacy" /* AMD AltMovCr8 */ ,X86CPU , env.cpuid_ext3_features,4 , false), +DEFINE_PROP_BIT ("f-abm" ,X86CPU , env.cpuid_ext3_features,5 , false), +DEFINE_PROP_BIT ("f-sse4a" ,X86CPU , env.cpuid_ext3_features,6 , false), +DEFINE_PROP_BIT ("f-misalignsse" ,X86CPU , env.cpuid_ext3_features,7 , false), +DEFINE_PROP_BIT ("f-3dnowprefetch" ,X86CPU , env.cpuid_ext3_features,8 , false), +DEFINE_PROP_BIT ("f-osvw" ,X86CPU , env.cpuid_ext3_features,9 , false), +DEFINE_PROP_BIT ("f-ibs" ,X86CPU , env.cpuid_ext3_features,10 , false), +DEFINE_PROP_BIT ("f-xop" ,X86CPU , env.cpuid_ext3_features,11 , false), +DEFINE_PROP_BIT ("f-skinit" ,X86CPU , env.cpuid_ext3_features,12 , false), +DEFINE_PROP_BIT ("f-wdt" ,X86CPU , env.cpuid_ext3_features,13 , false), +DEFINE_PROP_BIT ("f-fma4" ,X86CPU , env.cpuid_ext3_features,16 , false), +DEFINE_PROP_BIT ("f-cvt16" ,X86CPU , env.cpuid_ext3_features,18 , false), +DEFINE_PROP_BIT ("f-nodeid_msr" ,X86CPU , env.cpuid_ext3_features,19 , false), +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +DEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false), +DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), +DEFINE_PROP_BIT ("f-svm_lock" ,X86CPU , env.cpuid_svm_features,2 , false), +DEFINE_PROP_BIT ("f-nrip_save" ,X86CPU , env.cpuid_svm_features,3 , false), +DEFINE_PROP_BIT ("f-tsc_scale" ,X86CPU , env.cpuid_svm_features,4 , false), +DEFINE_PROP_BIT ("f-vmcb_clean" ,X86CPU , env.cpuid_svm_features,5 , false), +DEFINE_PROP_BIT ("f-flushbyasid" ,X86CPU , env.cpuid_svm_features,6 , false), +DEFINE_PROP_BIT ("f-decodeassists" ,X86CPU , env.cpuid_svm_features,7 , false), +DEFINE_PROP_BIT ("f-pause_filter" ,X86CPU , env.cpuid_svm_features,10 , false), +DEFINE_PROP_BIT ("f-pfthreshold" ,X86CPU , env.cpuid_svm_features,12 , false), +DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false), +DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false), +DEFINE_PROP_END_OF_LIST (), + }; +/* collects per-function cpuid data */ typedef struct model_features_t {
@@ -1948,9 +2058,11 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) {X86CPUClass *xcc =X86_CPU_CLASS (oc);CPUClass *cc =CPU_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); xcc->parent_reset = cc->reset; cc->reset = x86_cpu_reset; + dc->props = cpu_x86_properties; }static const TypeInfo x86_cpu_type_info = {
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 08/37] target-i386: define static properties for cpuid features
Quoted 36 lines · Igor Mammedov
- static properties names of CPUID features are changed to have "f-" prefix, so that it would be easy to distinguish them from other properties.
- use X86CPU as a type to count of offset correctly, because env field isn't starting at CPUstate begining, but located after it.
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)target-i386/cpu.c +10
-0@@ -33,6 +33,7 @@#include "hyperv.h" #include "hw/hw.h" +#include "hw/qdev-properties.h" #if defined(CONFIG_KVM )#include <linux/kvm_para.h> #endif @@ -111,6 +112,115 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +static Property cpu_x86_properties[] = { +DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false), +DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false), +DEFINE_PROP_BIT ("f-de" ,X86CPU , env.cpuid_features,2 , false), +DEFINE_PROP_BIT ("f-pse" ,X86CPU , env.cpuid_features,3 , false), +DEFINE_PROP_BIT ("f-tsc" ,X86CPU , env.cpuid_features,4 , false), +DEFINE_PROP_BIT ("f-msr" ,X86CPU , env.cpuid_features,5 , false), +DEFINE_PROP_BIT ("f-pae" ,X86CPU , env.cpuid_features,6 , false), +DEFINE_PROP_BIT ("f-mce" ,X86CPU , env.cpuid_features,7 , false),
target-i386/cpu.c static const char *cpuid_7_0_ebx_feature_name[] = { · line 133
Quoted 10 lines
target-i386/cpu.c +10
-0+DEFINE_PROP_BIT ("f-cx8" ,X86CPU , env.cpuid_features,8 , false), +DEFINE_PROP_BIT ("f-apic" ,X86CPU , env.cpuid_features,9 , false), +DEFINE_PROP_BIT ("f-sep" ,X86CPU , env.cpuid_features,11 , false), +DEFINE_PROP_BIT ("f-mtrr" ,X86CPU , env.cpuid_features,12 , false), +DEFINE_PROP_BIT ("f-pge" ,X86CPU , env.cpuid_features,13 , false), +DEFINE_PROP_BIT ("f-mca" ,X86CPU , env.cpuid_features,14 , false), +DEFINE_PROP_BIT ("f-cmov" ,X86CPU , env.cpuid_features,15 , false), +DEFINE_PROP_BIT ("f-pat" ,X86CPU , env.cpuid_features,16 , false), +DEFINE_PROP_BIT ("f-pse36" ,X86CPU , env.cpuid_features,17 , false), + DEFINE_PROP_BIT("f-pn" /* Intel psn */, X86CPU, env.cpuid_features, 18, false),
WARNING: line over 80 characters
#51: FILE: target-i386/cpu.c:133:
+ DEFINE_PROP_BIT("f-pn" /* Intel psn */, X86CPU, env.cpuid_features, 18, false),
target-i386/cpu.c static const char *cpuid_7_0_ebx_feature_name[] = { · line 134
Quoted 1 line
target-i386/cpu.c +1
-0+ DEFINE_PROP_BIT("f-clflush" /* Intel clfsh */, X86CPU, env.cpuid_features, 19, false),
WARNING: line over 80 characters
#52: FILE: target-i386/cpu.c:134:
+ DEFINE_PROP_BIT("f-clflush" /* Intel clfsh */, X86CPU, env.cpuid_features, 19, false),
...
Quoted 94 lines
target-i386/cpu.c +89
-0+DEFINE_PROP_BIT ("f-ds" /* Intel dts */ ,X86CPU , env.cpuid_features,21 , false), +DEFINE_PROP_BIT ("f-acpi" ,X86CPU , env.cpuid_features,22 , false), +DEFINE_PROP_BIT ("f-mmx" ,X86CPU , env.cpuid_features,23 , false), +DEFINE_PROP_BIT ("f-fxsr" ,X86CPU , env.cpuid_features,24 , false), +DEFINE_PROP_BIT ("f-sse" ,X86CPU , env.cpuid_features,25 , false), +DEFINE_PROP_BIT ("f-sse2" ,X86CPU , env.cpuid_features,26 , false), +DEFINE_PROP_BIT ("f-ss" ,X86CPU , env.cpuid_features,27 , false), +DEFINE_PROP_BIT ("f-ht" /* Intel htt */ ,X86CPU , env.cpuid_features,28 , false), +DEFINE_PROP_BIT ("f-tm" ,X86CPU , env.cpuid_features,29 , false), +DEFINE_PROP_BIT ("f-ia64" ,X86CPU , env.cpuid_features,30 , false), +DEFINE_PROP_BIT ("f-pbe" ,X86CPU , env.cpuid_features,31 , false), +DEFINE_PROP_BIT ("f-pni" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-sse3" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-pclmulqdq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-pclmuldq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-dtes64" ,X86CPU , env.cpuid_ext_features,2 , false), +DEFINE_PROP_BIT ("f-monitor" ,X86CPU , env.cpuid_ext_features,3 , false), +DEFINE_PROP_BIT ("f-ds_cpl" ,X86CPU , env.cpuid_ext_features,4 , false), +DEFINE_PROP_BIT ("f-vmx" ,X86CPU , env.cpuid_ext_features,5 , false), +DEFINE_PROP_BIT ("f-smx" ,X86CPU , env.cpuid_ext_features,6 , false), +DEFINE_PROP_BIT ("f-est" ,X86CPU , env.cpuid_ext_features,7 , false), +DEFINE_PROP_BIT ("f-tm2" ,X86CPU , env.cpuid_ext_features,8 , false), +DEFINE_PROP_BIT ("f-ssse3" ,X86CPU , env.cpuid_ext_features,9 , false), +DEFINE_PROP_BIT ("f-cid" ,X86CPU , env.cpuid_ext_features,10 , false), +DEFINE_PROP_BIT ("f-fma" ,X86CPU , env.cpuid_ext_features,12 , false), +DEFINE_PROP_BIT ("f-cx16" ,X86CPU , env.cpuid_ext_features,13 , false), +DEFINE_PROP_BIT ("f-xtpr" ,X86CPU , env.cpuid_ext_features,14 , false), +DEFINE_PROP_BIT ("f-pdcm" ,X86CPU , env.cpuid_ext_features,15 , false), +DEFINE_PROP_BIT ("f-pcid" ,X86CPU , env.cpuid_ext_features,17 , false), +DEFINE_PROP_BIT ("f-dca" ,X86CPU , env.cpuid_ext_features,18 , false), +DEFINE_PROP_BIT ("f-sse4.1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4.2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-sse4_1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4_2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-x2apic" ,X86CPU , env.cpuid_ext_features,21 , false), +DEFINE_PROP_BIT ("f-movbe" ,X86CPU , env.cpuid_ext_features,22 , false), +DEFINE_PROP_BIT ("f-popcnt" ,X86CPU , env.cpuid_ext_features,23 , false), +DEFINE_PROP_BIT ("f-tsc-deadline" ,X86CPU , env.cpuid_ext_features,24 , false), +DEFINE_PROP_BIT ("f-aes" ,X86CPU , env.cpuid_ext_features,25 , false), +DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false), +DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false), +DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false), +DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-xd" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-mmxext" ,X86CPU , env.cpuid_ext2_features,22 , false), +DEFINE_PROP_BIT ("f-fxsr_opt" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-ffxsr" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-pdpe1gb" /* AMD Page1GB */ ,X86CPU , env.cpuid_ext2_features,26 , false), +DEFINE_PROP_BIT ("f-rdtscp" ,X86CPU , env.cpuid_ext2_features,27 , false), +DEFINE_PROP_BIT ("f-lahf_lm" /* AMD LahfSahf */ ,X86CPU , env.cpuid_ext3_features,0 , false), +DEFINE_PROP_BIT ("f-cmp_legacy" ,X86CPU , env.cpuid_ext3_features,1 , false), +DEFINE_PROP_BIT ("f-svm" ,X86CPU , env.cpuid_ext3_features,2 , false), +DEFINE_PROP_BIT ("f-extapic" /* AMD ExtApicSpace */ ,X86CPU , env.cpuid_ext3_features,3 , false), +DEFINE_PROP_BIT ("f-cr8legacy" /* AMD AltMovCr8 */ ,X86CPU , env.cpuid_ext3_features,4 , false), +DEFINE_PROP_BIT ("f-abm" ,X86CPU , env.cpuid_ext3_features,5 , false), +DEFINE_PROP_BIT ("f-sse4a" ,X86CPU , env.cpuid_ext3_features,6 , false), +DEFINE_PROP_BIT ("f-misalignsse" ,X86CPU , env.cpuid_ext3_features,7 , false), +DEFINE_PROP_BIT ("f-3dnowprefetch" ,X86CPU , env.cpuid_ext3_features,8 , false), +DEFINE_PROP_BIT ("f-osvw" ,X86CPU , env.cpuid_ext3_features,9 , false), +DEFINE_PROP_BIT ("f-ibs" ,X86CPU , env.cpuid_ext3_features,10 , false), +DEFINE_PROP_BIT ("f-xop" ,X86CPU , env.cpuid_ext3_features,11 , false), +DEFINE_PROP_BIT ("f-skinit" ,X86CPU , env.cpuid_ext3_features,12 , false), +DEFINE_PROP_BIT ("f-wdt" ,X86CPU , env.cpuid_ext3_features,13 , false), +DEFINE_PROP_BIT ("f-fma4" ,X86CPU , env.cpuid_ext3_features,16 , false), +DEFINE_PROP_BIT ("f-cvt16" ,X86CPU , env.cpuid_ext3_features,18 , false), +DEFINE_PROP_BIT ("f-nodeid_msr" ,X86CPU , env.cpuid_ext3_features,19 , false), +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +DEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false), +DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), +DEFINE_PROP_BIT ("f-svm_lock" ,X86CPU , env.cpuid_svm_features,2 , false), +DEFINE_PROP_BIT ("f-nrip_save" ,X86CPU , env.cpuid_svm_features,3 , false), +DEFINE_PROP_BIT ("f-tsc_scale" ,X86CPU , env.cpuid_svm_features,4 , false), +DEFINE_PROP_BIT ("f-vmcb_clean" ,X86CPU , env.cpuid_svm_features,5 , false), +DEFINE_PROP_BIT ("f-flushbyasid" ,X86CPU , env.cpuid_svm_features,6 , false), +DEFINE_PROP_BIT ("f-decodeassists" ,X86CPU , env.cpuid_svm_features,7 , false), +DEFINE_PROP_BIT ("f-pause_filter" ,X86CPU , env.cpuid_svm_features,10 , false), +DEFINE_PROP_BIT ("f-pfthreshold" ,X86CPU , env.cpuid_svm_features,12 , false), +DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false), +DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false), + DEFINE_PROP_END_OF_LIST(), + }; +/* collects per-function cpuid data */ typedef struct model_features_t {@@ -1948,9 +2058,11 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) {
target-i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 2068
Quoted 10 lines
target-i386/cpu.c +2
-0X86CPUClass *xcc =X86_CPU_CLASS (oc);CPUClass *cc =CPU_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); xcc->parent_reset = cc->reset; cc->reset = x86_cpu_reset; + dc->props = cpu_x86_properties; }static const TypeInfo x86_cpu_type_info = {
I have checked all this bits and do not find an error. The only issue is checkpatch.pl
-Don Slutz
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Qemu-devel] [PATCH 08/37] target-i386: define static properties for cpuid features
Quoted 56 lines · Igor Mammedov
Quoted 53 lines · On Mon, 22 Oct 2012 19:19:29 -0400 Don Slutz <[email protected]> wrote:
Quoted 36 lines · Igor Mammedov
- static properties names of CPUID features are changed to have "f-" prefix, so that it would be easy to distinguish them from other properties.
- use X86CPU as a type to count of offset correctly, because env field isn't starting at CPUstate begining, but located after it.
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)target-i386/cpu.c +10
-0@@ -33,6 +33,7 @@#include "hyperv.h" #include "hw/hw.h" +#include "hw/qdev-properties.h" #if defined(CONFIG_KVM )#include <linux/kvm_para.h> #endif @@ -111,6 +112,115 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +static Property cpu_x86_properties[] = { +DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false), +DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false), +DEFINE_PROP_BIT ("f-de" ,X86CPU , env.cpuid_features,2 , false), +DEFINE_PROP_BIT ("f-pse" ,X86CPU , env.cpuid_features,3 , false), +DEFINE_PROP_BIT ("f-tsc" ,X86CPU , env.cpuid_features,4 , false), +DEFINE_PROP_BIT ("f-msr" ,X86CPU , env.cpuid_features,5 , false), +DEFINE_PROP_BIT ("f-pae" ,X86CPU , env.cpuid_features,6 , false), +DEFINE_PROP_BIT ("f-mce" ,X86CPU , env.cpuid_features,7 , false),target-i386/cpu.c static const char *cpuid_7_0_ebx_feature_name[] = { · line 133
Quoted 10 lines
target-i386/cpu.c +10
-0+DEFINE_PROP_BIT ("f-cx8" ,X86CPU , env.cpuid_features,8 , false), +DEFINE_PROP_BIT ("f-apic" ,X86CPU , env.cpuid_features,9 , false), +DEFINE_PROP_BIT ("f-sep" ,X86CPU , env.cpuid_features,11 , false), +DEFINE_PROP_BIT ("f-mtrr" ,X86CPU , env.cpuid_features,12 , false), +DEFINE_PROP_BIT ("f-pge" ,X86CPU , env.cpuid_features,13 , false), +DEFINE_PROP_BIT ("f-mca" ,X86CPU , env.cpuid_features,14 , false), +DEFINE_PROP_BIT ("f-cmov" ,X86CPU , env.cpuid_features,15 , false), +DEFINE_PROP_BIT ("f-pat" ,X86CPU , env.cpuid_features,16 , false), +DEFINE_PROP_BIT ("f-pse36" ,X86CPU , env.cpuid_features,17 , false), + DEFINE_PROP_BIT("f-pn" /* Intel psn */, X86CPU, env.cpuid_features, 18, false),WARNING: line over 80 characters
#51: FILE:target-i386/cpu.c:133:
+ DEFINE_PROP_BIT("f-pn" /* Intel psn */, X86CPU, env.cpuid_features,
18, false),Quoted 1 line
target-i386/cpu.c +1
-0+ DEFINE_PROP_BIT("f-clflush" /* Intel clfsh */, X86CPU, env.cpuid_features, 19, false),
Quoted 8 lines
Quoted 4 lines
WARNING: line over 80 characters
#52: FILE:target-i386/cpu.c:134:
+ DEFINE_PROP_BIT("f-clflush" /* Intel clfsh */, X86CPU,
env.cpuid_features, 19, false),this array trigger many such warnings, but I've left them long intentionally, because otherwise pretty one feature per line array becomes rather ugly and less readable.
I'd prefer to keep it as it's now.
Since I am new to the list, I do not see that I can ok this.
You can compress the line length by added 2 new defines like:
#define F(a,b,c) DEFINE_PROP_BIT(a, X86CPU, env.cpuid##b, c, false) #define T(a,b,c) DEFINE_PROP_BIT(a, X86CPU, env.cpuid##b, c, true)
And changing lines like:
F("f-fpu", _features, 0),
F("f-vme", _features, 1),
...
F("f-pn" /* Intel psn */, _features, 18),
F("f-clflush" /* Intel clfsh */, _features, 19),
F("f-ds" /* Intel dts */, _features, 21),
...
F("f-pni" /* Intel,AMD sse3 */, _ext_features, 0),
F("f-sse3" /* Intel,AMD sse3 */, _ext_features, 0),
...
F("vendor-override", _vendor_override, 0),...
Clearly you can go even shorter like
#define F(a,b,c) DEFINE_PROP_BIT("f-" a, X86CPU,
env.cpuid##b##features, c, false)
which uses the stranger looking:
F("pn" /* Intel psn */, _, 18),
F("clflush" /* Intel clfsh */, _, 19),
F("ds" /* Intel dts */, _, 21),
...
F("extapic" /* AMD ExtApicSpace */, _ext3_, 3),
F("cr8legacy" /* AMD AltMovCr8 */, _ext3_, 4),...
-Don Slutz
Quoted 111 lines
Quoted 110 lines
...
Quoted 94 lines
target-i386/cpu.c +89
-0+DEFINE_PROP_BIT ("f-ds" /* Intel dts */ ,X86CPU , env.cpuid_features,21 , false), +DEFINE_PROP_BIT ("f-acpi" ,X86CPU , env.cpuid_features,22 , false), +DEFINE_PROP_BIT ("f-mmx" ,X86CPU , env.cpuid_features,23 , false), +DEFINE_PROP_BIT ("f-fxsr" ,X86CPU , env.cpuid_features,24 , false), +DEFINE_PROP_BIT ("f-sse" ,X86CPU , env.cpuid_features,25 , false), +DEFINE_PROP_BIT ("f-sse2" ,X86CPU , env.cpuid_features,26 , false), +DEFINE_PROP_BIT ("f-ss" ,X86CPU , env.cpuid_features,27 , false), +DEFINE_PROP_BIT ("f-ht" /* Intel htt */ ,X86CPU , env.cpuid_features,28 , false), +DEFINE_PROP_BIT ("f-tm" ,X86CPU , env.cpuid_features,29 , false), +DEFINE_PROP_BIT ("f-ia64" ,X86CPU , env.cpuid_features,30 , false), +DEFINE_PROP_BIT ("f-pbe" ,X86CPU , env.cpuid_features,31 , false), +DEFINE_PROP_BIT ("f-pni" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-sse3" /* Intel,AMD sse3 */ ,X86CPU , env.cpuid_ext_features,0 , false), +DEFINE_PROP_BIT ("f-pclmulqdq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-pclmuldq" ,X86CPU , env.cpuid_ext_features,1 , false), +DEFINE_PROP_BIT ("f-dtes64" ,X86CPU , env.cpuid_ext_features,2 , false), +DEFINE_PROP_BIT ("f-monitor" ,X86CPU , env.cpuid_ext_features,3 , false), +DEFINE_PROP_BIT ("f-ds_cpl" ,X86CPU , env.cpuid_ext_features,4 , false), +DEFINE_PROP_BIT ("f-vmx" ,X86CPU , env.cpuid_ext_features,5 , false), +DEFINE_PROP_BIT ("f-smx" ,X86CPU , env.cpuid_ext_features,6 , false), +DEFINE_PROP_BIT ("f-est" ,X86CPU , env.cpuid_ext_features,7 , false), +DEFINE_PROP_BIT ("f-tm2" ,X86CPU , env.cpuid_ext_features,8 , false), +DEFINE_PROP_BIT ("f-ssse3" ,X86CPU , env.cpuid_ext_features,9 , false), +DEFINE_PROP_BIT ("f-cid" ,X86CPU , env.cpuid_ext_features,10 , false), +DEFINE_PROP_BIT ("f-fma" ,X86CPU , env.cpuid_ext_features,12 , false), +DEFINE_PROP_BIT ("f-cx16" ,X86CPU , env.cpuid_ext_features,13 , false), +DEFINE_PROP_BIT ("f-xtpr" ,X86CPU , env.cpuid_ext_features,14 , false), +DEFINE_PROP_BIT ("f-pdcm" ,X86CPU , env.cpuid_ext_features,15 , false), +DEFINE_PROP_BIT ("f-pcid" ,X86CPU , env.cpuid_ext_features,17 , false), +DEFINE_PROP_BIT ("f-dca" ,X86CPU , env.cpuid_ext_features,18 , false), +DEFINE_PROP_BIT ("f-sse4.1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4.2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-sse4_1" ,X86CPU , env.cpuid_ext_features,19 , false), +DEFINE_PROP_BIT ("f-sse4_2" ,X86CPU , env.cpuid_ext_features,20 , false), +DEFINE_PROP_BIT ("f-x2apic" ,X86CPU , env.cpuid_ext_features,21 , false), +DEFINE_PROP_BIT ("f-movbe" ,X86CPU , env.cpuid_ext_features,22 , false), +DEFINE_PROP_BIT ("f-popcnt" ,X86CPU , env.cpuid_ext_features,23 , false), +DEFINE_PROP_BIT ("f-tsc-deadline" ,X86CPU , env.cpuid_ext_features,24 , false), +DEFINE_PROP_BIT ("f-aes" ,X86CPU , env.cpuid_ext_features,25 , false), +DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false), +DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false), +DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false), +DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-xd" ,X86CPU , env.cpuid_ext2_features,20 , false), +DEFINE_PROP_BIT ("f-mmxext" ,X86CPU , env.cpuid_ext2_features,22 , false), +DEFINE_PROP_BIT ("f-fxsr_opt" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-ffxsr" ,X86CPU , env.cpuid_ext2_features,25 , false), +DEFINE_PROP_BIT ("f-pdpe1gb" /* AMD Page1GB */ ,X86CPU , env.cpuid_ext2_features,26 , false), +DEFINE_PROP_BIT ("f-rdtscp" ,X86CPU , env.cpuid_ext2_features,27 , false), +DEFINE_PROP_BIT ("f-lahf_lm" /* AMD LahfSahf */ ,X86CPU , env.cpuid_ext3_features,0 , false), +DEFINE_PROP_BIT ("f-cmp_legacy" ,X86CPU , env.cpuid_ext3_features,1 , false), +DEFINE_PROP_BIT ("f-svm" ,X86CPU , env.cpuid_ext3_features,2 , false), +DEFINE_PROP_BIT ("f-extapic" /* AMD ExtApicSpace */ ,X86CPU , env.cpuid_ext3_features,3 , false), +DEFINE_PROP_BIT ("f-cr8legacy" /* AMD AltMovCr8 */ ,X86CPU , env.cpuid_ext3_features,4 , false), +DEFINE_PROP_BIT ("f-abm" ,X86CPU , env.cpuid_ext3_features,5 , false), +DEFINE_PROP_BIT ("f-sse4a" ,X86CPU , env.cpuid_ext3_features,6 , false), +DEFINE_PROP_BIT ("f-misalignsse" ,X86CPU , env.cpuid_ext3_features,7 , false), +DEFINE_PROP_BIT ("f-3dnowprefetch" ,X86CPU , env.cpuid_ext3_features,8 , false), +DEFINE_PROP_BIT ("f-osvw" ,X86CPU , env.cpuid_ext3_features,9 , false), +DEFINE_PROP_BIT ("f-ibs" ,X86CPU , env.cpuid_ext3_features,10 , false), +DEFINE_PROP_BIT ("f-xop" ,X86CPU , env.cpuid_ext3_features,11 , false), +DEFINE_PROP_BIT ("f-skinit" ,X86CPU , env.cpuid_ext3_features,12 , false), +DEFINE_PROP_BIT ("f-wdt" ,X86CPU , env.cpuid_ext3_features,13 , false), +DEFINE_PROP_BIT ("f-fma4" ,X86CPU , env.cpuid_ext3_features,16 , false), +DEFINE_PROP_BIT ("f-cvt16" ,X86CPU , env.cpuid_ext3_features,18 , false), +DEFINE_PROP_BIT ("f-nodeid_msr" ,X86CPU , env.cpuid_ext3_features,19 , false), +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +DEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false), +DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), +DEFINE_PROP_BIT ("f-svm_lock" ,X86CPU , env.cpuid_svm_features,2 , false), +DEFINE_PROP_BIT ("f-nrip_save" ,X86CPU , env.cpuid_svm_features,3 , false), +DEFINE_PROP_BIT ("f-tsc_scale" ,X86CPU , env.cpuid_svm_features,4 , false), +DEFINE_PROP_BIT ("f-vmcb_clean" ,X86CPU , env.cpuid_svm_features,5 , false), +DEFINE_PROP_BIT ("f-flushbyasid" ,X86CPU , env.cpuid_svm_features,6 , false), +DEFINE_PROP_BIT ("f-decodeassists" ,X86CPU , env.cpuid_svm_features,7 , false), +DEFINE_PROP_BIT ("f-pause_filter" ,X86CPU , env.cpuid_svm_features,10 , false), +DEFINE_PROP_BIT ("f-pfthreshold" ,X86CPU , env.cpuid_svm_features,12 , false), +DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false), +DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false), + DEFINE_PROP_END_OF_LIST(), + }; +/* collects per-function cpuid data */ typedef struct model_features_t {@@ -1948,9 +2058,11 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) {target-i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 2068
Quoted 10 lines
target-i386/cpu.c +2
-0X86CPUClass *xcc =X86_CPU_CLASS (oc);CPUClass *cc =CPU_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); xcc->parent_reset = cc->reset; cc->reset = x86_cpu_reset; + dc->props = cpu_x86_properties; }static const TypeInfo x86_cpu_type_info = {I have checked all this bits and do not find an error. The only issue
is checkpatch.pl
-Don Slutz
PATCH v5 9/37 qdev: export qdev_prop_find() and allow it to be used with DeviceClass instead of Object
In reply to Igor MammedovOperating on DeviceClass instead of DEVICE will allow to find static properties before DEVICE instance is created. It will be used later in compat_normalize_cpu_model() to convert legacy CPUID features into corresponding static properties.
--- hw/qdev-properties.h | 4 +++- qom/qdev-properties.c | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-)
hw/qdev-properties.h +3 -1
@@ -98,7 +98,7 @@ extern PropertyInfo qdev_prop_pci_host_devaddr; {}/* Set properties between creation and init. */ -void *qdev_get_prop_ptr (DeviceState *dev,Property *prop); +void *qdev_get_prop_ptr (DeviceState *dev,const Property *prop);int qdev_prop_parse (DeviceState *dev,const char *name,const char *value);void qdev_prop_set_bit (DeviceState *dev,const char *name,bool value);void qdev_prop_set_uint8 (DeviceState *dev,const char *name,uint8_t value);
@@ -128,4 +128,6 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,*/ void qdev_property_add_static (DeviceState *dev,Property *prop,Error **errp); +const Property *qdev_prop_find (const DeviceClass *dc,const char *name); +#endif
qom/qdev-properties.c +9 -7
@@ -6,7 +6,7 @@#include "net/hub.h" #include "qapi/qapi-visit-core.h" -void *qdev_get_prop_ptr (DeviceState *dev,Property *prop) +void *qdev_get_prop_ptr (DeviceState *dev,const Property *prop) {void *ptr = dev; ptr += prop->offset;
@@ -784,13 +784,13 @@ static Property *qdev_prop_walk(Property *props, const char *name)return NULL ; } -static Property *qdev_prop_find (DeviceState *dev,const char *name) +const Property *qdev_prop_find (const DeviceClass *dc,const char *name) {ObjectClass *class;Property *prop;/* device properties */ - class =object_get_class (OBJECT (dev)); + class =OBJECT_CLASS (dc); do { prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name); if (prop) {
@@ -907,10 +907,11 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)void qdev_prop_set_enum (DeviceState *dev,const char *name,int value) { -Property *prop; +const Property *prop;Error *errp =NULL ; +DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (dev))); - prop =qdev_prop_find (dev, name); + prop =qdev_prop_find (dc, name);object_property_set_str (OBJECT (dev), prop->info->enum_table[value], name, &errp);assert_no_error (errp);
@@ -918,10 +919,11 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)void qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value) { -Property *prop; +const Property *prop;void **ptr; +DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (dev))); - prop =qdev_prop_find (dev, name); + prop =qdev_prop_find (dc, name);assert (prop && prop->info == &qdev_prop_ptr); ptr =qdev_get_prop_ptr (dev, prop); *ptr = value;
Signature · 1 line
1.7.11.7
PATCH v5 10/37 target-i386: parse cpu_model string into set of stringified properties
In reply to Igor Mammedovcpu_model string does represent features in following format:
([+-]feat)|(feat=foo)|(feat)
which makes it impossible directly use property infrastructure to set features on CPU.
This patch introduces parser that splits CPU name from cpu_model and converts legacy features string into canonized set of strings that is compatible with property manipulation infrastructure.
- convert CPUID features "feat" to "f-feat" format used by static properties
PS:
* later it could be used as a hook to convert legacy command line features to global properties. Then marked as deprecated and removed with -cpu option in the future.
---
v2:
* compiler complains that it's unused function but I guess it is easier for review this way, for pull req I'll squash it into next patch
* fix spelling error
* initialize sptr, due to a CentOS6 compiler warning, that breaks build when -Werror is set. Suggested-by: Don Slutz
v3:
* Mingw doesn't have strtok_r(), use g_strsplit() instead of it.
Suggested-by: Blue Swirl
v4:
* convert "+/-feat" to CPUID static features format "f-feat"
* fixup xlevel in compat_normalize_cpu_model() instead of its property setter, it's needed for moving xlevel into static properties
--- target-i386/cpu.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/cpu.h | 2 ++ 2 files changed, 82 insertions(+)
target-i386/cpu.c +80 -0
@@ -1250,6 +1250,86 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp) } } +/* convert legacy cpumodel string to string cpu_name and +* a uniform set of custom features that will be applied to CPU +* using object_property_parse() +*/ +void compat_normalize_cpu_model (const char *cpu_model,char **cpu_name, +QDict **features,Error **errp) +{ +int i; +gchar **feat_array =g_strsplit (cpu_model,"," ,0 ); + *features =qdict_new (); + +g_assert (feat_array[0 ] !=NULL ); + *cpu_name =g_strdup (feat_array[0 ]); + +for (i =1 ; feat_array[i]; ++i) { +gchar *featurestr = feat_array[i]; +char *val; +if (featurestr[0 ] =='+' || featurestr[0 ] =='-' ) { +const gchar *feat = featurestr +1 ; +gchar *cpuid_fname =g_strconcat ("f-" , feat,NULL ); + +if (qdev_prop_find (DEVICE_CLASS (object_class_by_name (TYPE_X86_CPU )), + cpuid_fname)) { + feat = cpuid_fname; + } + +if (featurestr[0 ] =='+' ) { +/* +* preseve legacy behaviour, if feature was disabled once +* do not allow to enable it again +*/ +if (!qdict_haskey (*features, feat)) { +qdict_put (*features, feat,qstring_from_str ("on" )); + } + }else { +qdict_put (*features, feat,qstring_from_str ("off" )); + } + +g_free (cpuid_fname); + }else { + val =strchr (featurestr,'=' ); +if (val) { + *val =0 ; val++; +if (!strcmp (featurestr,"vendor" )) { +qdict_put (*features,"vendor-override" , +qstring_from_str ("on" )); +qdict_put (*features, featurestr,qstring_from_str (val)); + }else if (!strcmp (featurestr,"tsc_freq" )) { +qdict_put (*features,"tsc-frequency" , +qstring_from_str (val)); + }else if (!strcmp (featurestr,"xlevel" )) { +uint32_t numvalue; +char *err; + numvalue =strtoul (val, &err,0 ); +if (!*val || *err) { +error_setg (errp,"bad xlevel value %s" , val); + goto out; + } +if (numvalue <0x80000000 ) { + numvalue +=0x80000000 ; +fprintf (stderr,"warning: xlevel: %s is too small," +"correcting it to: %u\n" , val, numvalue); + } + val =g_strdup_printf ("%u" , numvalue); +qdict_put (*features, featurestr,qstring_from_str (val)); +g_free (val); + }else { +qdict_put (*features, featurestr,qstring_from_str (val)); + } + }else { +qdict_put (*features, featurestr,qstring_from_str ("on" )); + } + } + } + +out: +g_strfreev (feat_array); +return ; +} +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) {
target-i386/cpu.h +2 -0
@@ -958,6 +958,8 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model);void cpu_clear_apic_feature (CPUX86State *env);void host_cpuid (uint32_t function,uint32_t count,uint32_t *eax,uint32_t *ebx,uint32_t *ecx,uint32_t *edx); +void compat_normalize_cpu_model (const char *cpu_model,char **cpu_name, +QDict **features,Error **errp);/* helper.c */ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
Signature · 1 line
1.7.11.7
PATCH v5 11/37 target-i386: introduce vendor-override static property
In reply to Igor Mammedovcurrently 'cpuid_vendor_override' can be set only via cmd line cpu_model string. But setting it in 'vendor' property prevents using 'vendor' property on its own without setting cpuid_vendor_override.
So fix/remove enabling cpuid_vendor_override from "vendor" property setter. It's up-to cpu_model string parser to maintain legacy behavior when user overrides vendor on command line.
- cpuid_vendor_override is converted to uint32_t so it could be used with DEFINE_PROP_BIT()
--- target-i386/cpu.c | 6 ++++-- target-i386/cpu.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
target-i386/cpu.c +4 -2
@@ -218,6 +218,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-pfthreshold" ,X86CPU , env.cpuid_svm_features,12 , false),DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false),DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false), +DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false), DEFINE_PROP_END_OF_LIST(), };
@@ -1136,7 +1137,6 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, env->cpuid_vendor2 |= ((uint8_t )value[i +4 ]) << (8 * i); env->cpuid_vendor3 |= ((uint8_t )value[i +8 ]) << (8 * i); } - env->cpuid_vendor_override =1 ; }static char *x86_cpuid_get_model_id (Object *obj,Error **errp)
@@ -1220,7 +1220,9 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp) env->cpuid_vendor2 =CPUID_VENDOR_INTEL_2 ; env->cpuid_vendor3 =CPUID_VENDOR_INTEL_3 ; } - env->cpuid_vendor_override = def->vendor_override; +if (def->vendor_override) { +object_property_set_bool (OBJECT (cpu), true,"vendor-override" , errp); + }object_property_set_int (OBJECT (cpu), def->level,"level" , errp);object_property_set_int (OBJECT (cpu), def->family,"family" , errp);object_property_set_int (OBJECT (cpu), def->model,"model" , errp);
target-i386/cpu.h +1 -1
@@ -788,7 +788,7 @@ typedef struct CPUX86State {uint32_t cpuid_ext2_features;uint32_t cpuid_ext3_features;uint32_t cpuid_apic_id; -int cpuid_vendor_override; +uint32_t cpuid_vendor_override;/* Store the results of Centaur's CPUID instructions */ uint32_t cpuid_xlevel2;uint32_t cpuid_ext4_features;
Signature · 1 line
1.7.11.7
PATCH v5 12/37 target-i386: convert "xlevel" to static property
In reply to Igor Mammedov---
- convert to static property
--- target-i386/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
target-i386/cpu.c +1 -19
@@ -219,6 +219,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false),DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false),DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false), +DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ), DEFINE_PROP_END_OF_LIST(), };
@@ -1083,22 +1084,6 @@ static void x86_cpuid_set_level(Object *obj, Visitor *v, void *opaque,visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); } -static void x86_cpuid_get_xlevel (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); -} - -static void x86_cpuid_set_xlevel (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); -} -static char *x86_cpuid_get_vendor (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj);
@@ -2111,9 +2096,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"level" ,"int" , x86_cpuid_get_level, x86_cpuid_set_level,NULL ,NULL ,NULL ); -object_property_add (obj,"xlevel" ,"int" , - x86_cpuid_get_xlevel, - x86_cpuid_set_xlevel,NULL ,NULL ,NULL );object_property_add_str (obj,"vendor" , x86_cpuid_get_vendor, x86_cpuid_set_vendor,NULL );
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 12/37] target-i386: convert "xlevel" to static property
Quoted 43 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
- convert to static property--- target-i386/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)target-i386/cpu.c +1
-16@@ -219,6 +219,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-smep" ,X86CPU , env.cpuid_7_0_ebx_features,7 , false),DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false),DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false), +DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ), DEFINE_PROP_END_OF_LIST(), };@@ -1083,22 +1084,6 @@ static void x86_cpuid_set_level(Object *obj, Visitor *v, void *opaque,visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); } -static void x86_cpuid_get_xlevel (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); -} - -static void x86_cpuid_set_xlevel (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); -} -static char *x86_cpuid_get_vendor (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj);
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2101
Quoted 9 lines
target-i386/cpu.c +0
-3@@ -2111,9 +2096,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"level" ,"int" , x86_cpuid_get_level, x86_cpuid_set_level,NULL ,NULL ,NULL ); -object_property_add (obj,"xlevel" ,"int" , - x86_cpuid_get_xlevel, - x86_cpuid_set_xlevel,NULL ,NULL ,NULL );object_property_add_str (obj,"vendor" , x86_cpuid_get_vendor, x86_cpuid_set_vendor,NULL );
PATCH v5 13/37 target-i386: convert "level" to static property
In reply to Igor Mammedov--- target-i386/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
target-i386/cpu.c +1 -19
@@ -220,6 +220,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false),DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false),DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ), +DEFINE_PROP_UINT32 ("level" ,X86CPU , env.cpuid_level,0 ), DEFINE_PROP_END_OF_LIST(), };
@@ -1068,22 +1069,6 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, env->cpuid_version |= value &0xf ; } -static void x86_cpuid_get_level (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); -} - -static void x86_cpuid_set_level (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); -} -static char *x86_cpuid_get_vendor (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj);
@@ -2093,9 +2078,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"stepping" ,"int" , x86_cpuid_version_get_stepping, x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); -object_property_add (obj,"level" ,"int" , - x86_cpuid_get_level, - x86_cpuid_set_level,NULL ,NULL ,NULL );object_property_add_str (obj,"vendor" , x86_cpuid_get_vendor, x86_cpuid_set_vendor,NULL );
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 13/37] target-i386: convert "level" to static property
Quoted 41 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)target-i386/cpu.c +1
-16@@ -220,6 +220,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-smap" ,X86CPU , env.cpuid_7_0_ebx_features,20 , false),DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false),DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ), +DEFINE_PROP_UINT32 ("level" ,X86CPU , env.cpuid_level,0 ), DEFINE_PROP_END_OF_LIST(), };@@ -1068,22 +1069,6 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, env->cpuid_version |= value &0xf ; } -static void x86_cpuid_get_level (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); -} - -static void x86_cpuid_set_level (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); - -visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); -} -static char *x86_cpuid_get_vendor (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj);
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2083
Quoted 9 lines
target-i386/cpu.c +0
-3@@ -2093,9 +2078,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"stepping" ,"int" , x86_cpuid_version_get_stepping, x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); -object_property_add (obj,"level" ,"int" , - x86_cpuid_get_level, - x86_cpuid_set_level,NULL ,NULL ,NULL );object_property_add_str (obj,"vendor" , x86_cpuid_get_vendor, x86_cpuid_set_vendor,NULL );
PATCH v5 14/37 target-i386: postpone cpuid_level update to realize time
In reply to Igor Mammedovdelay capping cpuid_level to 7 to realize time so property setters for cpuid_7_0_ebx_features and "level" could be used in any order/time between x86_cpu_initfn() and x86_cpu_realize().
--- target-i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target-i386/cpu.c +4 -3
@@ -1480,9 +1480,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,if (check_features_against_host (x86_cpu_def) && enforce_cpuid) goto error; } -if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level <7 ) { - x86_cpu_def->level =7 ; - }g_free (s);return 0 ;
@@ -2040,6 +2037,10 @@ void x86_cpu_realize(Object *obj, Error **errp)X86CPU *cpu =X86_CPU (obj);CPUX86State *env = &cpu->env; +if (env->cpuid_7_0_ebx_features && env->cpuid_level <7 ) { + env->cpuid_level =7 ; + } +if (!kvm_enabled ()) { env->cpuid_features &=TCG_FEATURES ; env->cpuid_ext_features &=TCG_EXT_FEATURES ;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 14/37] target-i386: postpone cpuid_level update to realize time
Am 22.10.2012 17:03, schrieb Igor Mammedov:
Quoted 5 lines
delay capping
cpuid_levelto 7 to realize time so property setters forcpuid_7_0_ebx_featuresand "level" could be used in any order/time betweenx86_cpu_initfn()andx86_cpu_realize().Signed-off-by Igor Mammedov <[email protected]>
Thanks, rebased and applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu
Andreas
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
PATCH v5 15/37 target-i386: set default value of "hypervisor" feature using static property
In reply to Igor Mammedov--- target-i386/cpu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
target-i386/cpu.c +3 -6
@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false),DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false),DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), -DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , true),DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false),DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false),
@@ -1307,11 +1307,12 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, {unsigned int i;x86_def_t *def; +CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; +uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ;uint32_t plus_kvm_features =0 , plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;
@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif -add_flagname_to_bitmaps ("hypervisor" , &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features, &plus_7_0_ebx_features); - featurestr =strtok (NULL ,"," );while (featurestr) {
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
Quoted 33 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +3
-2@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false),DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false),DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), -DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , true),DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false),DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false),@@ -1307,11 +1307,12 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, {unsigned int i;x86_def_t *def; +CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; +uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ;uint32_t plus_kvm_features =0 , plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1351
Quoted 10 lines
target-i386/cpu.c +0
-4@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif -add_flagname_to_bitmaps ("hypervisor" , &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features, &plus_7_0_ebx_features); - featurestr =strtok (NULL ,"," );while (featurestr) {
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
In reply to Igor MammedovQuoted 19 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +1
-1@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-xsave" ,X86CPU , env.cpuid_ext_features,26 , false),DEFINE_PROP_BIT ("f-osxsave" ,X86CPU , env.cpuid_ext_features,27 , false),DEFINE_PROP_BIT ("f-avx" ,X86CPU , env.cpuid_ext_features,28 , false), -DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , true),DEFINE_PROP_BIT ("f-syscall" ,X86CPU , env.cpuid_ext2_features,11 , false),DEFINE_PROP_BIT ("f-nx" ,X86CPU , env.cpuid_ext2_features,20 , false), DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false),
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1315
Quoted 10 lines
target-i386/cpu.c +2
-1@@ -1307,11 +1307,12 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, {unsigned int i;x86_def_t *def; +CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; +uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;
Moving data back and forth between CPUX86State and x86_def_t makes the initialization ordering confusing (today data is moved from x86_def_t to X86CPU, and never the other way around).
As this code is removed in the next patches, I don't mind too much, but maybe it's simpler to implement this change only after the "use static properties for setting cpuid features" patch?
Quoted 18 lines
target-i386/cpu.c +0
-4uint32_t plus_ext2_features =0 , plus_ext3_features =0 ;uint32_t plus_kvm_features =0 , plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif -add_flagname_to_bitmaps ("hypervisor" , &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features, &plus_7_0_ebx_features); - featurestr =strtok (NULL ,"," );while (featurestr) {Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
Quoted 40 lines · On Fri, 9 Nov 2012 16:48:07 +0100 Eduardo Habkost <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +1
-1@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-xsave", X86CPU, env.cpuid_ext_features, 26, false), DEFINE_PROP_BIT("f-osxsave", X86CPU, env.cpuid_ext_features, 27, false), DEFINE_PROP_BIT("f-avx", X86CPU, env.cpuid_ext_features, 28, false), - DEFINE_PROP_BIT("f-hypervisor", X86CPU, env.cpuid_ext_features, 31, false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , true), DEFINE_PROP_BIT("f-syscall", X86CPU, env.cpuid_ext2_features, 11,false),
DEFINE_PROP_BIT("f-nx", X86CPU, env.cpuid_ext2_features, 20, false),DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false), @@ -1307,11 +1307,12 @@ static int cpu_x86_find_by_name(X86CPU*cpu, x86_def_t *x86_cpu_def, { unsigned int i; x86_def_t *def;target-i386/cpu.c +2
-1+CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; + uint32_t plus_features = 0, plus_ext_features =Quoted 1 line
env->cpuid_ext_features;Moving data back and forth between CPUX86State and
x86_def_tmakes the initialization ordering confusing (today data is moved fromx86_def_tto X86CPU, and never the other way around).
Quoted 3 lines
As this code is removed in the next patches, I don't mind too much, but maybe it's simpler to implement this change only after the "use static properties for setting cpuid features" patch?
It won't eliminate moving data back and forth between CPUX86State and x86_def_t until CPU sub-classes (i.e. when x86_def_t isn't used anymore), if defaults from static properties are used.
But I've rewritten patches in a way to make this easier to review and less confusing.
Quoted 20 lines
Quoted 19 lines
uint32_t plus_ext2_features = 0, plus_ext3_features = 0; uint32_t plus_kvm_features = 0, plus_svm_features = 0; uint32_t plus_7_0_ebx_features = 0;target-i386/cpu.c +0
-3@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu,x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif - add_flagname_to_bitmaps("hypervisor", &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features,
&plus_7_0_ebx_features); -featurestr = strtok(NULL, ","); while (featurestr) {Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
Quoted 43 lines · Igor Mammedov
Quoted 40 lines · On Fri, 9 Nov 2012 16:48:07 +0100 Eduardo Habkost <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +1
-1@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-xsave", X86CPU, env.cpuid_ext_features, 26, false), DEFINE_PROP_BIT("f-osxsave", X86CPU, env.cpuid_ext_features, 27, false), DEFINE_PROP_BIT("f-avx", X86CPU, env.cpuid_ext_features, 28, false), - DEFINE_PROP_BIT("f-hypervisor", X86CPU, env.cpuid_ext_features, 31, false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features,31 , true), DEFINE_PROP_BIT("f-syscall", X86CPU, env.cpuid_ext2_features, 11,false),
DEFINE_PROP_BIT("f-nx", X86CPU, env.cpuid_ext2_features, 20, false),DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false), @@ -1307,11 +1307,12 @@ static int cpu_x86_find_by_name(X86CPU*cpu, x86_def_t *x86_cpu_def, { unsigned int i; x86_def_t *def;target-i386/cpu.c +2
-1+CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; + uint32_t plus_features = 0, plus_ext_features =Quoted 1 line
env->cpuid_ext_features;Moving data back and forth between CPUX86State and
x86_def_tmakes the initialization ordering confusing (today data is moved fromx86_def_tto X86CPU, and never the other way around).
Quoted 6 lines
Quoted 3 lines
As this code is removed in the next patches, I don't mind too much, but maybe it's simpler to implement this change only after the "use static properties for setting cpuid features" patch?
It won't eliminate moving data back and forth between CPUX86State and
x86_def_tuntil CPU sub-classes (i.e. whenx86_def_tisn't used anymore), if defaults from static properties are used.
You don't need CPU subclasses to reduce back-and-forth data movement. We can just reorder code to look like:
split_cpu_model_string(cpu_model, &model, &features); fill_cpudef_for_model_somehow(model, &cpudef); cpudef_2_x86_cpu(cpu, &cpudef); cpu_parse_feature_string(cpu, features);
Instead of what we have today, that is:
split_cpu_model_string(cpu_model, &model, &features); fill_cpudef_for_model_somehow(model, &cpudef); cpu_parse_feature_string(cpu, features);
/* (the 3 steps above are all done inside cpu_x86_find_by_name()) */ cpudef_2_x86_cpu(cpu, &cpudef);
You did that on patch 32/37, but I would be interesting to do that _before_ introducing the whole new CPU properties code, to make review easier.
Reordering the steps to make the code less confusing before introducing the CPU properties makes the code easier to review, that's why I sent the CPU init cleanup series. And it makes us one step closer to completely eliminate the X86CPUDefinition struct in the future.
I actually made the reordering change above using the CPU init series as base, and it was very easy to do, after the CPU init was cleaned up. You can see the result at:
https://github.com/ehabkost/qemu-hacks/commit/5256503135e787cb3550092c24dbeb3c5fc5a747
(it's completely untested. The rest of the changes are on the work/cpu-model-classes branch)
Quoted 3 lines
But I've rewritten patches in a way to make this easier to review and less confusing.
I'm curious to see the result. Right now I am using the CPU init cleanup series as base for my CPU subclass experiments.
Quoted 22 lines
Quoted 21 lines
Quoted 20 lines
uint32_t plus_ext2_features = 0, plus_ext3_features = 0; uint32_t plus_kvm_features = 0, plus_svm_features = 0; uint32_t plus_7_0_ebx_features = 0;target-i386/cpu.c +0
-3@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu,x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif - add_flagname_to_bitmaps("hypervisor", &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features,
&plus_7_0_ebx_features); -featurestr = strtok(NULL, ","); while (featurestr) {Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
Quoted 51 lines · On Thu, 29 Nov 2012 13:47:37 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 43 lines · Igor Mammedov
Quoted 40 lines · On Fri, 9 Nov 2012 16:48:07 +0100 Eduardo Habkost <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +1
-1@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-xsave", X86CPU, env.cpuid_ext_features, 26, false), DEFINE_PROP_BIT("f-osxsave", X86CPU, env.cpuid_ext_features, 27, false), DEFINE_PROP_BIT("f-avx", X86CPU, env.cpuid_ext_features, 28, false), - DEFINE_PROP_BIT("f-hypervisor", X86CPU, env.cpuid_ext_features, 31, false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features, 31, true), DEFINE_PROP_BIT("f-syscall", X86CPU,env.cpuid_ext2_features, 11, false),
DEFINE_PROP_BIT("f-nx", X86CPU, env.cpuid_ext2_features, 20, false),DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false), @@ -1307,11 +1307,12 @@ staticint cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, { unsigned int i; x86_def_t *def;target-i386/cpu.c +2
-1+CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; + uint32_t plus_features = 0, plus_ext_features =Quoted 1 line
env->cpuid_ext_features;Moving data back and forth between CPUX86State and
x86_def_tmakes the initialization ordering confusing (today data is moved fromx86_def_tto X86CPU, and never the other way around).Quoted 6 lines
Quoted 3 lines
As this code is removed in the next patches, I don't mind too much, but maybe it's simpler to implement this change only after the "use static properties for setting cpuid features" patch?
It won't eliminate moving data back and forth between CPUX86State and
x86_def_tuntil CPU sub-classes (i.e. whenx86_def_tisn't used anymore), if defaults from static properties are used.
Quoted 5 lines
You don't need CPU subclasses to reduce back-and-forth data movement. We can just reorder code to look like:
split_cpu_model_string(cpu_model, &model, &features);fill_cpudef_for_model_somehow(model, &cpudef);
somewhere between here and [2], One still needs to enable "hypervisor" feature, and set kvm_features defaults. I guess "hypervisor" could be pushed out into x86_def_t for each model and kvm_cpu_fill_host(). But it would be hard to do so for KVM features (see how pv_eoi is set).
see 8d239fbb9b, ded9f32153, a7bb291e5b, 2623e2f876, bd539e14ef in
https://github.com/imammedo/qemu/commits/x86-cpu-properties.WIP
Quoted 1 line
cpudef_2_x86_cpu(cpu, &cpudef);
As alternative it's possible to merge (OR) ext_features and kvm_features from cpudef into env inside of cpudef_2_x86_cpu() to keep defaults SET by static properties when cpu obj was created.
[2]
This merge won't disappear completely until cpudefs are converted into classes and X_class_init() will set all defaults for a given cpu model.
and common defaults could/should be set by parent X86CPU class_init(), and ideally rewrite should end up in a inheritance tree of subclasses, each adding new features relative to previous model.
Quoted 19 lines
cpu_parse_feature_string(cpu, features);Instead of what we have today, that is:
split_cpu_model_string(cpu_model, &model, &features);fill_cpudef_for_model_somehow(model, &cpudef);cpu_parse_feature_string(cpu, features);
/* (the 3 steps above are all done insidecpu_x86_find_by_name()) */cpudef_2_x86_cpu(cpu, &cpudef);You did that on patch 32/37, but I would be interesting to do that _before_ introducing the whole new CPU properties code, to make review easier.
Reordering the steps to make the code less confusing before introducing the CPU properties makes the code easier to review, that's why I sent the CPU init cleanup series. And it makes us one step closer to completely eliminate the X86CPUDefinition struct in the future.
Quoted 4 lines
I actually made the reordering change above using the CPU init series as base, and it was very easy to do, after the CPU init was cleaned up. You can see the result at:
https://github.com/ehabkost/qemu-hacks/commit/5256503135e787cb3550092c24dbeb3c5fc5a747
After some playing, I've abandoned approach to change cpu_x86_find_by_name() and opted in favor of not touching it and feature string parsing much, except of doing almost the same split as you. As additional thing, I've moved setting defaults out of it as well.
Quoted 2 lines
(it's completely untested. The rest of the changes are on the work/cpu-model-classes branch)
Some reordering has been done to series to make it clearer and easier to review. Pls, checkout it out on my x86-cpu-properties.WIP
Quoted 33 lines
Quoted 4 lines
But I've rewritten patches in a way to make this easier to review and less confusing.
I'm curious to see the result. Right now I am using the CPU init cleanup series as base for my CPU subclass experiments.
Quoted 23 lines
Quoted 22 lines
Quoted 21 lines
uint32_t plus_ext2_features = 0, plus_ext3_features = 0; uint32_t plus_kvm_features = 0, plus_svm_features = 0; uint32_t plus_7_0_ebx_features = 0;target-i386/cpu.c +0
-3@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu,x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif - add_flagname_to_bitmaps("hypervisor", &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features,
&plus_7_0_ebx_features); -featurestr = strtok(NULL, ","); while (featurestr) {Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property
Quoted 57 lines · Igor Mammedov
Quoted 54 lines · On Thu, 29 Nov 2012 13:47:37 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 43 lines · Igor Mammedov
Quoted 40 lines · On Fri, 9 Nov 2012 16:48:07 +0100 Eduardo Habkost <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)target-i386/cpu.c +1
-1@@ -174,7 +174,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-xsave", X86CPU, env.cpuid_ext_features, 26, false), DEFINE_PROP_BIT("f-osxsave", X86CPU, env.cpuid_ext_features, 27, false), DEFINE_PROP_BIT("f-avx", X86CPU, env.cpuid_ext_features, 28, false), - DEFINE_PROP_BIT("f-hypervisor", X86CPU, env.cpuid_ext_features, 31, false), +DEFINE_PROP_BIT ("f-hypervisor" ,X86CPU , env.cpuid_ext_features, 31, true), DEFINE_PROP_BIT("f-syscall", X86CPU,env.cpuid_ext2_features, 11, false),
DEFINE_PROP_BIT("f-nx", X86CPU, env.cpuid_ext2_features, 20, false),DEFINE_PROP_BIT("f-xd", X86CPU, env.cpuid_ext2_features, 20, false), @@ -1307,11 +1307,12 @@ staticint cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, { unsigned int i; x86_def_t *def;target-i386/cpu.c +2
-1+CPUX86State *env = &cpu->env;char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features =0 ; + uint32_t plus_features = 0, plus_ext_features =Quoted 1 line
env->cpuid_ext_features;Moving data back and forth between CPUX86State and
x86_def_tmakes the initialization ordering confusing (today data is moved fromx86_def_tto X86CPU, and never the other way around).Quoted 6 lines
Quoted 3 lines
As this code is removed in the next patches, I don't mind too much, but maybe it's simpler to implement this change only after the "use static properties for setting cpuid features" patch?
It won't eliminate moving data back and forth between CPUX86State and
x86_def_tuntil CPU sub-classes (i.e. whenx86_def_tisn't used anymore), if defaults from static properties are used.You don't need CPU subclasses to reduce back-and-forth data movement. We can just reorder code to look like:
Quoted 6 lines
Quoted 2 lines
split_cpu_model_string(cpu_model, &model, &features);fill_cpudef_for_model_somehow(model, &cpudef);somewhere between here and [2], One still needs to enable "hypervisor" feature, and set
kvm_featuresdefaults. I guess "hypervisor" could be pushed out intox86_def_tfor each model andkvm_cpu_fill_host(). But it would be hard to do so for KVM features (see howpv_eoiis set).
If the features are set by default on all models, we can hardcode or set them by default either in the fill_cpudef_for_model_somehow() step (meaning that the models have it implicitly set), or inside cpudef_2_x86_cpu() (meaning that the feature can't be controlled by the CPU feature string in any way).
In think both the KVM defaults and the hypervisor flag fit the former case (because the defaults can be changed by the feature string later). In other words: even if the feature is not mentioned in builtin_x86_defs, it can be simply be considered part of the defaults for all CPU models.
Currently the defaults are set inside the feature string parsing code (in the pseudo-code I wrote, that means setting them by default on cpu_parse_feature_string()). That works, too, but it's confusing IMO.
One thing I forgot to mention about the example code, is that eventually the two steps:
fill_cpudef_for_model_somehow(model, &cpudef); cpudef_2_x86_cpu(cpu, &cpudef);
will become just a single step:
initialize_default_flags_for_model(cpu, model);
or, even better, it will become:
cpu = create_cpu_object_with_default_flags_already_set(model);
When we change the code to do that, we will be able to easily introduce the subclasses, and to easily eliminate the X86CPUDefinnition struct (aka x86_def_t).
Quoted 8 lines
see
8d239fbb9b,ded9f32153,a7bb291e5b,2623e2f876,bd539e14efin
https://github.com/imammedo/qemu/commits/x86-cpu-properties.WIPQuoted 1 line
cpudef_2_x86_cpu(cpu, &cpudef);As alternative it's possible to merge (OR)
ext_featuresandkvm_featuresfrom cpudef into env inside ofcpudef_2_x86_cpu()to keep defaults SET by static properties when cpu obj was created.
The feature string can be used to disable features too, not just to enable them, so we can't just merge two bitmaps later.
Quoted 10 lines
[2]
This merge won't disappear completely until cpudefs are converted into classes and
X_class_init()will set all defaults for a given cpu model.and common defaults could/should be set by parent X86CPU
class_init(), and ideally rewrite should end up in a inheritance tree of subclasses, each adding new features relative to previous model.
We don't need subclasses and class_init() to do that, we just need the code to do that to run at the right point in cpu_x86_init(). And then that code can be easily converted to subclasses.
I mean: the initialization will be done by class_init when we implement subclasses, of course, but we don't need (and I don't want to) reorder the initialization _and_ add the subclasses all in one big patch.
Quoted 19 lines
Quoted 19 lines
cpu_parse_feature_string(cpu, features);Instead of what we have today, that is:
split_cpu_model_string(cpu_model, &model, &features);fill_cpudef_for_model_somehow(model, &cpudef);cpu_parse_feature_string(cpu, features);
/* (the 3 steps above are all done insidecpu_x86_find_by_name()) */cpudef_2_x86_cpu(cpu, &cpudef);You did that on patch 32/37, but I would be interesting to do that _before_ introducing the whole new CPU properties code, to make review easier.
Reordering the steps to make the code less confusing before introducing the CPU properties makes the code easier to review, that's why I sent the CPU init cleanup series. And it makes us one step closer to completely eliminate the X86CPUDefinition struct in the future.
Quoted 8 lines
Quoted 4 lines
I actually made the reordering change above using the CPU init series as base, and it was very easy to do, after the CPU init was cleaned up. You can see the result at:
https://github.com/ehabkost/qemu-hacks/commit/5256503135e787cb3550092c24dbeb3c5fc5a747After some playing, I've abandoned approach to change
cpu_x86_find_by_name()and opted in favor of not touching it and feature string parsing much, except of doing almost the same split as you. As additional thing, I've moved setting defaults out of it as well.
I really prefer the approach of cleaning up (or just isolating) the code first, and then simply replace the isolated code with the new CPU properties code. I think it makes it easier to review the code and make sure that we are not introducing subtle unexpected behavior changes. That's why I sent the CPU initialization refactor series.
Even if the CPU init cleanup series is not included, I think I will rebase your series on top of the CPU init refactor locally, as part of the review process--this way I can compare cpu_x86_parse_featurestr() with the new CPU property setting code, and make sure nothing was left out.
But if Andreas think the CPU properties series is reasonable as-is, without applying the CPU init cleanup first, I won't mind redoing (parts of) the CPU init changes later.
Quoted 6 lines
Quoted 3 lines
(it's completely untested. The rest of the changes are on the work/cpu-model-classes branch)
Some reordering has been done to series to make it clearer and easier to review. Pls, checkout it out on my x86-cpu-properties.WIP
I will take a look, thanks.
Quoted 35 lines
Quoted 34 lines
Quoted 5 lines
But I've rewritten patches in a way to make this easier to review and less confusing.
I'm curious to see the result. Right now I am using the CPU init cleanup series as base for my CPU subclass experiments.
Quoted 23 lines
Quoted 22 lines
Quoted 21 lines
uint32_t plus_ext2_features = 0, plus_ext3_features = 0; uint32_t plus_kvm_features = 0, plus_svm_features = 0; uint32_t plus_7_0_ebx_features = 0;target-i386/cpu.c +0
-3@@ -1345,10 +1346,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu,x86_def_t *x86_cpu_def, plus_kvm_features =0 ;#endif - add_flagname_to_bitmaps("hypervisor", &plus_features, - &plus_ext_features, &plus_ext2_features, &plus_ext3_features, - &plus_kvm_features, &plus_svm_features,
&plus_7_0_ebx_features); -featurestr = strtok(NULL, ","); while (featurestr) {Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
PATCH v5 16/37 target-i386: set kvm CPUID default feature values using static properties
In reply to Igor MammedovReplace setting default supported kvm features in cpu_x86_find_by_name() by default values in corresponding static properties.
- Compile in kvm CPUID features only if CONFIG_KVM is defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.
--- target-i386/cpu.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
target-i386/cpu.c +11 -19
@@ -200,12 +200,16 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-fma4", X86CPU, env.cpuid_ext3_features, 16, false), DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false), -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), -DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), -DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), -DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), -DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), -DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +#if defined(CONFIG_KVM ) +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , true), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , true), +DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true), +DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +#endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false),DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), DEFINE_PROP_BIT("f-svm_lock", X86CPU, env.cpuid_svm_features, 2, false),
@@ -1314,7 +1318,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,/* Features to be added*/ uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features =0 , plus_svm_features =0 ; +uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;/* Features to be removed */ uint32_t minus_features =0 , minus_ext_features =0 ;
@@ -1334,18 +1338,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } -#if defined(CONFIG_KVM ) - plus_kvm_features = (1 <<KVM_FEATURE_CLOCKSOURCE ) | - (1 <<KVM_FEATURE_NOP_IO_DELAY ) | - (1 <<KVM_FEATURE_MMU_OP ) | - (1 <<KVM_FEATURE_CLOCKSOURCE2 ) | - (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_STEAL_TIME ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); -#else - plus_kvm_features =0 ; -#endif - featurestr =strtok (NULL ,"," );while (featurestr) {
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties
Quoted 5 lines · Igor Mammedov
Replace setting default supported kvm features in
cpu_x86_find_by_name()by default values in corresponding static properties.- Compile in kvm CPUID features only if
CONFIG_KVMis defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.
Not sure that KVM_FEATURE_STEAL_TIME should translate to kvm_steal_tm. I think that I have seen that new names should use "-". So I would think the new name should be "f-kvm-steal-time". And KVM_FEATURE_CLOCKSOURCE_STABLE_BIT should be "f-kvm-clock-stable".
Quoted 51 lines
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)target-i386/cpu.c +11
-12@@ -200,12 +200,16 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-fma4", X86CPU, env.cpuid_ext3_features, 16, false), DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false), -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), -DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), -DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), -DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), -DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), -DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +#if defined(CONFIG_KVM ) +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , true), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , true), +DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true), +DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +#endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false),DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), DEFINE_PROP_BIT("f-svm_lock", X86CPU, env.cpuid_svm_features, 2, false),@@ -1314,7 +1318,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,/* Features to be added*/ uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features =0 , plus_svm_features =0 ; +uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;/* Features to be removed */ uint32_t minus_features =0 , minus_ext_features =0 ;@@ -1334,18 +1338,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } -#if defined(CONFIG_KVM ) - plus_kvm_features = (1 <<KVM_FEATURE_CLOCKSOURCE ) | - (1 <<KVM_FEATURE_NOP_IO_DELAY ) | - (1 <<KVM_FEATURE_MMU_OP ) | - (1 << KVM_FEATURE_CLOCKSOURCE2) |
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1343
Quoted 10 lines
target-i386/cpu.c +0
-7- (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_STEAL_TIME ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); -#else - plus_kvm_features =0 ; -#endif - featurestr =strtok (NULL ,"," );while (featurestr) {
-Don Slutz
Re: [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties
Quoted 10 lines · On Mon, 22 Oct 2012 19:20:10 -0400 Don Slutz <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
Replace setting default supported kvm features in
cpu_x86_find_by_name()by default values in corresponding static properties.- Compile in kvm CPUID features only if
CONFIG_KVMis defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.Not sure that
KVM_FEATURE_STEAL_TIMEshould translate tokvm_steal_tm. I think that I have seen that new names should use "-". So I would think the new name should be "f-kvm-steal-time". AndKVM_FEATURE_CLOCKSOURCE_STABLE_BITshould be "f-kvm-clock-stable".
That would be inconsistent with current naming scheme, I may be it should be f-kvm_steal_time and f-kvm_clock_stable for this series and than later all the features converted in a single batch, its a bit out of scope of this patch. Alternatively a separate patch could be send to convert current feature name arrays to '-' scheme. I'll happily rebase series on top of it.
Quoted 63 lines
Quoted 51 lines
Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)target-i386/cpu.c +11
-12@@ -200,12 +200,16 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-fma4", X86CPU, env.cpuid_ext3_features, 16, false), DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false), -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), -DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), -DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), -DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), -DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), -DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +#if defined(CONFIG_KVM ) +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , true), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , true), +DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true), +DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +#endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false),DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), DEFINE_PROP_BIT("f-svm_lock", X86CPU, env.cpuid_svm_features, 2, false),@@ -1314,7 +1318,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,/* Features to be added*/ uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features =0 , plus_svm_features =0 ; +uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ;uint32_t plus_7_0_ebx_features =0 ;/* Features to be removed */ uint32_t minus_features =0 , minus_ext_features =0 ;@@ -1334,18 +1338,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } -#if defined(CONFIG_KVM ) - plus_kvm_features = (1 <<KVM_FEATURE_CLOCKSOURCE ) | - (1 <<KVM_FEATURE_NOP_IO_DELAY ) | - (1 <<KVM_FEATURE_MMU_OP ) | - (1 << KVM_FEATURE_CLOCKSOURCE2) |target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1343
Quoted 10 lines
target-i386/cpu.c +0
-7- (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_STEAL_TIME ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); -#else - plus_kvm_features =0 ; -#endif - featurestr =strtok (NULL ,"," );while (featurestr) {-Don Slutz
Signature · 2 lines
Regards, Igor
Re: [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties
Am 23.10.2012 12:40, schrieb Igor Mammedov:
Quoted 13 lines
Quoted 10 lines · On Mon, 22 Oct 2012 19:20:10 -0400 Don Slutz <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
Replace setting default supported kvm features in
cpu_x86_find_by_name()by default values in corresponding static properties.- Compile in kvm CPUID features only if
CONFIG_KVMis defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.Not sure that
KVM_FEATURE_STEAL_TIMEshould translate tokvm_steal_tm. I think that I have seen that new names should use "-". So I would think the new name should be "f-kvm-steal-time". AndKVM_FEATURE_CLOCKSOURCE_STABLE_BITshould be "f-kvm-clock-stable".
Quoted 5 lines
That would be inconsistent with current naming scheme, I may be it should be f-kvm_steal_time and f-kvm_clock_stable for this series and than later all the features converted in a single batch, its a bit out of scope of this patch. Alternatively a separate patch could be send to convert current feature name arrays to '-' scheme. I'll happily rebase series on top of it.
I am pretty sure that someone (not me) proposed to have all new properties with dash and to translate the command line options from _ to -.
Andreas
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
Re: [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties
Quoted 14 lines · On Tue, 23 Oct 2012 12:55:00 +0200 Andreas Färber <[email protected]> wrote:
Am 23.10.2012 12:40, schrieb Igor Mammedov:
Quoted 13 lines
Quoted 10 lines · On Mon, 22 Oct 2012 19:20:10 -0400 Don Slutz <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
Replace setting default supported kvm features in
cpu_x86_find_by_name()by default values in corresponding static properties.- Compile in kvm CPUID features only if
CONFIG_KVMis defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.Not sure that
KVM_FEATURE_STEAL_TIMEshould translate tokvm_steal_tm. I think that I have seen that new names should use "-". So I would think the new name should be "f-kvm-steal-time". AndKVM_FEATURE_CLOCKSOURCE_STABLE_BITshould be "f-kvm-clock-stable".
Quoted 8 lines
Quoted 5 lines
That would be inconsistent with current naming scheme, I may be it should be f-kvm_steal_time and f-kvm_clock_stable for this series and than later all the features converted in a single batch, its a bit out of scope of this patch. Alternatively a separate patch could be send to convert current feature name arrays to '-' scheme. I'll happily rebase series on top of it.
I am pretty sure that someone (not me) proposed to have all new properties with dash and to translate the command line options from _ to -.
I remember it too except of how it ended. Any way since these are new features, I do not have any preference. Naming suggested by Don are now in WIP queue:
https://github.com/imammedo/qemu/commit/fd4fc7b5abb37373d02e3f1861856846ce231316
Thanks,
Igor
Quoted 7 lines
Andreas
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
Re: [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties
In reply to Igor MammedovQuoted 39 lines · Igor Mammedov
Replace setting default supported kvm features in
cpu_x86_find_by_name()by default values in corresponding static properties.- Compile in kvm CPUID features only if
CONFIG_KVMis defined.
- Make "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID features visible as properties.Signed-off-by Igor Mammedov <[email protected]>---
target-i386/cpu.c| 30 +++++++++++-------------------1 file changed, 11 insertions(+), 19 deletions(-)target-i386/cpu.c +10
-6@@ -200,12 +200,16 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-fma4", X86CPU, env.cpuid_ext3_features, 16, false), DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false), -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , false), -DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , false), -DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , false), -DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , false), -DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , false), -DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , false), +#if defined(CONFIG_KVM ) +DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true), +DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), +DEFINE_PROP_BIT ("f-kvmclock2" ,X86CPU , env.cpuid_kvm_features,3 , true), +DEFINE_PROP_BIT ("f-kvm_asyncpf" ,X86CPU , env.cpuid_kvm_features,4 , true), +DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true), +DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true), +DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +#endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false),DEFINE_PROP_BIT ("f-lbrv" ,X86CPU , env.cpuid_svm_features,1 , false), DEFINE_PROP_BIT("f-svm_lock", X86CPU, env.cpuid_svm_features, 2, false),
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1321
Quoted 5 lines
target-i386/cpu.c +1
-1@@ -1314,7 +1318,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,/* Features to be added*/ uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features;uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features =0 , plus_svm_features =0 ; +uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ;
This is where things gets interesting: now the PV EOI feature is enabled by default, but only on the pc-1.3 machine-type.
Maybe at this point in the series we are already able to use global properties for compatibility, so we can make the changes above, add "f-kvm_pv_eoi=false" to pc-1.2, and kill kvm_default_features and enable_kvm_pv_eoi(), all in the same patch?
Quoted 26 lines
target-i386/cpu.c +0
-12uint32_t plus_7_0_ebx_features =0 ;/* Features to be removed */ uint32_t minus_features =0 , minus_ext_features =0 ;@@ -1334,18 +1338,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } -#if defined(CONFIG_KVM ) - plus_kvm_features = (1 <<KVM_FEATURE_CLOCKSOURCE ) | - (1 <<KVM_FEATURE_NOP_IO_DELAY ) | - (1 <<KVM_FEATURE_MMU_OP ) | - (1 <<KVM_FEATURE_CLOCKSOURCE2 ) | - (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_STEAL_TIME ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); -#else - plus_kvm_features =0 ; -#endif - featurestr =strtok (NULL ,"," );while (featurestr) {Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
PATCH v5 17/37 target-i386: make 'f-kvmclock' compatible with legacy behaviour
In reply to Igor MammedovIt'll keep legacy behavior of kvmclock CPUID feature, which is toggles on KVM_FEATURE_CLOCKSOURCE and KVM_FEATURE_CLOCKSOURCE2 CPUID feature bits.
Rename feature corresponding to KVM_FEATURE_CLOCKSOURCE to f-kvmclock1 to free f-kvmclock for use of legacy feature.
--- target-i386/cpu.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
target-i386/cpu.c +38 -1
@@ -112,6 +112,42 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +#if defined(CONFIG_KVM ) +static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +bool value = cpu->env.cpuid_kvm_features; + value = (value &KVM_FEATURE_CLOCKSOURCE ) && + (value &KVM_FEATURE_CLOCKSOURCE2 ); +visit_type_bool (v, &value, name, errp); +} + +static void x86_cpu_set_kvmclock (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +bool value; +visit_type_bool (v, &value, name, errp); +if (value == true) { + cpu->env.cpuid_kvm_features |=KVM_FEATURE_CLOCKSOURCE | +KVM_FEATURE_CLOCKSOURCE2 ; + }else { + cpu->env.cpuid_kvm_features &= ~(KVM_FEATURE_CLOCKSOURCE | +KVM_FEATURE_CLOCKSOURCE2 ); + } +} + +PropertyInfo qdev_prop_kvmclock = { + .name ="boolean" , + .get = x86_cpu_get_kvmclock, + .set = x86_cpu_set_kvmclock, +}; +#define DEFINE_PROP_KVMCLOCK (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_kvmclock, uint32_t) + +#endif +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -201,7 +237,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false),#if defined(CONFIG_KVM ) -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvmclock1" ,X86CPU , env.cpuid_kvm_features,0 , true),DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true),DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), DEFINE_PROP_BIT("f-kvmclock2", X86CPU, env.cpuid_kvm_features, 3, true),
@@ -209,6 +245,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true),DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true),DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +DEFINE_PROP_KVMCLOCK ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features), #endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false), DEFINE_PROP_BIT("f-lbrv", X86CPU, env.cpuid_svm_features, 1, false),
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 17/37] target-i386: make 'f-kvmclock' compatible with legacy behaviour
Quoted 69 lines · Igor Mammedov
It'll keep legacy behavior of kvmclock CPUID feature, which is toggles on
KVM_FEATURE_CLOCKSOURCEandKVM_FEATURE_CLOCKSOURCE2CPUID feature bits.Rename feature corresponding to
KVM_FEATURE_CLOCKSOURCEto f-kvmclock1 to free f-kvmclock for use of legacy feature.Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)target-i386/cpu.c +37
-1@@ -112,6 +112,42 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +#if defined(CONFIG_KVM ) +static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +bool value = cpu->env.cpuid_kvm_features; + value = (value &KVM_FEATURE_CLOCKSOURCE ) && + (value &KVM_FEATURE_CLOCKSOURCE2 ); +visit_type_bool (v, &value, name, errp); +} + +static void x86_cpu_set_kvmclock (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +bool value; +visit_type_bool (v, &value, name, errp); +if (value == true) { + cpu->env.cpuid_kvm_features |=KVM_FEATURE_CLOCKSOURCE | +KVM_FEATURE_CLOCKSOURCE2 ; + }else { + cpu->env.cpuid_kvm_features &= ~(KVM_FEATURE_CLOCKSOURCE | +KVM_FEATURE_CLOCKSOURCE2 ); + } +} + +PropertyInfo qdev_prop_kvmclock = { + .name ="boolean" , + .get = x86_cpu_get_kvmclock, + .set = x86_cpu_set_kvmclock, +}; +#define DEFINE_PROP_KVMCLOCK (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_kvmclock, uint32_t) + +#endif +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),@@ -201,7 +237,7 @@ static Property cpu_x86_properties[] = { DEFINE_PROP_BIT("f-cvt16", X86CPU, env.cpuid_ext3_features, 18, false), DEFINE_PROP_BIT("f-nodeid_msr", X86CPU, env.cpuid_ext3_features, 19, false),#if defined(CONFIG_KVM ) -DEFINE_PROP_BIT ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features,0 , true), +DEFINE_PROP_BIT ("f-kvmclock1" ,X86CPU , env.cpuid_kvm_features,0 , true),DEFINE_PROP_BIT ("f-kvm_nopiodelay" ,X86CPU , env.cpuid_kvm_features,1 , true),DEFINE_PROP_BIT ("f-kvm_mmu" ,X86CPU , env.cpuid_kvm_features,2 , true), DEFINE_PROP_BIT("f-kvmclock2", X86CPU, env.cpuid_kvm_features, 3, true),
target-i386/cpu.c static Property cpu_x86_properties[] = { · line 251
Quoted 7 lines
target-i386/cpu.c +1
-0@@ -209,6 +245,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-kvm_steal_tm" ,X86CPU , env.cpuid_kvm_features,5 , true),DEFINE_PROP_BIT ("f-kvm_pv_eoi" ,X86CPU , env.cpuid_kvm_features,6 , true),DEFINE_PROP_BIT ("f-kvmclock_stable" ,X86CPU , env.cpuid_kvm_features,24 , true), +DEFINE_PROP_KVMCLOCK ("f-kvmclock" ,X86CPU , env.cpuid_kvm_features), #endifDEFINE_PROP_BIT ("f-npt" ,X86CPU , env.cpuid_svm_features,0 , false), DEFINE_PROP_BIT("f-lbrv", X86CPU, env.cpuid_svm_features, 1, false),
PATCH v5 18/37 target-i386: add stubs for hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
In reply to Igor MammedovIt's needed for converting hv_* features into properties and to avoid build breakage when qemu is built with --disable-kvm option.
--- target-i386/hyperv.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target-i386/hyperv.h +6 -3
@@ -30,16 +30,19 @@void hyperv_enable_vapic_recommended (bool val);void hyperv_enable_relaxed_timing (bool val);void hyperv_set_spinlock_retries (int val); +bool hyperv_vapic_recommended (void ); +bool hyperv_relaxed_timing_enabled (void ); +int hyperv_get_spinlock_retries (void );#else static inline void hyperv_enable_vapic_recommended (bool val) { }static inline void hyperv_enable_relaxed_timing (bool val) { }static inline void hyperv_set_spinlock_retries (int val) { } +static inline bool hyperv_vapic_recommended (void ) {return false; } +static inline bool hyperv_relaxed_timing_enabled (void ) {return false; } +static inline int hyperv_get_spinlock_retries (void ) {return 0 ; }#endif bool hyperv_enabled (void );bool hyperv_hypercall_available (void ); -bool hyperv_vapic_recommended (void ); -bool hyperv_relaxed_timing_enabled (void ); -int hyperv_get_spinlock_retries (void );#endif /* QEMU_HW_HYPERV_H */
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 18/37] target-i386: add stubs for hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
Quoted 26 lines · Igor Mammedov
It's needed for converting hv_* features into properties and to avoid build breakage when qemu is built with --disable-kvm option.
Signed-off-by Igor Mammedov <[email protected]>Reported-by Eduardo Habkost <[email protected]>--- target-i386/hyperv.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)target-i386/hyperv.h +5
-0@@ -30,16 +30,19 @@void hyperv_enable_vapic_recommended (bool val);void hyperv_enable_relaxed_timing (bool val);void hyperv_set_spinlock_retries (int val); +bool hyperv_vapic_recommended (void ); +bool hyperv_relaxed_timing_enabled (void ); +int hyperv_get_spinlock_retries (void );#else static inline void hyperv_enable_vapic_recommended (bool val) { }static inline void hyperv_enable_relaxed_timing (bool val) { }static inline void hyperv_set_spinlock_retries (int val) { } +static inline bool hyperv_vapic_recommended (void ) {return false; } +static inline bool hyperv_relaxed_timing_enabled (void ) {return false; }
target-i386/hyperv.h line 48
Quoted 10 lines
target-i386/hyperv.h +1
-3+static inline int hyperv_get_spinlock_retries (void ) {return 0 ; }#endif bool hyperv_enabled (void );bool hyperv_hypercall_available (void ); -bool hyperv_vapic_recommended (void ); -bool hyperv_relaxed_timing_enabled (void ); -int hyperv_get_spinlock_retries (void );#endif /* QEMU_HW_HYPERV_H */
PATCH v5 19/37 qdev: add DEFINE_ABSTRACT_PROP() helper
In reply to Igor MammedovIt will be used for declaring a static property with a custom setter/getter.
--- hw/qdev-properties.h | 5 +++++ 1 file changed, 5 insertions(+)
hw/qdev-properties.h +5 -0
@@ -27,6 +27,11 @@ extern PropertyInfo qdev_prop_pci_devfn;extern PropertyInfo qdev_prop_blocksize;extern PropertyInfo qdev_prop_pci_host_devaddr; +#define DEFINE_ABSTRACT_PROP (_name, _prop) { \ + .name = (_name), \ + .info = &(_prop), \ + } +#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \ .info = &(_prop), \
Signature · 1 line
1.7.11.7
PATCH v5 20/37 target-i386: convert 'hv_spinlocks' to static property
In reply to Igor Mammedov---
* in addition use error_setg() instead of error_set()
--- target-i386/cpu.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
target-i386/cpu.c +34 -0
@@ -148,6 +148,39 @@ PropertyInfo qdev_prop_kvmclock = {#endif +static void x86_get_hv_spinlocks (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +int64_t value =hyperv_get_spinlock_retries (); + +visit_type_int (v, &value, name, errp); +} + +static void x86_set_hv_spinlocks (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (!value) { +error_setg (errp,"Property '%s.%s' doesn't take value '%s'" , +object_get_typename (obj), name,"0" ); +return ; + } +hyperv_set_spinlock_retries (value); +} + +PropertyInfo qdev_prop_spinlocks = { + .name ="int" , + .get = x86_get_hv_spinlocks, + .set = x86_set_hv_spinlocks, +}; +#define DEFINE_PROP_HV_SPINLOCKS (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_spinlocks) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -262,6 +295,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("vendor-override" ,X86CPU , env.cpuid_vendor_override,0 , false),DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ),DEFINE_PROP_UINT32 ("level" ,X86CPU , env.cpuid_level,0 ), +DEFINE_PROP_HV_SPINLOCKS ("hv_spinlocks" ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.7.11.7
PATCH v5 21/37 target-i386: convert 'hv_relaxed' to static property
In reply to Igor Mammedov--- target-i386/cpu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
target-i386/cpu.c +29 -0
@@ -181,6 +181,34 @@ PropertyInfo qdev_prop_spinlocks = {#define DEFINE_PROP_HV_SPINLOCKS (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_spinlocks) +static void x86_get_hv_relaxed (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value =hyperv_relaxed_timing_enabled (); + +visit_type_bool (v, &value, name, errp); +} + +static void x86_set_hv_relaxed (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value; + +visit_type_bool (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +hyperv_enable_relaxed_timing (value); +} + +PropertyInfo qdev_prop_hv_relaxed = { + .name ="boolean" , + .get = x86_get_hv_relaxed, + .set = x86_set_hv_relaxed, +}; +#define DEFINE_PROP_HV_RELAXED (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_hv_relaxed) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -296,6 +324,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_UINT32 ("xlevel" ,X86CPU , env.cpuid_xlevel,0 ),DEFINE_PROP_UINT32 ("level" ,X86CPU , env.cpuid_level,0 ),DEFINE_PROP_HV_SPINLOCKS ("hv_spinlocks" ), +DEFINE_PROP_HV_RELAXED ("hv_relaxed" ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.7.11.7
PATCH v5 22/37 target-i386: convert 'hv_vapic' to static property
In reply to Igor Mammedov--- target-i386/cpu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
target-i386/cpu.c +29 -0
@@ -209,6 +209,34 @@ PropertyInfo qdev_prop_hv_relaxed = {#define DEFINE_PROP_HV_RELAXED (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_hv_relaxed) +static void x86_get_hv_vapic (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value =hyperv_vapic_recommended (); + +visit_type_bool (v, &value, name, errp); +} + +static void x86_set_hv_vapic (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value; + +visit_type_bool (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +hyperv_enable_vapic_recommended (value); +} + +PropertyInfo qdev_prop_hv_vapic = { + .name ="boolean" , + .get = x86_get_hv_vapic, + .set = x86_set_hv_vapic, +}; +#define DEFINE_PROP_HV_VAPIC (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_hv_vapic) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -325,6 +353,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_UINT32 ("level" ,X86CPU , env.cpuid_level,0 ),DEFINE_PROP_HV_SPINLOCKS ("hv_spinlocks" ),DEFINE_PROP_HV_RELAXED ("hv_relaxed" ), +DEFINE_PROP_HV_VAPIC ("hv_vapic" ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.7.11.7
PATCH v5 23/37 target-i386: convert 'check' and 'enforce' to static properties
In reply to Igor Mammedov---
v2:
* restore original behavior, check features against host before they might be filtered out by TCG masks. spotted-by: Eduardo Habkost
v3:
* use static properties instead of feature name arrays
* since "check" is becoming regular boolean property it would be possible to turn it off while "enforce=on", set check_cpuid=true if "enforce=on" after all properties set at realize time.
--- target-i386/cpu.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 12 deletions(-)
target-i386/cpu.c +73 -12
@@ -237,6 +237,62 @@ PropertyInfo qdev_prop_hv_vapic = {#define DEFINE_PROP_HV_VAPIC (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_hv_vapic) +static bool check_cpuid; + +static void x86_cpuid_get_check (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +visit_type_bool (v, &check_cpuid, name, errp); +} + +static void x86_cpuid_set_check (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value; + +visit_type_bool (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } + check_cpuid = value; +} + +PropertyInfo qdev_prop_check = { + .name ="bool" , + .get = x86_cpuid_get_check, + .set = x86_cpuid_set_check, +}; +#define DEFINE_PROP_CHECK (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_check) + +static bool enforce_cpuid; + +static void x86_cpuid_get_enforce (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +visit_type_bool (v, &enforce_cpuid, name, errp); +} + +static void x86_cpuid_set_enforce (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +bool value; + +visit_type_bool (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } + enforce_cpuid = value; +} + +PropertyInfo qdev_prop_enforce = { + .name ="boolean" , + .get = x86_cpuid_get_enforce, + .set = x86_cpuid_set_enforce, +}; +#define DEFINE_PROP_ENFORCE (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_enforce) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -354,6 +410,8 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_HV_SPINLOCKS ("hv_spinlocks" ),DEFINE_PROP_HV_RELAXED ("hv_relaxed" ),DEFINE_PROP_HV_VAPIC ("hv_vapic" ), +DEFINE_PROP_CHECK ("check" ), +DEFINE_PROP_ENFORCE ("enforce" ), DEFINE_PROP_END_OF_LIST(), };
@@ -367,9 +425,6 @@ typedef struct model_features_t {uint32_t cpuid; } model_features_t; -int check_cpuid =0 ; -int enforce_cpuid =0 ; -void host_cpuid (uint32_t function,uint32_t count,uint32_t *eax,uint32_t *ebx,uint32_t *ecx,uint32_t *edx) {
@@ -1064,19 +1119,20 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)* their way to the guest. Note: ft[].check_feat ideally should be * specified via a guest_def field to suppress report of extraneous flags. */ -static int check_features_against_host (x86_def_t *guest_def) +static int check_features_against_host (X86CPU *cpu) { +CPUX86State *env = &cpu->env;x86_def_t host_def;uint32_t mask;int rv, i;struct model_features_t ft[] = { - {&guest_def->features, &host_def.features, + {&env->cpuid_features, &host_def.features, ~0 , feature_name,0x00000000 }, - {&guest_def->ext_features, &host_def.ext_features, + {&env->cpuid_ext_features, &host_def.ext_features, ~CPUID_EXT_HYPERVISOR , ext_feature_name,0x00000001 }, - {&guest_def->ext2_features, &host_def.ext2_features, + {&env->cpuid_ext2_features, &host_def.ext2_features, ~PPRO_FEATURES , ext2_feature_name,0x80000000 }, - {&guest_def->ext3_features, &host_def.ext3_features, + {&env->cpuid_ext3_features, &host_def.ext3_features, ~CPUID_EXT3_SVM , ext3_feature_name,0x80000001 }};cpu_x86_fill_host (&host_def);
@@ -1594,10 +1650,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, x86_cpu_def->kvm_features &= ~minus_kvm_features; x86_cpu_def->svm_features &= ~minus_svm_features; x86_cpu_def->cpuid_7_0_ebx_features &= ~minus_7_0_ebx_features; -if (check_cpuid) { -if (check_features_against_host (x86_cpu_def) && enforce_cpuid) - goto error; - }g_free (s);return 0 ;
@@ -2159,6 +2211,15 @@ void x86_cpu_realize(Object *obj, Error **errp) env->cpuid_level =7 ; } +if (enforce_cpuid) { + check_cpuid = true; + } +if (check_cpuid &&check_features_against_host (cpu) + && enforce_cpuid) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } +if (!kvm_enabled ()) { env->cpuid_features &=TCG_FEATURES ; env->cpuid_ext_features &=TCG_EXT_FEATURES ;
Signature · 1 line
1.7.11.7
PATCH v5 24/37 target-i386: use define for cpuid vendor string size
In reply to Igor Mammedov--- target-i386/cpu.c | 6 +++--- target-i386/cpu.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
target-i386/cpu.c +3 -3
@@ -1265,13 +1265,13 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp)char *value;int i; - value = (char *)g_malloc (12 +1 ); + value = (char *)g_malloc (CPUID_VENDOR_SZ +1 );for (i =0 ; i <4 ; i++) { value[i ] = env->cpuid_vendor1 >> (8 * i); value[i +4 ] = env->cpuid_vendor2 >> (8 * i); value[i +8 ] = env->cpuid_vendor3 >> (8 * i); } - value[12 ] ='\0' ; + value[CPUID_VENDOR_SZ ] ='\0' ;return value; }
@@ -1282,7 +1282,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,CPUX86State *env = &cpu->env;int i; -if (strlen (value) !=12 ) { +if (strlen (value) !=CPUID_VENDOR_SZ ) {error_set (errp,QERR_PROPERTY_VALUE_BAD ,"" ,"vendor" , value);return ;
target-i386/cpu.h +2 -0
@@ -488,6 +488,8 @@#define CPUID_7_0_EBX_SMEP (1 << 7)#define CPUID_7_0_EBX_SMAP (1 << 20) +#define CPUID_VENDOR_SZ 12 +#define CPUID_VENDOR_INTEL_1 0x756e6547/* "Genu" */ #define CPUID_VENDOR_INTEL_2 0x49656e69/* "ineI" */ #define CPUID_VENDOR_INTEL_3 0x6c65746e/* "ntel" */
Signature · 1 line
1.7.11.7
Andreas Färber
AppliedRe: [Qemu-devel] [PATCH 24/37] target-i386: use define for cpuid vendor string size
Am 22.10.2012 17:03, schrieb Igor Mammedov:
Quoted 1 line
Signed-off-by Igor Mammedov <[email protected]>
Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu
Andreas
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
PATCH v5 25/37 target-i386: replace uint32_t vendor fields by vendor string in x86_def_t
In reply to Igor MammedovVendor property setter takes string as vendor value but cpudefs use uint32_t vendor[123] fields to define vendor value. It makes it difficult to unify and use property setter for values from cpudefs.
Simplify code by using vendor property setter, vendor[123] fields are converted into vendor[13] array to keep its value. And vendor property setter is used to access/set value on CPU.
---
[ehabkost: rebase on top of my unduplicate-features branch] [ehabkost: fix the new CPU models to use the string .vendor field, too,
on the CPU model array]
[ehabkost: keep CPUID_VENDOR_AMD_[123] #defines, as they are used
in the AMD CPU feature alias handling]
--- target-i386/cpu.c | 92 +++++++++++++++---------------------------------------- target-i386/cpu.h | 6 ++-- 2 files changed, 27 insertions(+), 71 deletions(-)
target-i386/cpu.c +24 -68
@@ -545,7 +545,7 @@ typedef struct x86_def_t {struct x86_def_t *next;const char *name;uint32_t level; -uint32_t vendor1, vendor2, vendor3; +char vendor[CPUID_VENDOR_SZ +1 ];int family;int model;int stepping;
@@ -610,9 +610,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "qemu64", .level = 4, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 6, .model = 2, .stepping = 3,
@@ -629,9 +627,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "phenom", .level = 5, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 16, .model = 2, .stepping = 3,
@@ -675,9 +671,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "kvm64", .level = 5, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 15, .model = 6, .stepping = 1,
@@ -776,9 +770,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "athlon", .level = 2, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 6, .model = 2, .stepping = 3,
@@ -810,9 +802,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Conroe", .level = 2, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 2, .stepping = 3,
@@ -830,9 +820,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Penryn", .level = 2, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 2, .stepping = 3,
@@ -851,9 +839,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Nehalem", .level = 2, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 2, .stepping = 3,
@@ -872,9 +858,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Westmere", .level = 11, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 44, .stepping = 1,
@@ -894,9 +878,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "SandyBridge", .level = 0xd, - .vendor1 = CPUID_VENDOR_INTEL_1, - .vendor2 = CPUID_VENDOR_INTEL_2, - .vendor3 = CPUID_VENDOR_INTEL_3, + .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 42, .stepping = 1,
@@ -919,9 +901,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Opteron_G1", .level = 5, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 15, .model = 6, .stepping = 1,
@@ -943,9 +923,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Opteron_G2", .level = 5, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 15, .model = 6, .stepping = 1,
@@ -969,9 +947,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Opteron_G3", .level = 5, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 15, .model = 6, .stepping = 1,
@@ -997,9 +973,7 @@ static x86_def_t builtin_x86_defs[] = { { .name = "Opteron_G4", .level = 0xd, - .vendor1 = CPUID_VENDOR_AMD_1, - .vendor2 = CPUID_VENDOR_AMD_2, - .vendor3 = CPUID_VENDOR_AMD_3, + .vendor = CPUID_VENDOR_AMD, .family = 21, .model = 1, .stepping = 2,
@@ -1046,13 +1020,16 @@ static int cpu_x86_fill_model_id(char *str)static int cpu_x86_fill_host (x86_def_t *x86_cpu_def) {uint32_t eax =0 , ebx =0 , ecx =0 , edx =0 ; +int i; x86_cpu_def->name ="host" ;host_cpuid (0x0 ,0 , &eax, &ebx, &ecx, &edx); x86_cpu_def->level = eax; - x86_cpu_def->vendor1 = ebx; - x86_cpu_def->vendor2 = edx; - x86_cpu_def->vendor3 = ecx; +for (i =0 ; i <4 ; i++) { + x86_cpu_def->vendor[i] = ebx >> (8 * i); + x86_cpu_def->vendor[i +4 ] = edx >> (8 * i); + x86_cpu_def->vendor[i +8 ] = ecx >> (8 * i); + }host_cpuid (0x1 ,0 , &eax, &ebx, &ecx, &edx); x86_cpu_def->family = ((eax >>8 ) &0x0F ) + ((eax >>20 ) &0xFF );
@@ -1077,9 +1054,7 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def) x86_cpu_def->vendor_override =0 ;/* Call Centaur's CPUID instruction. */ -if (x86_cpu_def->vendor1 ==CPUID_VENDOR_VIA_1 && - x86_cpu_def->vendor2 ==CPUID_VENDOR_VIA_2 && - x86_cpu_def->vendor3 ==CPUID_VENDOR_VIA_3 ) { +if (!strcmp (x86_cpu_def->vendor,CPUID_VENDOR_VIA )) {host_cpuid (0xC0000000 ,0 , &eax, &ebx, &ecx, &edx);if (eax >=0xC0000001 ) {/* Support VIA max extended level */
@@ -1370,15 +1345,8 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp) {CPUX86State *env = &cpu->env; -if (def->vendor1) { - env->cpuid_vendor1 = def->vendor1; - env->cpuid_vendor2 = def->vendor2; - env->cpuid_vendor3 = def->vendor3; - }else { - env->cpuid_vendor1 =CPUID_VENDOR_INTEL_1 ; - env->cpuid_vendor2 =CPUID_VENDOR_INTEL_2 ; - env->cpuid_vendor3 =CPUID_VENDOR_INTEL_3 ; - } +object_property_set_str (OBJECT (cpu), def->vendor[0 ] ? + def->vendor :CPUID_VENDOR_INTEL ,"vendor" , errp);if (def->vendor_override) {object_property_set_bool (OBJECT (cpu), true,"vendor-override" , errp); }
@@ -1494,7 +1462,6 @@ out:static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) { -unsigned int i;x86_def_t *def;CPUX86State *env = &cpu->env;
@@ -1583,18 +1550,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, } x86_cpu_def->xlevel = numvalue; }else if (!strcmp (featurestr,"vendor" )) { -if (strlen (val) !=12 ) { -fprintf (stderr,"vendor string must be 12 chars long\n" ); - goto error; - } - x86_cpu_def->vendor1 =0 ; - x86_cpu_def->vendor2 =0 ; - x86_cpu_def->vendor3 =0 ; -for (i =0 ; i <4 ; i++) { - x86_cpu_def->vendor1 |= ((uint8_t )val[i ]) << (8 * i); - x86_cpu_def->vendor2 |= ((uint8_t )val[i +4 ]) << (8 * i); - x86_cpu_def->vendor3 |= ((uint8_t )val[i +8 ]) << (8 * i); - } +pstrcpy (x86_cpu_def->vendor,sizeof (x86_cpu_def->vendor), val); x86_cpu_def->vendor_override =1 ; }else if (!strcmp (featurestr,"model_id" )) { pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),
target-i386/cpu.h +3 -3
@@ -493,14 +493,14 @@#define CPUID_VENDOR_INTEL_1 0x756e6547/* "Genu" */ #define CPUID_VENDOR_INTEL_2 0x49656e69/* "ineI" */ #define CPUID_VENDOR_INTEL_3 0x6c65746e/* "ntel" */ +#define CPUID_VENDOR_INTEL "GenuineIntel"#define CPUID_VENDOR_AMD_1 0x68747541/* "Auth" */ #define CPUID_VENDOR_AMD_2 0x69746e65/* "enti" */ #define CPUID_VENDOR_AMD_3 0x444d4163/* "cAMD" */ +#define CPUID_VENDOR_AMD "AuthenticAMD" -#define CPUID_VENDOR_VIA_1 0x746e6543/* "Cent" */ -#define CPUID_VENDOR_VIA_2 0x48727561/* "aurH" */ -#define CPUID_VENDOR_VIA_3 0x736c7561/* "auls" */ +#define CPUID_VENDOR_VIA "CentaurHauls"#define CPUID_MWAIT_IBE (1 << 1)/* Interrupts can exit capability */ #define CPUID_MWAIT_EMX (1 << 0)/* enumeration supported */
Signature · 1 line
1.7.11.7
PATCH v5 26/37 target-i386: convert "vendor" property to static property
In reply to Igor Mammedov---
* use error_setg() instead of error_set()
* checkpatch doesn't like 'foo[i ]' used in original setter/getter, make it happy.
--- target-i386/cpu.c | 102 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 43 deletions(-)
target-i386/cpu.c +59 -43
@@ -293,6 +293,64 @@ PropertyInfo qdev_prop_enforce = {#define DEFINE_PROP_ENFORCE (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_enforce) +static void x86_cpuid_get_vendor (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +char *value; +int i; + + value = (char *)g_malloc (CPUID_VENDOR_SZ +1 ); +for (i =0 ; i <4 ; i++) { + value[i] = env->cpuid_vendor1 >> (8 * i); + value[i +4 ] = env->cpuid_vendor2 >> (8 * i); + value[i +8 ] = env->cpuid_vendor3 >> (8 * i); + } + value[CPUID_VENDOR_SZ ] ='\0' ; +visit_type_str (v, &value, name, errp); +g_free (value); +} + +static void x86_cpuid_set_vendor (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +char *value; +int i; + +visit_type_str (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } + +if (strlen (value) !=CPUID_VENDOR_SZ ) { +error_setg (errp,"Property '%s.%s' doesn't take value '%s'" , +object_get_typename (obj), name, value); +g_free (value); +return ; + } + + env->cpuid_vendor1 =0 ; + env->cpuid_vendor2 =0 ; + env->cpuid_vendor3 =0 ; +for (i =0 ; i <4 ; i++) { + env->cpuid_vendor1 |= ((uint8_t )value[i]) << (8 * i); + env->cpuid_vendor2 |= ((uint8_t )value[i +4 ]) << (8 * i); + env->cpuid_vendor3 |= ((uint8_t )value[i +8 ]) << (8 * i); + } +g_free (value); +} + +PropertyInfo qdev_prop_vendor = { + .name ="string" , + .get = x86_cpuid_get_vendor, + .set = x86_cpuid_set_vendor, +}; +#define DEFINE_PROP_VENDOR (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_vendor, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -412,6 +470,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_HV_VAPIC ("hv_vapic" ),DEFINE_PROP_CHECK ("check" ),DEFINE_PROP_ENFORCE ("enforce" ), +DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1), DEFINE_PROP_END_OF_LIST(), };
@@ -1233,46 +1292,6 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, env->cpuid_version |= value &0xf ; } -static char *x86_cpuid_get_vendor (Object *obj,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -char *value; -int i; - - value = (char *)g_malloc (CPUID_VENDOR_SZ +1 ); -for (i =0 ; i <4 ; i++) { - value[i ] = env->cpuid_vendor1 >> (8 * i); - value[i +4 ] = env->cpuid_vendor2 >> (8 * i); - value[i +8 ] = env->cpuid_vendor3 >> (8 * i); - } - value[CPUID_VENDOR_SZ ] ='\0' ; -return value; -} - -static void x86_cpuid_set_vendor (Object *obj,const char *value, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int i; - -if (strlen (value) !=CPUID_VENDOR_SZ ) { -error_set (errp,QERR_PROPERTY_VALUE_BAD ,"" , -"vendor" , value); -return ; - } - - env->cpuid_vendor1 =0 ; - env->cpuid_vendor2 =0 ; - env->cpuid_vendor3 =0 ; -for (i =0 ; i <4 ; i++) { - env->cpuid_vendor1 |= ((uint8_t )value[i ]) << (8 * i); - env->cpuid_vendor2 |= ((uint8_t )value[i +4 ]) << (8 * i); - env->cpuid_vendor3 |= ((uint8_t )value[i +8 ]) << (8 * i); - } -} -static char *x86_cpuid_get_model_id (Object *obj,Error **errp) {X86CPU *cpu =X86_CPU (obj);
@@ -2214,9 +2233,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"stepping" ,"int" , x86_cpuid_version_get_stepping, x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); -object_property_add_str (obj,"vendor" , - x86_cpuid_get_vendor, - x86_cpuid_set_vendor,NULL );object_property_add_str (obj,"model-id" , x86_cpuid_get_model_id, x86_cpuid_set_model_id,NULL );
Signature · 1 line
1.7.11.7
PATCH v5 27/37 target-i386: convert "tsc-frequency" to static property
In reply to Igor Mammedov---
* in addition use error_setg() instead of error_set()
--- target-i386/cpu.c | 75 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 34 deletions(-)
target-i386/cpu.c +41 -34
@@ -351,6 +351,46 @@ PropertyInfo qdev_prop_vendor = {#define DEFINE_PROP_VENDOR (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_vendor, uint32_t) +static void x86_cpuid_get_tsc_freq (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +int64_t value; + + value = cpu->env.tsc_khz *1000 ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_set_tsc_freq (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +const int64_t min =0 ; +const int64_t max =INT64_MAX ; +int64_t value; + +visit_type_freq (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + cpu->env.tsc_khz = value /1000 ; +} + +PropertyInfo qdev_prop_tsc_freq = { + .name ="int32" , + .get = x86_cpuid_get_tsc_freq, + .set = x86_cpuid_set_tsc_freq, +}; +#define DEFINE_PROP_TSC_FREQ (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_tsc_freq, int32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -471,6 +511,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_CHECK ("check" ),DEFINE_PROP_ENFORCE ("enforce" ),DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1), +DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz), DEFINE_PROP_END_OF_LIST(), };
@@ -1329,37 +1370,6 @@ static void x86_cpuid_set_model_id(Object *obj, const char *model_id, } } -static void x86_cpuid_get_tsc_freq (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -int64_t value; - - value = cpu->env.tsc_khz *1000 ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_set_tsc_freq (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -const int64_t min =0 ; -const int64_t max =INT64_MAX ; -int64_t value; - -visit_type_freq (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - cpu->env.tsc_khz = value /1000 ; -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
@@ -2236,9 +2246,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add_str (obj,"model-id" , x86_cpuid_get_model_id, x86_cpuid_set_model_id,NULL ); -object_property_add (obj,"tsc-frequency" ,"int" , - x86_cpuid_get_tsc_freq, - x86_cpuid_set_tsc_freq,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 27/37] target-i386: convert "tsc-frequency" to static property
Quoted 39 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
* in addition useerror_setg()instead oferror_set()--- target-i386/cpu.c | 75 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 34 deletions(-)target-i386/cpu.c +24
-0@@ -351,6 +351,46 @@ PropertyInfo qdev_prop_vendor = {#define DEFINE_PROP_VENDOR (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_vendor, uint32_t) +static void x86_cpuid_get_tsc_freq (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +int64_t value; + + value = cpu->env.tsc_khz *1000 ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_set_tsc_freq (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +const int64_t min =0 ; +const int64_t max =INT64_MAX ; +int64_t value; + +visit_type_freq (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { + error_setg(errp, "Property %s.%s doesn't take value %" PRId64 " (min"
target-i386/cpu.c PropertyInfo qdev_prop_vendor = { · line 387
Quoted 10 lines
target-i386/cpu.c +10
-0+"imum: %" PRId64", maximum: %" PRId64, + object_get_typename(obj), name, value, min, max); +return ; + } + + cpu->env.tsc_khz = value /1000 ; +} + +PropertyInfo qdev_prop_tsc_freq = { + .name ="int32" ,
This should be at least int64. Better is 'frequency', since strtosz_suffix_unit() is used. I.E. 2.4G is valid for this.
Quoted 56 lines
target-i386/cpu.c +7
-31+ .get = x86_cpuid_get_tsc_freq, + .set = x86_cpuid_set_tsc_freq, +}; +#define DEFINE_PROP_TSC_FREQ (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_tsc_freq, int32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),@@ -471,6 +511,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_CHECK ("check" ),DEFINE_PROP_ENFORCE ("enforce" ),DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1), +DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz), DEFINE_PROP_END_OF_LIST(), };@@ -1329,37 +1370,6 @@ static void x86_cpuid_set_model_id(Object *obj, const char *model_id, } } -static void x86_cpuid_get_tsc_freq (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -int64_t value; - - value = cpu->env.tsc_khz *1000 ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_set_tsc_freq (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -const int64_t min =0 ; -const int64_t max =INT64_MAX ; -int64_t value; - -visit_type_freq (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - cpu->env.tsc_khz = value /1000 ; -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2251
Quoted 9 lines
target-i386/cpu.c +0
-3@@ -2236,9 +2246,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add_str (obj,"model-id" , x86_cpuid_get_model_id, x86_cpuid_set_model_id,NULL ); -object_property_add (obj,"tsc-frequency" ,"int" , - x86_cpuid_get_tsc_freq, - x86_cpuid_set_tsc_freq,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
The rest looks correct.
-Don Slutz
PATCH v5 28/37 target-i386: convert "model-id" to static property
In reply to Igor Mammedovcheck "if (model_id == NULL)" looks to unnecessary now, since all builtin model-ids are not NULL and user shouldn't be able to set it NULL (cpumodel string parsing code takes care of it, if feature is specified as "model-id=" on command line, its parsing will result in an empty string as value).
- use g_malloc0() instead of g_malloc() in x86_cpuid_get_model_id()
--- target-i386/cpu.c | 91 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 40 deletions(-)
target-i386/cpu.c +51 -40
@@ -391,6 +391,56 @@ PropertyInfo qdev_prop_tsc_freq = {#define DEFINE_PROP_TSC_FREQ (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_tsc_freq, int32_t) +static void x86_cpuid_get_model_id (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +char *value; +int i; + + value =g_malloc0 (48 +1 ); +for (i =0 ; i <48 ; i++) { + value[i] = env->cpuid_model[i >>2 ] >> (8 * (i &3 )); + } +visit_type_str (v, &value, name, errp); +g_free (value); +} + +static void x86_cpuid_set_model_id (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int c, len, i; +char *value; + +visit_type_str (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } + + len =strlen (value); +memset (env->cpuid_model,0 ,48 ); +for (i =0 ; i <48 ; i++) { +if (i >= len) { + c ='\0' ; + }else { + c = (uint8_t )value[i]; + } + env->cpuid_model[i >>2 ] |= c << (8 * (i &3 )); + } +g_free (value); +} + +PropertyInfo qdev_prop_model_id = { + .name ="string" , + .get = x86_cpuid_get_model_id, + .set = x86_cpuid_set_model_id, +}; +#define DEFINE_PROP_MODEL_ID (_n) \ + DEFINE_ABSTRACT_PROP(_n, qdev_prop_model_id) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -512,6 +562,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_ENFORCE ("enforce" ),DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1),DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz), +DEFINE_PROP_MODEL_ID ("model-id" ), DEFINE_PROP_END_OF_LIST(), };
@@ -1333,43 +1384,6 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, env->cpuid_version |= value &0xf ; } -static char *x86_cpuid_get_model_id (Object *obj,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -char *value; -int i; - - value =g_malloc (48 +1 ); -for (i =0 ; i <48 ; i++) { - value[i] = env->cpuid_model[i >>2 ] >> (8 * (i &3 )); - } - value[48 ] ='\0' ; -return value; -} - -static void x86_cpuid_set_model_id (Object *obj,const char *model_id, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int c, len, i; - -if (model_id ==NULL ) { - model_id ="" ; - } - len =strlen (model_id); -memset (env->cpuid_model,0 ,48 ); -for (i =0 ; i <48 ; i++) { -if (i >= len) { - c ='\0' ; - }else { - c = (uint8_t )model_id[i]; - } - env->cpuid_model[i >>2 ] |= c << (8 * (i &3 )); - } -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
@@ -2243,9 +2257,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"stepping" ,"int" , x86_cpuid_version_get_stepping, x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); -object_property_add_str (obj,"model-id" , - x86_cpuid_get_model_id, - x86_cpuid_set_model_id,NULL ); env->cpuid_apic_id = env->cpu_index;
Signature · 1 line
1.7.11.7
PATCH v5 29/37 target-i386: convert "stepping" to static property
In reply to Igor Mammedov---
- in addition use error_setg() instead of error_set()
--- target-i386/cpu.c | 85 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 39 deletions(-)
target-i386/cpu.c +46 -39
@@ -441,6 +441,51 @@ PropertyInfo qdev_prop_model_id = {#define DEFINE_PROP_MODEL_ID (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_model_id) +static void x86_cpuid_version_get_stepping (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = env->cpuid_version &0xf ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_stepping (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xf ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xf ; + env->cpuid_version |= value &0xf ; +} + +PropertyInfo qdev_prop_stepping = { + .name ="uint32" , + .get = x86_cpuid_version_get_stepping, + .set = x86_cpuid_version_set_stepping, +}; +#define DEFINE_PROP_STEPPING (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_stepping, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -563,6 +608,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1),DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz),DEFINE_PROP_MODEL_ID ("model-id" ), +DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };
@@ -1348,42 +1394,6 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); } -static void x86_cpuid_version_get_stepping (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = env->cpuid_version &0xf ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_stepping (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xf ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xf ; - env->cpuid_version |= value &0xf ; -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
@@ -2254,9 +2264,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"model" ,"int" , x86_cpuid_version_get_model, x86_cpuid_version_set_model,NULL ,NULL ,NULL ); -object_property_add (obj,"stepping" ,"int" , - x86_cpuid_version_get_stepping, - x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 29/37] target-i386: convert "stepping" to static property
Quoted 115 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
- in addition useerror_setg()instead oferror_set()--- target-i386/cpu.c | 85 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 39 deletions(-)target-i386/cpu.c +46
-36@@ -441,6 +441,51 @@ PropertyInfo qdev_prop_model_id = {#define DEFINE_PROP_MODEL_ID (_n) \ DEFINE_ABSTRACT_PROP(_n, qdev_prop_model_id) +static void x86_cpuid_version_get_stepping (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = env->cpuid_version &0xf ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_stepping (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xf ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xf ; + env->cpuid_version |= value &0xf ; +} + +PropertyInfo qdev_prop_stepping = { + .name ="uint32" , + .get = x86_cpuid_version_get_stepping, + .set = x86_cpuid_version_set_stepping, +}; +#define DEFINE_PROP_STEPPING (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_stepping, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),@@ -563,6 +608,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_VENDOR ("vendor" ,X86CPU , env.cpuid_vendor1),DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz),DEFINE_PROP_MODEL_ID ("model-id" ), +DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };@@ -1348,42 +1394,6 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); } -static void x86_cpuid_version_get_stepping (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = env->cpuid_version &0xf ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_stepping (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xf ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xf ; - env->cpuid_version |= value &0xf ; -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2269
Quoted 9 lines
target-i386/cpu.c +0
-3@@ -2254,9 +2264,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"model" ,"int" , x86_cpuid_version_get_model, x86_cpuid_version_set_model,NULL ,NULL ,NULL ); -object_property_add (obj,"stepping" ,"int" , - x86_cpuid_version_get_stepping, - x86_cpuid_version_set_stepping,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
PATCH v5 30/37 target-i386: convert "model" to static property
In reply to Igor Mammedov---
- in addition use error_setg() instead of error_set()
--- target-i386/cpu.c | 83 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 38 deletions(-)
target-i386/cpu.c +45 -38
@@ -486,6 +486,50 @@ PropertyInfo qdev_prop_stepping = {#define DEFINE_PROP_STEPPING (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_stepping, uint32_t) +static void x86_cpuid_version_get_model (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = (env->cpuid_version >>4 ) &0xf ; + value |= ((env->cpuid_version >>16 ) &0xf ) <<4 ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_model (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xff ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xf00f0 ; + env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); +} + +PropertyInfo qdev_prop_model = { + .name ="uint32" , + .get = x86_cpuid_version_get_model, + .set = x86_cpuid_version_set_model, +}; +#define DEFINE_PROP_MODEL (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_model, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -609,6 +653,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz),DEFINE_PROP_MODEL_ID ("model-id" ),DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version), +DEFINE_PROP_MODEL ("model" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };
@@ -1359,41 +1404,6 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, } } -static void x86_cpuid_version_get_model (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = (env->cpuid_version >>4 ) &0xf ; - value |= ((env->cpuid_version >>16 ) &0xf ) <<4 ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_model (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xff ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xf00f0 ; - env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
@@ -2261,9 +2271,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"family" ,"int" , x86_cpuid_version_get_family, x86_cpuid_version_set_family,NULL ,NULL ,NULL ); -object_property_add (obj,"model" ,"int" , - x86_cpuid_version_get_model, - x86_cpuid_version_set_model,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 30/37] target-i386: convert "model" to static property
Quoted 113 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
- in addition useerror_setg()instead oferror_set()--- target-i386/cpu.c | 83 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 38 deletions(-)target-i386/cpu.c +45
-35@@ -486,6 +486,50 @@ PropertyInfo qdev_prop_stepping = {#define DEFINE_PROP_STEPPING (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_stepping, uint32_t) +static void x86_cpuid_version_get_model (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = (env->cpuid_version >>4 ) &0xf ; + value |= ((env->cpuid_version >>16 ) &0xf ) <<4 ; +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_model (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xff ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xf00f0 ; + env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); +} + +PropertyInfo qdev_prop_model = { + .name ="uint32" , + .get = x86_cpuid_version_get_model, + .set = x86_cpuid_version_set_model, +}; +#define DEFINE_PROP_MODEL (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_model, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),@@ -609,6 +653,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_TSC_FREQ ("tsc-frequency" ,X86CPU , env.tsc_khz),DEFINE_PROP_MODEL_ID ("model-id" ),DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version), +DEFINE_PROP_MODEL ("model" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };@@ -1359,41 +1404,6 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, } } -static void x86_cpuid_version_get_model (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = (env->cpuid_version >>4 ) &0xf ; - value |= ((env->cpuid_version >>16 ) &0xf ) <<4 ; -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_model (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xff ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xf00f0 ; - env->cpuid_version |= ((value &0xf ) <<4 ) | ((value >>4 ) <<16 ); -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2276
Quoted 9 lines
target-i386/cpu.c +0
-3@@ -2261,9 +2271,6 @@ static void x86_cpu_initfn(Object *obj)object_property_add (obj,"family" ,"int" , x86_cpuid_version_get_family, x86_cpuid_version_set_family,NULL ,NULL ,NULL ); -object_property_add (obj,"model" ,"int" , - x86_cpuid_version_get_model, - x86_cpuid_version_set_model,NULL ,NULL ,NULL ); env->cpuid_apic_id = env->cpu_index;
PATCH v5 31/37 target-i386: convert "family" to static property
In reply to Igor Mammedov---
- in addition use error_setg() instead of error_set()
--- target-i386/cpu.c | 96 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 45 deletions(-)
target-i386/cpu.c +51 -45
@@ -530,6 +530,56 @@ PropertyInfo qdev_prop_model = {#define DEFINE_PROP_MODEL (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_model, uint32_t) +static void x86_cpuid_version_get_family (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = (env->cpuid_version >>8 ) &0xf ; +if (value ==0xf ) { + value += (env->cpuid_version >>20 ) &0xff ; + } +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_family (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xff +0xf ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xff00f00 ; +if (value >0x0f ) { + env->cpuid_version |=0xf00 | ((value -0x0f ) <<20 ); + }else { + env->cpuid_version |= value <<8 ; + } +} + +PropertyInfo qdev_prop_family = { + .name ="uint32" , + .get = x86_cpuid_version_get_family, + .set = x86_cpuid_version_set_family, +}; +#define DEFINE_PROP_FAMILY (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_family, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),
@@ -654,6 +704,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_MODEL_ID ("model-id" ),DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version),DEFINE_PROP_MODEL ("model" ,X86CPU , env.cpuid_version), +DEFINE_PROP_FAMILY ("family" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };
@@ -1363,47 +1414,6 @@ static int check_features_against_host(X86CPU *cpu)return rv; } -static void x86_cpuid_version_get_family (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = (env->cpuid_version >>8 ) &0xf ; -if (value ==0xf ) { - value += (env->cpuid_version >>20 ) &0xff ; - } -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_family (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xff +0xf ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xff00f00 ; -if (value >0x0f ) { - env->cpuid_version |=0xf00 | ((value -0x0f ) <<20 ); - }else { - env->cpuid_version |= value <<8 ; - } -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
@@ -2268,10 +2278,6 @@ static void x86_cpu_initfn(Object *obj)cpu_exec_init (env); -object_property_add (obj,"family" ,"int" , - x86_cpuid_version_get_family, - x86_cpuid_version_set_family,NULL ,NULL ,NULL ); - env->cpuid_apic_id = env->cpu_index;/* init various static tables used in TCG mode */
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 31/37] target-i386: convert "family" to static property
Quoted 125 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
- in addition useerror_setg()instead oferror_set()--- target-i386/cpu.c | 96 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 45 deletions(-)target-i386/cpu.c +51
-41@@ -530,6 +530,56 @@ PropertyInfo qdev_prop_model = {#define DEFINE_PROP_MODEL (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_model, uint32_t) +static void x86_cpuid_version_get_family (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +int64_t value; + + value = (env->cpuid_version >>8 ) &0xf ; +if (value ==0xf ) { + value += (env->cpuid_version >>20 ) &0xff ; + } +visit_type_int (v, &value, name, errp); +} + +static void x86_cpuid_version_set_family (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +X86CPU *cpu =X86_CPU (obj); +CPUX86State *env = &cpu->env; +const int64_t min =0 ; +const int64_t max =0xff +0xf ; +int64_t value; + +visit_type_int (v, &value, name, errp); +if (error_is_set (errp)) { +return ; + } +if (value < min || value > max) { +error_setg (errp,"Property %s.%s doesn't take value %" PRId64" (min" +"imum: %" PRId64", maximum: %" PRId64, +object_get_typename (obj), name, value, min, max); +return ; + } + + env->cpuid_version &= ~0xff00f00 ; +if (value >0x0f ) { + env->cpuid_version |=0xf00 | ((value -0x0f ) <<20 ); + }else { + env->cpuid_version |= value <<8 ; + } +} + +PropertyInfo qdev_prop_family = { + .name ="uint32" , + .get = x86_cpuid_version_get_family, + .set = x86_cpuid_version_set_family, +}; +#define DEFINE_PROP_FAMILY (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_family, uint32_t) +static Property cpu_x86_properties[] = {DEFINE_PROP_BIT ("f-fpu" ,X86CPU , env.cpuid_features,0 , false),DEFINE_PROP_BIT ("f-vme" ,X86CPU , env.cpuid_features,1 , false),@@ -654,6 +704,7 @@ static Property cpu_x86_properties[] = {DEFINE_PROP_MODEL_ID ("model-id" ),DEFINE_PROP_STEPPING ("stepping" ,X86CPU , env.cpuid_version),DEFINE_PROP_MODEL ("model" ,X86CPU , env.cpuid_version), +DEFINE_PROP_FAMILY ("family" ,X86CPU , env.cpuid_version), DEFINE_PROP_END_OF_LIST(), };@@ -1363,47 +1414,6 @@ static int check_features_against_host(X86CPU *cpu)return rv; } -static void x86_cpuid_version_get_family (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -int64_t value; - - value = (env->cpuid_version >>8 ) &0xf ; -if (value ==0xf ) { - value += (env->cpuid_version >>20 ) &0xff ; - } -visit_type_int (v, &value, name, errp); -} - -static void x86_cpuid_version_set_family (Object *obj,Visitor *v,void *opaque, -const char *name,Error **errp) -{ -X86CPU *cpu =X86_CPU (obj); -CPUX86State *env = &cpu->env; -const int64_t min =0 ; -const int64_t max =0xff +0xf ; -int64_t value; - -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - - env->cpuid_version &= ~0xff00f00 ; -if (value >0x0f ) { - env->cpuid_version |=0xf00 | ((value -0x0f ) <<20 ); - }else { - env->cpuid_version |= value <<8 ; - } -} -static void cpudef_2_x86_cpu (X86CPU *cpu,x86_def_t *def,Error **errp) {CPUX86State *env = &cpu->env;
target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2283
Quoted 10 lines
target-i386/cpu.c +0
-4@@ -2268,10 +2278,6 @@ static void x86_cpu_initfn(Object *obj)cpu_exec_init (env); -object_property_add (obj,"family" ,"int" , - x86_cpuid_version_get_family, - x86_cpuid_version_set_family,NULL ,NULL ,NULL ); - env->cpuid_apic_id = env->cpu_index;/* init various static tables used in TCG mode */
PATCH v5 32/37 target-i386: use static properties for setting cpuid features
In reply to Igor Mammedov - def->kvm_features was used only for setting hadcoded defaults, with defaults set by static props, we do not need it anymore, ignore it in cpudef_2_x86_cpu().
- take in account CPUID_EXT_HYPERVISOR feature set by static property default value;
---
* fix double free of features in cpu_x86_find_by_name()
--- target-i386/cpu.c | 271 +++++++----------------------------------------------- 1 file changed, 31 insertions(+), 240 deletions(-)
target-i386/cpu.c +31 -240
@@ -87,31 +87,6 @@ static const char *ext3_feature_name[] = { NULL, NULL, NULL, NULL, }; -static const char *kvm_feature_name[] = { -"kvmclock" ,"kvm_nopiodelay" ,"kvm_mmu" ,"kvmclock" ,"kvm_asyncpf" ,NULL ,"kvm_pv_eoi" ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; - -static const char *svm_feature_name[] = { -"npt" ,"lbrv" ,"svm_lock" ,"nrip_save" , -"tsc_scale" ,"vmcb_clean" ,"flushbyasid" ,"decodeassists" , -NULL ,NULL ,"pause_filter" ,NULL , -"pfthreshold" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; - -static const char *cpuid_7_0_ebx_feature_name[] = { -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"smep" , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,"smap" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)
@@ -752,88 +727,6 @@ void host_cpuid(uint32_t function, uint32_t count,#endif } -#define iswhite (c) ((c) && ((c) <= ' ' || '~' < (c))) - -/* general substring compare of *[s1..e1) and *[s2..e2). sx is start of -* a substring. ex if !NULL points to the first char after a substring, -* otherwise the string is assumed to sized by a terminating nul. -* Return lexical ordering of *s1:*s2. -*/ -static int sstrcmp (const char *s1,const char *e1,const char *s2, -const char *e2) -{ -for (;;) { -if (!*s1 || !*s2 || *s1 != *s2) -return (*s1 - *s2); - ++s1, ++s2; -if (s1 == e1 && s2 == e2) -return (0 ); -else if (s1 == e1) -return (*s2); -else if (s2 == e2) -return (*s1); - } -} - -/* compare *[s..e) to *altstr. *altstr may be a simple string or multiple -* '|' delimited (possibly empty) strings in which case search for a match -* within the alternatives proceeds left to right. Return 0 for success, -* non-zero otherwise. -*/ -static int altcmp (const char *s,const char *e,const char *altstr) -{ -const char *p, *q; - -for (q = p = altstr; ; ) { -while (*p && *p !='|' ) - ++p; -if ((q == p && !*s) || (q != p && !sstrcmp (s, e, q, p))) -return (0 ); -if (!*p) -return (1 ); -else - q = ++p; - } -} - -/* search featureset for flag *[s..e), if found set corresponding bit in -* *pval and return true, otherwise return false -*/ -static bool lookup_feature (uint32_t *pval,const char *s,const char *e, -const char **featureset) -{ -uint32_t mask; -const char **ppc; -bool found = false; - -for (mask =1 , ppc = featureset; mask; mask <<=1 , ++ppc) { -if (*ppc && !altcmp (s, e, *ppc)) { - *pval |= mask; - found = true; - } - } -return found; -} - -static void add_flagname_to_bitmaps (const char *flagname,uint32_t *features, -uint32_t *ext_features, -uint32_t *ext2_features, -uint32_t *ext3_features, -uint32_t *kvm_features, -uint32_t *svm_features, -uint32_t *cpuid_7_0_ebx_features) -{ -if (!lookup_feature (features, flagname,NULL , feature_name) && - !lookup_feature (ext_features, flagname,NULL , ext_feature_name) && - !lookup_feature (ext2_features, flagname,NULL , ext2_feature_name) && - !lookup_feature (ext3_features, flagname,NULL , ext3_feature_name) && - !lookup_feature (kvm_features, flagname,NULL , kvm_feature_name) && - !lookup_feature (svm_features, flagname,NULL , svm_feature_name) && - !lookup_feature (cpuid_7_0_ebx_features, flagname,NULL , - cpuid_7_0_ebx_feature_name)) -fprintf (stderr,"CPU feature %s not found\n" , flagname); -} - typedef struct x86_def_t { struct x86_def_t *next; const char *name;
@@ -1432,10 +1325,10 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)object_property_set_int (OBJECT (cpu), (int64_t )def->tsc_khz *1000 ,"tsc-frequency" , errp); env->cpuid_features = def->features; - env->cpuid_ext_features = def->ext_features; + env->cpuid_ext_features = (CPUID_EXT_HYPERVISOR & env->cpuid_ext_features) | + def->ext_features; env->cpuid_ext2_features = def->ext2_features; env->cpuid_ext3_features = def->ext3_features; - env->cpuid_kvm_features = def->kvm_features; env->cpuid_svm_features = def->svm_features; env->cpuid_ext4_features = def->ext4_features; env->cpuid_7_0_ebx_features = def->cpuid_7_0_ebx_features;
@@ -1532,25 +1425,32 @@ out:return ; } +/* Set features on X86CPU object based on a QDict */ +static void cpu_x86_set_props (X86CPU *cpu,QDict *features,Error **errp) +{ +const QDictEntry *ent; + +for (ent =qdict_first (features); ent; ent =qdict_next (features, ent)) { +const QString *qval =qobject_to_qstring (qdict_entry_value (ent)); +object_property_parse (OBJECT (cpu),qstring_get_str (qval), +qdict_entry_key (ent), errp); +if (error_is_set (errp)) { +return ; + } + } +} +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) {x86_def_t *def; -CPUX86State *env = &cpu->env; +QDict *features =NULL ; +char *name =NULL ; -char *s =g_strdup (cpu_model); -char *featurestr, *name =strtok (s,"," ); -/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features; -uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ; -uint32_t plus_7_0_ebx_features =0 ; -/* Features to be removed */ -uint32_t minus_features =0 , minus_ext_features =0 ; -uint32_t minus_ext2_features =0 , minus_ext3_features =0 ; -uint32_t minus_kvm_features =0 , minus_svm_features =0 ; -uint32_t minus_7_0_ebx_features =0 ; -uint32_t numvalue; +compat_normalize_cpu_model (cpu_model, &name, &features, errp); +if (error_is_set (errp)) { + goto error; + }for (def = x86_defs; def; def = def->next)if (name && !strcmp (name, def->name))
@@ -1563,127 +1463,18 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } - featurestr =strtok (NULL ,"," ); - -while (featurestr) { -char *val; -if (featurestr[0 ] =='+' ) { -add_flagname_to_bitmaps (featurestr +1 , &plus_features, - &plus_ext_features, &plus_ext2_features, - &plus_ext3_features, &plus_kvm_features, - &plus_svm_features, &plus_7_0_ebx_features); - }else if (featurestr[0 ] =='-' ) { -add_flagname_to_bitmaps (featurestr +1 , &minus_features, - &minus_ext_features, &minus_ext2_features, - &minus_ext3_features, &minus_kvm_features, - &minus_svm_features, &minus_7_0_ebx_features); - }else if ((val =strchr (featurestr,'=' ))) { - *val =0 ; val++; -if (!strcmp (featurestr,"family" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff +0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->family = numvalue; - }else if (!strcmp (featurestr,"model" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->model = numvalue; - }else if (!strcmp (featurestr,"stepping" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->stepping = numvalue ; - }else if (!strcmp (featurestr,"level" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->level = numvalue; - }else if (!strcmp (featurestr,"xlevel" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } -if (numvalue <0x80000000 ) { - numvalue +=0x80000000 ; - } - x86_cpu_def->xlevel = numvalue; - }else if (!strcmp (featurestr,"vendor" )) { -pstrcpy (x86_cpu_def->vendor,sizeof (x86_cpu_def->vendor), val); - x86_cpu_def->vendor_override =1 ; - }else if (!strcmp (featurestr,"model_id" )) { -pstrcpy (x86_cpu_def->model_id,sizeof (x86_cpu_def->model_id), - val); - }else if (!strcmp (featurestr,"tsc_freq" )) { -int64_t tsc_freq; -char *err; - - tsc_freq =strtosz_suffix_unit (val, &err, -STRTOSZ_DEFSUFFIX_B ,1000 ); -if (tsc_freq <0 || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->tsc_khz = tsc_freq /1000 ; - }else if (!strcmp (featurestr,"hv_spinlocks" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } -hyperv_set_spinlock_retries (numvalue); - }else { -fprintf (stderr,"unrecognized feature %s\n" , featurestr); - goto error; - } - }else if (!strcmp (featurestr,"check" )) { - check_cpuid =1 ; - }else if (!strcmp (featurestr,"enforce" )) { - check_cpuid = enforce_cpuid =1 ; - }else if (!strcmp (featurestr,"hv_relaxed" )) { -hyperv_enable_relaxed_timing (true); - }else if (!strcmp (featurestr,"hv_vapic" )) { -hyperv_enable_vapic_recommended (true); - }else { -fprintf (stderr,"feature string `%s' not in format (+feature|-feature|feature=xyz)\n" , featurestr); - goto error; - } - featurestr =strtok (NULL ,"," ); +cpu_x86_set_props (cpu, features, errp); +if (error_is_set (errp)) { + goto error; } - x86_cpu_def->features |= plus_features; - x86_cpu_def->ext_features |= plus_ext_features; - x86_cpu_def->ext2_features |= plus_ext2_features; - x86_cpu_def->ext3_features |= plus_ext3_features; - x86_cpu_def->kvm_features |= plus_kvm_features; - x86_cpu_def->svm_features |= plus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features |= plus_7_0_ebx_features; - x86_cpu_def->features &= ~minus_features; - x86_cpu_def->ext_features &= ~minus_ext_features; - x86_cpu_def->ext2_features &= ~minus_ext2_features; - x86_cpu_def->ext3_features &= ~minus_ext3_features; - x86_cpu_def->kvm_features &= ~minus_kvm_features; - x86_cpu_def->svm_features &= ~minus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features &= ~minus_7_0_ebx_features; -g_free (s); + +g_free (name); +QDECREF (features);return 0 ; error: -g_free (s); +g_free (name); +QDECREF (features);if (!error_is_set (errp)) {error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 32/37] target-i386: use static properties for setting cpuid features
Quoted 255 lines · Igor Mammedov
-
def->kvm_featureswas used only for setting hadcoded defaults, with defaults set by static props, we do not need it anymore, ignore it incpudef_2_x86_cpu().
- take in accountCPUID_EXT_HYPERVISORfeature set by staticproperty default value;Signed-off-by Igor Mammedov <[email protected]>---
* fix double free of features incpu_x86_find_by_name()--- target-i386/cpu.c | 271 +++++++----------------------------------------------- 1 file changed, 31 insertions(+), 240 deletions(-)target-i386/cpu.c +23
-176@@ -87,31 +87,6 @@ static const char *ext3_feature_name[] = { NULL, NULL, NULL, NULL, }; -static const char *kvm_feature_name[] = { -"kvmclock" ,"kvm_nopiodelay" ,"kvm_mmu" ,"kvmclock" ,"kvm_asyncpf" ,NULL ,"kvm_pv_eoi" ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; - -static const char *svm_feature_name[] = { -"npt" ,"lbrv" ,"svm_lock" ,"nrip_save" , -"tsc_scale" ,"vmcb_clean" ,"flushbyasid" ,"decodeassists" , -NULL ,NULL ,"pause_filter" ,NULL , -"pfthreshold" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; - -static const char *cpuid_7_0_ebx_feature_name[] = { -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"smep" , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,"smap" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -752,88 +727,6 @@ void host_cpuid(uint32_t function, uint32_t count,#endif } -#define iswhite (c) ((c) && ((c) <= ' ' || '~' < (c))) - -/* general substring compare of *[s1..e1) and *[s2..e2). sx is start of -* a substring. ex if !NULL points to the first char after a substring, -* otherwise the string is assumed to sized by a terminating nul. -* Return lexical ordering of *s1:*s2. -*/ -static int sstrcmp (const char *s1,const char *e1,const char *s2, -const char *e2) -{ -for (;;) { -if (!*s1 || !*s2 || *s1 != *s2) -return (*s1 - *s2); - ++s1, ++s2; -if (s1 == e1 && s2 == e2) -return (0 ); -else if (s1 == e1) -return (*s2); -else if (s2 == e2) -return (*s1); - } -} - -/* compare *[s..e) to *altstr. *altstr may be a simple string or multiple -* '|' delimited (possibly empty) strings in which case search for a match -* within the alternatives proceeds left to right. Return 0 for success, -* non-zero otherwise. -*/ -static int altcmp (const char *s,const char *e,const char *altstr) -{ -const char *p, *q; - -for (q = p = altstr; ; ) { -while (*p && *p !='|' ) - ++p; -if ((q == p && !*s) || (q != p && !sstrcmp (s, e, q, p))) -return (0 ); -if (!*p) -return (1 ); -else - q = ++p; - } -} - -/* search featureset for flag *[s..e), if found set corresponding bit in -* *pval and return true, otherwise return false -*/ -static bool lookup_feature (uint32_t *pval,const char *s,const char *e, -const char **featureset) -{ -uint32_t mask; -const char **ppc; -bool found = false; - -for (mask =1 , ppc = featureset; mask; mask <<=1 , ++ppc) { -if (*ppc && !altcmp (s, e, *ppc)) { - *pval |= mask; - found = true; - } - } -return found; -} - -static void add_flagname_to_bitmaps (const char *flagname,uint32_t *features, -uint32_t *ext_features, -uint32_t *ext2_features, -uint32_t *ext3_features, -uint32_t *kvm_features, -uint32_t *svm_features, -uint32_t *cpuid_7_0_ebx_features) -{ -if (!lookup_feature (features, flagname,NULL , feature_name) && - !lookup_feature (ext_features, flagname,NULL , ext_feature_name) && - !lookup_feature (ext2_features, flagname,NULL , ext2_feature_name) && - !lookup_feature (ext3_features, flagname,NULL , ext3_feature_name) && - !lookup_feature (kvm_features, flagname,NULL , kvm_feature_name) && - !lookup_feature (svm_features, flagname,NULL , svm_feature_name) && - !lookup_feature (cpuid_7_0_ebx_features, flagname,NULL , - cpuid_7_0_ebx_feature_name)) -fprintf (stderr,"CPU feature %s not found\n" , flagname); -} - typedef struct x86_def_t { struct x86_def_t *next; const char *name;@@ -1432,10 +1325,10 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)object_property_set_int (OBJECT (cpu), (int64_t )def->tsc_khz *1000 ,"tsc-frequency" , errp); env->cpuid_features = def->features; - env->cpuid_ext_features = def->ext_features; + env->cpuid_ext_features = (CPUID_EXT_HYPERVISOR & env->cpuid_ext_features) | + def->ext_features; env->cpuid_ext2_features = def->ext2_features; env->cpuid_ext3_features = def->ext3_features; - env->cpuid_kvm_features = def->kvm_features; env->cpuid_svm_features = def->svm_features; env->cpuid_ext4_features = def->ext4_features; env->cpuid_7_0_ebx_features = def->cpuid_7_0_ebx_features;@@ -1532,25 +1425,32 @@ out:return ; } +/* Set features on X86CPU object based on a QDict */ +static void cpu_x86_set_props (X86CPU *cpu,QDict *features,Error **errp) +{ +const QDictEntry *ent; + +for (ent =qdict_first (features); ent; ent =qdict_next (features, ent)) { +const QString *qval =qobject_to_qstring (qdict_entry_value (ent)); +object_property_parse (OBJECT (cpu),qstring_get_str (qval), +qdict_entry_key (ent), errp); +if (error_is_set (errp)) { +return ; + } + } +} +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) {x86_def_t *def; -CPUX86State *env = &cpu->env; +QDict *features =NULL ; +char *name =NULL ; -char *s =g_strdup (cpu_model); -char *featurestr, *name =strtok (s,"," ); -/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features; -uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ; -uint32_t plus_7_0_ebx_features =0 ; -/* Features to be removed */ -uint32_t minus_features =0 , minus_ext_features =0 ; -uint32_t minus_ext2_features =0 , minus_ext3_features =0 ; -uint32_t minus_kvm_features =0 , minus_svm_features =0 ; -uint32_t minus_7_0_ebx_features =0 ; -uint32_t numvalue; +compat_normalize_cpu_model (cpu_model, &name, &features, errp); +if (error_is_set (errp)) { + goto error; + }for (def = x86_defs; def; def = def->next)if (name && !strcmp (name, def->name))@@ -1563,127 +1463,18 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } - featurestr =strtok (NULL ,"," ); - -while (featurestr) { -char *val; -if (featurestr[0 ] =='+' ) { -add_flagname_to_bitmaps (featurestr +1 , &plus_features, - &plus_ext_features, &plus_ext2_features, - &plus_ext3_features, &plus_kvm_features, - &plus_svm_features, &plus_7_0_ebx_features); - }else if (featurestr[0 ] =='-' ) { -add_flagname_to_bitmaps (featurestr +1 , &minus_features, - &minus_ext_features, &minus_ext2_features, - &minus_ext3_features, &minus_kvm_features, - &minus_svm_features, &minus_7_0_ebx_features); - }else if ((val =strchr (featurestr,'=' ))) { - *val =0 ; val++; -if (!strcmp (featurestr,"family" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff +0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->family = numvalue; - }else if (!strcmp (featurestr,"model" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->model = numvalue; - }else if (!strcmp (featurestr,"stepping" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->stepping = numvalue ; - }else if (!strcmp (featurestr,"level" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->level = numvalue; - }else if (!strcmp (featurestr,"xlevel" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val);
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1628
Quoted 10 lines
target-i386/cpu.c +0
-10- goto error; - } -if (numvalue <0x80000000 ) { - numvalue +=0x80000000 ; - } - x86_cpu_def->xlevel = numvalue; - }else if (!strcmp (featurestr,"vendor" )) { -pstrcpy (x86_cpu_def->vendor,sizeof (x86_cpu_def->vendor), val); - x86_cpu_def->vendor_override =1 ; - }else if (!strcmp (featurestr,"model_id" )) {
This makes model_id= as a feature stop working. It needs to be added to this patch, or maybe #10 where "tsc_freq" was handled.
Quoted 59 lines
target-i386/cpu.c +5
-53-pstrcpy (x86_cpu_def->model_id,sizeof (x86_cpu_def->model_id), - val); - }else if (!strcmp (featurestr,"tsc_freq" )) { -int64_t tsc_freq; -char *err; - - tsc_freq =strtosz_suffix_unit (val, &err, -STRTOSZ_DEFSUFFIX_B ,1000 ); -if (tsc_freq <0 || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->tsc_khz = tsc_freq /1000 ; - }else if (!strcmp (featurestr,"hv_spinlocks" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } -hyperv_set_spinlock_retries (numvalue); - }else { -fprintf (stderr,"unrecognized feature %s\n" , featurestr); - goto error; - } - }else if (!strcmp (featurestr,"check" )) { - check_cpuid =1 ; - }else if (!strcmp (featurestr,"enforce" )) { - check_cpuid = enforce_cpuid =1 ; - }else if (!strcmp (featurestr,"hv_relaxed" )) { -hyperv_enable_relaxed_timing (true); - }else if (!strcmp (featurestr,"hv_vapic" )) { -hyperv_enable_vapic_recommended (true); - }else { -fprintf (stderr,"feature string `%s' not in format (+feature|-feature|feature=xyz)\n" , featurestr); - goto error; - } - featurestr =strtok (NULL ,"," ); +cpu_x86_set_props (cpu, features, errp); +if (error_is_set (errp)) { + goto error; } - x86_cpu_def->features |= plus_features; - x86_cpu_def->ext_features |= plus_ext_features; - x86_cpu_def->ext2_features |= plus_ext2_features; - x86_cpu_def->ext3_features |= plus_ext3_features; - x86_cpu_def->kvm_features |= plus_kvm_features; - x86_cpu_def->svm_features |= plus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features |= plus_7_0_ebx_features; - x86_cpu_def->features &= ~minus_features; - x86_cpu_def->ext_features &= ~minus_ext_features; - x86_cpu_def->ext2_features &= ~minus_ext2_features; - x86_cpu_def->ext3_features &= ~minus_ext3_features; - x86_cpu_def->kvm_features &= ~minus_kvm_features; - x86_cpu_def->svm_features &= ~minus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features &= ~minus_7_0_ebx_features; -g_free (s); + +g_free (name);
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1480
Quoted 10 lines
target-i386/cpu.c +3
-1+QDECREF (features);return 0 ; error: -g_free (s); +g_free (name); +QDECREF (features);if (!error_is_set (errp)) {error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); }
-Don Slutz
Re: [Qemu-devel] [PATCH 32/37] target-i386: use static properties for setting cpuid features
Quoted 260 lines · On Tue, 23 Oct 2012 11:29:46 -0400 Don Slutz <[email protected]> wrote:
Quoted 259 lines · Igor Mammedov
-
def->kvm_featureswas used only for setting hadcoded defaults, with defaults set by static props, we do not need it anymore, ignore it incpudef_2_x86_cpu().
- take in accountCPUID_EXT_HYPERVISORfeature set by staticproperty default value;Signed-off-by Igor Mammedov <[email protected]>---
* fix double free of features incpu_x86_find_by_name()--- target-i386/cpu.c | 271 +++++++----------------------------------------------- 1 file changed, 31 insertions(+), 240 deletions(-)target-i386/cpu.c +23
-180@@ -87,31 +87,6 @@ static const char *ext3_feature_name[] = { NULL, NULL, NULL, NULL, }; -static const char *kvm_feature_name[] = { -"kvmclock" ,"kvm_nopiodelay" ,"kvm_mmu" ,"kvmclock" ,"kvm_asyncpf" ,NULL ,"kvm_pv_eoi" ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; - -static const char *svm_feature_name[] = { -"npt" ,"lbrv" ,"svm_lock" ,"nrip_save" , -"tsc_scale" ,"vmcb_clean" ,"flushbyasid" ,"decodeassists" , -NULL ,NULL ,"pause_filter" ,NULL , -"pfthreshold" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; - -static const char *cpuid_7_0_ebx_feature_name[] = { -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"smep" , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,"smap" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -752,88 +727,6 @@ void host_cpuid(uint32_t function, uint32_t count,#endif } -#define iswhite (c) ((c) && ((c) <= ' ' || '~' < (c))) - -/* general substring compare of *[s1..e1) and *[s2..e2). sx is start of -* a substring. ex if !NULL points to the first char after a substring, -* otherwise the string is assumed to sized by a terminating nul. -* Return lexical ordering of *s1:*s2. -*/ -static int sstrcmp (const char *s1,const char *e1,const char *s2, -const char *e2) -{ -for (;;) { -if (!*s1 || !*s2 || *s1 != *s2) -return (*s1 - *s2); - ++s1, ++s2; -if (s1 == e1 && s2 == e2) -return (0 ); -else if (s1 == e1) -return (*s2); -else if (s2 == e2) -return (*s1); - } -} - -/* compare *[s..e) to *altstr. *altstr may be a simple string or multiple -* '|' delimited (possibly empty) strings in which case search for a match -* within the alternatives proceeds left to right. Return 0 for success, -* non-zero otherwise. -*/ -static int altcmp (const char *s,const char *e,const char *altstr) -{ -const char *p, *q; - -for (q = p = altstr; ; ) { -while (*p && *p !='|' ) - ++p; -if ((q == p && !*s) || (q != p && !sstrcmp (s, e, q, p))) -return (0 ); -if (!*p) -return (1 ); -else - q = ++p; - } -} - -/* search featureset for flag *[s..e), if found set corresponding bit in -* *pval and return true, otherwise return false -*/ -static bool lookup_feature (uint32_t *pval,const char *s,const char *e, -const char **featureset) -{ -uint32_t mask; -const char **ppc; -bool found = false; - -for (mask =1 , ppc = featureset; mask; mask <<=1 , ++ppc) { -if (*ppc && !altcmp (s, e, *ppc)) { - *pval |= mask; - found = true; - } - } -return found; -} - -static void add_flagname_to_bitmaps (const char *flagname,uint32_t *features, -uint32_t *ext_features, -uint32_t *ext2_features, -uint32_t *ext3_features, -uint32_t *kvm_features, -uint32_t *svm_features, -uint32_t *cpuid_7_0_ebx_features) -{ -if (!lookup_feature (features, flagname,NULL , feature_name) && - !lookup_feature (ext_features, flagname,NULL , ext_feature_name) && - !lookup_feature (ext2_features, flagname,NULL , ext2_feature_name) && - !lookup_feature (ext3_features, flagname,NULL , ext3_feature_name) && - !lookup_feature (kvm_features, flagname,NULL , kvm_feature_name) && - !lookup_feature (svm_features, flagname,NULL , svm_feature_name) && - !lookup_feature (cpuid_7_0_ebx_features, flagname,NULL , - cpuid_7_0_ebx_feature_name)) -fprintf (stderr,"CPU feature %s not found\n" , flagname); -} - typedef struct x86_def_t { struct x86_def_t *next; const char *name;@@ -1432,10 +1325,10 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)object_property_set_int (OBJECT (cpu), (int64_t )def->tsc_khz *1000 ,"tsc-frequency" , errp); env->cpuid_features = def->features; - env->cpuid_ext_features = def->ext_features; + env->cpuid_ext_features = (CPUID_EXT_HYPERVISOR & env->cpuid_ext_features) | + def->ext_features; env->cpuid_ext2_features = def->ext2_features; env->cpuid_ext3_features = def->ext3_features; - env->cpuid_kvm_features = def->kvm_features; env->cpuid_svm_features = def->svm_features; env->cpuid_ext4_features = def->ext4_features; env->cpuid_7_0_ebx_features = def->cpuid_7_0_ebx_features;@@ -1532,25 +1425,32 @@ out:return ; } +/* Set features on X86CPU object based on a QDict */ +static void cpu_x86_set_props (X86CPU *cpu,QDict *features,Error **errp) +{ +const QDictEntry *ent; + +for (ent =qdict_first (features); ent; ent =qdict_next (features, ent)) { +const QString *qval =qobject_to_qstring (qdict_entry_value (ent)); +object_property_parse (OBJECT (cpu),qstring_get_str (qval), +qdict_entry_key (ent), errp); +if (error_is_set (errp)) { +return ; + } + } +} +static int cpu_x86_find_by_name (X86CPU *cpu,x86_def_t *x86_cpu_def,const char *cpu_model,Error **errp) {x86_def_t *def; -CPUX86State *env = &cpu->env; +QDict *features =NULL ; +char *name =NULL ; -char *s =g_strdup (cpu_model); -char *featurestr, *name =strtok (s,"," ); -/* Features to be added*/ -uint32_t plus_features =0 , plus_ext_features = env->cpuid_ext_features; -uint32_t plus_ext2_features =0 , plus_ext3_features =0 ; -uint32_t plus_kvm_features = env->cpuid_kvm_features, plus_svm_features =0 ; -uint32_t plus_7_0_ebx_features =0 ; -/* Features to be removed */ -uint32_t minus_features =0 , minus_ext_features =0 ; -uint32_t minus_ext2_features =0 , minus_ext3_features =0 ; -uint32_t minus_kvm_features =0 , minus_svm_features =0 ; -uint32_t minus_7_0_ebx_features =0 ; -uint32_t numvalue; +compat_normalize_cpu_model (cpu_model, &name, &features, errp); +if (error_is_set (errp)) { + goto error; + }for (def = x86_defs; def; def = def->next)if (name && !strcmp (name, def->name))@@ -1563,127 +1463,18 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,memcpy (x86_cpu_def, def,sizeof (*def)); } - featurestr =strtok (NULL ,"," ); - -while (featurestr) { -char *val; -if (featurestr[0 ] =='+' ) { -add_flagname_to_bitmaps (featurestr +1 , &plus_features, - &plus_ext_features, &plus_ext2_features, - &plus_ext3_features, &plus_kvm_features, - &plus_svm_features, &plus_7_0_ebx_features); - }else if (featurestr[0 ] =='-' ) { -add_flagname_to_bitmaps (featurestr +1 , &minus_features, - &minus_ext_features, &minus_ext2_features, - &minus_ext3_features, &minus_kvm_features, - &minus_svm_features, &minus_7_0_ebx_features); - }else if ((val =strchr (featurestr,'=' ))) { - *val =0 ; val++; -if (!strcmp (featurestr,"family" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff +0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->family = numvalue; - }else if (!strcmp (featurestr,"model" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xff ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->model = numvalue; - }else if (!strcmp (featurestr,"stepping" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err || numvalue >0xf ) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->stepping = numvalue ; - }else if (!strcmp (featurestr,"level" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->level = numvalue; - }else if (!strcmp (featurestr,"xlevel" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } -if (numvalue <0x80000000 ) { - numvalue +=0x80000000 ;
Quoted 8 lines
target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1628
Quoted 6 lines
target-i386/cpu.c +0
-6- } - x86_cpu_def->xlevel = numvalue; - }else if (!strcmp (featurestr,"vendor" )) { -pstrcpy (x86_cpu_def->vendor,sizeof (x86_cpu_def->vendor), val); - x86_cpu_def->vendor_override =1 ; - }else if (!strcmp (featurestr,"model_id" )) {This makes model_id= as a feature stop working. It needs to be added to this patch, or maybe #10 where "
tsc_freq" was handled.
Thanks for finding this one, I'll put it in compat_normalize_cpu_model() alongside with "tsc_freq" legacy name handling.
Quoted 70 lines
Quoted 59 lines
target-i386/cpu.c +5
-53-pstrcpy (x86_cpu_def->model_id,sizeof (x86_cpu_def->model_id), - val); - }else if (!strcmp (featurestr,"tsc_freq" )) { -int64_t tsc_freq; -char *err; - - tsc_freq =strtosz_suffix_unit (val, &err, -STRTOSZ_DEFSUFFIX_B ,1000 ); -if (tsc_freq <0 || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } - x86_cpu_def->tsc_khz = tsc_freq /1000 ; - }else if (!strcmp (featurestr,"hv_spinlocks" )) { -char *err; - numvalue =strtoul (val, &err,0 ); -if (!*val || *err) { -fprintf (stderr,"bad numerical value %s\n" , val); - goto error; - } -hyperv_set_spinlock_retries (numvalue); - }else { -fprintf (stderr,"unrecognized feature %s\n" , featurestr); - goto error; - } - }else if (!strcmp (featurestr,"check" )) { - check_cpuid =1 ; - }else if (!strcmp (featurestr,"enforce" )) { - check_cpuid = enforce_cpuid =1 ; - }else if (!strcmp (featurestr,"hv_relaxed" )) { -hyperv_enable_relaxed_timing (true); - }else if (!strcmp (featurestr,"hv_vapic" )) { -hyperv_enable_vapic_recommended (true); - }else { -fprintf (stderr,"feature string `%s' not in format (+feature|-feature|feature=xyz)\n" , featurestr); - goto error; - } - featurestr =strtok (NULL ,"," ); +cpu_x86_set_props (cpu, features, errp); +if (error_is_set (errp)) { + goto error; } - x86_cpu_def->features |= plus_features; - x86_cpu_def->ext_features |= plus_ext_features; - x86_cpu_def->ext2_features |= plus_ext2_features; - x86_cpu_def->ext3_features |= plus_ext3_features; - x86_cpu_def->kvm_features |= plus_kvm_features; - x86_cpu_def->svm_features |= plus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features |= plus_7_0_ebx_features; - x86_cpu_def->features &= ~minus_features; - x86_cpu_def->ext_features &= ~minus_ext_features; - x86_cpu_def->ext2_features &= ~minus_ext2_features; - x86_cpu_def->ext3_features &= ~minus_ext3_features; - x86_cpu_def->kvm_features &= ~minus_kvm_features; - x86_cpu_def->svm_features &= ~minus_svm_features; - x86_cpu_def->cpuid_7_0_ebx_features &= ~minus_7_0_ebx_features; -g_free (s); + +g_free (name);target-i386/cpu.c static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, · line 1480
Quoted 10 lines
target-i386/cpu.c +3
-1+QDECREF (features);return 0 ; error: -g_free (s); +g_free (name); +QDECREF (features);if (!error_is_set (errp)) {error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); }-Don Slutz
Signature · 2 lines
Regards, Igor
PATCH v5 33/37 qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREACH
In reply to Igor Mammedovhelpers to iterate over device static properties to allow to simplify code a little.
--- hw/qdev-properties.h | 9 +++++++++ qom/qdev-core.c | 10 ++++------ qom/qdev-properties.c | 29 +++++++---------------------- 3 files changed, 20 insertions(+), 28 deletions(-)
hw/qdev-properties.h +9 -0
@@ -135,4 +135,13 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);const Property *qdev_prop_find (const DeviceClass *dc,const char *name); +#define QDEV_PROP_FOREACH (_var, _class) \ + for ((_var) = DEVICE_CLASS((_class))->props; \ + (_var) && (_var)->name; \ + (_var)++) + +#define QDEV_CLASS_FOREACH (_var, _class) \ + for ((_var) = (_class); \ + (_var) != DEVICE_CLASS(object_class_by_name(TYPE_DEVICE)); \ + (_var) = DEVICE_CLASS(object_class_get_parent(OBJECT_CLASS((_var)))))#endif
qom/qdev-core.c +4 -6
@@ -592,7 +592,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,static void device_initfn (Object *obj) {DeviceState *dev =DEVICE (obj); -ObjectClass *class; +DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (dev)));Property *prop;if (qdev_hotplug) {
@@ -603,14 +603,12 @@ static void device_initfn(Object *obj) dev->instance_id_alias =-1 ; dev->state =DEV_STATE_CREATED ; - class =object_get_class (OBJECT (dev)); -do { -for (prop =DEVICE_CLASS (class)->props; prop && prop->name; prop++) { + QDEV_CLASS_FOREACH(dc, dc) { + QDEV_PROP_FOREACH(prop, dc) {qdev_property_add_legacy (dev, prop,NULL );qdev_property_add_static (dev, prop,NULL ); } - class =object_class_get_parent (class); - }while (class !=object_class_by_name (TYPE_DEVICE )); + }qdev_prop_set_globals (dev); object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
qom/qdev-properties.c +7 -22
@@ -772,33 +772,18 @@ PropertyInfo qdev_prop_pci_host_devaddr = {/* --- public helpers --- */ -static Property *qdev_prop_walk (Property *props,const char *name) -{ -if (!props) -return NULL ; -while (props->name) { -if (strcmp (props->name, name) ==0 ) -return props; - props++; - } -return NULL ; -} -const Property *qdev_prop_find (const DeviceClass *dc,const char *name) { -ObjectClass *class; -Property *prop; +const Property *prop;/* device properties */ - class =OBJECT_CLASS (dc); -do { - prop =qdev_prop_walk (DEVICE_CLASS (class)->props, name); -if (prop) { -return prop; + QDEV_CLASS_FOREACH(dc, dc) { + QDEV_PROP_FOREACH(prop, dc) { +if (strcmp (prop->name, name) ==0 ) { +return prop; + } } - class =object_class_get_parent (class); - }while (class !=object_class_by_name (TYPE_DEVICE )); - + }return NULL ; }
Signature · 1 line
1.7.11.7
PATCH v5 34/37 qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit()
In reply to Igor Mammedovit allows to find bit static property corresponding to a specific bit in specified field.
---
* it will be used by next commit to print cpuid feature names for unavailable feature bits.
--- hw/qdev-properties.h | 8 ++++++++ qom/qdev-properties.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+)
hw/qdev-properties.h +8 -0
@@ -144,4 +144,12 @@ const Property *qdev_prop_find(const DeviceClass *dc, const char *name);for ((_var) = (_class); \ (_var) !=DEVICE_CLASS (object_class_by_name (TYPE_DEVICE )); \ (_var) =DEVICE_CLASS (object_class_get_parent (OBJECT_CLASS ((_var))))) + +const Property *qdev_prop_find_bit(const DeviceClass *dc, const int offset, +const uint8_t bitnr); +#define QDEV_FIND_PROP_FROM_BIT (_class, _state, _field, _bitnr) \ + qdev_prop_find_bit(_class, \ + offsetof(_state, _field) + \ + type_check(uint32_t, typeof_field(_state, _field)), \ + _bitnr)#endif
qom/qdev-properties.c +15 -0
@@ -787,6 +787,21 @@ const Property *qdev_prop_find(const DeviceClass *dc, const char *name)return NULL ; } +const Property *qdev_prop_find_bit (const DeviceClass *dc,const int offset, +const uint8_t bitnr) +{ +const Property *prop; + + QDEV_CLASS_FOREACH(dc, dc) { + QDEV_PROP_FOREACH(prop, dc) { +if (prop->offset == offset && prop->bitnr == bitnr) { +return prop; + } + } + } +return NULL ; +} +void error_set_from_qdev_prop_error (Error **errp,int ret,DeviceState *dev,Property *prop,const char *value) {
Signature · 1 line
1.7.11.7
PATCH v5 35/37 target-i386: use static properties in check_features_against_host() to print CPUID feature names
In reply to Igor Mammedov---
v2:
* use separate for() for every feature word
--- target-i386/cpu.c | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 29 deletions(-)
target-i386/cpu.c +43 -29
@@ -1261,19 +1261,12 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def)return 0 ; } -static int unavailable_host_feature (struct model_features_t *f,uint32_t mask) +static void unavailable_host_feat (const uint32_t cpuid,const char *name, +const uint32_t mask) { -int i; - -for (i =0 ; i <32 ; ++i) -if (1 << i & mask) { -fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" -" flag '%s' [0x%08x]\n" , - f->cpuid >>16 , f->cpuid &0xffff , - f->flag_names[i] ? f->flag_names[i] :"[reserved]" , mask); -break ; - } -return 0 ; +fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" +" flag '%s' [0x%08x]\n" , cpuid >>16 , cpuid &0xffff , + name ? name :"[reserved]" , mask); }/* best effort attempt to inform user requested cpu flags aren't making
@@ -1282,28 +1275,49 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)*/ static int check_features_against_host (X86CPU *cpu) { +const DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (cpu)));CPUX86State *env = &cpu->env;x86_def_t host_def;uint32_t mask; -int rv, i; -struct model_features_t ft[] = { - {&env->cpuid_features, &host_def.features, - ~0 , feature_name,0x00000000 }, - {&env->cpuid_ext_features, &host_def.ext_features, - ~CPUID_EXT_HYPERVISOR , ext_feature_name,0x00000001 }, - {&env->cpuid_ext2_features, &host_def.ext2_features, - ~PPRO_FEATURES , ext2_feature_name,0x80000000 }, - {&env->cpuid_ext3_features, &host_def.ext3_features, - ~CPUID_EXT3_SVM , ext3_feature_name,0x80000001 }}; +int rv =0 , bit; +const Property *prop;cpu_x86_fill_host (&host_def); -for (rv =0 , i =0 ; i <ARRAY_SIZE (ft); ++i) -for (mask =1 ; mask; mask <<=1 ) -if (ft[i].check_feat & mask && *ft[i].guest_feat & mask && - !(*ft[i].host_feat & mask)) { -unavailable_host_feature (&ft[i], mask); - rv =1 ; - } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (env->cpuid_features & mask && !(host_def.features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_features, bit); +unavailable_host_feat (0x00000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT_HYPERVISOR & env->cpuid_ext_features & mask && + !(host_def.ext_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext_features, bit); +unavailable_host_feat (0x00000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~PPRO_FEATURES & env->cpuid_ext2_features & mask && + !(host_def.ext2_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext2_features, bit); +unavailable_host_feat (0x80000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT3_SVM & env->cpuid_ext3_features & mask && + !(host_def.ext3_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext3_features, bit); +unavailable_host_feat (0x80000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + }return rv; }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 35/37] target-i386: use static properties in check_features_against_host() to print CPUID feature names
Quoted 59 lines · On Mon, 22 Oct 2012 17:03:21 +0200 Igor Mammedov <[email protected]> wrote:
Signed-off-by Igor Mammedov <[email protected]>---
v2:
* use separatefor()for every feature word--- target-i386/cpu.c | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 29 deletions(-)target-i386/cpu.c +8
-22@@ -1261,19 +1261,12 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def)return 0 ; } -static int unavailable_host_feature (struct model_features_t *f,uint32_t mask) +static void unavailable_host_feat (const uint32_t cpuid,const char *name, +const uint32_t mask) { -int i; - -for (i =0 ; i <32 ; ++i) -if (1 << i & mask) { -fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" -" flag '%s' [0x%08x]\n" , - f->cpuid >>16 , f->cpuid &0xffff , - f->flag_names[i] ? f->flag_names[i] :"[reserved]" , mask); -break ; - } -return 0 ; +fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" +" flag '%s' [0x%08x]\n" , cpuid >>16 , cpuid &0xffff , + name ? name :"[reserved]" , mask); }/* best effort attempt to inform user requested cpu flags aren't making @@ -1282,28 +1275,49 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)*/ static int check_features_against_host (X86CPU *cpu) { +const DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (cpu)));CPUX86State *env = &cpu->env;x86_def_t host_def;uint32_t mask; -int rv, i; -struct model_features_t ft[] = { - {&env->cpuid_features, &host_def.features, - ~0 , feature_name,0x00000000 }, - {&env->cpuid_ext_features, &host_def.ext_features, - ~CPUID_EXT_HYPERVISOR , ext_feature_name,0x00000001 }, - {&env->cpuid_ext2_features, &host_def.ext2_features, - ~PPRO_FEATURES , ext2_feature_name,0x80000000 }, - {&env->cpuid_ext3_features, &host_def.ext3_features, - ~CPUID_EXT3_SVM , ext3_feature_name,0x80000001 }}; +int rv =0 , bit; +const Property *prop;cpu_x86_fill_host (&host_def);
target-i386/cpu.c static int unavailable_host_feature(struct model_features_t *f, uint32_t mask) · line 1288
Quoted 10 lines
target-i386/cpu.c +3
-7-for (rv =0 , i =0 ; i <ARRAY_SIZE (ft); ++i) -for (mask =1 ; mask; mask <<=1 ) -if (ft[i].check_feat & mask && *ft[i].guest_feat & mask && - !(*ft[i].host_feat & mask)) { -unavailable_host_feature (&ft[i], mask); - rv =1 ; - } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (env->cpuid_features & mask && !(host_def.features & mask)) { + prop = QDEV_FIND_PROP_FROM_BIT(dc, CPUX86State,
^^^ should be X86CPU
the same for the next patch, fixed patches will soon follow. git tree with fixes at:
https://github.com/imammedo/qemu/tree/x86-cpu-properties.WIP
Quoted 39 lines
target-i386/cpu.c +32
-0+ cpuid_features, bit); +unavailable_host_feat (0x00000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT_HYPERVISOR & env->cpuid_ext_features & mask && + !(host_def.ext_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext_features, bit); +unavailable_host_feat (0x00000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~PPRO_FEATURES & env->cpuid_ext2_features & mask && + !(host_def.ext2_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext2_features, bit); +unavailable_host_feat (0x80000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT3_SVM & env->cpuid_ext3_features & mask && + !(host_def.ext3_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc, CPUX86State, + cpuid_ext3_features, bit); +unavailable_host_feat (0x80000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + }return rv; }Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards, Igor
PATCH v2 1/1 target-i386: use static properties in check_features_against_host() to print CPUID feature names
In reply to Igor Mammedov---
v2:
* use separate for() for every feature word
v3:
* fix check_features_against_host(), use X86CPU as base to count offset correctly
--- target-i386/cpu.c | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 29 deletions(-)
target-i386/cpu.c +43 -29
@@ -1261,19 +1261,12 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def)return 0 ; } -static int unavailable_host_feature (struct model_features_t *f,uint32_t mask) +static void unavailable_host_feat (const uint32_t cpuid,const char *name, +const uint32_t mask) { -int i; - -for (i =0 ; i <32 ; ++i) -if (1 << i & mask) { -fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" -" flag '%s' [0x%08x]\n" , - f->cpuid >>16 , f->cpuid &0xffff , - f->flag_names[i] ? f->flag_names[i] :"[reserved]" , mask); -break ; - } -return 0 ; +fprintf (stderr,"warning: host cpuid %04x_%04x lacks requested" +" flag '%s' [0x%08x]\n" , cpuid >>16 , cpuid &0xffff , + name ? name :"[reserved]" , mask); }/* best effort attempt to inform user requested cpu flags aren't making
@@ -1282,28 +1275,49 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)*/ static int check_features_against_host (X86CPU *cpu) { +const DeviceClass *dc =DEVICE_CLASS (object_get_class (OBJECT (cpu)));CPUX86State *env = &cpu->env;x86_def_t host_def;uint32_t mask; -int rv, i; -struct model_features_t ft[] = { - {&env->cpuid_features, &host_def.features, - ~0 , feature_name,0x00000000 }, - {&env->cpuid_ext_features, &host_def.ext_features, - ~CPUID_EXT_HYPERVISOR , ext_feature_name,0x00000001 }, - {&env->cpuid_ext2_features, &host_def.ext2_features, - ~PPRO_FEATURES , ext2_feature_name,0x80000000 }, - {&env->cpuid_ext3_features, &host_def.ext3_features, - ~CPUID_EXT3_SVM , ext3_feature_name,0x80000001 }}; +int rv =0 , bit; +const Property *prop;cpu_x86_fill_host (&host_def); -for (rv =0 , i =0 ; i <ARRAY_SIZE (ft); ++i) -for (mask =1 ; mask; mask <<=1 ) -if (ft[i].check_feat & mask && *ft[i].guest_feat & mask && - !(*ft[i].host_feat & mask)) { -unavailable_host_feature (&ft[i], mask); - rv =1 ; - } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (env->cpuid_features & mask && !(host_def.features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc,X86CPU , + env.cpuid_features, bit); +unavailable_host_feat (0x00000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT_HYPERVISOR & env->cpuid_ext_features & mask && + !(host_def.ext_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc,X86CPU , + env.cpuid_ext_features, bit); +unavailable_host_feat (0x00000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~PPRO_FEATURES & env->cpuid_ext2_features & mask && + !(host_def.ext2_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc,X86CPU , + env.cpuid_ext2_features, bit); +unavailable_host_feat (0x80000000 , prop ? prop->name :NULL , mask); + rv =1 ; + } + } +for (bit =0 , mask =1 ; mask; mask <<=1 , bit++) { +if (~CPUID_EXT3_SVM & env->cpuid_ext3_features & mask && + !(host_def.ext3_features & mask)) { + prop =QDEV_FIND_PROP_FROM_BIT (dc,X86CPU , + env.cpuid_ext3_features, bit); +unavailable_host_feat (0x80000001 , prop ? prop->name :NULL , mask); + rv =1 ; + } + }return rv; }
Signature · 1 line
1.7.11.7
PATCH v5 36/37 target-i386: use static properties to list CPUID features
In reply to Igor Mammedovconvert x86_cpu_list() to use QDEV_FIND_PROP_FROM_BIT() for getting CPUID feature name.
In addition since x86_cpu_list() was the last user of *feature_name arrays, clean them up.
--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)
target-i386/cpu.c +20 -86
@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD. -*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" , -NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , -NULL /* fxsr */ ,"fxsr_opt|ffxsr" ,"pdpe1gb" /* AMD Page1GB */ ,"rdtscp" , -}; -static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)
@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext3_features); }CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp)
Signature · 1 line
1.7.11.7
PATCH v2 1/1 target-i386: use static properties to list CPUID features
convert x86_cpu_list() to use QDEV_FIND_PROP_FROM_BIT() for getting CPUID feature name.
In addition since x86_cpu_list() was the last user of *feature_name arrays, clean them up.
---
v2:
* fix x86_cpu_list(), use X86CPU as base to count offset correctly
* Do not forget to print 0 bit
--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)
target-i386/cpu.c +20 -86
@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD. -*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" , -NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , -NULL /* fxsr */ ,"fxsr_opt|ffxsr" ,"pdpe1gb" /* AMD Page1GB */ ,"rdtscp" , -}; -static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)
@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i >= 0; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext3_features); }CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp)
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH v2] target-i386: use static properties to list CPUID features
Quoted 132 lines · Igor Mammedov
convert
x86_cpu_list()to useQDEV_FIND_PROP_FROM_BIT()for getting CPUID feature name.
In addition sincex86_cpu_list()was the last user of*feature_namearrays, clean them up.Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fixx86_cpu_list(), use X86CPU as base to count offset correctly
* Do not forget to print 0 bit--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)target-i386/cpu.c +16
-80@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD. -*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" , -NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , -NULL /* fxsr */ ,"fxsr_opt|ffxsr" ,"pdpe1gb" /* AMD Page1GB */ ,"rdtscp" , -}; -static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i >= 0; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf);
target-i386/cpu.c void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 1483
Quoted 10 lines
target-i386/cpu.c +4
-6-listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext3_features);
Do we really need to filter the property list and list only the ones that correspond to feature bits in the X86CPU struct?
I mean: the specific X86CPU struct field where the CPU property bit is being stored isn't part of the interface. For external code, all that matters are the property names/types, the struct fields/offsets are internal implementation details.
IMO we can simply list all recognized X86CPU properties, or (if listing all the properties is too much) list all the CPU properties that start with "f-".
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v2] target-i386: use static properties to list CPUID features
Quoted 147 lines · On Tue, 23 Oct 2012 11:51:49 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 132 lines · Igor Mammedov
convert
x86_cpu_list()to useQDEV_FIND_PROP_FROM_BIT()for getting CPUID feature name.
In addition sincex86_cpu_list()was the last user of*feature_namearrays, clean them up.Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fixx86_cpu_list(), use X86CPU as base to count offset correctly
* Do not forget to print 0 bit--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)target-i386/cpu.c +16
-80@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD. -*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" , -NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , -NULL /* fxsr */ ,"fxsr_opt|ffxsr" ,"pdpe1gb" /* AMD Page1GB */ ,"rdtscp" , -}; -static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i >= 0; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf);target-i386/cpu.c void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 1483
Quoted 10 lines
target-i386/cpu.c +4
-6-listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU ,X86CPU , env.cpuid_ext3_features);Do we really need to filter the property list and list only the ones that correspond to feature bits in the X86CPU struct?
Quoted 8 lines
I mean: the specific X86CPU struct field where the CPU property bit is being stored isn't part of the interface. For external code, all that matters are the property names/types, the struct fields/offsets are internal implementation details.
IMO we can simply list all recognized X86CPU properties, or (if listing all the properties is too much) list all the CPU properties that start with "f-".
Probably "f-" will be better because it won't surprise users who expect only CPUID feature flags that was so far printed here.
I'll do it for the next respin.
Quoted 4 lines
Signature · 2 lines
-- Eduardo
Signature · 2 lines
Regards, Igor
Re: [Qemu-devel] [PATCH 36/37] target-i386: use static properties to list CPUID features
In reply to Igor MammedovTurns out that patch #32 is the one that causes the command line:
./x86_64-softmmu/qemu-system-x86_64 -cpu 486,+fpu,+vme,+de,+pse,+tsc,+msr,+pae,+mce,+cx8,+apic,+sep,+mtrr,+pge,+mca,+cmov,+pat,+pse36,+pn,+clflush,+ds,+acpi,+mmx,+fxsr,+sse,+sse2,+ss,+ht,+tm,+ia64,+pbe,+pni,+sse3,+pclmulqdq,+pclmuldq,+dtes64,+monitor,+ds_cpl,+vmx,+smx,+est,+tm2,+ssse3,+cid,+fma,+cx16,+xtpr,+pdcm,+pcid,+dca,+sse4.1,+sse4.2,+sse4_1,+sse4_2,+x2apic,+movbe,+popcnt,+tsc-deadline,+aes,+xsave,+osxsave,+avx,+hypervisor,+syscall,+nx,+xd,+mmxext,+fxsr_opt,+ffxsr,+pdpe1gb,+rdtscp,+lahf_lm,+cmp_legacy,+svm,+extapic,+cr8legacy,+abm,+sse4a,+misalignsse,+3dnowprefetch,+osvw,+ibs,+xop,+skinit,+wdt,+fma4,+cvt16,+nodeid_msr,+kvmclock1,+kvm_nopiodelay,+kvm_mmu,+kvmclock2,+kvm_asyncpf,+kvm_steal_tm,+kvm_pv_eoi,+kvmclock_stable,+npt,+lbrv,+svm_lock,+nrip_save,+tsc_scale,+vmcb_clean,+flushbyasid,+decodeassists,+pause_filter,+pfthreshold,+smep,+smap,family=6,model=23,stepping=10,level=13,xlevel=0x80000008,vendor="GenuineIntel",model-id="Intel(R) Core(TM)2 Quad CPU Q9650 @ 3.00GHz",+pbe,+tm,+ht,+ss,+sse2,+sse,+fxsr,+mmx,+acpi,+ds,+clflush,+pse36,+pat,+cmov,+mca,+pge,+mtrr,+sep,+apic,+cx8,+mce,+pae,+msr,+tsc,+pse,+de,+vme,+fpu,+osxsave,+xsave,+sse4_1,+pdcm,+xtpr,+cx16,+ssse3,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+sse3,+nx,+lahf_lm ~/qemu-img/CentOS5-32.raw -cdrom /isos/iso/centos/i386/CentOS-5.3-i386-bin-DVD.iso -machine pc,accel=kvm -m 1024 -monitor stdio
to stop allowing 64bit code to run. However this patch has the key info (see below).
Quoted 46 lines · Igor Mammedov
convert
x86_cpu_list()to useQDEV_FIND_PROP_FROM_BIT()for getting CPUID feature name.
In addition sincex86_cpu_list()was the last user of*feature_namearrays, clean them up.Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)target-i386/cpu.c +0
-28@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD.
target-i386/cpu.c line 78
Quoted 10 lines
target-i386/cpu.c +0
-10-*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" , -NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , -NULL /* fxsr */ ,"fxsr_opt|ffxsr" ,"pdpe1gb" /* AMD Page1GB */ ,"rdtscp" , -};
This array does not have 32 entries. And at least on my test machine "+lahf_lm" sets ext2_feature bit 29 (and also ext3_feature bit 0).
From http://www.sandpile.org/x86/cpuid.htm#level_8000_0001h
bit 29 (LM) AMD64/EM64T, Long Mode
bit 29 (LM) AMD64/EM64T, Long Mode
(And the next 2 bits are defined as well:
bit 30 (3DNow!+) extended 3DNow!
bit 31 (3DNow!) 3DNow!
).
Since master has this bug (feature?), I feel that access to ext2 bit 29 is needed ("f-lm" ?)
-Don Slutz
Quoted 85 lines
target-i386/cpu.c +20
-48-static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext3_features); }CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp)
Re: [Qemu-devel] [PATCH 36/37] target-i386: use static properties to list CPUID features
Quoted 62 lines · Don Slutz
Turns out that patch #32 is the one that causes the command line:
./x86_64-softmmu/qemu-system-x86_64 -cpu 486,+fpu,+vme,+de,+pse,+tsc,+msr,+pae,+mce,+cx8,+apic,+sep,+mtrr,+pge,+mca,+cmov,+pat,+pse36,+pn,+clflush,+ds,+acpi,+mmx,+fxsr,+sse,+sse2,+ss,+ht,+tm,+ia64,+pbe,+pni,+sse3,+pclmulqdq,+pclmuldq,+dtes64,+monitor,+ds_cpl,+vmx,+smx,+est,+tm2,+ssse3,+cid,+fma,+cx16,+xtpr,+pdcm,+pcid,+dca,+sse4.1,+sse4.2,+sse4_1,+sse4_2,+x2apic,+movbe,+popcnt,+tsc-deadline,+aes,+xsave,+osxsave,+avx,+hypervisor,+syscall,+nx,+xd,+mmxext,+fxsr_opt,+ffxsr,+pdpe1gb,+rdtscp,+lahf_lm,+cmp_legacy,+svm,+extapic,+cr8legacy,+abm,+sse4a,+misalignsse,+3dnowprefetch,+osvw,+ibs,+xop,+skinit,+wdt,+fma4,+cvt16,+nodeid_msr,+kvmclock1,+kvm_nopiodelay,+kvm_mmu,+kvmclock2,+kvm_asyncpf,+kvm_steal_tm,+kvm_pv_eoi,+kvmclock_stable,+npt,+lbrv,+svm_lock,+nrip_save,+tsc_scale,+vmcb_clean,+flushbyasid,+decodeassists,+pause_filter,+pfthreshold,+smep,+smap,family=6,model=23,stepping=10,level=13,xlevel=0x80000008,vendor="GenuineIntel",model-id="Intel(R)
Core(TM)2 Quad CPU Q9650 @ 3.00GHz",+pbe,+tm,+ht,+ss,+sse2,+sse,+fxsr,+mmx,+acpi,+ds,+clflush,+pse36,+pat,+cmov,+mca,+pge,+mtrr,+sep,+apic,+cx8,+mce,+pae,+msr,+tsc,+pse,+de,+vme,+fpu,+osxsave,+xsave,+sse4_1,+pdcm,+xtpr,+cx16,+ssse3,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+sse3,+nx,+lahf_lm
~/qemu-img/CentOS5-32.raw -cdrom
/isos/iso/centos/i386/CentOS-5.3-i386-bin-DVD.iso -machine
pc,accel=kvm -m 1024 -monitor stdioto stop allowing 64bit code to run. However this patch has the key info (see below).
Quoted 50 lines · Igor Mammedov
convert
x86_cpu_list()to useQDEV_FIND_PROP_FROM_BIT()for getting CPUID feature name.
In addition sincex86_cpu_list()was the last user of*feature_namearrays, clean them up.Signed-off-by Igor Mammedov <[email protected]>--- target-i386/cpu.c | 106 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 86 deletions(-)target-i386/cpu.c +0
-33@@ -38,55 +38,6 @@#include <linux/kvm_para.h> #endif -/* feature flags taken from "Intel Processor Identification and the CPUID -* Instruction" and AMD's "CPUID Specification". In cases of disagreement -* between feature naming conventions, aliases may be added. -*/ -static const char *feature_name[] = { -"fpu" ,"vme" ,"de" ,"pse" , -"tsc" ,"msr" ,"pae" ,"mce" , -"cx8" ,"apic" ,NULL ,"sep" , -"mtrr" ,"pge" ,"mca" ,"cmov" , -"pat" ,"pse36" ,"pn" /* Intel psn */ ,"clflush" /* Intel clfsh */ , -NULL ,"ds" /* Intel dts */ ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" , -"ht" /* Intel htt */ ,"tm" ,"ia64" ,"pbe" , -}; -static const char *ext_feature_name[] = { -"pni|sse3" /* Intel,AMD sse3 */ ,"pclmulqdq|pclmuldq" ,"dtes64" ,"monitor" , -"ds_cpl" ,"vmx" ,"smx" ,"est" , -"tm2" ,"ssse3" ,"cid" ,NULL , -"fma" ,"cx16" ,"xtpr" ,"pdcm" , -NULL ,"pcid" ,"dca" ,"sse4.1|sse4_1" , -"sse4.2|sse4_2" ,"x2apic" ,"movbe" ,"popcnt" , -"tsc-deadline" ,"aes" ,"xsave" ,"osxsave" , -"avx" ,NULL ,NULL ,"hypervisor" , -}; -/* Feature names that are already defined on feature_name[] but are set on -* CPUID[8000_0001].EDX on AMD CPUs don't have their names on -* ext2_feature_name[]. They are copied automatically to cpuid_ext2_features -* if and only if CPU vendor is AMD. -*/ -static const char *ext2_feature_name[] = { -NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , -NULL /* tsc */ ,NULL /* msr */ ,NULL /* pae */ ,NULL /* mce */ , -NULL /* cx8 */ /* AMD CMPXCHG8B */ ,NULL /* apic */ ,NULL ,"syscall" ,
Quoted 8 lines
target-i386/cpu.c line 78
Quoted 5 lines
target-i386/cpu.c +0
-5-NULL /* mtrr */ ,NULL /* pge */ ,NULL /* mca */ ,NULL /* cmov */ , -NULL /* pat */ ,NULL /* pse36 */ ,NULL ,NULL /* Linux mp */ , -"nx|xd" ,NULL ,"mmxext" ,NULL /* mmx */ , - NULL /* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp", -};This array does not have 32 entries. And at least on my test machine "+lahf_lm" sets
ext2_featurebit 29 (and alsoext3_featurebit 0).
Ouch. I broke the code on commit 3b671a40cab2404bc63e57db8cd3afa4ec70bfab. I will send a fix ASAP.
Quoted 8 lines
From http://www.sandpile.org/x86/cpuid.htm#level_8000_0001h
bit 29 (LM) AMD64/EM64T, Long Mode
bit 29 (LM) AMD64/EM64T, Long Mode
Quoted 7 lines
(And the next 2 bits are defined as well:
bit 30 (3DNow!+) extended 3DNow!
bit 31 (3DNow!) 3DNow!
).Since master has this bug (feature?), I feel that access to ext2 bit 29 is needed ("f-lm" ?)
The 1.2.0 code had the following line:
NULL, "lm|i64", "3dnowext", "3dnow",
We just need to re-add it (and add the corresponding properties when converting it to static properties).
Quoted 86 lines
-Don Slutz
Quoted 82 lines
target-i386/cpu.c +20
-48-static const char *ext3_feature_name[] = { -"lahf_lm" /* AMD LahfSahf */ ,"cmp_legacy" ,"svm" ,"extapic" /* AMD ExtApicSpace */ , -"cr8legacy" /* AMD AltMovCr8 */ ,"abm" ,"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,"xop" , -"skinit" ,"wdt" ,NULL ,NULL , -"fma4" ,NULL ,"cvt16" ,"nodeid_msr" , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , -}; -#if defined(CONFIG_KVM )static void x86_cpu_get_kvmclock (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp)@@ -1495,35 +1446,22 @@ error:return -1 ; } -/* generate a composite string into buf of all cpuid names in featureset -* selected by fbits. indicate truncation at bufsize in the event of overflow. -* if flags, suppress names undefined in featureset. -*/ -static void listflags (char *buf,int bufsize,uint32_t fbits, -const char **featureset,uint32_t flags) -{ -const char **p = &featureset[31 ]; -char *q, *b, bit; -int nc; - - b =4 <= bufsize ? buf + (bufsize -=3 ) -1 :NULL ; - *buf ='\0' ; -for (q = buf, bit =31 ; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit) -if (fbits &1 << bit && (*p || !flags)) { -if (*p) - nc =snprintf (q, bufsize,"%s%s" , q == buf ?"" :" " , *p); -else - nc =snprintf (q, bufsize,"%s[%d]" , q == buf ?"" :" " , bit); -if (bufsize <= nc) { -if (b) { -memcpy (b,"..." ,sizeof ("..." )); - } -return ; - } - q += nc; - bufsize -= nc; - } -} +#define LIST_FLAGS (_typename, _state, _field) \ + do { \ + int i; \ + const Property *prop; \ + const DeviceClass *dc; \ + dc = DEVICE_CLASS(object_class_by_name((_typename))); \ + (*cpu_fprintf)(f, " "); \ + for (i = 31; i; --i) { \ + prop = QDEV_FIND_PROP_FROM_BIT(dc, _state, _field, i); \ + if (prop) { \ +/* for compatibility do not print f- prefix */ \ + (*cpu_fprintf)(f," %s" , prop->name +2 ); \ + } \ + } \ + (*cpu_fprintf)(f,"\n" ); \ + } while (0)/* generate CPU information. */ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)@@ -1539,14 +1477,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) (*cpu_fprintf)(f,"x86 %16s\n" ,"[host]" ); } (*cpu_fprintf)(f,"\nRecognized CPUID flags:\n" ); -listflags (buf,sizeof (buf), (uint32_t )~0 , feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext2_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); -listflags (buf,sizeof (buf), (uint32_t )~0 , ext3_feature_name,1 ); - (*cpu_fprintf)(f," %s\n" , buf); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext2_features); +LIST_FLAGS (TYPE_X86_CPU , CPUX86State, cpuid_ext3_features); }CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp)
Signature · 1 line
Eduardo
PATCH v5 37/37 target-i386: cleanup cpu_x86_find_by_name(), only fill x86_def_t in it
In reply to Igor MammedovDo in cpu_x86_find_by_name() only what name implies. i.e. leave only cpudef search and copy/fill passed in x86_def_t structure.
and move out of it cpu_model parsing and CPU initializing into cpu_x86_register(). Plus add hints to where blocks should go when cpu_x86_register() is disbanded.
--- target-i386/cpu.c | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-)
target-i386/cpu.c +21 -29
@@ -1409,41 +1409,20 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, const char *cpu_model, Error **errp) { x86_def_t *def; -QDict *features =NULL ; -char *name =NULL ; - -compat_normalize_cpu_model (cpu_model, &name, &features, errp); -if (error_is_set (errp)) { - goto error; - } -for (def = x86_defs; def; def = def->next) -if (name && !strcmp (name, def->name)) +if (!strcmp (cpu_model, def->name)) {break ; -if (kvm_enabled () && name &&strcmp (name,"host" ) ==0 ) { + } +if (kvm_enabled () &&strcmp (cpu_model,"host" ) ==0 ) {cpu_x86_fill_host (x86_cpu_def); }else if (!def) { - goto error; +error_setg (errp,"CPU device '%s' not found" , cpu_model); +return -1 ; }else {memcpy (x86_cpu_def, def,sizeof (*def)); } -cpu_x86_set_props (cpu, features, errp); -if (error_is_set (errp)) { - goto error; - } - -g_free (name); -QDECREF (features);return 0 ; - -error: -g_free (name); -QDECREF (features); -if (!error_is_set (errp)) { -error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); - } -return -1 ; }#define LIST_FLAGS (_typename, _state, _field) \
@@ -1508,16 +1487,29 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) {x86_def_t def1, *def = &def1;Error *error =NULL ; +QDict *features =NULL ; +char *name =NULL ; -memset (def,0 ,sizeof (*def)); - -if (cpu_x86_find_by_name (cpu, def, cpu_model, &error) <0 ) { +/* for CPU subclasses should go into cpu_x86_init() before object_new() */ +compat_normalize_cpu_model (cpu_model, &name, &features, &error); +if (error) { goto out; } +/* this block should be replaced by CPU subclasses */ +memset (def,0 ,sizeof (*def)); +if (cpu_x86_find_by_name (cpu, def, name, &error) <0 ) { + goto out; + }cpudef_2_x86_cpu (cpu, def, &error); +/* for CPU subclasses should go between object_new() and +* x86_cpu_realize() */ +cpu_x86_set_props (cpu, features, &error); + out: +g_free (name); +QDECREF (features);if (error) {fprintf (stderr,"%s\n" ,error_get_pretty (error));error_free (error);
Signature · 1 line
1.7.11.7
Quoted 10 lines · Igor Mammedov
v5:
- Use static properties instead of dynamic ones
- Compile in KVM CPUID features only ifCONFIG_KVMis defined
- Add "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID feature names
- Some qdev hacking to:
- allow iterate over Property[] before object instance exists
- find a static bit property definition by specifying bit number and field's offset
- Replaceerror_set()witherror_setg()where patches touch it.
Quoted 2 lines
git tree for testing:
https://github.com/imammedo/qemu/tree/x86-cpu-properties.v5
This tree is failing to build cleanly:
CC microblaze-softmmu/hw/microblaze/../microblaze_boot.o
In file included from /home/don/qemu/include/qemu/cpu.h:23,
from /home/don/qemu/target-microblaze/cpu-qom.h:23,
from /home/don/qemu/target-microblaze/cpu.h:273,
from /home/don/qemu/qemu-common.h:128,
from /home/don/qemu/qlist.h:18,
from /home/don/qemu/qdict.h:17,
from /home/don/qemu/qemu-option.h:32,
from /home/don/qemu/hw/microblaze/../microblaze_boot.c:27:/home/don/qemu/hw/qdev-core.h:68: error: expected specifier-qualifier-list before 'QemuOpts' make[1]: *** [hw/microblaze/../microblaze_boot.o] Error 1
make: *** [subdir-microblaze-softmmu] Error 2
bisected to:
commit 2652c28759bc658fee228d4d329d9d514683b261
Which looks to be: http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02786.html
-Don Slutz
Quoted 67 lines
Depends on "CPU as Device" series:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02776.htmlReference to a previous version:
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg00210.htmlIgor Mammedov (37):
target-i386: return Error fromcpu_x86_find_by_name()
target-i386:cpu_x86_register(): report error from property setter
target-i386: ifx86_cpu_realize()failed report error and do cleanup
target-i386: filter out not TCG features if running without kvm at
realize time
target-i386: move out CPU features initialization in separate func add visitor for parsing hz[KMG] input string
target-i386: usevisit_type_hzto parsetsc_freqproperty value
target-i386: define static properties for cpuid features
qdev: exportqdev_prop_find()and allow it to be used with
DeviceClass instead of Object
target-i386: parsecpu_modelstring into set of stringified
properties
target-i386: introduce vendor-override static property
target-i386: convert "xlevel" to static property
target-i386: convert "level" to static property
target-i386: postponecpuid_levelupdate to realize time
target-i386: set default value of "hypervisor" feature using static
property
target-i386: set kvm CPUID default feature values using static
properties
target-i386: make 'f-kvmclock' compatible with legacy behaviour
target-i386: add stubs for
hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
qdev: addDEFINE_ABSTRACT_PROP()helper
target-i386: convert 'hv_spinlocks' to static property
target-i386: convert 'hv_relaxed' to static property
target-i386: convert 'hv_vapic' to static property
target-i386: convert 'check' and 'enforce' to static properties
target-i386: use define for cpuid vendor string size
target-i386: replaceuint32_tvendor fields by vendor string inx86_def_ttarget-i386: convert "vendor" property to static property
target-i386: convert "tsc-frequency" to static property
target-i386: convert "model-id" to static property
target-i386: convert "stepping" to static property
target-i386: convert "model" to static property
target-i386: convert "family" to static property
target-i386: use static properties for setting cpuid features
qdev:QDEV_PROP_FOREACHandQDEV_CLASS_FOREACH
qdev: introduceQDEV_FIND_PROP_FROM_BITandqdev_prop_find_bit()
target-i386: use static properties incheck_features_against_host()
to print CPUID feature names
target-i386: use static properties to list CPUID features
target-i386: cleanupcpu_x86_find_by_name(), only fillx86_def_tin
ithw/qdev-properties.h | 26 +- qapi/qapi-visit-core.c | 11 + qapi/qapi-visit-core.h | 2 + qapi/string-input-visitor.c | 22 + qom/qdev-core.c | 10 +- qom/qdev-properties.c | 50 +- target-i386/cpu.c | 1667 +++++++++++++++++++++++-------------------- target-i386/cpu.h | 12 +- target-i386/helper.c | 9 +- target-i386/hyperv.h | 9 +- 10 files changed, 992 insertions(+), 826 deletions(-)
Quoted 11 lines · On Tue, 23 Oct 2012 09:32:53 -0400 Don Slutz <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
v5:
- Use static properties instead of dynamic ones
- Compile in KVM CPUID features only ifCONFIG_KVMis defined
- Add "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID feature names
- Some qdev hacking to:
- allow iterate over Property[] before object instance exists
- find a static bit property definition by specifying bit number and field's offset
- Replaceerror_set()witherror_setg()where patches touch it.
Quoted 3 lines
Quoted 2 lines
git tree for testing:
https://github.com/imammedo/qemu/tree/x86-cpu-properties.v5This tree is failing to build cleanly:
Since series targeted to target-i386, I haven't tested it with build all. Thanks for finding bug in CPU as DeviceState series though.
Quoted 7 lines
CC
microblaze-softmmu/hw/microblaze/../microblaze_boot.o
In file included from/home/don/qemu/include/qemu/cpu.h:23,from /home/don/qemu/target-microblaze/cpu-qom.h:23, from /home/don/qemu/target-microblaze/cpu.h:273, from /home/don/qemu/qemu-common.h:128, from /home/don/qemu/qlist.h:18,
Looks like circular header dependency strikes again ^^^,
I've had patch that fixes qlist.h which doesn't need qemu-common.h, when I experimented with inlining APIC in X86CPU. Let's me dig it out, it should help.
Quoted 83 lines
from /home/don/qemu/qdict.h:17, from /home/don/qemu/qemu-option.h:32, from /home/don/qemu/hw/microblaze/../microblaze_boot.c:27:
/home/don/qemu/hw/qdev-core.h:68: error: expected specifier-qualifier-list before 'QemuOpts' make[1]: *** [hw/microblaze/../microblaze_boot.o] Error 1
make: *** [subdir-microblaze-softmmu] Error 2bisected to:
commit2652c28759bc658fee228d4d329d9d514683b261Which looks to be:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02786.html-Don Slutz
Quoted 67 lines
Depends on "CPU as Device" series:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02776.htmlReference to a previous version:
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg00210.htmlIgor Mammedov (37):
target-i386: return Error fromcpu_x86_find_by_name()
target-i386:cpu_x86_register(): report error from property setter
target-i386: ifx86_cpu_realize()failed report error and do cleanup
target-i386: filter out not TCG features if running without kvm at
realize time
target-i386: move out CPU features initialization in separate func add visitor for parsing hz[KMG] input string
target-i386: usevisit_type_hzto parsetsc_freqproperty value
target-i386: define static properties for cpuid features
qdev: exportqdev_prop_find()and allow it to be used with
DeviceClass instead of Object
target-i386: parsecpu_modelstring into set of stringified
properties
target-i386: introduce vendor-override static property
target-i386: convert "xlevel" to static property
target-i386: convert "level" to static property
target-i386: postponecpuid_levelupdate to realize time
target-i386: set default value of "hypervisor" feature using static
property
target-i386: set kvm CPUID default feature values using static
properties
target-i386: make 'f-kvmclock' compatible with legacy behaviour
target-i386: add stubs for
hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
qdev: addDEFINE_ABSTRACT_PROP()helper
target-i386: convert 'hv_spinlocks' to static property
target-i386: convert 'hv_relaxed' to static property
target-i386: convert 'hv_vapic' to static property
target-i386: convert 'check' and 'enforce' to static properties
target-i386: use define for cpuid vendor string size
target-i386: replaceuint32_tvendor fields by vendor string inx86_def_ttarget-i386: convert "vendor" property to static property
target-i386: convert "tsc-frequency" to static property
target-i386: convert "model-id" to static property
target-i386: convert "stepping" to static property
target-i386: convert "model" to static property
target-i386: convert "family" to static property
target-i386: use static properties for setting cpuid features
qdev:QDEV_PROP_FOREACHandQDEV_CLASS_FOREACH
qdev: introduceQDEV_FIND_PROP_FROM_BITandqdev_prop_find_bit()
target-i386: use static properties incheck_features_against_host()
to print CPUID feature names
target-i386: use static properties to list CPUID features
target-i386: cleanupcpu_x86_find_by_name(), only fillx86_def_tin
ithw/qdev-properties.h | 26 +- qapi/qapi-visit-core.c | 11 + qapi/qapi-visit-core.h | 2 + qapi/string-input-visitor.c | 22 + qom/qdev-core.c | 10 +- qom/qdev-properties.c | 50 +- target-i386/cpu.c | 1667 +++++++++++++++++++++++-------------------- target-i386/cpu.h | 12 +- target-i386/helper.c | 9 +- target-i386/hyperv.h | 9 +- 10 files changed, 992 insertions(+), 826 deletions(-)
Signature · 2 lines
Regards, Igor
Quoted 26 lines · Igor Mammedov
Quoted 11 lines · On Tue, 23 Oct 2012 09:32:53 -0400 Don Slutz <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
v5:
- Use static properties instead of dynamic ones
- Compile in KVM CPUID features only ifCONFIG_KVMis defined
- Add "f-kvm_steal_tm" and "f-kvmclock_stable" CPUID feature names
- Some qdev hacking to:
- allow iterate over Property[] before object instance exists
- find a static bit property definition by specifying bit number and field's offset
- Replaceerror_set()witherror_setg()where patches touch it.Quoted 3 lines
Quoted 2 lines
git tree for testing:
https://github.com/imammedo/qemu/tree/x86-cpu-properties.v5This tree is failing to build cleanly:
Since series targeted to target-i386, I haven't tested it with build all. Thanks for finding bug in CPU as DeviceState series though.
Quoted 7 lines
CC
microblaze-softmmu/hw/microblaze/../microblaze_boot.o
In file included from/home/don/qemu/include/qemu/cpu.h:23,from /home/don/qemu/target-microblaze/cpu-qom.h:23, from /home/don/qemu/target-microblaze/cpu.h:273, from /home/don/qemu/qemu-common.h:128, from /home/don/qemu/qlist.h:18,
Quoted 3 lines
Looks like circular header dependency strikes again ^^^,
I've had patch that fixesqlist.hwhich doesn't needqemu-common.h, when I experimented with inlining APIC in X86CPU. Let's me dig it out, it should help.
I have fixed this on v5 of the CPU DeviceState series. I ended up having to fix header dependencies of multiple files, just to be able to safely remove qemu-common.h from qlist.h.
Quoted 89 lines
Quoted 84 lines
from /home/don/qemu/qdict.h:17, from /home/don/qemu/qemu-option.h:32, from /home/don/qemu/hw/microblaze/../microblaze_boot.c:27:
/home/don/qemu/hw/qdev-core.h:68: error: expected specifier-qualifier-list before 'QemuOpts' make[1]: *** [hw/microblaze/../microblaze_boot.o] Error 1
make: *** [subdir-microblaze-softmmu] Error 2bisected to:
commit2652c28759bc658fee228d4d329d9d514683b261Which looks to be:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02786.html-Don Slutz
Quoted 67 lines
Depends on "CPU as Device" series:
http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02776.htmlReference to a previous version:
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg00210.htmlIgor Mammedov (37):
target-i386: return Error fromcpu_x86_find_by_name()
target-i386:cpu_x86_register(): report error from property setter
target-i386: ifx86_cpu_realize()failed report error and do cleanup
target-i386: filter out not TCG features if running without kvm at
realize time
target-i386: move out CPU features initialization in separate func add visitor for parsing hz[KMG] input string
target-i386: usevisit_type_hzto parsetsc_freqproperty value
target-i386: define static properties for cpuid features
qdev: exportqdev_prop_find()and allow it to be used with
DeviceClass instead of Object
target-i386: parsecpu_modelstring into set of stringified
properties
target-i386: introduce vendor-override static property
target-i386: convert "xlevel" to static property
target-i386: convert "level" to static property
target-i386: postponecpuid_levelupdate to realize time
target-i386: set default value of "hypervisor" feature using static
property
target-i386: set kvm CPUID default feature values using static
properties
target-i386: make 'f-kvmclock' compatible with legacy behaviour
target-i386: add stubs for
hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)()
qdev: addDEFINE_ABSTRACT_PROP()helper
target-i386: convert 'hv_spinlocks' to static property
target-i386: convert 'hv_relaxed' to static property
target-i386: convert 'hv_vapic' to static property
target-i386: convert 'check' and 'enforce' to static properties
target-i386: use define for cpuid vendor string size
target-i386: replaceuint32_tvendor fields by vendor string inx86_def_ttarget-i386: convert "vendor" property to static property
target-i386: convert "tsc-frequency" to static property
target-i386: convert "model-id" to static property
target-i386: convert "stepping" to static property
target-i386: convert "model" to static property
target-i386: convert "family" to static property
target-i386: use static properties for setting cpuid features
qdev:QDEV_PROP_FOREACHandQDEV_CLASS_FOREACH
qdev: introduceQDEV_FIND_PROP_FROM_BITandqdev_prop_find_bit()
target-i386: use static properties incheck_features_against_host()
to print CPUID feature names
target-i386: use static properties to list CPUID features
target-i386: cleanupcpu_x86_find_by_name(), only fillx86_def_tin
ithw/qdev-properties.h | 26 +- qapi/qapi-visit-core.c | 11 + qapi/qapi-visit-core.h | 2 + qapi/string-input-visitor.c | 22 + qom/qdev-core.c | 10 +- qom/qdev-properties.c | 50 +- target-i386/cpu.c | 1667 +++++++++++++++++++++++-------------------- target-i386/cpu.h | 12 +- target-i386/helper.c | 9 +- target-i386/hyperv.h | 9 +- 10 files changed, 992 insertions(+), 826 deletions(-)Signature · 2 lines
Regards, Igor
Signature · 1 line
Eduardo