From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421591928380.1974471694191; Tue, 15 May 2018 14:59:51 -0700 (PDT) Received: from localhost ([::1]:34908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhz5-0003FR-6G for importer@patchew.org; Tue, 15 May 2018 17:59:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhuj-0008LD-Vy for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhui-00010b-L7 for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhui-00010O-7n for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7BA730D34F1; Tue, 15 May 2018 21:55:18 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0F9327190; Tue, 15 May 2018 21:55:15 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:30 -0300 Message-Id: <20180515215436.6457-2-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 15 May 2018 21:55:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/7] i386: add KnightsMill cpu model X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boqun Feng , Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Boqun Feng A new cpu model called "KnightsMill" is added to model Knights Mill processors. Compared to "Skylake-Server" cpu model, the following features are added: avx512_4vnniw avx512_4fmaps avx512pf avx512er avx512_vpopcntdq and the following features are removed: pcid invpcid clflushopt avx512dq avx512bw clwb smap rtm mpx xsavec xgetbv1 hle Signed-off-by: Boqun Feng Message-Id: <20180320000821.8337-1-boqun.feng@intel.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b0a1c629a3..52fd35b6a1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1839,6 +1839,48 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .xlevel =3D 0x80000008, .model_id =3D "Intel Xeon Processor (Skylake, IBRS)", }, + { + .name =3D "KnightsMill", + .level =3D 0xd, + .vendor =3D CPUID_VENDOR_INTEL, + .family =3D 6, + .model =3D 133, + .stepping =3D 0, + .features[FEAT_1_EDX] =3D + CPUID_VME | CPUID_SS | CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | + CPUID_MMX | CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CM= OV | + CPUID_MCA | CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | + CPUID_CX8 | CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | + CPUID_PSE | CPUID_DE | CPUID_FP87, + .features[FEAT_1_ECX] =3D + CPUID_EXT_AVX | CPUID_EXT_XSAVE | CPUID_EXT_AES | + CPUID_EXT_POPCNT | CPUID_EXT_X2APIC | CPUID_EXT_SSE42 | + CPUID_EXT_SSE41 | CPUID_EXT_CX16 | CPUID_EXT_SSSE3 | + CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3 | + CPUID_EXT_TSC_DEADLINE_TIMER | CPUID_EXT_FMA | CPUID_EXT_MOVBE= | + CPUID_EXT_F16C | CPUID_EXT_RDRAND, + .features[FEAT_8000_0001_EDX] =3D + CPUID_EXT2_LM | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP | + CPUID_EXT2_NX | CPUID_EXT2_SYSCALL, + .features[FEAT_8000_0001_ECX] =3D + CPUID_EXT3_ABM | CPUID_EXT3_LAHF_LM | CPUID_EXT3_3DNOWPREFETCH, + .features[FEAT_7_0_EBX] =3D + CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AV= X2 | + CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | + CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_AVX51= 2F | + CPUID_7_0_EBX_AVX512CD | CPUID_7_0_EBX_AVX512PF | + CPUID_7_0_EBX_AVX512ER, + .features[FEAT_7_0_ECX] =3D + CPUID_7_0_ECX_AVX512_VPOPCNTDQ, + .features[FEAT_7_0_EDX] =3D + CPUID_7_0_EDX_AVX512_4VNNIW | CPUID_7_0_EDX_AVX512_4FMAPS, + .features[FEAT_XSAVE] =3D + CPUID_XSAVE_XSAVEOPT, + .features[FEAT_6_EAX] =3D + CPUID_6_EAX_ARAT, + .xlevel =3D 0x80000008, + .model_id =3D "Intel Xeon Phi Processor (Knights Mill)", + }, { .name =3D "Opteron_G1", .level =3D 5, --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421725007194.50788298471662; Tue, 15 May 2018 15:02:05 -0700 (PDT) Received: from localhost ([::1]:34968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIi19-0004id-WE for importer@patchew.org; Tue, 15 May 2018 18:02:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhuq-0008Pf-Dz for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhun-00011Z-9n for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhum-00011D-V7 for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC8391CCC2B; Tue, 15 May 2018 21:55:23 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A79B10512; Tue, 15 May 2018 21:55:23 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:31 -0300 Message-Id: <20180515215436.6457-3-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 15 May 2018 21:55:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/7] x86/cpu: Enable CLDEMOTE(Demote Cache Line) cpu feature X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , Jingqi Liu , qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jingqi Liu The CLDEMOTE instruction hints to hardware that the cache line that contains the linear address should be moved("demoted") from the cache(s) closest to the processor core to a level more distant from the processor core. This may accelerate subsequent accesses to the line by other cores in the same coherence domain, especially if the line was written by the core that demotes the line. Intel Snow Ridge has added new cpu feature, CLDEMOTE. The new cpu feature needs to be exposed to guest VM. The bit definition: CPUID.(EAX=3D7,ECX=3D0):ECX[bit 25] CLDEMOTE The release document ref below link: https://software.intel.com/sites/default/files/managed/c5/15/\ architecture-instruction-set-extensions-programming-reference.pdf Signed-off-by: Jingqi Liu Message-Id: <1525406253-54846-1-git-send-email-jingqi.liu@intel.com> Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost --- target/i386/cpu.h | 1 + target/i386/cpu.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b58b779bff..8fbe1537c1 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -680,6 +680,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_ECX_AVX512_VPOPCNTDQ (1U << 14) /* POPCNT for vectors of= DW/QW */ #define CPUID_7_0_ECX_LA57 (1U << 16) #define CPUID_7_0_ECX_RDPID (1U << 22) +#define CPUID_7_0_ECX_CLDEMOTE (1U << 25) /* CLDEMOTE Instruction */ =20 #define CPUID_7_0_EDX_AVX512_4VNNIW (1U << 2) /* AVX512 Neural Network Ins= tructions */ #define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accumulat= ion Single Precision */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 52fd35b6a1..4b39ab5dd4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -494,7 +494,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS]= =3D { "avx512bitalg", NULL, "avx512-vpopcntdq", NULL, "la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL, - NULL, NULL, NULL, NULL, + NULL, "cldemote", NULL, NULL, NULL, NULL, NULL, NULL, }, .cpuid_eax =3D 7, --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421608073969.3902960085197; Tue, 15 May 2018 15:00:08 -0700 (PDT) Received: from localhost ([::1]:34910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhzL-0003Pr-5L for importer@patchew.org; Tue, 15 May 2018 18:00:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhus-0008RQ-IQ for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhup-00012N-HH for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45944) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhup-000120-72 for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:27 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46DD430C0A21; Tue, 15 May 2018 21:55:26 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8166030012B9; Tue, 15 May 2018 21:55:25 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:32 -0300 Message-Id: <20180515215436.6457-4-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 15 May 2018 21:55:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] i386: Helpers to encode cache information consistently X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of having a collection of macros that need to be used in complex expressions to build CPUID data, define a CPUCacheInfo struct that can hold information about a given cache. Helper functions will take a CPUCacheInfo struct as input to encode CPUID leaves for a cache. This will help us ensure consistency between cache information CPUID leaves, and make the existing inconsistencies in CPUID info more visible. Signed-off-by: Eduardo Habkost Signed-off-by: Babu Moger Tested-by: Geoffrey McRae Message-Id: <20180510204148.11687-2-babu.moger@amd.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.h | 53 ++++++ target/i386/cpu.c | 495 ++++++++++++++++++++++++++++++++++++++++----------= ---- 2 files changed, 424 insertions(+), 124 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8fbe1537c1..512c69dddd 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1045,6 +1045,59 @@ typedef enum TPRAccess { TPR_ACCESS_WRITE, } TPRAccess; =20 +/* Cache information data structures: */ + +enum CacheType { + DCACHE, + ICACHE, + UNIFIED_CACHE +}; + +typedef struct CPUCacheInfo { + enum CacheType type; + uint8_t level; + /* Size in bytes */ + uint32_t size; + /* Line size, in bytes */ + uint16_t line_size; + /* + * Associativity. + * Note: representation of fully-associative caches is not implemented + */ + uint8_t associativity; + /* Physical line partitions. CPUID[0x8000001D].EBX, CPUID[4].EBX */ + uint8_t partitions; + /* Number of sets. CPUID[0x8000001D].ECX, CPUID[4].ECX */ + uint32_t sets; + /* + * Lines per tag. + * AMD-specific: CPUID[0x80000005], CPUID[0x80000006]. + * (Is this synonym to @partitions?) + */ + uint8_t lines_per_tag; + + /* Self-initializing cache */ + bool self_init; + /* + * WBINVD/INVD is not guaranteed to act upon lower level caches of + * non-originating threads sharing this cache. + * CPUID[4].EDX[bit 0], CPUID[0x8000001D].EDX[bit 0] + */ + bool no_invd_sharing; + /* + * Cache is inclusive of lower cache levels. + * CPUID[4].EDX[bit 1], CPUID[0x8000001D].EDX[bit 1]. + */ + bool inclusive; + /* + * A complex function is used to index the cache, potentially using all + * address bits. CPUID[4].EDX[bit 2]. + */ + bool complex_indexing; +} CPUCacheInfo; + + + typedef struct CPUX86State { /* standard registers */ target_ulong regs[CPU_NB_REGS]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4b39ab5dd4..28bb93990e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -56,33 +56,240 @@ =20 #include "disas/capstone.h" =20 +/* Helpers for building CPUID[2] descriptors: */ + +struct CPUID2CacheDescriptorInfo { + enum CacheType type; + int level; + int size; + int line_size; + int associativity; +}; =20 -/* Cache topology CPUID constants: */ +#define KiB 1024 +#define MiB (1024 * 1024) =20 -/* CPUID Leaf 2 Descriptors */ +/* + * Known CPUID 2 cache descriptors. + * From Intel SDM Volume 2A, CPUID instruction + */ +struct CPUID2CacheDescriptorInfo cpuid2_cache_descriptors[] =3D { + [0x06] =3D { .level =3D 1, .type =3D ICACHE, .size =3D 8 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x08] =3D { .level =3D 1, .type =3D ICACHE, .size =3D 16 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x09] =3D { .level =3D 1, .type =3D ICACHE, .size =3D 32 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x0A] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 8 * Ki= B, + .associativity =3D 2, .line_size =3D 32, }, + [0x0C] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 16 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x0D] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 16 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x0E] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 24 * Ki= B, + .associativity =3D 6, .line_size =3D 64, }, + [0x1D] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 128 * Ki= B, + .associativity =3D 2, .line_size =3D 64, }, + [0x21] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 * Ki= B, + .associativity =3D 8, .line_size =3D 64, }, + /* lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x22, 0x23 are not included + */ + [0x24] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + /* lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x25, 0x20 are not included + */ + [0x2C] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 32 * Ki= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x30] =3D { .level =3D 1, .type =3D ICACHE, .size =3D 32 * Ki= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x41] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 128 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x42] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x43] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x44] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x45] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 4, .line_size =3D 32, }, + [0x46] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 4 * Mi= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x47] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 8 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x48] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 3 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + /* Descriptor 0x49 depends on CPU family/model, so it is not included = */ + [0x4A] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 6 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + [0x4B] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 8 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + [0x4C] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 12 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + [0x4D] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 16 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + [0x4E] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 6 * Mi= B, + .associativity =3D 24, .line_size =3D 64, }, + [0x60] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 16 * Ki= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x66] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 8 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x67] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 16 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x68] =3D { .level =3D 1, .type =3D DCACHE, .size =3D 32 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x78] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 4, .line_size =3D 64, }, + /* lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x79, 0x7A, 0x7B, 0x7C are not included. + */ + [0x7D] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x7F] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 2, .line_size =3D 64, }, + [0x80] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 8, .line_size =3D 64, }, + [0x82] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 * Ki= B, + .associativity =3D 8, .line_size =3D 32, }, + [0x83] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 8, .line_size =3D 32, }, + [0x84] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 8, .line_size =3D 32, }, + [0x85] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 8, .line_size =3D 32, }, + [0x86] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0x87] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0xD0] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 512 * Ki= B, + .associativity =3D 4, .line_size =3D 64, }, + [0xD1] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 4, .line_size =3D 64, }, + [0xD2] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 4, .line_size =3D 64, }, + [0xD6] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 1 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0xD7] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0xD8] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 4 * Mi= B, + .associativity =3D 8, .line_size =3D 64, }, + [0xDC] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 1.5 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + [0xDD] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 3 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + [0xDE] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 6 * Mi= B, + .associativity =3D 12, .line_size =3D 64, }, + [0xE2] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 2 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + [0xE3] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 4 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + [0xE4] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 8 * Mi= B, + .associativity =3D 16, .line_size =3D 64, }, + [0xEA] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 12 * Mi= B, + .associativity =3D 24, .line_size =3D 64, }, + [0xEB] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 18 * Mi= B, + .associativity =3D 24, .line_size =3D 64, }, + [0xEC] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 24 * Mi= B, + .associativity =3D 24, .line_size =3D 64, }, +}; + +/* + * "CPUID leaf 2 does not report cache descriptor information, + * use CPUID leaf 4 to query cache parameters" + */ +#define CACHE_DESCRIPTOR_UNAVAILABLE 0xFF =20 -#define CPUID_2_L1D_32KB_8WAY_64B 0x2c -#define CPUID_2_L1I_32KB_8WAY_64B 0x30 -#define CPUID_2_L2_2MB_8WAY_64B 0x7d -#define CPUID_2_L3_16MB_16WAY_64B 0x4d +/* + * Return a CPUID 2 cache descriptor for a given cache. + * If no known descriptor is found, return CACHE_DESCRIPTOR_UNAVAILABLE + */ +static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *cache) +{ + int i; + + assert(cache->size > 0); + assert(cache->level > 0); + assert(cache->line_size > 0); + assert(cache->associativity > 0); + for (i =3D 0; i < ARRAY_SIZE(cpuid2_cache_descriptors); i++) { + struct CPUID2CacheDescriptorInfo *d =3D &cpuid2_cache_descriptors[= i]; + if (d->level =3D=3D cache->level && d->type =3D=3D cache->type && + d->size =3D=3D cache->size && d->line_size =3D=3D cache->line_= size && + d->associativity =3D=3D cache->associativity) { + return i; + } + } =20 + return CACHE_DESCRIPTOR_UNAVAILABLE; +} =20 /* CPUID Leaf 4 constants: */ =20 /* EAX: */ -#define CPUID_4_TYPE_DCACHE 1 -#define CPUID_4_TYPE_ICACHE 2 -#define CPUID_4_TYPE_UNIFIED 3 +#define CACHE_TYPE_D 1 +#define CACHE_TYPE_I 2 +#define CACHE_TYPE_UNIFIED 3 =20 -#define CPUID_4_LEVEL(l) ((l) << 5) +#define CACHE_LEVEL(l) (l << 5) =20 -#define CPUID_4_SELF_INIT_LEVEL (1 << 8) -#define CPUID_4_FULLY_ASSOC (1 << 9) +#define CACHE_SELF_INIT_LEVEL (1 << 8) =20 /* EDX: */ -#define CPUID_4_NO_INVD_SHARING (1 << 0) -#define CPUID_4_INCLUSIVE (1 << 1) -#define CPUID_4_COMPLEX_IDX (1 << 2) +#define CACHE_NO_INVD_SHARING (1 << 0) +#define CACHE_INCLUSIVE (1 << 1) +#define CACHE_COMPLEX_IDX (1 << 2) + +/* Encode CacheType for CPUID[4].EAX */ +#define CACHE_TYPE(t) (((t) =3D=3D DCACHE) ? CACHE_TYPE_D : \ + ((t) =3D=3D ICACHE) ? CACHE_TYPE_I : \ + ((t) =3D=3D UNIFIED_CACHE) ? CACHE_TYPE_UNIFIED := \ + 0 /* Invalid value */) + + +/* Encode cache info for CPUID[4] */ +static void encode_cache_cpuid4(CPUCacheInfo *cache, + int num_apic_ids, int num_cores, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + assert(cache->size =3D=3D cache->line_size * cache->associativity * + cache->partitions * cache->sets); + + assert(num_apic_ids > 0); + *eax =3D CACHE_TYPE(cache->type) | + CACHE_LEVEL(cache->level) | + (cache->self_init ? CACHE_SELF_INIT_LEVEL : 0) | + ((num_cores - 1) << 26) | + ((num_apic_ids - 1) << 14); + + assert(cache->line_size > 0); + assert(cache->partitions > 0); + assert(cache->associativity > 0); + /* We don't implement fully-associative caches */ + assert(cache->associativity < cache->sets); + *ebx =3D (cache->line_size - 1) | + ((cache->partitions - 1) << 12) | + ((cache->associativity - 1) << 22); + + assert(cache->sets > 0); + *ecx =3D cache->sets - 1; + + *edx =3D (cache->no_invd_sharing ? CACHE_NO_INVD_SHARING : 0) | + (cache->inclusive ? CACHE_INCLUSIVE : 0) | + (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); +} + +/* Encode cache info for CPUID[0x80000005].ECX or CPUID[0x80000005].EDX */ +static uint32_t encode_cache_cpuid80000005(CPUCacheInfo *cache) +{ + assert(cache->size % 1024 =3D=3D 0); + assert(cache->lines_per_tag > 0); + assert(cache->associativity > 0); + assert(cache->line_size > 0); + return ((cache->size / 1024) << 24) | (cache->associativity << 16) | + (cache->lines_per_tag << 8) | (cache->line_size); +} =20 #define ASSOC_FULL 0xFF =20 @@ -100,57 +307,140 @@ a =3D=3D ASSOC_FULL ? 0xF : \ 0 /* invalid value */) =20 +/* + * Encode cache info for CPUID[0x80000006].ECX and CPUID[0x80000006].EDX + * @l3 can be NULL. + */ +static void encode_cache_cpuid80000006(CPUCacheInfo *l2, + CPUCacheInfo *l3, + uint32_t *ecx, uint32_t *edx) +{ + assert(l2->size % 1024 =3D=3D 0); + assert(l2->associativity > 0); + assert(l2->lines_per_tag > 0); + assert(l2->line_size > 0); + *ecx =3D ((l2->size / 1024) << 16) | + (AMD_ENC_ASSOC(l2->associativity) << 12) | + (l2->lines_per_tag << 8) | (l2->line_size); + + if (l3) { + assert(l3->size % (512 * 1024) =3D=3D 0); + assert(l3->associativity > 0); + assert(l3->lines_per_tag > 0); + assert(l3->line_size > 0); + *edx =3D ((l3->size / (512 * 1024)) << 18) | + (AMD_ENC_ASSOC(l3->associativity) << 12) | + (l3->lines_per_tag << 8) | (l3->line_size); + } else { + *edx =3D 0; + } +} =20 /* Definitions of the hardcoded cache entries we expose: */ =20 /* L1 data cache: */ -#define L1D_LINE_SIZE 64 -#define L1D_ASSOCIATIVITY 8 -#define L1D_SETS 64 -#define L1D_PARTITIONS 1 -/* Size =3D LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS =3D 32KiB */ -#define L1D_DESCRIPTOR CPUID_2_L1D_32KB_8WAY_64B +static CPUCacheInfo l1d_cache =3D { + .type =3D DCACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, +}; + /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -#define L1D_LINES_PER_TAG 1 -#define L1D_SIZE_KB_AMD 64 -#define L1D_ASSOCIATIVITY_AMD 2 +static CPUCacheInfo l1d_cache_amd =3D { + .type =3D DCACHE, + .level =3D 1, + .size =3D 64 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 2, + .sets =3D 512, + .partitions =3D 1, + .lines_per_tag =3D 1, + .no_invd_sharing =3D true, +}; =20 /* L1 instruction cache: */ -#define L1I_LINE_SIZE 64 -#define L1I_ASSOCIATIVITY 8 -#define L1I_SETS 64 -#define L1I_PARTITIONS 1 -/* Size =3D LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS =3D 32KiB */ -#define L1I_DESCRIPTOR CPUID_2_L1I_32KB_8WAY_64B +static CPUCacheInfo l1i_cache =3D { + .type =3D ICACHE, + .level =3D 1, + .size =3D 32 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 64, + .partitions =3D 1, + .no_invd_sharing =3D true, +}; + /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -#define L1I_LINES_PER_TAG 1 -#define L1I_SIZE_KB_AMD 64 -#define L1I_ASSOCIATIVITY_AMD 2 +static CPUCacheInfo l1i_cache_amd =3D { + .type =3D ICACHE, + .level =3D 1, + .size =3D 64 * KiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 2, + .sets =3D 512, + .partitions =3D 1, + .lines_per_tag =3D 1, + .no_invd_sharing =3D true, +}; =20 /* Level 2 unified cache: */ -#define L2_LINE_SIZE 64 -#define L2_ASSOCIATIVITY 16 -#define L2_SETS 4096 -#define L2_PARTITIONS 1 -/* Size =3D LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS =3D 4MiB */ +static CPUCacheInfo l2_cache =3D { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 4 * MiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 4096, + .partitions =3D 1, + .no_invd_sharing =3D true, +}; + /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ -#define L2_DESCRIPTOR CPUID_2_L2_2MB_8WAY_64B +static CPUCacheInfo l2_cache_cpuid2 =3D { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 2 * MiB, + .line_size =3D 64, + .associativity =3D 8, +}; + + /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ -#define L2_LINES_PER_TAG 1 -#define L2_SIZE_KB_AMD 512 +static CPUCacheInfo l2_cache_amd =3D { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 512 * KiB, + .line_size =3D 64, + .lines_per_tag =3D 1, + .associativity =3D 16, + .sets =3D 512, + .partitions =3D 1, +}; =20 /* Level 3 unified cache: */ -#define L3_SIZE_KB 0 /* disabled */ -#define L3_ASSOCIATIVITY 0 /* disabled */ -#define L3_LINES_PER_TAG 0 /* disabled */ -#define L3_LINE_SIZE 0 /* disabled */ -#define L3_N_LINE_SIZE 64 -#define L3_N_ASSOCIATIVITY 16 -#define L3_N_SETS 16384 -#define L3_N_PARTITIONS 1 -#define L3_N_DESCRIPTOR CPUID_2_L3_16MB_16WAY_64B -#define L3_N_LINES_PER_TAG 1 -#define L3_N_SIZE_KB_AMD 16384 +static CPUCacheInfo l3_cache =3D { + .type =3D UNIFIED_CACHE, + .level =3D 3, + .size =3D 16 * MiB, + .line_size =3D 64, + .associativity =3D 16, + .sets =3D 16384, + .partitions =3D 1, + .lines_per_tag =3D 1, + .self_init =3D true, + .inclusive =3D true, + .complex_indexing =3D true, +}; =20 /* TLB definitions: */ =20 @@ -3344,85 +3634,53 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, if (!cpu->enable_l3_cache) { *ecx =3D 0; } else { - *ecx =3D L3_N_DESCRIPTOR; + *ecx =3D cpuid2_cache_descriptor(&l3_cache); } - *edx =3D (L1D_DESCRIPTOR << 16) | \ - (L1I_DESCRIPTOR << 8) | \ - (L2_DESCRIPTOR); + *edx =3D (cpuid2_cache_descriptor(&l1d_cache) << 16) | + (cpuid2_cache_descriptor(&l1i_cache) << 8) | + (cpuid2_cache_descriptor(&l2_cache_cpuid2)); break; case 4: /* cache info: needed for Core compatibility */ if (cpu->cache_info_passthrough) { host_cpuid(index, count, eax, ebx, ecx, edx); + /* QEMU gives out its own APIC IDs, never pass down bits 31..2= 6. */ *eax &=3D ~0xFC000000; + if ((*eax & 31) && cs->nr_cores > 1) { + *eax |=3D (cs->nr_cores - 1) << 26; + } } else { *eax =3D 0; switch (count) { case 0: /* L1 dcache info */ - *eax |=3D CPUID_4_TYPE_DCACHE | \ - CPUID_4_LEVEL(1) | \ - CPUID_4_SELF_INIT_LEVEL; - *ebx =3D (L1D_LINE_SIZE - 1) | \ - ((L1D_PARTITIONS - 1) << 12) | \ - ((L1D_ASSOCIATIVITY - 1) << 22); - *ecx =3D L1D_SETS - 1; - *edx =3D CPUID_4_NO_INVD_SHARING; + encode_cache_cpuid4(&l1d_cache, + 1, cs->nr_cores, + eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - *eax |=3D CPUID_4_TYPE_ICACHE | \ - CPUID_4_LEVEL(1) | \ - CPUID_4_SELF_INIT_LEVEL; - *ebx =3D (L1I_LINE_SIZE - 1) | \ - ((L1I_PARTITIONS - 1) << 12) | \ - ((L1I_ASSOCIATIVITY - 1) << 22); - *ecx =3D L1I_SETS - 1; - *edx =3D CPUID_4_NO_INVD_SHARING; + encode_cache_cpuid4(&l1i_cache, + 1, cs->nr_cores, + eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - *eax |=3D CPUID_4_TYPE_UNIFIED | \ - CPUID_4_LEVEL(2) | \ - CPUID_4_SELF_INIT_LEVEL; - if (cs->nr_threads > 1) { - *eax |=3D (cs->nr_threads - 1) << 14; - } - *ebx =3D (L2_LINE_SIZE - 1) | \ - ((L2_PARTITIONS - 1) << 12) | \ - ((L2_ASSOCIATIVITY - 1) << 22); - *ecx =3D L2_SETS - 1; - *edx =3D CPUID_4_NO_INVD_SHARING; + encode_cache_cpuid4(&l2_cache, + cs->nr_threads, cs->nr_cores, + eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - if (!cpu->enable_l3_cache) { - *eax =3D 0; - *ebx =3D 0; - *ecx =3D 0; - *edx =3D 0; + pkg_offset =3D apicid_pkg_offset(cs->nr_cores, cs->nr_thre= ads); + if (cpu->enable_l3_cache) { + encode_cache_cpuid4(&l3_cache, + (1 << pkg_offset), cs->nr_cores, + eax, ebx, ecx, edx); break; } - *eax |=3D CPUID_4_TYPE_UNIFIED | \ - CPUID_4_LEVEL(3) | \ - CPUID_4_SELF_INIT_LEVEL; - pkg_offset =3D apicid_pkg_offset(cs->nr_cores, cs->nr_thre= ads); - *eax |=3D ((1 << pkg_offset) - 1) << 14; - *ebx =3D (L3_N_LINE_SIZE - 1) | \ - ((L3_N_PARTITIONS - 1) << 12) | \ - ((L3_N_ASSOCIATIVITY - 1) << 22); - *ecx =3D L3_N_SETS - 1; - *edx =3D CPUID_4_INCLUSIVE | CPUID_4_COMPLEX_IDX; - break; + /* fall through */ default: /* end of info */ - *eax =3D 0; - *ebx =3D 0; - *ecx =3D 0; - *edx =3D 0; + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } } - - /* QEMU gives out its own APIC IDs, never pass down bits 31..26. = */ - if ((*eax & 31) && cs->nr_cores > 1) { - *eax |=3D (cs->nr_cores - 1) << 26; - } break; case 5: /* mwait info: needed for Core compatibility */ @@ -3626,10 +3884,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx =3D (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | \ (L1_ITLB_4K_ASSOC << 8) | (L1_ITLB_4K_ENTRIES); - *ecx =3D (L1D_SIZE_KB_AMD << 24) | (L1D_ASSOCIATIVITY_AMD << 16) |= \ - (L1D_LINES_PER_TAG << 8) | (L1D_LINE_SIZE); - *edx =3D (L1I_SIZE_KB_AMD << 24) | (L1I_ASSOCIATIVITY_AMD << 16) |= \ - (L1I_LINES_PER_TAG << 8) | (L1I_LINE_SIZE); + *ecx =3D encode_cache_cpuid80000005(&l1d_cache_amd); + *edx =3D encode_cache_cpuid80000005(&l1i_cache_amd); break; case 0x80000006: /* cache info (L2 cache) */ @@ -3645,18 +3901,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | \ (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | \ (L2_ITLB_4K_ENTRIES); - *ecx =3D (L2_SIZE_KB_AMD << 16) | \ - (AMD_ENC_ASSOC(L2_ASSOCIATIVITY) << 12) | \ - (L2_LINES_PER_TAG << 8) | (L2_LINE_SIZE); - if (!cpu->enable_l3_cache) { - *edx =3D ((L3_SIZE_KB / 512) << 18) | \ - (AMD_ENC_ASSOC(L3_ASSOCIATIVITY) << 12) | \ - (L3_LINES_PER_TAG << 8) | (L3_LINE_SIZE); - } else { - *edx =3D ((L3_N_SIZE_KB_AMD / 512) << 18) | \ - (AMD_ENC_ASSOC(L3_N_ASSOCIATIVITY) << 12) | \ - (L3_N_LINES_PER_TAG << 8) | (L3_N_LINE_SIZE); - } + encode_cache_cpuid80000006(&l2_cache_amd, + cpu->enable_l3_cache ? &l3_cache : NULL, + ecx, edx); break; case 0x80000007: *eax =3D 0; --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421456757116.52743495873585; Tue, 15 May 2018 14:57:36 -0700 (PDT) Received: from localhost ([::1]:34797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhwt-0001DB-Vi for importer@patchew.org; Tue, 15 May 2018 17:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhus-0008RL-Df for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhur-00015f-Em for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhur-00014N-95 for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:29 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FD37C113813; Tue, 15 May 2018 21:55:28 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id C105D30012B1; Tue, 15 May 2018 21:55:27 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:33 -0300 Message-Id: <20180515215436.6457-5-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 15 May 2018 21:55:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/7] i386: Add cache information in X86CPUDefinition X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Babu Moger , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Babu Moger Add cache information in X86CPUDefinition and CPUX86State. Signed-off-by: Babu Moger Tested-by: Geoffrey McRae Reviewed-by: Eduardo Habkost Message-Id: <20180510204148.11687-3-babu.moger@amd.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.h | 7 +++++++ target/i386/cpu.c | 1 + 2 files changed, 8 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 512c69dddd..ac94013c4a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1097,6 +1097,12 @@ typedef struct CPUCacheInfo { } CPUCacheInfo; =20 =20 +typedef struct CPUCaches { + CPUCacheInfo l1d_cache; + CPUCacheInfo l1i_cache; + CPUCacheInfo l2_cache; + CPUCacheInfo l3_cache; +} CPUCaches; =20 typedef struct CPUX86State { /* standard registers */ @@ -1286,6 +1292,7 @@ typedef struct CPUX86State { /* Features that were explicitly enabled/disabled */ FeatureWordArray user_features; uint32_t cpuid_model[12]; + CPUCaches *cache_info; =20 /* MTRRs */ uint64_t mtrr_fixed[11]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 28bb93990e..55685ed19d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1106,6 +1106,7 @@ struct X86CPUDefinition { int stepping; FeatureWordArray features; const char *model_id; + CPUCaches *cache_info; }; =20 static X86CPUDefinition builtin_x86_defs[] =3D { --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152642151154547.290983793105966; Tue, 15 May 2018 14:58:31 -0700 (PDT) Received: from localhost ([::1]:34799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhxm-0001uL-5n for importer@patchew.org; Tue, 15 May 2018 17:58:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhuu-0008Sv-AL for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhut-00016n-FQ for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56609) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhut-00016Q-9q for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BCC330D8784; Tue, 15 May 2018 21:55:30 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id D548C1778D; Tue, 15 May 2018 21:55:29 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:34 -0300 Message-Id: <20180515215436.6457-6-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 15 May 2018 21:55:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/7] i386: Initialize cache information for EPYC family processors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Babu Moger , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Babu Moger Initialize pre-determined cache information for EPYC processors. Signed-off-by: Babu Moger Tested-by: Geoffrey McRae Message-Id: <20180510204148.11687-5-babu.moger@amd.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 55685ed19d..174a8f434b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1109,6 +1109,56 @@ struct X86CPUDefinition { CPUCaches *cache_info; }; =20 +static CPUCaches epyc_cache_info =3D { + .l1d_cache =3D { + .type =3D DCACHE, + .level =3D 1, + .size =3D 32 * KiB, + .line_size =3D 64, + .associativity =3D 8, + .partitions =3D 1, + .sets =3D 64, + .lines_per_tag =3D 1, + .self_init =3D 1, + .no_invd_sharing =3D true, + }, + .l1i_cache =3D { + .type =3D ICACHE, + .level =3D 1, + .size =3D 64 * KiB, + .line_size =3D 64, + .associativity =3D 4, + .partitions =3D 1, + .sets =3D 256, + .lines_per_tag =3D 1, + .self_init =3D 1, + .no_invd_sharing =3D true, + }, + .l2_cache =3D { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 512 * KiB, + .line_size =3D 64, + .associativity =3D 8, + .partitions =3D 1, + .sets =3D 1024, + .lines_per_tag =3D 1, + }, + .l3_cache =3D { + .type =3D UNIFIED_CACHE, + .level =3D 3, + .size =3D 8 * MiB, + .line_size =3D 64, + .associativity =3D 16, + .partitions =3D 1, + .sets =3D 8192, + .lines_per_tag =3D 1, + .self_init =3D true, + .inclusive =3D true, + .complex_indexing =3D true, + }, +}; + static X86CPUDefinition builtin_x86_defs[] =3D { { .name =3D "qemu64", @@ -2345,6 +2395,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { CPUID_6_EAX_ARAT, .xlevel =3D 0x8000000A, .model_id =3D "AMD EPYC Processor", + .cache_info =3D &epyc_cache_info, }, { .name =3D "EPYC-IBPB", @@ -2391,6 +2442,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { CPUID_6_EAX_ARAT, .xlevel =3D 0x8000000A, .model_id =3D "AMD EPYC Processor (with IBPB)", + .cache_info =3D &epyc_cache_info, }, }; =20 --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421463227718.3615811638603; Tue, 15 May 2018 14:57:43 -0700 (PDT) Received: from localhost ([::1]:34798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhx0-0001Ir-Fs for importer@patchew.org; Tue, 15 May 2018 17:57:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhuw-0008Un-Br for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhuv-000189-GT for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhuv-00017p-85 for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51B27C113800; Tue, 15 May 2018 21:55:32 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id C651B21EF6; Tue, 15 May 2018 21:55:31 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:35 -0300 Message-Id: <20180515215436.6457-7-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 15 May 2018 21:55:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] pc: add 2.13 machine types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Babu Moger , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Babu Moger Add pc-q35-2.13 and pc-i440fx-2.13 machine types Signed-off-by: Babu Moger Message-Id: <20180514164156.27034-2-babu.moger@amd.com> Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost --- include/hw/i386/pc.h | 3 +++ hw/i386/pc_piix.c | 15 ++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 2a98e3ad68..d4fe073cb8 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -296,6 +296,9 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); =20 +#define PC_COMPAT_2_12 \ + HW_COMPAT_2_12 \ + #define PC_COMPAT_2_11 \ HW_COMPAT_2_11 \ {\ diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 729a0508aa..e36c7bbb40 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -425,21 +425,30 @@ static void pc_i440fx_machine_options(MachineClass *m) m->default_display =3D "std"; } =20 -static void pc_i440fx_2_12_machine_options(MachineClass *m) +static void pc_i440fx_2_13_machine_options(MachineClass *m) { pc_i440fx_machine_options(m); m->alias =3D "pc"; m->is_default =3D 1; } =20 +DEFINE_I440FX_MACHINE(v2_13, "pc-i440fx-2.13", NULL, + pc_i440fx_2_13_machine_options); + +static void pc_i440fx_2_12_machine_options(MachineClass *m) +{ + pc_i440fx_2_13_machine_options(m); + m->is_default =3D 0; + m->alias =3D NULL; + SET_MACHINE_COMPAT(m, PC_COMPAT_2_12); +} + DEFINE_I440FX_MACHINE(v2_12, "pc-i440fx-2.12", NULL, pc_i440fx_2_12_machine_options); =20 static void pc_i440fx_2_11_machine_options(MachineClass *m) { pc_i440fx_2_12_machine_options(m); - m->is_default =3D 0; - m->alias =3D NULL; SET_MACHINE_COMPAT(m, PC_COMPAT_2_11); } =20 diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 9ae916327e..2372457c6a 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -308,12 +308,22 @@ static void pc_q35_machine_options(MachineClass *m) m->max_cpus =3D 288; } =20 -static void pc_q35_2_12_machine_options(MachineClass *m) +static void pc_q35_2_13_machine_options(MachineClass *m) { pc_q35_machine_options(m); m->alias =3D "q35"; } =20 +DEFINE_Q35_MACHINE(v2_13, "pc-q35-2.13", NULL, + pc_q35_2_13_machine_options); + +static void pc_q35_2_12_machine_options(MachineClass *m) +{ + pc_q35_2_13_machine_options(m); + m->alias =3D NULL; + SET_MACHINE_COMPAT(m, PC_COMPAT_2_12); +} + DEFINE_Q35_MACHINE(v2_12, "pc-q35-2.12", NULL, pc_q35_2_12_machine_options); =20 @@ -323,7 +333,6 @@ static void pc_q35_2_11_machine_options(MachineClass *m) =20 pc_q35_2_12_machine_options(m); pcmc->default_nic_model =3D "e1000"; - m->alias =3D NULL; SET_MACHINE_COMPAT(m, PC_COMPAT_2_11); } =20 --=20 2.14.3 From nobody Sat Apr 20 03:56:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526421737365590.203996775235; Tue, 15 May 2018 15:02:17 -0700 (PDT) Received: from localhost ([::1]:34974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIi1Q-0004sk-Fq for importer@patchew.org; Tue, 15 May 2018 18:02:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIhuz-00006O-Ja for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIhuy-0001AH-4L for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIhux-0001A5-Qi for qemu-devel@nongnu.org; Tue, 15 May 2018 17:55:36 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D65F330C021E; Tue, 15 May 2018 21:55:34 +0000 (UTC) Received: from localhost (ovpn-116-15.gru2.redhat.com [10.97.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3918930012D6; Tue, 15 May 2018 21:55:34 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Tue, 15 May 2018 18:54:36 -0300 Message-Id: <20180515215436.6457-8-ehabkost@redhat.com> In-Reply-To: <20180515215436.6457-1-ehabkost@redhat.com> References: <20180515215436.6457-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 15 May 2018 21:55:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/7] i386: Add new property to control cache info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Babu Moger , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Babu Moger The property legacy-cache will be used to control the cache information. If user passes "-cpu legacy-cache" then older information will be displayed even if the hardware supports new information. Otherwise use the statically loaded cache definitions if available. Renamed the previous cache structures to legacy_*. If there is any change in the cache information, then it needs to be initialized in builtin_x86_defs. Signed-off-by: Babu Moger Tested-by: Geoffrey McRae Message-Id: <20180514164156.27034-3-babu.moger@amd.com> Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost --- include/hw/i386/pc.h | 5 +++ target/i386/cpu.h | 5 +++ target/i386/cpu.c | 97 ++++++++++++++++++++++++++++++++++++++----------= ---- 3 files changed, 81 insertions(+), 26 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index d4fe073cb8..a0c269fc34 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -298,6 +298,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_= t *); =20 #define PC_COMPAT_2_12 \ HW_COMPAT_2_12 \ + {\ + .driver =3D TYPE_X86_CPU,\ + .property =3D "legacy-cache",\ + .value =3D "on",\ + }, =20 #define PC_COMPAT_2_11 \ HW_COMPAT_2_11 \ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index ac94013c4a..8bc54d70bf 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1399,6 +1399,11 @@ struct X86CPU { */ bool enable_l3_cache; =20 + /* Compatibility bits for old machine types. + * If true present the old cache topology information + */ + bool legacy_cache; + /* Compatibility bits for old machine types: */ bool enable_cpuid_0xb; =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 174a8f434b..e5e66a75d4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -336,10 +336,14 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *= l2, } } =20 -/* Definitions of the hardcoded cache entries we expose: */ +/* + * Definitions of the hardcoded cache entries we expose: + * These are legacy cache values. If there is a need to change any + * of these values please use builtin_x86_defs + */ =20 /* L1 data cache: */ -static CPUCacheInfo l1d_cache =3D { +static CPUCacheInfo legacy_l1d_cache =3D { .type =3D DCACHE, .level =3D 1, .size =3D 32 * KiB, @@ -352,7 +356,7 @@ static CPUCacheInfo l1d_cache =3D { }; =20 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l1d_cache_amd =3D { +static CPUCacheInfo legacy_l1d_cache_amd =3D { .type =3D DCACHE, .level =3D 1, .size =3D 64 * KiB, @@ -366,7 +370,7 @@ static CPUCacheInfo l1d_cache_amd =3D { }; =20 /* L1 instruction cache: */ -static CPUCacheInfo l1i_cache =3D { +static CPUCacheInfo legacy_l1i_cache =3D { .type =3D ICACHE, .level =3D 1, .size =3D 32 * KiB, @@ -379,7 +383,7 @@ static CPUCacheInfo l1i_cache =3D { }; =20 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l1i_cache_amd =3D { +static CPUCacheInfo legacy_l1i_cache_amd =3D { .type =3D ICACHE, .level =3D 1, .size =3D 64 * KiB, @@ -393,7 +397,7 @@ static CPUCacheInfo l1i_cache_amd =3D { }; =20 /* Level 2 unified cache: */ -static CPUCacheInfo l2_cache =3D { +static CPUCacheInfo legacy_l2_cache =3D { .type =3D UNIFIED_CACHE, .level =3D 2, .size =3D 4 * MiB, @@ -406,7 +410,7 @@ static CPUCacheInfo l2_cache =3D { }; =20 /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ -static CPUCacheInfo l2_cache_cpuid2 =3D { +static CPUCacheInfo legacy_l2_cache_cpuid2 =3D { .type =3D UNIFIED_CACHE, .level =3D 2, .size =3D 2 * MiB, @@ -416,7 +420,7 @@ static CPUCacheInfo l2_cache_cpuid2 =3D { =20 =20 /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l2_cache_amd =3D { +static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, .size =3D 512 * KiB, @@ -428,7 +432,7 @@ static CPUCacheInfo l2_cache_amd =3D { }; =20 /* Level 3 unified cache: */ -static CPUCacheInfo l3_cache =3D { +static CPUCacheInfo legacy_l3_cache =3D { .type =3D UNIFIED_CACHE, .level =3D 3, .size =3D 16 * MiB, @@ -3338,6 +3342,10 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefi= nition *def, Error **errp) env->features[w] =3D def->features[w]; } =20 + /* Store Cache information from the X86CPUDefinition if available */ + env->cache_info =3D def->cache_info; + cpu->legacy_cache =3D def->cache_info ? 0 : 1; + /* Special cases not set in the X86CPUDefinition structs: */ /* TODO: in-kernel irqchip for hvf */ if (kvm_enabled()) { @@ -3687,11 +3695,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, if (!cpu->enable_l3_cache) { *ecx =3D 0; } else { - *ecx =3D cpuid2_cache_descriptor(&l3_cache); + if (env->cache_info && !cpu->legacy_cache) { + *ecx =3D cpuid2_cache_descriptor(&env->cache_info->l3_cach= e); + } else { + *ecx =3D cpuid2_cache_descriptor(&legacy_l3_cache); + } + } + if (env->cache_info && !cpu->legacy_cache) { + *edx =3D (cpuid2_cache_descriptor(&env->cache_info->l1d_cache)= << 16) | + (cpuid2_cache_descriptor(&env->cache_info->l1i_cache) <= < 8) | + (cpuid2_cache_descriptor(&env->cache_info->l2_cache)); + } else { + *edx =3D (cpuid2_cache_descriptor(&legacy_l1d_cache) << 16) | + (cpuid2_cache_descriptor(&legacy_l1i_cache) << 8) | + (cpuid2_cache_descriptor(&legacy_l2_cache_cpuid2)); } - *edx =3D (cpuid2_cache_descriptor(&l1d_cache) << 16) | - (cpuid2_cache_descriptor(&l1i_cache) << 8) | - (cpuid2_cache_descriptor(&l2_cache_cpuid2)); break; case 4: /* cache info: needed for Core compatibility */ @@ -3704,27 +3722,35 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } } else { *eax =3D 0; + CPUCacheInfo *l1d, *l1i, *l2, *l3; + if (env->cache_info && !cpu->legacy_cache) { + l1d =3D &env->cache_info->l1d_cache; + l1i =3D &env->cache_info->l1i_cache; + l2 =3D &env->cache_info->l2_cache; + l3 =3D &env->cache_info->l3_cache; + } else { + l1d =3D &legacy_l1d_cache; + l1i =3D &legacy_l1i_cache; + l2 =3D &legacy_l2_cache; + l3 =3D &legacy_l3_cache; + } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid4(&l1d_cache, - 1, cs->nr_cores, + encode_cache_cpuid4(l1d, 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid4(&l1i_cache, - 1, cs->nr_cores, + encode_cache_cpuid4(l1i, 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid4(&l2_cache, - cs->nr_threads, cs->nr_cores, + encode_cache_cpuid4(l2, cs->nr_threads, cs->nr_cores, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ pkg_offset =3D apicid_pkg_offset(cs->nr_cores, cs->nr_thre= ads); if (cpu->enable_l3_cache) { - encode_cache_cpuid4(&l3_cache, - (1 << pkg_offset), cs->nr_cores, + encode_cache_cpuid4(l3, (1 << pkg_offset), cs->nr_core= s, eax, ebx, ecx, edx); break; } @@ -3937,8 +3963,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx =3D (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | \ (L1_ITLB_4K_ASSOC << 8) | (L1_ITLB_4K_ENTRIES); - *ecx =3D encode_cache_cpuid80000005(&l1d_cache_amd); - *edx =3D encode_cache_cpuid80000005(&l1i_cache_amd); + if (env->cache_info && !cpu->legacy_cache) { + *ecx =3D encode_cache_cpuid80000005(&env->cache_info->l1d_cach= e); + *edx =3D encode_cache_cpuid80000005(&env->cache_info->l1i_cach= e); + } else { + *ecx =3D encode_cache_cpuid80000005(&legacy_l1d_cache_amd); + *edx =3D encode_cache_cpuid80000005(&legacy_l1i_cache_amd); + } break; case 0x80000006: /* cache info (L2 cache) */ @@ -3954,9 +3985,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | \ (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | \ (L2_ITLB_4K_ENTRIES); - encode_cache_cpuid80000006(&l2_cache_amd, - cpu->enable_l3_cache ? &l3_cache : NULL, - ecx, edx); + if (env->cache_info && !cpu->legacy_cache) { + encode_cache_cpuid80000006(&env->cache_info->l2_cache, + cpu->enable_l3_cache ? + &env->cache_info->l3_cache : NULL, + ecx, edx); + } else { + encode_cache_cpuid80000006(&legacy_l2_cache_amd, + cpu->enable_l3_cache ? + &legacy_l3_cache : NULL, + ecx, edx); + } break; case 0x80000007: *eax =3D 0; @@ -5135,6 +5174,12 @@ static Property x86_cpu_properties[] =3D { false), DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true), DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true), + /* + * lecacy_cache defaults to CPU model being chosen. This is set in + * x86_cpu_load_def based on cache_info which is initialized in + * builtin_x86_defs + */ + DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, false), =20 /* * From "Requirements for Implementing the Microsoft --=20 2.14.3