Skip to content

Commit 030ba30

Browse files
niruiyumergify[bot]
authored andcommitted
UefiCpuPkg/MpInitLib: avoid printing debug messages in AP
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 <[email protected]> Reviewed-by: Eric Dong <[email protected]> Acked-by: Laszlo Ersek <[email protected]> Cc: Rahul Kumar <[email protected]>
1 parent e4ff377 commit 030ba30

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

UefiCpuPkg/Library/MpInitLib/Microcode.c

+1-10
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,8 @@ MicrocodeDetect (
315315
MSR_IA32_BIOS_UPDT_TRIG,
316316
(UINT64) (UINTN) MicrocodeData
317317
);
318-
//
319-
// Get and check new microcode signature
320-
//
321-
CurrentRevision = GetCurrentMicrocodeSignature ();
322-
if (CurrentRevision != LatestRevision) {
323-
AcquireSpinLock(&CpuMpData->MpLock);
324-
DEBUG ((EFI_D_ERROR, "Updated microcode signature [0x%08x] does not match \
325-
loaded microcode signature [0x%08x]\n", CurrentRevision, LatestRevision));
326-
ReleaseSpinLock(&CpuMpData->MpLock);
327-
}
328318
}
319+
CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision = GetCurrentMicrocodeSignature ();
329320
}
330321

331322
/**

UefiCpuPkg/Library/MpInitLib/MpLib.c

+25
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,31 @@ MpInitLibInitialize (
21352135
}
21362136
}
21372137

2138+
//
2139+
// Dump the microcode revision for each core.
2140+
//
2141+
DEBUG_CODE (
2142+
UINT32 ThreadId;
2143+
UINT32 ExpectedMicrocodeRevision;
2144+
CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
2145+
for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
2146+
GetProcessorLocationByApicId (CpuInfoInHob[Index].InitialApicId, NULL, NULL, &ThreadId);
2147+
if (ThreadId == 0) {
2148+
//
2149+
// MicrocodeDetect() loads microcode in first thread of each core, so,
2150+
// CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized only for first thread of each core.
2151+
//
2152+
ExpectedMicrocodeRevision = 0;
2153+
if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {
2154+
ExpectedMicrocodeRevision = ((CPU_MICROCODE_HEADER *)(UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision;
2155+
}
2156+
DEBUG ((
2157+
DEBUG_INFO, "CPU[%04d]: Microcode revision = %08x, expected = %08x\n",
2158+
Index, CpuMpData->CpuData[Index].MicrocodeRevision, ExpectedMicrocodeRevision
2159+
));
2160+
}
2161+
}
2162+
);
21382163
//
21392164
// Initialize global data for MP support
21402165
//

UefiCpuPkg/Library/MpInitLib/MpLib.h

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef struct {
144144
UINT32 ProcessorSignature;
145145
UINT8 PlatformId;
146146
UINT64 MicrocodeEntryAddr;
147+
UINT32 MicrocodeRevision;
147148
} CPU_AP_DATA;
148149

149150
//

0 commit comments

Comments
 (0)