thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
5d360b
From 9875f9aaef996083064bf6a7afa1bfa30ff7d953 Mon Sep 17 00:00:00 2001
5d360b
From: Paolo Bonzini <pbonzini@redhat.com>
5d360b
Date: Wed, 13 Dec 2017 15:43:40 -0200
5d360b
Subject: [PATCH 2/3] target-i386: add support for SPEC_CTRL MSR
5d360b
5d360b
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
5d360b
Message-id: <20171213174341.20684-3-ehabkost@redhat.com>
5d360b
Patchwork-id: n/a
5d360b
O-Subject: [CONFIDENTIAL][RHEL-7.5 qemu-kvm PATCH v2 2/3] target-i386: add
5d360b
 support for SPEC_CTRL MSR
5d360b
Bugzilla: CVE-2017-5715
5d360b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 target-i386/cpu.h     |  4 ++++
5d360b
 target-i386/kvm.c     | 14 ++++++++++++++
5d360b
 target-i386/machine.c | 21 +++++++++++++++++++++
5d360b
 3 files changed, 39 insertions(+)
5d360b
5d360b
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
5d360b
index 1e5c980..7d815cd 100644
5d360b
--- a/target-i386/cpu.h
5d360b
+++ b/target-i386/cpu.h
5d360b
@@ -304,6 +304,7 @@
5d360b
 #define MSR_IA32_APICBASE_ENABLE        (1<<11)
5d360b
 #define MSR_IA32_APICBASE_BASE          (0xfffff<<12)
5d360b
 #define MSR_TSC_ADJUST                  0x0000003b
5d360b
+#define MSR_IA32_SPEC_CTRL              0x48
5d360b
 #define MSR_IA32_TSCDEADLINE            0x6e0
5d360b
 
5d360b
 #define MSR_P6_PERFCTR0                 0xc1
5d360b
@@ -963,6 +964,7 @@ typedef struct CPUX86State {
5d360b
     uint64_t msr_fixed_counters[MAX_FIXED_COUNTERS];
5d360b
     uint64_t msr_gp_counters[MAX_GP_COUNTERS];
5d360b
     uint64_t msr_gp_evtsel[MAX_GP_COUNTERS];
5d360b
+
5d360b
     uint64_t msr_hv_hypercall;
5d360b
     uint64_t msr_hv_guest_os_id;
5d360b
     uint64_t msr_hv_vapic;
5d360b
@@ -1037,6 +1039,8 @@ typedef struct CPUX86State {
5d360b
 
5d360b
     uint32_t pkru;
5d360b
 
5d360b
+    uint64_t spec_ctrl;
5d360b
+
5d360b
     TPRAccess tpr_access_type;
5d360b
 } CPUX86State;
5d360b
 
5d360b
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
5d360b
index 0dc0e79..24d17ad 100644
5d360b
--- a/target-i386/kvm.c
5d360b
+++ b/target-i386/kvm.c
5d360b
@@ -77,6 +77,7 @@ static bool has_msr_hv_vapic;
5d360b
 static bool has_msr_hv_tsc;
5d360b
 static bool has_msr_mtrr;
5d360b
 static bool has_msr_xss;
5d360b
+static bool has_msr_spec_ctrl;
5d360b
 
5d360b
 static bool has_msr_architectural_pmu;
5d360b
 static uint32_t num_architectural_pmu_counters;
5d360b
@@ -800,6 +801,10 @@ static int kvm_get_supported_msrs(KVMState *s)
5d360b
                     has_msr_xss = true;
5d360b
                     continue;
5d360b
                 }
5d360b
+                if (kvm_msr_list->indices[i] == MSR_IA32_SPEC_CTRL) {
5d360b
+                    has_msr_spec_ctrl = true;
5d360b
+                    continue;
5d360b
+                }
5d360b
             }
5d360b
         }
5d360b
 
5d360b
@@ -1187,6 +1192,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
5d360b
     if (has_msr_xss) {
5d360b
         kvm_msr_entry_set(&msrs[n++], MSR_IA32_XSS, env->xss);
5d360b
     }
5d360b
+    if (has_msr_spec_ctrl) {
5d360b
+        kvm_msr_entry_set(&msrs[n++], MSR_IA32_SPEC_CTRL, env->spec_ctrl);
5d360b
+    }
5d360b
 #ifdef TARGET_X86_64
5d360b
     if (lm_capable_kernel) {
5d360b
         kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar);
5d360b
@@ -1544,6 +1552,9 @@ static int kvm_get_msrs(X86CPU *cpu)
5d360b
     if (has_msr_xss) {
5d360b
         msrs[n++].index = MSR_IA32_XSS;
5d360b
     }
5d360b
+    if (has_msr_spec_ctrl) {
5d360b
+        msrs[n++].index = MSR_IA32_SPEC_CTRL;
5d360b
+    }
5d360b
 
5d360b
 
5d360b
     if (!env->tsc_valid) {
5d360b
@@ -1786,6 +1797,9 @@ static int kvm_get_msrs(X86CPU *cpu)
5d360b
                 env->mtrr_var[MSR_MTRRphysIndex(index)].base = msrs[i].data;
5d360b
             }
5d360b
             break;
5d360b
+        case MSR_IA32_SPEC_CTRL:
5d360b
+            env->spec_ctrl = msrs[i].data;
5d360b
+            break;
5d360b
         }
5d360b
     }
5d360b
 
5d360b
diff --git a/target-i386/machine.c b/target-i386/machine.c
5d360b
index ba34088..d883c86 100644
5d360b
--- a/target-i386/machine.c
5d360b
+++ b/target-i386/machine.c
5d360b
@@ -742,6 +742,24 @@ static const VMStateDescription vmstate_pkru = {
5d360b
 };
5d360b
 #endif
5d360b
 
5d360b
+static bool spec_ctrl_needed(void *opaque)
5d360b
+{
5d360b
+    X86CPU *cpu = opaque;
5d360b
+    CPUX86State *env = &cpu->env;
5d360b
+
5d360b
+    return env->spec_ctrl != 0;
5d360b
+}
5d360b
+
5d360b
+static const VMStateDescription vmstate_spec_ctrl = {
5d360b
+    .name = "cpu/spec_ctrl",
5d360b
+    .version_id = 1,
5d360b
+    .minimum_version_id = 1,
5d360b
+    .fields = (VMStateField[]){
5d360b
+        VMSTATE_UINT64(env.spec_ctrl, X86CPU),
5d360b
+        VMSTATE_END_OF_LIST()
5d360b
+    }
5d360b
+};
5d360b
+
5d360b
 const VMStateDescription vmstate_x86_cpu = {
5d360b
     .name = "cpu",
5d360b
     .version_id = 12,
5d360b
@@ -896,6 +914,9 @@ const VMStateDescription vmstate_x86_cpu = {
5d360b
             .vmsd = &vmstate_pkru,
5d360b
             .needed = pkru_needed,
5d360b
 #endif
5d360b
+        }, {
5d360b
+            .vmsd = &vmstate_spec_ctrl,
5d360b
+            .needed = spec_ctrl_needed,
5d360b
         } , {
5d360b
             /* empty */
5d360b
         }
5d360b
-- 
5d360b
1.8.3.1
5d360b