From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D6D0181F17 for ; Wed, 16 Nov 2016 21:34:41 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP; 16 Nov 2016 21:34:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,504,1473145200"; d="scan'208";a="32360405" Received: from mdkinney-mobl.amr.corp.intel.com ([10.232.100.21]) by fmsmga006.fm.intel.com with ESMTP; 16 Nov 2016 21:34:46 -0800 From: Michael Kinney To: edk2-devel@lists.01.org Cc: Liming Gao , Laszlo Ersek , Andrew Fish , Jeff Fan Date: Wed, 16 Nov 2016 21:34:44 -0800 Message-Id: <1479360884-16708-1-git-send-email-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.6.3.windows.1 Subject: [Patch] UefiCpuPkg/PiSmmCpuDxeSmm: Add volatile to mNumberToFinish X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Nov 2016 05:34:41 -0000 Add volatile qualifier to mNumberToFinish to prevent compiler optimization. Also update TransferApToSafeState() to pass in UINTN values and treat the mNumberToFinish as an address value that is passed to the assembly code. Cc: Liming Gao Cc: Laszlo Ersek Cc: Andrew Fish Cc: Jeff Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 10 +++++----- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c | 18 +++++++++--------- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 12 ++++++------ UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 18 +++++++++--------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index 3fb6864..4531298 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -55,7 +55,7 @@ AsmGetAddressMap ( #define LEGACY_REGION_BASE (0xA0000 - LEGACY_REGION_SIZE) ACPI_CPU_DATA mAcpiCpuData; -UINT32 mNumberToFinish; +volatile UINT32 mNumberToFinish; MP_CPU_EXCHANGE_INFO *mExchangeInfo; BOOLEAN mRestoreSmmConfigurationInS3 = FALSE; VOID *mGdtForAp = NULL; @@ -385,7 +385,7 @@ MPRendezvousProcedure ( CPU_REGISTER_TABLE *RegisterTableList; UINT32 InitApicId; UINTN Index; - UINT32 TopOfStack; + UINTN TopOfStack; UINT8 Stack[128]; ProgramVirtualWireMode (); @@ -403,10 +403,10 @@ MPRendezvousProcedure ( // // Place AP into the safe code, count down the number with lock mechanism in the safe code. // - TopOfStack = (UINT32) (UINTN) Stack + sizeof (Stack); - TopOfStack &= ~(UINT32) (CPU_STACK_ALIGNMENT - 1); + TopOfStack = (UINTN) Stack + sizeof (Stack); + TopOfStack &= ~(CPU_STACK_ALIGNMENT - 1); CopyMem ((VOID *) (UINTN) mApHltLoopCode, mApHltLoopCodeTemplate, sizeof (mApHltLoopCodeTemplate)); - TransferApToSafeState ((UINT32) (UINTN) mApHltLoopCode, TopOfStack, &mNumberToFinish); + TransferApToSafeState ((UINTN)mApHltLoopCode, TopOfStack, (UINTN)(VOID *)&mNumberToFinish); } /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c index 9760373..d57eb33 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c @@ -98,23 +98,23 @@ InitGdt ( /** Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch. - @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. - @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. - @param[in] NumberToFinish Semaphore of APs finish count. + @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. + @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. + @param[in] NumberToFinishAddress Address of Semaphore of APs finish count. **/ VOID TransferApToSafeState ( - IN UINT32 ApHltLoopCode, - IN UINT32 TopOfStack, - IN UINT32 *NumberToFinish + IN UINTN ApHltLoopCode, + IN UINTN TopOfStack, + IN UINTN NumberToFinishAddress ) { SwitchStack ( - (SWITCH_STACK_ENTRY_POINT) (UINTN) ApHltLoopCode, - NumberToFinish, + (SWITCH_STACK_ENTRY_POINT)ApHltLoopCode, + (VOID *)NumberToFinishAddress, NULL, - (VOID *) (UINTN) TopOfStack + (VOID *)TopOfStack ); // // It should never reach here diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 88d9c85..38dd9fa 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -828,16 +828,16 @@ GetAcpiS3EnableFlag ( /** Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch. - @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. - @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. - @param[in] NumberToFinish Semaphore of APs finish count. + @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. + @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. + @param[in] NumberToFinishAddress Address of Semaphore of APs finish count. **/ VOID TransferApToSafeState ( - IN UINT32 ApHltLoopCode, - IN UINT32 TopOfStack, - IN UINT32 *NumberToFinish + IN UINTN ApHltLoopCode, + IN UINTN TopOfStack, + IN UINTN NumberToFinishAddress ); #endif diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c index 6844c3f..d45fed2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c @@ -103,24 +103,24 @@ GetProtectedModeCS ( /** Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch. - @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. - @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. - @param[in] NumberToFinish Semaphore of APs finish count. + @param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function. + @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode. + @param[in] NumberToFinishAddress Address of Semaphore of APs finish count. **/ VOID TransferApToSafeState ( - IN UINT32 ApHltLoopCode, - IN UINT32 TopOfStack, - IN UINT32 *NumberToFinish + IN UINTN ApHltLoopCode, + IN UINTN TopOfStack, + IN UINTN NumberToFinishAddress ) { AsmDisablePaging64 ( GetProtectedModeCS (), - (UINT32) (UINTN) ApHltLoopCode, - (UINT32) (UINTN) NumberToFinish, + (UINT32)ApHltLoopCode, + (UINT32)NumberToFinishAddress, 0, - TopOfStack + (UINT32)TopOfStack ); // // It should never reach here -- 2.6.3.windows.1