From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web10.5566.1579262640500717471 for ; Fri, 17 Jan 2020 04:04:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WOAK8yaK; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579262639; 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=PlXNOuAsMdyi2q0Hdt9aWlfL3wpee7Vtb24hWjJlJk0=; b=WOAK8yaKsxoy89GTiIvyMYpxHqR1mPmr15+YZDmK3b6SBCt5LTO3HDucQrADFnDZ7yCtdN J5H7qFW4iinRUi99OCIq90f+jpKZ3pp3NDv/epWwPnvyycb3lvuK0lc1x86DhLUhpZrTK9 XQynO9gf5S3qvkUueVakNS8Xm/5eCro= 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-286-HU2gBVFqO3GOjU9H6Ml7wg-1; Fri, 17 Jan 2020 07:03:55 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 709D018A8C92; Fri, 17 Jan 2020 12:03:54 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-211.ams2.redhat.com [10.36.116.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E8D05DA32; Fri, 17 Jan 2020 12:03:52 +0000 (UTC) Subject: Re: [PATCH v2] UefiCpuPkg/MpInitLib: Fix possible uninitialized 'InitFlag' field To: Hao A Wu , devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Michael D Kinney References: <20200117113525.4768-1-hao.a.wu@intel.com> From: "Laszlo Ersek" Message-ID: <557c365d-8288-6a65-065f-2d63e6954591@redhat.com> Date: Fri, 17 Jan 2020 13:03:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200117113525.4768-1-hao.a.wu@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: HU2gBVFqO3GOjU9H6Ml7wg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 01/17/20 12:35, Hao A Wu wrote: > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2474 > > Previous commit d786a17232: > UefiCpuPkg/MpInitLib: Reduce the size when loading microcode patches > > Removed the below assignments for the 'InitFlag' field of CPU_MP_DATA > structure in function MpInitLibInitialize() when APs are waken up to do > some initialize sync: > > CpuMpData->InitFlag = ApInitReconfig; > ... > CpuMpData->InitFlag = ApInitDone; > > The above commit mistakenly assumed the 'InitFlag' field will have a value > of 'ApInitDone' when the APs have been successfully waken up before. And > since there is no explicit comparision for the 'InitFlag' field with the > 'ApInitReconfig' value. The commit removed those assignments. > > However, under some cases (e.g. when variable OldCpuMpData is not NULL, > which means function CollectProcessorCount() will not be called), removing > the above assignments will left the 'InitFlag' field being uninitialized > with a value of 0, which is a invalid value for the type of 'InitFlag' > (AP_INIT_STATE). > > It may potentially cause the WakeUpAP() function to run some unnecessary > codes when the APs have been successfully waken up before: > > if (CpuMpData->WakeUpByInitSipiSipi || > CpuMpData->InitFlag != ApInitDone) { > ResetVectorRequired = TRUE; > AllocateResetVector (CpuMpData); > FillExchangeInfoData (CpuMpData); > SaveLocalApicTimerSetting (CpuMpData); > } > > This commit will address the above-mentioned issue. > > Test done: > * OS boot on a real platform with multi processors > > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Michael D Kinney > Signed-off-by: Hao A Wu > Reviewed-by: Ray Ni > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 6ec9b172b8..855d37ba3e 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1775,11 +1775,15 @@ MpInitLibInitialize ( > // Wakeup APs to do some AP initialize sync (Microcode & MTRR) > // > if (CpuMpData->CpuCount > 1) { > + CpuMpData->InitFlag = ApInitReconfig; > WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE); > + // > + // Wait for all APs finished initialization > + // > while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { > CpuPause (); > } > - > + CpuMpData->InitFlag = ApInitDone; > for (Index = 0; Index < CpuMpData->CpuCount; Index++) { > SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); > } > Acked-by: Laszlo Ersek