From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: More than 10 MX records returned) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 BE85E2214E324 for ; Mon, 11 Dec 2017 05:18:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2017 05:23:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,391,1508828400"; d="scan'208";a="183224629" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga005.jf.intel.com with ESMTP; 11 Dec 2017 05:23:08 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 11 Dec 2017 05:23:07 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.175]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.152]) with mapi id 14.03.0319.002; Mon, 11 Dec 2017 21:23:06 +0800 From: "Yao, Jiewen" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Dong, Eric" Thread-Topic: [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume Thread-Index: AQHTclseuUVmcSM2AU2Sp/YnKzKwPaM+IYmw Date: Mon, 11 Dec 2017 13:23:05 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AA4263E@shsmsx102.ccr.corp.intel.com> References: <1512981360-15104-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1512981360-15104-1-git-send-email-star.zeng@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDJmMWZiYzQtNzZiMC00NzhjLTkyM2ItYmEzNTRkN2IwZDA2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJrSEpkMjY5bzFlaVRjODZtRDVDRktEVDhMTGZMdUx6a1owOE1jYnVQN01yY1cyczEyRGZiazNBdm1UZitqREZlIn0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2017 13:18:31 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen.yao@intel.com > -----Original Message----- > From: Zeng, Star > Sent: Monday, December 11, 2017 4:36 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Yao, Jiewen ; > Dong, Eric > Subject: [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume > during S3 resume >=20 > Otherwise, it may be triggered wrongly by other code in OS. >=20 > This patch is to use S3 entry callback to determine if it will be > during S3 resume, and check it in SmmReadyToBootHandler(). >=20 > Cc: Jiewen Yao > Cc: Eric Dong > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng > --- > MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 79 > +++++++++++++++++++++++++++++-- > MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 1 + > MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf | 1 + > 3 files changed, 77 insertions(+), 4 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c > b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c > index 0b9c7958c75c..6d266933868d 100644 > --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c > +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c > @@ -72,6 +72,12 @@ EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst =3D { > BOOLEAN mInLegacyBoot =3D FALSE; >=20 > // > +// Flag to determine if it is during S3 resume. > +// It will be set in S3 entry callback and cleared at EndOfS3Resume. > +// > +BOOLEAN mDuringS3Resume =3D FALSE; > + > +// > // Table of SMI Handlers that are registered by the SMM Core when it is > initialized > // > SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] =3D { > @@ -213,6 +219,37 @@ SmmExitBootServicesHandler ( > } >=20 > /** > + Main entry point for an SMM handler dispatch or communicate-based > callback. > + > + @param[in] DispatchHandle The unique handle assigned to this > handler by SmiHandlerRegister(). > + @param[in] Context Points to an optional handler context > which was specified when the > + handler was registered. > + @param[in,out] CommBuffer A pointer to a collection of data in > memory that will > + be conveyed from a non-SMM > environment into an SMM environment. > + @param[in,out] CommBufferSize The size of the CommBuffer. > + > + @retval EFI_SUCCESS The interrupt was > handled and quiesced. No other handlers > + should still be called. > + @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has > been quiesced but other handlers should > + still be called. > + @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still > pending and other handlers should still > + be called. > + @retval EFI_INTERRUPT_PENDING The interrupt could not > be quiesced. > +**/ > +EFI_STATUS > +EFIAPI > +SmmS3EntryCallBack ( > + IN EFI_HANDLE DispatchHandle, > + IN CONST VOID *Context OPTIONAL, > + IN OUT VOID *CommBuffer OPTIONAL, > + IN OUT UINTN *CommBufferSize OPTIONAL > + ) > +{ > + mDuringS3Resume =3D TRUE; > + return EFI_SUCCESS; > +} > + > +/** > Software SMI handler that is called when an Ready To Boot event is sig= nalled. > Then the SMM Core also install SMM Ready To Boot protocol to notify SM= M > driver > that system enter ready to boot. > @@ -235,8 +272,11 @@ SmmReadyToBootHandler ( > IN OUT UINTN *CommBufferSize OPTIONAL > ) > { > - EFI_STATUS Status; > - EFI_HANDLE SmmHandle; > + EFI_STATUS Status; > + EFI_HANDLE SmmHandle; > + EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch; > + EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext; > + EFI_HANDLE S3SleepEntryHandle; >=20 > // > // Install SMM Ready To Boot protocol. > @@ -251,7 +291,31 @@ SmmReadyToBootHandler ( >=20 > SmiHandlerUnRegister (DispatchHandle); >=20 > - return Status; > + // > + // Locate SmmSxDispatch2 protocol. > + // > + Status =3D SmmLocateProtocol ( > + &gEfiSmmSxDispatch2ProtocolGuid, > + NULL, > + &SxDispatch > + ); > + if (!EFI_ERROR (Status)) { > + // > + // Register a S3 entry callback function to > + // determine if it will be during S3 resume. > + // > + EntryRegisterContext.Type =3D SxS3; > + EntryRegisterContext.Phase =3D SxEntry; > + Status =3D SxDispatch->Register ( > + SxDispatch, > + SmmS3EntryCallBack, > + &EntryRegisterContext, > + &S3SleepEntryHandle > + ); > + ASSERT_EFI_ERROR (Status); > + } > + > + return EFI_SUCCESS; > } >=20 > /** > @@ -409,7 +473,12 @@ SmmEndOfS3ResumeHandler ( > EFI_STATUS Status; > EFI_HANDLE SmmHandle; >=20 > - DEBUG ((EFI_D_INFO, "SmmEndOfS3ResumeHandler\n")); > + DEBUG ((DEBUG_INFO, "SmmEndOfS3ResumeHandler\n")); > + > + if (!mDuringS3Resume) { > + DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n")); > + return EFI_ACCESS_DENIED; > + } >=20 > // > // Install SMM EndOfS3Resume protocol > @@ -434,6 +503,8 @@ SmmEndOfS3ResumeHandler ( > ); > ASSERT_EFI_ERROR (Status); >=20 > + mDuringS3Resume =3D FALSE; > + > return Status; > } >=20 > diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h > b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h > index 2729a434d8f8..8c10d833e2ae 100644 > --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h > +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include >=20 > #include > #include > diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf > b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf > index de0037fe4a99..5c04e851f94b 100644 > --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf > +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf > @@ -92,6 +92,7 @@ [Protocols] > gEfiSmmUsbDispatch2ProtocolGuid ## > SOMETIMES_CONSUMES > gEfiSmmCpuProtocolGuid ## > SOMETIMES_CONSUMES > gEdkiiSmmMemoryAttributeProtocolGuid ## CONSUMES > + gEfiSmmSxDispatch2ProtocolGuid ## > SOMETIMES_CONSUMES >=20 > [Pcd] >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressSmmCodePageNumber > ## SOMETIMES_CONSUMES > -- > 2.7.0.windows.1