yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

69f3e1
From 4263a1e54da9f6e1d1b0aa74d52436224a6cfd5e Mon Sep 17 00:00:00 2001
69f3e1
From: "plai@redhat.com" <plai@redhat.com>
69f3e1
Date: Tue, 20 Aug 2019 00:24:35 +0100
69f3e1
Subject: [PATCH 4/9] x86: define a new MSR based feature word --
69f3e1
 FEATURE_WORDS_ARCH_CAPABILITIES
69f3e1
69f3e1
RH-Author: plai@redhat.com
69f3e1
Message-id: <1566260680-20995-5-git-send-email-plai@redhat.com>
69f3e1
Patchwork-id: 90069
69f3e1
O-Subject: [RHEL8.0 qemu-kvm PATCH v3 4/9] x86: define a new MSR based feature word -- FEATURE_WORDS_ARCH_CAPABILITIES
69f3e1
Bugzilla: 1718235
69f3e1
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
RH-Acked-by: John Snow <jsnow@redhat.com>
69f3e1
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
69f3e1
69f3e1
From: Robert Hoo <robert.hu@linux.intel.com>
69f3e1
69f3e1
Note RSBA is specially treated -- no matter host support it or not, qemu
69f3e1
pretends it is supported.
69f3e1
69f3e1
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
69f3e1
Message-Id: <1539578845-37944-4-git-send-email-robert.hu@linux.intel.com>
69f3e1
[ehabkost: removed automatic enabling of RSBA]
69f3e1
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
69f3e1
(cherry picked from commit d86f963694df27f11b3681ffd225c9362de1b634)
69f3e1
Signed-off-by: Paul Lai <plai@redhat.com>
69f3e1
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
69f3e1
---
69f3e1
 target/i386/cpu.c | 24 +++++++++++++++++++++++-
69f3e1
 target/i386/cpu.h |  8 ++++++++
69f3e1
 target/i386/kvm.c | 11 +++++++++++
69f3e1
 3 files changed, 42 insertions(+), 1 deletion(-)
69f3e1
69f3e1
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
69f3e1
index bbca6f4..fbcf124 100644
69f3e1
--- a/target/i386/cpu.c
69f3e1
+++ b/target/i386/cpu.c
69f3e1
@@ -1143,6 +1143,27 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
69f3e1
         },
69f3e1
         .tcg_features = ~0U,
69f3e1
     },
69f3e1
+    /*Below are MSR exposed features*/
69f3e1
+    [FEAT_ARCH_CAPABILITIES] = {
69f3e1
+        .type = MSR_FEATURE_WORD,
69f3e1
+        .feat_names = {
69f3e1
+            "rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
69f3e1
+            "ssb-no", NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+            NULL, NULL, NULL, NULL,
69f3e1
+        },
69f3e1
+        .msr = {
69f3e1
+            .index = MSR_IA32_ARCH_CAPABILITIES,
69f3e1
+            .cpuid_dep = {
69f3e1
+                FEAT_7_0_EDX,
69f3e1
+                CPUID_7_0_EDX_ARCH_CAPABILITIES
69f3e1
+            }
69f3e1
+        },
69f3e1
+    },
69f3e1
 };
69f3e1
 
69f3e1
 typedef struct X86RegisterInfo32 {
69f3e1
@@ -3550,7 +3571,8 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
69f3e1
                                                         wi->cpuid.reg);
69f3e1
             break;
69f3e1
         case MSR_FEATURE_WORD:
69f3e1
-            r = kvm_arch_get_supported_msr_feature(kvm_state, wi->msr.index);
69f3e1
+            r = kvm_arch_get_supported_msr_feature(kvm_state,
69f3e1
+                        wi->msr.index);
69f3e1
             break;
69f3e1
         }
69f3e1
     } else if (hvf_enabled()) {
69f3e1
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
69f3e1
index e5e5169..6820a70 100644
69f3e1
--- a/target/i386/cpu.h
69f3e1
+++ b/target/i386/cpu.h
69f3e1
@@ -500,6 +500,7 @@ typedef enum FeatureWord {
69f3e1
     FEAT_6_EAX,         /* CPUID[6].EAX */
69f3e1
     FEAT_XSAVE_COMP_LO, /* CPUID[EAX=0xd,ECX=0].EAX */
69f3e1
     FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
69f3e1
+    FEAT_ARCH_CAPABILITIES,
69f3e1
     FEATURE_WORDS,
69f3e1
 } FeatureWord;
69f3e1
 
69f3e1
@@ -726,6 +727,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
69f3e1
 #define CPUID_TOPOLOGY_LEVEL_SMT      (1U << 8)
69f3e1
 #define CPUID_TOPOLOGY_LEVEL_CORE     (2U << 8)
69f3e1
 
69f3e1
+/* MSR Feature Bits */
69f3e1
+#define MSR_ARCH_CAP_RDCL_NO    (1U << 0)
69f3e1
+#define MSR_ARCH_CAP_IBRS_ALL   (1U << 1)
69f3e1
+#define MSR_ARCH_CAP_RSBA       (1U << 2)
69f3e1
+#define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3)
69f3e1
+#define MSR_ARCH_CAP_SSB_NO     (1U << 4)
69f3e1
+
69f3e1
 #ifndef HYPERV_SPINLOCK_NEVER_RETRY
69f3e1
 #define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
69f3e1
 #endif
69f3e1
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
69f3e1
index 87e4771..187ee19 100644
69f3e1
--- a/target/i386/kvm.c
69f3e1
+++ b/target/i386/kvm.c
69f3e1
@@ -1753,6 +1753,17 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
69f3e1
     }
69f3e1
 #endif
69f3e1
 
69f3e1
+    /* If host supports feature MSR, write down. */
69f3e1
+    if (kvm_feature_msrs) {
69f3e1
+        int i;
69f3e1
+        for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
69f3e1
+            if (kvm_feature_msrs->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
69f3e1
+                kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
69f3e1
+                              env->features[FEAT_ARCH_CAPABILITIES]);
69f3e1
+                break;
69f3e1
+            }
69f3e1
+    }
69f3e1
+
69f3e1
     /*
69f3e1
      * The following MSRs have side effects on the guest or are too heavy
69f3e1
      * for normal writeback. Limit them to reset or full state updates.
69f3e1
-- 
69f3e1
1.8.3.1
69f3e1