From 9840b1299de78458a42d35b8d1d6cbadd1f6da72 Mon Sep 17 00:00:00 2001 From: Chen Fan Date: Mon, 17 Nov 2014 14:54:09 +0000 Subject: [PATCH] UefiCpuPkg/CpuDxe: Put APs in wait for SIPI state at ExitBootServices when gBS->ExitBootServices() is called, the APs should avoid to access the unsafed buff datas which were allocated by boot services. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen Fan Tested-by: Gabriel Somlo Reviewed-by: Jordan Justen Reviewed-by: Jeff Fan Tested-by: Laszlo Ersek git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16397 6f19259b-4bc3-4df7-8a09-765794883524 --- UefiCpuPkg/CpuDxe/CpuMp.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index f864de1f6f..b65300c773 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -20,7 +20,8 @@ UINTN gApStackSize; UINTN gPollInterval = 100; // 100 microseconds MP_SYSTEM_DATA mMpSystemData; -EFI_HANDLE mMpServiceHandle = NULL; +EFI_HANDLE mMpServiceHandle = NULL; +EFI_EVENT mExitBootServicesEvent = (EFI_EVENT)NULL; VOID *mCommonStack = 0; VOID *mTopOfApCommonStack = 0; @@ -1464,6 +1465,28 @@ InitMpSystemData ( return EFI_SUCCESS; } +/** + Callback function for ExitBootServices. + + @param Event Event whose notification function is being invoked. + @param Context The pointer to the notification function's context, + which is implementation-dependent. + +**/ +VOID +EFIAPI +ExitBootServicesCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Avoid APs access invalid buff datas which allocated by BootServices, + // so we send INIT IPI to APs to let them wait for SIPI state. + // + SendInitIpiAllExcludingSelf (); +} + /** Initialize Multi-processor support. @@ -1531,4 +1554,13 @@ InitializeMpSupport ( (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) * gApStackSize)); } + + Status = gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_CALLBACK, + ExitBootServicesCallback, + NULL, + &mExitBootServicesEvent + ); + ASSERT_EFI_ERROR (Status); } -- 2.39.2