public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix bug in CompatibleRangeTest
@ 2018-03-06  3:39 Ruiyu Ni
  2018-03-06  3:39 ` [PATCH 1/2] MdeModulePkg/NullMemoryTest: Change prototype of ConvertToTestedMemory Ruiyu Ni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-03-06  3:39 UTC (permalink / raw)
  To: edk2-devel


Ruiyu Ni (2):
  MdeModulePkg/NullMemoryTest: Change prototype of ConvertToTestedMemory
  MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest

 .../MemoryTest/NullMemoryTestDxe/NullMemoryTest.c  | 82 +++++++++++++++++-----
 1 file changed, 65 insertions(+), 17 deletions(-)

-- 
2.16.1.windows.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] MdeModulePkg/NullMemoryTest: Change prototype of ConvertToTestedMemory
  2018-03-06  3:39 [PATCH 0/2] Fix bug in CompatibleRangeTest Ruiyu Ni
@ 2018-03-06  3:39 ` Ruiyu Ni
  2018-03-06  3:39 ` [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest Ruiyu Ni
  2018-03-07  4:09 ` [PATCH 0/2] " Kinney, Michael D
  2 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-03-06  3:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao

The patch should not impact the functionality.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 .../MemoryTest/NullMemoryTestDxe/NullMemoryTest.c  | 37 ++++++++++++++--------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
index 11af8ea77f..c66f3fd208 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
@@ -59,37 +59,40 @@ GenericMemoryTestEntryPoint (
 }
 
 /**
-  Convert the memory descriptor to tested.
+  Convert the memory range to tested.
 
-  @param Descriptor  Pointer to EFI_GCD_MEMORY_SPACE_DESCRIPTOR
+  @param BaseAddress  Base address of the memory range.
+  @param Length       Length of the memory range.
+  @param Capabilities Capabilities of the memory range.
 
-  @retval EFI_SUCCESS The memory descriptor is converted to tested.
+  @retval EFI_SUCCESS The memory range is converted to tested.
   @retval others      Error happens.
 **/
 EFI_STATUS
 ConvertToTestedMemory (
-  IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor
+  IN UINT64           BaseAddress,
+  IN UINT64           Length,
+  IN UINT64           Capabilities
   )
 {
   EFI_STATUS Status;
   Status = gDS->RemoveMemorySpace (
-                  Descriptor->BaseAddress,
-                  Descriptor->Length
+                  BaseAddress,
+                  Length
                   );
   if (!EFI_ERROR (Status)) {
     Status = gDS->AddMemorySpace (
-                    ((Descriptor->Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
+                    ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
                     EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
-                    Descriptor->BaseAddress,
-                    Descriptor->Length,
-                    Descriptor->Capabilities &~
+                    BaseAddress,
+                    Length,
+                    Capabilities &~
                     (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
                     );
   }
   return Status;
 }
 
-
 /**
   Initialize the generic memory test.
 
@@ -129,7 +132,11 @@ InitializeMemoryTest (
       //
       // For those reserved memory that have not been tested, simply promote to system memory.
       //
-      Status = ConvertToTestedMemory (&MemorySpaceMap[Index]);
+      Status = ConvertToTestedMemory (
+                 MemorySpaceMap[Index].BaseAddress,
+                 MemorySpaceMap[Index].Length,
+                 MemorySpaceMap[Index].Capabilities
+                 );
       ASSERT_EFI_ERROR (Status);
       mTestedSystemMemory += MemorySpaceMap[Index].Length;
       mTotalSystemMemory += MemorySpaceMap[Index].Length;
@@ -236,7 +243,11 @@ GenCompatibleRangeTest (
 
   Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);
   if (!EFI_ERROR (Status)) {
-    Status = ConvertToTestedMemory (&Descriptor);
+    Status = ConvertToTestedMemory (
+               Descriptor.BaseAddress,
+               Descriptor.Length,
+               Descriptor.Capabilities
+               );
   }
   return Status;
 }
-- 
2.16.1.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest
  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
  2018-03-07  4:09 ` [PATCH 0/2] " Kinney, Michael D
  2 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-03-06  3:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Liming Gao

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fix bug in CompatibleRangeTest
  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 ` [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest Ruiyu Ni
@ 2018-03-07  4:09 ` Kinney, Michael D
  2018-03-07  4:25   ` Gao, Liming
  2 siblings, 1 reply; 5+ messages in thread
From: Kinney, Michael D @ 2018-03-07  4:09 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org, Kinney, Michael D

Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-
> bounces@lists.01.org] On Behalf Of Ruiyu Ni
> Sent: Monday, March 5, 2018 7:40 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/2] Fix bug in
> CompatibleRangeTest
> 
> 
> Ruiyu Ni (2):
>   MdeModulePkg/NullMemoryTest: Change prototype of
> ConvertToTestedMemory
>   MdeModulePkg/NullMemoryTest: Fix bug in
> CompatibleRangeTest
> 
>  .../MemoryTest/NullMemoryTestDxe/NullMemoryTest.c  | 82
> +++++++++++++++++-----
>  1 file changed, 65 insertions(+), 17 deletions(-)
> 
> --
> 2.16.1.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fix bug in CompatibleRangeTest
  2018-03-07  4:09 ` [PATCH 0/2] " Kinney, Michael D
@ 2018-03-07  4:25   ` Gao, Liming
  0 siblings, 0 replies; 5+ messages in thread
From: Gao, Liming @ 2018-03-07  4:25 UTC (permalink / raw)
  To: Kinney, Michael D, Ni, Ruiyu, edk2-devel@lists.01.org,
	Kinney, Michael D

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Kinney, Michael D
>Sent: Wednesday, March 07, 2018 12:09 PM
>To: Ni, Ruiyu <ruiyu.ni@intel.com>; edk2-devel@lists.01.org; Kinney, Michael
>D <michael.d.kinney@intel.com>
>Subject: Re: [edk2] [PATCH 0/2] Fix bug in CompatibleRangeTest
>
>Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
>
>> -----Original Message-----
>> From: edk2-devel [mailto:edk2-devel-
>> bounces@lists.01.org] On Behalf Of Ruiyu Ni
>> Sent: Monday, March 5, 2018 7:40 PM
>> To: edk2-devel@lists.01.org
>> Subject: [edk2] [PATCH 0/2] Fix bug in
>> CompatibleRangeTest
>>
>>
>> Ruiyu Ni (2):
>>   MdeModulePkg/NullMemoryTest: Change prototype of
>> ConvertToTestedMemory
>>   MdeModulePkg/NullMemoryTest: Fix bug in
>> CompatibleRangeTest
>>
>>  .../MemoryTest/NullMemoryTestDxe/NullMemoryTest.c  | 82
>> +++++++++++++++++-----
>>  1 file changed, 65 insertions(+), 17 deletions(-)
>>
>> --
>> 2.16.1.windows.1
>>
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-07  4:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest Ruiyu Ni
2018-03-07  4:09 ` [PATCH 0/2] " Kinney, Michael D
2018-03-07  4:25   ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox