UefiCpuPkg/MpInitLib: Avoid calling PEI services from AP

Today's MpInitLib PEI implementation directly calls
PeiServices->GetHobList() from AP which may cause racing issue.

This patch fixes this issue by duplicating IDT for APs.
Because CpuMpData structure is stored just after IDT, the CpuMPData
address equals to IDTR.BASE + IDTR.LIMIT + 1.

v2:
  1. Add ALIGN_VALUE() on BufferSize.
  2. Add ASSERT() to make sure no memory usage outside of the allocated buffer.
  3. Add more comments in InitConfig path when restoring CpuData[0].VolatileRegisters.

Cc: Jeff Fan <vanjeff_919@hotmail.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Fish Andrew <afish@apple.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Ni, Ruiyu
2018-07-02 14:01:35 +08:00
committed by Eric Dong
parent 895b87e380
commit c563077a38
2 changed files with 62 additions and 13 deletions

View File

@@ -27,6 +27,8 @@ EnableDebugAgent (
/**
Get pointer to CPU MP Data structure.
For BSP, the pointer is retrieved from HOB.
For AP, the structure is just after IDT.
@return The pointer to CPU MP Data structure.
**/
@@ -35,10 +37,18 @@ GetCpuMpData (
VOID
)
{
CPU_MP_DATA *CpuMpData;
CPU_MP_DATA *CpuMpData;
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
IA32_DESCRIPTOR Idtr;
CpuMpData = GetCpuMpDataFromGuidedHob ();
ASSERT (CpuMpData != NULL);
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
if (ApicBaseMsr.Bits.BSP == 1) {
CpuMpData = GetCpuMpDataFromGuidedHob ();
ASSERT (CpuMpData != NULL);
} else {
AsmReadIdtr (&Idtr);
CpuMpData = (CPU_MP_DATA *) (Idtr.Base + Idtr.Limit + 1);
}
return CpuMpData;
}