diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapDxeSmm.c index 8dbcd8d950..27f159b98c 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapDxeSmm.c @@ -460,6 +460,24 @@ GetSmmProfileData ( return Base; } +/** + Return if the Address is the NonMmram logging Address. + + @param[in] Address the address to be checked + + @return TRUE The address is the NonMmram logging Address. + @return FALSE The address is not the NonMmram logging Address. +**/ +BOOLEAN +IsNonMmramLoggingAddress ( + IN UINT64 Address + ) +{ + ASSERT (FALSE); + + return TRUE; +} + /** Return if the Address is forbidden as SMM communication buffer. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c index 8c5286b744..70e94a6b76 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c @@ -46,6 +46,38 @@ GetSmmProfileData ( return SmmProfileDataHob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress; } +/** + Return if the Address is the NonMmram logging Address. + + @param[in] Address the address to be checked + + @return TRUE The address is the NonMmram logging Address. + @return FALSE The address is not the NonMmram logging Address. +**/ +BOOLEAN +IsNonMmramLoggingAddress ( + IN UINT64 Address + ) +{ + EFI_PEI_HOB_POINTERS Hob; + + Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR); + while (Hob.Raw != NULL) { + if ((Address >= Hob.ResourceDescriptor->PhysicalStart) && (Address < Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength)) { + if ((Hob.ResourceDescriptor->ResourceAttribute & MM_RESOURCE_ATTRIBUTE_LOGGING) != 0) { + return TRUE; + } + + return FALSE; + } + + Hob.Raw = GET_NEXT_HOB (Hob); + Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw); + } + + return FALSE; +} + /** Return if the Address is forbidden as SMM communication buffer. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h index 44bf3f3aba..73ace4efa4 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h @@ -979,6 +979,19 @@ GetSmmProfileData ( IN OUT UINT64 *Size ); +/** + Return if the Address is the NonMmram logging Address. + + @param[in] Address the address to be checked + + @return TRUE The address is the NonMmram logging Address. + @return FALSE The address is not the NonMmram logging Address. +**/ +BOOLEAN +IsNonMmramLoggingAddress ( + IN UINT64 Address + ); + /** Return if the Address is forbidden as SMM communication buffer. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c index a5253e8167..f56d2849de 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -821,6 +821,13 @@ SmiPFHandler ( } if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mIsStandaloneMm) { + // + // Only logging ranges shall run here in MM env. + // + ASSERT (IsNonMmramLoggingAddress (PFAddress)); + } + SmmProfilePFHandler ( SystemContext.SystemContextX64->Rip, SystemContext.SystemContextX64->ExceptionData