Patchwork [17/37] target-i386: make 'f-kvmclock' compatible with legacy behaviour

login
register
mail settings
Submitter Igor Mammedov
Date Oct. 22, 2012, 3:03 p.m.
Message ID <1350918203-25198-18-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/193218/
State New
Headers show

Comments

Igor Mammedov - Oct. 22, 2012, 3:03 p.m.
It'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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
Don Slutz - Oct. 23, 2012, 9:41 p.m.
On 10/22/12 11:03, Igor Mammedov wrote:
> It'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.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   target-i386/cpu.c | 39 ++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 407c5ce..9cdcae8 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -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),
>   #endif
>       DEFINE_PROP_BIT("f-npt", X86CPU, env.cpuid_svm_features,  0, false),
>       DEFINE_PROP_BIT("f-lbrv", X86CPU, env.cpuid_svm_features,  1, false),
Reviewed-by: Don Slutz <Don@CloudSwitch.com>

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 407c5ce..9cdcae8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -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),
 #endif
     DEFINE_PROP_BIT("f-npt", X86CPU, env.cpuid_svm_features,  0, false),
     DEFINE_PROP_BIT("f-lbrv", X86CPU, env.cpuid_svm_features,  1, false),