From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3A38A209603DB for ; Fri, 25 May 2018 04:40:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9DDC401EF25; Fri, 25 May 2018 11:40:33 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-182.rdu2.redhat.com [10.10.120.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F948111AF2E; Fri, 25 May 2018 11:40:32 +0000 (UTC) To: =?UTF-8?Q?Marvin_H=c3=a4user?= References: From: Laszlo Ersek Cc: "edk2-devel@lists.01.org" , "eric.dong@intel.com" Message-ID: <2ef9271f-1bca-1d02-1ac8-fa845ff30ef7@redhat.com> Date: Fri, 25 May 2018 13:40:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 25 May 2018 11:40:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 25 May 2018 11:40:33 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: CpuS3DataDxe / DxeRegisterCpuFeaturesLib dependency. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 May 2018 11:40:37 -0000 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit On 05/25/18 12:54, Marvin H?user wrote: > Good day, > > While I was inspecting CpuS3DataDxe and the modules depending on its > PCD PcdCpuS3DataAddress, (Side remark: see e.g. the commit message on 92b87f1c8c0b, "OvmfPkg: build CpuS3DataDxe for -D SMM_REQUIRE", 2015-11-30.) > I noticed that DxeRegisterCpuFeaturesLib seemingly has an asserted > dependency on the PCD being ready when it its executed. I did neither > see a Depex entry, nor an event callback ensuring CpuS3DataDxe has > been loaded, neither exposed by CpuS3DataDxe, nor consumed by this > library. > https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c#L211 "DxeRegisterCpuFeaturesLib.inf" has a depex on "gEdkiiCpuFeaturesSetDoneGuid". No module in the open source edk2 tree produces this protocol GUID, thus I think this library instance is unusable without other, out-of-tree, modules. I assume that one of those modules satisfies the dependency somehow. Note that CpuS3DataDxe is a platform driver [1]; it is possible that the platform that includes DxeRegisterCpuFeaturesLib in a driver *also* includes such a CpuS3DataDxe variant that populates the PCD and then installs gEdkiiCpuFeaturesSetDoneGuid. [1] I suggest reviewing the message of commit bfec5efa56ca ("UefiCpuPkg/CpuS3DataDxe: Add module to initialize ACPI_CPU_DATA for S3", 2015-11-25). In fact, the series that added "DxeRegisterCpuFeaturesLib.inf" (with the depex mentioned above) *also* modified CpuS3DataDxe: see [2] and [3]. [2] 8b371e93f206 ("UefiCpuPkg/CpuS3DataDxe: Consume the existing PcdCpuS3DataAddress", 2017-03-22) [3] "[edk2] [PATCH 00/11] Add CPU features driver" https://bugzilla.tianocore.org/show_bug.cgi?id=421 http://mid.mail-archive.com/20170309083553.6016-1-jeff.fan@intel.com This suggests that there is an out-of-tree module that populates PcdCpuS3DataAddress before *both* CpuS3DataDxe and DxeRegisterCpuFeaturesLib access the PCD. For achieving this kind of ordering, it would be enough for a driver to first populate the PCD, and then install "gEfiMpServiceProtocolGuid", as both "DxeRegisterCpuFeaturesLib.inf" and "CpuS3DataDxe.inf" depend on that. > Is there anything I'm missing that ensures the execution of > CpuS3DataDxe prior to executing the dependent code? If not, should > there be a dummy protocol exposed? PiSmmCpuDxeSmm also retrieves this > PCD, however safely quits when it has not been set. However, this > could cause unexpected behavior when the PCD is set after this code > has been executed. I did not notice any dependency satisfaction > actions here either. The ordering between CpuS3DataDxe and PiSmmCpuDxeSmm is safe; it's orchestrated by Platform BDS. See commit 92b87f1c8c0b above. > Furthermore, not directly related to this dependency issue, the DXE > code obviously does not implement AllocateAcpiCpuData() entirely. More precisely, the DXE code expects AllocateAcpiCpuData() never to be called; i.e., when the common "RegisterCpuFeaturesLib.c" source file is executed in DXE, the expectation is that it never reaches the call to AllocateAcpiCpuData(). > Hence, the if-branch following its call, will either add another layer > of firing ASSERTs, or it will plainly do nothing. Maybe it could be > moved into the current AllocateAcpiCpuData() function and it be > renamed accordingly? > https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c#L526 Sorry, I don't understand your point -- CpuRegisterTableWriteWorker() is used in both PEI and DXE, and it's implemented for the general case. When it runs in DXE, the expectation is apparently that AllocateAcpiCpuData() will never be needed / reached, hence the ASSERT(FALSE) stub implementation for the latter, in "DxeRegisterCpuFeaturesLib.c". Oh wait, I think you mistyped your point. The "if" that you refer to does not *follow* the call to AllocateAcpiCpuData(). It *precedes* (guards) it. What the "if" follows is the PcdGet64() call, for PcdCpuS3DataAddress. In DXE, that PcdGet64() is expected to return a nonzero value, hence AllocateAcpiCpuData() is never called, and the assertions about the return value of AllocateAcpiCpuData() are irrelevant (unreached). Thanks Laszlo