UefiCpuPkg/SmmCpuFeaturesLib: Skip SMBASE configuration

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4337

This patch is to avoid configure SMBASE if SmBase relocation has been
done. If gSmmBaseHobGuid found, means SmBase info has been relocated
and recorded in the SmBase array. No need to do the relocation in
SmmCpuFeaturesInitializeProcessor().

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Wu, Jiaxin 2023-02-16 14:16:32 +08:00 committed by mergify[bot]
parent ec07fd0e35
commit f6b86eec5a
6 changed files with 36 additions and 9 deletions

View File

@ -9,11 +9,13 @@
#ifndef CPU_FEATURES_LIB_H_ #ifndef CPU_FEATURES_LIB_H_
#define CPU_FEATURES_LIB_H_ #define CPU_FEATURES_LIB_H_
#include <Guid/SmmBaseHob.h>
#include <Library/SmmCpuFeaturesLib.h> #include <Library/SmmCpuFeaturesLib.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/HobLib.h>
/** /**
Performs library initialization. Performs library initialization.

View File

@ -1,7 +1,7 @@
/** @file /** @file
Implementation shared across all library instances. Implementation shared across all library instances.
Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR> Copyright (c) 2010 - 2023, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.<BR> Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
@ -38,6 +38,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
UINT32 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE; UINT32 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE;
UINT32 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK; UINT32 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK;
//
// Indicate SmBase for each Processors has been relocated or not. If TRUE,
// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor().
//
BOOLEAN mSmmCpuFeaturesSmmRelocated;
// //
// Set default value to assume MTRRs need to be configured on each SMI // Set default value to assume MTRRs need to be configured on each SMI
// //
@ -144,6 +150,12 @@ CpuFeaturesLibInitialization (
// //
mSmrrEnabled = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * GetCpuMaxLogicalProcessorNumber ()); mSmrrEnabled = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * GetCpuMaxLogicalProcessorNumber ());
ASSERT (mSmrrEnabled != NULL); ASSERT (mSmrrEnabled != NULL);
//
// If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded
// in the SmBase array.
//
mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL);
} }
/** /**
@ -187,10 +199,15 @@ SmmCpuFeaturesInitializeProcessor (
UINTN ModelId; UINTN ModelId;
// //
// Configure SMBASE. // No need to configure SMBASE if SmBase relocation has been done.
// //
CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); if (!mSmmCpuFeaturesSmmRelocated) {
CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; //
// Configure SMBASE.
//
CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
}
// //
// Intel(R) 64 and IA-32 Architectures Software Developer's Manual // Intel(R) 64 and IA-32 Architectures Software Developer's Manual

View File

@ -1,7 +1,7 @@
## @file ## @file
# The CPU specific programming for PiSmmCpuDxeSmm module. # The CPU specific programming for PiSmmCpuDxeSmm module.
# #
# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
## ##
@ -33,6 +33,10 @@
PcdLib PcdLib
MemoryAllocationLib MemoryAllocationLib
DebugLib DebugLib
HobLib
[Guids]
gSmmBaseHobGuid ## CONSUMES
[Pcd] [Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES

View File

@ -2,7 +2,7 @@
# The CPU specific programming for PiSmmCpuDxeSmm module when STM support # The CPU specific programming for PiSmmCpuDxeSmm module when STM support
# is included. # is included.
# #
# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
## ##
@ -64,6 +64,7 @@
gMsegSmramGuid ## SOMETIMES_CONSUMES ## HOB gMsegSmramGuid ## SOMETIMES_CONSUMES ## HOB
gEfiAcpi20TableGuid ## SOMETIMES_CONSUMES ## SystemTable gEfiAcpi20TableGuid ## SOMETIMES_CONSUMES ## SystemTable
gEfiAcpi10TableGuid ## SOMETIMES_CONSUMES ## SystemTable gEfiAcpi10TableGuid ## SOMETIMES_CONSUMES ## SystemTable
gSmmBaseHobGuid ## CONSUMES
[Pcd] [Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES

View File

@ -1,14 +1,13 @@
/** @file /** @file
SMM STM support functions SMM STM support functions
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include <PiMm.h> #include <PiMm.h>
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/SmmServicesTableLib.h> #include <Library/SmmServicesTableLib.h>
#include <Library/TpmMeasurementLib.h> #include <Library/TpmMeasurementLib.h>

View File

@ -1,7 +1,7 @@
## @file ## @file
# Standalone MM CPU specific programming. # Standalone MM CPU specific programming.
# #
# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
# Copyright (c) Microsoft Corporation.<BR> # Copyright (c) Microsoft Corporation.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
@ -34,6 +34,10 @@
DebugLib DebugLib
MemoryAllocationLib MemoryAllocationLib
PcdLib PcdLib
HobLib
[Guids]
gSmmBaseHobGuid ## CONSUMES
[FixedPcd] [FixedPcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES