From: Qian Wen <qian.wen@intel.com>
To: qemu-devel@nongnu.org
Cc: xiaoyao.li@intel.com, zhao1.liu@intel.com, pbonzini@redhat.com,
richard.henderson@linaro.org, babu.moger@amd.com,
Qian Wen <qian.wen@intel.com>,
Isaku Yamahata <isaku.yamahata@intel.com>
Subject: [PATCH v4 2/2] target/i386: Avoid overflow of the cache parameter enumerated by leaf 4
Date: Tue, 29 Aug 2023 12:24:05 +0800 [thread overview]
Message-ID: <20230829042405.932523-3-qian.wen@intel.com> (raw)
In-Reply-To: <20230829042405.932523-1-qian.wen@intel.com>
According to SDM, CPUID.0x4:EAX[31:26] indicates the Maximum number of
addressable IDs for processor cores in the physical package. If we
launch over 64 cores VM, the 6-bit field will overflow, and the wrong
core_id number will be reported.
Since the HW reports 0x3f when the intel processor has over 64 cores,
limit the max value written to EBX[31:26] to 63, so max num_cores should
be 64.
Signed-off-by: Qian Wen <qian.wen@intel.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
target/i386/cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index fc0437bdb1..90fe0a6a46 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -248,7 +248,7 @@ static void encode_cache_cpuid4(CPUCacheInfo *cache,
*eax = CACHE_TYPE(cache->type) |
CACHE_LEVEL(cache->level) |
(cache->self_init ? CACHE_SELF_INIT_LEVEL : 0) |
- ((num_cores - 1) << 26) |
+ ((MIN(num_cores, 64) - 1) << 26) |
((num_apic_ids - 1) << 14);
assert(cache->line_size > 0);
--
2.25.1
next prev parent reply other threads:[~2023-08-29 4:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 4:24 [PATCH v4 0/2] Fix overflow of the max number of IDs for logic processor and core Qian Wen
2023-08-29 4:24 ` [PATCH v4 1/2] target/i386: Avoid cpu number overflow in legacy topology Qian Wen
2023-08-29 4:24 ` Qian Wen [this message]
2023-09-11 5:38 ` [PATCH v4 0/2] Fix overflow of the max number of IDs for logic processor and core Wen, Qian
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=20230829042405.932523-3-qian.wen@intel.com \
--to=qian.wen@intel.com \
--cc=babu.moger@amd.com \
--cc=isaku.yamahata@intel.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=xiaoyao.li@intel.com \
--cc=zhao1.liu@intel.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).