yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
619821
From a824033fdc6956ee449f49f6d1a74ebfb21d0700 Mon Sep 17 00:00:00 2001
619821
From: Eduardo Habkost <ehabkost@redhat.com>
619821
Date: Fri, 31 Mar 2017 11:37:37 +0200
619821
Subject: [PATCH 1/4] target-i386: get/set/migrate XSAVES state
619821
619821
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
619821
Message-id: <20170331113737.9930-1-ehabkost@redhat.com>
619821
Patchwork-id: 74596
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH] target-i386: get/set/migrate XSAVES state
619821
Bugzilla: 1327593
619821
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
619821
RH-Acked-by: Bandan Das <bsd@redhat.com>
619821
RH-Acked-by: David Hildenbrand <david@redhat.com>
619821
619821
From: Wanpeng Li <wanpeng.li@linux.intel.com>
619821
619821
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1327593
619821
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12913269
619821
619821
Add xsaves related definition, it also adds corresponding part
619821
to kvm_get/put, and vmstate.
619821
619821
Backport notes:
619821
* As we didn't have unmigratable_flags yet, our backport
619821
  of upstream commit 0bb0b2d2fe7f645ddaf1f0ff40ac669c9feb4aa1
619821
  (commit 5fcaf5176d7545518c76f3aa8ea7ce6fb063c62d) didn't
619821
  include "xsaves" cpuid_xsave_feature_name[]. This patch now
619821
  adds "xsave" to cpuid_xsave_feature_name[].
619821
619821
Signed-off-by: Wanpeng Li <wanpeng.li@linux.intel.com>
619821
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
619821
(cherry picked from commit 18cd2c17b5370369a886155c001da0a7f54bbcca)
619821
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 target-i386/cpu.c     |  2 +-
619821
 target-i386/cpu.h     |  2 ++
619821
 target-i386/kvm.c     | 15 +++++++++++++++
619821
 target-i386/machine.c | 21 +++++++++++++++++++++
619821
 4 files changed, 39 insertions(+), 1 deletion(-)
619821
619821
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
619821
index 33f0997..ae56995 100644
619821
--- a/target-i386/cpu.c
619821
+++ b/target-i386/cpu.c
619821
@@ -177,7 +177,7 @@ static const char *cpuid_7_0_edx_feature_name[] = {
619821
 };
619821
 
619821
 static const char *cpuid_xsave_feature_name[] = {
619821
-    "xsaveopt", "xsavec", "xgetbv1", NULL,
619821
+    "xsaveopt", "xsavec", "xgetbv1", "xsaves",
619821
     NULL, NULL, NULL, NULL,
619821
     NULL, NULL, NULL, NULL,
619821
     NULL, NULL, NULL, NULL,
619821
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
619821
index f04deb4..ac60309 100644
619821
--- a/target-i386/cpu.h
619821
+++ b/target-i386/cpu.h
619821
@@ -384,6 +384,7 @@
619821
 #define MSR_VM_HSAVE_PA                 0xc0010117
619821
 
619821
 #define MSR_IA32_BNDCFGS                0x00000d90
619821
+#define MSR_IA32_XSS                    0x00000da0
619821
 
619821
 #define XSTATE_FP                       (1ULL << 0)
619821
 #define XSTATE_SSE                      (1ULL << 1)
619821
@@ -1026,6 +1027,7 @@ typedef struct CPUX86State {
619821
     uint64_t xstate_bv;
619821
 
619821
     uint64_t xcr0;
619821
+    uint64_t xss;
619821
 
619821
     TPRAccess tpr_access_type;
619821
 } CPUX86State;
619821
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
619821
index e1b0ca2..6a479f4 100644
619821
--- a/target-i386/kvm.c
619821
+++ b/target-i386/kvm.c
619821
@@ -76,6 +76,7 @@ static bool has_msr_hv_hypercall;
619821
 static bool has_msr_hv_vapic;
619821
 static bool has_msr_hv_tsc;
619821
 static bool has_msr_mtrr;
619821
+static bool has_msr_xss;
619821
 
619821
 static bool has_msr_architectural_pmu;
619821
 static uint32_t num_architectural_pmu_counters;
619821
@@ -795,6 +796,10 @@ static int kvm_get_supported_msrs(KVMState *s)
619821
                     has_msr_bndcfgs = true;
619821
                     continue;
619821
                 }
619821
+                if (kvm_msr_list->indices[i] == MSR_IA32_XSS) {
619821
+                    has_msr_xss = true;
619821
+                    continue;
619821
+                }
619821
             }
619821
         }
619821
 
619821
@@ -1177,6 +1182,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
619821
     if (has_msr_bndcfgs) {
619821
         kvm_msr_entry_set(&msrs[n++], MSR_IA32_BNDCFGS, env->msr_bndcfgs);
619821
     }
619821
+    if (has_msr_xss) {
619821
+        kvm_msr_entry_set(&msrs[n++], MSR_IA32_XSS, env->xss);
619821
+    }
619821
 #ifdef TARGET_X86_64
619821
     if (lm_capable_kernel) {
619821
         kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar);
619821
@@ -1530,6 +1538,10 @@ static int kvm_get_msrs(X86CPU *cpu)
619821
     if (has_msr_bndcfgs) {
619821
         msrs[n++].index = MSR_IA32_BNDCFGS;
619821
     }
619821
+    if (has_msr_xss) {
619821
+        msrs[n++].index = MSR_IA32_XSS;
619821
+    }
619821
+
619821
 
619821
     if (!env->tsc_valid) {
619821
         msrs[n++].index = MSR_IA32_TSC;
619821
@@ -1677,6 +1689,9 @@ static int kvm_get_msrs(X86CPU *cpu)
619821
         case MSR_IA32_BNDCFGS:
619821
             env->msr_bndcfgs = msrs[i].data;
619821
             break;
619821
+        case MSR_IA32_XSS:
619821
+            env->xss = msrs[i].data;
619821
+            break;
619821
         default:
619821
             if (msrs[i].index >= MSR_MC0_CTL &&
619821
                 msrs[i].index < MSR_MC0_CTL + (env->mcg_cap & 0xff) * 4) {
619821
diff --git a/target-i386/machine.c b/target-i386/machine.c
619821
index 2c97002..ce7fcd3 100644
619821
--- a/target-i386/machine.c
619821
+++ b/target-i386/machine.c
619821
@@ -704,6 +704,24 @@ static const VMStateDescription vmstate_avx512 = {
619821
     }
619821
 };
619821
 
619821
+static bool xss_needed(void *opaque)
619821
+{
619821
+    X86CPU *cpu = opaque;
619821
+    CPUX86State *env = &cpu->env;
619821
+
619821
+    return env->xss != 0;
619821
+}
619821
+
619821
+static const VMStateDescription vmstate_xss = {
619821
+    .name = "cpu/xss",
619821
+    .version_id = 1,
619821
+    .minimum_version_id = 1,
619821
+    .fields = (VMStateField[]) {
619821
+        VMSTATE_UINT64(env.xss, X86CPU),
619821
+        VMSTATE_END_OF_LIST()
619821
+    }
619821
+};
619821
+
619821
 const VMStateDescription vmstate_x86_cpu = {
619821
     .name = "cpu",
619821
     .version_id = 12,
619821
@@ -850,6 +868,9 @@ const VMStateDescription vmstate_x86_cpu = {
619821
         }, {
619821
             .vmsd = &vmstate_avx512,
619821
             .needed = avx512_needed,
619821
+         }, {
619821
+            .vmsd = &vmstate_xss,
619821
+            .needed = xss_needed,
619821
         } , {
619821
             /* empty */
619821
         }
619821
-- 
619821
1.8.3.1
619821