|
Pablo Greco |
e6a3ae |
From 39c3a18b4b956d0533e07de2640be064e07e3c97 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
e6a3ae |
From: Eduardo Habkost <ehabkost@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Date: Tue, 3 Dec 2019 23:53:08 +0000
|
|
Pablo Greco |
e6a3ae |
Subject: [PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Message-id: <20191203235308.590845-3-ehabkost@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Patchwork-id: 92850
|
|
Pablo Greco |
e6a3ae |
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
Pablo Greco |
e6a3ae |
Bugzilla: 1771971
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
The MSR_IA32_TSX_CTRL MSR can be used to hide TSX (also known as the
|
|
Pablo Greco |
e6a3ae |
Trusty Side-channel Extension). By virtualizing the MSR, KVM guests
|
|
Pablo Greco |
e6a3ae |
can disable TSX and avoid paying the price of mitigating TSX-based
|
|
Pablo Greco |
e6a3ae |
attacks on microarchitectural side channels.
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Pablo Greco |
e6a3ae |
(cherry picked from commit 2a9758c51e2c2d13fc3845c3d603c11df98b8823)
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
Pablo Greco |
e6a3ae |
---
|
|
Pablo Greco |
e6a3ae |
target/i386/cpu.c | 2 +-
|
|
Pablo Greco |
e6a3ae |
target/i386/cpu.h | 4 ++++
|
|
Pablo Greco |
e6a3ae |
target/i386/kvm.c | 13 +++++++++++++
|
|
Pablo Greco |
e6a3ae |
target/i386/machine.c | 20 ++++++++++++++++++++
|
|
Pablo Greco |
e6a3ae |
4 files changed, 38 insertions(+), 1 deletion(-)
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
|
|
Pablo Greco |
e6a3ae |
index 68fe865..ef6b958 100644
|
|
Pablo Greco |
e6a3ae |
--- a/target/i386/cpu.c
|
|
Pablo Greco |
e6a3ae |
+++ b/target/i386/cpu.c
|
|
Pablo Greco |
e6a3ae |
@@ -1143,7 +1143,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
|
|
Pablo Greco |
e6a3ae |
.type = MSR_FEATURE_WORD,
|
|
Pablo Greco |
e6a3ae |
.feat_names = {
|
|
Pablo Greco |
e6a3ae |
"rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
|
|
Pablo Greco |
e6a3ae |
- "ssb-no", "mds-no", NULL, NULL,
|
|
Pablo Greco |
e6a3ae |
+ "ssb-no", "mds-no", NULL, "tsx-ctrl",
|
|
Pablo Greco |
e6a3ae |
"taa-no", NULL, NULL, NULL,
|
|
Pablo Greco |
e6a3ae |
NULL, NULL, NULL, NULL,
|
|
Pablo Greco |
e6a3ae |
NULL, NULL, NULL, NULL,
|
|
Pablo Greco |
e6a3ae |
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
|
|
Pablo Greco |
e6a3ae |
index 386e821..8d8814e 100644
|
|
Pablo Greco |
e6a3ae |
--- a/target/i386/cpu.h
|
|
Pablo Greco |
e6a3ae |
+++ b/target/i386/cpu.h
|
|
Pablo Greco |
e6a3ae |
@@ -355,6 +355,9 @@ typedef enum X86Seg {
|
|
Pablo Greco |
e6a3ae |
#define MSR_IA32_PRED_CMD 0x49
|
|
Pablo Greco |
e6a3ae |
#define MSR_IA32_CORE_CAPABILITY 0xcf
|
|
Pablo Greco |
e6a3ae |
#define MSR_IA32_ARCH_CAPABILITIES 0x10a
|
|
Pablo Greco |
e6a3ae |
+#define ARCH_CAP_TSX_CTRL_MSR (1<<7)
|
|
Pablo Greco |
e6a3ae |
+
|
|
Pablo Greco |
e6a3ae |
+#define MSR_IA32_TSX_CTRL 0x122
|
|
Pablo Greco |
e6a3ae |
#define MSR_IA32_TSCDEADLINE 0x6e0
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
#define FEATURE_CONTROL_LOCKED (1<<0)
|
|
Pablo Greco |
e6a3ae |
@@ -1373,6 +1376,7 @@ typedef struct CPUX86State {
|
|
Pablo Greco |
e6a3ae |
uint64_t msr_smi_count;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
uint32_t pkru;
|
|
Pablo Greco |
e6a3ae |
+ uint32_t tsx_ctrl;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
uint64_t spec_ctrl;
|
|
Pablo Greco |
e6a3ae |
uint64_t virt_ssbd;
|
|
Pablo Greco |
e6a3ae |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
Pablo Greco |
e6a3ae |
index 6366172..107c53b 100644
|
|
Pablo Greco |
e6a3ae |
--- a/target/i386/kvm.c
|
|
Pablo Greco |
e6a3ae |
+++ b/target/i386/kvm.c
|
|
Pablo Greco |
e6a3ae |
@@ -92,6 +92,7 @@ static bool has_msr_hv_stimer;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_hv_frequencies;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_xss;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_spec_ctrl;
|
|
Pablo Greco |
e6a3ae |
+static bool has_msr_tsx_ctrl;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_virt_ssbd;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_smi_count;
|
|
Pablo Greco |
e6a3ae |
static bool has_msr_arch_capabs;
|
|
Pablo Greco |
e6a3ae |
@@ -1458,6 +1459,9 @@ static int kvm_get_supported_msrs(KVMState *s)
|
|
Pablo Greco |
e6a3ae |
case MSR_IA32_SPEC_CTRL:
|
|
Pablo Greco |
e6a3ae |
has_msr_spec_ctrl = true;
|
|
Pablo Greco |
e6a3ae |
break;
|
|
Pablo Greco |
e6a3ae |
+ case MSR_IA32_TSX_CTRL:
|
|
Pablo Greco |
e6a3ae |
+ has_msr_tsx_ctrl = true;
|
|
Pablo Greco |
e6a3ae |
+ break;
|
|
Pablo Greco |
e6a3ae |
case MSR_VIRT_SSBD:
|
|
Pablo Greco |
e6a3ae |
has_msr_virt_ssbd = true;
|
|
Pablo Greco |
e6a3ae |
break;
|
|
Pablo Greco |
e6a3ae |
@@ -2095,6 +2099,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
Pablo Greco |
e6a3ae |
if (has_msr_spec_ctrl) {
|
|
Pablo Greco |
e6a3ae |
kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, env->spec_ctrl);
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
+ if (has_msr_tsx_ctrl) {
|
|
Pablo Greco |
e6a3ae |
+ kvm_msr_entry_add(cpu, MSR_IA32_TSX_CTRL, env->tsx_ctrl);
|
|
Pablo Greco |
e6a3ae |
+ }
|
|
Pablo Greco |
e6a3ae |
if (has_msr_virt_ssbd) {
|
|
Pablo Greco |
e6a3ae |
kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, env->virt_ssbd);
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
@@ -2491,6 +2498,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
Pablo Greco |
e6a3ae |
if (has_msr_spec_ctrl) {
|
|
Pablo Greco |
e6a3ae |
kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, 0);
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
+ if (has_msr_tsx_ctrl) {
|
|
Pablo Greco |
e6a3ae |
+ kvm_msr_entry_add(cpu, MSR_IA32_TSX_CTRL, 0);
|
|
Pablo Greco |
e6a3ae |
+ }
|
|
Pablo Greco |
e6a3ae |
if (has_msr_virt_ssbd) {
|
|
Pablo Greco |
e6a3ae |
kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, 0);
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
@@ -2862,6 +2872,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
Pablo Greco |
e6a3ae |
case MSR_IA32_SPEC_CTRL:
|
|
Pablo Greco |
e6a3ae |
env->spec_ctrl = msrs[i].data;
|
|
Pablo Greco |
e6a3ae |
break;
|
|
Pablo Greco |
e6a3ae |
+ case MSR_IA32_TSX_CTRL:
|
|
Pablo Greco |
e6a3ae |
+ env->tsx_ctrl = msrs[i].data;
|
|
Pablo Greco |
e6a3ae |
+ break;
|
|
Pablo Greco |
e6a3ae |
case MSR_VIRT_SSBD:
|
|
Pablo Greco |
e6a3ae |
env->virt_ssbd = msrs[i].data;
|
|
Pablo Greco |
e6a3ae |
break;
|
|
Pablo Greco |
e6a3ae |
diff --git a/target/i386/machine.c b/target/i386/machine.c
|
|
Pablo Greco |
e6a3ae |
index fa8d1cc..76b173c 100644
|
|
Pablo Greco |
e6a3ae |
--- a/target/i386/machine.c
|
|
Pablo Greco |
e6a3ae |
+++ b/target/i386/machine.c
|
|
Pablo Greco |
e6a3ae |
@@ -1226,6 +1226,25 @@ static const VMStateDescription vmstate_efer32 = {
|
|
Pablo Greco |
e6a3ae |
};
|
|
Pablo Greco |
e6a3ae |
#endif
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
+static bool msr_tsx_ctrl_needed(void *opaque)
|
|
Pablo Greco |
e6a3ae |
+{
|
|
Pablo Greco |
e6a3ae |
+ X86CPU *cpu = opaque;
|
|
Pablo Greco |
e6a3ae |
+ CPUX86State *env = &cpu->env;
|
|
Pablo Greco |
e6a3ae |
+
|
|
Pablo Greco |
e6a3ae |
+ return env->features[FEAT_ARCH_CAPABILITIES] & ARCH_CAP_TSX_CTRL_MSR;
|
|
Pablo Greco |
e6a3ae |
+}
|
|
Pablo Greco |
e6a3ae |
+
|
|
Pablo Greco |
e6a3ae |
+static const VMStateDescription vmstate_msr_tsx_ctrl = {
|
|
Pablo Greco |
e6a3ae |
+ .name = "cpu/msr_tsx_ctrl",
|
|
Pablo Greco |
e6a3ae |
+ .version_id = 1,
|
|
Pablo Greco |
e6a3ae |
+ .minimum_version_id = 1,
|
|
Pablo Greco |
e6a3ae |
+ .needed = msr_tsx_ctrl_needed,
|
|
Pablo Greco |
e6a3ae |
+ .fields = (VMStateField[]) {
|
|
Pablo Greco |
e6a3ae |
+ VMSTATE_UINT32(env.tsx_ctrl, X86CPU),
|
|
Pablo Greco |
e6a3ae |
+ VMSTATE_END_OF_LIST()
|
|
Pablo Greco |
e6a3ae |
+ }
|
|
Pablo Greco |
e6a3ae |
+};
|
|
Pablo Greco |
e6a3ae |
+
|
|
Pablo Greco |
e6a3ae |
VMStateDescription vmstate_x86_cpu = {
|
|
Pablo Greco |
e6a3ae |
.name = "cpu",
|
|
Pablo Greco |
e6a3ae |
.version_id = 12,
|
|
Pablo Greco |
e6a3ae |
@@ -1357,6 +1376,7 @@ VMStateDescription vmstate_x86_cpu = {
|
|
Pablo Greco |
e6a3ae |
#ifdef CONFIG_KVM
|
|
Pablo Greco |
e6a3ae |
&vmstate_nested_state,
|
|
Pablo Greco |
e6a3ae |
#endif
|
|
Pablo Greco |
e6a3ae |
+ &vmstate_msr_tsx_ctrl,
|
|
Pablo Greco |
e6a3ae |
NULL
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
};
|
|
Pablo Greco |
e6a3ae |
--
|
|
Pablo Greco |
e6a3ae |
1.8.3.1
|
|
Pablo Greco |
e6a3ae |
|