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.65; helo=mga03.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 631E1223CDC1F for ; Mon, 5 Mar 2018 19:33:25 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 19:39:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,430,1515484800"; d="scan'208";a="209154733" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.44]) by fmsmga006.fm.intel.com with ESMTP; 05 Mar 2018 19:39:38 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Michael D Kinney , Liming Gao Date: Tue, 6 Mar 2018 11:39:33 +0800 Message-Id: <20180306033933.278752-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20180306033933.278752-1-ruiyu.ni@intel.com> References: <20180306033933.278752-1-ruiyu.ni@intel.com> Subject: [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest 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: Tue, 06 Mar 2018 03:33:25 -0000 CompatibleRangeTest() contains two bugs: 1. It doesn't reject the memory above 16MB 2. it cannot handle the case when the partial or whole range of requested memory is already tested. The patch fixes the two bugs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Michael D Kinney Cc: Liming Gao --- .../MemoryTest/NullMemoryTestDxe/NullMemoryTest.c | 55 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c index c66f3fd208..a9bd101501 100644 --- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c +++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c @@ -240,14 +240,51 @@ GenCompatibleRangeTest ( { EFI_STATUS Status; EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; - - Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor); - if (!EFI_ERROR (Status)) { - Status = ConvertToTestedMemory ( - Descriptor.BaseAddress, - Descriptor.Length, - Descriptor.Capabilities - ); + EFI_PHYSICAL_ADDRESS CurrentBase; + UINT64 CurrentLength; + + // + // Check if the parameter is below 16MB + // + if (StartAddress + Length > SIZE_16MB) { + return EFI_INVALID_PARAMETER; } - return Status; + CurrentBase = StartAddress; + do { + // + // Check the required memory range status; if the required memory range span + // the different GCD memory descriptor, it may be cause different action. + // + Status = gDS->GetMemorySpaceDescriptor ( + CurrentBase, + &Descriptor + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved && + (Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) == + (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED) + ) { + CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase; + if (CurrentBase + CurrentLength > StartAddress + Length) { + CurrentLength = StartAddress + Length - CurrentBase; + } + Status = ConvertToTestedMemory ( + CurrentBase, + CurrentLength, + Descriptor.Capabilities + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + CurrentBase = Descriptor.BaseAddress + Descriptor.Length; + } while (CurrentBase < StartAddress + Length); + // + // Here means the required range already be tested, so just return success. + // + return EFI_SUCCESS; } + -- 2.16.1.windows.1