thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-x86-define-a-new-MSR-based-feature-word-FEATURE_WORD.patch

9ae3a8
From a047703bdb55821e77d9a89f484e98e5293dc5bf Mon Sep 17 00:00:00 2001
9ae3a8
From: "plai@redhat.com" <plai@redhat.com>
9ae3a8
Date: Mon, 23 Sep 2019 20:40:24 +0200
9ae3a8
Subject: [PATCH 08/12] x86: define a new MSR based feature word --
9ae3a8
 FEATURE_WORDS_ARCH_CAPABILITIES
9ae3a8
9ae3a8
RH-Author: plai@redhat.com
9ae3a8
Message-id: <1569271227-28026-8-git-send-email-plai@redhat.com>
9ae3a8
Patchwork-id: 90860
9ae3a8
O-Subject: [RHEL7.8 qemu-kvm PATCH v6 07/10] x86: define a new MSR based feature word -- FEATURE_WORDS_ARCH_CAPABILITIES
9ae3a8
Bugzilla: 1709971
9ae3a8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
RH-Acked-by: Bandan Das <bsd@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Robert Hoo <robert.hu@linux.intel.com>
9ae3a8
9ae3a8
Note RSBA is specially treated -- no matter host support it or not, qemu
9ae3a8
pretends it is supported.
9ae3a8
9ae3a8
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
9ae3a8
Message-Id: <1539578845-37944-4-git-send-email-robert.hu@linux.intel.com>
9ae3a8
[ehabkost: removed automatic enabling of RSBA]
9ae3a8
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
9ae3a8
(cherry picked from commit d86f963694df27f11b3681ffd225c9362de1b634)
9ae3a8
Signed-off-by: Paul Lai <plai@redhat.com>
9ae3a8
9ae3a8
Resolved Conflicts:
9ae3a8
	target/i386/cpu.c
9ae3a8
	target/i386/cpu.h
9ae3a8
	target/i386/kvm.c
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 target-i386/cpu.c | 23 +++++++++++++++++++++++
9ae3a8
 target-i386/cpu.h |  8 ++++++++
9ae3a8
 target-i386/kvm.c | 10 ++++++++++
9ae3a8
 3 files changed, 41 insertions(+)
9ae3a8
9ae3a8
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
9ae3a8
index 488634c..24fc000 100644
9ae3a8
--- a/target-i386/cpu.c
9ae3a8
+++ b/target-i386/cpu.c
9ae3a8
@@ -210,6 +210,17 @@ static const char *cpuid_apm_edx_feature_name[] = {
9ae3a8
     NULL, NULL, NULL, NULL,
9ae3a8
 };
9ae3a8
 
9ae3a8
+static const char *cpuid_arch_capabilities_feature_name[] = {
9ae3a8
+    "rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
9ae3a8
+    "ssb-no", NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+    NULL, NULL, NULL, NULL,
9ae3a8
+};
9ae3a8
+
9ae3a8
 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
9ae3a8
 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
9ae3a8
           CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
9ae3a8
@@ -392,6 +403,18 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
9ae3a8
             .reg = R_EAX,
9ae3a8
         },
9ae3a8
     },
9ae3a8
+    /*Below are MSR exposed features*/
9ae3a8
+    [FEAT_ARCH_CAPABILITIES] = {
9ae3a8
+        .type = MSR_FEATURE_WORD,
9ae3a8
+        .feat_names = cpuid_arch_capabilities_feature_name,
9ae3a8
+        .msr = {
9ae3a8
+            .index = MSR_IA32_ARCH_CAPABILITIES,
9ae3a8
+            .cpuid_dep = {
9ae3a8
+                FEAT_7_0_EDX,
9ae3a8
+                CPUID_7_0_EDX_ARCH_CAPABILITIES
9ae3a8
+            }
9ae3a8
+        },
9ae3a8
+    },
9ae3a8
 };
9ae3a8
 
9ae3a8
 typedef struct X86RegisterInfo32 {
9ae3a8
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
9ae3a8
index 0ce479a..5a86b2c 100644
9ae3a8
--- a/target-i386/cpu.h
9ae3a8
+++ b/target-i386/cpu.h
9ae3a8
@@ -416,6 +416,7 @@ typedef enum FeatureWord {
9ae3a8
     FEAT_KVM,           /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */
9ae3a8
     FEAT_SVM,           /* CPUID[8000_000A].EDX */
9ae3a8
     FEAT_XSAVE,         /* CPUID[EAX=0xd,ECX=1].EAX */
9ae3a8
+    FEAT_ARCH_CAPABILITIES,
9ae3a8
     FEATURE_WORDS,
9ae3a8
 } FeatureWord;
9ae3a8
 
9ae3a8
@@ -636,6 +637,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
9ae3a8
 #define CPUID_MWAIT_IBE     (1U << 1) /* Interrupts can exit capability */
9ae3a8
 #define CPUID_MWAIT_EMX     (1U << 0) /* enumeration supported */
9ae3a8
 
9ae3a8
+/* MSR Feature Bits */
9ae3a8
+#define MSR_ARCH_CAP_RDCL_NO    (1U << 0)
9ae3a8
+#define MSR_ARCH_CAP_IBRS_ALL   (1U << 1)
9ae3a8
+#define MSR_ARCH_CAP_RSBA       (1U << 2)
9ae3a8
+#define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3)
9ae3a8
+#define MSR_ARCH_CAP_SSB_NO     (1U << 4)
9ae3a8
+
9ae3a8
 #ifndef HYPERV_SPINLOCK_NEVER_RETRY
9ae3a8
 #define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
9ae3a8
 #endif
9ae3a8
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
9ae3a8
index 159ed4c..722cfbc 100644
9ae3a8
--- a/target-i386/kvm.c
9ae3a8
+++ b/target-i386/kvm.c
9ae3a8
@@ -1339,6 +1339,16 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
9ae3a8
             kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSC, env->tsc);
9ae3a8
         }
9ae3a8
     }
9ae3a8
+    /* If host supports feature MSR, write down. */
9ae3a8
+    if (kvm_feature_msrs) {
9ae3a8
+        int i;
9ae3a8
+        for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
9ae3a8
+            if (kvm_feature_msrs->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
9ae3a8
+                kvm_msr_entry_set(&msrs[n++], MSR_IA32_ARCH_CAPABILITIES,
9ae3a8
+                              env->features[FEAT_ARCH_CAPABILITIES]);
9ae3a8
+                break;
9ae3a8
+            }
9ae3a8
+    }
9ae3a8
     /*
9ae3a8
      * The following MSRs have side effects on the guest or are too heavy
9ae3a8
      * for normal writeback. Limit them to reset or full state updates.
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8