From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 349DE2222C220 for ; Sun, 28 Jan 2018 20:47:14 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2018 20:52:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,429,1511856000"; d="scan'208";a="13824519" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.193.4]) by fmsmga008.fm.intel.com with ESMTP; 28 Jan 2018 20:52:46 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Ruiyu Ni , Star Zeng , Eric Dong Date: Mon, 29 Jan 2018 12:52:41 +0800 Message-Id: <20180129045241.20360-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [PATCH] MdeModulePkg/Core: fix guard page missing issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jan 2018 04:47:15 -0000 This issue is a regression one caused by a patch at 425d25699be83c35e12df8470b827d7fbcef3bce That fix didn't take the 0 page to free into account, which still needs to call UnsetGuardPage() even no memory needs to free. The fix is just moving the calling of UnsetGuardPage() to the place right after calling AdjustMemoryF(). Cc: Ruiyu Ni Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 7 +++---- MdeModulePkg/Core/Dxe/Mem/Pool.c | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index 92753c7269..392aeb8a02 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard ( OldPages = NumberOfPages; AdjustMemoryF (&Start, &NumberOfPages); - if (NumberOfPages == 0) { - return EFI_SUCCESS; - } - // // It's safe to unset Guard page inside memory lock because there should // be no memory allocation occurred in updating memory page attribute at @@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard ( // marking it usable (from non-present to present). // UnsetGuardForMemory (OldStart, OldPages); + if (NumberOfPages == 0) { + return EFI_SUCCESS; + } } else { AdjustMemoryA (&Start, &NumberOfPages); } diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index df9a1d28df..1ff2061f7f 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard ( NoPagesGuarded = NoPages; AdjustMemoryF (&Memory, &NoPages); + // + // It's safe to unset Guard page inside memory lock because there should + // be no memory allocation occurred in updating memory page attribute at + // this point. And unsetting Guard page before free will prevent Guard + // page just freed back to pool from being allocated right away before + // marking it usable (from non-present to present). + // + UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded); if (NoPages > 0) { - // - // It's safe to unset Guard page inside memory lock because there should - // be no memory allocation occurred in updating memory page attribute at - // this point. And unsetting Guard page before free will prevent Guard - // page just freed back to pool from being allocated right away before - // marking it usable (from non-present to present). - // - UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded); CoreFreePoolPagesI (PoolType, Memory, NoPages); } } -- 2.14.1.windows.1