MdeModulePkg PiSmmCore: Enhance memory profile for memory leak detection

1. Produce SMM memory profile protocol.
2. Consume PcdMemoryProfilePropertyMask to support disable recording
at the start.
3. Consume PcdMemoryProfileDriverPath to control which drivers need
memory profile data.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Star Zeng 2016-06-18 10:14:40 +08:00
parent c16b7fe71a
commit e524f68064
6 changed files with 1113 additions and 318 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
SMM Memory page management functions. SMM Memory page management functions.
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at distribution. The full text of the license may be found at
@ -226,7 +226,14 @@ SmmAllocatePages (
Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory); Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePages, MemoryType, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) *Memory); SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
MemoryProfileActionAllocatePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
(VOID *) (UINTN) *Memory,
NULL
);
} }
return Status; return Status;
} }
@ -344,7 +351,14 @@ SmmFreePages (
Status = SmmInternalFreePages (Memory, NumberOfPages); Status = SmmInternalFreePages (Memory, NumberOfPages);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory); SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
EfiMaxMemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
(VOID *) (UINTN) Memory,
NULL
);
} }
return Status; return Status;
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
SMM Core Main Entry Point SMM Core Main Entry Point
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at distribution. The full text of the license may be found at
@ -632,6 +632,7 @@ SmmMain (
} }
RegisterSmramProfileHandler (); RegisterSmramProfileHandler ();
SmramProfileInstallProtocol ();
SmmCoreInstallLoadedImage (); SmmCoreInstallLoadedImage ();

View File

@ -2,7 +2,7 @@
The internal header file includes the common header files, defines The internal header file includes the common header files, defines
internal structure and functions used by SmmCore module. internal structure and functions used by SmmCore module.
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at distribution. The full text of the license may be found at
@ -42,6 +42,7 @@
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/PeCoffLib.h> #include <Library/PeCoffLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/CacheMaintenanceLib.h> #include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/ReportStatusCodeLib.h> #include <Library/ReportStatusCodeLib.h>
@ -884,17 +885,28 @@ SmramProfileInit (
VOID VOID
); );
/**
Install SMRAM profile protocol.
**/
VOID
SmramProfileInstallProtocol (
VOID
);
/** /**
Register SMM image to SMRAM profile. Register SMM image to SMRAM profile.
@param DriverEntry SMM image info. @param DriverEntry SMM image info.
@param RegisterToDxe Register image to DXE. @param RegisterToDxe Register image to DXE.
@retval TRUE Register success. @return EFI_SUCCESS Register successfully.
@retval FALSE Register fail. @return EFI_UNSUPPORTED Memory profile unsupported,
or memory profile for the image is not required.
@return EFI_OUT_OF_RESOURCES No enough resource for this register.
**/ **/
BOOLEAN EFI_STATUS
RegisterSmramProfileImage ( RegisterSmramProfileImage (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry, IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN RegisterToDxe IN BOOLEAN RegisterToDxe
@ -906,11 +918,13 @@ RegisterSmramProfileImage (
@param DriverEntry SMM image info. @param DriverEntry SMM image info.
@param UnregisterToDxe Unregister image from DXE. @param UnregisterToDxe Unregister image from DXE.
@retval TRUE Unregister success. @return EFI_SUCCESS Unregister successfully.
@retval FALSE Unregister fail. @return EFI_UNSUPPORTED Memory profile unsupported,
or memory profile for the image is not required.
@return EFI_NOT_FOUND The image is not found.
**/ **/
BOOLEAN EFI_STATUS
UnregisterSmramProfileImage ( UnregisterSmramProfileImage (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry, IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN UnregisterToDxe IN BOOLEAN UnregisterToDxe
@ -922,20 +936,31 @@ UnregisterSmramProfileImage (
@param CallerAddress Address of caller who call Allocate or Free. @param CallerAddress Address of caller who call Allocate or Free.
@param Action This Allocate or Free action. @param Action This Allocate or Free action.
@param MemoryType Memory type. @param MemoryType Memory type.
EfiMaxMemoryType means the MemoryType is unknown.
@param Size Buffer size. @param Size Buffer size.
@param Buffer Buffer address. @param Buffer Buffer address.
@param ActionString String for memory profile action.
Only needed for user defined allocate action.
@retval TRUE Profile udpate success. @return EFI_SUCCESS Memory profile is updated.
@retval FALSE Profile update fail. @return EFI_UNSUPPORTED Memory profile is unsupported,
or memory profile for the image is not required,
or memory profile for the memory type is not required.
@return EFI_ACCESS_DENIED It is during memory profile data getting.
@return EFI_ABORTED Memory profile recording is not enabled.
@return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
@return EFI_NOT_FOUND No matched allocate info found for free action.
**/ **/
BOOLEAN EFI_STATUS
EFIAPI
SmmCoreUpdateProfile ( SmmCoreUpdateProfile (
IN EFI_PHYSICAL_ADDRESS CallerAddress, IN PHYSICAL_ADDRESS CallerAddress,
IN MEMORY_PROFILE_ACTION Action, IN MEMORY_PROFILE_ACTION Action,
IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool
IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool
IN VOID *Buffer IN VOID *Buffer,
IN CHAR8 *ActionString OPTIONAL
); );
/** /**

View File

@ -1,7 +1,7 @@
## @file ## @file
# This module provide an SMM CIS compliant implementation of SMM Core. # This module provide an SMM CIS compliant implementation of SMM Core.
# #
# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
# #
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # are licensed and made available under the terms and conditions of the BSD License
@ -48,6 +48,7 @@
BaseLib BaseLib
BaseMemoryLib BaseMemoryLib
PeCoffLib PeCoffLib
PeCoffGetEntryPointLib
CacheMaintenanceLib CacheMaintenanceLib
DebugLib DebugLib
ReportStatusCodeLib ReportStatusCodeLib
@ -81,6 +82,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileMemoryType ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileMemoryType ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath ## CONSUMES
[Guids] [Guids]
gAprioriGuid ## SOMETIMES_CONSUMES ## File gAprioriGuid ## SOMETIMES_CONSUMES ## File
@ -92,6 +94,8 @@
## SOMETIMES_CONSUMES ## GUID # Locate protocol ## SOMETIMES_CONSUMES ## GUID # Locate protocol
## SOMETIMES_PRODUCES ## GUID # SmiHandlerRegister ## SOMETIMES_PRODUCES ## GUID # SmiHandlerRegister
gEdkiiMemoryProfileGuid gEdkiiMemoryProfileGuid
## SOMETIMES_PRODUCES ## GUID # Install protocol
gEdkiiSmmMemoryProfileGuid
gZeroGuid ## SOMETIMES_CONSUMES ## GUID gZeroGuid ## SOMETIMES_CONSUMES ## GUID
[UserExtensions.TianoCore."ExtraFiles"] [UserExtensions.TianoCore."ExtraFiles"]

View File

@ -1,7 +1,7 @@
/** @file /** @file
SMM Memory pool management functions. SMM Memory pool management functions.
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at distribution. The full text of the license may be found at
@ -260,7 +260,14 @@ SmmAllocatePool (
Status = SmmInternalAllocatePool (PoolType, Size, Buffer); Status = SmmInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePool, PoolType, Size, *Buffer); SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
*Buffer,
NULL
);
} }
return Status; return Status;
} }
@ -319,7 +326,14 @@ SmmFreePool (
Status = SmmInternalFreePool (Buffer); Status = SmmInternalFreePool (Buffer);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePool, 0, 0, Buffer); SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
EfiMaxMemoryType,
0,
Buffer,
NULL
);
} }
return Status; return Status;
} }

File diff suppressed because it is too large Load Diff