From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web11.1725.1579250510521502358 for ; Fri, 17 Jan 2020 00:41:50 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gYCGj1GS; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579250509; 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=RAO7RJpwnkE40H7Q+uO9NbvT+XKhYhXPlarALDck0eE=; b=gYCGj1GSTLnqa3ATn++F5pO/28U4Y58/rgpIo2Y+UPwbWAW6DBrjAmhQu5Kg7yLlr0bYGb zGHDlcRCP7zlvy1HbNx/uDGKzIAL9n+MpniHAve2IPiIl9MvBQ8ulcNUwtReCfIKiJxY+x /yflOJhB1DpiO5y4VCciBn6PCWaNCO0= 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-329-o5buBgErNuSLDJ2CidbnWw-1; Fri, 17 Jan 2020 03:41:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E47D4107ACC4; Fri, 17 Jan 2020 08:41:44 +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 71BF35C1D8; Fri, 17 Jan 2020 08:41:43 +0000 (UTC) Subject: Re: [PATCH v1] UefiCpuPkg/MpInitLib: Fix possible uninitialized 'InitFlag' field To: Hao A Wu , devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Michael D Kinney References: <20200117065638.9176-1-hao.a.wu@intel.com> From: "Laszlo Ersek" Message-ID: <6e723520-b2ee-de9f-27f3-51d27f67f84e@redhat.com> Date: Fri, 17 Jan 2020 09:41:42 +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: <20200117065638.9176-1-hao.a.wu@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: o5buBgErNuSLDJ2CidbnWw-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 07:56, 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; > > Under some cases (e.g. when variable OldCpuMpData is not NULL, which means > function CollectProcessorCount() will not be called), this 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 > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 6ec9b172b8..17e19395f2 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1775,11 +1775,12 @@ 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); > while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { > CpuPause (); > } > - > + CpuMpData->InitFlag = ApInitDone; > for (Index = 0; Index < CpuMpData->CpuCount; Index++) { > SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); > } > It looks reasonable to me, but I was away while patch "UefiCpuPkg/MpInitLib: Reduce the size when loading microcode patches" was being reviewed, so I can't really say. Can you explain (in the commit message) *why* commit d786a17232 removed these InitFlag assignments? I've now read the commit message on d786a17232, and it's not obvious to me. Also, it would be nice to reinstate the following comment: // // Wait for all APs finish initialization // just before the "while" statement. Thanks Laszlo