From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.5220.1579154196708154690 for ; Wed, 15 Jan 2020 21:56:36 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2020 21:56:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,325,1574150400"; d="scan'208";a="220262569" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga008.fm.intel.com with ESMTP; 15 Jan 2020 21:56:36 -0800 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Jan 2020 21:56:36 -0800 Received: from shsmsx606.ccr.corp.intel.com (10.109.6.216) by SHSMSX603.ccr.corp.intel.com (10.109.6.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 16 Jan 2020 13:56:34 +0800 Received: from shsmsx606.ccr.corp.intel.com ([10.109.6.216]) by SHSMSX606.ccr.corp.intel.com ([10.109.6.216]) with mapi id 15.01.1713.004; Thu, 16 Jan 2020 13:56:34 +0800 From: "Liming Gao" To: "Wang, Jian J" , "Kubacki, Michael A" , "devel@edk2.groups.io" CC: "Kinney, Michael D" , Michael Turner , "Wu, Hao A" Subject: Re: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fix VarErrorFlag RT cache offset calculation Thread-Topic: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fix VarErrorFlag RT cache offset calculation Thread-Index: AQHVymfwVCZUY6AhUU6EB3QkcljozKfpMMWAgAFi0ICAAASbAIAABhaAgAFwNACAAL/bEA== Date: Thu, 16 Jan 2020 05:56:34 +0000 Message-ID: References: <20200113231908.29724-1-michael.a.kubacki@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-product: dlpe-windows dlp-reaction: no-action x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Wang, Jian J > Sent: Thursday, January 16, 2020 10:29 AM > To: Kubacki, Michael A ; devel@edk2.groups.= io > Cc: Gao, Liming ; Kinney, Michael D ; Michael Turner > ; Wu, Hao A > Subject: RE: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fix VarE= rrorFlag RT cache offset calculation >=20 >=20 > Reviewed-by: Jian J Wang >=20 > Regards, > Jian >=20 > > -----Original Message----- > > From: Kubacki, Michael A > > Sent: Wednesday, January 15, 2020 12:31 PM > > To: Wang, Jian J ; devel@edk2.groups.io > > Cc: Gao, Liming ; Kinney, Michael D > > ; Michael Turner > > ; Wu, Hao A > > Subject: RE: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fix > > VarErrorFlag RT cache offset calculation > > > > Since I don't have a strong opinion either, I won't make any changes t= o V1 at this > > time. > > > > Thanks, > > Michael > > > > > -----Original Message----- > > > From: Wang, Jian J > > > Sent: Tuesday, January 14, 2020 8:09 PM > > > To: Kubacki, Michael A ; > > > devel@edk2.groups.io > > > Cc: Gao, Liming ; Kinney, Michael D > > > ; Michael Turner > > > ; Wu, Hao A > > > Subject: RE: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fix > > > VarErrorFlag RT cache offset calculation > > > > > > Mike, > > > > > > Thanks for explaining. You're right that the error is rare case and = it won't > > > cause big problem, and NonVolatileLastVariableOffset will be approac= hing > > > the whole FV size after some time. I don't have strong opinion. Both= work for > > > me. > > > > > > Regards, > > > Jian > > > > > > > -----Original Message----- > > > > From: Kubacki, Michael A > > > > Sent: Wednesday, January 15, 2020 11:53 AM > > > > To: Wang, Jian J ; devel@edk2.groups.io > > > > Cc: Gao, Liming ; Kinney, Michael D > > > > ; Michael Turner > > > > ; Wu, Hao A > > > > Subject: RE: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fi= x > > > > VarErrorFlag RT cache offset calculation > > > > > > > > Hi Jian, > > > > > > > > I considered that but these are the reasons I settled on the appro= ach in > > > patch V1. > > > > > > > > 1. With the variable store filled, the length of > > > > mVariableModuleGlobal- > > > > >NonVolatileLastVariableOffset will only marginally be a smaller v= alue > > > > >than > > > > mNvVariableCache->Size (since variable writes grow the store for S= PI > > > > mNvVariableCache->flash wear > > > > leveling). In this case, it will be ~CommonRuntimeVariableSpace wh= ich > > > > is usually a major portion of the variable store size anyway. > > > > 2. Since mVariableModuleGlobal->NonVolatileLastVariableOffset is a > > > > global moving value that is more frequently manipulated than the f= ixed > > > > variable store size, depending upon it increases the likelihood it > > > > will be set to an invalid value somewhere else. > > > > 3. This is a relatively rare case (an error condition) and the mem= ory > > > > copy is within DRAM for variable stores that are typically ~128KB = - ~512KB. > > > > > > > > To reduce the copy size, the Offset parameter can be "(UINTN) > > > > VarErrFlag - > > > > (UINTN) mNvVariableCache" (just remove the unnecessary addition of > > > > (UINTN) > > > > mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase) wit= h > > > > mVariableModuleGlobal->size > > > > "sizeof (TempFlag)". How about this in a V2? > > > > > > > > Thanks, > > > > Michael > > > > > > > > > -----Original Message----- > > > > > From: Wang, Jian J > > > > > Sent: Monday, January 13, 2020 10:43 PM > > > > > To: devel@edk2.groups.io; Kubacki, Michael A > > > > > > > > > > Cc: Gao, Liming ; Kinney, Michael D > > > > > ; Michael Turner > > > > > ; Wu, Hao A > > > > > Subject: RE: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: = Fix > > > > > VarErrorFlag RT cache offset calculation > > > > > > > > > > Michael, > > > > > > > > > > I'm not sure sync-ing whole variable cache memory is an efficien= t > > > operation. > > > > > What about using > > > > > mVariableModuleGlobal->NonVolatileLastVariableOffset > > > > > as Length parameter? > > > > > > > > > > Status =3D SynchronizeRuntimeVariableCache ( > > > > > &mVariableModuleGlobal- > > > > > > > > >VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeNvCache, > > > > > 0, > > > > > mVariableModuleGlobal->NonVolatileLastVariabl= eOffset > > > > > ); > > > > > > > > > > Regards, > > > > > Jian > > > > > > > > > > > -----Original Message----- > > > > > > From: devel@edk2.groups.io On Behalf Of > > > > > > Kubacki, Michael A > > > > > > Sent: Tuesday, January 14, 2020 7:19 AM > > > > > > To: devel@edk2.groups.io > > > > > > Cc: Gao, Liming ; Kinney, Michael D > > > > > > ; Michael Turner > > > > > > ; Wang, Jian J > > > > > > ; Wu, Hao A > > > > > > Subject: [edk2-devel] [PATCH V1 1/1] MdeModulePkg/Variable: Fi= x > > > > > > VarErrorFlag RT cache offset calculation > > > > > > > > > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2457 > > > > > > > > > > > > This commit fixes an offset calculation that is used to write = the > > > > > > VarErrorFlag UEFI variable to the UEFI variable runtime cache. > > > > > > > > > > > > Currently a physical address is used instead of an offset. Thi= s > > > > > > commit changes the offset to zero with a length of the entire > > > > > > non-volatile variable store so the entire non-volatile variabl= e > > > > > > store buffer in SMRAM (with the variable update modification) = is > > > > > > copied to the runtime variable cache. This follows the same > > > > > > pattern used in other SynchronizeRuntimeVariableCache () calls= for > > > consistency. > > > > > > > > > > > > * Observable symptom: An exception in SMM will most likely occ= ur > > > > > > due to the invalid memory reference when the VarErrorFlag va= riable > > > > > > is written. The variable is most commonly written when the U= EFI > > > > > > variable store is full. > > > > > > > > > > > > * The issue only occurs when the variable runtime cache is ena= bled > > > > > > by the following PCD being set to TRUE: > > > > > > gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache > > > > > > > > > > > > Fixes: aab3b9b9a1e5e1f3fa966fb1667fc3e6c47e7706 > > > > > > > > > > > > Cc: Liming Gao > > > > > > Cc: Michael D Kinney > > > > > > Cc: Michael Turner > > > > > > Cc: Jian J Wang > > > > > > Cc: Hao A Wu > > > > > > Signed-off-by: Michael Kubacki > > > > > > --- > > > > > > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 6 +++= --- > > > > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > > > > > > > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variab= le.c > > > > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > > > > > index b0ee5e50d0..d23aea4bc7 100644 > > > > > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > > > > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > > > > > @@ -16,7 +16,7 @@ > > > > > > VariableServiceSetVariable() should also check authenticate > > > > > > data to avoid buffer overflow, > > > > > > integer overflow. It should also check attribute to avoid > > > > > > authentication > > > > > bypass. > > > > > > > > > > > > -Copyright (c) 2006 - 2019, Intel Corporation. All rights > > > > > > reserved.
> > > > > > +Copyright (c) 2006 - 2020, Intel Corporation. All rights > > > > > > +reserved.
> > > > > > (C) Copyright 2015-2018 Hewlett Packard Enterprise Developmen= t > > > > > > LP
> > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > @@ -335,8 +335,8 @@ RecordVarErrorFlag ( > > > > > > *VarErrFlag =3D TempFlag; > > > > > > Status =3D SynchronizeRuntimeVariableCache ( > > > > > > &mVariableModuleGlobal- > > > > > > > > > >VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeNvCache > > > > > > >, > > > > > > - (UINTN) VarErrFlag - (UINTN) mNvVariableCac= he + (UINTN) > > > > > > mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase, > > > > > > - sizeof (TempFlag) > > > > > > + 0, > > > > > > + mNvVariableCache->Size > > > > > > ); > > > > > > ASSERT_EFI_ERROR (Status); > > > > > > } > > > > > > -- > > > > > > 2.16.2.windows.1 > > > > > > > > > > > > > > > > > >=20 > > > > > > > > > > > > > >