|
|
9bac43 |
From f0fac2e6c70510f7a5c5c572831b1a851a29fc07 Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9bac43 |
Date: Wed, 13 Dec 2017 15:47:36 -0200
|
|
|
9bac43 |
Subject: [PATCH 1/3] target-i386: add support for SPEC_CTRL MSR
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9bac43 |
Message-id: <20171213174738.20852-2-ehabkost@redhat.com>
|
|
|
9bac43 |
Patchwork-id: n/a
|
|
|
9bac43 |
O-Subject: [CONFIDENTIAL][RHEL-7.5 qemu-kvm-rhev PATCH v2 1/3] target-i386: cpu:
|
|
|
9bac43 |
add new CPUID bits for indirect branch predictor restrictions
|
|
|
9bac43 |
Bugzilla: CVE-2017-5715
|
|
|
9bac43 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
target/i386/cpu.h | 3 +++
|
|
|
9bac43 |
target/i386/kvm.c | 14 ++++++++++++++
|
|
|
9bac43 |
target/i386/machine.c | 20 ++++++++++++++++++++
|
|
|
9bac43 |
3 files changed, 37 insertions(+)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
|
|
|
9bac43 |
index fd73888..4dfb859 100644
|
|
|
9bac43 |
--- a/target/i386/cpu.h
|
|
|
9bac43 |
+++ b/target/i386/cpu.h
|
|
|
9bac43 |
@@ -335,6 +335,7 @@
|
|
|
9bac43 |
#define MSR_IA32_APICBASE_BASE (0xfffffU<<12)
|
|
|
9bac43 |
#define MSR_IA32_FEATURE_CONTROL 0x0000003a
|
|
|
9bac43 |
#define MSR_TSC_ADJUST 0x0000003b
|
|
|
9bac43 |
+#define MSR_IA32_SPEC_CTRL 0x48
|
|
|
9bac43 |
#define MSR_IA32_TSCDEADLINE 0x6e0
|
|
|
9bac43 |
|
|
|
9bac43 |
#define FEATURE_CONTROL_LOCKED (1<<0)
|
|
|
9bac43 |
@@ -1082,6 +1083,8 @@ typedef struct CPUX86State {
|
|
|
9bac43 |
|
|
|
9bac43 |
uint32_t pkru;
|
|
|
9bac43 |
|
|
|
9bac43 |
+ uint64_t spec_ctrl;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
/* End of state preserved by INIT (dummy marker). */
|
|
|
9bac43 |
struct {} end_init_save;
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
|
9bac43 |
index ee4e91f..3f59629 100644
|
|
|
9bac43 |
--- a/target/i386/kvm.c
|
|
|
9bac43 |
+++ b/target/i386/kvm.c
|
|
|
9bac43 |
@@ -91,6 +91,7 @@ static bool has_msr_hv_synic;
|
|
|
9bac43 |
static bool has_msr_hv_stimer;
|
|
|
9bac43 |
static bool has_msr_hv_frequencies;
|
|
|
9bac43 |
static bool has_msr_xss;
|
|
|
9bac43 |
+static bool has_msr_spec_ctrl;
|
|
|
9bac43 |
|
|
|
9bac43 |
static bool has_msr_architectural_pmu;
|
|
|
9bac43 |
static uint32_t num_architectural_pmu_counters;
|
|
|
9bac43 |
@@ -1145,6 +1146,9 @@ static int kvm_get_supported_msrs(KVMState *s)
|
|
|
9bac43 |
case HV_X64_MSR_TSC_FREQUENCY:
|
|
|
9bac43 |
has_msr_hv_frequencies = true;
|
|
|
9bac43 |
break;
|
|
|
9bac43 |
+ case MSR_IA32_SPEC_CTRL:
|
|
|
9bac43 |
+ has_msr_spec_ctrl = true;
|
|
|
9bac43 |
+ break;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
@@ -1627,6 +1631,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
9bac43 |
if (has_msr_xss) {
|
|
|
9bac43 |
kvm_msr_entry_add(cpu, MSR_IA32_XSS, env->xss);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
+ if (has_msr_spec_ctrl) {
|
|
|
9bac43 |
+ kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, env->spec_ctrl);
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
#ifdef TARGET_X86_64
|
|
|
9bac43 |
if (lm_capable_kernel) {
|
|
|
9bac43 |
kvm_msr_entry_add(cpu, MSR_CSTAR, env->cstar);
|
|
|
9bac43 |
@@ -1635,6 +1642,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
9bac43 |
kvm_msr_entry_add(cpu, MSR_LSTAR, env->lstar);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
#endif
|
|
|
9bac43 |
+
|
|
|
9bac43 |
/*
|
|
|
9bac43 |
* The following MSRs have side effects on the guest or are too heavy
|
|
|
9bac43 |
* for normal writeback. Limit them to reset or full state updates.
|
|
|
9bac43 |
@@ -2000,6 +2008,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
9bac43 |
if (has_msr_xss) {
|
|
|
9bac43 |
kvm_msr_entry_add(cpu, MSR_IA32_XSS, 0);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
+ if (has_msr_spec_ctrl) {
|
|
|
9bac43 |
+ kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, 0);
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
|
|
|
9bac43 |
|
|
|
9bac43 |
if (!env->tsc_valid) {
|
|
|
9bac43 |
@@ -2349,6 +2360,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
9bac43 |
env->mtrr_var[MSR_MTRRphysIndex(index)].base = msrs[i].data;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
break;
|
|
|
9bac43 |
+ case MSR_IA32_SPEC_CTRL:
|
|
|
9bac43 |
+ env->spec_ctrl = msrs[i].data;
|
|
|
9bac43 |
+ break;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/target/i386/machine.c b/target/i386/machine.c
|
|
|
9bac43 |
index 6156626..0212270 100644
|
|
|
9bac43 |
--- a/target/i386/machine.c
|
|
|
9bac43 |
+++ b/target/i386/machine.c
|
|
|
9bac43 |
@@ -838,6 +838,25 @@ static const VMStateDescription vmstate_xsave ={
|
|
|
9bac43 |
}
|
|
|
9bac43 |
};
|
|
|
9bac43 |
|
|
|
9bac43 |
+static bool spec_ctrl_needed(void *opaque)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ X86CPU *cpu = opaque;
|
|
|
9bac43 |
+ CPUX86State *env = &cpu->env;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ return env->spec_ctrl != 0;
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static const VMStateDescription vmstate_spec_ctrl = {
|
|
|
9bac43 |
+ .name = "cpu/spec_ctrl",
|
|
|
9bac43 |
+ .version_id = 1,
|
|
|
9bac43 |
+ .minimum_version_id = 1,
|
|
|
9bac43 |
+ .needed = spec_ctrl_needed,
|
|
|
9bac43 |
+ .fields = (VMStateField[]){
|
|
|
9bac43 |
+ VMSTATE_UINT64(env.spec_ctrl, X86CPU),
|
|
|
9bac43 |
+ VMSTATE_END_OF_LIST()
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+};
|
|
|
9bac43 |
+
|
|
|
9bac43 |
VMStateDescription vmstate_x86_cpu = {
|
|
|
9bac43 |
.name = "cpu",
|
|
|
9bac43 |
.version_id = 12,
|
|
|
9bac43 |
@@ -956,6 +975,7 @@ VMStateDescription vmstate_x86_cpu = {
|
|
|
9bac43 |
#ifdef TARGET_X86_64
|
|
|
9bac43 |
&vmstate_pkru,
|
|
|
9bac43 |
#endif
|
|
|
9bac43 |
+ &vmstate_spec_ctrl,
|
|
|
9bac43 |
&vmstate_mcg_ext_ctl,
|
|
|
9bac43 |
&vmstate_xsave,
|
|
|
9bac43 |
NULL
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|