thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-i386-Define-the-Virt-SSBD-MSR-and-handling-of-it-CVE.patch

ae23c9
From 96f6d8855246a66bde59fd3e663bee0da00f709b Mon Sep 17 00:00:00 2001
ae23c9
From: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Date: Wed, 13 Jun 2018 18:08:11 +0200
ae23c9
Subject: [PATCH 152/268] i386: Define the Virt SSBD MSR and handling of it
ae23c9
 (CVE-2018-3639)
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Message-id: <20180613180812.28169-2-ehabkost@redhat.com>
ae23c9
Patchwork-id: 80677
ae23c9
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/2] i386: Define the Virt SSBD MSR and handling of it (CVE-2018-3639)
ae23c9
Bugzilla: 1574216
ae23c9
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ae23c9
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
ae23c9
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
ae23c9
ae23c9
"Some AMD processors only support a non-architectural means of enabling
ae23c9
speculative store bypass disable (SSBD).  To allow a simplified view of
ae23c9
this to a guest, an architectural definition has been created through a new
ae23c9
CPUID bit, 0x80000008_EBX[25], and a new MSR, 0xc001011f.  With this, a
ae23c9
hypervisor can virtualize the existence of this definition and provide an
ae23c9
architectural method for using SSBD to a guest.
ae23c9
ae23c9
Add the new CPUID feature, the new MSR and update the existing SSBD
ae23c9
support to use this MSR when present." (from x86/speculation: Add virtualized
ae23c9
speculative store bypass disable support in Linux).
ae23c9
ae23c9
Backport conflicts:
ae23c9
  * target-i386/machine.c: trivial conflict with vmstate_xsave section
ae23c9
ae23c9
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
ae23c9
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
ae23c9
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
ae23c9
Message-Id: <20180521215424.13520-4-berrange@redhat.com>
ae23c9
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
(cherry picked from commit cfeea0c021db6234c154dbc723730e81553924ff)
ae23c9
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 target/i386/cpu.h     |  2 ++
ae23c9
 target/i386/kvm.c     | 16 ++++++++++++++--
ae23c9
 target/i386/machine.c | 20 ++++++++++++++++++++
ae23c9
 3 files changed, 36 insertions(+), 2 deletions(-)
ae23c9
ae23c9
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
ae23c9
index 88fdf80..c47db96 100644
ae23c9
--- a/target/i386/cpu.h
ae23c9
+++ b/target/i386/cpu.h
ae23c9
@@ -351,6 +351,7 @@ typedef enum X86Seg {
ae23c9
 #define MSR_IA32_FEATURE_CONTROL        0x0000003a
ae23c9
 #define MSR_TSC_ADJUST                  0x0000003b
ae23c9
 #define MSR_IA32_SPEC_CTRL              0x48
ae23c9
+#define MSR_VIRT_SSBD                   0xc001011f
ae23c9
 #define MSR_IA32_TSCDEADLINE            0x6e0
ae23c9
 
ae23c9
 #define FEATURE_CONTROL_LOCKED                    (1<<0)
ae23c9
@@ -1208,6 +1209,7 @@ typedef struct CPUX86State {
ae23c9
     uint32_t pkru;
ae23c9
 
ae23c9
     uint64_t spec_ctrl;
ae23c9
+    uint64_t virt_ssbd;
ae23c9
 
ae23c9
     /* End of state preserved by INIT (dummy marker).  */
ae23c9
     struct {} end_init_save;
ae23c9
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
ae23c9
index bb5e485..00f2141 100644
ae23c9
--- a/target/i386/kvm.c
ae23c9
+++ b/target/i386/kvm.c
ae23c9
@@ -92,6 +92,7 @@ static bool has_msr_hv_stimer;
ae23c9
 static bool has_msr_hv_frequencies;
ae23c9
 static bool has_msr_xss;
ae23c9
 static bool has_msr_spec_ctrl;
ae23c9
+static bool has_msr_virt_ssbd;
ae23c9
 static bool has_msr_smi_count;
ae23c9
 
ae23c9
 static uint32_t has_architectural_pmu_version;
ae23c9
@@ -1248,6 +1249,9 @@ static int kvm_get_supported_msrs(KVMState *s)
ae23c9
                 case MSR_IA32_SPEC_CTRL:
ae23c9
                     has_msr_spec_ctrl = true;
ae23c9
                     break;
ae23c9
+                case MSR_VIRT_SSBD:
ae23c9
+                    has_msr_virt_ssbd = true;
ae23c9
+                    break;
ae23c9
                 }
ae23c9
             }
ae23c9
         }
ae23c9
@@ -1736,6 +1740,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
ae23c9
     if (has_msr_spec_ctrl) {
ae23c9
         kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, env->spec_ctrl);
ae23c9
     }
ae23c9
+    if (has_msr_virt_ssbd) {
ae23c9
+        kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, env->virt_ssbd);
ae23c9
+    }
ae23c9
+
ae23c9
 #ifdef TARGET_X86_64
ae23c9
     if (lm_capable_kernel) {
ae23c9
         kvm_msr_entry_add(cpu, MSR_CSTAR, env->cstar);
ae23c9
@@ -2107,8 +2115,9 @@ static int kvm_get_msrs(X86CPU *cpu)
ae23c9
     if (has_msr_spec_ctrl) {
ae23c9
         kvm_msr_entry_add(cpu, MSR_IA32_SPEC_CTRL, 0);
ae23c9
     }
ae23c9
-
ae23c9
-
ae23c9
+    if (has_msr_virt_ssbd) {
ae23c9
+        kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, 0);
ae23c9
+    }
ae23c9
     if (!env->tsc_valid) {
ae23c9
         kvm_msr_entry_add(cpu, MSR_IA32_TSC, 0);
ae23c9
         env->tsc_valid = !runstate_is_running();
ae23c9
@@ -2474,6 +2483,9 @@ static int kvm_get_msrs(X86CPU *cpu)
ae23c9
         case MSR_IA32_SPEC_CTRL:
ae23c9
             env->spec_ctrl = msrs[i].data;
ae23c9
             break;
ae23c9
+        case MSR_VIRT_SSBD:
ae23c9
+            env->virt_ssbd = msrs[i].data;
ae23c9
+            break;
ae23c9
         case MSR_IA32_RTIT_CTL:
ae23c9
             env->msr_rtit_ctrl = msrs[i].data;
ae23c9
             break;
ae23c9
diff --git a/target/i386/machine.c b/target/i386/machine.c
ae23c9
index c9a3b5c..5e9a19b 100644
ae23c9
--- a/target/i386/machine.c
ae23c9
+++ b/target/i386/machine.c
ae23c9
@@ -913,6 +913,25 @@ static const VMStateDescription vmstate_xsave ={
ae23c9
     }
ae23c9
 };
ae23c9
 
ae23c9
+static bool virt_ssbd_needed(void *opaque)
ae23c9
+{
ae23c9
+    X86CPU *cpu = opaque;
ae23c9
+    CPUX86State *env = &cpu->env;
ae23c9
+
ae23c9
+    return env->virt_ssbd != 0;
ae23c9
+}
ae23c9
+
ae23c9
+static const VMStateDescription vmstate_msr_virt_ssbd = {
ae23c9
+    .name = "cpu/virt_ssbd",
ae23c9
+    .version_id = 1,
ae23c9
+    .minimum_version_id = 1,
ae23c9
+    .needed = virt_ssbd_needed,
ae23c9
+    .fields = (VMStateField[]){
ae23c9
+        VMSTATE_UINT64(env.virt_ssbd, X86CPU),
ae23c9
+        VMSTATE_END_OF_LIST()
ae23c9
+    }
ae23c9
+};
ae23c9
+
ae23c9
 VMStateDescription vmstate_x86_cpu = {
ae23c9
     .name = "cpu",
ae23c9
     .version_id = 12,
ae23c9
@@ -1036,6 +1055,7 @@ VMStateDescription vmstate_x86_cpu = {
ae23c9
         &vmstate_mcg_ext_ctl,
ae23c9
         &vmstate_msr_intel_pt,
ae23c9
         &vmstate_xsave,
ae23c9
+        &vmstate_msr_virt_ssbd,
ae23c9
         NULL
ae23c9
     }
ae23c9
 };
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9