From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 67A1620886F46 for ; Sun, 17 Feb 2019 21:58:50 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Feb 2019 21:58:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,383,1544515200"; d="scan'208";a="319888084" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga006.fm.intel.com with ESMTP; 17 Feb 2019 21:58:49 -0800 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 17 Feb 2019 21:58:49 -0800 Received: from shsmsx107.ccr.corp.intel.com (10.239.4.96) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 17 Feb 2019 21:58:48 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.207]) by SHSMSX107.ccr.corp.intel.com ([169.254.9.162]) with mapi id 14.03.0415.000; Mon, 18 Feb 2019 13:58:47 +0800 From: "Yao, Jiewen" To: "Chen, Chen A" , "edk2-devel@lists.01.org" CC: "Dong, Eric" Thread-Topic: [edk2] [PATCH] UefiCpuPkg/Microcode: Fix incorrect checksum issue for extended table Thread-Index: AQHUx05ciM5noKUD8k6NjbQxkAMr46XlDx9A Date: Mon, 18 Feb 2019 05:58:47 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503F512B22@shsmsx102.ccr.corp.intel.com> References: <20190218055330.13448-1-chen.a.chen@intel.com> In-Reply-To: <20190218055330.13448-1-chen.a.chen@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjc2ZWY1YWYtMjA2NC00NDkzLWIwMDgtZTM0YmE1MWVkMWM3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiQ3dGMU5kbVQxeXZtUUR5Y2RCRHBZUkxJYmFBeHg1U0FTYWM4dnFtc0txc3FkV2tVQmxlTTB2VHJXdG00alRsbiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] UefiCpuPkg/Microcode: Fix incorrect checksum issue for extended table X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Feb 2019 05:58:50 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi ChenChen Thanks! Do you think we also need fix IntelSiliconPkg\Feature\Capsule\MicrocodeUpda= teDxe? Thank you Yao Jiewen > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Chen A Chen > Sent: Monday, February 18, 2019 1:54 PM > To: edk2-devel@lists.01.org > Cc: Dong, Eric > Subject: [edk2] [PATCH] UefiCpuPkg/Microcode: Fix incorrect checksum > issue for extended table >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1020 >=20 > The following Microcode payload format is define in SDM spec. > Payload: > |MicrocodeHeader|MicrocodeBinary|ExtendedHeader|ExtendedTable|. > When we verify the CheckSum32 with ExtendedTable, we should use the > fields > of ExtendedTable to replace corresponding fields in MicrocodeHeader, > and then calculate the CheckSum32 with > MicrocodeHeader+MicrocodeBinary. > This patch already verified on ICL platform. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chen A Chen > Cc: Ray Ni > Cc: Eric Dong > --- > UefiCpuPkg/Library/MpInitLib/Microcode.c | 38 > ++++++++++++++++++++++++-------- > 1 file changed, 29 insertions(+), 9 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c > b/UefiCpuPkg/Library/MpInitLib/Microcode.c > index d84344c6f5..38880cdbec 100644 > --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c > +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c > @@ -57,6 +57,7 @@ MicrocodeDetect ( > UINT32 LatestRevision; > UINTN TotalSize; > UINT32 CheckSum32; > + UINT32 > InCompleteCheckSum32; > BOOLEAN CorrectMicrocode; > VOID *MicrocodeData; > MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr; > @@ -121,6 +122,26 @@ MicrocodeDetect ( > MicrocodeData =3D NULL; > MicrocodeEnd =3D (UINTN) (CpuMpData->MicrocodePatchAddress + > CpuMpData->MicrocodePatchRegionSize); > MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (UINTN) > CpuMpData->MicrocodePatchAddress; > + > + // > + // To avoid double calculate checksum32 value. > + // Save the CheckSum32 of the common parts in advance. > + // > + if (MicrocodeEntryPoint->DataSize =3D=3D 0) { > + InCompleteCheckSum32 =3D CalculateSum32 ( > + (UINT32 *) MicrocodeEntryPoint, > + sizeof (CPU_MICROCODE_HEADER) + > 2000 > + ); > + } else { > + InCompleteCheckSum32 =3D CalculateSum32 ( > + (UINT32 *) MicrocodeEntryPoint, > + sizeof (CPU_MICROCODE_HEADER) + > MicrocodeEntryPoint->DataSize > + ); > + } > + InCompleteCheckSum32 -=3D > MicrocodeEntryPoint->ProcessorSignature.Uint32; > + InCompleteCheckSum32 -=3D MicrocodeEntryPoint->ProcessorFlags; > + InCompleteCheckSum32 -=3D MicrocodeEntryPoint->Checksum; > + > do { > // > // Check if the microcode is for the Cpu and the version is newer > @@ -137,14 +158,10 @@ MicrocodeDetect ( > MicrocodeEntryPoint->UpdateRevision > LatestRevision && > (MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId)) > ) { > - if (MicrocodeEntryPoint->DataSize =3D=3D 0) { > - CheckSum32 =3D CalculateSum32 ((UINT32 *) > MicrocodeEntryPoint, 2048); > - } else { > - CheckSum32 =3D CalculateSum32 ( > - (UINT32 *) MicrocodeEntryPoint, > - MicrocodeEntryPoint->DataSize + sizeof > (CPU_MICROCODE_HEADER) > - ); > - } > + CheckSum32 =3D InCompleteCheckSum32; > + CheckSum32 +=3D > MicrocodeEntryPoint->ProcessorSignature.Uint32; > + CheckSum32 +=3D MicrocodeEntryPoint->ProcessorFlags; > + CheckSum32 +=3D MicrocodeEntryPoint->Checksum; > if (CheckSum32 =3D=3D 0) { > CorrectMicrocode =3D TRUE; > ProcessorFlags =3D MicrocodeEntryPoint->ProcessorFlags; > @@ -171,7 +188,10 @@ MicrocodeDetect ( > ExtendedTableCount =3D > ExtendedTableHeader->ExtendedSignatureCount; > ExtendedTable =3D > (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTableHeader + 1); > for (Index =3D 0; Index < ExtendedTableCount; Index ++) { > - CheckSum32 =3D CalculateSum32 ((UINT32 *) > ExtendedTable, sizeof(CPU_MICROCODE_EXTENDED_TABLE)); > + CheckSum32 =3D InCompleteCheckSum32; > + CheckSum32 +=3D > ExtendedTable->ProcessorSignature.Uint32; > + CheckSum32 +=3D ExtendedTable->ProcessorFlag; > + CheckSum32 +=3D ExtendedTable->Checksum; > if (CheckSum32 =3D=3D 0) { > // > // Verify Header > -- > 2.16.2.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel