From a8d75a1802df015a79d929f45972de98b9a0a2d9 Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Mon, 26 Dec 2016 16:52:48 +0800 Subject: [PATCH 1/1] UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker() During switching BSP phase, we need to disable CPU interruput to prevent stack crashed by Timer interrupt handle. But when we enabled source debugging feature, debug timer interrupt handler (existing on both PEI and DXE) also could crash the stack used during switching BSP. So,we need to move save/restore interrupt to SwitchBSPWorker(). Cc: Feng Tian Cc: Kinney Michael D Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Feng Tian --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 19 ------------------- UefiCpuPkg/Library/MpInitLib/MpLib.c | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c index 1204abd577..733a9fb7be 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -646,29 +646,10 @@ MpInitLibSwitchBSP ( ) { EFI_STATUS Status; - BOOLEAN OldInterruptState; - // - // Before send both BSP and AP to a procedure to exchange their roles, - // interrupt must be disabled. This is because during the exchange role - // process, 2 CPU may use 1 stack. If interrupt happens, the stack will - // be corrupted, since interrupt return address will be pushed to stack - // by hardware. - // - OldInterruptState = SaveAndDisableInterrupts (); - - // - // Mask LINT0 & LINT1 for the old BSP - // - DisableLvtInterrupts (); Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP); - // - // Restore interrupt state. - // - SetInterruptState (OldInterruptState); - return Status; } diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index e5842ef505..9dae827306 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1511,6 +1511,21 @@ SwitchBSPWorker ( UINTN CallerNumber; CPU_STATE State; MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr; + BOOLEAN OldInterruptState; + + // + // Before send both BSP and AP to a procedure to exchange their roles, + // interrupt must be disabled. This is because during the exchange role + // process, 2 CPU may use 1 stack. If interrupt happens, the stack will + // be corrupted, since interrupt return address will be pushed to stack + // by hardware. + // + OldInterruptState = SaveAndDisableInterrupts (); + + // + // Mask LINT0 & LINT1 for the old BSP + // + DisableLvtInterrupts (); CpuMpData = GetCpuMpData (); @@ -1593,6 +1608,12 @@ SwitchBSPWorker ( // CpuMpData->BspNumber = (UINT32) ProcessorNumber; + // + // Restore interrupt state. + // + SetInterruptState (OldInterruptState); + + return EFI_SUCCESS; } -- 2.39.2