public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zhou Jianfeng via groups.io" <jianfeng.zhou=intel.com@groups.io>
To: devel@edk2.groups.io
Cc: Zhou Jianfeng <jianfeng.zhou@intel.com>,
	Ray Ni <ray.ni@intel.com>, Gerd Hoffmann <kraxel@redhat.com>,
	Jiaxin Wu <jiaxin.wu@intel.com>,
	Zhiguang Liu <zhiguang.liu@intel.com>,
	Dun Tan <dun.tan@intel.com>, Rahul Kumar <rahul1.kumar@intel.com>,
	Star Zeng <star.zeng@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>
Subject: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Fix SMRAM memory leak during S3 resume
Date: Tue,  6 May 2025 08:48:54 -0400	[thread overview]
Message-ID: <20250506124854.3342637-1-jianfeng.zhou@intel.com> (raw)

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]
-=-=-=-=-=-=-=-=-=-=-=-



             reply	other threads:[~2025-05-06 12:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 12:48 Zhou Jianfeng via groups.io [this message]
  -- strict thread matches above, loose matches on Subject: below --
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
2025-05-06 12:42 Zhou Jianfeng via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250506124854.3342637-1-jianfeng.zhou@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox