From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228418; cv=none; d=zohomail.com; s=zohoarc; b=HTmacrOeFr63lpTzU4Q912gi/DDd7WkXLFCXWGL31L5xGYVRVitJ1OqgfqGF0ljheqkTRAMj6mKONvbfGU610giIugCzu3gpeyAziioZqlRf0/6z72JlImtgRZiM1YErEBQBt+CZuPdRlxSWO/fogsIzOwHCuMDHeCmzmN1uR10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228418; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X1Mf2G3Q4QJnIHsJ5OMog1IefaPHndXXpgj62DHB+nM=; b=fgrQJcr1EbTF5Yyvsij4enQtA2sLU/k6BTCv6DA0Jf9Qi69ItnFC4yRqUnFGnX2gyhMITiRDmWfDwqnKUlXjsKSRbJF+2B5kJt986I37dIke+mJg6o00d34G8HCI3qXx3ylHIpMkG3Pqqcdb8NBc2wkZbqBSMOFSevGKAQqEmZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228417993138.37147666111719; Fri, 11 Jul 2025 03:06:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAYt-0001v6-72; Fri, 11 Jul 2025 06:01:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYR-0001SK-AB for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:31 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYO-0005FJ-5v for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:30 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:26 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228028; x=1783764028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q8vxlSp8vNdf+rAvGc2M8Yga/kO4BDydluyykj+THNg=; b=Lb6Qx6YJvKLE08qqKHhJCwV8+TrzxiPbRXP97Itcjph7B9dLF15tio/0 PLNCGFmqzn6vp0GG7YB87LNRVk9sfUTl9afWcZ4bUDIPLzw00F6Zit6IN lrg8FqfQm0jvKwAcOJrh9mbgKRjq01uWcBC7CxuAgDM7jFWVHw4oRTs4M WEKWfHBap5K8ZhyOVfq5vlpfUmdsq3PKcANwjDJ2J+FaW4/1RsO9OOSca r04tXaPTOOtwS3ap0mpbJ0DAJ/YxCJoJcgTRu6zzKAxlJi+q1PZe/O86k +0JHRUCV2x27bAgU0LP/VXQdhldUHWL7kdQPI7qR9Dk1yNDsxe4vgeyzJ Q==; X-CSE-ConnectionGUID: h0YKNzBtREiIeFkzGKUqsg== X-CSE-MsgGUID: eD6qA7BVTlGIr/bDjc4XTQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496191" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496191" X-CSE-ConnectionGUID: onw+2bYBQkuhQgZOe42X2w== X-CSE-MsgGUID: KuWsCJSDR7WF/8+CEpZN8Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662006" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 01/18] i386/cpu: Refine comment of CPUID2CacheDescriptorInfo Date: Fri, 11 Jul 2025 18:21:26 +0800 Message-Id: <20250711102143.1622339-2-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228418971116600 Content-Type: text/plain; charset="utf-8" Refer to SDM vol.3 table 1-21, add the notes about the missing descriptor, and fix the typo and comment format. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Fix the typo in comment. (Dapeng) --- target/i386/cpu.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0d35e95430fe..6983b5f70457 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -66,6 +66,7 @@ struct CPUID2CacheDescriptorInfo { =20 /* * Known CPUID 2 cache descriptors. + * TLB, prefetch and sectored cache related descriptors are not included. * From Intel SDM Volume 2A, CPUID instruction */ struct CPUID2CacheDescriptorInfo cpuid2_cache_descriptors[] =3D { @@ -87,18 +88,29 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descripto= rs[] =3D { .associativity =3D 2, .line_size =3D 64, }, [0x21] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 = * KiB, .associativity =3D 8, .line_size =3D 64, }, - /* lines per sector is not supported cpuid2_cache_descriptor(), - * so descriptors 0x22, 0x23 are not included - */ + /* + * 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 = * MiB, .associativity =3D 16, .line_size =3D 64, }, - /* lines per sector is not supported cpuid2_cache_descriptor(), - * so descriptors 0x25, 0x20 are not included - */ + /* + * lines per sector is not supported cpuid2_cache_descriptor(), + * so descriptors 0x25, 0x29 are not included + */ [0x2C] =3D { .level =3D 1, .type =3D DATA_CACHE, .size =3D 32 = * KiB, .associativity =3D 8, .line_size =3D 64, }, [0x30] =3D { .level =3D 1, .type =3D INSTRUCTION_CACHE, .size =3D 32 = * KiB, .associativity =3D 8, .line_size =3D 64, }, + /* + * Newer Intel CPUs (having the cores without L3, e.g., Intel MTL, ARL) + * use CPUID 0x4 leaf to describe cache topology, by encoding CPUID 0x2 + * leaf with 0xFF. For older CPUs (without 0x4 leaf), it's also valid + * to just ignore L3's code if there's no L3. + * + * This already covers all the cases in QEMU, so code 0x40 is not + * included. + */ [0x41] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 128 = * KiB, .associativity =3D 4, .line_size =3D 32, }, [0x42] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 256 = * KiB, @@ -136,9 +148,10 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descript= ors[] =3D { .associativity =3D 4, .line_size =3D 64, }, [0x78] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 1 = * MiB, .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. - */ + /* + * 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 = * MiB, .associativity =3D 8, .line_size =3D 64, }, [0x7F] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 512 = * KiB, --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228191; cv=none; d=zohomail.com; s=zohoarc; b=Ot7v4N00Fb99PlcI7UXQzjGXXI9gjZ7ANL4BVg/Wmi3dmH0Rl9Gne5/5xp/oHVHvoznvEbbIkG0ZtXu+8n12b4ZmLcDANBxnBiUBX5cgwmCAtYU6+2jsp2OnQvdGkJtaVTuqYcli2S2IhK+sMlmVyWNZ1Fkdi4mkrXUDH3H4KVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228191; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A16pg3JKMZCVZgZVty5z2CozdjA3keBHcOmu9cI/3UY=; b=O/dF3gETG0J6Rz4mrYI2Xf6gGApQrTn0I1yF+kXuwGjnh2T1hgYBGOAjpPT3gN9pfbhiDnmOwCJeFnkyTnV1epcLCHFWRtV29Zp7RRHvlL54qvAhBkXhPL8A9ShAo7/5mauF7I9aPaph1DcMbX8W1YaGdMtVcbIO1jWckp1w4YA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228191323964.6475754601578; Fri, 11 Jul 2025 03:03:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAYz-00028l-PR; Fri, 11 Jul 2025 06:01:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYW-0001mK-WD for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:39 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYR-0005FJ-O7 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:36 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:31 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228032; x=1783764032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ROoVRKY7dce0T2TAcHTZK8KJkdKbNMAzZALpbA8p8yk=; b=WcaDsf1ZupC8g10+QzQhtiqa+2PmrcTaYz3cUQfj7wEah5xQiyPEEDf6 AnumZtWgQbLEmkYr7DaFhk/xShQadgQ2ayokNPwxqS+tMNCKSHtmeDdX2 cLpN9/TpsTdbdZrQJGSfN8HCSw6qWWrJ4a692AbHLtc2NtdAISneRlaTu bhZP0Mt37tml3gWYfAFT9IlJRlylbXCLgSbRiHI6YtqPpFpVBX5mslAd8 tsHgUG0sX9Le7PUqBvQMi2WrhShm28qwqO8nHdh7/QpHO5gXix/Zi/9xl tdBFPz8znyAI1+oEoHmUV8wCpZYUMLOizVNIdQwsjvAQikF7yxA2Ujc2A g==; X-CSE-ConnectionGUID: vVcQQSMoSRSpC1HqLnULSg== X-CSE-MsgGUID: iFzQxaf2QmiA5Wmu7Bp6Ig== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496216" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496216" X-CSE-ConnectionGUID: kEwFLIVOTGajOgISGLQ+zg== X-CSE-MsgGUID: I/V0E3r4RNuATUyrQCZTfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662034" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 02/18] i386/cpu: Add descriptor 0x49 for CPUID 0x2 encoding Date: Fri, 11 Jul 2025 18:21:27 +0800 Message-Id: <20250711102143.1622339-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228191955116600 Content-Type: text/plain; charset="utf-8" The legacy_l2_cache (2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size) corresponds to descriptor 0x49, but at present cpuid2_cache_descriptors doesn't support descriptor 0x49 because it has multiple meanings. The 0x49 is necessary when CPUID 0x2 and 0x4 leaves have the consistent cache model, and use legacy_l2_cache as the default L2 cache. Therefore, add descriptor 0x49 to represent general L2 cache. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v2: * Fix the typo in comment. (Dapeng) --- target/i386/cpu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6983b5f70457..75932579542a 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -127,7 +127,18 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descript= ors[] =3D { .associativity =3D 8, .line_size =3D 64, }, [0x48] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 3 = * MiB, .associativity =3D 12, .line_size =3D 64, }, - /* Descriptor 0x49 depends on CPU family/model, so it is not included = */ + /* + * Descriptor 0x49 has 2 cases: + * - 2nd-level cache: 4 MByte, 16-way set associative, 64 byte line s= ize. + * - 3rd-level cache: 4MB, 16-way set associative, 64-byte line size + * (Intel Xeon processor MP, Family 0FH, Model 06H). + * + * When it represents L3, then it depends on CPU family/model. Fortuna= tely, + * the legacy cache/CPU models don't have such special L3. So, just ad= d it + * to represent the general L2 case. + */ + [0x49] =3D { .level =3D 2, .type =3D UNIFIED_CACHE, .size =3D 4 = * MiB, + .associativity =3D 16, .line_size =3D 64, }, [0x4A] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 6 = * MiB, .associativity =3D 12, .line_size =3D 64, }, [0x4B] =3D { .level =3D 3, .type =3D UNIFIED_CACHE, .size =3D 8 = * MiB, --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228474; cv=none; d=zohomail.com; s=zohoarc; b=STLVxiMRA+tLkj421WCw6ezz1kORgw+NvVQC4YnpoYL2GydtPaIe9E98dqkvHMYL2FY7KZ3sRwVTPKEVwUzv9c2HkNF97p3Ari6J4b9sNoEGHGQclC/bPAzFfiFxJRmbCId386BeMls9gFXnAGk6H1zKtJUodThRktF5n30yT6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228474; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tCy6WdO6jFKBsXurMJABaK4JONeycj6bsnNRQXTJnyQ=; b=iBrEVgqMnR9SYgGOzB2emU9zt2tjPjdjQFdJt1AKBsLjrdZ8IXiN78PYHZsSxfouTpU8oZg6fvaVMKUmjwTLJAvMBGhS7v4SIbfqYhEYZ2j3K7nNn2ePaBlUtVtL8jh2S5iOk4lDpue4ZGPtdVFx2EDBPAOPCnW0s8E5ZiTcp30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228474674232.09775954387953; Fri, 11 Jul 2025 03:07:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAYy-00026W-6u; Fri, 11 Jul 2025 06:01:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYZ-0001tg-PH for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:46 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYX-0005FJ-F4 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:39 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:35 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228037; x=1783764037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N4j+RvAXnffezaGqQKQKZV+fiLAWxKiP/f4514lxOVU=; b=iovA9tkEkU/vkD1Y4s5cYpfIJ8AKWUVonE685IbQbXU3hCxVqj6XeauM t+bHG38CM5lImu7X6x7MeVAw1PtGp6iWMvVotb0cBMtGXNHoXItrId0kz tb1D1FgjwGMW8thkjgB+d79iGY8ITfNJGSjijXFduQ6r380vHkX/ATMTd 3JlNok8+YVz4P6/GfhMf4snPsAKzoWWABXOwn7EFcoTGbyQPgQ4r03Qcq RCvJ/u/I6IqTQy3pxCd+Gq8vEg/VSC9sG7IWZddQurJ1xlCsQeawuxgze UlTyo+SEWJqMdFaagfDTzjF1Hch5kQy/q0NlKoHN1DBh0XRw+um4CQzVh w==; X-CSE-ConnectionGUID: /+GIGuhPTpyDtGpKLXf0iA== X-CSE-MsgGUID: SrMvFuphSwmu9ltrFt7lNw== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496225" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496225" X-CSE-ConnectionGUID: CbqxAaMDQuaahZezcZBMig== X-CSE-MsgGUID: F+mi/dcpRk2W+ezusK1MfA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662038" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 03/18] i386/cpu: Add default cache model for Intel CPUs with level < 4 Date: Fri, 11 Jul 2025 18:21:28 +0800 Message-Id: <20250711102143.1622339-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228475892116600 Content-Type: text/plain; charset="utf-8" Old Intel CPUs with CPUID level < 4, use CPUID 0x2 leaf (if available) to encode cache information. Introduce a cache model "legacy_intel_cpuid2_cache_info" for the CPUs with CPUID level < 4, based on legacy_l1d_cache, legacy_l1i_cache, legacy_l2_cache_cpuid2 and legacy_l3_cache. But for L2 cache, this cache model completes self_init, sets, partitions, no_invd_sharing and share_level fields, referring legacy_l2_cache, to avoid someone increases CPUID level manually and meets assert() error. But the cache information present in CPUID 0x2 leaf doesn't change. This new cache model makes it possible to remove legacy_l2_cache_cpuid2 in X86CPUState and help to clarify historical cache inconsistency issue. Furthermore, apply this legacy cache model to all Intel CPUs with CPUID level < 4. This includes not only "pentium2" and "pentium3" (which have 0x2 leaf), but also "486" and "pentium" (which only have 0x1 leaf, and cache model won't be presented, just for simplicity). A legacy_intel_cpuid2_cache_info cache model doesn't change the cache information of the above CPUs, because they just depend on 0x2 leaf. Only when someone adjusts the min-level to >=3D4 will the cache information in CPUID leaf 4 differ from before: previously, the L2 cache information in CPUID leaf 0x2 and 0x4 was different, but now with legacy_intel_cpuid2_cache_info, the information they present will be consistent. This case almost never happens, emulating a CPUID that is not supported by the "ancient" hardware is itself meaningless behavior. Therefore, even though there's the above difference (for really rare case) and considering these old CPUs ("486", "pentium", "pentium2" and "pentium3") won't be used for migration, there's no need to add new versioned CPU models Tested-by: Yi Lai Signed-off-by: Zhao Liu Reviewed-by:=C2=A0 Dapeng Mi --- target/i386/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 75932579542a..f85e087bf7df 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -710,6 +710,67 @@ static CPUCacheInfo legacy_l3_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, }; =20 +/* + * Only used for the CPU models with CPUID level < 4. + * These CPUs (CPUID level < 4) only use CPUID leaf 2 to present + * cache information. + * + * Note: This cache model is just a default one, and is not + * guaranteed to match real hardwares. + */ +static const CPUCaches legacy_intel_cpuid2_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .type =3D UNIFIED_CACHE, + .level =3D 2, + .size =3D 2 * MiB, + .self_init =3D 1, + .line_size =3D 64, + .associativity =3D 8, + .sets =3D 4096, + .partitions =3D 1, + .no_invd_sharing =3D true, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, +}; + /* TLB definitions: */ =20 #define L1_DTLB_2M_ASSOC 1 @@ -3043,6 +3104,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { I486_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium", @@ -3055,6 +3117,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium2", @@ -3067,6 +3130,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM2_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "pentium3", @@ -3079,6 +3143,7 @@ static const X86CPUDefinition builtin_x86_defs[] =3D { PENTIUM3_FEATURES, .xlevel =3D 0, .model_id =3D "", + .cache_info =3D &legacy_intel_cpuid2_cache_info, }, { .name =3D "athlon", --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228367; cv=none; d=zohomail.com; s=zohoarc; b=j8/T4cS6ZTpSi2gLLGYJk0s38mboAQBzN8hsaBGdZy+no+0sKU7mT21/n/qjg3zhB5QkSDRShBXviWcf23Z5o9VtDht7HlHEXIdxAC1PeqQN599HnzxHO+rXzuFiFhUaYyW+dUoCEH4ENcFWzUHmESGOKSVOmamg4owpKSFYvVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228367; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Al57Qa6qJcEyxWc8SpdhnJQpj/UkC6RoBVwWmbPDx1s=; b=X806KTJwmMMrxJeBIYRIbHFOueSdc+F3IGeiPsmZGfujlMph3Ae2VdHxhblgacHU8gEnieQcoZwEc/S7Qob1xRxgj/BRU8rXC47ijGEf4BBo+mSmnumjvVaVuTJd7EIuUoNZiTTQiMm00RxtK5WmEgojjvtjddOuzKj2gtotbBM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228367643176.6230284951465; Fri, 11 Jul 2025 03:06:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZ8-0002i6-0j; Fri, 11 Jul 2025 06:01:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYi-0001vl-42 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:53 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYd-0005H0-7B for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:45 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:40 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228043; x=1783764043; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yG3qiMYa7f3Vg06cEK8SdJIMxpzMK6proPRZfmYy1os=; b=SRFoQj9LJogmfP1Z6um4/R/x5bFgrXcE91FLoXFR/RKHkzZbCp7e92p0 27pbnWzt3Sfp4XXrhTvIQwkAWB3XkNtuhfVOQLMZBcYohP9qF5MEeA1J5 /tXfuzeofXPFsQe01BjTOlgHI+Ti8sfgVvGOsSr41Oo/BYLlHVM0TGwMG HdlHPigZS30jGsgPj4as5woXv1gVIbX9HZ6VX8GP/C8zI910NKCVnVlHj 9qkB5ma64BPASnk8MLzkbzqEXY7JTDgvZtgC11aFdCe5IT9zjQJC1wrN/ 6nRWH7aOkTeH4jNKGfXRzSEh1+VXBs1fu6FZmlzdWqVRvF6fTk2n3ukND w==; X-CSE-ConnectionGUID: 8R38wFDeR+CRgDQFCanSuA== X-CSE-MsgGUID: eu+XRhjeRi+lRgyMvbVmrQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496252" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496252" X-CSE-ConnectionGUID: RFZxQlyATGagBmo5IyZX9A== X-CSE-MsgGUID: 54hzDnYpRJqJEGjMYteDSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662043" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Alexander Graf Subject: [PATCH v2 04/18] i386/cpu: Present same cache model in CPUID 0x2 & 0x4 Date: Fri, 11 Jul 2025 18:21:29 +0800 Message-Id: <20250711102143.1622339-5-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228368899116600 Content-Type: text/plain; charset="utf-8" For a long time, the default cache models used in CPUID 0x2 and 0x4 were inconsistent and had a FIXME note from Eduardo at commit 5e891bf8fd50 ("target-i386: Use #defines instead of magic numbers for CPUID cache info"): "/*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */". This difference is wrong, in principle, both 0x2 and 0x4 are used for Intel's cache description. 0x2 leaf is used for ancient machines while 0x4 leaf is a subsequent addition, and both should be based on the same cache model. Furthermore, on real hardware, 0x4 leaf should be used in preference to 0x2 when it is available. Revisiting the git history, that difference occurred much earlier. Current legacy_l2_cache_cpuid2 (hardcode: "0x2c307d"), which is used for CPUID 0x2 leaf, is introduced in commit d8134d91d9b7 ("Intel cache info, by Filip Navara."). Its commit message didn't said anything, but its patch [1] mentioned the cache model chosen is "closest to the ones reported in the AMD registers". Now it is not possible to check which AMD generation this cache model is based on (unfortunately, AMD does not use 0x2 leaf), but at least it is close to the Pentium 4. In fact, the patch description of commit d8134d91d9b7 is also a bit wrong, the original cache model in leaf 2 is from Pentium Pro, and its cache descriptor had specified the cache line size ad 32 byte by default, while the updated cache model in commit d8134d91d9b7 has 64 byte line size. But after so many years, such judgments are no longer meaningful. On the other hand, for legacy_l2_cache, which is used in CPUID 0x4 leaf, is based on Intel Core Duo (patch [2]) and Core2 Duo (commit e737b32a3688 ("Core 2 Duo specification (Alexander Graf).") The patches of Core Duo and Core 2 Duo add the cache model for CPUID 0x4, but did not update CPUID 0x2 encoding. This is the reason that Intel Guests use two cache models in 0x2 and 0x4 all the time. Of course, while no Core Duo or Core 2 Duo machines have been found for double checking, this still makes no sense to encode different cache models on a single machine. Referring to the SDM and the real hardware available, 0x2 leaf can be directly encoded 0xFF to instruct software to go to 0x4 leaf to get the cache information, when 0x4 is available. Therefore, it's time to clean up Intel's default cache models. As the first step, add "x-consistent-cache" compat option to allow newer machines (v10.1 and newer) to have the consistent cache model in CPUID 0x2 and 0x4 leaves. This doesn't affect the CPU models with CPUID level < 4 ("486", "pentium", "pentium2" and "pentium3"), because they have already had the special default cache model - legacy_intel_cpuid2_cache_info. [1]: https://lore.kernel.org/qemu-devel/5b31733c0709081227w3e5f1036odbc649e= dfdc8c79b@mail.gmail.com/ [2]: https://lore.kernel.org/qemu-devel/478B65C8.2080602@csgraf.de/ Cc: Alexander Graf Tested-by: Yi Lai Signed-off-by: Zhao Liu --- hw/i386/pc.c | 4 +++- target/i386/cpu.c | 7 ++++++- target/i386/cpu.h | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b2116335752d..ad2d6495ebde 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -81,7 +81,9 @@ { "qemu64-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }= ,\ { "athlon-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }, =20 -GlobalProperty pc_compat_10_0[] =3D {}; +GlobalProperty pc_compat_10_0[] =3D { + { TYPE_X86_CPU, "x-consistent-cache", "false" }, +}; const size_t pc_compat_10_0_len =3D G_N_ELEMENTS(pc_compat_10_0); =20 GlobalProperty pc_compat_9_2[] =3D {}; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f85e087bf7df..70ac969a9cdc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8935,7 +8935,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) /* Build legacy cache information */ env->cache_info_cpuid2.l1d_cache =3D &legacy_l1d_cache; env->cache_info_cpuid2.l1i_cache =3D &legacy_l1i_cache; - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; + if (!cpu->consistent_cache) { + env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; + } else { + env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache; + } env->cache_info_cpuid2.l3_cache =3D &legacy_l3_cache; =20 env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; @@ -9461,6 +9465,7 @@ static const Property x86_cpu_properties[] =3D { * own cache information (see x86_cpu_load_def()). */ DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, true), + DEFINE_PROP_BOOL("x-consistent-cache", X86CPU, consistent_cache, true), DEFINE_PROP_BOOL("legacy-multi-node", X86CPU, legacy_multi_node, false= ), DEFINE_PROP_BOOL("xen-vapic", X86CPU, xen_vapic, false), =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 51e10139dfdf..d7c9a1f91446 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2259,6 +2259,13 @@ struct ArchCPU { */ bool legacy_cache; =20 + /* + * Compatibility bits for old machine types. + * If true, use the same cache model in CPUID leaf 0x2 + * and 0x4. + */ + bool consistent_cache; + /* Compatibility bits for old machine types. * If true decode the CPUID Function 0x8000001E_ECX to support multiple * nodes per processor --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228296; cv=none; d=zohomail.com; s=zohoarc; b=SLfGNZNrqJ9hNpRCy0HNcxI1LBzOUpKcFx4ksxZgZ7agOoTlbd7jyHaOwzHKrUo4Heynh91HYxk5zyYLiMPgwnXwURx1NPzmGfCbNKHU4mREpoxgnBIHueFMSvwWi4wcnjZUE63Me2kDdyhZkqnUe8crTgIWMZFiDAFG6BwQrb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228296; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JvXa2NBi1f6HbXa8PaDOu60DPmaBmNvlmT4pNuseQSM=; b=BPDltOH2iFVM2WbB1Mz91YmXLSMtfdcSZnlk58WsqKymqQDSak/nRg/p7OZCtECJZUTV+4g+wgVyJw/+/A+8x6+8HD2/SvXuYBdCQ2UWjUHrG3ZoU0nGJGeD8mc3RGUgmS8bBbX8t5OCRv+7J1rt9LaavtLnmVImVZrRoaeitS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175222829650786.28695808785392; Fri, 11 Jul 2025 03:04:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZF-0003GF-QU; Fri, 11 Jul 2025 06:01:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYo-0001wQ-GX for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:58 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYm-0005H0-BA for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:54 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:49 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228052; x=1783764052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NAdqAYTXJZb5DjKif7WlBLOUKuZAQoUj2XZSaZ6yx2o=; b=M+gVXMA7vmN+9doMeVXD3HURG8s13xJ6Btr835h9/dIzOQC9RD92icQn TaNSc2CRfdo43sijgsh3bxgvjB8qEFg9T6BDQyCjQ0sP34dy2BQSnzNCn FKQE1dMMZC+kDsv5F8hAoeCfF6NzJodob6JAShGYYc2KgPdI4JSNKgmY4 s9TjsehSzU1XG7ExBlRxnoZfy+ibN94Iz11Dollyhmqd8XvPQW9xtNr2a QEDLM3M8JPxtjzIwWjWMofD2Pma6j4AXQVW9XtHUv1DHsh6TGzBnDX2P3 ed9tpESexQX5hx+9kOkGld7ZzIVSsEJt47zBWp0IQrJPt2fd7qrRLO243 w==; X-CSE-ConnectionGUID: U01vystwQL68AC0gt3GryA== X-CSE-MsgGUID: eKL86v6SSwWzPWRnO3N4PQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496265" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496265" X-CSE-ConnectionGUID: TL4xReLGT6GyGPh2jf5l2w== X-CSE-MsgGUID: e8KFagqBT5yjLtE1jLAYew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662047" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 05/18] i386/cpu: Consolidate CPUID 0x4 leaf Date: Fri, 11 Jul 2025 18:21:30 +0800 Message-Id: <20250711102143.1622339-6-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228297134116600 Content-Type: text/plain; charset="utf-8" Modern Intel CPUs use CPUID 0x4 leaf to describe cache information and leave space in 0x2 for prefetch and TLBs (even TLB has its own leaf CPUID 0x18). And 0x2 leaf provides a descriptor 0xFF to instruct software to check cache information in 0x4 leaf instead. Therefore, follow this behavior to encode 0xFF when Intel CPU has 0x4 leaf with "x-consistent-cache=3Dtrue" for compatibility. In addition, for older CPUs without 0x4 leaf, still enumerate the cache descriptor in 0x2 leaf, except the case that there's no descriptor matching the cache model, then directly encode 0xFF in 0x2 leaf. This makes sense, as in the 0x2 leaf era, all supported caches should have the corresponding descriptor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Fix the typo in comment. (Ewan) --- target/i386/cpu.c | 48 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 70ac969a9cdc..37cf591bea8d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -223,7 +223,7 @@ struct CPUID2CacheDescriptorInfo cpuid2_cache_descripto= rs[] =3D { * 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) +static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *cache, bool *unmacthe= d) { int i; =20 @@ -240,9 +240,44 @@ static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *c= ache) } } =20 + *unmacthed |=3D true; return CACHE_DESCRIPTOR_UNAVAILABLE; } =20 +/* Encode cache info for CPUID[2] */ +static void encode_cache_cpuid2(X86CPU *cpu, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + CPUX86State *env =3D &cpu->env; + CPUCaches *caches =3D &env->cache_info_cpuid2; + int l1d, l1i, l2, l3; + bool unmatched =3D false; + + *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ + *ebx =3D *ecx =3D *edx =3D 0; + + l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); + l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); + l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); + l3 =3D cpuid2_cache_descriptor(caches->l3_cache, &unmatched); + + if (!cpu->consistent_cache || + (env->cpuid_min_level < 0x4 && !unmatched)) { + /* + * Though SDM defines code 0x40 for cases with no L2 or L3. It's + * also valid to just ignore l3's code if there's no l2. + */ + if (cpu->enable_l3_cache) { + *ecx =3D l3; + } + *edx =3D (l1d << 16) | (l1i << 8) | l2; + } else { + *ecx =3D 0; + *edx =3D CACHE_DESCRIPTOR_UNAVAILABLE; + } +} + /* CPUID Leaf 4 constants: */ =20 /* EAX: */ @@ -7448,16 +7483,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } - *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ - *ebx =3D 0; - if (!cpu->enable_l3_cache) { - *ecx =3D 0; - } else { - *ecx =3D cpuid2_cache_descriptor(env->cache_info_cpuid2.l3_cac= he); - } - *edx =3D (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1d_cache= ) << 16) | - (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1i_cache) = << 8) | - (cpuid2_cache_descriptor(env->cache_info_cpuid2.l2_cache)); + encode_cache_cpuid2(cpu, eax, ebx, ecx, edx); break; case 4: /* cache info: needed for Core compatibility */ --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228325; cv=none; d=zohomail.com; s=zohoarc; b=YivoWC17ICYM8OXFW3SfsWtOfjZVMWWTJNP91O1G9NLPbmeaYa4fxN1Sn04BG0dytnnR297cupBjeJl8NcqvtbHyUhxJ1mzbPILBHlr4RS3VCRdTtyOLhxvF0ihyeWIrEW5TdkzpNewUxKdj+SqHi02u0mfH6MAV04Bm7r+higI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228325; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HtPg+H22I2VruXxTb9q6nh6F188d6zBQ/hS/Yjvh57c=; b=GetuGtvAqNqVLNyHCC3XqQAilxcHQGodjOE0iFBAHu1s/sUnR+5zuQy2BIMadcuqXys2pdz17uMts28bdbyJZPyovEtN8o+pGjk82ZOdHEpu+pXqMWvALkfDLDYFJ3zjudF8gxjVjqNXAXcSi2j4gL++KeKz2VM9HyxLoRFWffw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228325528483.0946677257972; Fri, 11 Jul 2025 03:05:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZ2-0002R6-T5; Fri, 11 Jul 2025 06:01:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYp-0001wT-Ul for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:58 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYn-0005Iz-IB for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:55 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:51 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228053; x=1783764053; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=37ekHmbjiymc2w14B0h3SzMdkzEg65B1RzqZEcyBXL0=; b=FJUybO+WcUcc+t00tSP7mf97TCHtyRTUzCiUAIsFNT0NB6AxgT7t5M1F lpkqDZMp5AGkbJI/8FCnYZI/4DjNVNcviCIjta8X40wBfxjYiRVfab//V hsb9t4ZeufLXJT+7jafh5GmLY6k8FL+aae5nRUAyNZolcQWRJFHg8JFbZ As7LPgiK8rlywpGHYKFCMHgYNkjXQeteftKeIVTgjiU4VRl02C/UJCE9S VvbMijVCSpNKZ6HVwWgr38ALjxDEIsxKW5Zo3aN1eDYwo8uiLdAaxJQBU L777fQujd7i9U4R+k9ClVLbpUq+cPXNWxA7laFKnD2R9psViPD2+peTOZ A==; X-CSE-ConnectionGUID: 4mXQqwH/QYONZIh15zZhPw== X-CSE-MsgGUID: iRiAZLxjTsKYQsctOgJ5KQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496274" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496274" X-CSE-ConnectionGUID: kbaFEx9UQ9aHinuKt7LG5A== X-CSE-MsgGUID: RtRdR5z/Tf6auFkf17qefg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662051" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 06/18] i386/cpu: Drop CPUID 0x2 specific cache info in X86CPUState Date: Fri, 11 Jul 2025 18:21:31 +0800 Message-Id: <20250711102143.1622339-7-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228327803116600 Content-Type: text/plain; charset="utf-8" With the pre-defined cache model legacy_intel_cpuid2_cache_info, for X86CPUState there's no need to cache special cache information for CPUID 0x2 leaf. Drop the cache_info_cpuid2 field of X86CPUState and use the legacy_intel_cpuid2_cache_info directly. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 31 +++++++++++-------------------- target/i386/cpu.h | 3 ++- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 37cf591bea8d..af67f12e939d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -244,19 +244,27 @@ static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *= cache, bool *unmacthed) return CACHE_DESCRIPTOR_UNAVAILABLE; } =20 +static const CPUCaches legacy_intel_cpuid2_cache_info; + /* Encode cache info for CPUID[2] */ static void encode_cache_cpuid2(X86CPU *cpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { CPUX86State *env =3D &cpu->env; - CPUCaches *caches =3D &env->cache_info_cpuid2; + const CPUCaches *caches; int l1d, l1i, l2, l3; bool unmatched =3D false; =20 *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ *ebx =3D *ecx =3D *edx =3D 0; =20 + if (env->enable_legacy_cpuid2_cache) { + caches =3D &legacy_intel_cpuid2_cache_info; + } else { + caches =3D &env->cache_info_cpuid4; + } + l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); @@ -705,17 +713,6 @@ static CPUCacheInfo legacy_l2_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ -static CPUCacheInfo legacy_l2_cache_cpuid2 =3D { - .type =3D UNIFIED_CACHE, - .level =3D 2, - .size =3D 2 * MiB, - .line_size =3D 64, - .associativity =3D 8, - .share_level =3D CPU_TOPOLOGY_LEVEL_INVALID, -}; - - /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, @@ -8955,18 +8952,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) "CPU model '%s' doesn't support legacy-cache=3Doff"= , name); return; } - env->cache_info_cpuid2 =3D env->cache_info_cpuid4 =3D env->cache_i= nfo_amd =3D - *cache_info; + env->cache_info_cpuid4 =3D env->cache_info_amd =3D *cache_info; } else { /* Build legacy cache information */ - env->cache_info_cpuid2.l1d_cache =3D &legacy_l1d_cache; - env->cache_info_cpuid2.l1i_cache =3D &legacy_l1i_cache; if (!cpu->consistent_cache) { - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache_cpuid2; - } else { - env->cache_info_cpuid2.l2_cache =3D &legacy_l2_cache; + env->enable_legacy_cpuid2_cache =3D true; } - env->cache_info_cpuid2.l3_cache =3D &legacy_l3_cache; =20 env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; env->cache_info_cpuid4.l1i_cache =3D &legacy_l1i_cache; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index d7c9a1f91446..9adba8fdf773 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2076,7 +2076,8 @@ typedef struct CPUArchState { * on each CPUID leaf will be different, because we keep compatibility * with old QEMU versions. */ - CPUCaches cache_info_cpuid2, cache_info_cpuid4, cache_info_amd; + CPUCaches cache_info_cpuid4, cache_info_amd; + bool enable_legacy_cpuid2_cache; =20 /* MTRRs */ uint64_t mtrr_fixed[11]; --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228390; cv=none; d=zohomail.com; s=zohoarc; b=ndMo+YGkuvIBPOdHZf8qiz1YbZdcNYpDFDD7ME8PaWLkppDfkUojWTWjHFKZIrEEz5k7VqIM0rCdZfOTzZnxL43oSiFA54bkOEIppuAYWv3P06NGDrOr1NLimID0UomNNJSixmGh5n7gUicjrNjD6qDcsJkJKIx09LgQXVftyo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228390; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HS1MffmSEW1JammgTmE1uVgR2gDz2c6itTQb6+U+tPg=; b=bw6P8BRJpV4P394XPDtq07Xt9t2cjaHwAJ9UEbX1ryKqCS8YtTR4Epl5cwJx4lyFyKwT6YDOyqgJVEj0LYCY01Up3FuiiTyKvANhKD9sIspkGxMYHF68elI+pm2+YQP1N1GE/C3qTFLV0IW1eLzZzIcMvMLvJDAu0J2vPWwAuSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228390844175.99102841903232; Fri, 11 Jul 2025 03:06:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZg-0003t6-Lm; Fri, 11 Jul 2025 06:01:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYt-0001yw-TC for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:01 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYr-0005KY-RI for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:00:59 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:00:56 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228058; x=1783764058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=whdrh4f2CvSh7ztiRXZ9xAUTYQf/ppVVjSzuT5hVdFw=; b=aKvkmAWpsayv86BUJOxv85ilk4l17nbj0QWQ1cKjWrQCT2U1qH+UQMXd HrKqpop4OnVrcgh37r+4wcmesFzvNsxAkq659KB7Q/FMLEuj3ZSVfkLC2 /l3uvwYHij8XGtzOuZu/iL83iYlDfVeL3v3nOn9krIuimYhqz9a7qp6xK TyyMc8guyp4cpgE+nwe/XbWm+A6jv/kF1eCSNv0mO193g6lpy1qaq+l6t U2igS9US51SweTZ/ygKrlpNEb3Zf1OHjMmRwjhK63q27MvgQYks/oQj4w 5YJ/0QtvbYxM/ahrb6o6aBbc7hG2JebU0cXItFsx3hd9x0sCAuS0Q/CEM g==; X-CSE-ConnectionGUID: nbSzpyCnT9y+I2tl4ZD/XA== X-CSE-MsgGUID: tGNtNTyXR365V6ukG/H1KA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496285" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496285" X-CSE-ConnectionGUID: QSkNiVqjRvm2Mkffpmntrg== X-CSE-MsgGUID: aHq+KBnZS3yXnjLhhjM1EA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662056" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 07/18] i386/cpu: Add x-vendor-cpuid-only-v2 option for compatibility Date: Fri, 11 Jul 2025 18:21:32 +0800 Message-Id: <20250711102143.1622339-8-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228392529116600 Content-Type: text/plain; charset="utf-8" Add a compat property "x-vendor-cpuid-only-v2" (for PC machine v10.0 and older) to keep the original behavior. This property will be used to adjust vendor specific CPUID fields. Make x-vendor-cpuid-only-v2 depend on x-vendor-cpuid-only. Although x-vendor-cpuid-only and v2 should be initernal only, QEMU doesn't support "internal" property. To avoid any other unexpected issues, check the dependency. Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Split the x-vendor-cpuid-only-v2 support into a seperate pacth and make sure it depends on x-vendor-cpuid-only. --- hw/i386/pc.c | 1 + target/i386/cpu.c | 10 ++++++++++ target/i386/cpu.h | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ad2d6495ebde..9ec3f4db31f3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -83,6 +83,7 @@ =20 GlobalProperty pc_compat_10_0[] =3D { { TYPE_X86_CPU, "x-consistent-cache", "false" }, + { TYPE_X86_CPU, "x-vendor-cpuid-only-v2", "false" }, }; const size_t pc_compat_10_0_len =3D G_N_ELEMENTS(pc_compat_10_0); =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index af67f12e939d..b6d41aa110a2 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8749,6 +8749,16 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) tcg_cflags_set(cs, CF_PCREL); #endif =20 + /* + * x-vendor-cpuid-only and v2 should be initernal only. But + * QEMU doesn't support "internal" property. + */ + if (!cpu->vendor_cpuid_only && cpu->vendor_cpuid_only_v2) { + error_setg(errp, "x-vendor-cpuid-only-v2 property " + "depends on x-vendor-cpuid-only"); + return; + } + if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 9adba8fdf773..03a7b735d090 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2282,9 +2282,18 @@ struct ArchCPU { /* Enable auto level-increase for all CPUID leaves */ bool full_cpuid_auto_level; =20 - /* Only advertise CPUID leaves defined by the vendor */ + /* + * Compatibility bits for old machine types (PC machine v6.0 and older= ). + * Only advertise CPUID leaves defined by the vendor. + */ bool vendor_cpuid_only; =20 + /* + * Compatibility bits for old machine types (PC machine v10.0 and olde= r). + * Only advertise CPUID leaves defined by the vendor. + */ + bool vendor_cpuid_only_v2; + /* Only advertise TOPOEXT features that AMD defines */ bool amd_topoext_features_only; =20 --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228418; cv=none; d=zohomail.com; s=zohoarc; b=CPo60mjca43Yko2gM/HALV9Py07yBLCLxWI6SPuAQZl1IDhuXg9Hpb3uF4FdYk+d9MD9G8KjEz8zZjFRi+vOJ5S9EPrgNmhjqWOFnxtXg3GYQUTQ94Hor8jcwPhs3aPz4oAfXwH3nKcNCsARRDZ91u/Zgi826qPwtuXeMkt1CQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228418; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TuUu0piEJ8J/IsONgkMddmvR79Bc7uem9aiXbQCEpA8=; b=QmiHMJj1NBAp8EFp6Eie5nT4IrXAM3NfyeF+73xtsMh7TBv0cm7Q7uDIH13yByRr976XaQ+nl2qkaTozfmSzW2UVwgwGoinnkQqOdw75iO/pNglJ4czoaRxkDas1de/MTB0QMxGxEpxXYN4gDrU5L1GF+C036H29j7uLrRK2tG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175222841891369.02801953627988; Fri, 11 Jul 2025 03:06:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZr-00043Q-UF; Fri, 11 Jul 2025 06:02:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYy-0002Fz-RF for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:05 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAYw-0005KY-B2 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:04 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:01 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:00:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228062; x=1783764062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wKjEW9bps5EkjAhmB9EjInZbONVf26jZWeVxusx0w0s=; b=ltjUDTNyNogS8wLHTIKsRmr4QoSGOwgObWivCeURPGtosZHu6jT/EcCQ MGOZujeyBOFnyKgPYNz3zvA9z/0RknoAgzF43uCcFA1AyTR1ywBOkGB9j GzHuqY82/1Iz4eTbWQ/5BSBBhvaLkA+AlWuFXRBQUpmjJaelM3wZHCopI w1lTZiXa/Ycbj2KOhmkCLFUh7xiFQS0SllEKf4BCR4HXLNw1eVHeT8nRT 2Kz0QqJHOj6pdc268z8v9wHWdOYlAjiVtRG0B2XROyCfy9wjBQaGJXjan ZUpRLHf+UGV+B6omZtrVkvcbK/KDBe/CQEq5XgB9IVIE5zQOqP6rnW5xt A==; X-CSE-ConnectionGUID: a9pytUY3S0mXhM3C81Ho0Q== X-CSE-MsgGUID: eqc1SY9FQZOAHnrz34n/yg== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496301" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496301" X-CSE-ConnectionGUID: I17h21xoSkiwkPVFNCJnTg== X-CSE-MsgGUID: Nztrt/okTAyj0GRuPPC/uA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662064" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 08/18] i386/cpu: Mark CPUID[0x80000005] as reserved for Intel Date: Fri, 11 Jul 2025 18:21:33 +0800 Message-Id: <20250711102143.1622339-9-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228421002116600 Content-Type: text/plain; charset="utf-8" Per SDM, 0x80000005 leaf is reserved for Intel CPU, and its current "assert" check blocks adding new cache model for non-AMD CPUs. And please note, although Zhaoxin mostly follows Intel behavior, this leaf is an exception [1]. So, with the compat property "x-vendor-cpuid-only-v2", for the machine since v10.1, check the vendor and encode this leaf as all-0 only for Intel CPU. In addition, drop lines_per_tag assertion in encode_cache_cpuid80000005(), since Zhaoxin will use legacy Intel cache model in this leaf - which doesn't have this field. This fix also resolves 2 FIXMEs of legacy_l1d_cache_amd and legacy_l1i_cache_amd: /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ In addition, per AMD's APM, update the comment of CPUID[0x80000005]. [1]: https://lore.kernel.org/qemu-devel/fa16f7a8-4917-4731-9d9f-7d4c1097716= 8@zhaoxin.com/ Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Drop lines_per_tag assertion in encode_cache_cpuid80000005(). Changes Since RFC: * Only set all-0 for Intel CPU. * Add x-vendor-cpuid-only-v2. --- target/i386/cpu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b6d41aa110a2..6ab199c9a112 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -497,7 +497,6 @@ static void encode_topo_cpuid1f(CPUX86State *env, uint3= 2_t count, 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) | @@ -655,7 +654,6 @@ static CPUCacheInfo legacy_l1d_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l1d_cache_amd =3D { .type =3D DATA_CACHE, .level =3D 1, @@ -684,7 +682,6 @@ static CPUCacheInfo legacy_l1i_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l1i_cache_amd =3D { .type =3D INSTRUCTION_CACHE, .level =3D 1, @@ -7886,11 +7883,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D env->cpuid_model[(index - 0x80000002) * 4 + 3]; break; case 0x80000005: - /* cache info (L1 cache) */ + /* cache info (L1 cache/TLB Associativity Field) */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } + + if (cpu->vendor_cpuid_only_v2 && IS_INTEL_CPU(env)) { + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + break; + } + *eax =3D (L1_DTLB_2M_ASSOC << 24) | (L1_DTLB_2M_ENTRIES << 16) | (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx =3D (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | @@ -9478,6 +9481,7 @@ static const Property x86_cpu_properties[] =3D { DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor), DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true), DEFINE_PROP_BOOL("x-vendor-cpuid-only", X86CPU, vendor_cpuid_only, tru= e), + DEFINE_PROP_BOOL("x-vendor-cpuid-only-v2", X86CPU, vendor_cpuid_only_v= 2, true), DEFINE_PROP_BOOL("x-amd-topoext-features-only", X86CPU, amd_topoext_fe= atures_only, true), DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false), DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true), --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228162; cv=none; d=zohomail.com; s=zohoarc; b=MtxlWBNkaKDAWW/IsgSm4alXbvtzLbt9QJKA4k7PuERjoqXZYvhXozQzFsvqvzBBwwoBST9mHYOt8UEFOn4XPmhsZkbLD5O37zDNHb2ayxs9IdYPFDXahz4e+0fs0AbA1AYjEk2ib+ydVhlHZevRsf033ORb7Py/2gDLHDXSWFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228162; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z4gZ13ZW/y2bQtUmvFdaMwtIPmpFysoKUAVx7DUKRMQ=; b=Pd7UX3Akl3wQmvZdc/mtEmrAYwsy52mnch+ie1sxHyYvtZTThdHBCvbk1R1X2THgRmBYvgDDIHUm+UQuOFpeQOu8nDJO/gIAKtW26fD1VFDTl1FcB5npL/RqRfIMh1Np0CRMnG/Vc2WtVDM11Rqo981TWfNplUuc4pHQ/0wgSus= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228162465587.1094383477553; Fri, 11 Jul 2025 03:02:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAa2-0004R3-RT; Fri, 11 Jul 2025 06:02:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZ3-0002f0-C7 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:10 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZ0-0005KY-ST for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:09 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:05 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228067; x=1783764067; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m/3V6uk+n+NZ1SFoxeznqGZElzksyaiZeYkUPu8QMoI=; b=aqXQRifm26cE4HevO9r/fkVbIJ9SyNWPJ0nfn9NmT/MVTjsRD/atoiUU 0PScU4lqQFZN/DUjKv5exq9PI/cigXlL9BWnSR71Jw/6BfGLP2OQsMsZ6 edQAq/g74n7W6aD8hvyFGQzSTDumBCMEhpZVJOosrS9ECKVQbwJMxRVGZ 5Hs7SiQ46kUd5YrZijqkcudHZmt+03sEZ7246rat131n9BPuM6lpddEWJ k/FMcjsPA8GIDoe1k3nBYvvjW57+ajZE9kMBHaNnMaKoEZFzuzSleBdeq d1wr+ruE/OQREs1I/+dUfbM54rhHNJb5HhpXN93KmJFl+QQFY0IxIxdM3 Q==; X-CSE-ConnectionGUID: Bmhg+Hy6SQG/xI3glc7caw== X-CSE-MsgGUID: hhzNCI7BQQOBALvs5LeP+Q== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496327" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496327" X-CSE-ConnectionGUID: evhk2FJkTOS7fU+EyNZjgA== X-CSE-MsgGUID: KyTMyk8lRNOLMW+rqHZ91A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662069" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 09/18] i386/cpu: Rename AMD_ENC_ASSOC to X86_ENC_ASSOC Date: Fri, 11 Jul 2025 18:21:34 +0800 Message-Id: <20250711102143.1622339-10-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228163909116600 Content-Type: text/plain; charset="utf-8" Rename AMD_ENC_ASSOC to X86_ENC_ASSOC since Intel also uses the same rules. While there are some slight differences between the rules in AMD APM v4.07 no.40332 and Intel. But considerring the needs of current QEMU, generally they are consistent and current AMD_ENC_ASSOC can be applied for Intel CPUs.. Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Spilt this cleanup as a seperate patch. --- target/i386/cpu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6ab199c9a112..e0d5a39e477c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -505,8 +505,8 @@ static uint32_t encode_cache_cpuid80000005(CPUCacheInfo= *cache) =20 #define ASSOC_FULL 0xFF =20 -/* AMD associativity encoding used on CPUID Leaf 0x80000006: */ -#define AMD_ENC_ASSOC(a) (a <=3D 1 ? a : \ +/* x86 associativity encoding used on CPUID Leaf 0x80000006: */ +#define X86_ENC_ASSOC(a) (a <=3D 1 ? a : \ a =3D=3D 2 ? 0x2 : \ a =3D=3D 4 ? 0x4 : \ a =3D=3D 8 ? 0x6 : \ @@ -532,7 +532,7 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, assert(l2->lines_per_tag > 0); assert(l2->line_size > 0); *ecx =3D ((l2->size / 1024) << 16) | - (AMD_ENC_ASSOC(l2->associativity) << 12) | + (X86_ENC_ASSOC(l2->associativity) << 12) | (l2->lines_per_tag << 8) | (l2->line_size); =20 if (l3) { @@ -541,7 +541,7 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, assert(l3->lines_per_tag > 0); assert(l3->line_size > 0); *edx =3D ((l3->size / (512 * 1024)) << 18) | - (AMD_ENC_ASSOC(l3->associativity) << 12) | + (X86_ENC_ASSOC(l3->associativity) << 12) | (l3->lines_per_tag << 8) | (l3->line_size); } else { *edx =3D 0; @@ -7907,13 +7907,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } - *eax =3D (AMD_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | + *eax =3D (X86_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | (L2_DTLB_2M_ENTRIES << 16) | - (AMD_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | + (X86_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | (L2_ITLB_2M_ENTRIES); - *ebx =3D (AMD_ENC_ASSOC(L2_DTLB_4K_ASSOC) << 28) | + *ebx =3D (X86_ENC_ASSOC(L2_DTLB_4K_ASSOC) << 28) | (L2_DTLB_4K_ENTRIES << 16) | - (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | + (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, cpu->enable_l3_cache ? --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228488; cv=none; d=zohomail.com; s=zohoarc; b=OUSw8CiDFF/d7PB/f3ar1JAu5wcPUOnlWDzvuMXYoxmGF5mkKcqru5AmtsERufOZFxDjSIl/C2VJxw1xeNfU4X9FX8xkvFDwwx56rZEeP341jAxrTwludsnFqL0elR5hdPIGUF+oYEEMBbMmdxUBjgnx5W9AX7wltt40vqItvWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228488; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B3Aott8LmGD5AG0EGnuC0qYU3dZbh/rMmv8wblKZ/1Q=; b=N/jboGozNbPA7v0LX5FzG48k06IfKavsLnYaZU2poMTHc2YkGMjxMSYOdzLJcfu23LfwOmX5Cm5awl/UHy8z5fWCDoUvV/SINOUabY3U53zjbvYEemVRl9zyCfgbvBBIKevBZB25GPYftKiftzSThs1IRsqmzqLuqE7wvXgAfGs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228488423822.2394404735273; Fri, 11 Jul 2025 03:08:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAa0-0004K5-Hy; Fri, 11 Jul 2025 06:02:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZ7-0002im-Bg for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:13 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZ5-0005KY-8M for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:13 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:10 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228071; x=1783764071; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OWvNFKsV7hzM+qTU1YrQuD91g8tHqECnL/vc/zNLCno=; b=a27ORQnYHLL/KAcSjHt66pZcxrzrtHYy0S+E5DJuPojj2iPoq3zw5wNL cYBZ8cg0O/YoEWA4AhxqxpAyLGMq0KoKBkg18i0kccCxD8p/h62Q/vg16 XcK9SLKKRZxVWuBd145YebrITpOWTDn+9CRw6wTsbIX5zZUo6qungTDin HAbIuU6RwTJln4f6xblJOqqE5j2RaTXAvtoneoLiexV/BtJhnYNtnOyEV eMh7L5dOXa+n2QuHKvz+jPnAYoQObWv4bLjIUyr5gvwUfVbHYU23VzzO7 /BVCuBxLD6kVU1089+oTY5AwdOlb9KSCTAH3R+ApEmdAyW+LkqwqHDU0q A==; X-CSE-ConnectionGUID: WPKQmhRnT6m61F7PQjUUmw== X-CSE-MsgGUID: aweWttU0QRyS2o1lBMaOxA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496345" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496345" X-CSE-ConnectionGUID: uXa0yX4nQbq6F4DewAEYdQ== X-CSE-MsgGUID: 2anHszCTTw20zsbfqlyKJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662076" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 10/18] i386/cpu: Fix CPUID[0x80000006] for Intel CPU Date: Fri, 11 Jul 2025 18:21:35 +0800 Message-Id: <20250711102143.1622339-11-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228490618116600 Content-Type: text/plain; charset="utf-8" Per SDM, Intel supports CPUID[0x80000006]. But only L2 information is encoded in ECX (note that L2 associativity field encodings rules consistent with AMD are used), all other fields are reserved. Therefore, make the following changes to CPUID[0x80000006]: * Check the vendor in CPUID[0x80000006] and just encode L2 to ECX for Intel. * Drop the lines_per_tag assertion, since AMD supports this field but Intel doesn't. And this field can be easily checked via cpuid tool in Guest. * Apply the encoding change of Intel for Zhaoxin as well [1]. This fix also resolves the FIXME of legacy_l2_cache_amd: /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ In addition, per AMD's APM, update the comment of CPUID[0x80000006]. [1]: https://lore.kernel.org/qemu-devel/c522ebb5-04d5-49c6-9ad8-d755b899898= 8@zhaoxin.com/ Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Changes Since v1: * Drop the lines_per_tag assertion in encode_cache_cpuid80000006(), since it breaks the case running Intel CPUs (with cache model) on PC/Q35 machine v10.0. Changes Since RFC: * Check vendor_cpuid_only_v2 instead of vendor_cpuid_only. * Move lines_per_tag assert check into encode_cache_cpuid80000006(). --- target/i386/cpu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e0d5a39e477c..609efb10ddb5 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -529,16 +529,15 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *= l2, { 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) | (X86_ENC_ASSOC(l2->associativity) << 12) | (l2->lines_per_tag << 8) | (l2->line_size); =20 + /* For Intel, EDX is reserved. */ 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) | (X86_ENC_ASSOC(l3->associativity) << 12) | @@ -710,7 +709,6 @@ static CPUCacheInfo legacy_l2_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, @@ -7902,11 +7900,20 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); break; case 0x80000006: - /* cache info (L2 cache) */ + /* cache info (L2 cache/TLB/L3 cache) */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } + + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *eax =3D *ebx =3D 0; + encode_cache_cpuid80000006(env->cache_info_cpuid4.l2_cache, + NULL, ecx, edx); + break; + } + *eax =3D (X86_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | (L2_DTLB_2M_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | @@ -7915,6 +7922,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); + encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, cpu->enable_l3_cache ? env->cache_info_amd.l3_cache : NULL, --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228283; cv=none; d=zohomail.com; s=zohoarc; b=BIbuPbKIWXpKJ6G9Uf8e9A1ZFj3Aw2a4suFvpbYk/n/DoBtlupoPZWSIUnBLa0IHvuawk/2t8OrnwjsCn3YhXe7UNG5YBTMBLggi8SOq7grpzsZhN1uZGggMkeZEDSgIGTikA13xf2q+0ZoAcfwmsg3VMMpJrgOF8GcQrvXCbhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228283; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=111MxUFWeZnjo6Wl5Meb5d2PVxLm0YVcAkSAKCzDddI=; b=kxciLhOjctuqNeTxBRbDFMapoNB693Qygj05+9ICsRWduzXPM8D1X1P14h4r4YwChXSLPYTjOxER60ZsN92Mn6F3KhtUcinDJwpap5yUuvkSX6RISHsB+2bu4o/5tYq3LarFXo/CRPftDzWGmkUjN5KdGAePIA5HDYkOq1zBon8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228283585681.6082058791778; Fri, 11 Jul 2025 03:04:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAZX-0003eL-GT; Fri, 11 Jul 2025 06:01:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZC-00037Z-EO for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:18 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZA-0005KY-9w for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:18 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:15 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228076; x=1783764076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2YgiqgBwgQ2xRniG9fxBQVr1kcJH4e6UNHL2Y40Boa4=; b=V689nWexp4fzUl7GTaGIn2Eheuac/UW2C220lVPW7b1I+fBkDodlABi1 Zb5vUhZtLcOSKILV2fUj3RSINnz+xXo6yYr4/ZysvXloaFHyil9xm4F49 x5Tn4R5mezefYKhf23DU6kJ8cZFTlCchQJoZvV9YfxEoyZcY3Ve0Cgynt r62/ILaxYeEeZqfNJWsgR6pry1Q9i17rNyWSonGQNR9BxkVRIIIiPNX40 2Ko4p/rCs9gJp1CYWzZGX2pQKu0pBD2EWGIOb09H8eeUFqLPmFHXrtBGs anBbHos45rz6TbaIxk1UPd6ecKJn7nRLpLrMYwvhWUsRxd0+Isd110F/d A==; X-CSE-ConnectionGUID: u3lGWztHSqKqgRu3STLDRA== X-CSE-MsgGUID: 6zGMIw2mRUOxASYHJkGOWQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496359" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496359" X-CSE-ConnectionGUID: EY0bXHd+ToO+CXcvqFBxmg== X-CSE-MsgGUID: /HPSHUnrRP+Axi4IeiDikw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662089" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 11/18] i386/cpu: Add legacy_intel_cache_info cache model Date: Fri, 11 Jul 2025 18:21:36 +0800 Message-Id: <20250711102143.1622339-12-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228285550116600 Content-Type: text/plain; charset="utf-8" Based on legacy_l1d_cache, legacy_l1i_cache, legacy_l2_cache and legacy_l3_cache, build a complete legacy intel cache model, which can clarify the purpose of these trivial legacy cache models, simplify the initialization of cache info in X86CPUState, and make it easier to handle compatibility later. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 101 +++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 609efb10ddb5..6cd942f95779 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -638,21 +638,6 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X86= CPUTopoInfo *topo_info, * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs */ - -/* L1 data cache: */ -static CPUCacheInfo legacy_l1d_cache =3D { - .type =3D DATA_CACHE, - .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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l1d_cache_amd =3D { .type =3D DATA_CACHE, .level =3D 1, @@ -667,20 +652,6 @@ static CPUCacheInfo legacy_l1d_cache_amd =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/* L1 instruction cache: */ -static CPUCacheInfo legacy_l1i_cache =3D { - .type =3D INSTRUCTION_CACHE, - .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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l1i_cache_amd =3D { .type =3D INSTRUCTION_CACHE, .level =3D 1, @@ -695,20 +666,6 @@ static CPUCacheInfo legacy_l1i_cache_amd =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/* Level 2 unified cache: */ -static CPUCacheInfo legacy_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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, @@ -798,6 +755,59 @@ static const CPUCaches legacy_intel_cpuid2_cache_info = =3D { }, }; =20 +static const CPUCaches legacy_intel_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, +}; + /* TLB definitions: */ =20 #define L1_DTLB_2M_ASSOC 1 @@ -8980,10 +8990,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) env->enable_legacy_cpuid2_cache =3D true; } =20 - env->cache_info_cpuid4.l1d_cache =3D &legacy_l1d_cache; - env->cache_info_cpuid4.l1i_cache =3D &legacy_l1i_cache; - env->cache_info_cpuid4.l2_cache =3D &legacy_l2_cache; - env->cache_info_cpuid4.l3_cache =3D &legacy_l3_cache; + env->cache_info_cpuid4 =3D legacy_intel_cache_info; =20 env->cache_info_amd.l1d_cache =3D &legacy_l1d_cache_amd; env->cache_info_amd.l1i_cache =3D &legacy_l1i_cache_amd; --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228292; cv=none; d=zohomail.com; s=zohoarc; b=gDIyrPOMuckRPPDxVlupkSEURf4Z+Nb3qY1iz/guRzPKLIF3+LjO6Ygxxljp6Avw9fj1yq1xzIdho5chOaw8h78MkXJCyFiPIdLRNKqQx2dFsnZ+iAAs8o9pi/n9IBpatmmy4Fsrzt+CPorUwvSL5LsUm5YffwRnWOyy8Il/xKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3rhpKBnORuDmArVwjZ70mkZwws4bvo9at2U9pzbgJIQ=; b=BWqmCbnr4fL7wpfuL/Q6LKOwSZIzLbs0ieL9OBcfxWmWA3k1d9aByaxmXWQrZwq9ullL+JiVRkPK+wGHcQtl33lXMA5b5yVUI47HRhvrFZxW+N/YYQMNS3vKUaOpOkGMVe+Rs3J1V8pqPsr+E8E49f4mG0+UCk4lfo+bqYSbT0M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228292942975.2560907280247; Fri, 11 Jul 2025 03:04:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAa7-00053E-3k; Fri, 11 Jul 2025 06:02:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZH-0003Tk-MN for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:24 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZF-0005KY-Il for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:23 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:20 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228081; x=1783764081; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k7XAWqK5epSjHbUsK5O+B5YEq6VSgB/UAnTZPzrTEwE=; b=Vvg+kJJzz9NB2c5EkWP+wh+/YtWOM2jZ8rIGZ8VGXozGv6ymTswRRZT+ MSzBV8s6nJBFIz5y+nQoAYNQ2YWpfuWSpbUSotMaUANyrXutDZu7svzB9 RgkWvFi9dCcOuprYsEku/ob/N6x6fte+n+Qy/dnqCartZ2uI04iEkHALz /dQdOVb1tYZZ8gmw2VrJncMRrMeL3Fl3cp0JuWpHlXMSS/CMBbxVx2u0R fYWptW7N3vSW1CX5MA62kSeVsNMU4msiLY/1IlSzUHq9+vpYf2TiMEVG6 qNB12DNXI5f9DV4iSqiF09Iixz9hEzrXpJdRL0L1QFC7fiGj61Rt86lIl g==; X-CSE-ConnectionGUID: 67NtHi2CQ7GhlFcDim2Jbg== X-CSE-MsgGUID: hjWSCEfFTn+90Rrb9HIvJA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496380" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496380" X-CSE-ConnectionGUID: LxjevcRPQD+fhEbi8zGBWw== X-CSE-MsgGUID: GRVwHIQdQZKqnA4ha5GhOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662114" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 12/18] i386/cpu: Add legacy_amd_cache_info cache model Date: Fri, 11 Jul 2025 18:21:37 +0800 Message-Id: <20250711102143.1622339-13-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228296140116600 Content-Type: text/plain; charset="utf-8" Based on legacy_l1d_cachei_amd, legacy_l1i_cache_amd, legacy_l2_cache_amd and legacy_l3_cache, build a complete legacy AMD cache model, which can clarify the purpose of these trivial legacy cache models, simplify the initialization of cache info in X86CPUState, and make it easier to handle compatibility later. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 112 ++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6cd942f95779..4a0505004bfb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -638,60 +638,58 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X8= 6CPUTopoInfo *topo_info, * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs */ -static CPUCacheInfo legacy_l1d_cache_amd =3D { - .type =3D DATA_CACHE, - .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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -static CPUCacheInfo legacy_l1i_cache_amd =3D { - .type =3D INSTRUCTION_CACHE, - .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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -static CPUCacheInfo legacy_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, - .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, -}; - -/* Level 3 unified cache: */ -static CPUCacheInfo legacy_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, - .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, +static const CPUCaches legacy_amd_cache_info =3D { + .l1d_cache =3D &(CPUCacheInfo) { + .type =3D DATA_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l1i_cache =3D &(CPUCacheInfo) { + .type =3D INSTRUCTION_CACHE, + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l2_cache =3D &(CPUCacheInfo) { + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, + }, + .l3_cache =3D &(CPUCacheInfo) { + .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, + .share_level =3D CPU_TOPOLOGY_LEVEL_DIE, + }, }; =20 /* @@ -8991,11 +8989,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) } =20 env->cache_info_cpuid4 =3D legacy_intel_cache_info; - - env->cache_info_amd.l1d_cache =3D &legacy_l1d_cache_amd; - env->cache_info_amd.l1i_cache =3D &legacy_l1i_cache_amd; - env->cache_info_amd.l2_cache =3D &legacy_l2_cache_amd; - env->cache_info_amd.l3_cache =3D &legacy_l3_cache; + env->cache_info_amd =3D legacy_amd_cache_info; } =20 #ifndef CONFIG_USER_ONLY --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228292; cv=none; d=zohomail.com; s=zohoarc; b=VBRte92r8Rtf4sG3THtjaUh1vKOGgjEssKuAQtYMNseDH2GrgNjBZL02uLL+O/kXxN0QEbc7l5bpUcgycX9ojDtQBszG06eROKdrRQ4xjOKxZVXWCwGzZqMUBV5+iM7GDXX+GMFjBPSM2FJ9QqMbM3c1kE3UlLjpuhdDQru0nbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Q9sTRC1Bl5vQZuIeORCBXwS7Qw2nov8FbPi6hmdJNRY=; b=Kl6skMljkydUMMvkxp7L4xT3Mruo1ufoQESmu08Atv/OqvFPoZcuQdzNHWTPGMp2vTnbbBwiOzD68spHGOIxELbMjowcKQdpgWdafN8oyeZwk3hs/thZQlQfH0S1bjbWHUfanhTl8K++ri7HU3+lQIwBJ4BE0Zxqq6K9BuCv8Wg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228292765961.9377184745924; Fri, 11 Jul 2025 03:04:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAaD-0005YB-Ni; Fri, 11 Jul 2025 06:02:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZO-0003h1-Nm for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:35 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZK-0005KY-En for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:30 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:25 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228086; x=1783764086; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UHCtpH2VK6WpA+WnzZ3YsdnTTvrM2MCq9aP8ih6Hyec=; b=XbaCGUHAyFCiw1HC4ReCtLEiRwPvKuFYwvVnWcfS/ZWLr+UEHCx0+thI zVHQuiXRnY9V7P+eLArrOk0apAAAFipx838UuAymLkXCL3Am3ngYlWTyA KskX2Zi0rAD5OqS+5hKH0i61tYmSOeen9560vW/t4w2790tcBfti07QUd dSDFT2g+ze7LCDNYDvFCSxF7Fb18e65nDA/w71Gt8OtPJudmDRyyzCAYY lIOyMh+g/U8yhJU0xMrcOs1oAdR6XMWnYEMJx9pTFgXOUyu8s1UAVtoHO We4U29EJsPak02+MSDXRIG6Z9FOzg7hyX3AH3Uj50Uplo3m3QKnG7CoGJ w==; X-CSE-ConnectionGUID: v9/IOjgaRlu6m+RNccMAoA== X-CSE-MsgGUID: QZCktMLnQ7etVSiHtn4YKw== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496401" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496401" X-CSE-ConnectionGUID: RmRFC3U/SGeM3n96YM6VUA== X-CSE-MsgGUID: I1fEkMz5TPOpQQIxPwyAhw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662129" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 13/18] i386/cpu: Select legacy cache model based on vendor in CPUID 0x2 Date: Fri, 11 Jul 2025 18:21:38 +0800 Message-Id: <20250711102143.1622339-14-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228296236116600 Content-Type: text/plain; charset="utf-8" As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x2 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model, otherwise, select legacy Intel cache model (in cache_info_cpuid4) as before. To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x2 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x2 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x2 leaf regardless of the vendor. Only AMD CPUs have all-0 leaf due to vendor_cpuid_only=3Dtrue, and this is exactly the behavior of these old machines. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model. Similarly, only AMD CPUs have all-0 leaf, and this is exactly the behavior of these old machines. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x2 leaf regardless of the vendor. And AMD CPUs have all-0 leaf. Nothing will change. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache but still get all-0 leaf due to vendor_cpuid_only=3Dtrue. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x2 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 47 +++++++++++++++++++++++++++++++++++++---------- target/i386/cpu.h | 1 + 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4a0505004bfb..34a82a378ccb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -248,23 +248,17 @@ static const CPUCaches legacy_intel_cpuid2_cache_info; =20 /* Encode cache info for CPUID[2] */ static void encode_cache_cpuid2(X86CPU *cpu, + const CPUCaches *caches, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { CPUX86State *env =3D &cpu->env; - const CPUCaches *caches; int l1d, l1i, l2, l3; bool unmatched =3D false; =20 *eax =3D 1; /* Number of CPUID[EAX=3D2] calls required */ *ebx =3D *ecx =3D *edx =3D 0; =20 - if (env->enable_legacy_cpuid2_cache) { - caches =3D &legacy_intel_cpuid2_cache_info; - } else { - caches =3D &env->cache_info_cpuid4; - } - l1d =3D cpuid2_cache_descriptor(caches->l1d_cache, &unmatched); l1i =3D cpuid2_cache_descriptor(caches->l1i_cache, &unmatched); l2 =3D cpuid2_cache_descriptor(caches->l2_cache, &unmatched); @@ -7474,8 +7468,37 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ebx |=3D threads_per_pkg << 16; } break; - case 2: - /* cache info: needed for Pentium Pro compatibility */ + case 2: { /* cache info: needed for Pentium Pro compatibility */ + const CPUCaches *caches; + + if (env->enable_legacy_cpuid2_cache) { + caches =3D &legacy_intel_cpuid2_cache_info; + } else if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_intel_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't use l= egacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD + * CPU will use cache_info_amd. But this doesn't matter for= AMD + * CPU, because this leaf encodes all-0 for AMD whatever it= s cache + * model is. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7483,8 +7506,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } - encode_cache_cpuid2(cpu, eax, ebx, ecx, edx); + encode_cache_cpuid2(cpu, caches, eax, ebx, ecx, edx); break; + } case 4: /* cache info: needed for Core compatibility */ if (cpu->cache_info_passthrough) { @@ -8988,6 +9012,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) env->enable_legacy_cpuid2_cache =3D true; } =20 + if (!cpu->vendor_cpuid_only_v2) { + env->enable_legacy_vendor_cache =3D true; + } env->cache_info_cpuid4 =3D legacy_intel_cache_info; env->cache_info_amd =3D legacy_amd_cache_info; } diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 03a7b735d090..bb474e65c4f7 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2078,6 +2078,7 @@ typedef struct CPUArchState { */ CPUCaches cache_info_cpuid4, cache_info_amd; bool enable_legacy_cpuid2_cache; + bool enable_legacy_vendor_cache; =20 /* MTRRs */ uint64_t mtrr_fixed[11]; --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228292; cv=none; d=zohomail.com; s=zohoarc; b=Ok2XgFsdjrCsFzDyu0w3gEBlMSD5/kWijVpBPPLXdPs40BURY6vUsRT0vVu6tdvpa4LvHO4lPI2Xs0G6iUrd1Y0BENsMOJ6WDbRc5ev5qM3KGkbPyRDvfKBeIy5G5fs7NZ5fkxhFxBLxIQUItPS9XiDm6m4mBMFMsIbcYd8oXsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mQBScKLw6V5ue3c2dvzOomhM8hauTpvdMKpSFrgtJXY=; b=RH7Arsdp+Q1HPG5mA3IjTVPPwhPgrOuqiWpG+pjBUjHK0Ke3VSNFaCH7Zje5BzVLW0XklHwmGdpkvJrnO452v2NqqLeOW7g/Rin7P8JOmYBFwQ3pD6cwGv8aPKlFbYAXsQoGDKiGB59T8vjkwFjo1TCMMrnfJR5DlPs8AsiJOVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228292909112.10955712196585; Fri, 11 Jul 2025 03:04:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAa8-00056N-OG; Fri, 11 Jul 2025 06:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZT-0003jJ-7J for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:38 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZQ-0005KY-K7 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:34 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:30 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228092; x=1783764092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j8odLVnM9w8fLy47xRX+1dq3IYxvEsda+LnJYmX4Fgk=; b=ARiT+dAPe1jjwPgFW7g+2WYj+5qqqU463VIzy5GQD+ex79Z52WXdpJda K4sFsEmwnKFZaNX5QJh9oEoznbBH0vK4rqYlnnmZwA7CETkS7yjz5ME2g aKY87dnCUmmX62pCMCReaaPwJh9kxU8SCE8EfJeHv735l7OH+BxOOJhzk Qivev6iPzkOZujOj1F8WCp48L6BfwNk4tvQDITyr2fIfHCb0U2SJvfLP2 mMQL4dd67HrfrwUDZ8n7ZfXOpRgedvfU04YBbNgEPT4beHp2sa+/tmDH8 gUUx1n4VJyDNGnI4fODUQf9FB2E2S18e0gQF6rEEAxXHqLzXy8ynC9TbN g==; X-CSE-ConnectionGUID: Tztie6g8SWCxaJgAa0UhIw== X-CSE-MsgGUID: sW0+xzJWTXaZIeBXhtaMfg== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496413" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496413" X-CSE-ConnectionGUID: yPrMTo30QZqMGdNTovpZQQ== X-CSE-MsgGUID: AX6m/CruRfWq2f/HEzhRTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662136" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 14/18] i386/cpu: Select legacy cache model based on vendor in CPUID 0x4 Date: Fri, 11 Jul 2025 18:21:39 +0800 Message-Id: <20250711102143.1622339-15-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228296177116600 Content-Type: text/plain; charset="utf-8" As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x4 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model, otherwise, select legacy Intel cache model (in cache_info_cpuid4) as before. To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x4 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x4 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x4 leaf regardless of the vendor. Only AMD CPUs have all-0 leaf due to vendor_cpuid_only=3Dtrue, and this is exactly the behavior of these old machines. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy Intel cache model. Similarly, only AMD CPUs have all-0 leaf, and this is exactly the behavior of these old machines. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x4 leaf regardless of the vendor. And AMD CPUs have all-0 leaf. Nothing will change. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache but still get all-0 leaf due to vendor_cpuid_only=3Dtrue. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x4 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 34a82a378ccb..73872cb74b6f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7509,7 +7509,35 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, encode_cache_cpuid2(cpu, caches, eax, ebx, ecx, edx); break; } - case 4: + case 4: { + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_intel_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't use l= egacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD + * CPU will use cache_info_amd. But this doesn't matter for= AMD + * CPU, because this leaf encodes all-0 for AMD whatever it= s cache + * model is. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + /* cache info: needed for Core compatibility */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -7537,30 +7565,26 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, =20 switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l1d_cache, - topo_info, + encode_cache_cpuid4(caches->l1d_cache, topo_info, eax, ebx, ecx, edx); if (!cpu->l1_cache_per_core) { *eax &=3D ~MAKE_64BIT_MASK(14, 12); } break; case 1: /* L1 icache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l1i_cache, - topo_info, + encode_cache_cpuid4(caches->l1i_cache, topo_info, eax, ebx, ecx, edx); if (!cpu->l1_cache_per_core) { *eax &=3D ~MAKE_64BIT_MASK(14, 12); } break; case 2: /* L2 cache info */ - encode_cache_cpuid4(env->cache_info_cpuid4.l2_cache, - topo_info, + encode_cache_cpuid4(caches->l2_cache, topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ if (cpu->enable_l3_cache) { - encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache, - topo_info, + encode_cache_cpuid4(caches->l3_cache, topo_info, eax, ebx, ecx, edx); break; } @@ -7571,6 +7595,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, } } break; + } case 5: /* MONITOR/MWAIT Leaf */ *eax =3D cpu->mwait.eax; /* Smallest monitor-line size in bytes */ --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228383; cv=none; d=zohomail.com; s=zohoarc; b=fWEnTuaVRXMll5j71slojbw36H5hh3esB21yzxhrSFMMZ6zoEC598AZFUJdw/QC0P802tl4l64fl0js1JXsvVfl6wm7Jly58IIBUdnAXQoyDoBu6Kiq2E78E8SipJWOvhtDjP+K3VlhHQepxyiIaVCLRFr/owmtOgdow2nZoEHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228383; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8ZmG7LnKklOF7GVh/J/6OIqR2C0zC4yyyPvrQXc0UB0=; b=Lfy84mwCx59fVARtLrVBcbYWqLJG9JuM1TTvdz14Ko1U1An5yDPZUQQSXNmCzm0Eouz6YmHFz04kcyQ6Bx+n8Pz0QYwotSIauTR40l8fjjI5Mh80wgr9AU6JVKv6qOujYdjJyCFZr8PPAG0ouO6pFHN77Zh+HVKPEbU4vXBd3bQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228383791793.6877593871579; Fri, 11 Jul 2025 03:06:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAa6-0004oY-HS; Fri, 11 Jul 2025 06:02:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZW-0003n6-4x for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:40 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZT-0005KY-UE for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:37 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:35 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228096; x=1783764096; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=htnFm4BrBbQOnh6jhI+zR4FEgr7u9fy4FwyoLCptThA=; b=Ho7F2GGDpLu7geZQ9WkYiOEZa9VKbfQwzyVaDSqBJ57R0k8jI5q1OEvd FiM1+At4Oke1fKML/pZrnJbZ8CwqVN3G8L0Ymnnm9K9zb4uYO7YCt4Pml cODakXX6CNdthDgUaVxBP9yYKbmqLv8YR0Or+ejoP/2vzgvi8Q9zy2fbH xXjrgsZy5TQuZpYO6D/9kWlYg+y58/IrRXtTXk4/bO8rR8OI7uKZjnaMe zbG0+3xzoCFdMIe0j/67UGekd1DDsw5eNwDQbivJwV/MorkShnoyJBGjy +9NuX3+jQcnRAmBsq1R9lkfKRRmehP7a1JlRa+jfphHHIocm8/CsUrfGg w==; X-CSE-ConnectionGUID: 58aAjJYpTQqqCDbufSVlmQ== X-CSE-MsgGUID: mdPERk/CQd2wsBh1HrmWrA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496423" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496423" X-CSE-ConnectionGUID: LkSMSK/JSeaJSx4zGPSBeQ== X-CSE-MsgGUID: HQ3KamkbRUicSIfLTvgtpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662145" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 15/18] i386/cpu: Select legacy cache model based on vendor in CPUID 0x80000005 Date: Fri, 11 Jul 2025 18:21:40 +0800 Message-Id: <20250711102143.1622339-16-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228384565116600 Content-Type: text/plain; charset="utf-8" As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x80000005 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x80000005 leaf, enable_legacy_vendor_cache flag indicates to pick legacy AMD cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x80000005 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy AMD cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - No change, since this leaf doesn't aware vendor_cpuid_only. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x80000005 leaf regardless of the vendor. Only Intel CPUs have all-0 leaf due to vendor_cpuid_only_2=3Dtrue, and this is exactly the expected behavior. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache as expected. For Intel CPU, it will use legacy Intel cache but still get all-0 leaf due to vendor_cpuid_only_2=3Dtrue as expected. (Note) And for Zhaoxin CPU, it will use legacy Intel cache model instead of AMD's. This is the difference brought by this change! But it's correct since then Zhaoxin could have the consistent cache info in CPUID 0x2, 0x4 and 0x80000005 leaves. Here, except Zhaoxin, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. And the change for Zhaoxin is also a good improvement. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x80000005 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Cc: EwanHai Tested-by: Yi Lai Signed-off-by: Zhao Liu --- Note, side effect of this patch: fix the inconsistency cache info for Zhaoxin. For more details, see the commit message above. --- target/i386/cpu.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 73872cb74b6f..22c955c44000 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7937,8 +7937,36 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx =3D env->cpuid_model[(index - 0x80000002) * 4 + 2]; *edx =3D env->cpuid_model[(index - 0x80000002) * 4 + 3]; break; - case 0x80000005: + case 0x80000005: { /* cache info (L1 cache/TLB Associativity Field) */ + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_amd_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't uses = legacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. AMD CPUs use cache_info_amd like before and non-A= MD + * CPU will use cache_info_cpuid4. But this doesn't matter, + * because for Intel CPU, it will get all-0 leaf, and Zhaox= in CPU + * will get correct cache info. Both are expected. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7953,9 +7981,10 @@ 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(env->cache_info_amd.l1d_cache); - *edx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); + *ecx =3D encode_cache_cpuid80000005(caches->l1d_cache); + *edx =3D encode_cache_cpuid80000005(caches->l1i_cache); break; + } case 0x80000006: /* cache info (L2 cache/TLB/L3 cache) */ if (cpu->cache_info_passthrough) { --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228246; cv=none; d=zohomail.com; s=zohoarc; b=I6ZMWYPp0nd/QtoyQdHMV1u1FTSffBpG56tceXvEPmY0+NR7CJy+uBrYQPXXpdPL7Capb1KeaSmj2sLwwq4CcpkLMaWD8zml2/VFSKwcVokwJh+vWmUY6ZbZT6j7CcGUwVHDcrZZgG3VIsu6NRcbOf9MAhHhxpT7PRRErAoNmWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228246; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IzLkSV6ae+vR7ouU5nT1a5Z7/qBwHvugl3YY+dmpRq0=; b=jSjGTkgEl/41snPRRVeN0Pzx7AjMsBxwfc5rFEFTfBoDMJG6Hyh9zPWpTuEQnhQw8KO6YgrOly1G10jdOmRHfaQoC7KRcmvH4yhXTK8JQFoSiWmoMmAia7cQ8W+nvazfk54Gti3mdPca35XQAmLQIDvxLbfscyeTFHDM1A7/x1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228246189578.431589721186; Fri, 11 Jul 2025 03:04:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAaJ-0005rC-VO; Fri, 11 Jul 2025 06:02:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZf-0003wj-HK for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:48 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZa-0005KY-5n for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:47 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:40 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228102; x=1783764102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KLtRBrU7pyXx+1v3WsNd6w0Pzc8d6ZFkUOlzgqUA5mQ=; b=OnGR+6wkPQ3LPC1g/pZloy7NK0pCgkQEzCsMUsRm93dFrPMc0c3zY4nu 4wdvcOMlhjGn1oPHAsYZsoSkcBSNKbyKTvMQMNfBSDIfkWifA/NPkzvCU SnZtxOHdcq1+FsmDOURA9wXdk4Wau0+VFp83ootl4dV18KLV9qROvTKHS Q4/cxovb/G7lpOFCU6boIXIWlMeTJRBAlWiHlWPfbKXlrEN7YA4sg4b63 Hxc7u/vVtAYE1RHAFa99fTK9a7O2KsA1LR7MoEuj1vqKQFW4yNrM46xnN galb/z0AVLFf2WN5qrf1dumZyfv0pv0elYp0uCv4GVORoPe6++NjNid5M A==; X-CSE-ConnectionGUID: zPeTBU5GRNaPK+sHI1QSVw== X-CSE-MsgGUID: d4Rm+pZRRm+3AdfBhiUOaA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496439" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496439" X-CSE-ConnectionGUID: a7hFDBWySc2fLCFB9aaxTQ== X-CSE-MsgGUID: In32M7ACR7GHbpWOwAtV2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662152" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 16/18] i386/cpu: Select legacy cache model based on vendor in CPUID 0x80000006 Date: Fri, 11 Jul 2025 18:21:41 +0800 Message-Id: <20250711102143.1622339-17-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228246915116600 Content-Type: text/plain; charset="utf-8" As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x80000006 leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). To ensure compatibility is not broken, add an enable_legacy_vendor_cache flag based on x-vendor-only-v2 to indicate cases where the legacy cache model should be used regardless of the vendor. For CPUID 0x80000006 leaf, enable_legacy_vendor_cache flag indicates to pick legacy Intel cache model, which is for compatibility with the behavior of PC machine v10.0 and older. The following explains how current vendor-based default legacy cache model ensures correctness without breaking compatibility. * For the PC machine v6.0 and older, vendor_cpuid_only=3Dfalse, and vendor_cpuid_only_v2=3Dfalse. - If the named CPU model has its own cache model, and doesn't use legacy cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 and cache_info_amd are same, so 0x80000006 leaf uses its own cache model regardless of the vendor. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is true, they will use legacy AMD cache model just like their previous behavior. * For the PC machine v10.0 and older (to v6.1), vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dfalse. - No change, since this leaf doesn't aware vendor_cpuid_only. * For the PC machine v10.1 and newer, vendor_cpuid_only=3Dtrue, and vendor_cpuid_only_v2=3Dtrue. - If the named CPU model has its own cache model (legacy_cache=3Dfalse), then cache_info_cpuid4 & cache_info_amd both equal to its own cache model, so it uses its own cache model in 0x80000006 leaf regardless of the vendor. Intel and Zhaoxin CPUs have their special encoding based on SDM, which is the expected behavior and no different from before. - For max/host/named CPU (without its own cache model), then the flag enable_legacy_vendor_cache is false, the legacy cache model is selected based on vendor. For AMD CPU, it will use legacy AMD cache as before. For non-AMD (Intel/Zhaoxin) CPU, it will use legacy Intel cache and be encoded based on SDM as expected. Here, selecting the legacy cache model based on the vendor does not change the previous (before the change) behavior. Therefore, the above analysis proves that, with the help of the flag enable_legacy_vendor_cache, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x80000006 leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 22c955c44000..fe1c118b284f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7985,8 +7985,33 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D encode_cache_cpuid80000005(caches->l1i_cache); break; } - case 0x80000006: - /* cache info (L2 cache/TLB/L3 cache) */ + case 0x80000006: { /* cache info (L2 cache/TLB/L3 cache) */ + const CPUCaches *caches; + + if (env->enable_legacy_vendor_cache) { + caches =3D &legacy_amd_cache_info; + } else { + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * This condition covers the following cases (with + * enable_legacy_vendor_cache=3Dfalse): + * - When CPU model has its own cache model and doesn't uses = legacy + * cache model (legacy_model=3Doff). Then cache_info_amd and + * cache_info_cpuid4 are the same. + * + * - For v10.1 and newer machines, when CPU model uses legacy= cache + * model. AMD CPUs use cache_info_amd like before and non-A= MD + * CPU (Intel & Zhaoxin) will use cache_info_cpuid4 as expe= cted. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + } + if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; @@ -7995,7 +8020,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, if (cpu->vendor_cpuid_only_v2 && (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { *eax =3D *ebx =3D 0; - encode_cache_cpuid80000006(env->cache_info_cpuid4.l2_cache, + encode_cache_cpuid80000006(caches->l2_cache, NULL, ecx, edx); break; } @@ -8009,11 +8034,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); =20 - encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, + encode_cache_cpuid80000006(caches->l2_cache, cpu->enable_l3_cache ? - env->cache_info_amd.l3_cache : NULL, + caches->l3_cache : NULL, ecx, edx); break; + } case 0x80000007: *eax =3D 0; *ebx =3D env->features[FEAT_8000_0007_EBX]; --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228246; cv=none; d=zohomail.com; s=zohoarc; b=I0oUStUYpI9a4Ns9QaCaDMZZF+ipicJ35cf80N+qnIAFGd+26ya6r8pVMvtd9s/eI5d2jB3W42V7toq0IVAJtXf7Ucmjm9kH6nHvfnwwNWOoADfJSbpO0kchjPjWaVrxArNn9wuAbuRkdi40K7W+GnKOFF35CHI/G91tKrkShRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228246; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Cl1uXL8p22znqLBNNHNmkP8u3WqiSG893BdAeYsMUe8=; b=KgkFUyfza4UdW94Z7qM25EueM7ODnt/Syweg2Ks2zQmZUIkzeI+rIjOknBd4jbBr2dxPseQ/hRObV9aH+jPvw2YBv+LVmzXpXuVRMjGte3KIO/qagUfRl8tHfHlFbnu7Q67jMGpzDnkQwIIKAKX5C6DLToItL+v1ATYZbty/2Qw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228246189943.6424748999239; Fri, 11 Jul 2025 03:04:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAaC-0005Rs-8S; Fri, 11 Jul 2025 06:02:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZg-0003wv-Hg for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:48 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZe-0005cy-9n for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:48 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:45 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228106; x=1783764106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XIdoThL/w+88qJ0nzFUPEXeYz1YyOXsdwaPKHQb2Un8=; b=KWwYyYp+fZQOFq7il7Dn2MCGAjOVp4c/ZmSMvavRKBcsLzXM339ERKQm maDgcJSWfcBTwbBPNBn1F9+VISMJXdgpNl51DqNagbl/9jutbb7dMINml sLfir4XS/nh8qglGTYZtrOLQ4JZl3cLGDR+K9edNd2gOBJ664QQjk5TWK P+s1zRKxpa2hV17C9chYVc0WqAbBSqZXBJXMDdOMcGI73Oe9+rprAGBps eGxSd50rY1VQnYMvH0vwvwIeFqEITOxAAq+7NB0jhFr89TvdIBAe/+n0i vPQT3skJ+uEvsQ9e3TibBuounzBTxKANfPCLn+KI2BAeoDZIQkr0H5wt0 A==; X-CSE-ConnectionGUID: lw1veNEgSP2hv0gGIK9RFQ== X-CSE-MsgGUID: w85HEczXSiyke0vmZ9p5rw== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496451" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496451" X-CSE-ConnectionGUID: VE1FAdX3SfqhL5gNMRIQvQ== X-CSE-MsgGUID: vdtHbcFEQEqYm/U0kIVTnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662159" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu Subject: [PATCH v2 17/18] i386/cpu: Select legacy cache model based on vendor in CPUID 0x8000001D Date: Fri, 11 Jul 2025 18:21:42 +0800 Message-Id: <20250711102143.1622339-18-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228248834116600 Content-Type: text/plain; charset="utf-8" As preparation for merging cache_info_cpuid4 and cache_info_amd in X86CPUState, set legacy cache model based on vendor in the CPUID 0x8000001D leaf. For AMD CPU, select legacy AMD cache model (in cache_info_amd) as the default cache model like before, otherwise, select legacy Intel cache model (in cache_info_cpuid4). In fact, for Intel (and Zhaoxin) CPU, this change is safe because the extended CPUID level supported by Intel is up to 0x80000008. So Intel Guest doesn't have this 0x8000001D leaf. Although someone could bump "xlevel" up to 0x8000001D for Intel Guest, it's meaningless and this is undefined behavior. This leaf should be considered reserved, but the SDM does not explicitly state this. So, there's no need to specifically use vendor_cpuid_only_v2 to fix anything, as it doesn't even qualify as a fix since nothing is currently broken. Therefore, it is acceptable to select the default legacy cache model based on the vendor. For the CPUID 0x8000001D leaf, in X86CPUState, a unified cache_info is enough. It only needs to be initialized and configured with the corresponding legacy cache model based on the vendor. Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fe1c118b284f..df13dbc63a3f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8082,7 +8082,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; } break; - case 0x8000001D: + case 0x8000001D: { + const CPUCaches *caches; + + /* + * FIXME: Temporarily select cache info model here based on + * vendor, and merge these 2 cache info models later. + * + * Intel doesn't support this leaf so that Intel Guests don't + * have this leaf. This change is harmless to Intel CPUs. + */ + if (IS_AMD_CPU(env)) { + caches =3D &env->cache_info_amd; + } else { + caches =3D &env->cache_info_cpuid4; + } + *eax =3D 0; if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -8090,19 +8105,19 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, + encode_cache_cpuid8000001d(caches->l1d_cache, topo_info, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, + encode_cache_cpuid8000001d(caches->l1i_cache, topo_info, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, + encode_cache_cpuid8000001d(caches->l2_cache, topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, + encode_cache_cpuid8000001d(caches->l3_cache, topo_info, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -8113,6 +8128,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *edx &=3D CACHE_NO_INVD_SHARING | CACHE_INCLUSIVE; } break; + } case 0x8000001E: if (cpu->core_id <=3D 255) { encode_topo_cpuid8000001e(cpu, topo_info, eax, ebx, ecx, edx); --=20 2.34.1 From nobody Mon Feb 9 20:52:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1752228325; cv=none; d=zohomail.com; s=zohoarc; b=SZPbY611aZYsuvOlTI1QZ05nOZsEnsZh4KgMpqbqEKw4t3KCKHRjSU5ciho708pSdH+MRMYFnfZrnSNERb9KT4Hkoo6FH+MsxZWI3Rsrk3iVrAs1oNjQmcVrUi0Hhuha/aOczJpqGRMhV0rFmkFRmbW/Nty8vTfMTl+Ieh3GKNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752228325; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=V1HSs1Du72UeowTtQQVfLg1eB1aXKys33opqa4RSbsA=; b=CBE5Rtt6z+vYwbAXLD+LOmf87aEVHXcIXW3qXcbGBPxZt4Ou7Eh7IdO3HvTHmiRu7SaGldAhxA0mQ9FoM3sJTYS453j2gFmI7zCGQH0yeQqGDj2YmZIiyjt0J00Sx9tq7KUr+3SAIqQdwsGTe4ak/QCJBmXu1Eb/tkDlDiP/5NI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752228325259306.7559402064537; Fri, 11 Jul 2025 03:05:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaAaI-0005hc-4D; Fri, 11 Jul 2025 06:02:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZq-00047C-Pl for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:59 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaAZk-0005gb-OJ for qemu-devel@nongnu.org; Fri, 11 Jul 2025 06:01:58 -0400 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2025 03:01:50 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2025 03:01:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752228113; x=1783764113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2otHjRjWFXMpNbrnGgfOTh3c1Qw0xqo7w+y00sXBUEI=; b=PdZXBzjKw0u+iaWKLz38sitc9f5IU6xr6d5Cza8REtIswz165qwF/5ca r/eE+TIHdagaFDg7HMZuT3WirrckbxGPGHRBVZ3luXL5mwV3qwINMax8d wCFsG1hzBYW/Vx8zzbTQI5gSJ7MUeFENk4ZVPEqWJTuVQaTbzbbfuGsqG CbHyYHnBgG9QTkRbkP/YG0qe3ZwOhxWi9Y0aj0I9u26DaaTq1to40lhr0 t8HWJdUXiGQJ73eZknqo5eR1lUJxr0NIfzYzp0u4it87MHZPE1L+wPex6 aEvWW0IbTGGUj8kMICQEWm8d0zA4m96HUUpVvZqvbB0t1MtvVxCUacsXg A==; X-CSE-ConnectionGUID: foWwodNbSt6Q8V7X8KDV6g== X-CSE-MsgGUID: lEX6nL8mTXmbpeWYRkV3WA== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="54496464" X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="54496464" X-CSE-ConnectionGUID: qYYYD/I+QluSm8oJY8FfVA== X-CSE-MsgGUID: xxeM9sLLSjyWseOo+Fo72g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,303,1744095600"; d="scan'208";a="160662165" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , "Michael S . Tsirkin" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger , Ewan Hai , Pu Wen , Tao Su , Yi Lai , Dapeng Mi , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhao Liu , Dapeng Mi Subject: [PATCH v2 18/18] i386/cpu: Use a unified cache_info in X86CPUState Date: Fri, 11 Jul 2025 18:21:43 +0800 Message-Id: <20250711102143.1622339-19-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250711102143.1622339-1-zhao1.liu@intel.com> References: <20250711102143.1622339-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1752228327910116600 Content-Type: text/plain; charset="utf-8" At present, all cases using the cache model (CPUID 0x2, 0x4, 0x80000005, 0x80000006 and 0x8000001D leaves) have been verified to be able to select either cache_info_intel or cache_info_amd based on the vendor. Therefore, further merge cache_info_intel and cache_info_amd into a unified cache_info in X86CPUState, and during its initialization, set different legacy cache models based on the vendor. Reviewed-by: Dapeng Mi Tested-by: Yi Lai Signed-off-by: Zhao Liu --- target/i386/cpu.c | 150 ++++++++-------------------------------------- target/i386/cpu.h | 5 +- 2 files changed, 27 insertions(+), 128 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index df13dbc63a3f..7f88fe0c8697 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7476,27 +7476,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } else if (env->enable_legacy_vendor_cache) { caches =3D &legacy_intel_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't use l= egacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD - * CPU will use cache_info_amd. But this doesn't matter for= AMD - * CPU, because this leaf encodes all-0 for AMD whatever it= s cache - * model is. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -7515,27 +7495,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_intel_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't use l= egacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. Non-AMD CPUs use cache_info_cpuid4 like before an= d AMD - * CPU will use cache_info_amd. But this doesn't matter for= AMD - * CPU, because this leaf encodes all-0 for AMD whatever it= s cache - * model is. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 /* cache info: needed for Core compatibility */ @@ -7944,27 +7904,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_amd_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't uses = legacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. AMD CPUs use cache_info_amd like before and non-A= MD - * CPU will use cache_info_cpuid4. But this doesn't matter, - * because for Intel CPU, it will get all-0 leaf, and Zhaox= in CPU - * will get correct cache info. Both are expected. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -7991,25 +7931,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, if (env->enable_legacy_vendor_cache) { caches =3D &legacy_amd_cache_info; } else { - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * This condition covers the following cases (with - * enable_legacy_vendor_cache=3Dfalse): - * - When CPU model has its own cache model and doesn't uses = legacy - * cache model (legacy_model=3Doff). Then cache_info_amd and - * cache_info_cpuid4 are the same. - * - * - For v10.1 and newer machines, when CPU model uses legacy= cache - * model. AMD CPUs use cache_info_amd like before and non-A= MD - * CPU (Intel & Zhaoxin) will use cache_info_cpuid4 as expe= cted. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } + caches =3D &env->cache_info; } =20 if (cpu->cache_info_passthrough) { @@ -8082,22 +8004,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; } break; - case 0x8000001D: { - const CPUCaches *caches; - - /* - * FIXME: Temporarily select cache info model here based on - * vendor, and merge these 2 cache info models later. - * - * Intel doesn't support this leaf so that Intel Guests don't - * have this leaf. This change is harmless to Intel CPUs. - */ - if (IS_AMD_CPU(env)) { - caches =3D &env->cache_info_amd; - } else { - caches =3D &env->cache_info_cpuid4; - } - + case 0x8000001D: *eax =3D 0; if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, count, eax, ebx, ecx, edx); @@ -8105,19 +8012,19 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid8000001d(caches->l1d_cache, + encode_cache_cpuid8000001d(env->cache_info.l1d_cache, topo_info, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(caches->l1i_cache, + encode_cache_cpuid8000001d(env->cache_info.l1i_cache, topo_info, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(caches->l2_cache, + encode_cache_cpuid8000001d(env->cache_info.l2_cache, topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(caches->l3_cache, + encode_cache_cpuid8000001d(env->cache_info.l3_cache, topo_info, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -8128,7 +8035,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *edx &=3D CACHE_NO_INVD_SHARING | CACHE_INCLUSIVE; } break; - } case 0x8000001E: if (cpu->core_id <=3D 255) { encode_topo_cpuid8000001e(cpu, topo_info, eax, ebx, ecx, edx); @@ -8825,46 +8731,34 @@ static bool x86_cpu_update_smp_cache_topo(MachineSt= ate *ms, X86CPU *cpu, =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l1d_cache->share_level =3D level; - env->cache_info_amd.l1d_cache->share_level =3D level; + env->cache_info.l1d_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, - env->cache_info_cpuid4.l1d_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, - env->cache_info_amd.l1d_cache->share_level); + env->cache_info.l1d_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l1i_cache->share_level =3D level; - env->cache_info_amd.l1i_cache->share_level =3D level; + env->cache_info.l1i_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, - env->cache_info_cpuid4.l1i_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, - env->cache_info_amd.l1i_cache->share_level); + env->cache_info.l1i_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l2_cache->share_level =3D level; - env->cache_info_amd.l2_cache->share_level =3D level; + env->cache_info.l2_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, - env->cache_info_cpuid4.l2_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, - env->cache_info_amd.l2_cache->share_level); + env->cache_info.l2_cache->share_level); } =20 level =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3); if (level !=3D CPU_TOPOLOGY_LEVEL_DEFAULT) { - env->cache_info_cpuid4.l3_cache->share_level =3D level; - env->cache_info_amd.l3_cache->share_level =3D level; + env->cache_info.l3_cache->share_level =3D level; } else { machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, - env->cache_info_cpuid4.l3_cache->share_level); - machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, - env->cache_info_amd.l3_cache->share_level); + env->cache_info.l3_cache->share_level); } =20 if (!machine_check_smp_cache(ms, errp)) { @@ -9101,7 +8995,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) "CPU model '%s' doesn't support legacy-cache=3Doff"= , name); return; } - env->cache_info_cpuid4 =3D env->cache_info_amd =3D *cache_info; + env->cache_info =3D *cache_info; } else { /* Build legacy cache information */ if (!cpu->consistent_cache) { @@ -9111,8 +9005,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) if (!cpu->vendor_cpuid_only_v2) { env->enable_legacy_vendor_cache =3D true; } - env->cache_info_cpuid4 =3D legacy_intel_cache_info; - env->cache_info_amd =3D legacy_amd_cache_info; + + if (IS_AMD_CPU(env)) { + env->cache_info =3D legacy_amd_cache_info; + } else { + env->cache_info =3D legacy_intel_cache_info; + } } =20 #ifndef CONFIG_USER_ONLY diff --git a/target/i386/cpu.h b/target/i386/cpu.h index bb474e65c4f7..3eecee3721b8 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2072,11 +2072,12 @@ typedef struct CPUArchState { /* Features that were explicitly enabled/disabled */ FeatureWordArray user_features; uint32_t cpuid_model[12]; - /* Cache information for CPUID. When legacy-cache=3Don, the cache data + /* + * Cache information for CPUID. When legacy-cache=3Don, the cache data * on each CPUID leaf will be different, because we keep compatibility * with old QEMU versions. */ - CPUCaches cache_info_cpuid4, cache_info_amd; + CPUCaches cache_info; bool enable_legacy_cpuid2_cache; bool enable_legacy_vendor_cache; =20 --=20 2.34.1