]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: avoid printing debug messages in AP
authorRay Ni <ray.ni@intel.com>
Fri, 12 Mar 2021 11:39:38 +0000 (19:39 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 17 Mar 2021 12:39:31 +0000 (12:39 +0000)
MpInitLib contains a function MicrocodeDetect() which is called by
all threads as an AP procedure.
Today this function contains below code:

    if (CurrentRevision != LatestRevision) {
      AcquireSpinLock(&CpuMpData->MpLock);
      DEBUG ((
        EFI_D_ERROR,
        "Updated microcode signature [0x%08x] does not match \
        loaded microcode signature [0x%08x]\n",
        CurrentRevision, LatestRevision
        ));
      ReleaseSpinLock(&CpuMpData->MpLock);
    }

When the if-check is passed, the code may call into PEI services:
1. AcquireSpinLock
   When the PcdSpinTimeout is not 0, TimerLib
   GetPerformanceCounterProperties() is called. And some of the
   TimerLib implementations would get the information cached in
   HOB. But AP procedure cannot call PEI services to retrieve the
   HOB list.

2. DEBUG
   Certain DebugLib relies on ReportStatusCode services and the
   ReportStatusCode PPI is retrieved through the PEI services.
   DebugLibSerialPort should be used.
   But when SerialPortLib is implemented to depend on PEI services,
   even using DebugLibSerialPort can still cause AP calls PEI
   services resulting hang.

It causes a lot of debugging effort on the platform side.

There are 2 options to fix the problem:
1. make sure platform DSC chooses the proper DebugLib and set the
   PcdSpinTimeout to 0. So that AcquireSpinLock and DEBUG don't call
   PEI services.
2. remove the AcquireSpinLock and DEBUG call from the procedure.

Option #2 is preferred because it's not practical to ask every
platform DSC to be written properly.

Following option #2, there are two sub-options:
2.A. Just remove the if-check.
2.B. Capture the CurrentRevision and ExpectedRevision in the memory
     for each AP and print them together from BSP.

The patch follows option 2.B.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
UefiCpuPkg/Library/MpInitLib/Microcode.c
UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.h

index 15629591e2444cbe217b5946520e73fb35afa24e..297c2abcd13aacc91ac5d872c738749d622069be 100644 (file)
@@ -315,17 +315,8 @@ Done:
         MSR_IA32_BIOS_UPDT_TRIG,\r
         (UINT64) (UINTN) MicrocodeData\r
         );\r
-    //\r
-    // Get and check new microcode signature\r
-    //\r
-    CurrentRevision = GetCurrentMicrocodeSignature ();\r
-    if (CurrentRevision != LatestRevision) {\r
-      AcquireSpinLock(&CpuMpData->MpLock);\r
-      DEBUG ((EFI_D_ERROR, "Updated microcode signature [0x%08x] does not match \\r
-                loaded microcode signature [0x%08x]\n", CurrentRevision, LatestRevision));\r
-      ReleaseSpinLock(&CpuMpData->MpLock);\r
-    }\r
   }\r
+  CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision = GetCurrentMicrocodeSignature ();\r
 }\r
 \r
 /**\r
index 5040053dad07eeab563c566056b50f3c424ad937..3d945972a025ba7bc14d959500c55e471bbfe8a2 100644 (file)
@@ -2135,6 +2135,31 @@ MpInitLibInitialize (
     }\r
   }\r
 \r
+  //\r
+  // Dump the microcode revision for each core.\r
+  //\r
+  DEBUG_CODE (\r
+    UINT32 ThreadId;\r
+    UINT32 ExpectedMicrocodeRevision;\r
+    CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;\r
+    for (Index = 0; Index < CpuMpData->CpuCount; Index++) {\r
+      GetProcessorLocationByApicId (CpuInfoInHob[Index].InitialApicId, NULL, NULL, &ThreadId);\r
+      if (ThreadId == 0) {\r
+        //\r
+        // MicrocodeDetect() loads microcode in first thread of each core, so,\r
+        // CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized only for first thread of each core.\r
+        //\r
+        ExpectedMicrocodeRevision = 0;\r
+        if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {\r
+          ExpectedMicrocodeRevision = ((CPU_MICROCODE_HEADER *)(UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision;\r
+        }\r
+        DEBUG ((\r
+          DEBUG_INFO, "CPU[%04d]: Microcode revision = %08x, expected = %08x\n",\r
+          Index, CpuMpData->CpuData[Index].MicrocodeRevision, ExpectedMicrocodeRevision\r
+          ));\r
+      }\r
+    }\r
+  );\r
   //\r
   // Initialize global data for MP support\r
   //\r
index 0bd60388b10a7a4b70851d3d5f9bb93ee7a5a6b5..66f9eb2304cb759200673591cff7042ae6fdc26f 100644 (file)
@@ -144,6 +144,7 @@ typedef struct {
   UINT32                         ProcessorSignature;\r
   UINT8                          PlatformId;\r
   UINT64                         MicrocodeEntryAddr;\r
+  UINT32                         MicrocodeRevision;\r
 } CPU_AP_DATA;\r
 \r
 //\r