yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
6e7d01
From 4daa8dca77edec191dfe0ae4a0a9fc70f8f63607 Mon Sep 17 00:00:00 2001
6e7d01
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
6e7d01
Date: Wed, 24 Feb 2021 11:30:37 -0500
6e7d01
Subject: [PATCH 4/4] i386: Add the support for AMD EPYC 3rd generation
6e7d01
 processors
6e7d01
6e7d01
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
6e7d01
Message-id: <20210224113037.15599-5-dgilbert@redhat.com>
6e7d01
Patchwork-id: 101202
6e7d01
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 4/4] i386: Add the support for AMD EPYC 3rd generation processors
6e7d01
Bugzilla: 1790620
6e7d01
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
6e7d01
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
6e7d01
RH-Acked-by: Peter Xu <peterx@redhat.com>
6e7d01
6e7d01
From: Babu Moger <babu.moger@amd.com>
6e7d01
6e7d01
Adds the support for AMD 3rd generation processors. The model
6e7d01
display for the new processor will be EPYC-Milan.
6e7d01
6e7d01
Adds the following new feature bits on top of the feature bits from
6e7d01
the first and second generation EPYC models.
6e7d01
6e7d01
pcid          : Process context identifiers support
6e7d01
ibrs          : Indirect Branch Restricted Speculation
6e7d01
ssbd          : Speculative Store Bypass Disable
6e7d01
erms          : Enhanced REP MOVSB/STOSB support
6e7d01
fsrm          : Fast Short REP MOVSB support
6e7d01
invpcid       : Invalidate processor context ID
6e7d01
pku           : Protection keys support
6e7d01
svme-addr-chk : SVM instructions address check for #GP handling
6e7d01
6e7d01
Depends on the following kernel commits:
6e7d01
14c2bf81fcd2 ("KVM: SVM: Fix #GP handling for doubly-nested virtualization")
6e7d01
3b9c723ed7cf ("KVM: SVM: Add support for SVM instruction address check change")
6e7d01
4aa2691dcbd3 ("8ce1c461188799d863398dd2865d KVM: x86: Factor out x86 instruction emulation with decoding")
6e7d01
4407a797e941 ("KVM: SVM: Enable INVPCID feature on AMD")
6e7d01
9715092f8d7e ("KVM: X86: Move handling of INVPCID types to x86")
6e7d01
3f3393b3ce38 ("KVM: X86: Rename and move the function vmx_handle_memory_failure to x86.c")
6e7d01
830bd71f2c06 ("KVM: SVM: Remove set_cr_intercept, clr_cr_intercept and is_cr_intercept")
6e7d01
4c44e8d6c193 ("KVM: SVM: Add new intercept word in vmcb_control_area")
6e7d01
c62e2e94b9d4 ("KVM: SVM: Modify 64 bit intercept field to two 32 bit vectors")
6e7d01
9780d51dc2af ("KVM: SVM: Modify intercept_exceptions to generic intercepts")
6e7d01
30abaa88382c ("KVM: SVM: Change intercept_dr to generic intercepts")
6e7d01
03bfeeb988a9 ("KVM: SVM: Change intercept_cr to generic intercepts")
6e7d01
c45ad7229d13 ("KVM: SVM: Introduce vmcb_(set_intercept/clr_intercept/_is_intercept)")
6e7d01
a90c1ed9f11d ("(pcid) KVM: nSVM: Remove unused field")
6e7d01
fa44b82eb831 ("KVM: x86: Move MPK feature detection to common code")
6e7d01
38f3e775e9c2 ("x86/Kconfig: Update config and kernel doc for MPK feature on AMD")
6e7d01
37486135d3a7 ("KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c")
6e7d01
6e7d01
Signed-off-by: Babu Moger <babu.moger@amd.com>
6e7d01
Message-Id: <161290460478.11352.8933244555799318236.stgit@bmoger-ubuntu>
6e7d01
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
6e7d01
(cherry picked from commit 623972ceae091b31331ae4a1dc94fe5cbb891937)
6e7d01
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
6e7d01
---
6e7d01
 target/i386/cpu.c | 107 +++++++++++++++++++++++++++++++++++++++++++++-
6e7d01
 target/i386/cpu.h |   4 ++
6e7d01
 2 files changed, 110 insertions(+), 1 deletion(-)
6e7d01
6e7d01
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
6e7d01
index 7227c803c3..d5b0d4b7f0 100644
6e7d01
--- a/target/i386/cpu.c
6e7d01
+++ b/target/i386/cpu.c
6e7d01
@@ -1133,7 +1133,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
6e7d01
             "clzero", NULL, "xsaveerptr", NULL,
6e7d01
             NULL, NULL, NULL, NULL,
6e7d01
             NULL, "wbnoinvd", NULL, NULL,
6e7d01
-            "ibpb", NULL, NULL, "amd-stibp",
6e7d01
+            "ibpb", NULL, "ibrs", "amd-stibp",
6e7d01
             NULL, NULL, NULL, NULL,
6e7d01
             NULL, NULL, NULL, NULL,
6e7d01
             "amd-ssbd", "virt-ssbd", "amd-no-ssb", NULL,
6e7d01
@@ -1853,6 +1853,56 @@ static CPUCaches epyc_rome_cache_info = {
6e7d01
     },
6e7d01
 };
6e7d01
 
6e7d01
+static CPUCaches epyc_milan_cache_info = {
6e7d01
+    .l1d_cache = &(CPUCacheInfo) {
6e7d01
+        .type = DATA_CACHE,
6e7d01
+        .level = 1,
6e7d01
+        .size = 32 * KiB,
6e7d01
+        .line_size = 64,
6e7d01
+        .associativity = 8,
6e7d01
+        .partitions = 1,
6e7d01
+        .sets = 64,
6e7d01
+        .lines_per_tag = 1,
6e7d01
+        .self_init = 1,
6e7d01
+        .no_invd_sharing = true,
6e7d01
+    },
6e7d01
+    .l1i_cache = &(CPUCacheInfo) {
6e7d01
+        .type = INSTRUCTION_CACHE,
6e7d01
+        .level = 1,
6e7d01
+        .size = 32 * KiB,
6e7d01
+        .line_size = 64,
6e7d01
+        .associativity = 8,
6e7d01
+        .partitions = 1,
6e7d01
+        .sets = 64,
6e7d01
+        .lines_per_tag = 1,
6e7d01
+        .self_init = 1,
6e7d01
+        .no_invd_sharing = true,
6e7d01
+    },
6e7d01
+    .l2_cache = &(CPUCacheInfo) {
6e7d01
+        .type = UNIFIED_CACHE,
6e7d01
+        .level = 2,
6e7d01
+        .size = 512 * KiB,
6e7d01
+        .line_size = 64,
6e7d01
+        .associativity = 8,
6e7d01
+        .partitions = 1,
6e7d01
+        .sets = 1024,
6e7d01
+        .lines_per_tag = 1,
6e7d01
+    },
6e7d01
+    .l3_cache = &(CPUCacheInfo) {
6e7d01
+        .type = UNIFIED_CACHE,
6e7d01
+        .level = 3,
6e7d01
+        .size = 32 * MiB,
6e7d01
+        .line_size = 64,
6e7d01
+        .associativity = 16,
6e7d01
+        .partitions = 1,
6e7d01
+        .sets = 32768,
6e7d01
+        .lines_per_tag = 1,
6e7d01
+        .self_init = true,
6e7d01
+        .inclusive = true,
6e7d01
+        .complex_indexing = true,
6e7d01
+    },
6e7d01
+};
6e7d01
+
6e7d01
 /* The following VMX features are not supported by KVM and are left out in the
6e7d01
  * CPU definitions:
6e7d01
  *
6e7d01
@@ -4124,6 +4174,61 @@ static X86CPUDefinition builtin_x86_defs[] = {
6e7d01
         .model_id = "AMD EPYC-Rome Processor",
6e7d01
         .cache_info = &epyc_rome_cache_info,
6e7d01
     },
6e7d01
+    {
6e7d01
+        .name = "EPYC-Milan",
6e7d01
+        .level = 0xd,
6e7d01
+        .vendor = CPUID_VENDOR_AMD,
6e7d01
+        .family = 25,
6e7d01
+        .model = 1,
6e7d01
+        .stepping = 1,
6e7d01
+        .features[FEAT_1_EDX] =
6e7d01
+            CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | CPUID_CLFLUSH |
6e7d01
+            CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA | CPUID_PGE |
6e7d01
+            CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 | CPUID_MCE |
6e7d01
+            CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE | CPUID_DE |
6e7d01
+            CPUID_VME | CPUID_FP87,
6e7d01
+        .features[FEAT_1_ECX] =
6e7d01
+            CPUID_EXT_RDRAND | CPUID_EXT_F16C | CPUID_EXT_AVX |
6e7d01
+            CPUID_EXT_XSAVE | CPUID_EXT_AES |  CPUID_EXT_POPCNT |
6e7d01
+            CPUID_EXT_MOVBE | CPUID_EXT_SSE42 | CPUID_EXT_SSE41 |
6e7d01
+            CPUID_EXT_CX16 | CPUID_EXT_FMA | CPUID_EXT_SSSE3 |
6e7d01
+            CPUID_EXT_MONITOR | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3 |
6e7d01
+            CPUID_EXT_PCID,
6e7d01
+        .features[FEAT_8000_0001_EDX] =
6e7d01
+            CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_PDPE1GB |
6e7d01
+            CPUID_EXT2_FFXSR | CPUID_EXT2_MMXEXT | CPUID_EXT2_NX |
6e7d01
+            CPUID_EXT2_SYSCALL,
6e7d01
+        .features[FEAT_8000_0001_ECX] =
6e7d01
+            CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH |
6e7d01
+            CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM |
6e7d01
+            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM |
6e7d01
+            CPUID_EXT3_TOPOEXT | CPUID_EXT3_PERFCORE,
6e7d01
+        .features[FEAT_8000_0008_EBX] =
6e7d01
+            CPUID_8000_0008_EBX_CLZERO | CPUID_8000_0008_EBX_XSAVEERPTR |
6e7d01
+            CPUID_8000_0008_EBX_WBNOINVD | CPUID_8000_0008_EBX_IBPB |
6e7d01
+            CPUID_8000_0008_EBX_IBRS | CPUID_8000_0008_EBX_STIBP |
6e7d01
+            CPUID_8000_0008_EBX_AMD_SSBD,
6e7d01
+        .features[FEAT_7_0_EBX] =
6e7d01
+            CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 |
6e7d01
+            CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_RDSEED |
6e7d01
+            CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_CLFLUSHOPT |
6e7d01
+            CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_ERMS |
6e7d01
+            CPUID_7_0_EBX_INVPCID,
6e7d01
+        .features[FEAT_7_0_ECX] =
6e7d01
+            CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_RDPID | CPUID_7_0_ECX_PKU,
6e7d01
+        .features[FEAT_7_0_EDX] =
6e7d01
+            CPUID_7_0_EDX_FSRM,
6e7d01
+        .features[FEAT_XSAVE] =
6e7d01
+            CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
6e7d01
+            CPUID_XSAVE_XGETBV1 | CPUID_XSAVE_XSAVES,
6e7d01
+        .features[FEAT_6_EAX] =
6e7d01
+            CPUID_6_EAX_ARAT,
6e7d01
+        .features[FEAT_SVM] =
6e7d01
+            CPUID_SVM_NPT | CPUID_SVM_NRIPSAVE | CPUID_SVM_SVME_ADDR_CHK,
6e7d01
+        .xlevel = 0x8000001E,
6e7d01
+        .model_id = "AMD EPYC-Milan Processor",
6e7d01
+        .cache_info = &epyc_milan_cache_info,
6e7d01
+    },
6e7d01
 };
6e7d01
 
6e7d01
 /* KVM-specific features that are automatically added/removed
6e7d01
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
6e7d01
index e1b67910c2..7a3aa40201 100644
6e7d01
--- a/target/i386/cpu.h
6e7d01
+++ b/target/i386/cpu.h
6e7d01
@@ -800,8 +800,12 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
6e7d01
 #define CPUID_8000_0008_EBX_WBNOINVD    (1U << 9)
6e7d01
 /* Indirect Branch Prediction Barrier */
6e7d01
 #define CPUID_8000_0008_EBX_IBPB        (1U << 12)
6e7d01
+/* Indirect Branch Restricted Speculation */
6e7d01
+#define CPUID_8000_0008_EBX_IBRS        (1U << 14)
6e7d01
 /* Single Thread Indirect Branch Predictors */
6e7d01
 #define CPUID_8000_0008_EBX_STIBP       (1U << 15)
6e7d01
+/* Speculative Store Bypass Disable */
6e7d01
+#define CPUID_8000_0008_EBX_AMD_SSBD    (1U << 24)
6e7d01
 
6e7d01
 #define CPUID_XSAVE_XSAVEOPT   (1U << 0)
6e7d01
 #define CPUID_XSAVE_XSAVEC     (1U << 1)
6e7d01
-- 
6e7d01
2.27.0
6e7d01