From: Zhao Liu <zhao1.liu@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Chuang Xu" <xuchuangxclwt@bytedance.com>,
"Xiaoyao Li" <xiaoyao.li@intel.com>,
"Isaku Yamahata" <isaku.yamahata@intel.com>,
"Babu Moger" <babu.moger@amd.com>
Cc: qemu-devel@nongnu.org, Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH 4/4] i386/cpu: Honor maximum value for CPUID.8000001DH.EAX[25:14]
Date: Thu, 27 Feb 2025 14:25:23 +0800 [thread overview]
Message-ID: <20250227062523.124601-5-zhao1.liu@intel.com> (raw)
In-Reply-To: <20250227062523.124601-1-zhao1.liu@intel.com>
CPUID.8000001DH:EAX[25:14] is "NumSharingCache", and the number of
logical processors sharing this cache is the value of this field
incremented by 1. Because of its width limitation, the maximum value
currently supported is 4095.
Though at present Q35 supports up to 4096 CPUs, to prevent potential
overflow issues from further increasing the number of CPUs in the
future, check and honor the maximum value as CPUID.04H did.
Cc: Babu Moger <babu.moger@amd.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
RFC:
* Although there are currently no overflow cases, to avoid any
potential issue, add the overflow check, just as I did for Intel.
---
target/i386/cpu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index d75175b0850a..7ca9740e8c97 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -493,7 +493,8 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache,
*eax = CACHE_TYPE(cache->type) | CACHE_LEVEL(cache->level) |
(cache->self_init ? CACHE_SELF_INIT_LEVEL : 0);
- *eax |= max_thread_ids_for_cache(topo_info, cache->share_level) << 14;
+ /* Bits 25:14 - NumSharingCache: maximum 4095. */
+ *eax |= MIN(max_thread_ids_for_cache(topo_info, cache->share_level), 4095) << 14;
assert(cache->line_size > 0);
assert(cache->partitions > 0);
--
2.34.1
next prev parent reply other threads:[~2025-02-27 6:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 6:25 [PATCH 0/4] i386/cpu: Fix topological field encoding & overflow Zhao Liu
2025-02-27 6:25 ` [PATCH 1/4] i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16] Zhao Liu
2025-05-12 9:32 ` Michael Tokarev
2025-05-13 3:42 ` Zhao Liu
2025-02-27 6:25 ` [PATCH 2/4] i386/cpu: Fix cpu number overflow in CPUID.01H.EBX[23:16] Zhao Liu
2025-02-27 7:13 ` Xiaoyao Li
2025-02-27 6:25 ` [PATCH 3/4] i386/cpu: Fix overflow of cache topology fields in CPUID.04H Zhao Liu
2025-02-27 7:14 ` Xiaoyao Li
2025-02-27 6:25 ` Zhao Liu [this message]
2025-05-21 8:53 ` [PATCH 0/4] i386/cpu: Fix topological field encoding & overflow Zhao Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250227062523.124601-5-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=babu.moger@amd.com \
--cc=berrange@redhat.com \
--cc=imammedo@redhat.com \
--cc=isaku.yamahata@intel.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xiaoyao.li@intel.com \
--cc=xuchuangxclwt@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).