There is one dead lock issue between BSP and AP. AP has one logic to enter into
Sleep state (hlt) if it found its state is Idle in one loop.
In StartupThisAp() function, BSP will get current AP state (Sleep or Idle) to
know how to wakeup AP. If AP is in Idle state, BSP will write one semaphore to
wakeup AP. If AP is in Sleep state, BSP will send INIT-SIPI-SIPI to wakeup AP.
The dead lock may happen if BSP found AP is in Idle state firstly but AP changed
its state to Sleep state later. BSP cannot wakeup AP by writing semaphore.
This fix is to release lock till BSP finished setting the semaphore.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>
Cc: Michael Kinney <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Chen Fan <[email protected]>
---
 UefiCpuPkg/CpuDxe/CpuMp.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 04c2f1f..3de2aa5 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -940,15 +940,18 @@ StartupThisAP (
     return EFI_INVALID_PARAMETER;
   }
 
-  CpuState = GetApState (CpuData);
+  GetMpSpinLock (CpuData);
+  CpuState = CpuData->State;
   if (CpuState != CpuStateIdle &&
       CpuState != CpuStateSleeping) {
+    ReleaseMpSpinLock (CpuData);
     return EFI_NOT_READY;
   }
+  CpuData->State     = CpuStateReady;
+  CpuData->Parameter = ProcedureArgument;
+  CpuData->Procedure = Procedure;
+  ReleaseMpSpinLock (CpuData);
 
-  SetApState (CpuData, CpuStateReady);
-
-  SetApProcedure (CpuData, Procedure, ProcedureArgument);
   //
   // If this AP previous state is Sleeping, we should
   // wake up this AP by sent a SIPI. and avoid
-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to