From 43d696a3667a808dbe9117cf8131dbfa64dcf631 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 3 Jul 2025 20:34:03 +0200 Subject: [PATCH] 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 --- OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 4 ++++ OvmfPkg/CpuHotplugSmm/Smbase.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf index ebcc7e2ac6..0996968016 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf @@ -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 diff --git a/OvmfPkg/CpuHotplugSmm/Smbase.c b/OvmfPkg/CpuHotplugSmm/Smbase.c index 2fd3ffb0b0..433633df98 100644 --- a/OvmfPkg/CpuHotplugSmm/Smbase.c +++ b/OvmfPkg/CpuHotplugSmm/Smbase.c @@ -10,7 +10,9 @@ #include // CpuPause() #include // CopyMem() #include // DEBUG() +#include // GetFirstGuidHob() #include // SendInitSipiSipi() +#include // EFI_HOB_PLATFORM_INFO #include // InterlockedCompareExchange64() #include // 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; + } + } } /**