Skip to content

Commit 58b4bf7

Browse files
hongbin123mergify[bot]
authored andcommitted
StandaloneMmPkg/MmIpl: Correct unblocked memory regions attribute
When CPU smm profile feature was enabled, unblocked memory should not set logging attribute when building resource HOB. Signed-off-by: Hongbin1 Zhang <[email protected]> Cc: Jiewen Yao <[email protected]> Cc: Ray Ni <[email protected]> Cc: Star Zeng <[email protected]> Cc: Jiaxin Wu <[email protected]> Cc: Wei6 Xu <[email protected]> Cc: Sami Mujawar <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Supreeth Venkatesh <[email protected]>
1 parent 14c9ba1 commit 58b4bf7

File tree

1 file changed

+87
-27
lines changed

1 file changed

+87
-27
lines changed

StandaloneMmPkg/Drivers/StandaloneMmIplPei/MmFoundationHob.c

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,44 @@ MmIplBuildResourceHobForUnblockedRegion (
450450
*HobBufferSize = UsedSize;
451451
}
452452

453+
/**
454+
Collect unblock memory regions.
455+
456+
@param[in, out] MemoryRegion Pointer to unblock memory regions.
457+
@param[in, out] MemoryRegionCount Count of unblock memory regions.
458+
**/
459+
VOID
460+
CollectUnblockMemoryRegions (
461+
IN OUT MM_IPL_MEMORY_REGION *MemoryRegion,
462+
IN OUT UINTN *MemoryRegionCount
463+
)
464+
{
465+
UINTN Index;
466+
EFI_HOB_GENERIC_HEADER *GuidHob;
467+
MM_UNBLOCK_REGION *UnblockRegion;
468+
469+
ASSERT (MemoryRegionCount != NULL);
470+
ASSERT (*MemoryRegionCount == 0 || MemoryRegion != NULL);
471+
472+
Index = 0;
473+
//
474+
// Collect unblock memory ranges
475+
//
476+
GuidHob = GetFirstGuidHob (&gMmUnblockRegionHobGuid);
477+
while (GuidHob != NULL) {
478+
if (Index < *MemoryRegionCount) {
479+
UnblockRegion = GET_GUID_HOB_DATA (GuidHob);
480+
MemoryRegion[Index].Base = UnblockRegion->PhysicalStart;
481+
MemoryRegion[Index].Length = EFI_PAGES_TO_SIZE (UnblockRegion->NumberOfPages);
482+
}
483+
484+
Index++;
485+
GuidHob = GetNextGuidHob (&gMmUnblockRegionHobGuid, GET_NEXT_HOB (GuidHob));
486+
}
487+
488+
*MemoryRegionCount = Index;
489+
}
490+
453491
/**
454492
Create MMIO memory map according to platform HOB.
455493
@@ -564,16 +602,15 @@ MmIplCalculateMaximumSupportAddress (
564602

565603
/**
566604
Build resource HOB to cover [0, PhysicalAddressBits length] by excluding
567-
all Mmram ranges, MM Profile data and MMIO ranges.
568-
569-
@param[in] HobBuffer The pointer of new HOB buffer.
570-
@param[in, out] HobBufferSize The available size of the HOB buffer when as input.
571-
The used size of when as output.
572-
@param[in] PlatformHobList Platform HOB list.
573-
@param[in] PlatformHobSize Platform HOB size.
574-
@param[in] Block Pointer of MMRAM descriptor block.
575-
@param[in] MmProfileDataHob Pointer to MM profile data HOB.
576-
605+
all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges.
606+
607+
@param[in] HobBuffer The pointer of new HOB buffer.
608+
@param[in, out] HobBufferSize The available size of the HOB buffer when as input.
609+
The used size of when as output.
610+
@param[in] PlatformHobList Platform HOB list.
611+
@param[in] PlatformHobSize Platform HOB size.
612+
@param[in] Block Pointer of MMRAM descriptor block.
613+
@param[in] MmProfileDataHob Pointer to MM profile data HOB.
577614
**/
578615
VOID
579616
MmIplBuildResourceHobForAllSystemMemory (
@@ -593,6 +630,7 @@ MmIplBuildResourceHobForAllSystemMemory (
593630
UINT64 MaxAddress;
594631
MM_IPL_MEMORY_REGION *MemoryRegions;
595632
MM_IPL_MEMORY_REGION SortBuffer;
633+
UINTN UnblockRegionCount;
596634

597635
MaxAddress = LShiftU64 (1, MmIplCalculateMaximumSupportAddress ());
598636

@@ -605,9 +643,16 @@ MmIplBuildResourceHobForAllSystemMemory (
605643
}
606644

607645
//
608-
// Allocate buffer for platform memory regions, MM Profile data, MMRam ranges, an extra terminator.
646+
// Get the count of platform memory regions
647+
//
648+
UnblockRegionCount = 0;
649+
CollectUnblockMemoryRegions (NULL, &UnblockRegionCount);
650+
651+
//
652+
// Allocate buffer for platform memory regions, unblock memory regions,
653+
// MM Profile data, MMRam ranges, an extra terminator.
609654
//
610-
Count = PlatformRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;
655+
Count = PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;
611656
MemoryRegions = AllocatePages (EFI_SIZE_TO_PAGES (Count * sizeof (*MemoryRegions)));
612657
ASSERT (MemoryRegions != NULL);
613658
if (MemoryRegions == NULL) {
@@ -629,24 +674,31 @@ MmIplBuildResourceHobForAllSystemMemory (
629674
CollectPlatformMemoryRegions (PlatformHobList, PlatformHobSize, MemoryRegions, &PlatformRegionCount);
630675
}
631676

677+
//
678+
// Collect unblock memory regions
679+
//
680+
if (UnblockRegionCount != 0) {
681+
CollectUnblockMemoryRegions (&MemoryRegions[PlatformRegionCount], &UnblockRegionCount);
682+
}
683+
632684
//
633685
// Collect SMRAM regions
634686
//
635687
for (Index = 0; Index < Block->NumberOfMmReservedRegions; Index++) {
636-
MemoryRegions[PlatformRegionCount + Index].Base = Block->Descriptor[Index].CpuStart;
637-
MemoryRegions[PlatformRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;
688+
MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Base = Block->Descriptor[Index].CpuStart;
689+
MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;
638690
}
639691

640692
//
641693
// Collect MM profile database region
642694
//
643695
if (MmProfileDataHob != NULL) {
644-
MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Base = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;
645-
MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;
696+
MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Base = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;
697+
MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;
646698
}
647699

648700
//
649-
// Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database.
701+
// Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database, Unblocked memory regions.
650702
//
651703
QuickSort (MemoryRegions, Count, sizeof (*MemoryRegions), MemoryRegionBaseAddressCompare, &SortBuffer);
652704
UsedSize = 0;
@@ -843,24 +895,32 @@ CreateMmFoundationHobList (
843895
UsedSize += HobLength;
844896
}
845897

898+
//
899+
// Build resource HOB for unblocked region
900+
//
846901
HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);
847-
if (PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {
848-
//
849-
// Only unblocked memory regions are accessible
850-
//
851-
MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);
852-
} else {
902+
MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);
903+
UsedSize += HobLength;
904+
905+
if (!PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {
853906
//
854907
// All system memory (DRAM) is accessible.
855908
// When SMM Profile is enabled:
856-
// * Access to regions reported from MmPlatformHobProducerLib do not require logging.
909+
// * Access to regions included all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges do not require logging.
857910
// * Access to other system memory requires logging.
858911
//
859-
MmIplBuildResourceHobForAllSystemMemory (FoundationHobList + UsedSize, &HobLength, PlatformHobList, PlatformHobSize, Block, MmProfileDataHob);
912+
HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);
913+
MmIplBuildResourceHobForAllSystemMemory (
914+
FoundationHobList + UsedSize,
915+
&HobLength,
916+
PlatformHobList,
917+
PlatformHobSize,
918+
Block,
919+
MmProfileDataHob
920+
);
921+
UsedSize += HobLength;
860922
}
861923

862-
UsedSize += HobLength;
863-
864924
if (*FoundationHobSize < UsedSize) {
865925
Status = RETURN_BUFFER_TOO_SMALL;
866926
} else {

0 commit comments

Comments
 (0)