From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: hao.a.wu@intel.com) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by groups.io with SMTP; Thu, 03 Oct 2019 01:04:42 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Oct 2019 01:04:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,251,1566889200"; d="scan'208";a="391865612" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga005.fm.intel.com with ESMTP; 03 Oct 2019 01:04:41 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 3 Oct 2019 01:04:41 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 3 Oct 2019 01:04:41 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.166]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.165]) with mapi id 14.03.0439.000; Thu, 3 Oct 2019 16:04:39 +0800 From: "Wu, Hao A" To: "Kubacki, Michael A" , "devel@edk2.groups.io" CC: "Bi, Dandan" , Ard Biesheuvel , "Dong, Eric" , Laszlo Ersek , "Gao, Liming" , "Kinney, Michael D" , "Ni, Ray" , "Wang, Jian J" , "Yao, Jiewen" Subject: Re: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Thread-Topic: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Thread-Index: AQHVdZ69aao24nyK0UqxTLIg6pa5BadIlNZA Date: Thu, 3 Oct 2019 08:04:38 +0000 Message-ID: References: <20190928014717.31372-1-michael.a.kubacki@intel.com> <20190928014717.31372-9-michael.a.kubacki@intel.com> In-Reply-To: <20190928014717.31372-9-michael.a.kubacki@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: hao.a.wu@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Kubacki, Michael A > Sent: Saturday, September 28, 2019 9:47 AM > To: devel@edk2.groups.io > Cc: Bi, Dandan; Ard Biesheuvel; Dong, Eric; Laszlo Ersek; Gao, Liming; Ki= nney, > Michael D; Ni, Ray; Wang, Jian J; Wu, Hao A; Yao, Jiewen > Subject: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT > GetNextVariableName() cache support >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220 >=20 > This change implements the Runtime Service GetNextVariableName() > using the Runtime Cache in VariableSmmRuntimeDxe. Runtime Service > calls to GetNextVariableName() will no longer trigger a SW SMI. >=20 > Overall system performance and stability will be improved by > eliminating an SMI for these calls as they typically result in a > relatively large number of invocations to retrieve all variable > names in all variable stores present. >=20 > Cc: Dandan Bi > Cc: Ard Biesheuvel > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Liming Gao > Cc: Michael D Kinney > Cc: Ray Ni > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Jiewen Yao > Signed-off-by: Michael Kubacki > --- >=20 > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe > .c | 118 +++++++++----------- > 1 file changed, 50 insertions(+), 68 deletions(-) >=20 > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD > xe.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD > xe.c > index 46f69765a4..bc3b56b0ce 100644 > --- > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD > xe.c > +++ > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD > xe.c > @@ -799,87 +799,69 @@ RuntimeServiceGetNextVariableName ( > IN OUT EFI_GUID *VendorGuid > ) > { > - EFI_STATUS Status; > - UINTN PayloadSize; > - SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME > *SmmGetNextVariableName; > - UINTN OutVariableNameSize; > - UINTN InVariableNameSize; > + EFI_STATUS Status; > + UINTN DelayIndex; > + UINTN MaxLen; > + UINTN VarNameSize; > + VARIABLE_HEADER *VariablePtr; > + VARIABLE_STORE_HEADER > *VariableStoreHeader[VariableStoreTypeMax]; > + > + Status =3D EFI_NOT_FOUND; >=20 > if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || Vendor= Guid =3D=3D > NULL) { > return EFI_INVALID_PARAMETER; > } >=20 > - OutVariableNameSize =3D *VariableNameSize; > - InVariableNameSize =3D StrSize (VariableName); > - SmmGetNextVariableName =3D NULL; > - > // > - // If input string exceeds SMM payload limit. Return failure > + // Calculate the possible maximum length of name string, including the > Null terminator. > // > - if (InVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) { > + MaxLen =3D *VariableNameSize / sizeof (CHAR16); > + if ((MaxLen =3D=3D 0) || (StrnLenS (VariableName, MaxLen) =3D=3D MaxLe= n)) { > + // > + // Null-terminator is not found in the first VariableNameSize bytes = of the > input VariableName buffer, > + // follow spec to return EFI_INVALID_PARAMETER. > + // > return EFI_INVALID_PARAMETER; > } >=20 > - AcquireLockOnlyAtBootTime(&mVariableServicesLock); > + AcquireLockOnlyAtBootTime (&mVariableServicesLock); >=20 > - // > - // Init the communicate buffer. The buffer data size is: > - // SMM_COMMUNICATE_HEADER_SIZE + > SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize. > - // > - if (OutVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) { > - // > - // If output buffer exceed SMM payload limit. Trim output buffer to = SMM > payload size > - // > - OutVariableNameSize =3D mVariableBufferPayloadSize - OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name); > + for (DelayIndex =3D 0; mVariableRuntimeCacheReadLock && DelayIndex < > VARIABLE_RT_CACHE_READ_LOCK_TIMEOUT; DelayIndex++) { > + MicroSecondDelay (10); > } > - // > - // Payload should be Guid + NameSize + MAX of Input & Output buffer > - // > - PayloadSize =3D OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + > MAX (OutVariableNameSize, InVariableNameSize); > - > - Status =3D InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, > PayloadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME); > - if (EFI_ERROR (Status)) { > - goto Done; > - } > - ASSERT (SmmGetNextVariableName !=3D NULL); > - > - // > - // SMM comm buffer->NameSize is buffer size for return string > - // > - SmmGetNextVariableName->NameSize =3D OutVariableNameSize; > - > - CopyGuid (&SmmGetNextVariableName->Guid, VendorGuid); > - // > - // Copy whole string > - // > - CopyMem (SmmGetNextVariableName->Name, VariableName, > InVariableNameSize); > - if (OutVariableNameSize > InVariableNameSize) { > - ZeroMem ((UINT8 *) SmmGetNextVariableName->Name + > InVariableNameSize, OutVariableNameSize - InVariableNameSize); > - } > - > - // > - // Send data to SMM > - // > - Status =3D SendCommunicateBuffer (PayloadSize); > - > - // > - // Get data from SMM. > - // > - if (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_BUFFER_TOO_SMALL) { > - // > - // SMM CommBuffer NameSize can be a trimed value > - // Only update VariableNameSize when needed > - // > - *VariableNameSize =3D SmmGetNextVariableName->NameSize; > - } > - if (EFI_ERROR (Status)) { > - goto Done; > + if (DelayIndex < VARIABLE_RT_CACHE_READ_LOCK_TIMEOUT) { > + ASSERT (!mVariableRuntimeCacheReadLock); > + > + CheckForRuntimeCacheSync (); > + mVariableRuntimeCacheReadLock =3D TRUE; > + > + if (!mVariableRuntimeCachePendingUpdate) { > + // > + // 0: Volatile, 1: HOB, 2: Non-Volatile. > + // The index and attributes mapping must be kept in this order as > FindVariable > + // makes use of this mapping to implement search algorithm. > + // > + VariableStoreHeader[VariableStoreTypeVolatile] =3D > mVariableRuntimeVolatileCacheBuffer; > + VariableStoreHeader[VariableStoreTypeHob] =3D > mVariableRuntimeHobCacheBuffer; > + VariableStoreHeader[VariableStoreTypeNv] =3D > mVariableRuntimeNvCacheBuffer; > + > + Status =3D GetNextVariableEx (VariableName, VendorGuid, > VariableStoreHeader, &VariablePtr); > + if (!EFI_ERROR (Status)) { > + VarNameSize =3D NameSizeOfVariable (VariablePtr); > + ASSERT (VarNameSize !=3D 0); > + if (VarNameSize <=3D *VariableNameSize) { > + CopyMem (VariableName, GetVariableNamePtr (VariablePtr), > VarNameSize); > + CopyMem (VendorGuid, GetVendorGuidPtr (VariablePtr), sizeof > (EFI_GUID)); > + Status =3D EFI_SUCCESS; > + } else { > + Status =3D EFI_BUFFER_TOO_SMALL; > + } > + > + *VariableNameSize =3D VarNameSize; > + } > + } > } > - > - CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid); > - CopyMem (VariableName, SmmGetNextVariableName->Name, > SmmGetNextVariableName->NameSize); > - > -Done: > + mVariableRuntimeCacheReadLock =3D FALSE; Similar to the previous patch (7/9), if timeout occurs when acquiring the read lock, should this flag be set to = FALSE in such case? Best Regards, Hao Wu > ReleaseLockOnlyAtBootTime (&mVariableServicesLock); > return Status; > } > -- > 2.16.2.windows.1