From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 952FF21AEB0C4 for ; Tue, 25 Jul 2017 19:50:40 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2017 19:52:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,413,1496127600"; d="scan'208";a="1199368895" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga002.fm.intel.com with ESMTP; 25 Jul 2017 19:52:36 -0700 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 25 Jul 2017 19:51:27 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 25 Jul 2017 19:51:26 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.116]) with mapi id 14.03.0319.002; Wed, 26 Jul 2017 10:51:24 +0800 From: "Yao, Jiewen" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: Baraneedharan Anbazhagan Thread-Topic: [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion for COMM buffer Thread-Index: AQHTAexIEdLxf7WTvkir9nNVhkW7WKJlcETQ Date: Wed, 26 Jul 2017 02:51:23 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A97F155@shsmsx102.ccr.corp.intel.com> References: <1500619221-300708-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1500619221-300708-1-git-send-email-star.zeng@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion for COMM buffer 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: Wed, 26 Jul 2017 02:50:40 -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: Friday, July 21, 2017 2:40 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Yao, Jiewen ; > Baraneedharan Anbazhagan > Subject: [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion > for COMM buffer >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D593 >=20 > Currently, SmmCommunciate fails in RestoreLockBox after > SmmReadyToLock since COMM buffer is in stack instead of > using SmmCommRegion by gEdkiiPiSmmCommunicationRegionTableGuid. >=20 > This patch is to get SmmCommRegion by > gEdkiiPiSmmCommunicationRegionTableGuid for COMM buffer >=20 > Cc: Jiewen Yao > Cc: Baraneedharan Anbazhagan > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Star Zeng > --- > .../Library/SmmLockBoxLib/SmmLockBoxDxeLib.c | 199 > +++++++++++++++------ > .../Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf | 6 +- > 2 files changed, 147 insertions(+), 58 deletions(-) >=20 > diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c > b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c > index 9659f014e937..b75f81e69e04 100644 > --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c > +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c > @@ -1,6 +1,6 @@ > /** @file >=20 > -Copyright (c) 2010, Intel Corporation. All rights reserved.
> +Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
>=20 > This program and the accompanying materials > are licensed and made available under the terms and conditions > @@ -20,11 +20,108 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > +#include > #include > #include > +#include >=20 > #include "SmmLockBoxLibPrivate.h" >=20 > +EFI_SMM_COMMUNICATION_PROTOCOL *mLockBoxSmmCommProtocol =3D > NULL; > +UINT8 *mLockBoxSmmCommBuffer =3D NULL; > + > +/** > + Get smm communication protocol for lockbox. > + > + @return Pointer to smm communication protocol, NULL if not found. > + > +**/ > +EFI_SMM_COMMUNICATION_PROTOCOL * > +LockBoxGetSmmCommProtocol ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + > + // > + // If the protocol has been got previously, return it. > + // > + if (mLockBoxSmmCommProtocol !=3D NULL) { > + return mLockBoxSmmCommProtocol; > + } > + > + Status =3D gBS->LocateProtocol ( > + &gEfiSmmCommunicationProtocolGuid, > + NULL, > + (VOID **)&mLockBoxSmmCommProtocol > + ); > + if (EFI_ERROR (Status)) { > + mLockBoxSmmCommProtocol =3D NULL; > + } > + return mLockBoxSmmCommProtocol; > +} > + > +/** > + Get smm communication buffer for lockbox. > + > + @return Pointer to smm communication buffer, NULL if not found. > + > +**/ > +UINT8 * > +LockBoxGetSmmCommBuffer ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + UINTN MinimalSizeNeeded; > + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE > *PiSmmCommunicationRegionTable; > + UINT32 Index; > + EFI_MEMORY_DESCRIPTOR *Entry; > + UINTN Size; > + > + // > + // If the buffer has been got previously, return it. > + // > + if (mLockBoxSmmCommBuffer !=3D NULL) { > + return mLockBoxSmmCommBuffer; > + } > + > + MinimalSizeNeeded =3D sizeof (EFI_GUID) + > + sizeof (UINTN) + > + MAX (sizeof > (EFI_SMM_LOCK_BOX_PARAMETER_SAVE), > + MAX (sizeof > (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES), > + MAX (sizeof > (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE), > + MAX (sizeof > (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE), > + sizeof > (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE))))); > + > + Status =3D EfiGetSystemConfigurationTable ( > + &gEdkiiPiSmmCommunicationRegionTableGuid, > + (VOID **) &PiSmmCommunicationRegionTable > + ); > + if (EFI_ERROR (Status)) { > + mLockBoxSmmCommBuffer =3D NULL; > + return mLockBoxSmmCommBuffer; > + } > + ASSERT (PiSmmCommunicationRegionTable !=3D NULL); > + Entry =3D (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + > 1); > + Size =3D 0; > + for (Index =3D 0; Index < PiSmmCommunicationRegionTable->NumberOfEntri= es; > Index++) { > + if (Entry->Type =3D=3D EfiConventionalMemory) { > + Size =3D EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages); > + if (Size >=3D MinimalSizeNeeded) { > + break; > + } > + } > + Entry =3D (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + > PiSmmCommunicationRegionTable->DescriptorSize); > + } > + if (Index >=3D PiSmmCommunicationRegionTable->NumberOfEntries) { > + mLockBoxSmmCommBuffer =3D NULL; > + } else { > + mLockBoxSmmCommBuffer =3D (UINT8 *) (UINTN) Entry->PhysicalStart; > + } > + return mLockBoxSmmCommBuffer; > +} > + > /** > This function will save confidential information to lockbox. >=20 > @@ -52,7 +149,8 @@ SaveLockBox ( > EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; > EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave; > EFI_SMM_COMMUNICATE_HEADER *CommHeader; > - UINT8 CommBuffer[sizeof(EFI_GUID) + > sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; > + UINT8 TempCommBuffer[sizeof(EFI_GUID) + > sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; > + UINT8 *CommBuffer; > UINTN CommSize; >=20 > DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SaveLockBox - Enter\n")); > @@ -64,21 +162,18 @@ SaveLockBox ( > return EFI_INVALID_PARAMETER; > } >=20 > - // > - // Get needed resource > - // > - Status =3D gBS->LocateProtocol ( > - &gEfiSmmCommunicationProtocolGuid, > - NULL, > - (VOID **)&SmmCommunication > - ); > - if (EFI_ERROR (Status)) { > + SmmCommunication =3D LockBoxGetSmmCommProtocol (); > + if (SmmCommunication =3D=3D NULL) { > return EFI_NOT_STARTED; > } >=20 > // > // Prepare parameter > // > + CommBuffer =3D LockBoxGetSmmCommBuffer (); > + if (CommBuffer =3D=3D NULL) { > + CommBuffer =3D &TempCommBuffer[0]; > + } > CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; > CopyMem (&CommHeader->HeaderGuid, > &gEfiSmmLockBoxCommunicationGuid, > sizeof(gEfiSmmLockBoxCommunicationGuid)); > CommHeader->MessageLength =3D sizeof(*LockBoxParameterSave); > @@ -94,7 +189,7 @@ SaveLockBox ( > // > // Send command > // > - CommSize =3D sizeof(CommBuffer); > + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE); > Status =3D SmmCommunication->Communicate ( > SmmCommunication, > &CommBuffer[0], > @@ -136,7 +231,8 @@ SetLockBoxAttributes ( > EFI_SMM_COMMUNICATION_PROTOCOL > *SmmCommunication; > EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES > *LockBoxParameterSetAttributes; > EFI_SMM_COMMUNICATE_HEADER *CommHeader; > - UINT8 > CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; > + UINT8 > TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; > + UINT8 *CommBuffer; > UINTN CommSize; >=20 > DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SetLockBoxAttributes - > Enter\n")); > @@ -149,21 +245,18 @@ SetLockBoxAttributes ( > return EFI_INVALID_PARAMETER; > } >=20 > - // > - // Get needed resource > - // > - Status =3D gBS->LocateProtocol ( > - &gEfiSmmCommunicationProtocolGuid, > - NULL, > - (VOID **)&SmmCommunication > - ); > - if (EFI_ERROR (Status)) { > + SmmCommunication =3D LockBoxGetSmmCommProtocol (); > + if (SmmCommunication =3D=3D NULL) { > return EFI_NOT_STARTED; > } >=20 > // > // Prepare parameter > // > + CommBuffer =3D LockBoxGetSmmCommBuffer (); > + if (CommBuffer =3D=3D NULL) { > + CommBuffer =3D &TempCommBuffer[0]; > + } > CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; > CopyMem (&CommHeader->HeaderGuid, > &gEfiSmmLockBoxCommunicationGuid, > sizeof(gEfiSmmLockBoxCommunicationGuid)); > CommHeader->MessageLength =3D sizeof(*LockBoxParameterSetAttributes); > @@ -178,7 +271,7 @@ SetLockBoxAttributes ( > // > // Send command > // > - CommSize =3D sizeof(CommBuffer); > + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES); > Status =3D SmmCommunication->Communicate ( > SmmCommunication, > &CommBuffer[0], > @@ -225,7 +318,8 @@ UpdateLockBox ( > EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; > EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate; > EFI_SMM_COMMUNICATE_HEADER *CommHeader; > - UINT8 CommBuffer[sizeof(EFI_GUID) + > sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; > + UINT8 TempCommBuffer[sizeof(EFI_GUID) > + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; > + UINT8 *CommBuffer; > UINTN CommSize; >=20 > DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib UpdateLockBox - Enter\n")); > @@ -237,21 +331,18 @@ UpdateLockBox ( > return EFI_INVALID_PARAMETER; > } >=20 > - // > - // Get needed resource > - // > - Status =3D gBS->LocateProtocol ( > - &gEfiSmmCommunicationProtocolGuid, > - NULL, > - (VOID **)&SmmCommunication > - ); > - if (EFI_ERROR (Status)) { > + SmmCommunication =3D LockBoxGetSmmCommProtocol (); > + if (SmmCommunication =3D=3D NULL) { > return EFI_NOT_STARTED; > } >=20 > // > // Prepare parameter > // > + CommBuffer =3D LockBoxGetSmmCommBuffer (); > + if (CommBuffer =3D=3D NULL) { > + CommBuffer =3D &TempCommBuffer[0]; > + } > CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; > CopyMem (&CommHeader->HeaderGuid, > &gEfiSmmLockBoxCommunicationGuid, > sizeof(gEfiSmmLockBoxCommunicationGuid)); > CommHeader->MessageLength =3D sizeof(*LockBoxParameterUpdate); > @@ -268,7 +359,7 @@ UpdateLockBox ( > // > // Send command > // > - CommSize =3D sizeof(CommBuffer); > + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE); > Status =3D SmmCommunication->Communicate ( > SmmCommunication, > &CommBuffer[0], > @@ -316,7 +407,8 @@ RestoreLockBox ( > EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; > EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore; > EFI_SMM_COMMUNICATE_HEADER *CommHeader; > - UINT8 CommBuffer[sizeof(EFI_GUID) + > sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; > + UINT8 TempCommBuffer[sizeof(EFI_GUID) > + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; > + UINT8 *CommBuffer; > UINTN CommSize; >=20 > DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreLockBox - Enter\n")); > @@ -330,21 +422,18 @@ RestoreLockBox ( > return EFI_INVALID_PARAMETER; > } >=20 > - // > - // Get needed resource > - // > - Status =3D gBS->LocateProtocol ( > - &gEfiSmmCommunicationProtocolGuid, > - NULL, > - (VOID **)&SmmCommunication > - ); > - if (EFI_ERROR (Status)) { > + SmmCommunication =3D LockBoxGetSmmCommProtocol (); > + if (SmmCommunication =3D=3D NULL) { > return EFI_NOT_STARTED; > } >=20 > // > // Prepare parameter > // > + CommBuffer =3D LockBoxGetSmmCommBuffer (); > + if (CommBuffer =3D=3D NULL) { > + CommBuffer =3D &TempCommBuffer[0]; > + } > CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; > CopyMem (&CommHeader->HeaderGuid, > &gEfiSmmLockBoxCommunicationGuid, > sizeof(gEfiSmmLockBoxCommunicationGuid)); > CommHeader->MessageLength =3D sizeof(*LockBoxParameterRestore); > @@ -364,7 +453,7 @@ RestoreLockBox ( > // > // Send command > // > - CommSize =3D sizeof(CommBuffer); > + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE); > Status =3D SmmCommunication->Communicate ( > SmmCommunication, > &CommBuffer[0], > @@ -403,26 +492,24 @@ RestoreAllLockBoxInPlace ( > EFI_SMM_COMMUNICATION_PROTOCOL > *SmmCommunication; > EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE > *LockBoxParameterRestoreAllInPlace; > EFI_SMM_COMMUNICATE_HEADER *CommHeader; > - UINT8 > CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; > + UINT8 > TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; > + UINT8 *CommBuffer; > UINTN CommSize; >=20 > DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - > Enter\n")); >=20 > - // > - // Get needed resource > - // > - Status =3D gBS->LocateProtocol ( > - &gEfiSmmCommunicationProtocolGuid, > - NULL, > - (VOID **)&SmmCommunication > - ); > - if (EFI_ERROR (Status)) { > + SmmCommunication =3D LockBoxGetSmmCommProtocol (); > + if (SmmCommunication =3D=3D NULL) { > return EFI_NOT_STARTED; > } >=20 > // > // Prepare parameter > // > + CommBuffer =3D LockBoxGetSmmCommBuffer (); > + if (CommBuffer =3D=3D NULL) { > + CommBuffer =3D &TempCommBuffer[0]; > + } > CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; > CopyMem (&CommHeader->HeaderGuid, > &gEfiSmmLockBoxCommunicationGuid, > sizeof(gEfiSmmLockBoxCommunicationGuid)); > CommHeader->MessageLength =3D > sizeof(*LockBoxParameterRestoreAllInPlace); > @@ -435,7 +522,7 @@ RestoreAllLockBoxInPlace ( > // > // Send command > // > - CommSize =3D sizeof(CommBuffer); > + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + > sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE); > Status =3D SmmCommunication->Communicate ( > SmmCommunication, > &CommBuffer[0], > diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf > b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf > index 48cdb9c66ab7..f3120ccb42d5 100644 > --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf > +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf > @@ -1,7 +1,7 @@ > ## @file > # DXE LockBox library instance. > # > -# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved. > +# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. > # > # This program and the accompanying materials > # are licensed and made available under the terms and conditions > @@ -42,9 +42,11 @@ [LibraryClasses] > BaseLib > BaseMemoryLib > DebugLib > + UefiLib >=20 > [Guids] > - gEfiSmmLockBoxCommunicationGuid ## SOMETIMES_CONSUMES ## > GUID # Used to do smm communication > + gEfiSmmLockBoxCommunicationGuid ## > SOMETIMES_CONSUMES ## GUID # Used to do smm communication > + gEdkiiPiSmmCommunicationRegionTableGuid ## > SOMETIMES_CONSUMES ## SystemTable >=20 > [Protocols] > gEfiSmmCommunicationProtocolGuid ## SOMETIMES_CONSUMES > -- > 2.7.0.windows.1