From nobody Tue May 7 22:15:19 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+72851+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+72851+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1615859534; cv=none; d=zohomail.com; s=zohoarc; b=ILf144uFK3G/XUk5py6lR6k76vTcLkxWT+WtSDj6LsR5+7MtxMrcNLqT1DU2Jjp35rl0MyywliaW6tCKnLj8HY2SvGxs/SAp4LBg6ILJTkK3vc4geiVAVAtjFpMChO75xIZ+4lWLZnnxiyXxHh+B8Pu6r7AHOzglIoLXqL7C9l8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615859534; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=IA5eXh8IcTf9GYM0V2gjA4BahG+4V83dgBoLkEnXE78=; b=O2np25uzdy9Quk+/Wqf/xZKeZ2qlpw5ADIDK9wiwUZ//vWT28NUq27aVwAWHEsBNu1oNXg/gw3QhuvEzL+UuME/BuqRmmDKFXTvEmBrfhAzEmvYB2TcXfakfPWWp7KbjWsKz6XrCWUnc/CDC3fzpLOnReFyS8cjI3xdYgxMDMEU= 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+72851+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 1615859534883945.0431043002558; Mon, 15 Mar 2021 18:52:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4RRaYY1788612xnlJON15tWr; Mon, 15 Mar 2021 18:52:14 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.2807.1615859534075385280 for ; Mon, 15 Mar 2021 18:52:14 -0700 IronPort-SDR: KWRoZEbKjJhoNUvODUzPOQIKr9qbvtZEyfBAJTbEtAOFWMDmJSn9IpuPzj0j+2jyHC2LYJ5shd heohWxmQDfiw== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="250548429" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="250548429" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2021 18:52:13 -0700 IronPort-SDR: sVg/1QhraGJOkj9tnFHcNcQZuNqNCQcCbcEu0FTz1YFPtNnPsr4r3X5jAFW/DTyw+KsLxB+ZBL Jxt3X2kd2g8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="601651057" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2021 18:52:11 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP Date: Tue, 16 Mar 2021 09:52:03 +0800 Message-Id: <20210316015203.1507-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: HOgJfqO0NsjJMe7fY090MHZZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615859534; bh=yzrlWm7fFiKSGsP0gNMoDudtbj2Ut96gQEYMSxSVIhE=; h=Cc:Date:From:Reply-To:Subject:To; b=paw4Fnsx1EKy+UfnbvM0dAEsEofHfh2sRG2lDPEM+WwzYGKtLKDYldx3TtJvCbmSXiE G/jbhwkGPJOu1W4KGRUyQZZQOFmpjKO7+mGYzB/5HkQU1dBHW8HmBBG+YaXIBbmHieGdO fHM0v158wSZQfRPews/v3VeFQBDuFM1wlJk= 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 | 25 ++++++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + 3 files changed, 27 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..3d945972a0 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -2135,6 +2135,31 @@ MpInitLibInitialize ( } } =20 + // + // Dump the microcode revision for each core. + // + DEBUG_CODE ( + 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, NUL= L, NULL, &ThreadId); + if (ThreadId =3D=3D 0) { + // + // MicrocodeDetect() loads microcode in first thread of each core,= so, + // CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized onl= y for first thread of each core. + // + ExpectedMicrocodeRevision =3D 0; + if (CpuMpData->CpuData[Index].MicrocodeEntryAddr !=3D 0) { + ExpectedMicrocodeRevision =3D ((CPU_MICROCODE_HEADER *)(UINTN)Cp= uMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision; + } + DEBUG (( + DEBUG_INFO, "CPU[%04d]: Microcode revision =3D %08x, expected = =3D %08x\n", + Index, CpuMpData->CpuData[Index].MicrocodeRevision, ExpectedMicr= ocodeRevision + )); + } + } + ); // // Initialize global data for MP support // 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 (#72851): https://edk2.groups.io/g/devel/message/72851 Mute This Topic: https://groups.io/mt/81367127/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-