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.20; helo=mga02.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 66B6B22135D47 for ; Tue, 6 Mar 2018 20:34:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2018 20:40:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,434,1515484800"; d="scan'208";a="180543201" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.93]) by orsmga004.jf.intel.com with ESMTP; 06 Mar 2018 20:40:44 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Star Zeng , Eric Dong , Jiewen Yao Date: Wed, 7 Mar 2018 12:40:41 +0800 Message-Id: <20180307044041.18392-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [PATCH] MdeModulePkg/Core: fix too many available pages between BS_Data 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: Wed, 07 Mar 2018 04:34:31 -0000 The root cause is an unnecessary check to Size parameter in function AdjustMemoryS(). It will cause one standalone free page (happen to have Guard page around) in the free memory list cannot be allocated, even if the requested memory size is less than a page. // // At least one more page needed for Guard page. // if (Size < (SizeRequested + EFI_PAGES_TO_SIZE (1))) { return 0; } The following code in the same function actually covers above check implicitly. So the fix is simply removing above check. Cc: Star Zeng Cc: Eric Dong Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 9 +-------- MdeModulePkg/Core/PiSmmCore/HeapGuard.c | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index d7906e08c5..19245049c2 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -1,7 +1,7 @@ /** @file UEFI Heap Guard functions. -Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017-2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -905,13 +905,6 @@ AdjustMemoryS ( Target = Start + Size - SizeRequested; - // - // At least one more page needed for Guard page. - // - if (Size < (SizeRequested + EFI_PAGES_TO_SIZE (1))) { - return 0; - } - if (!IsGuardPage (Start + Size)) { // No Guard at tail to share. One more page is needed. Target -= EFI_PAGES_TO_SIZE (1); diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c index c5ffb26342..aa9c25d102 100644 --- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c +++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c @@ -1,7 +1,7 @@ /** @file UEFI Heap Guard functions. -Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017-2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -888,13 +888,6 @@ AdjustMemoryS ( Target = Start + Size - SizeRequested; - // - // At least one more page needed for Guard page. - // - if (Size < (SizeRequested + EFI_PAGES_TO_SIZE (1))) { - return 0; - } - if (!IsGuardPage (Start + Size)) { // No Guard at tail to share. One more page is needed. Target -= EFI_PAGES_TO_SIZE (1); -- 2.14.1.windows.1