|
|
73f313 |
From 73fac9c9beb00cc462eaae8589b4b2261142a8b2 Mon Sep 17 00:00:00 2001
|
|
|
73f313 |
From: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
73f313 |
Date: Wed, 4 Dec 2019 01:48:29 +0100
|
|
|
73f313 |
Subject: [PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
|
73f313 |
|
|
|
73f313 |
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
73f313 |
Message-id: <20191204014829.608318-3-ehabkost@redhat.com>
|
|
|
73f313 |
Patchwork-id: 92854
|
|
|
73f313 |
O-Subject: [RHEL-7.8 qemu-kvm PATCH 2/2] target/i386: add support for MSR_IA32_TSX_CTRL
|
|
|
73f313 |
Bugzilla: 1771961
|
|
|
73f313 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
73f313 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
73f313 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
73f313 |
|
|
|
73f313 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
73f313 |
|
|
|
73f313 |
The MSR_IA32_TSX_CTRL MSR can be used to hide TSX (also known as the
|
|
|
73f313 |
Trusty Side-channel Extension). By virtualizing the MSR, KVM guests
|
|
|
73f313 |
can disable TSX and avoid paying the price of mitigating TSX-based
|
|
|
73f313 |
attacks on microarchitectural side channels.
|
|
|
73f313 |
|
|
|
73f313 |
Backport notes:
|
|
|
73f313 |
* MSR code had to be rewritten
|
|
|
73f313 |
* .needed is inside VMStateSubsection
|
|
|
73f313 |
|
|
|
73f313 |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
73f313 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
73f313 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
73f313 |
(cherry picked from commit 2a9758c51e2c2d13fc3845c3d603c11df98b8823)
|
|
|
73f313 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
73f313 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
73f313 |
---
|
|
|
73f313 |
target-i386/cpu.c | 2 +-
|
|
|
73f313 |
target-i386/cpu.h | 5 +++++
|
|
|
73f313 |
target-i386/kvm.c | 14 ++++++++++++++
|
|
|
73f313 |
target-i386/machine.c | 21 +++++++++++++++++++++
|
|
|
73f313 |
4 files changed, 41 insertions(+), 1 deletion(-)
|
|
|
73f313 |
|
|
|
73f313 |
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
|
|
|
73f313 |
index 120df73..57f5364 100644
|
|
|
73f313 |
--- a/target-i386/cpu.c
|
|
|
73f313 |
+++ b/target-i386/cpu.c
|
|
|
73f313 |
@@ -211,7 +211,7 @@ static const char *cpuid_apm_edx_feature_name[] = {
|
|
|
73f313 |
|
|
|
73f313 |
static const char *cpuid_arch_capabilities_feature_name[] = {
|
|
|
73f313 |
"rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
|
|
|
73f313 |
- "ssb-no", "mds-no", NULL, NULL,
|
|
|
73f313 |
+ "ssb-no", "mds-no", NULL, "tsx-ctrl",
|
|
|
73f313 |
"taa-no", NULL, NULL, NULL,
|
|
|
73f313 |
NULL, NULL, NULL, NULL,
|
|
|
73f313 |
NULL, NULL, NULL, NULL,
|
|
|
73f313 |
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
|
|
|
73f313 |
index 8f73af7..c9bcdd5 100644
|
|
|
73f313 |
--- a/target-i386/cpu.h
|
|
|
73f313 |
+++ b/target-i386/cpu.h
|
|
|
73f313 |
@@ -307,7 +307,11 @@
|
|
|
73f313 |
#define MSR_IA32_SPEC_CTRL 0x48
|
|
|
73f313 |
#define MSR_VIRT_SSBD 0xc001011f
|
|
|
73f313 |
#define MSR_IA32_PRED_CMD 0x49
|
|
|
73f313 |
+
|
|
|
73f313 |
#define MSR_IA32_ARCH_CAPABILITIES 0x10a
|
|
|
73f313 |
+#define ARCH_CAP_TSX_CTRL_MSR (1<<7)
|
|
|
73f313 |
+
|
|
|
73f313 |
+#define MSR_IA32_TSX_CTRL 0x122
|
|
|
73f313 |
#define MSR_IA32_TSCDEADLINE 0x6e0
|
|
|
73f313 |
|
|
|
73f313 |
#define MSR_P6_PERFCTR0 0xc1
|
|
|
73f313 |
@@ -1067,6 +1071,7 @@ typedef struct CPUX86State {
|
|
|
73f313 |
uint64_t xss;
|
|
|
73f313 |
|
|
|
73f313 |
uint32_t pkru;
|
|
|
73f313 |
+ uint32_t tsx_ctrl;
|
|
|
73f313 |
|
|
|
73f313 |
uint64_t spec_ctrl;
|
|
|
73f313 |
uint64_t virt_ssbd;
|
|
|
73f313 |
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
|
|
|
73f313 |
index c79b0ea..7df2b28 100644
|
|
|
73f313 |
--- a/target-i386/kvm.c
|
|
|
73f313 |
+++ b/target-i386/kvm.c
|
|
|
73f313 |
@@ -80,6 +80,7 @@ static bool has_msr_hv_tsc;
|
|
|
73f313 |
static bool has_msr_mtrr;
|
|
|
73f313 |
static bool has_msr_xss;
|
|
|
73f313 |
static bool has_msr_spec_ctrl;
|
|
|
73f313 |
+static bool has_msr_tsx_ctrl;
|
|
|
73f313 |
static bool has_msr_virt_ssbd;
|
|
|
73f313 |
static bool has_msr_arch_capabs;
|
|
|
73f313 |
|
|
|
73f313 |
@@ -908,6 +909,10 @@ static int kvm_get_supported_msrs(KVMState *s)
|
|
|
73f313 |
has_msr_spec_ctrl = true;
|
|
|
73f313 |
continue;
|
|
|
73f313 |
}
|
|
|
73f313 |
+ if (kvm_msr_list->indices[i] == MSR_IA32_TSX_CTRL) {
|
|
|
73f313 |
+ has_msr_tsx_ctrl = true;
|
|
|
73f313 |
+ continue;
|
|
|
73f313 |
+ }
|
|
|
73f313 |
if (kvm_msr_list->indices[i] == MSR_VIRT_SSBD) {
|
|
|
73f313 |
has_msr_virt_ssbd = true;
|
|
|
73f313 |
continue;
|
|
|
73f313 |
@@ -1330,6 +1335,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
73f313 |
if (has_msr_spec_ctrl) {
|
|
|
73f313 |
kvm_msr_entry_set(&msrs[n++], MSR_IA32_SPEC_CTRL, env->spec_ctrl);
|
|
|
73f313 |
}
|
|
|
73f313 |
+ if (has_msr_tsx_ctrl) {
|
|
|
73f313 |
+ kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSX_CTRL, env->tsx_ctrl);
|
|
|
73f313 |
+ }
|
|
|
73f313 |
if (has_msr_virt_ssbd) {
|
|
|
73f313 |
kvm_msr_entry_set(&msrs[n++], MSR_VIRT_SSBD, env->virt_ssbd);
|
|
|
73f313 |
}
|
|
|
73f313 |
@@ -1699,6 +1707,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
73f313 |
if (has_msr_spec_ctrl) {
|
|
|
73f313 |
msrs[n++].index = MSR_IA32_SPEC_CTRL;
|
|
|
73f313 |
}
|
|
|
73f313 |
+ if (has_msr_tsx_ctrl) {
|
|
|
73f313 |
+ msrs[n++].index = MSR_IA32_TSX_CTRL;
|
|
|
73f313 |
+ }
|
|
|
73f313 |
if (has_msr_virt_ssbd) {
|
|
|
73f313 |
msrs[n++].index = MSR_VIRT_SSBD;
|
|
|
73f313 |
}
|
|
|
73f313 |
@@ -1945,6 +1956,9 @@ static int kvm_get_msrs(X86CPU *cpu)
|
|
|
73f313 |
case MSR_IA32_SPEC_CTRL:
|
|
|
73f313 |
env->spec_ctrl = msrs[i].data;
|
|
|
73f313 |
break;
|
|
|
73f313 |
+ case MSR_IA32_TSX_CTRL:
|
|
|
73f313 |
+ env->tsx_ctrl = msrs[i].data;
|
|
|
73f313 |
+ break;
|
|
|
73f313 |
case MSR_VIRT_SSBD:
|
|
|
73f313 |
env->virt_ssbd = msrs[i].data;
|
|
|
73f313 |
break;
|
|
|
73f313 |
diff --git a/target-i386/machine.c b/target-i386/machine.c
|
|
|
73f313 |
index cd2cf6f..892c8f4 100644
|
|
|
73f313 |
--- a/target-i386/machine.c
|
|
|
73f313 |
+++ b/target-i386/machine.c
|
|
|
73f313 |
@@ -778,6 +778,24 @@ static const VMStateDescription vmstate_msr_virt_ssbd = {
|
|
|
73f313 |
}
|
|
|
73f313 |
};
|
|
|
73f313 |
|
|
|
73f313 |
+static bool msr_tsx_ctrl_needed(void *opaque)
|
|
|
73f313 |
+{
|
|
|
73f313 |
+ X86CPU *cpu = opaque;
|
|
|
73f313 |
+ CPUX86State *env = &cpu->env;
|
|
|
73f313 |
+
|
|
|
73f313 |
+ return env->features[FEAT_ARCH_CAPABILITIES] & ARCH_CAP_TSX_CTRL_MSR;
|
|
|
73f313 |
+}
|
|
|
73f313 |
+
|
|
|
73f313 |
+static const VMStateDescription vmstate_msr_tsx_ctrl = {
|
|
|
73f313 |
+ .name = "cpu/msr_tsx_ctrl",
|
|
|
73f313 |
+ .version_id = 1,
|
|
|
73f313 |
+ .minimum_version_id = 1,
|
|
|
73f313 |
+ .fields = (VMStateField[]) {
|
|
|
73f313 |
+ VMSTATE_UINT32(env.tsx_ctrl, X86CPU),
|
|
|
73f313 |
+ VMSTATE_END_OF_LIST()
|
|
|
73f313 |
+ }
|
|
|
73f313 |
+};
|
|
|
73f313 |
+
|
|
|
73f313 |
VMStateDescription vmstate_x86_cpu = {
|
|
|
73f313 |
.name = "cpu",
|
|
|
73f313 |
.version_id = 12,
|
|
|
73f313 |
@@ -938,6 +956,9 @@ VMStateDescription vmstate_x86_cpu = {
|
|
|
73f313 |
}, {
|
|
|
73f313 |
.vmsd = &vmstate_msr_virt_ssbd,
|
|
|
73f313 |
.needed = virt_ssbd_needed,
|
|
|
73f313 |
+ }, {
|
|
|
73f313 |
+ .vmsd = &vmstate_msr_tsx_ctrl,
|
|
|
73f313 |
+ .needed = msr_tsx_ctrl_needed,
|
|
|
73f313 |
} , {
|
|
|
73f313 |
/* empty */
|
|
|
73f313 |
}
|
|
|
73f313 |
--
|
|
|
73f313 |
1.8.3.1
|
|
|
73f313 |
|