audk/UefiCpuPkg/Library
Hao A Wu 18fcb37598 UefiCpuPkg/MpInitLib: Fix possible uninitialized 'InitFlag' field
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2474

Previous commit d786a17232:
UefiCpuPkg/MpInitLib: Reduce the size when loading microcode patches

Removed the below assignments for the 'InitFlag' field of CPU_MP_DATA
structure in function MpInitLibInitialize() when APs are waken up to do
some initialize sync:

CpuMpData->InitFlag  = ApInitReconfig;
...
CpuMpData->InitFlag = ApInitDone;

The above commit mistakenly assumed the 'InitFlag' field will have a value
of 'ApInitDone' when the APs have been successfully waken up before. And
since there is no explicit comparision for the 'InitFlag' field with the
'ApInitReconfig' value. The commit removed those assignments.

However, under some cases (e.g. when variable OldCpuMpData is not NULL,
which means function CollectProcessorCount() will not be called), removing
the above assignments will left the 'InitFlag' field being uninitialized
with a value of 0, which is a invalid value for the type of 'InitFlag'
(AP_INIT_STATE).

It may potentially cause the WakeUpAP() function to run some unnecessary
codes when the APs have been successfully waken up before:

  if (CpuMpData->WakeUpByInitSipiSipi ||
      CpuMpData->InitFlag   != ApInitDone) {
    ResetVectorRequired = TRUE;
    AllocateResetVector (CpuMpData);
    FillExchangeInfoData (CpuMpData);
    SaveLocalApicTimerSetting (CpuMpData);
  }

This commit will address the above-mentioned issue.

Test done:
* OS boot on a real platform with multi processors

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2020-01-19 04:10:43 +00:00
..
BaseUefiCpuLib UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00
BaseXApicLib UefiCpuPkg: Update code to include register definitions from MdePkg 2019-08-09 08:52:09 +08:00
BaseXApicX2ApicLib UefiCpuPkg: Update code to include register definitions from MdePkg 2019-08-09 08:52:09 +08:00
CpuCommonFeaturesLib UefiCpuPkg/CpuCommonFeaturesLib: SMXE bit of CR4 should set 2020-01-10 03:41:55 +00:00
CpuExceptionHandlerLib UefiCpuPkg/CpuExceptionHandlerLib: Fix split lock 2019-09-20 14:37:42 +08:00
CpuTimerLib UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf 2019-08-21 21:36:56 +08:00
MpInitLib UefiCpuPkg/MpInitLib: Fix possible uninitialized 'InitFlag' field 2020-01-19 04:10:43 +00:00
MpInitLibUp UefiCpuPkg/MpInitLibUp: Add MpInitLibStartupAllCPUs API. 2019-07-29 09:25:20 +08:00
MtrrLib UefiCpuPkg: Update code to include register definitions from MdePkg 2019-08-09 08:52:09 +08:00
PlatformSecLibNull UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00
RegisterCpuFeaturesLib UefiCpuPkg/RegisterCpuFeaturesLib: Supports test then write new value logic. 2019-08-21 02:44:49 +08:00
SecPeiDxeTimerLibUefiCpu UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00
SmmCpuFeaturesLib UefiCpuPkg: Update code to include register definitions from MdePkg 2019-08-09 08:52:09 +08:00
SmmCpuPlatformHookLibNull UefiCpuPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:28 -07:00