From nobody Tue Apr 30 21:22:29 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+72714+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+72714+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1615549710; cv=none; d=zohomail.com; s=zohoarc; b=id9pmnv47HfVpICdBSIu+zFm6z9yWpyDWbdzWorOO2KSOse6S/toal4ZLWKsCLrVeyxpeYdgocmTqbyoZBHczJkeroEW3jhcOycdd2Wx3nsAApL7D3d+Z2l0MbjxygjOwa29PcOpQ8sOG91YdDbYI08Czv6PiYeoo4kJBjW7OCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615549710; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=/210NUYAdctnWErWepw8TjZ4gljBhL9w1HB13Qf8D/0=; b=j20EBo7FYE3D7qm1Lg3fmHp+2vPqTOzW3Pb48jeo0pfQ+s93G6FgqmFUD1cRUSXVZyBF9ORqNGsw3AOGTLtROaQiGho1u0rRghtws4iPNadRkj12wZbafzE5WRFntY/n8QRIJa1XZI1lSWa+LcCMRKEXT06DPEdX31UJH9u6NJA= 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+72714+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1615549710782423.7346112764668; Fri, 12 Mar 2021 03:48:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id I8ItYY1788612xbhQxpRaNmK; Fri, 12 Mar 2021 03:48:30 -0800 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web08.7011.1615549709446855494 for ; Fri, 12 Mar 2021 03:48:29 -0800 IronPort-SDR: ihKgXZCi56Nh9LFYo7v5/C95TRnknMop+f2SXm7Yk1nl2GaazGm+Zq0yzphv913M5JsmBaIHBz 8xbW1N7utGVQ== X-IronPort-AV: E=McAfee;i="6000,8403,9920"; a="168094663" X-IronPort-AV: E=Sophos;i="5.81,243,1610438400"; d="scan'208";a="168094663" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2021 03:48:13 -0800 IronPort-SDR: 4RlF6Uajpw0ms16gGTCYKm9rtAPueZruU3+8ShJHrqEv0KFwO51KOwwFr6NDmqMitrE0xysAGy PfJon1/uM2ag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,243,1610438400"; d="scan'208";a="603905389" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by fmsmga005.fm.intel.com with ESMTP; 12 Mar 2021 03:48:11 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP Date: Fri, 12 Mar 2021 19:48:04 +0800 Message-Id: <20210312114804.2-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: PrArFLYAzUkZ4zWxfE5Wy5Afx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615549710; bh=5pgmdK9ZnyqYhTeE2vAKFKiHfuXu21T+yp+ZlsRho/g=; h=Cc:Date:From:Reply-To:Subject:To; b=oBCFWjvt6Xn7I09RhCuw3wdtjRdjqmJk8CnyL/dv2qjkFeGFC7T6n+tdxQwHMSs00Ek QolAbOZIuTn/G3VW0b+oMpwHbnwgfDkfQcodEkAOMxVqDoOm63y3WI+CaMsnhkMs/n97K /iGMRhp/8w61d8P9RODAdwAPhPBhnJfOoCA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" MpInitLib contains a function MicrocodeDetect() which is called by all threads as an AP procedure. Today this function contains below code: if (CurrentRevision !=3D LatestRevision) { AcquireSpinLock(&CpuMpData->MpLock); DEBUG (( EFI_D_ERROR, "Updated microcode signature [0x%08x] does not match \ loaded microcode signature [0x%08x]\n", CurrentRevision, LatestRevision )); ReleaseSpinLock(&CpuMpData->MpLock); } When the if-check is passed, the code may call into PEI services: 1. AcquireSpinLock When the PcdSpinTimeout is not 0, TimerLib GetPerformanceCounterProperties() is called. And some of the TimerLib implementations would get the information cached in HOB. But AP procedure cannot call PEI services to retrieve the HOB list. 2. DEBUG Certain DebugLib relies on ReportStatusCode services and the ReportStatusCode PPI is retrieved through the PEI services. DebugLibSerialPort should be used. But when SerialPortLib is implemented to depend on PEI services, even using DebugLibSerialPort can still cause AP calls PEI services resulting hang. It causes a lot of debugging effort on the platform side. There are 2 options to fix the problem: 1. make sure platform DSC chooses the proper DebugLib and set the PcdSpinTimeout to 0. So that AcquireSpinLock and DEBUG don't call PEI services. 2. remove the AcquireSpinLock and DEBUG call from the procedure. Option #2 is preferred because it's not practical to ask every platform DSC to be written properly. Following option #2, there are two sub-options: 2.A. Just remove the if-check. 2.B. Capture the CurrentRevision and ExpectedRevision in the memory for each AP and print them together from BSP. The patch follows option 2.B. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar Acked-by: Laszlo Ersek Reviewed-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 11 +---------- UefiCpuPkg/Library/MpInitLib/MpLib.c | 9 +++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 15629591e2..297c2abcd1 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -315,17 +315,8 @@ Done: MSR_IA32_BIOS_UPDT_TRIG, (UINT64) (UINTN) MicrocodeData ); - // - // Get and check new microcode signature - // - CurrentRevision =3D GetCurrentMicrocodeSignature (); - if (CurrentRevision !=3D LatestRevision) { - AcquireSpinLock(&CpuMpData->MpLock); - DEBUG ((EFI_D_ERROR, "Updated microcode signature [0x%08x] does not = match \ - loaded microcode signature [0x%08x]\n", CurrentRevision, L= atestRevision)); - ReleaseSpinLock(&CpuMpData->MpLock); - } } + CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision =3D GetCurrentMicr= ocodeSignature (); } =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 5040053dad..e4baeff894 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1947,6 +1947,7 @@ MpInitLibInitialize ( UINTN ApResetVectorSize; UINTN BackupBufferAddr; UINTN ApIdtBase; + UINT32 ExpectedMicrocodeRevision; =20 OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); if (OldCpuMpData =3D=3D NULL) { @@ -2131,6 +2132,14 @@ MpInitLibInitialize ( CpuMpData->InitFlag =3D ApInitDone; } for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + 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, ExpectedMicroc= odeRevision + )); SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); } } diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 0bd60388b1..66f9eb2304 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -144,6 +144,7 @@ typedef struct { UINT32 ProcessorSignature; UINT8 PlatformId; UINT64 MicrocodeEntryAddr; + UINT32 MicrocodeRevision; } CPU_AP_DATA; =20 // --=20 2.27.0.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 (#72714): https://edk2.groups.io/g/devel/message/72714 Mute This Topic: https://groups.io/mt/81276903/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-