yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 6d78a7906b69054a4798b1b68548f59fec9e5da8 Mon Sep 17 00:00:00 2001
0a122b
From: Vadim Rozenfeld <vrozenfe@redhat.com>
0a122b
Date: Mon, 3 Mar 2014 12:09:13 +0100
0a122b
Subject: [PATCH 01/12] target-i386: Move hyperv_* static globals to X86CPU
0a122b
MIME-Version: 1.0
0a122b
Content-Type: text/plain; charset=UTF-8
0a122b
Content-Transfer-Encoding: 8bit
0a122b
0a122b
RH-Author: Vadim Rozenfeld <vrozenfe@redhat.com>
0a122b
Message-id: <1393848564-10511-2-git-send-email-vrozenfe@redhat.com>
0a122b
Patchwork-id: 57957
0a122b
O-Subject: [RHEL-7.0 qemu-kvm v4 PATCH 01/12] target-i386: Move hyperv_* static globals to X86CPU
0a122b
Bugzilla: 1004773
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Juan Quintela <quintela@redhat.com>
0a122b
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
0a122b
0a122b
From: Igor Mammedov <imammedo@redhat.com>
0a122b
0a122b
  since hyperv_* helper functions are used only in target-i386/kvm.c
0a122b
  move them there as static helpers
0a122b
0a122b
Requested-by: Eduardo Habkost <ehabkost@redhat.com>
0a122b
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Signed-off-by: Andreas Färber <afaerber@suse.de>
0a122b
(cherry picked from commit 92067bf4bfa144ea3967a9951808f5e587bdab18)
0a122b
0a122b
Conflicts:
0a122b
	target-i386/cpu.h
0a122b
	target-i386/kvm.c
0a122b
---
0a122b
 target-i386/Makefile.objs |  2 +-
0a122b
 target-i386/cpu-qom.h     |  4 +++
0a122b
 target-i386/cpu.c         | 16 ++++++++----
0a122b
 target-i386/cpu.h         |  4 +++
0a122b
 target-i386/hyperv.c      | 64 -----------------------------------------------
0a122b
 target-i386/hyperv.h      | 45 ---------------------------------
0a122b
 target-i386/kvm.c         | 36 ++++++++++++++++++--------
0a122b
 7 files changed, 46 insertions(+), 125 deletions(-)
0a122b
 delete mode 100644 target-i386/hyperv.c
0a122b
 delete mode 100644 target-i386/hyperv.h
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 target-i386/Makefile.objs |    2 +-
0a122b
 target-i386/cpu-qom.h     |    4 +++
0a122b
 target-i386/cpu.c         |   16 +++++++---
0a122b
 target-i386/cpu.h         |    4 +++
0a122b
 target-i386/hyperv.c      |   64 ---------------------------------------------
0a122b
 target-i386/hyperv.h      |   45 -------------------------------
0a122b
 target-i386/kvm.c         |   36 ++++++++++++++++++-------
0a122b
 7 files changed, 46 insertions(+), 125 deletions(-)
0a122b
 delete mode 100644 target-i386/hyperv.c
0a122b
 delete mode 100644 target-i386/hyperv.h
0a122b
0a122b
diff --git a/target-i386/Makefile.objs b/target-i386/Makefile.objs
0a122b
index c1d4f05..887dca7 100644
0a122b
--- a/target-i386/Makefile.objs
0a122b
+++ b/target-i386/Makefile.objs
0a122b
@@ -2,7 +2,7 @@ obj-y += translate.o helper.o cpu.o
0a122b
 obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o
0a122b
 obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o
0a122b
 obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o
0a122b
-obj-$(CONFIG_KVM) += kvm.o hyperv.o
0a122b
+obj-$(CONFIG_KVM) += kvm.o
0a122b
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
0a122b
 obj-$(CONFIG_LINUX_USER) += ioport-user.o
0a122b
 obj-$(CONFIG_BSD_USER) += ioport-user.o
0a122b
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
0a122b
index 12c7bea..ac56fec 100644
0a122b
--- a/target-i386/cpu-qom.h
0a122b
+++ b/target-i386/cpu-qom.h
0a122b
@@ -66,6 +66,10 @@ typedef struct X86CPU {
0a122b
 
0a122b
     CPUX86State env;
0a122b
 
0a122b
+    bool hyperv_vapic;
0a122b
+    bool hyperv_relaxed_timing;
0a122b
+    int hyperv_spinlock_attempts;
0a122b
+
0a122b
     /* Features that were filtered out because of missing host capabilities */
0a122b
     uint32_t filtered_features[FEATURE_WORDS];
0a122b
 
0a122b
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
0a122b
index 31ff568..826d8d6 100644
0a122b
--- a/target-i386/cpu.c
0a122b
+++ b/target-i386/cpu.c
0a122b
@@ -35,8 +35,6 @@
0a122b
 #include "qapi/visitor.h"
0a122b
 #include "sysemu/arch_init.h"
0a122b
 
0a122b
-#include "hyperv.h"
0a122b
-
0a122b
 #include "hw/hw.h"
0a122b
 #if defined(CONFIG_KVM)
0a122b
 #include <linux/kvm_para.h>
0a122b
@@ -1629,12 +1627,19 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
0a122b
                 object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
0a122b
             } else if (!strcmp(featurestr, "hv-spinlocks")) {
0a122b
                 char *err;
0a122b
+                const int min = 0xFFF;
0a122b
                 numvalue = strtoul(val, &err, 0);
0a122b
                 if (!*val || *err) {
0a122b
                     error_setg(errp, "bad numerical value %s", val);
0a122b
                     goto out;
0a122b
                 }
0a122b
-                hyperv_set_spinlock_retries(numvalue);
0a122b
+                if (numvalue < min) {
0a122b
+                    fprintf(stderr, "hv-spinlocks value shall always be >= 0x%x"
0a122b
+                            ", fixup will be removed in future versions\n",
0a122b
+                            min);
0a122b
+                    numvalue = min;
0a122b
+                }
0a122b
+                cpu->hyperv_spinlock_attempts = numvalue;
0a122b
             } else {
0a122b
                 error_setg(errp, "unrecognized feature %s", featurestr);
0a122b
                 goto out;
0a122b
@@ -1644,9 +1649,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
0a122b
         } else if (!strcmp(featurestr, "enforce")) {
0a122b
             check_cpuid = enforce_cpuid = 1;
0a122b
         } else if (!strcmp(featurestr, "hv_relaxed")) {
0a122b
-            hyperv_enable_relaxed_timing(true);
0a122b
+            cpu->hyperv_relaxed_timing = true;
0a122b
         } else if (!strcmp(featurestr, "hv_vapic")) {
0a122b
-            hyperv_enable_vapic_recommended(true);
0a122b
+            cpu->hyperv_vapic = true;
0a122b
         } else {
0a122b
             error_setg(errp, "feature string `%s' not in format (+feature|"
0a122b
                        "-feature|feature=xyz)", featurestr);
0a122b
@@ -2559,6 +2564,7 @@ static void x86_cpu_initfn(Object *obj)
0a122b
                         x86_cpu_get_feature_words,
0a122b
                         NULL, NULL, (void *)cpu->filtered_features, NULL);
0a122b
 
0a122b
+    cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
0a122b
     env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
0a122b
 
0a122b
     /* init various static tables used in TCG mode */
0a122b
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
0a122b
index 37ff264..4c4c9ff 100644
0a122b
--- a/target-i386/cpu.h
0a122b
+++ b/target-i386/cpu.h
0a122b
@@ -565,6 +565,10 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
0a122b
 #define CPUID_MWAIT_IBE     (1 << 1) /* Interrupts can exit capability */
0a122b
 #define CPUID_MWAIT_EMX     (1 << 0) /* enumeration supported */
0a122b
 
0a122b
+#ifndef HYPERV_SPINLOCK_NEVER_RETRY
0a122b
+#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
0a122b
+#endif
0a122b
+
0a122b
 #define EXCP00_DIVZ     0
0a122b
 #define EXCP01_DB       1
0a122b
 #define EXCP02_NMI      2
0a122b
diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c
0a122b
deleted file mode 100644
0a122b
index f284e99..0000000
0a122b
--- a/target-i386/hyperv.c
0a122b
+++ /dev/null
0a122b
@@ -1,64 +0,0 @@
0a122b
-/*
0a122b
- * QEMU Hyper-V support
0a122b
- *
0a122b
- * Copyright Red Hat, Inc. 2011
0a122b
- *
0a122b
- * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
0a122b
- *
0a122b
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
0a122b
- * See the COPYING file in the top-level directory.
0a122b
- *
0a122b
- */
0a122b
-
0a122b
-#include "hyperv.h"
0a122b
-
0a122b
-static bool hyperv_vapic;
0a122b
-static bool hyperv_relaxed_timing;
0a122b
-static int hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
0a122b
-
0a122b
-void hyperv_enable_vapic_recommended(bool val)
0a122b
-{
0a122b
-    hyperv_vapic = val;
0a122b
-}
0a122b
-
0a122b
-void hyperv_enable_relaxed_timing(bool val)
0a122b
-{
0a122b
-    hyperv_relaxed_timing = val;
0a122b
-}
0a122b
-
0a122b
-void hyperv_set_spinlock_retries(int val)
0a122b
-{
0a122b
-    hyperv_spinlock_attempts = val;
0a122b
-    if (hyperv_spinlock_attempts < 0xFFF) {
0a122b
-        hyperv_spinlock_attempts = 0xFFF;
0a122b
-    }
0a122b
-}
0a122b
-
0a122b
-bool hyperv_enabled(void)
0a122b
-{
0a122b
-    return hyperv_hypercall_available() || hyperv_relaxed_timing_enabled();
0a122b
-}
0a122b
-
0a122b
-bool hyperv_hypercall_available(void)
0a122b
-{
0a122b
-    if (hyperv_vapic ||
0a122b
-        (hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY)) {
0a122b
-      return true;
0a122b
-    }
0a122b
-    return false;
0a122b
-}
0a122b
-
0a122b
-bool hyperv_vapic_recommended(void)
0a122b
-{
0a122b
-    return hyperv_vapic;
0a122b
-}
0a122b
-
0a122b
-bool hyperv_relaxed_timing_enabled(void)
0a122b
-{
0a122b
-    return hyperv_relaxed_timing;
0a122b
-}
0a122b
-
0a122b
-int hyperv_get_spinlock_retries(void)
0a122b
-{
0a122b
-    return hyperv_spinlock_attempts;
0a122b
-}
0a122b
diff --git a/target-i386/hyperv.h b/target-i386/hyperv.h
0a122b
deleted file mode 100644
0a122b
index bacb1d4..0000000
0a122b
--- a/target-i386/hyperv.h
0a122b
+++ /dev/null
0a122b
@@ -1,45 +0,0 @@
0a122b
-/*
0a122b
- * QEMU Hyper-V support
0a122b
- *
0a122b
- * Copyright Red Hat, Inc. 2011
0a122b
- *
0a122b
- * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
0a122b
- *
0a122b
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
0a122b
- * See the COPYING file in the top-level directory.
0a122b
- *
0a122b
- */
0a122b
-
0a122b
-#ifndef QEMU_HW_HYPERV_H
0a122b
-#define QEMU_HW_HYPERV_H 1
0a122b
-
0a122b
-#include "qemu-common.h"
0a122b
-#ifdef CONFIG_KVM
0a122b
-#include <asm/hyperv.h>
0a122b
-#endif
0a122b
-
0a122b
-#ifndef HYPERV_SPINLOCK_NEVER_RETRY
0a122b
-#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
0a122b
-#endif
0a122b
-
0a122b
-#ifndef KVM_CPUID_SIGNATURE_NEXT
0a122b
-#define KVM_CPUID_SIGNATURE_NEXT                0x40000100
0a122b
-#endif
0a122b
-
0a122b
-#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_KVM)
0a122b
-void hyperv_enable_vapic_recommended(bool val);
0a122b
-void hyperv_enable_relaxed_timing(bool val);
0a122b
-void hyperv_set_spinlock_retries(int val);
0a122b
-#else
0a122b
-static inline void hyperv_enable_vapic_recommended(bool val) { }
0a122b
-static inline void hyperv_enable_relaxed_timing(bool val) { }
0a122b
-static inline void hyperv_set_spinlock_retries(int val) { }
0a122b
-#endif
0a122b
-
0a122b
-bool hyperv_enabled(void);
0a122b
-bool hyperv_hypercall_available(void);
0a122b
-bool hyperv_vapic_recommended(void);
0a122b
-bool hyperv_relaxed_timing_enabled(void);
0a122b
-int hyperv_get_spinlock_retries(void);
0a122b
-
0a122b
-#endif /* QEMU_HW_HYPERV_H */
0a122b
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
0a122b
index 4b470e4..c7fabd7 100644
0a122b
--- a/target-i386/kvm.c
0a122b
+++ b/target-i386/kvm.c
0a122b
@@ -31,7 +31,7 @@
0a122b
 #include "hw/i386/pc.h"
0a122b
 #include "hw/i386/apic.h"
0a122b
 #include "exec/ioport.h"
0a122b
-#include "hyperv.h"
0a122b
+#include <asm/hyperv.h>
0a122b
 #include "hw/pci/pci.h"
0a122b
 
0a122b
 //#define DEBUG_KVM
0a122b
@@ -421,6 +421,22 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)
0a122b
     return cpu->env.cpuid_apic_id;
0a122b
 }
0a122b
 
0a122b
+#ifndef KVM_CPUID_SIGNATURE_NEXT
0a122b
+#define KVM_CPUID_SIGNATURE_NEXT                0x40000100
0a122b
+#endif
0a122b
+
0a122b
+static bool hyperv_hypercall_available(X86CPU *cpu)
0a122b
+{
0a122b
+    return cpu->hyperv_vapic ||
0a122b
+           (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY);
0a122b
+}
0a122b
+
0a122b
+static bool hyperv_enabled(X86CPU *cpu)
0a122b
+{
0a122b
+    return hyperv_hypercall_available(cpu) ||
0a122b
+           cpu->hyperv_relaxed_timing;
0a122b
+}
0a122b
+
0a122b
 #define KVM_MAX_CPUID_ENTRIES  100
0a122b
 
0a122b
 int kvm_arch_init_vcpu(CPUState *cs)
0a122b
@@ -443,7 +459,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
0a122b
     c = &cpuid_data.entries[cpuid_i++];
0a122b
     memset(c, 0, sizeof(*c));
0a122b
     c->function = KVM_CPUID_SIGNATURE;
0a122b
-    if (!hyperv_enabled()) {
0a122b
+    if (!hyperv_enabled(cpu)) {
0a122b
         memcpy(signature, "KVMKVMKVM\0\0\0", 12);
0a122b
         c->eax = 0;
0a122b
     } else {
0a122b
@@ -459,7 +475,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
0a122b
     c->function = KVM_CPUID_FEATURES;
0a122b
     c->eax = env->features[FEAT_KVM];
0a122b
 
0a122b
-    if (hyperv_enabled()) {
0a122b
+    if (hyperv_enabled(cpu)) {
0a122b
         memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
0a122b
         c->eax = signature[0];
0a122b
 
0a122b
@@ -472,10 +488,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
0a122b
         c = &cpuid_data.entries[cpuid_i++];
0a122b
         memset(c, 0, sizeof(*c));
0a122b
         c->function = HYPERV_CPUID_FEATURES;
0a122b
-        if (hyperv_relaxed_timing_enabled()) {
0a122b
+        if (cpu->hyperv_relaxed_timing) {
0a122b
             c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
0a122b
         }
0a122b
-        if (hyperv_vapic_recommended()) {
0a122b
+        if (cpu->hyperv_vapic) {
0a122b
             c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
0a122b
             c->eax |= HV_X64_MSR_APIC_ACCESS_AVAILABLE;
0a122b
         }
0a122b
@@ -483,13 +499,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
0a122b
         c = &cpuid_data.entries[cpuid_i++];
0a122b
         memset(c, 0, sizeof(*c));
0a122b
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
0a122b
-        if (hyperv_relaxed_timing_enabled()) {
0a122b
+        if (cpu->hyperv_relaxed_timing) {
0a122b
             c->eax |= HV_X64_RELAXED_TIMING_RECOMMENDED;
0a122b
         }
0a122b
-        if (hyperv_vapic_recommended()) {
0a122b
+        if (cpu->hyperv_vapic) {
0a122b
             c->eax |= HV_X64_APIC_ACCESS_RECOMMENDED;
0a122b
         }
0a122b
-        c->ebx = hyperv_get_spinlock_retries();
0a122b
+        c->ebx = cpu->hyperv_spinlock_attempts;
0a122b
 
0a122b
         c = &cpuid_data.entries[cpuid_i++];
0a122b
         memset(c, 0, sizeof(*c));
0a122b
@@ -1177,11 +1193,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
0a122b
             kvm_msr_entry_set(&msrs[n++], MSR_CORE_PERF_GLOBAL_CTRL,
0a122b
                               env->msr_global_ctrl);
0a122b
         }
0a122b
-        if (hyperv_hypercall_available()) {
0a122b
+        if (hyperv_hypercall_available(cpu)) {
0a122b
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0);
0a122b
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0);
0a122b
         }
0a122b
-        if (hyperv_vapic_recommended()) {
0a122b
+        if (cpu->hyperv_vapic) {
0a122b
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
0a122b
         }
0a122b
     }
0a122b
-- 
0a122b
1.7.1
0a122b