From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web12.2503.1628213605432307357 for ; Thu, 05 Aug 2021 18:33:25 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=Wf/52JlO; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [167.220.2.74]) by linux.microsoft.com (Postfix) with ESMTPSA id 015AE20B36ED; Thu, 5 Aug 2021 18:33:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 015AE20B36ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1628213605; bh=o5lslBtXvgf25DPJ0E4DeqiXa+s43ahgVfL2oVIXo8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wf/52JlOBRISDV8BqzXA30KNYKx4lI8FBicMoVvK5EMkzmdMpu8Sf5j6VZ3xfT5ZS d7K6vpBnGxaOnexrELPmzL42MocJK2AH/NdSzz/667jj2ZzYCwKwJz2lRdK9WFPnXD 1tH5jYKrtDWZfPeb1aZltU3IJg3qHjxWvKg+blwQ= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [edk2-platforms][PATCH v2 4/5] MinPlatformPkg/TestPointCheckLib: Improve adjacent region checking Date: Thu, 5 Aug 2021 21:32:49 -0400 Message-Id: <20210806013250.2928-5-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210806013250.2928-1-mikuback@linux.microsoft.com> References: <20210806013250.2928-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3521 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 Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Michael Kubacki Reviewed-by: Nate DeSimone --- Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckSmm= Info.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/TestPoint= CheckLib/DxeCheckSmmInfo.c index c493750a27e6..f15f76eab574 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckSmmInfo.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckSmmInfo.c @@ -59,34 +59,36 @@ CheckSmramDescriptor ( ) { UINTN Index; - UINT64 Base; + UINTN Index2; UINT64 Length; + BOOLEAN AdjacentRegion; =20 - Base =3D 0; Length =3D 0; for (Index =3D 0; Index < NumberOfSmmReservedRegions; Index++) { - if (Base =3D=3D 0) { - Base =3D Descriptor[Index].PhysicalStart; - Length =3D Descriptor[Index].PhysicalSize; + AdjacentRegion =3D FALSE; + for (Index2 =3D 0; Index2 < NumberOfSmmReservedRegions; Index2++) { + if ((NumberOfSmmReservedRegions =3D=3D 1) + || (Descriptor[Index].PhysicalStart + Descriptor[Index].Physic= alSize =3D=3D Descriptor[Index2].PhysicalStart) + || (Descriptor[Index2].PhysicalStart + Descriptor[Index2].Phys= icalSize =3D=3D Descriptor[Index].PhysicalStart)) { + AdjacentRegion =3D TRUE; + break; + } + } + + if (AdjacentRegion =3D=3D TRUE) { + Length +=3D Descriptor[Index].PhysicalSize; } else { - if (Base + Length =3D=3D Descriptor[Index].PhysicalStart) { - Length =3D Length + Descriptor[Index].PhysicalSize; - } else if (Descriptor[Index].PhysicalStart + Descriptor[Index].Phy= sicalSize =3D=3D Base) { - Base =3D Descriptor[Index].PhysicalStart; - Length =3D 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_COD= E \ - TEST_POINT_DXE_SMM_READY_TO_LOCK=20 - TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_S= TRING - ); - 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_STR= ING + ); + return EFI_INVALID_PARAMETER; } - } =20 + } =20 if (Length !=3D 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=20 + TEST_POINT_DXE_SMM_READY_TO_LOCK TEST_POINT_BYTE7_DXE_SMM_READY_TO_LOCK_SMRAM_ALIGNED_ERROR_STRIN= G ); return EFI_INVALID_PARAMETER; @@ -111,14 +113,14 @@ TestPointCheckSmmInfo ( EFI_SMM_ACCESS2_PROTOCOL *SmmAccess; UINTN Size; EFI_SMRAM_DESCRIPTOR *SmramRanges; - =20 + DEBUG ((DEBUG_INFO, "=3D=3D=3D=3D TestPointCheckSmmInfo - Enter\n")); - =20 + Status =3D gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VO= ID **)&SmmAccess); if (EFI_ERROR (Status)) { goto Done ; } - =20 + Size =3D 0; Status =3D SmmAccess->GetCapabilities (SmmAccess, &Size, NULL); ASSERT (Status =3D=3D EFI_BUFFER_TOO_SMALL); @@ -128,7 +130,7 @@ TestPointCheckSmmInfo ( =20 Status =3D SmmAccess->GetCapabilities (SmmAccess, &Size, SmramRanges); ASSERT_EFI_ERROR (Status); - =20 + DEBUG ((DEBUG_INFO, "SMRAM Info\n")); DumpSmramDescriptor (Size / sizeof (EFI_SMRAM_DESCRIPTOR), SmramRanges= ); =20 --=20 2.28.0.windows.1