edk2/UefiCpuPkg/Library/MpInitLib
Tom Lendacky dca5d26bc5 UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs
A typical initial AP boot up will choose a CpuNumber based on the ApIndex
value that it gets back after a locked increment of the ApIndex value.
The ApIndex to APIC ID relationship is random, which is not an issue when
a broadcast INIT-SIPI is performed.

With SNP and a hypervisor that supports retrieval of the known APIC IDs,
the broadcast INIT-SIPI method is replaced by waking each individual vCPU.
In this situation, a specific VMSA is associated with a specific APIC ID.
However, random assignment of an ApIndex can break this association. This
isn't typically an issue, because the AP bring-up finishes with the AP
issuing a HLT instruction, which is intercepted by the hypervisor and the
AP won't run again until the next INIT-SIPI. However, when HLT isn't
intercepted by the hypervisor (Qemu '-overcommit cpu-pm=on' parameter),
then the HLT does not exit to the hypervisor. On the next INIT-SIPI, it
can happen that a VMRUN is executed with a different VMSA address than
was originally used, and if that VMSA is still in a VMRUN on another AP,
then the executing VMRUN will fail, crashing the guest.

To fix this issue, add a CPU exchange info field, SevSnpKnownInitApicId,
that indicates the APs are starting with an already known initial APIC ID
and set the initial APIC ID and APIC ID in the CPU_INFO_IN_HOB HOB.
During AP boot, the SevSnpKnownInitApicId field will result in the
CpuNumber being set to the index with a matching APIC ID (similar to AP
booting when the InitFlag != ApInitConfig).

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
2025-05-02 23:38:20 +00:00
..
Ia32 UefiCpuPkg: Disable PG in IA32 ApLoopCode 2024-06-04 07:40:27 +00:00
LoongArch64 UefiCpuPkg: Using the new name of LoongArch CSR 0x20 register 2024-08-30 19:54:01 +00:00
X64 UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs 2025-05-02 23:38:20 +00:00
AmdSev.c UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs 2025-05-02 23:38:20 +00:00
DxeMpInitLib.inf UefiCpuPkg: Fix unchecked returns and potential integer overflows 2024-11-15 17:50:21 +00:00
DxeMpInitLib.uni UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00
DxeMpLib.c UefiCpuPkg: Fix unchecked returns and potential integer overflows 2024-11-15 17:50:21 +00:00
Microcode.c UefiCpuPkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
MpEqu.inc UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs 2025-05-02 23:38:20 +00:00
MpHandOff.h UefiCpuPkg/MpInitLib: add struct MP_HAND_OFF_CONFIG 2024-02-29 09:56:38 +00:00
MpLib.c UefiCpuPkg: Fix unchecked returns and potential integer overflows 2024-11-15 17:50:21 +00:00
MpLib.h UefiCpuPkg/MpInitLib: Fix SNP AP creation when using known APIC IDs 2025-05-02 23:38:20 +00:00
PeiMpInitLib.inf UefiCpuPkg: Fix unchecked returns and potential integer overflows 2024-11-15 17:50:21 +00:00
PeiMpInitLib.uni UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00
PeiMpLib.c UefiCpuPkg: Fix unchecked returns and potential integer overflows 2024-11-15 17:50:21 +00:00