TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmProfile.c File Reference
#include "PiSmmCpuCommon.h"
#include "SmmProfileInternal.h"

Go to the source code of this file.

Functions

VOID DisableBTS (VOID)
 
VOID EnableBTS (VOID)
 
UINTN GetCpuIndex (VOID)
 
UINT64 GetSourceFromDestinationOnBts (UINTN CpuIndex, UINT64 DestinationIP)
 
VOID EFIAPI DebugExceptionHandler (IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
 
BOOLEAN IsInSmmRanges (IN EFI_PHYSICAL_ADDRESS Address)
 
BOOLEAN IsSmmProfilePFAddressAbove4GValid (IN EFI_PHYSICAL_ADDRESS Address, OUT BOOLEAN *Nx)
 
BOOLEAN IsAddressSplit (IN EFI_PHYSICAL_ADDRESS Address)
 
INTN EFIAPI ProtectionRangeCompare (IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
 
VOID InitProtectedMemRange (VOID)
 
VOID SmmProfileUpdateMemoryAttributes (VOID)
 
VOID SmmProfileStart (VOID)
 
EFI_STATUS EFIAPI InitSmmProfileCallBack (IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
 
VOID InitSmmProfileInternal (VOID)
 
VOID CheckFeatureSupported (IN UINTN CpuIndex)
 
VOID ActivateSingleStepDB (VOID)
 
VOID ActivateLBR (VOID)
 
VOID ActivateBTS (IN UINTN CpuIndex)
 
VOID SmmProfileRecordSmiNum (VOID)
 
VOID ActivateSmmProfile (IN UINTN CpuIndex)
 
VOID InitSmmProfile (UINT32 Cr3)
 
VOID RestorePageTableBelow4G (UINT64 *PageTable, UINT64 PFAddress, UINTN CpuIndex, UINTN ErrorCode)
 
VOID GuardPagePFHandler (UINTN ErrorCode)
 
VOID SmmProfilePFHandler (UINTN Rip, UINTN ErrorCode)
 
VOID InitIdtr (VOID)
 

Variables

UINT32 mSmmProfileCr3
 
SMM_PROFILE_HEADERmSmmProfileBase
 
MSR_DS_AREA_STRUCTmMsrDsAreaBase
 
UINTN mSmmProfileSize
 
UINTN mMsrDsAreaSize = SMM_PROFILE_DTS_SIZE
 
BOOLEAN mXdSupported = TRUE
 
BOOLEAN mXdEnabled = FALSE
 
BOOLEAN mBtsSupported = TRUE
 
BOOLEAN mSmmProfileEnabled = FALSE
 
BOOLEAN mSmmProfileStart = FALSE
 
BOOLEAN mSetupDebugTrap = FALSE
 
UINTNmPFEntryCount
 
UINT64(* mLastPFEntryValue )[MAX_PF_ENTRY_COUNT]
 
UINT64 *(* mLastPFEntryPointer )[MAX_PF_ENTRY_COUNT]
 
MSR_DS_AREA_STRUCT ** mMsrDsArea
 
BRANCH_TRACE_RECORD ** mMsrBTSRecord
 
UINTN mBTSRecordNumber
 
PEBS_RECORD ** mMsrPEBSRecord
 
MEMORY_PROTECTION_RANGEmProtectionMemRange = NULL
 
UINTN mProtectionMemRangeCount = 0
 
MEMORY_PROTECTION_RANGE mProtectionMemRangeTemplate []
 
MEMORY_RANGEmSplitMemRange = NULL
 
UINTN mSplitMemRangeCount = 0
 
UINT32 mSmiCommandPort
 

Detailed Description

Enable SMM profile.

Copyright (c) 2012 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SmmProfile.c.

Function Documentation

◆ ActivateBTS()

VOID ActivateBTS ( IN UINTN  CpuIndex)

Enable branch trace store.

Parameters
CpuIndexThe index of the processor.

Definition at line 963 of file SmmProfile.c.

◆ ActivateLBR()

VOID ActivateLBR ( VOID  )

Enable last branch.

Definition at line 941 of file SmmProfile.c.

◆ ActivateSingleStepDB()

VOID ActivateSingleStepDB ( VOID  )

Enable single step.

Definition at line 921 of file SmmProfile.c.

◆ ActivateSmmProfile()

VOID ActivateSmmProfile ( IN UINTN  CpuIndex)

Initialize processor environment for SMM profile.

Parameters
CpuIndexThe index of the processor.

Definition at line 1007 of file SmmProfile.c.

◆ CheckFeatureSupported()

VOID CheckFeatureSupported ( IN UINTN  CpuIndex)

Check if feature is supported by a processor.

Parameters
CpuIndexThe index of the CPU.

Definition at line 859 of file SmmProfile.c.

◆ DebugExceptionHandler()

VOID EFIAPI DebugExceptionHandler ( IN EFI_EXCEPTION_TYPE  InterruptType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

SMM profile specific INT 1 (single-step) exception handler.

Parameters
InterruptTypeDefines the type of interrupt or exception that occurred on the processor.This parameter is processor architecture specific.
SystemContextA pointer to the processor context when the interrupt occurred on the processor.

Definition at line 247 of file SmmProfile.c.

◆ DisableBTS()

VOID DisableBTS ( VOID  )

Disable branch trace store.

Definition at line 130 of file SmmProfile.c.

◆ EnableBTS()

VOID EnableBTS ( VOID  )

Enable branch trace store.

Definition at line 148 of file SmmProfile.c.

◆ GetCpuIndex()

UINTN GetCpuIndex ( VOID  )

Get CPU Index from APIC ID.

Definition at line 166 of file SmmProfile.c.

◆ GetSourceFromDestinationOnBts()

UINT64 GetSourceFromDestinationOnBts ( UINTN  CpuIndex,
UINT64  DestinationIP 
)

Get the source of IP after execute-disable exception is triggered.

Parameters
CpuIndexThe index of CPU.
DestinationIPThe destination address.

Definition at line 193 of file SmmProfile.c.

◆ GuardPagePFHandler()

VOID GuardPagePFHandler ( UINTN  ErrorCode)

Handler for Page Fault triggered by Guard page.

Parameters
ErrorCodeThe Error code of exception.

Definition at line 1208 of file SmmProfile.c.

◆ InitIdtr()

VOID InitIdtr ( VOID  )

Replace INT1 exception handler to restore page table to absent/execute-disable state in order to trigger page fault again to save SMM profile data..

Definition at line 1394 of file SmmProfile.c.

◆ InitProtectedMemRange()

VOID InitProtectedMemRange ( VOID  )

Initialize the protected memory ranges and the 4KB-page mapped memory ranges.

Definition at line 420 of file SmmProfile.c.

◆ InitSmmProfile()

VOID InitSmmProfile ( UINT32  Cr3)

Initialize SMM profile in SMM CPU entry point.

Parameters
[in]Cr3The base address of the page tables to use in SMM.

Definition at line 1036 of file SmmProfile.c.

◆ InitSmmProfileCallBack()

EFI_STATUS EFIAPI InitSmmProfileCallBack ( IN CONST EFI_GUID Protocol,
IN VOID *  Interface,
IN EFI_HANDLE  Handle 
)

Initialize SMM profile in SmmReadyToLock protocol callback function.

Parameters
ProtocolPoints to the protocol's unique identifier.
InterfacePoints to the interface instance.
HandleThe handle on which the interface was installed.
Return values
EFI_SUCCESSSmmReadyToLock protocol callback runs successfully.

Definition at line 708 of file SmmProfile.c.

◆ InitSmmProfileInternal()

VOID InitSmmProfileInternal ( VOID  )

Initialize SMM profile data structures.

Definition at line 742 of file SmmProfile.c.

◆ IsAddressSplit()

BOOLEAN IsAddressSplit ( IN EFI_PHYSICAL_ADDRESS  Address)

Check if the memory address will be mapped by 4KB-page.

Parameters
AddressThe address of Memory.

Definition at line 356 of file SmmProfile.c.

◆ IsInSmmRanges()

BOOLEAN IsInSmmRanges ( IN EFI_PHYSICAL_ADDRESS  Address)

Check if the input address is in SMM ranges.

Parameters
[in]AddressThe input address.
Return values
TRUEThe input address is in SMM.
FALSEThe input address is not in SMM.

Definition at line 296 of file SmmProfile.c.

◆ IsSmmProfilePFAddressAbove4GValid()

BOOLEAN IsSmmProfilePFAddressAbove4GValid ( IN EFI_PHYSICAL_ADDRESS  Address,
OUT BOOLEAN *  Nx 
)

Check if the SMM profile page fault address above 4GB is in protected range or not.

Parameters
[in]AddressThe address of Memory.
[out]NxThe flag indicates if the memory is execute-disable.
Return values
TRUEThe input address is in protected range.
FALSEThe input address is not in protected range.

Definition at line 328 of file SmmProfile.c.

◆ ProtectionRangeCompare()

INTN EFIAPI ProtectionRangeCompare ( IN CONST VOID *  Buffer1,
IN CONST VOID *  Buffer2 
)

Function to compare 2 MEMORY_PROTECTION_RANGE based on range base.

Parameters
[in]Buffer1pointer to Device Path poiner to compare
[in]Buffer2pointer to second DevicePath pointer to compare
Return values
0Buffer1 equal to Buffer2
<0Buffer1 is less than Buffer2
>0Buffer1 is greater than Buffer2

Definition at line 401 of file SmmProfile.c.

◆ RestorePageTableBelow4G()

VOID RestorePageTableBelow4G ( UINT64 *  PageTable,
UINT64  PFAddress,
UINTN  CpuIndex,
UINTN  ErrorCode 
)

Update page table to map the memory correctly in order to make the instruction which caused page fault execute successfully. And it also save the original page table to be restored in single-step exception.

Parameters
PageTablePageTable Address.
PFAddressThe memory address which caused page fault exception.
CpuIndexThe index of the processor.
ErrorCodeThe Error code of exception.

Definition at line 1078 of file SmmProfile.c.

◆ SmmProfilePFHandler()

VOID SmmProfilePFHandler ( UINTN  Rip,
UINTN  ErrorCode 
)

The Page fault handler to save SMM profile data.

Parameters
RipThe RIP when exception happens.
ErrorCodeThe Error code of exception.

Definition at line 1249 of file SmmProfile.c.

◆ SmmProfileRecordSmiNum()

VOID SmmProfileRecordSmiNum ( VOID  )

Increase SMI number in each SMI entry.

Definition at line 991 of file SmmProfile.c.

◆ SmmProfileStart()

VOID SmmProfileStart ( VOID  )

Updates page table to make some memory ranges (like system memory) absent and make some memory ranges (like MMIO) present and execute disable. It also update 2MB-page to 4KB-page for some memory ranges.

Definition at line 682 of file SmmProfile.c.

◆ SmmProfileUpdateMemoryAttributes()

VOID SmmProfileUpdateMemoryAttributes ( VOID  )

This function updates memory attribute according to mProtectionMemRangeCount.

Definition at line 597 of file SmmProfile.c.

Variable Documentation

◆ mBTSRecordNumber

UINTN mBTSRecordNumber

Definition at line 68 of file SmmProfile.c.

◆ mBtsSupported

BOOLEAN mBtsSupported = TRUE

Definition at line 41 of file SmmProfile.c.

◆ mLastPFEntryPointer

UINT64*(* mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT]

Definition at line 64 of file SmmProfile.c.

◆ mLastPFEntryValue

UINT64(* mLastPFEntryValue)[MAX_PF_ENTRY_COUNT]

Definition at line 63 of file SmmProfile.c.

◆ mMsrBTSRecord

BRANCH_TRACE_RECORD** mMsrBTSRecord

Definition at line 67 of file SmmProfile.c.

◆ mMsrDsArea

MSR_DS_AREA_STRUCT** mMsrDsArea

Definition at line 66 of file SmmProfile.c.

◆ mMsrDsAreaBase

MSR_DS_AREA_STRUCT* mMsrDsAreaBase

Definition at line 17 of file SmmProfile.c.

◆ mMsrDsAreaSize

UINTN mMsrDsAreaSize = SMM_PROFILE_DTS_SIZE

Definition at line 26 of file SmmProfile.c.

◆ mMsrPEBSRecord

PEBS_RECORD** mMsrPEBSRecord

Definition at line 69 of file SmmProfile.c.

◆ mPFEntryCount

UINTN* mPFEntryCount

Definition at line 61 of file SmmProfile.c.

◆ mProtectionMemRange

MEMORY_PROTECTION_RANGE* mProtectionMemRange = NULL

Definition at line 75 of file SmmProfile.c.

◆ mProtectionMemRangeCount

UINTN mProtectionMemRangeCount = 0

Definition at line 76 of file SmmProfile.c.

◆ mProtectionMemRangeTemplate

MEMORY_PROTECTION_RANGE mProtectionMemRangeTemplate[]

Definition at line 81 of file SmmProfile.c.

◆ mSetupDebugTrap

BOOLEAN mSetupDebugTrap = FALSE

Definition at line 56 of file SmmProfile.c.

◆ mSmiCommandPort

UINT32 mSmiCommandPort

Definition at line 123 of file SmmProfile.c.

◆ mSmmProfileBase

SMM_PROFILE_HEADER* mSmmProfileBase

Definition at line 16 of file SmmProfile.c.

◆ mSmmProfileCr3

UINT32 mSmmProfileCr3

Definition at line 14 of file SmmProfile.c.

◆ mSmmProfileEnabled

BOOLEAN mSmmProfileEnabled = FALSE

Definition at line 46 of file SmmProfile.c.

◆ mSmmProfileSize

UINTN mSmmProfileSize

Definition at line 21 of file SmmProfile.c.

◆ mSmmProfileStart

BOOLEAN mSmmProfileStart = FALSE

Definition at line 51 of file SmmProfile.c.

◆ mSplitMemRange

MEMORY_RANGE* mSplitMemRange = NULL

Definition at line 117 of file SmmProfile.c.

◆ mSplitMemRangeCount

UINTN mSplitMemRangeCount = 0

Definition at line 118 of file SmmProfile.c.

◆ mXdEnabled

BOOLEAN mXdEnabled = FALSE

Definition at line 36 of file SmmProfile.c.

◆ mXdSupported

BOOLEAN mXdSupported = TRUE

Definition at line 31 of file SmmProfile.c.