902636
From 1bee5a77b3f999d2933a440021737d0720b32269 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Wed, 29 Jul 2020 18:56:21 -0400
902636
Subject: [PATCH 1/4] i386: Add 2nd Generation AMD EPYC processors
902636
902636
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-id: <20200729185621.152427-2-dgilbert@redhat.com>
902636
Patchwork-id: 98078
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 1/1] i386: Add 2nd Generation AMD EPYC processors
902636
Bugzilla: 1780385
902636
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
902636
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
902636
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
902636
902636
From: "Moger, Babu" <Babu.Moger@amd.com>
902636
902636
Adds the support for 2nd Gen AMD EPYC Processors. The model display
902636
name will be EPYC-Rome.
902636
902636
Adds the following new feature bits on top of the feature bits from the
902636
first generation EPYC models.
902636
perfctr-core : core performance counter extensions support. Enables the VM to
902636
               use extended performance counter support. It enables six
902636
               programmable counters instead of four counters.
902636
clzero       : instruction zeroes out the 64 byte cache line specified in RAX.
902636
xsaveerptr   : XSAVE, XSAVE, FXSAVEOPT, XSAVEC, XSAVES always save error
902636
               pointers and FXRSTOR, XRSTOR, XRSTORS always restore error
902636
               pointers.
902636
wbnoinvd     : Write back and do not invalidate cache
902636
ibpb         : Indirect Branch Prediction Barrier
902636
amd-stibp    : Single Thread Indirect Branch Predictor
902636
clwb         : Cache Line Write Back and Retain
902636
xsaves       : XSAVES, XRSTORS and IA32_XSS support
902636
rdpid        : Read Processor ID instruction support
902636
umip         : User-Mode Instruction Prevention support
902636
902636
The  Reference documents are available at
902636
https://developer.amd.com/wp-content/resources/55803_0.54-PUB.pdf
902636
https://www.amd.com/system/files/TechDocs/24594.pdf
902636
902636
Depends on following kernel commits:
902636
40bc47b08b6e ("kvm: x86: Enumerate support for CLZERO instruction")
902636
504ce1954fba ("KVM: x86: Expose XSAVEERPTR to the guest")
902636
6d61e3c32248 ("kvm: x86: Expose RDPID in KVM_GET_SUPPORTED_CPUID")
902636
52297436199d ("kvm: svm: Update svm_xsaves_supported")
902636
902636
Signed-off-by: Babu Moger <babu.moger@amd.com>
902636
Message-Id: <157314966312.23828.17684821666338093910.stgit@naples-babu.amd.com>
902636
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
902636
(cherry picked from commit 143c30d4d346831a09e59e9af45afdca0331e819)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 target/i386/cpu.c | 102 +++++++++++++++++++++++++++++++++++++++++++++-
902636
 target/i386/cpu.h |   2 +
902636
 2 files changed, 103 insertions(+), 1 deletion(-)
902636
902636
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
902636
index a343de0c9d..ff39fc9905 100644
902636
--- a/target/i386/cpu.c
902636
+++ b/target/i386/cpu.c
902636
@@ -1133,7 +1133,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
902636
             "clzero", NULL, "xsaveerptr", NULL,
902636
             NULL, NULL, NULL, NULL,
902636
             NULL, "wbnoinvd", NULL, NULL,
902636
-            "ibpb", NULL, NULL, NULL,
902636
+            "ibpb", NULL, NULL, "amd-stibp",
902636
             NULL, NULL, NULL, NULL,
902636
             NULL, NULL, NULL, NULL,
902636
             "amd-ssbd", "virt-ssbd", "amd-no-ssb", NULL,
902636
@@ -1803,6 +1803,56 @@ static CPUCaches epyc_cache_info = {
902636
     },
902636
 };
902636
 
902636
+static CPUCaches epyc_rome_cache_info = {
902636
+    .l1d_cache = &(CPUCacheInfo) {
902636
+        .type = DATA_CACHE,
902636
+        .level = 1,
902636
+        .size = 32 * KiB,
902636
+        .line_size = 64,
902636
+        .associativity = 8,
902636
+        .partitions = 1,
902636
+        .sets = 64,
902636
+        .lines_per_tag = 1,
902636
+        .self_init = 1,
902636
+        .no_invd_sharing = true,
902636
+    },
902636
+    .l1i_cache = &(CPUCacheInfo) {
902636
+        .type = INSTRUCTION_CACHE,
902636
+        .level = 1,
902636
+        .size = 32 * KiB,
902636
+        .line_size = 64,
902636
+        .associativity = 8,
902636
+        .partitions = 1,
902636
+        .sets = 64,
902636
+        .lines_per_tag = 1,
902636
+        .self_init = 1,
902636
+        .no_invd_sharing = true,
902636
+    },
902636
+    .l2_cache = &(CPUCacheInfo) {
902636
+        .type = UNIFIED_CACHE,
902636
+        .level = 2,
902636
+        .size = 512 * KiB,
902636
+        .line_size = 64,
902636
+        .associativity = 8,
902636
+        .partitions = 1,
902636
+        .sets = 1024,
902636
+        .lines_per_tag = 1,
902636
+    },
902636
+    .l3_cache = &(CPUCacheInfo) {
902636
+        .type = UNIFIED_CACHE,
902636
+        .level = 3,
902636
+        .size = 16 * MiB,
902636
+        .line_size = 64,
902636
+        .associativity = 16,
902636
+        .partitions = 1,
902636
+        .sets = 16384,
902636
+        .lines_per_tag = 1,
902636
+        .self_init = true,
902636
+        .inclusive = true,
902636
+        .complex_indexing = true,
902636
+    },
902636
+};
902636
+
902636
 /* The following VMX features are not supported by KVM and are left out in the
902636
  * CPU definitions:
902636
  *
902636
@@ -4024,6 +4074,56 @@ static X86CPUDefinition builtin_x86_defs[] = {
902636
         .model_id = "Hygon Dhyana Processor",
902636
         .cache_info = &epyc_cache_info,
902636
     },
902636
+    {
902636
+        .name = "EPYC-Rome",
902636
+        .level = 0xd,
902636
+        .vendor = CPUID_VENDOR_AMD,
902636
+        .family = 23,
902636
+        .model = 49,
902636
+        .stepping = 0,
902636
+        .features[FEAT_1_EDX] =
902636
+            CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | CPUID_CLFLUSH |
902636
+            CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA | CPUID_PGE |
902636
+            CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 | CPUID_MCE |
902636
+            CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE | CPUID_DE |
902636
+            CPUID_VME | CPUID_FP87,
902636
+        .features[FEAT_1_ECX] =
902636
+            CPUID_EXT_RDRAND | CPUID_EXT_F16C | CPUID_EXT_AVX |
902636
+            CPUID_EXT_XSAVE | CPUID_EXT_AES |  CPUID_EXT_POPCNT |
902636
+            CPUID_EXT_MOVBE | CPUID_EXT_SSE42 | CPUID_EXT_SSE41 |
902636
+            CPUID_EXT_CX16 | CPUID_EXT_FMA | CPUID_EXT_SSSE3 |
902636
+            CPUID_EXT_MONITOR | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3,
902636
+        .features[FEAT_8000_0001_EDX] =
902636
+            CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_PDPE1GB |
902636
+            CPUID_EXT2_FFXSR | CPUID_EXT2_MMXEXT | CPUID_EXT2_NX |
902636
+            CPUID_EXT2_SYSCALL,
902636
+        .features[FEAT_8000_0001_ECX] =
902636
+            CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH |
902636
+            CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM |
902636
+            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM |
902636
+            CPUID_EXT3_TOPOEXT | CPUID_EXT3_PERFCORE,
902636
+        .features[FEAT_8000_0008_EBX] =
902636
+            CPUID_8000_0008_EBX_CLZERO | CPUID_8000_0008_EBX_XSAVEERPTR |
902636
+            CPUID_8000_0008_EBX_WBNOINVD | CPUID_8000_0008_EBX_IBPB |
902636
+            CPUID_8000_0008_EBX_STIBP,
902636
+        .features[FEAT_7_0_EBX] =
902636
+            CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 |
902636
+            CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_RDSEED |
902636
+            CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_CLFLUSHOPT |
902636
+            CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_CLWB,
902636
+        .features[FEAT_7_0_ECX] =
902636
+            CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_RDPID,
902636
+        .features[FEAT_XSAVE] =
902636
+            CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
902636
+            CPUID_XSAVE_XGETBV1 | CPUID_XSAVE_XSAVES,
902636
+        .features[FEAT_6_EAX] =
902636
+            CPUID_6_EAX_ARAT,
902636
+        .features[FEAT_SVM] =
902636
+            CPUID_SVM_NPT | CPUID_SVM_NRIPSAVE,
902636
+        .xlevel = 0x8000001E,
902636
+        .model_id = "AMD EPYC-Rome Processor",
902636
+        .cache_info = &epyc_rome_cache_info,
902636
+    },
902636
 };
902636
 
902636
 /* KVM-specific features that are automatically added/removed
902636
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
902636
index 7bfbf2a5e5..f3da25cb8a 100644
902636
--- a/target/i386/cpu.h
902636
+++ b/target/i386/cpu.h
902636
@@ -792,6 +792,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
902636
 #define CPUID_8000_0008_EBX_WBNOINVD    (1U << 9)
902636
 /* Indirect Branch Prediction Barrier */
902636
 #define CPUID_8000_0008_EBX_IBPB        (1U << 12)
902636
+/* Single Thread Indirect Branch Predictors */
902636
+#define CPUID_8000_0008_EBX_STIBP       (1U << 15)
902636
 
902636
 #define CPUID_XSAVE_XSAVEOPT   (1U << 0)
902636
 #define CPUID_XSAVE_XSAVEC     (1U << 1)
902636
-- 
902636
2.27.0
902636