Blame SOURCES/kvm-i386-Add-the-support-for-AMD-EPYC-3rd-generation-pro.patch

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