From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <liming.gao@intel.com>
Subject: [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest
Date: Tue, 6 Mar 2018 11:39:33 +0800 [thread overview]
Message-ID: <20180306033933.278752-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20180306033933.278752-1-ruiyu.ni@intel.com>
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 <ruiyu.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
.../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
next prev parent reply other threads:[~2018-03-06 3:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 3:39 [PATCH 0/2] Fix bug in CompatibleRangeTest Ruiyu Ni
2018-03-06 3:39 ` [PATCH 1/2] MdeModulePkg/NullMemoryTest: Change prototype of ConvertToTestedMemory Ruiyu Ni
2018-03-06 3:39 ` Ruiyu Ni [this message]
2018-03-07 4:09 ` [PATCH 0/2] Fix bug in CompatibleRangeTest Kinney, Michael D
2018-03-07 4:25 ` Gao, Liming
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=20180306033933.278752-3-ruiyu.ni@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