UefiCpuPkg/MpInitLib: Fix random SEV-ES guest boot crash

The SevSnpKnownInitApicId field within the MP_CPU_EXCHANGE_INFO structure
is not guaranteed to be zero when booting an SEV-ES guest. While the check
in SevSnpGetInitCpuNumber() is conditionally guarded by verifying if the
guest is an SEV-SNP guest, the check in SevEsGetApicId() is not similarly
guarded.

This lack of protection can cause SevEsGetApicId() to return to the wrong
location. If the value of the SevSnpKnownInitApicId field contains the
exact random value of 1, the guest will be treated as an SEV-SNP guest
rather than an SEV-ES guest and return to the wrong location in the code
which will lead to a crash.

Ensure that all SEV related fields in MP_CPU_EXCHANGE_INFO structure are
properly initialized, thus removing the need for guarding access to the
SevSnpKnownInitApicId field.

Fixes: dca5d26bc5 ("UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
This commit is contained in:
Tom Lendacky
2025-07-15 10:07:24 -05:00
committed by mergify[bot]
parent 0bb4cf0228
commit 046ba401c2
3 changed files with 5 additions and 12 deletions

View File

@@ -293,8 +293,6 @@ FillExchangeInfoDataSevEs (
);
ExchangeInfo->ExtTopoAvail = !!ExtTopoEbx.Bits.LogicalProcessors;
}
ExchangeInfo->SevSnpKnownInitApicId = FALSE;
}
/**

View File

@@ -1018,9 +1018,11 @@ FillExchangeInfoData (
ExchangeInfo->Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));
ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
ExchangeInfo->ExtTopoAvail = FALSE;
ExchangeInfo->SevSnpKnownInitApicId = FALSE;
//
// Populate SEV-ES specific exchange data.

View File

@@ -23,13 +23,6 @@
; relationship getting out of sync after the first AP boot.
;
SevSnpGetInitCpuNumber:
;
; If not an SNP guest, leave EBX (CpuNumber) as is
;
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)]
cmp byte [edi], 1 ; SevSnpIsEnabled
jne SevSnpGetCpuNumberDone
;
; If not starting the AP with a specific ApicId, leave EBX (CpuNumber) as is
;