From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web10.90164.1673623849597548955 for ; Fri, 13 Jan 2023 07:30:57 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=KRMdxT+2; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: jiaxin.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673623857; x=1705159857; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=HoydFztkHPuvlSBrgOJznPFDHnM1Isv5BIAfRG7Fe3k=; b=KRMdxT+2lukojP51BC9gVsDrXgC23KqZKhN0r6US1bK7Zl4o21QVwpIR 7q10orjl1rdJIFji2ft+Ux9ssN6dIPB2FGOiD1IsFI9IT9u3WlmsQndJq 6S8hutWXMFhK5MQUlDJ5spvyXnJd+T9jKxlnCOZWpmkpa/PXGAOyM0I4v uPT+qhBdpvoG3+XNBFHfJiwx2Rk5sF6hlaQ265If/MpIuPJHbEsRhMwCu xkAnZDTPfxTUbgLg6pYWYUL7Ptk1ro4AAbckkqzRuSY9RQoi3pM2ijTiy MVdRcwD0srURBgBJXsN2aBigRv1UsSFGOZNpTm9aFOK2KPw2ZItd0DVtY A==; X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="410251866" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="410251866" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2023 07:30:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="782182356" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="782182356" Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.79]) by orsmga004.jf.intel.com with ESMTP; 13 Jan 2023 07:30:55 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Zeng Star , Laszlo Ersek , Gerd Hoffmann , Rahul Kumar Subject: [PATCH v2 4/4] OvmfPkg/SmmCpuFeaturesLib: Skip to configure SMBASE Date: Fri, 13 Jan 2023 23:30:45 +0800 Message-Id: <20230113153045.13060-5-jiaxin.wu@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20230113153045.13060-1-jiaxin.wu@intel.com> References: <20230113153045.13060-1-jiaxin.wu@intel.com> 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 Cc: Ray Ni Cc: Zeng Star Cc: Laszlo Ersek Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 37 ++++++++++++++++------ .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 4 +++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 6693666d04..d2841af6a4 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -15,20 +15,28 @@ #include #include #include #include #include +#include #include #include #include #include +#include // // EFER register LMA bit // #define LMA BIT10 +// +// Indicate SmBase for each Processors has been relocated or not. If TRUE, +// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor(). +// +BOOLEAN mSmmCpuFeaturesSmmRelocated; + /** The constructor function @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @@ -41,10 +49,16 @@ EFIAPI SmmCpuFeaturesLibConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { + // + // If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded + // in the SmBase array. + // + mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL); + // // No need to program SMRRs on our virtual platform. // return EFI_SUCCESS; } @@ -83,20 +97,25 @@ SmmCpuFeaturesInitializeProcessor ( ) { QEMU_SMRAM_SAVE_STATE_MAP *CpuState; // - // Configure SMBASE. + // No need to configure SMBASE if SmBase relocation has been done. // - CpuState = (QEMU_SMRAM_SAVE_STATE_MAP *)(UINTN)( - SMM_DEFAULT_SMBASE + - SMRAM_SAVE_STATE_MAP_OFFSET - ); - if ((CpuState->x86.SMMRevId & 0xFFFF) == 0) { - CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; - } else { - CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + if (!mSmmCpuFeaturesSmmRelocated) { + // + // Configure SMBASE. + // + CpuState = (QEMU_SMRAM_SAVE_STATE_MAP *)(UINTN)( + SMM_DEFAULT_SMBASE + + SMRAM_SAVE_STATE_MAP_OFFSET + ); + if ((CpuState->x86.SMMRevId & 0xFFFF) == 0) { + CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + } else { + CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + } } // // No need to program SMRRs on our virtual platform. // diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index 8a426a4c10..6a281518f5 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -33,10 +33,14 @@ MemoryAllocationLib PcdLib SafeIntLib SmmServicesTableLib UefiBootServicesTableLib + HobLib + +[Guids] + gSmmBaseHobGuid ## CONSUMES [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase -- 2.16.2.windows.1