|
|
8b1478 |
From d84d88a3036a0d5db9b19a1611158946cd362603 Mon Sep 17 00:00:00 2001
|
|
|
8b1478 |
From: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
8b1478 |
Date: Tue, 17 Dec 2019 22:23:42 +0100
|
|
|
8b1478 |
Subject: [PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
|
8b1478 |
|
|
|
8b1478 |
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
8b1478 |
Message-id: <20191217222342.1939034-3-ehabkost@redhat.com>
|
|
|
8b1478 |
Patchwork-id: 93165
|
|
|
8b1478 |
O-Subject: [RHEL-7.8 qemu-kvm-rhev PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
|
8b1478 |
Bugzilla: 1779530
|
|
|
8b1478 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
8b1478 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
8b1478 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
8b1478 |
|
|
|
8b1478 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
8b1478 |
|
|
|
8b1478 |
The MSR_IA32_TSX_CTRL MSR can be used to hide TSX (also known as the
|
|
|
8b1478 |
Trusty Side-channel Extension). By virtualizing the MSR, KVM guests
|
|
|
8b1478 |
can disable TSX and avoid paying the price of mitigating TSX-based
|
|
|
8b1478 |
attacks on microarchitectural side channels.
|
|
|
8b1478 |
|
|
|
8b1478 |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
8b1478 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
8b1478 |
(cherry picked from commit 2a9758c51e2c2d13fc3845c3d603c11df98b8823)
|
|
|
8b1478 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
8b1478 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
8b1478 |
---
|
|
|
8b1478 |
target/i386/cpu.c | 2 +-
|
|
|
8b1478 |
target/i386/cpu.h | 4 ++++
|
|
|
8b1478 |
target/i386/kvm.c | 13 +++++++++++++
|
|
|
8b1478 |
target/i386/machine.c | 20 ++++++++++++++++++++
|
|
|
8b1478 |
4 files changed, 38 insertions(+), 1 deletion(-)
|
|
|
8b1478 |
|
|
|
8b1478 |
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
|
|
|
8b1478 |
index 8d03d0e..4d87879 100644
|
|
|
8b1478 |
--- a/target/i386/cpu.c
|
|
|
8b1478 |
+++ b/target/i386/cpu.c
|
|
|
8b1478 |
@@ -1147,7 +1147,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
|
|
|
8b1478 |
.type = MSR_FEATURE_WORD,
|
|
|
8b1478 |
.feat_names = {
|
|
|
8b1478 |
"rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
|
|
|
8b1478 |
- "ssb-no", "mds-no", NULL, NULL,
|
|
|
8b1478 |
+ "ssb-no", "mds-no", NULL, "tsx-ctrl",
|
|
|
8b1478 |
"taa-no", NULL, NULL, NULL,
|
|
|
8b1478 |
NULL, NULL, NULL, NULL,
|
|
|
8b1478 |
NULL, NULL, NULL, NULL,
|
|
|
8b1478 |
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
|
|
|
8b1478 |
index 095e695..65c4fda 100644
|
|
|
8b1478 |
--- a/target/i386/cpu.h
|
|
|
8b1478 |
+++ b/target/i386/cpu.h
|
|
|
8b1478 |
@@ -354,6 +354,9 @@ typedef enum X86Seg {
|
|
|
8b1478 |
#define MSR_VIRT_SSBD 0xc001011f
|
|
|
8b1478 |
#define MSR_IA32_PRED_CMD 0x49
|
|
|
8b1478 |
#define MSR_IA32_ARCH_CAPABILITIES 0x10a
|
|
|
8b1478 |
+#define ARCH_CAP_TSX_CTRL_MSR (1<<7)
|
|
|
8b1478 |
+
|
|
|
8b1478 |
+#define MSR_IA32_TSX_CTRL 0x122
|
|
|
8b1478 |
#define MSR_IA32_TSCDEADLINE 0x6e0
|
|
|
8b1478 |
|
|
|
8b1478 |
#define FEATURE_CONTROL_LOCKED (1<<0)
|
|
|
8b1478 |
@@ -1221,6 +1224,7 @@ typedef struct CPUX86State {
|
|
|
8b1478 |
uint64_t msr_smi_count;
|
|
|
8b1478 |
|
|
|
8b1478 |
uint32_t pkru;
|
|
|
8b1478 |
+ uint32_t tsx_ctrl;
|
|
|
8b1478 |
|
|
|
8b1478 |
uint64_t spec_ctrl;
|
|
|
8b1478 |
uint64_t virt_ssbd;
|
|
|
8b1478 |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
|
8b1478 |
index 72901e1..a6e5a87 100644
|
|
|
8b1478 |
--- a/target/i386/kvm.c
|
|
|
8b1478 |
+++ b/target/i386/kvm.c
|
|
|
8b1478 |
@@ -92,6 +92,7 @@ static bool has_msr_hv_stimer;
|
|
|
8b1478 |
static bool has_msr_hv_frequencies;
|
|
|
8b1478 |
static bool has_msr_xss;
|
|
|
8b1478 |
static bool has_msr_spec_ctrl;
|
|
|
8b1478 |
+static bool has_msr_tsx_ctrl;
|
|
|
8b1478 |
static bool has_msr_virt_ssbd;
|
|
|
8b1478 |
static bool has_msr_smi_count;
|
|
|
8b1478 |
static bool has_msr_arch_capabs;
|
|
|
8b1478 |
@@ -1340,6 +1341,9 @@ static int kvm_get_supported_msrs(KVMState *s)
|
|
|
8b1478 |
case MSR_IA32_SPEC_CTRL:
|
|
|
8b1478 |
has_msr_spec_ctrl = true;
|
|
|
8b1478 |
break;
|
|
|
8b1478 |
+ case MSR_IA32_TSX_CTRL:
|
|
|
8b1478 |
+ has_msr_tsx_ctrl = true;
|
|
|
8b1478 |
+ break;
|
|
|
8b1478 |
case MSR_VIRT_SSBD:
|
|
|
8b1478 |
has_msr_virt_ssbd = true;
|
|
|
8b1478 |
break;
|
|
|
8b1478 |
@@ -1836,6 +1840,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
8b1478 |
if (has_msr_spec_ctrl) {
|
|
|
8b1478 |
kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, env->spec_ctrl);
|
|
|
8b1478 |
}
|
|
|
8b1478 |
+ if (has_msr_tsx_ctrl) {
|
|
|
8b1478 |
+ kvm_msr_entry_add(cpu, MSR_IA32_TSX_CTRL, env->tsx_ctrl);
|
|
|
8b1478 |
+ }
|
|
|
8b1478 |
if (has_msr_virt_ssbd) {
|
|
|
8b1478 |
kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, env->virt_ssbd);
|
|
|
8b1478 |
}
|
|
|
8b1478 |
@@ -2222,6 +2229,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
8b1478 |
if (has_msr_spec_ctrl) {
|
|
|
8b1478 |
kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, 0);
|
|
|
8b1478 |
}
|
|
|
8b1478 |
+ if (has_msr_tsx_ctrl) {
|
|
|
8b1478 |
+ kvm_msr_entry_add(cpu, MSR_IA32_TSX_CTRL, 0);
|
|
|
8b1478 |
+ }
|
|
|
8b1478 |
if (has_msr_virt_ssbd) {
|
|
|
8b1478 |
kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, 0);
|
|
|
8b1478 |
}
|
|
|
8b1478 |
@@ -2597,6 +2607,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
8b1478 |
case MSR_IA32_SPEC_CTRL:
|
|
|
8b1478 |
env->spec_ctrl = msrs[i].data;
|
|
|
8b1478 |
break;
|
|
|
8b1478 |
+ case MSR_IA32_TSX_CTRL:
|
|
|
8b1478 |
+ env->tsx_ctrl = msrs[i].data;
|
|
|
8b1478 |
+ break;
|
|
|
8b1478 |
case MSR_VIRT_SSBD:
|
|
|
8b1478 |
env->virt_ssbd = msrs[i].data;
|
|
|
8b1478 |
break;
|
|
|
8b1478 |
diff --git a/target/i386/machine.c b/target/i386/machine.c
|
|
|
8b1478 |
index 52b1eae..6a2d761 100644
|
|
|
8b1478 |
--- a/target/i386/machine.c
|
|
|
8b1478 |
+++ b/target/i386/machine.c
|
|
|
8b1478 |
@@ -954,6 +954,25 @@ static const VMStateDescription vmstate_msr_virt_ssbd = {
|
|
|
8b1478 |
}
|
|
|
8b1478 |
};
|
|
|
8b1478 |
|
|
|
8b1478 |
+static bool msr_tsx_ctrl_needed(void *opaque)
|
|
|
8b1478 |
+{
|
|
|
8b1478 |
+ X86CPU *cpu = opaque;
|
|
|
8b1478 |
+ CPUX86State *env = &cpu->env;
|
|
|
8b1478 |
+
|
|
|
8b1478 |
+ return env->features[FEAT_ARCH_CAPABILITIES] & ARCH_CAP_TSX_CTRL_MSR;
|
|
|
8b1478 |
+}
|
|
|
8b1478 |
+
|
|
|
8b1478 |
+static const VMStateDescription vmstate_msr_tsx_ctrl = {
|
|
|
8b1478 |
+ .name = "cpu/msr_tsx_ctrl",
|
|
|
8b1478 |
+ .version_id = 1,
|
|
|
8b1478 |
+ .minimum_version_id = 1,
|
|
|
8b1478 |
+ .needed = msr_tsx_ctrl_needed,
|
|
|
8b1478 |
+ .fields = (VMStateField[]) {
|
|
|
8b1478 |
+ VMSTATE_UINT32(env.tsx_ctrl, X86CPU),
|
|
|
8b1478 |
+ VMSTATE_END_OF_LIST()
|
|
|
8b1478 |
+ }
|
|
|
8b1478 |
+};
|
|
|
8b1478 |
+
|
|
|
8b1478 |
VMStateDescription vmstate_x86_cpu = {
|
|
|
8b1478 |
.name = "cpu",
|
|
|
8b1478 |
.version_id = 12,
|
|
|
8b1478 |
@@ -1079,6 +1098,7 @@ VMStateDescription vmstate_x86_cpu = {
|
|
|
8b1478 |
&vmstate_msr_intel_pt,
|
|
|
8b1478 |
&vmstate_xsave,
|
|
|
8b1478 |
&vmstate_msr_virt_ssbd,
|
|
|
8b1478 |
+ &vmstate_msr_tsx_ctrl,
|
|
|
8b1478 |
NULL
|
|
|
8b1478 |
}
|
|
|
8b1478 |
};
|
|
|
8b1478 |
--
|
|
|
8b1478 |
1.8.3.1
|
|
|
8b1478 |
|