* [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
* Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
2025-05-06 12:50 [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume 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
0 siblings, 1 reply; 5+ messages in thread
From: Wu, Jiaxin via groups.io @ 2025-05-07 6:32 UTC (permalink / raw)
To: Zhou, Jianfeng, devel@edk2.groups.io
Cc: Ni, Ray, Gerd Hoffmann, Liu, Zhiguang, Tan, Dun, Kumar, Rahul R,
Zeng, Star, Liming Gao
It looks good to me, Jianfeng, can you send the PR to the edk2 directly?
Thanks,
Jiaxin
> -----Original Message-----
> From: Zhou, Jianfeng <jianfeng.zhou@intel.com>
> Sent: Tuesday, May 6, 2025 8:51 PM
> To: devel@edk2.groups.io
> Cc: Zhou, Jianfeng <jianfeng.zhou@intel.com>; Ni, Ray <ray.ni@intel.com>;
> Gerd Hoffmann <kraxel@redhat.com>; Wu, Jiaxin <jiaxin.wu@intel.com>; Liu,
> Zhiguang <zhiguang.liu@intel.com>; Tan, Dun <dun.tan@intel.com>; Kumar,
> Rahul R <rahul.r.kumar@intel.com>; Zeng, Star <star.zeng@intel.com>; Liming
> Gao <gaoliming@byosoft.com.cn>
> Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak
> during S3 resume
>
> 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 (#121316): https://edk2.groups.io/g/devel/message/121316
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 [flat|nested] 5+ messages in thread
* Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
2025-05-07 6:32 ` Wu, Jiaxin via groups.io
@ 2025-05-07 6:35 ` Zhou Jianfeng via groups.io
0 siblings, 0 replies; 5+ messages in thread
From: Zhou Jianfeng via groups.io @ 2025-05-07 6:35 UTC (permalink / raw)
To: Wu, Jiaxin, devel@edk2.groups.io
Cc: Ni, Ray, Gerd Hoffmann, Liu, Zhiguang, Tan, Dun, Kumar, Rahul R,
Zeng, Star, Liming Gao
Sorry for inconvenience.
I wrongly sent this patch because of misunderstanding.
I submitted https://github.com/tianocore/edk2/pull/11024 and it has been merged.
Thanks & Regards,
Zhou Jianfeng
-----Original Message-----
From: Wu, Jiaxin <jiaxin.wu@intel.com>
Sent: Wednesday, May 7, 2025 2:32 PM
To: Zhou, Jianfeng <jianfeng.zhou@intel.com>; devel@edk2.groups.io
Cc: Ni, Ray <ray.ni@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Liu, Zhiguang <zhiguang.liu@intel.com>; Tan, Dun <dun.tan@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Zeng, Star <star.zeng@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
Subject: RE: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
It looks good to me, Jianfeng, can you send the PR to the edk2 directly?
Thanks,
Jiaxin
> -----Original Message-----
> From: Zhou, Jianfeng <jianfeng.zhou@intel.com>
> Sent: Tuesday, May 6, 2025 8:51 PM
> To: devel@edk2.groups.io
> Cc: Zhou, Jianfeng <jianfeng.zhou@intel.com>; Ni, Ray
> <ray.ni@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Wu, Jiaxin
> <jiaxin.wu@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>; Tan,
> Dun <dun.tan@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>;
> Zeng, Star <star.zeng@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>
> Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak
> during S3 resume
>
> 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 (#121317): https://edk2.groups.io/g/devel/message/121317
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 [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: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
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:50 [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume 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
-- strict thread matches above, loose matches on Subject: below --
2025-05-06 12:48 Zhou Jianfeng via groups.io
2025-05-06 12:42 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