From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Wed, 25 Sep 2019 11:57:34 -0700 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 060C0315C00D; Wed, 25 Sep 2019 18:57:34 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-25.rdu2.redhat.com [10.10.120.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D8275D721; Wed, 25 Sep 2019 18:57:32 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg: Enable/Disable S3BootScript dynamically. To: devel@edk2.groups.io, chasel.chiu@intel.com Cc: Hao A Wu , Eric Dong , Nate DeSimone , Liming Gao References: <20190925092135.16664-1-chasel.chiu@intel.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 25 Sep 2019 20:57:31 +0200 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: <20190925092135.16664-1-chasel.chiu@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 25 Sep 2019 18:57:34 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 09/25/19 11:21, Chiu, Chasel wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2212 > > In binary model the same binary may have to support both > S3 enabled and disabled scenarios, however not all DXE > drivers linking PiDxeS3BootScriptLib can return error to > invoke library DESTRUCTOR for releasing resource. Thanks, this sounds better. More comments: > To support this usage model below PCD is used to skip > S3BootScript functions when PCD set to FALSE: > gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable > > Test: Verified on internal platform and S3BootScript > functions can be skipped by PCD during boot time. > > Cc: Hao A Wu > Cc: Eric Dong > Cc: Nate DeSimone > Cc: Liming Gao > Cc: Laszlo Ersek > Signed-off-by: Chasel Chiu > --- > MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c | 13 ++++++++++++- > MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf | 4 +++- > 2 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c > index c116727531..c5353119f7 100644 > --- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c > +++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c > @@ -1,7 +1,7 @@ > /** @file > Save the S3 data to S3 boot script. > > - Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
> + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -124,6 +124,7 @@ VOID *mRegistrationSmmReadyToLock = NULL; > BOOLEAN mS3BootScriptTableAllocated = FALSE; > BOOLEAN mS3BootScriptTableSmmAllocated = FALSE; > EFI_SMM_SYSTEM_TABLE2 *mBootScriptSmst = NULL; > +BOOLEAN mAcpiS3Enable = TRUE; > > /** > This is an internal function to add a terminate node the entry, recalculate the table > @@ -436,6 +437,11 @@ S3BootScriptLibInitialize ( > BOOLEAN InSmm; > EFI_PHYSICAL_ADDRESS Buffer; > > + if (!PcdGetBool (PcdAcpiS3Enable)) { > + mAcpiS3Enable = FALSE; > + return RETURN_SUCCESS; > + } > + > S3TablePtr = (SCRIPT_TABLE_PRIVATE_DATA*)(UINTN)PcdGet64(PcdS3BootScriptTablePrivateDataPtr); > // > // The Boot script private data is not be initialized. create it (1) I think that, for future maintenance, it would help if we added a similar check (on mAcpiS3Enable) to S3BootScriptLibDeinitialize() as well. I understand that, right now, if the constructor is short-circuited, then the destructor will end up doing nothing. But I think it would make maintenance easier if the destructor were short-circuited explicitly as well. > @@ -810,6 +816,11 @@ S3BootScriptGetEntryAddAddress ( > { > UINT8* NewEntryPtr; > > + if (!mAcpiS3Enable) { > + DEBUG ((DEBUG_INFO, "Skip S3BootScript because ACPI S3 disabled.\n")); > + return NULL; > + } > + > if (mS3BootScriptTablePtr->SmmLocked) { > // > // We need check InSmm, because after SmmReadyToLock, only SMM driver is allowed to write boot script. (2) I would like to see the debug message updated: (2a) please log, as part of the message, with "%a", the "gEfiCallerBaseName" variable. A library instance can be linked into multiple modules, and knowing the module name is useful. (2b) I think we should add the debug message to the constructor function instead. Please see the message that we already have in the destructor. Mainly, a DEBUG_INFO message is too loud for a utility function that may be called several times. So, if we keep the message at DEBUG_INFO, it should be moved into the constructor. Conversely, if you want to keep the message in S3BootScriptGetEntryAddAddress(), then it should be downgraded to DEBUG_VERBOSE. > diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf b/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf > index 517ea69568..fa139b03ff 100644 > --- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf > +++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf > @@ -1,7 +1,7 @@ > ## @file > # DXE S3 boot script Library. > # > -# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> +# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -65,4 +65,6 @@ > ## SOMETIMES_PRODUCES > gEfiMdeModulePkgTokenSpaceGuid.PcdS3BootScriptTablePrivateSmmDataPtr > gEfiMdeModulePkgTokenSpaceGuid.PcdS3BootScriptRuntimeTableReservePageNumber ## CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable ## CONSUMES > + (3) Please do not add the superfluous empty line. Thanks Laszlo