cryptospore / 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

Pablo Greco e6a3ae
From 8b64571f3ce90fc14c571ea588f608bce4328d34 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: "plai@redhat.com" <plai@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 3 Apr 2019 15:54:32 +0100
Pablo Greco e6a3ae
Subject: [PATCH 08/10] x86: define a new MSR based feature word --
Pablo Greco e6a3ae
 FEATURE_WORDS_ARCH_CAPABILITIES
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: plai@redhat.com
Pablo Greco e6a3ae
Message-id: <1554306874-28796-9-git-send-email-plai@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 85385
Pablo Greco e6a3ae
O-Subject: [RHEL8.1 qemu-kvm PATCH resend 08/10] x86: define a new MSR based feature word -- FEATURE_WORDS_ARCH_CAPABILITIES
Pablo Greco e6a3ae
Bugzilla: 1561761
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Robert Hoo <robert.hu@linux.intel.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Note RSBA is specially treated -- no matter host support it or not, qemu
Pablo Greco e6a3ae
pretends it is supported.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
Pablo Greco e6a3ae
Message-Id: <1539578845-37944-4-git-send-email-robert.hu@linux.intel.com>
Pablo Greco e6a3ae
[ehabkost: removed automatic enabling of RSBA]
Pablo Greco e6a3ae
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
(cherry picked from commit d86f963694df27f11b3681ffd225c9362de1b634)
Pablo Greco e6a3ae
Signed-off-by: Paul Lai <plai@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.c | 24 +++++++++++++++++++++++-
Pablo Greco e6a3ae
 target/i386/cpu.h |  8 ++++++++
Pablo Greco e6a3ae
 target/i386/kvm.c | 11 +++++++++++
Pablo Greco e6a3ae
 3 files changed, 42 insertions(+), 1 deletion(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
Pablo Greco e6a3ae
index a0fdd3a..8750f64 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.c
Pablo Greco e6a3ae
+++ b/target/i386/cpu.c
Pablo Greco e6a3ae
@@ -1143,6 +1143,27 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
         .tcg_features = ~0U,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
+    /*Below are MSR exposed features*/
Pablo Greco e6a3ae
+    [FEAT_ARCH_CAPABILITIES] = {
Pablo Greco e6a3ae
+        .type = MSR_FEATURE_WORD,
Pablo Greco e6a3ae
+        .feat_names = {
Pablo Greco e6a3ae
+            "rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry",
Pablo Greco e6a3ae
+            "ssb-no", NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
+        .msr = {
Pablo Greco e6a3ae
+            .index = MSR_IA32_ARCH_CAPABILITIES,
Pablo Greco e6a3ae
+            .cpuid_dep = {
Pablo Greco e6a3ae
+                FEAT_7_0_EDX,
Pablo Greco e6a3ae
+                CPUID_7_0_EDX_ARCH_CAPABILITIES
Pablo Greco e6a3ae
+            }
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
+    },
Pablo Greco e6a3ae
 };
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 typedef struct X86RegisterInfo32 {
Pablo Greco e6a3ae
@@ -3665,7 +3686,8 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
Pablo Greco e6a3ae
                                                         wi->cpuid.reg);
Pablo Greco e6a3ae
             break;
Pablo Greco e6a3ae
         case MSR_FEATURE_WORD:
Pablo Greco e6a3ae
-            r = kvm_arch_get_supported_msr_feature(kvm_state, wi->msr.index);
Pablo Greco e6a3ae
+            r = kvm_arch_get_supported_msr_feature(kvm_state,
Pablo Greco e6a3ae
+                        wi->msr.index);
Pablo Greco e6a3ae
             break;
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
     } else if (hvf_enabled()) {
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
Pablo Greco e6a3ae
index dd4493e..63f692f 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.h
Pablo Greco e6a3ae
+++ b/target/i386/cpu.h
Pablo Greco e6a3ae
@@ -500,6 +500,7 @@ typedef enum FeatureWord {
Pablo Greco e6a3ae
     FEAT_6_EAX,         /* CPUID[6].EAX */
Pablo Greco e6a3ae
     FEAT_XSAVE_COMP_LO, /* CPUID[EAX=0xd,ECX=0].EAX */
Pablo Greco e6a3ae
     FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
Pablo Greco e6a3ae
+    FEAT_ARCH_CAPABILITIES,
Pablo Greco e6a3ae
     FEATURE_WORDS,
Pablo Greco e6a3ae
 } FeatureWord;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -729,6 +730,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
Pablo Greco e6a3ae
 #define CPUID_TOPOLOGY_LEVEL_SMT      (1U << 8)
Pablo Greco e6a3ae
 #define CPUID_TOPOLOGY_LEVEL_CORE     (2U << 8)
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+/* MSR Feature Bits */
Pablo Greco e6a3ae
+#define MSR_ARCH_CAP_RDCL_NO    (1U << 0)
Pablo Greco e6a3ae
+#define MSR_ARCH_CAP_IBRS_ALL   (1U << 1)
Pablo Greco e6a3ae
+#define MSR_ARCH_CAP_RSBA       (1U << 2)
Pablo Greco e6a3ae
+#define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3)
Pablo Greco e6a3ae
+#define MSR_ARCH_CAP_SSB_NO     (1U << 4)
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 #ifndef HYPERV_SPINLOCK_NEVER_RETRY
Pablo Greco e6a3ae
 #define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
Pablo Greco e6a3ae
 #endif
Pablo Greco e6a3ae
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
Pablo Greco e6a3ae
index 096ed24..f1626a4 100644
Pablo Greco e6a3ae
--- a/target/i386/kvm.c
Pablo Greco e6a3ae
+++ b/target/i386/kvm.c
Pablo Greco e6a3ae
@@ -1833,6 +1833,17 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 #endif
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+    /* If host supports feature MSR, write down. */
Pablo Greco e6a3ae
+    if (kvm_feature_msrs) {
Pablo Greco e6a3ae
+        int i;
Pablo Greco e6a3ae
+        for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
Pablo Greco e6a3ae
+            if (kvm_feature_msrs->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
Pablo Greco e6a3ae
+                kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
Pablo Greco e6a3ae
+                              env->features[FEAT_ARCH_CAPABILITIES]);
Pablo Greco e6a3ae
+                break;
Pablo Greco e6a3ae
+            }
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
     /*
Pablo Greco e6a3ae
      * The following MSRs have side effects on the guest or are too heavy
Pablo Greco e6a3ae
      * for normal writeback. Limit them to reset or full state updates.
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae