Blame SOURCES/kvm-target-i386-Add-support-for-save-load-IA32_UMWAIT_CO.patch

Pablo Greco e6a3ae
From 9c3757a2d7302918456da459a8d188bb41299891 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Tao Xu <tao3.xu@intel.com>
Pablo Greco e6a3ae
Date: Fri, 11 Oct 2019 15:41:03 +0800
Pablo Greco e6a3ae
Subject: [PATCH 11/11] target/i386: Add support for save/load
Pablo Greco e6a3ae
 IA32_UMWAIT_CONTROL MSR
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: plai@redhat.com
Pablo Greco e6a3ae
Message-id: <1574797015-32564-8-git-send-email-plai@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 92693
Pablo Greco e6a3ae
O-Subject: [RHEL8.2 qemu-kvm PATCH 7/7] target/i386: Add support for save/load IA32_UMWAIT_CONTROL MSR
Pablo Greco e6a3ae
Bugzilla: 1634827
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
UMWAIT and TPAUSE instructions use 32bits IA32_UMWAIT_CONTROL at MSR
Pablo Greco e6a3ae
index E1H to determines the maximum time in TSC-quanta that the processor
Pablo Greco e6a3ae
can reside in either C0.1 or C0.2.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
This patch is to Add support for save/load IA32_UMWAIT_CONTROL MSR in
Pablo Greco e6a3ae
guest.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Co-developed-by: Jingqi Liu <jingqi.liu@intel.com>
Pablo Greco e6a3ae
Signed-off-by: Jingqi Liu <jingqi.liu@intel.com>
Pablo Greco e6a3ae
Signed-off-by: Tao Xu <tao3.xu@intel.com>
Pablo Greco e6a3ae
Message-Id: <20191011074103.30393-3-tao3.xu@intel.com>
Pablo Greco e6a3ae
Signed-off-by: Paolo Bonzini <pbonzini@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.h     |  2 ++
Pablo Greco e6a3ae
 target/i386/kvm.c     | 13 +++++++++++++
Pablo Greco e6a3ae
 target/i386/machine.c | 20 ++++++++++++++++++++
Pablo Greco e6a3ae
 3 files changed, 35 insertions(+)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
Pablo Greco e6a3ae
index fac98aa..ecbe4f0 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.h
Pablo Greco e6a3ae
+++ b/target/i386/cpu.h
Pablo Greco e6a3ae
@@ -461,6 +461,7 @@ typedef enum X86Seg {
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define MSR_IA32_BNDCFGS                0x00000d90
Pablo Greco e6a3ae
 #define MSR_IA32_XSS                    0x00000da0
Pablo Greco e6a3ae
+#define MSR_IA32_UMWAIT_CONTROL         0xe1
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define MSR_IA32_VMX_BASIC              0x00000480
Pablo Greco e6a3ae
 #define MSR_IA32_VMX_PINBASED_CTLS      0x00000481
Pablo Greco e6a3ae
@@ -1510,6 +1511,7 @@ typedef struct CPUX86State {
Pablo Greco e6a3ae
     uint16_t fpregs_format_vmstate;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     uint64_t xss;
Pablo Greco e6a3ae
+    uint32_t umwait;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     TPRAccess tpr_access_type;
Pablo Greco e6a3ae
 } CPUX86State;
Pablo Greco e6a3ae
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
Pablo Greco e6a3ae
index 0fd5650..ad58bfb 100644
Pablo Greco e6a3ae
--- a/target/i386/kvm.c
Pablo Greco e6a3ae
+++ b/target/i386/kvm.c
Pablo Greco e6a3ae
@@ -91,6 +91,7 @@ static bool has_msr_hv_synic;
Pablo Greco e6a3ae
 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_umwait;
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
@@ -1450,6 +1451,9 @@ static int kvm_get_supported_msrs(KVMState *s)
Pablo Greco e6a3ae
             case MSR_IA32_XSS:
Pablo Greco e6a3ae
                 has_msr_xss = true;
Pablo Greco e6a3ae
                 break;
Pablo Greco e6a3ae
+            case MSR_IA32_UMWAIT_CONTROL:
Pablo Greco e6a3ae
+                has_msr_umwait = true;
Pablo Greco e6a3ae
+                break;
Pablo Greco e6a3ae
             case HV_X64_MSR_CRASH_CTL:
Pablo Greco e6a3ae
                 has_msr_hv_crash = true;
Pablo Greco e6a3ae
                 break;
Pablo Greco e6a3ae
@@ -2134,6 +2138,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
Pablo Greco e6a3ae
     if (has_msr_xss) {
Pablo Greco e6a3ae
         kvm_msr_entry_add(cpu, MSR_IA32_XSS, env->xss);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+    if (has_msr_umwait) {
Pablo Greco e6a3ae
+        kvm_msr_entry_add(cpu, MSR_IA32_UMWAIT_CONTROL, env->umwait);
Pablo Greco e6a3ae
+    }
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
@@ -2533,6 +2540,9 @@ static int kvm_get_msrs(X86CPU *cpu)
Pablo Greco e6a3ae
     if (has_msr_xss) {
Pablo Greco e6a3ae
         kvm_msr_entry_add(cpu, MSR_IA32_XSS, 0);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+    if (has_msr_umwait) {
Pablo Greco e6a3ae
+        kvm_msr_entry_add(cpu, MSR_IA32_UMWAIT_CONTROL, 0);
Pablo Greco e6a3ae
+    }
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
@@ -2780,6 +2790,9 @@ static int kvm_get_msrs(X86CPU *cpu)
Pablo Greco e6a3ae
         case MSR_IA32_XSS:
Pablo Greco e6a3ae
             env->xss = msrs[i].data;
Pablo Greco e6a3ae
             break;
Pablo Greco e6a3ae
+        case MSR_IA32_UMWAIT_CONTROL:
Pablo Greco e6a3ae
+            env->umwait = msrs[i].data;
Pablo Greco e6a3ae
+            break;
Pablo Greco e6a3ae
         default:
Pablo Greco e6a3ae
             if (msrs[i].index >= MSR_MC0_CTL &&
Pablo Greco e6a3ae
                 msrs[i].index < MSR_MC0_CTL + (env->mcg_cap & 0xff) * 4) {
Pablo Greco e6a3ae
diff --git a/target/i386/machine.c b/target/i386/machine.c
Pablo Greco e6a3ae
index 76b173c..960cb51 100644
Pablo Greco e6a3ae
--- a/target/i386/machine.c
Pablo Greco e6a3ae
+++ b/target/i386/machine.c
Pablo Greco e6a3ae
@@ -894,6 +894,25 @@ static const VMStateDescription vmstate_xss = {
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 };
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+static bool umwait_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->umwait != 0;
Pablo Greco e6a3ae
+}
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+static const VMStateDescription vmstate_umwait = {
Pablo Greco e6a3ae
+    .name = "cpu/umwait",
Pablo Greco e6a3ae
+    .version_id = 1,
Pablo Greco e6a3ae
+    .minimum_version_id = 1,
Pablo Greco e6a3ae
+    .needed = umwait_needed,
Pablo Greco e6a3ae
+    .fields = (VMStateField[]) {
Pablo Greco e6a3ae
+        VMSTATE_UINT32(env.umwait, X86CPU),
Pablo Greco e6a3ae
+        VMSTATE_END_OF_LIST()
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
+};
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 #ifdef TARGET_X86_64
Pablo Greco e6a3ae
 static bool pkru_needed(void *opaque)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
@@ -1360,6 +1379,7 @@ VMStateDescription vmstate_x86_cpu = {
Pablo Greco e6a3ae
         &vmstate_msr_hyperv_stimer,
Pablo Greco e6a3ae
         &vmstate_avx512,
Pablo Greco e6a3ae
         &vmstate_xss,
Pablo Greco e6a3ae
+        &vmstate_umwait,
Pablo Greco e6a3ae
         &vmstate_tsc_khz,
Pablo Greco e6a3ae
         &vmstate_msr_smi_count,
Pablo Greco e6a3ae
 #ifdef TARGET_X86_64
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae