OvmfPkg/CpuHotplugSmm: hook up MSR_IA32_FEATURE_CONTROL with platform info

Map the feature control MSR config from the OVMF platform info HOB to
FIRST_SMI_HANDLER_CONTEXT.

(Note that CpuHotplugSmm already consumes -- indirectly -- the
"MdePkg/Library/DxeHobLib/DxeHobLib.inf" library instance, according to
the build report; therefore adding an explicit HobLib class dependency
shouldn't *generally* increase this SMM driver's exposure. The consumed
lib instances are the same before and after this patch, at least in
"OvmfPkgIa32X64.dsc".)

Fixes: https://github.com/tianocore/edk2/issues/11188
Signed-off-by: Laszlo Ersek <laszlo.ersek@posteo.net>
This commit is contained in:
Laszlo Ersek
2025-07-03 20:34:03 +02:00
committed by Laszlo Ersek
parent 0e814e829e
commit 43d696a366
2 changed files with 24 additions and 1 deletions

View File

@@ -42,6 +42,7 @@
BaseMemoryLib
CpuLib
DebugLib
HobLib
LocalApicLib
MmServicesTableLib
PcdLib
@@ -53,6 +54,9 @@
gEfiMmCpuIoProtocolGuid ## CONSUMES
gEfiSmmCpuServiceProtocolGuid ## CONSUMES
[Guids]
gUefiOvmfPkgPlatformInfoGuid ## CONSUMES
[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress ## CONSUMES

View File

@@ -10,7 +10,9 @@
#include <Library/BaseLib.h> // CpuPause()
#include <Library/BaseMemoryLib.h> // CopyMem()
#include <Library/DebugLib.h> // DEBUG()
#include <Library/HobLib.h> // GetFirstGuidHob()
#include <Library/LocalApicLib.h> // SendInitSipiSipi()
#include <Library/PlatformInitLib.h> // EFI_HOB_PLATFORM_INFO
#include <Library/SynchronizationLib.h> // InterlockedCompareExchange64()
#include <Register/Intel/SmramSaveStateMap.h> // SMM_DEFAULT_SMBASE
@@ -133,7 +135,9 @@ SmbaseReleasePostSmmPen (
Note that this effects an "SMRAM to SMRAM" copy.
Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT, and prepare
for configuring MSR_IA32_FEATURE_CONTROL.
for configuring MSR_IA32_FEATURE_CONTROL. (The latter depends on a GUID HOB,
which does not live in SMRAM; however, if we can't trust the HOB list at this
stage, we're doomed anyway.)
This function may only be called from the entry point function of the driver,
and only after PcdQ35SmramAtDefaultSmbase has been determined to be TRUE.
@@ -144,6 +148,7 @@ SmbaseInstallFirstSmiHandler (
)
{
FIRST_SMI_HANDLER_CONTEXT *Context;
EFI_HOB_GUID_TYPE *GuidHob;
CopyMem (
(VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
@@ -155,6 +160,20 @@ SmbaseInstallFirstSmiHandler (
Context->ApicIdGate = MAX_UINT64;
Context->FeatureControl = 0;
GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
if (GuidHob != NULL) {
EFI_HOB_PLATFORM_INFO *Info;
Info = GET_GUID_HOB_DATA (GuidHob);
if (Info->FeatureControl) {
Context->FeatureControlHighValue = (UINT32)RShiftU64 (
Info->FeatureControlValue,
32
);
Context->FeatureControlLowValue = (UINT32)Info->FeatureControlValue;
Context->FeatureControl = 1;
}
}
}
/**