From nobody Thu May 9 22:46:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111687+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111687+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700794604; cv=none; d=zohomail.com; s=zohoarc; b=hAwmbTer4ttP1xVqKHZuNvUzX+X9KjK73JsVA0DAGHBCzYW/KJH8pGjmBJE1tx6KTGIJbyREp7+BLtEempaxMtvC2618vb/tkN+W+gjiaOeFw4OFpxvks/RyIclvpYW8sWtYr/BAH9Nw/YH6D8l4zDFcid9HpnF3uWOBZNQlgCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700794604; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=0Hx3vCWN1bYV+lc6JF83oMECo4MpSFdDSfU2u7lj+Tk=; b=nJzO5Le3EUI4o5Pd8c2YLqRhT8rogGKUkcxleGQiAVTTL2oXtjt4UstCrsONOW3yUMDwLhXUat4s7AZkeGNYM79bsyww+VTjDU+HauihT63FFRFM0pRul4RCb1+Y8baCrD50RPtwt+e2wttMqorJpJxxAlT3djnHy7TqLsGYBVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111687+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 17007946040451012.5118785184854; Thu, 23 Nov 2023 18:56:44 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=LphvU15hfpNmLWCEqaFWZzJVOtbGVtFfIu5AvMHeCZk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1700794603; v=1; b=Mf1roj9N7YpiHo11kPbjFR4cKMV37gfykEHVd7fIRpLkF9dyy5gmjQGGkbDs5IXd/R9BrJdi FNAH8Uh+qb3eDUgYuaUf/im41WyJp8g9cZqhAUx9PVbHiyU1Ohf+54p1TDBxTKSrn2xA7WjTgML NV3d8T7m/SMhpKIPL7xSqkjM= X-Received: by 127.0.0.2 with SMTP id 4uNUYY1788612x0G8lxHGVuK; Thu, 23 Nov 2023 18:56:43 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.128508.1700794600506959702 for ; Thu, 23 Nov 2023 18:56:43 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="377386849" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="377386849" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 18:56:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="802087268" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="802087268" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga001.jf.intel.com with ESMTP; 23 Nov 2023 18:56:40 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: xieyuanh , Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky , Laszlo Ersek Subject: [edk2-devel] [Patch V4 1/3] UefiCpuPkg/MpInitLib: Eliminate redundant microcode loading in DXE. Date: Fri, 24 Nov 2023 10:56:33 +0800 Message-Id: <20231124025635.3629-2-yuanhao.xie@intel.com> In-Reply-To: <20231124025635.3629-1-yuanhao.xie@intel.com> References: <20231124025635.3629-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: SyvGDUAOn2YPZWARONZNu3OTx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700794604373100005 Content-Type: text/plain; charset="utf-8" The DXE stage's Microcode loading process has been elimincated by: 1. Let ShadowMicrocodeUpdatePatch and MicrocodeDetect for BSP performed only during the PEI phase. DXE skip those actions. 2. BSP in DXE WakeUpAp only for synchronizing MTRR settings, not loading microcode. Synchronizing the MTRRs setting to the APs is always essential. The modification of the MTRRs on the BSP may happens during timing in the early DXE phase, while the CpuMp PPI service and the CpuMp Protocol both not available. Cc: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Tom Lendacky Cc: Laszlo Ersek Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 46 ----------------------------= ------------------ UefiCpuPkg/Library/MpInitLib/MpLib.c | 39 ++++++++++++++++++++++++----= ----------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 21 --------------------- 3 files changed, 24 insertions(+), 82 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 11720560af..8faa93024d 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -338,49 +338,3 @@ ShadowMicrocodeUpdatePatch ( ShadowMicrocodePatchByPcd (CpuMpData); } } - -/** - Get the cached microcode patch base address and size from the microcode = patch - information cache HOB. - - @param[out] Address Base address of the microcode patches data. - It will be updated if the microcode patch - information cache HOB is found. - @param[out] RegionSize Size of the microcode patches data. - It will be updated if the microcode patch - information cache HOB is found. - - @retval TRUE The microcode patch information cache HOB is found. - @retval FALSE The microcode patch information cache HOB is not found. - -**/ -BOOLEAN -GetMicrocodePatchInfoFromHob ( - UINT64 *Address, - UINT64 *RegionSize - ) -{ - EFI_HOB_GUID_TYPE *GuidHob; - EDKII_MICROCODE_PATCH_HOB *MicrocodePathHob; - - GuidHob =3D GetFirstGuidHob (&gEdkiiMicrocodePatchHobGuid); - if (GuidHob =3D=3D NULL) { - DEBUG ((DEBUG_INFO, "%a: Microcode patch cache HOB is not found.\n", _= _func__)); - return FALSE; - } - - MicrocodePathHob =3D GET_GUID_HOB_DATA (GuidHob); - - *Address =3D MicrocodePathHob->MicrocodePatchAddress; - *RegionSize =3D MicrocodePathHob->MicrocodePatchRegionSize; - - DEBUG (( - DEBUG_INFO, - "%a: MicrocodeBase =3D 0x%lx, MicrocodeSize =3D 0x%lx\n", - __func__, - *Address, - *RegionSize - )); - - return TRUE; -} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9a6ec5db5c..1fd6440a53 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -451,12 +451,20 @@ ApInitializeSync ( CpuMpData =3D (CPU_MP_DATA *)Buffer; Status =3D GetProcessorNumber (CpuMpData, &ProcessorNumber); ASSERT_EFI_ERROR (Status); + ASSERT (CpuMpData->InitFlag =3D=3D ApInitReconfig || CpuMpData->InitFlag= =3D=3D ApInitDone); + if (CpuMpData->InitFlag !=3D ApInitReconfig) { + // + // Load microcode on AP for PEI phase. + // During the DXE phase, it cannot omitted. + // + MicrocodeDetect (CpuMpData, ProcessorNumber); + } + // - // Load microcode on AP - // - MicrocodeDetect (CpuMpData, ProcessorNumber); - // - // Sync BSP's MTRR table to AP + // Synchronizing the MTRRs setting to the APs is always essential. + // The modification of the MTRRs on the BSP may happens during + // timing in the early DXE phase, while the CpuMp PPI service and + // the CpuMp Protocol are both not available. // MtrrSetAllMtrrs (&CpuMpData->MtrrTable); } @@ -2224,29 +2232,25 @@ MpInitLibInitialize ( } } =20 - if (!GetMicrocodePatchInfoFromHob ( - &CpuMpData->MicrocodePatchAddress, - &CpuMpData->MicrocodePatchRegionSize - )) - { + if (MpHandOff =3D=3D NULL) { // // The microcode patch information cache HOB does not exist, which mea= ns // the microcode patches data has not been loaded into memory yet // ShadowMicrocodeUpdatePatch (CpuMpData); + // + // Detect and apply Microcode on BSP + // + MicrocodeDetect (CpuMpData, CpuMpData->BspNumber); } =20 - // - // Detect and apply Microcode on BSP - // - MicrocodeDetect (CpuMpData, CpuMpData->BspNumber); // // Store BSP's MTRR setting // MtrrGetAllMtrrs (&CpuMpData->MtrrTable); =20 // - // Wakeup APs to do some AP initialize sync (Microcode & MTRR) + // Wakeup APs to do some AP initialize sync (MTRR and/or Microcode). // if (CpuMpData->CpuCount > 1) { if (MpHandOff !=3D NULL) { @@ -2258,6 +2262,11 @@ MpInitLibInitialize ( CpuMpData->InitFlag =3D ApInitReconfig; } =20 + // + // Wake up APs to perform AP initialization synchronization. + // 1. For the PEI stage, load microcode and synchronize MTRRs, + // 2. For the DXE phase, only synchronize MTRRs. + // WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE); // // Wait for all APs finished initialization diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 763db4963d..01b5b9c113 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -744,27 +744,6 @@ ShadowMicrocodeUpdatePatch ( IN OUT CPU_MP_DATA *CpuMpData ); =20 -/** - Get the cached microcode patch base address and size from the microcode = patch - information cache HOB. - - @param[out] Address Base address of the microcode patches data. - It will be updated if the microcode patch - information cache HOB is found. - @param[out] RegionSize Size of the microcode patches data. - It will be updated if the microcode patch - information cache HOB is found. - - @retval TRUE The microcode patch information cache HOB is found. - @retval FALSE The microcode patch information cache HOB is not found. - -**/ -BOOLEAN -GetMicrocodePatchInfoFromHob ( - UINT64 *Address, - UINT64 *RegionSize - ); - /** Detect whether Mwait-monitor feature is supported. =20 --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111687): https://edk2.groups.io/g/devel/message/111687 Mute This Topic: https://groups.io/mt/102775771/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 22:46:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111688+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111688+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700794606; cv=none; d=zohomail.com; s=zohoarc; b=RdFaB28FGnCgXJ+EgI20U6wmhOO+MZJMinyHam/tMYAep+fqyS/7vz5Ff7sMaTVTaUntvHjHlQTE7WWLbxHIN0N79TX3K9LDr3/eoLiT6xjLTM30mybzEBk8yvwSSRy9wfpWuKHw5k1Gl3QWdn7O3GQgKxCvH72DBGuAWxqKOGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700794606; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=iL1dueVjdmoWZ6DWF7kkxaUzJUQZmqnXbft+j2MtF+c=; b=P9G400pzZInUOFNzdayfeC41mWKmyA2UDTFsLaq1iQ+lXwNWzLU9QHOt5X5CHRRBiMkGOGpnyCmhSLn8qkR4vaLTm4Omaztm9iGg6a18L7kBx8k3xPLo+JyHXhKFdDrdqceYzBUJ8+qN1FJ33Al7Ohbo6dBx5dYR5sI5SYWV+8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111688+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1700794606810318.35925733766396; Thu, 23 Nov 2023 18:56:46 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=VPKupKazEwgKrztgMWZ2zL6o6NzsW9q0OJoBMLM0OOU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1700794606; v=1; b=IIfykLnMPrUNNojqoTE0oJz2Y4+ihaqsDzSTeMAIp1W1f9V+UT5FzbgG1evcWdwLm2KjdoJF G/qNSRq+TSNXvFwYlrT/4AuuFG6CIjEWzWES9GUiSbtUKMl5HLpjTeDgNnVxB9EY046W5n0AHzr 0wFABtk+htRH/6xvkxIDZbSI= X-Received: by 127.0.0.2 with SMTP id H0qaYY1788612x6dHXrz8eNN; Thu, 23 Nov 2023 18:56:46 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.128508.1700794600506959702 for ; Thu, 23 Nov 2023 18:56:46 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="377386860" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="377386860" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 18:56:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="802087283" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="802087283" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga001.jf.intel.com with ESMTP; 23 Nov 2023 18:56:43 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: xieyuanh , Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky , Laszlo Ersek Subject: [edk2-devel] [Patch V4 2/3] UefiCpuPkg/MpInitLib: Store MTRRs settings only when CpuCount>1 Date: Fri, 24 Nov 2023 10:56:34 +0800 Message-Id: <20231124025635.3629-3-yuanhao.xie@intel.com> In-Reply-To: <20231124025635.3629-1-yuanhao.xie@intel.com> References: <20231124025635.3629-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: vrqhGaHGI3eOW06Epj8qQHEfx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700794608275100011 Content-Type: text/plain; charset="utf-8" Store BSP's MTRR setting only when CpuCount>1. Reviewed-by: Ray Ni Cc: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Tom Lendacky Cc: Laszlo Ersek Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 1fd6440a53..4dac931fa5 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -2244,15 +2244,14 @@ MpInitLibInitialize ( MicrocodeDetect (CpuMpData, CpuMpData->BspNumber); } =20 - // - // Store BSP's MTRR setting - // - MtrrGetAllMtrrs (&CpuMpData->MtrrTable); - // // Wakeup APs to do some AP initialize sync (MTRR and/or Microcode). // if (CpuMpData->CpuCount > 1) { + // + // Store BSP's MTRR setting + // + MtrrGetAllMtrrs (&CpuMpData->MtrrTable); if (MpHandOff !=3D NULL) { // // Only needs to use this flag for DXE phase to update the wake up --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111688): https://edk2.groups.io/g/devel/message/111688 Mute This Topic: https://groups.io/mt/102775772/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 22:46:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111689+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111689+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700794610; cv=none; d=zohomail.com; s=zohoarc; b=IhozHt8bGYOUr+40OOSvlHMvzLIZk6hHL3V2F1yoW7zSkPKhhEuE5vvdRFRrjzq2xS60XHuesbctQJ0rkwyELWuNKDB2ZP9kX0Z94Gj3SY2mMd7rNcsEBDzogu5Ln6jh5aQ8e+WyQsmTVe3KP9If2vHmQ/QfWeCIzHJgbkw8o10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700794610; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=eRq61U45zXiKA2lgGbKlvc/wpeuq/yVnkc9F5gDs9w0=; b=A06T99ev9yPLQkHxE0NScNGXDH9/wLfb/Xv68crfycTQ/7WseFh57YoJ7xeZg99hD6WC/LjH9sJ9ZDfQ8hysz8lhqQOw3p0e/tpc4uApY1uAa/bi1vtYgK96hhhRzsyLKncjZNuqPFjIEoVvlTS2j/5P5UbM6vTe9Fstwt5rVQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111689+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1700794610965149.89305093040662; Thu, 23 Nov 2023 18:56:50 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Tg7j1DkHSVKKktdJWuaRzU6pAN3A9sVBEgfjKhrfB70=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1700794610; v=1; b=n2U97ZgOIBh4gh2EfdI/59xUwHvVnXWCgM8rL+LCYWpk3xhZVnhIeVqcZ0Xby0/ZqGjPI2xZ FR7wr9D8WBeN4h4nRHhNUno9TzdukplYPmJD+F3pTSc8PM071HD40dwk9CCT++huF+tfjs4aVbD 0nGvu71IV9mPTOVX7xj2ygtY= X-Received: by 127.0.0.2 with SMTP id srCjYY1788612xGn7Mmlwdb5; Thu, 23 Nov 2023 18:56:50 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.128508.1700794600506959702 for ; Thu, 23 Nov 2023 18:56:50 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="377386883" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="377386883" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 18:56:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="802087297" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="802087297" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga001.jf.intel.com with ESMTP; 23 Nov 2023 18:56:47 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: xieyuanh , Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky , Laszlo Ersek Subject: [edk2-devel] [Patch V4 3/3] UefiCpuPkg/MpInitLib: Extract Dump Microcode Revision as function. Date: Fri, 24 Nov 2023 10:56:35 +0800 Message-Id: <20231124025635.3629-4-yuanhao.xie@intel.com> In-Reply-To: <20231124025635.3629-1-yuanhao.xie@intel.com> References: <20231124025635.3629-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: pZ9o7GFUQQazBoGovNi3AxWAx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700794612319100003 Content-Type: text/plain; charset="utf-8" There is no functional changes, only extract DumpMicrocodeRevision since only in PEI BSP will detect, apply microcode, and APs will sync microcode. Cc: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Tom Lendacky Cc: Laszlo Ersek Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 39 ++++++++++++++++++++++++++++= +++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 33 ++++------------------------= ----- UefiCpuPkg/Library/MpInitLib/MpLib.h | 10 ++++++++++ 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 8faa93024d..947caee97a 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -321,6 +321,45 @@ OnExit: FreePages (MicrocodeCpuIds, EFI_SIZE_TO_PAGES (CpuMpData->CpuCount * siz= eof (EDKII_PEI_MICROCODE_CPU_ID))); } =20 +/** + Dump the microcode revision for each core. + + @param[in] CpuMpData Pointer to CPU MP Data + **/ +VOID +DumpMicrocodeRevision ( + IN CPU_MP_DATA *CpuMpData + ) +{ + UINT32 ThreadId; + UINT32 ExpectedMicrocodeRevision; + CPU_INFO_IN_HOB *CpuInfoInHob; + UINTN Index; + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + GetProcessorLocationByApicId (CpuInfoInHob[Index].InitialApicId, NULL,= NULL, &ThreadId); + if (ThreadId =3D=3D 0) { + // + // MicrocodeDetect() loads microcode in first thread of each core, s= o, + // CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized only = for first thread of each core. + // + ExpectedMicrocodeRevision =3D 0; + if (CpuMpData->CpuData[Index].MicrocodeEntryAddr !=3D 0) { + ExpectedMicrocodeRevision =3D ((CPU_MICROCODE_HEADER *)(UINTN)CpuM= pData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision; + } + + DEBUG (( + DEBUG_INFO, + "CPU[%04d]: Microcode revision =3D %08x, expected =3D %08x\n", + Index, + CpuMpData->CpuData[Index].MicrocodeRevision, + ExpectedMicrocodeRevision + )); + } + } +} + /** Shadow the required microcode patches data into memory. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 4dac931fa5..785042a8d7 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -2283,37 +2283,12 @@ MpInitLibInitialize ( } } =20 - // - // Dump the microcode revision for each core. - // - DEBUG_CODE_BEGIN (); - UINT32 ThreadId; - UINT32 ExpectedMicrocodeRevision; - - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; - for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { - GetProcessorLocationByApicId (CpuInfoInHob[Index].InitialApicId, NULL,= NULL, &ThreadId); - if (ThreadId =3D=3D 0) { - // - // MicrocodeDetect() loads microcode in first thread of each core, s= o, - // CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized only = for first thread of each core. - // - ExpectedMicrocodeRevision =3D 0; - if (CpuMpData->CpuData[Index].MicrocodeEntryAddr !=3D 0) { - ExpectedMicrocodeRevision =3D ((CPU_MICROCODE_HEADER *)(UINTN)CpuM= pData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision; - } - - DEBUG (( - DEBUG_INFO, - "CPU[%04d]: Microcode revision =3D %08x, expected =3D %08x\n", - Index, - CpuMpData->CpuData[Index].MicrocodeRevision, - ExpectedMicrocodeRevision - )); - } + if (MpHandOff =3D=3D NULL) { + DEBUG_CODE ( + DumpMicrocodeRevision (CpuMpData); + ); } =20 - DEBUG_CODE_END (); // // Initialize global data for MP support // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 01b5b9c113..fd302e6845 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -734,6 +734,16 @@ MicrocodeDetect ( IN UINTN ProcessorNumber ); =20 +/** + Dump the microcode revision for each core. + + @param[in] CpuMpData Pointer to CPU MP Data + **/ +VOID +DumpMicrocodeRevision ( + IN CPU_MP_DATA *CpuMpData + ); + /** Shadow the required microcode patches data into memory. =20 --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111689): https://edk2.groups.io/g/devel/message/111689 Mute This Topic: https://groups.io/mt/102775773/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-