From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.86.1615580045070460882 for ; Fri, 12 Mar 2021 12:14:05 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bmPmIBwU; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615580044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QE+KTpdi1FviJ9hcDlkd8ZgpL9i0F+FvldKVWZe5JvQ=; b=bmPmIBwU764/YT03rD7AjqTUXu22HEfD6j7scaRKnIAzu24Tgp1+lk0q9KzNFiqZBtdcDA ekOx+9hKdnGCyJD5kEJuC1SHmnomrG9dwv+n1KOfA8Fspij8xQ34otE3qZq/HLEZzptek4 Iwl+/WTOyzZpQBSpyLpPZB6HVJczhtI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-V1Bk8CB_NaeKEIT2kkoyTQ-1; Fri, 12 Mar 2021 15:14:00 -0500 X-MC-Unique: V1Bk8CB_NaeKEIT2kkoyTQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1DD9192FDBD; Fri, 12 Mar 2021 20:13:57 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-80.ams2.redhat.com [10.36.112.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4A6E60BD8; Fri, 12 Mar 2021 20:13:56 +0000 (UTC) Subject: Re: [PATCH] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP To: Ray Ni , devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar References: <20210312114804.2-1-ray.ni@intel.com> From: "Laszlo Ersek" Message-ID: <576d72ed-de89-9f0e-4fee-c1a2cfd2b38e@redhat.com> Date: Fri, 12 Mar 2021 21:13:55 +0100 MIME-Version: 1.0 In-Reply-To: <20210312114804.2-1-ray.ni@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/12/21 12:48, Ray Ni wrote: > MpInitLib contains a function MicrocodeDetect() which is called by > all threads as an AP procedure. > Today this function contains below code: > > if (CurrentRevision != 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 > --- > 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 = GetCurrentMicrocodeSignature (); > - if (CurrentRevision != 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); > - } > } > + CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision = GetCurrentMicrocodeSignature (); > } > > /** > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/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; > > OldCpuMpData = GetCpuMpDataFromGuidedHob (); > if (OldCpuMpData == NULL) { > @@ -2131,6 +2132,14 @@ MpInitLibInitialize ( > CpuMpData->InitFlag = ApInitDone; > } > for (Index = 0; Index < CpuMpData->CpuCount; Index++) { > + ExpectedMicrocodeRevision = 0; > + if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) { > + ExpectedMicrocodeRevision = ((CPU_MICROCODE_HEADER *)(UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision; > + } > + DEBUG (( > + DEBUG_INFO, "CPU[%04d]: Microcode revision = %08x, expected = %08x\n", > + Index, CpuMpData->CpuData[Index].MicrocodeRevision, ExpectedMicrocodeRevision > + )); > SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); > } > } > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/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; > > // > Acked-by: Laszlo Ersek