public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Kubacki" <mikuback@linux.microsoft.com>
To: devel@edk2.groups.io
Cc: Chasel Chiu <chasel.chiu@intel.com>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Eric Dong <eric.dong@intel.com>
Subject: [edk2-platforms][PATCH v1 4/5] MinPlatformPkg/TestPointCheckLib: Improve adjacent region checking
Date: Thu,  5 Aug 2021 10:57:05 -0400	[thread overview]
Message-ID: <20210805145706.2470-5-mikuback@linux.microsoft.com> (raw)
In-Reply-To: <20210805145706.2470-1-mikuback@linux.microsoft.com>

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3521

The current logic depends on a particular order in which the
descriptors for three or more regions are placed in the array to
perform proper adjacency checking. When three or more regions are
all adjacent, but neighboring descriptors are not adjacent, the
logic can improperly report a failure. Adjust the logic so that
all descriptors are checked for adjacency.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---
 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmmInfo.c | 56 ++++++++++----------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmmInfo.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmmInfo.c
index c493750a27e6..f15f76eab574 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmmInfo.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmmInfo.c
@@ -59,34 +59,36 @@ CheckSmramDescriptor (
   )
 {
   UINTN   Index;
-  UINT64  Base;
+  UINTN   Index2;
   UINT64  Length;
+  BOOLEAN AdjacentRegion;
 
-  Base = 0;
   Length = 0;
   for (Index = 0; Index < NumberOfSmmReservedRegions; Index++) {
-    if (Base == 0) {
-      Base   = Descriptor[Index].PhysicalStart;
-      Length = Descriptor[Index].PhysicalSize;
+    AdjacentRegion = FALSE;
+    for (Index2 = 0; Index2 < NumberOfSmmReservedRegions; Index2++) {
+      if ((NumberOfSmmReservedRegions == 1)
+          || (Descriptor[Index].PhysicalStart + Descriptor[Index].PhysicalSize == Descriptor[Index2].PhysicalStart)
+          || (Descriptor[Index2].PhysicalStart + Descriptor[Index2].PhysicalSize == Descriptor[Index].PhysicalStart)) {
+        AdjacentRegion = TRUE;
+        break;
+      }
+    }
+
+    if (AdjacentRegion == TRUE) {
+      Length += Descriptor[Index].PhysicalSize;
     } else {
-      if (Base + Length == Descriptor[Index].PhysicalStart) {
-        Length = Length + Descriptor[Index].PhysicalSize;
-      } else if (Descriptor[Index].PhysicalStart + Descriptor[Index].PhysicalSize == Base) {
-        Base = Descriptor[Index].PhysicalStart;
-        Length = Length + Descriptor[Index].PhysicalSize;
-      } else {
-        DEBUG ((DEBUG_ERROR, "Smram is not adjacent\n"));
-        TestPointLibAppendErrorString (
-          PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV,
-          NULL,
-          TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_CODE \
-            TEST_POINT_DXE_SMM_READY_TO_LOCK 
-            TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_STRING
-          );
-        return EFI_INVALID_PARAMETER;
-      }
+      DEBUG ((DEBUG_ERROR, "Smram is not adjacent\n"));
+      TestPointLibAppendErrorString (
+        PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV,
+        NULL,
+        TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_CODE \
+          TEST_POINT_DXE_SMM_READY_TO_LOCK
+          TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_STRING
+        );
+      return EFI_INVALID_PARAMETER;
     }
-  }        
+  }
 
   if (Length != GetPowerOfTwo64 (Length)) {
     DEBUG ((DEBUG_ERROR, "Smram is not aligned\n"));
@@ -94,7 +96,7 @@ CheckSmramDescriptor (
       PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV,
       NULL,
       TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_CODE \
-        TEST_POINT_DXE_SMM_READY_TO_LOCK 
+        TEST_POINT_DXE_SMM_READY_TO_LOCK
         TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_STRING
       );
     return EFI_INVALID_PARAMETER;
@@ -111,14 +113,14 @@ TestPointCheckSmmInfo (
   EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;
   UINTN                    Size;
   EFI_SMRAM_DESCRIPTOR     *SmramRanges;
-  
+
   DEBUG ((DEBUG_INFO, "==== TestPointCheckSmmInfo - Enter\n"));
-  
+
   Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);
   if (EFI_ERROR (Status)) {
     goto Done ;
   }
-  
+
   Size = 0;
   Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);
   ASSERT (Status == EFI_BUFFER_TOO_SMALL);
@@ -128,7 +130,7 @@ TestPointCheckSmmInfo (
 
   Status = SmmAccess->GetCapabilities (SmmAccess, &Size, SmramRanges);
   ASSERT_EFI_ERROR (Status);
-  
+
   DEBUG ((DEBUG_INFO, "SMRAM Info\n"));
   DumpSmramDescriptor (Size / sizeof (EFI_SMRAM_DESCRIPTOR), SmramRanges);
 
-- 
2.28.0.windows.1


  parent reply	other threads:[~2021-08-05 14:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05 14:57 [edk2-platforms][PATCH v1 0/5] MinPlatformPkg: TestPointCheckLib bug fixes and improvements Michael Kubacki
2021-08-05 14:57 ` [edk2-platforms][PATCH v1 1/5] MinPlatformPkg/TestPointCheckLib: Fix MessageLength cast issue Michael Kubacki
2021-08-05 23:15   ` Nate DeSimone
2021-08-05 14:57 ` [edk2-platforms][PATCH v1 2/5] MinPlatformPkg/TestPointCheckLib: Set required size field in protocol Michael Kubacki
2021-08-05 23:14   ` Nate DeSimone
2021-08-05 14:57 ` [edk2-platforms][PATCH v1 3/5] MinPlatformPkg/TestPointCheckLib: Fix incorrect array index Michael Kubacki
2021-08-05 23:14   ` Nate DeSimone
2021-08-05 14:57 ` Michael Kubacki [this message]
2021-08-05 23:15   ` [edk2-devel] [edk2-platforms][PATCH v1 4/5] MinPlatformPkg/TestPointCheckLib: Improve adjacent region checking Nate DeSimone
2021-08-05 14:57 ` [edk2-platforms][PATCH v1 5/5] MinPlatformPkg/TestPointCheckLib: Make OutTable parameter optional Michael Kubacki
2021-08-05 23:15   ` [edk2-devel] " Nate DeSimone
2021-08-05 23:14 ` [edk2-devel] [edk2-platforms][PATCH v1 0/5] MinPlatformPkg: TestPointCheckLib bug fixes and improvements Nate DeSimone
2021-08-06  1:34   ` Michael Kubacki

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=20210805145706.2470-5-mikuback@linux.microsoft.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