public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
@ 2025-05-06 12:42 Zhou Jianfeng via groups.io
  0 siblings, 0 replies; 5+ messages in thread
From: Zhou Jianfeng via groups.io @ 2025-05-06 12:42 UTC (permalink / raw)
  To: devel
  Cc: Zhou Jianfeng, Ray Ni, Gerd Hoffmann, Jiaxin Wu, Zhiguang Liu,
	Dun Tan, Rahul Kumar, Star Zeng, Liming Gao

SyncContext of SMM_DISPATCHER_MP_SYNC_DATA was dynamically allocated from
SMRAM. The memory was not freed before reallocation in S3 resume path.
This could lead to:
1. Memory leak in SMRAM.
2. Potential S3 resume failure after repeated S3 tests due to SMRAM
exhaustion.

This change releases the SyncContext memory before reallocating it

Cc: Ray Ni <ray.ni@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Zhou Jianfeng <jianfeng.zhou@intel.com>
Signed-off-by: Zhou Jianfeng <jianfeng.zhou@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index b19906b610..7bc68087ad 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1868,6 +1868,10 @@ InitializeMpSyncData (
   UINTN  CpuIndex;

   if (mSmmMpSyncData != NULL) {
+    if (mSmmMpSyncData->SyncContext != NULL) {
+      SmmCpuSyncContextDeinit (mSmmMpSyncData->SyncContext);
+    }
+
     //
     // mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC_DATA, one
     // CpuData array of SMM_CPU_DATA_BLOCK and one CandidateBsp array of BOOLEAN.
@@ -1968,6 +1972,7 @@ InitializeMpServiceData (
   mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA *)AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));
   ASSERT (mSmmMpSyncData != NULL);

+  ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);
   RelaxedMode = FALSE;
   GetSmmCpuSyncConfigData (&RelaxedMode, NULL, NULL);
   mCpuSmmSyncMode = RelaxedMode ? MmCpuSyncModeRelaxedAp : MmCpuSyncModeTradition;
--
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121308): https://edk2.groups.io/g/devel/message/121308
Mute This Topic: https://groups.io/mt/112647890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
@ 2025-05-06 12:48 Zhou Jianfeng via groups.io
  0 siblings, 0 replies; 5+ messages in thread
From: Zhou Jianfeng via groups.io @ 2025-05-06 12:48 UTC (permalink / raw)
  To: devel
  Cc: Zhou Jianfeng, Ray Ni, Gerd Hoffmann, Jiaxin Wu, Zhiguang Liu,
	Dun Tan, Rahul Kumar, Star Zeng, Liming Gao

SyncContext of SMM_DISPATCHER_MP_SYNC_DATA was dynamically allocated from
SMRAM. The memory was not freed before reallocation in S3 resume path.
This could lead to:
1. Memory leak in SMRAM.
2. Potential S3 resume failure after repeated S3 tests due to SMRAM
exhaustion.

This change releases the SyncContext memory before reallocating it

Cc: Ray Ni <ray.ni@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Zhou Jianfeng <jianfeng.zhou@intel.com>

Signed-off-by: Zhou Jianfeng <jianfeng.zhou@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index b19906b610..7bc68087ad 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1868,6 +1868,10 @@ InitializeMpSyncData (
   UINTN  CpuIndex;
 
   if (mSmmMpSyncData != NULL) {
+    if (mSmmMpSyncData->SyncContext != NULL) {
+      SmmCpuSyncContextDeinit (mSmmMpSyncData->SyncContext);
+    }
+
     //
     // mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC_DATA, one
     // CpuData array of SMM_CPU_DATA_BLOCK and one CandidateBsp array of BOOLEAN.
@@ -1968,6 +1972,7 @@ InitializeMpServiceData (
   mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA *)AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));
   ASSERT (mSmmMpSyncData != NULL);
 
+  ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);
   RelaxedMode = FALSE;
   GetSmmCpuSyncConfigData (&RelaxedMode, NULL, NULL);
   mCpuSmmSyncMode = RelaxedMode ? MmCpuSyncModeRelaxedAp : MmCpuSyncModeTradition;
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121309): https://edk2.groups.io/g/devel/message/121309
Mute This Topic: https://groups.io/mt/112647890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
@ 2025-05-06 12:50 Zhou Jianfeng via groups.io
  2025-05-07  6:32 ` Wu, Jiaxin via groups.io
  0 siblings, 1 reply; 5+ messages in thread
From: Zhou Jianfeng via groups.io @ 2025-05-06 12:50 UTC (permalink / raw)
  To: devel
  Cc: Zhou Jianfeng, Ray Ni, Gerd Hoffmann, Jiaxin Wu, Zhiguang Liu,
	Dun Tan, Rahul Kumar, Star Zeng, Liming Gao

SyncContext of SMM_DISPATCHER_MP_SYNC_DATA was dynamically allocated from
SMRAM. The memory was not freed before reallocation in S3 resume path.
This could lead to:
1. Memory leak in SMRAM.
2. Potential S3 resume failure after repeated S3 tests due to SMRAM
exhaustion.

This change releases the SyncContext memory before reallocating it

Cc: Ray Ni <ray.ni@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Zhou Jianfeng <jianfeng.zhou@intel.com>

Signed-off-by: Zhou Jianfeng <jianfeng.zhou@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index b19906b610..7bc68087ad 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1868,6 +1868,10 @@ InitializeMpSyncData (
   UINTN  CpuIndex;

   if (mSmmMpSyncData != NULL) {
+    if (mSmmMpSyncData->SyncContext != NULL) {
+      SmmCpuSyncContextDeinit (mSmmMpSyncData->SyncContext);
+    }
+
     //
     // mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC_DATA, one
     // CpuData array of SMM_CPU_DATA_BLOCK and one CandidateBsp array of BOOLEAN.
@@ -1968,6 +1972,7 @@ InitializeMpServiceData (
   mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA *)AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));
   ASSERT (mSmmMpSyncData != NULL);

+  ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);
   RelaxedMode = FALSE;
   GetSmmCpuSyncConfigData (&RelaxedMode, NULL, NULL);
   mCpuSmmSyncMode = RelaxedMode ? MmCpuSyncModeRelaxedAp : MmCpuSyncModeTradition;
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121310): https://edk2.groups.io/g/devel/message/121310
Mute This Topic: https://groups.io/mt/112647890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-07  6:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 12:42 [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume Zhou Jianfeng via groups.io
  -- strict thread matches above, loose matches on Subject: below --
2025-05-06 12:48 Zhou Jianfeng via groups.io
2025-05-06 12:50 Zhou Jianfeng via groups.io
2025-05-07  6:32 ` Wu, Jiaxin via groups.io
2025-05-07  6:35   ` Zhou Jianfeng via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox