From 447798cd3a78c8bfc5adb90254d50d22a838b301 Mon Sep 17 00:00:00 2001 From: Tom Lendacky Date: Tue, 7 Nov 2023 06:45:30 +0800 Subject: [PATCH] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf The CPUID_EXTENDED_TOPOLOGY CPUID leaf takes a subleaf as input when returning CPUID information. However, the AsmCpuid() function does not zero out ECX before the CPUID instruction, so the input leaf is used as the sub-leaf for the CPUID request and returns erroneous/invalid CPUID data, since the intent of the request was to get data related to sub-leaf 0. Instead, use AsmCpuidEx() for the CPUID_EXTENDED_TOPOLOGY leaf. Fixes: d4d7c9ad5fe5 ("UefiCpuPkg/MpInitLib: use BSP to do extended ...") Signed-off-by: Tom Lendacky Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/AmdSev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpInitLib/AmdSev.c index bda4960f6f..d34f9513e0 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -256,7 +256,14 @@ FillExchangeInfoDataSevEs ( if (StdRangeMax >= CPUID_EXTENDED_TOPOLOGY) { CPUID_EXTENDED_TOPOLOGY_EBX ExtTopoEbx; - AsmCpuid (CPUID_EXTENDED_TOPOLOGY, NULL, &ExtTopoEbx.Uint32, NULL, NULL); + AsmCpuidEx ( + CPUID_EXTENDED_TOPOLOGY, + 0, + NULL, + &ExtTopoEbx.Uint32, + NULL, + NULL + ); ExchangeInfo->ExtTopoAvail = !!ExtTopoEbx.Bits.LogicalProcessors; } }