From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web09.13699.1644516079522961577 for ; Thu, 10 Feb 2022 10:01:20 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Fxyyaw2+; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: isaac.w.oram@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644516079; x=1676052079; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=AsMcmh2sUGlF/SciWbrM74xMBMBE45raSl6XAbYKFG4=; b=Fxyyaw2+rWveAlITvUuNSm0iiFcY54S478MFt6ZUM2KbbcYNaUqgiGFZ POfImAzBLQnAjbvd0pZwPaROrBi4qsinDD6+LYFAwCkJQfQU8kn8sJd95 LtA9XTA9lxot9q2jae0GW3cxATp6+Qqxhh6nQHclsNBVasksaHgVL7Moi NrleCSKNZbmJ108OQi0AP/UOw3yTFrqgQER0jkarPDZ+J787j+mgUTknP +faXBDbYYsRHNK5T+hnKaE2CBYxLgBicmZ915/Xf82vfluUnA8cWoxuIo as2U0M9fFE0FOigdOJw7+JDxul7jeOoHlapxYgYdxqIAJBHu2rL6riufq A==; X-IronPort-AV: E=McAfee;i="6200,9189,10254"; a="310291295" X-IronPort-AV: E=Sophos;i="5.88,359,1635231600"; d="scan'208";a="310291295" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2022 10:01:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,359,1635231600"; d="scan'208";a="602118546" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by fmsmga004.fm.intel.com with ESMTP; 10 Feb 2022 10:01:18 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 10 Feb 2022 10:01:17 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Thu, 10 Feb 2022 10:01:17 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.107) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Thu, 10 Feb 2022 10:01:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiPq+wpB52SOnj1EdAG0aY1xCGxh9M96/Te4s5FMCgvVkrLuOC/dLo89GK3fREpyi6mBGKY5JWhjaprdiktNjCP//r8acXxksNPQnEzbjg82oCTMxYEiYDPevEdPjyrDVVSspLM5lqprzpcJNfnoEVbNkOio8FetutBA7CeW4NHizY1hl6/zEJlyPVn/qehOpPqWf9kX0AQBqxMmMg8wZVFWGnV1NDBEKHifiF8z40aohDZYgqyB6/7nB3pRSNOE3eCLHUvkWGNNvn79FSaqVkUUxOFfeNhvNLyD7/X/F9CXzKjU/SUgqEsTmP7gC4ie6nW9j9T8ubYdpRCOOntsMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mxNzrb2PEE7E49x6RqP979oOICToovt3qFxiBcX6fyA=; b=Fp1RQUGiUw/oj3BRLmyhl+nrHN8ttUq6+empVdNtdV8HlaC1Skm0XjIHbw/Tw4CKjSyy0UdyLEad4P8vEikG2VZSLGXBGAOiCJlQZylbZLXQ/3SpFZcsIdI6TScWFp3d39xW4Mrab+4AEJqiRp9CUTu8i44ZEDiwe1UHriOo70TJ++UHxIXxFsB5px8DejJmjgU9KlFyQ95Zh2o+QD1dKO7TrWPRztxNTCpOSmqPe6FYS1z8yXwQtjvLJoWqGSeG5WSKmeHyJNS0eEv5sn+yLt1rO0rx7UCovZFa8tUzM0yQo594V2aA6amSpN8eJo7/ikjIfzjEPvY+0ZUDbih7tQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MW3PR11MB4747.namprd11.prod.outlook.com (2603:10b6:303:2f::11) by BN6PR11MB1361.namprd11.prod.outlook.com (2603:10b6:404:49::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 18:01:10 +0000 Received: from MW3PR11MB4747.namprd11.prod.outlook.com ([fe80::9c36:57de:e967:55a3]) by MW3PR11MB4747.namprd11.prod.outlook.com ([fe80::9c36:57de:e967:55a3%8]) with mapi id 15.20.4951.019; Thu, 10 Feb 2022 18:01:10 +0000 From: "Oram, Isaac W" To: "devel@edk2.groups.io" , "Chiu, Chasel" CC: "Desimone, Nathaniel L" , "Gao, Liming" , "Dong, Eric" Subject: Re: [edk2-devel] [edk2-platforms: PATCH v2] MinPlatformPkg/SaveMemoryConfig: Variable may not be locked. Thread-Topic: [edk2-devel] [edk2-platforms: PATCH v2] MinPlatformPkg/SaveMemoryConfig: Variable may not be locked. Thread-Index: AQHYHku4RbcjIrtJYEid5rK/qA6gkayNEhAQ Date: Thu, 10 Feb 2022 18:01:10 +0000 Message-ID: References: <20220210065901.714-1-chasel.chiu@intel.com> In-Reply-To: <20220210065901.714-1-chasel.chiu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.200.16 dlp-reaction: no-action authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 11d9478d-70ba-4236-ab8a-08d9ecbf51ad x-ms-traffictypediagnostic: BN6PR11MB1361:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Yc1seBKaCrXSwhn97xOFv82NopwjDIRL8myYD+H5rbNivylNenKdiKVpiWtLksEzqx2b/VL3JXGW1Bn0byi1jSkorgVtpA/tmtgqsCbzwk2vzJ2wSdPx1YNKEoEaTmPycO7oFqNvUxM5juttacjXcGTYIbFjRkhnmcyv7NrJL7DCZ7b59Rbo+5RTDt+X+oM/SeMDxKYZoVWWavyar4N/VTJn8BTpdgQM4i6ZLIuaj6QVNzD3n2OcuyBvtY+PHpRprNje90iywN3ADtxNcnSrujiS9IM0JzB1v+DfMPtGA1MYcPsnq5maRL8JUvC4jHjeKdXZxG3VP6sXvvgbdIsD4H3RwPHaBVh2oWd9KvTpqQbq8/k+aOSsDcoy97ENDzCYamdQ57N+5KNFnBGRFtpqEa6TH/8kFPPGvl5PUajTKUSdmIHNx3O7vBlmPrSdpkLBd9tP/hrkfPZZIETc6n//eBoba/0KALxJIEVMXrk6IMwO3ciKo+TpPCK/q494YYQEDJist3BES5uq1mKr01pU7pQYpUlLaH+L3tBA532eYTLD/Nr/skxp8PoA7tosbKmeJP2GhQVHXv/ESngEriWYmDknuaUGfqX9r0j0M9C8LJWmPI/dm0hG6dV5kZRHA6X6U7YVTgmUsLElC4O8aAEW1Rbak9LNBc0HWYnYamjcRnDq0IXXxbSNKlVhJHnRTUdC6aPwA2wlkHFBBiFDyymRLOZUcXCV7d90fS65O2kztfwVRifwdMnKkf/dpOfFTsdxEjFxAvR4LozttSHGzaOW9GIeX1IPPGQ2sXQDDXYvEa39s6mzy9/SlbHOf8UG2qOGh4hIg3Usps/hfbjU2XCToA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR11MB4747.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(8676002)(186003)(7696005)(9686003)(4326008)(6506007)(122000001)(71200400001)(8936002)(26005)(55016003)(66476007)(66556008)(66946007)(64756008)(66446008)(76116006)(33656002)(54906003)(6636002)(110136005)(316002)(38100700002)(38070700005)(53546011)(107886003)(86362001)(508600001)(82960400001)(83380400001)(5660300002)(966005)(30864003)(2906002)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?lvXJr37jZh+us2w9km4O+alRugf7CUdX5moJZsAf3YRn6qZ2+gTssCkkIw57?= =?us-ascii?Q?jcn1FP67aAWUkMICV2i9paW+DxGWp0dKqME4V+swsVy1DqVpI3g3TesIWJaA?= =?us-ascii?Q?O33Rez4q6iiHlI6xnFRGIKglZjlbunNnj07XJuYl828+FUAttxW8EeuNFQT7?= =?us-ascii?Q?uJq0uKRBy7ooccL8Da/JPmxk5WcjJgw1x5kWXdnlHXCDfF0hOgW+Avni4K7w?= =?us-ascii?Q?4x0CZxnoVb28x5tWxwKJoHZLohUdxSos2i/pGCbX+Hsi87Yjy3NgrheJ+azv?= =?us-ascii?Q?vWeGrw2fVIv1wCt+3aGSOWqgpvh27u6tqPBYcw0+oVYKGGQnfSH30+0uqIZL?= =?us-ascii?Q?ypCIT7gWXwPWxGUXIDuqEiojJmDUi6HMNHxMH2clz/j+gLP8aRhj2TBsAdeF?= =?us-ascii?Q?MOtxDlTNrMxBBXufN8CDeNPe1g66L1xRiXhrLZ9rCjffmwgF47nI3WPKfiAN?= =?us-ascii?Q?8y2Zu1yzKy5L2K0ArRyYVKzqKqQF92H7DwGFXb3vUpbhD2Xu3DvgtBVU1dkW?= =?us-ascii?Q?j5ODXCy/E9/trr+IvtiLV2M2AczXxyQOiF959zY5WHUrpQF5Hme57BcjGjMS?= =?us-ascii?Q?XXvmOq3sCm0SijbJZ8IUUn3rhpVQfdayzwlW1oBKPIMkFL9pGnl4sqieL3SK?= =?us-ascii?Q?+Q7gSW/sQbzB08oMQ+NXs6cZZ345pAiSNSzvajf6DZ90CB5Du1sLVq0rpsQb?= =?us-ascii?Q?e86q5EeKVg3D4IwX8jwgWgfJyxqShelljyuyGb/mIaz/q7iP2J7FoVnOr4Hm?= =?us-ascii?Q?Dv2jeiNxswuHzsN66BqKUaqWW324U8nWfvxDb+X95Wpi2KF/zRqkCccoaChJ?= =?us-ascii?Q?lqIbIeq9LUpxdVeN6GSvI6+ihOYmFvFM+GODAf7lGIqE0PxTiqC3TZVfZ7Cc?= =?us-ascii?Q?mkQzDwKr5wajhR6HaAg8Y5mJ8qheDlZiuKOBd2Se0QDs411cZljCPu7gsuDG?= =?us-ascii?Q?AYDfiqWH4+9alma9V5k3GN6r8VR8NLhIWcetdp9Q+WdFxx1LgajPtWdoGb4r?= =?us-ascii?Q?BVqq9auqiewG3mww+QEZjyClTITXFJQqX8Nyba6276lNlxaAqzi1NY2Ki+3A?= =?us-ascii?Q?e87+mlW1gQr9KDPxSnoNE4xgk5cI59ZyI6CgYaCqZxMBu5YhESUJezlHPNyn?= =?us-ascii?Q?qs9XIcuR6Jf6RuiRKgoVQp9jd1RnuyxKW59KzcGp8YCuuyHT+LcJUjuKj3cu?= =?us-ascii?Q?+Dbe7Wh8snqwMzn3PQ3d+Y29Wu4Lu7qM1ybCGUQzBguYMM9ZxXF1TBaGou0W?= =?us-ascii?Q?8baQbmnF8Dggp2jzgok0MUVUeYWXuiGfGLGE6YChUhXDRkLEMSTOsIITaLpk?= =?us-ascii?Q?UMfiIRdydWB3rLwowo0ZpABYg7pMfYHZnvJsSz/CL1FH7PMnAYoKkZ36d5p6?= =?us-ascii?Q?f6NNOxQj8qfykpNcPH03uV2P3CPJ0Yu+0uLWtlSgv6Uz/zMen/N1f1G2ixme?= =?us-ascii?Q?00BJoSns5zx0LQrzlCqf+B848Een9yN8W/N9yE8A43Z8WnH4BWVaInnGV1TV?= =?us-ascii?Q?p2B2sKUzhKBdsoUl1bA8AA7eEsgYeTtrPJv2WwJtEiG/5Mb1dLfzFlBkp9oH?= =?us-ascii?Q?qLJAtdnsfOkXzmY73hBqHVz0DGtJIde1b+m6liDwNnMjpEk5absVfH6oxlzm?= =?us-ascii?Q?s2V/Mt6M3z8+yorDzOeVvso=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4747.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11d9478d-70ba-4236-ab8a-08d9ecbf51ad X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Feb 2022 18:01:10.0836 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: GDNQN7SCfLhxK2eSXgFEJVo0m5c/0C06UqXPHAVhuu8tBRlWQ7O5uHh4hm6wJFf5croqSxckyUzBwXDso40a/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1361 Return-Path: isaac.w.oram@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Chasel, The changes look good to me in general. The request I have is to please ad= d error return paths related to locking the variables. Given the sensitivi= ty related to UEFI variables, I don't think asserts are sufficient for erro= r flows. We should get explicit errors if anything fails in the attempts t= o lock variables. Regards, Isaac -----Original Message----- From: devel@edk2.groups.io On Behalf Of Chiu, Chasel Sent: Wednesday, February 9, 2022 10:59 PM To: devel@edk2.groups.io Cc: Chiu, Chasel ; Desimone, Nathaniel L ; Gao, Liming ; Dong, Eric <= eric.dong@intel.com> Subject: [edk2-devel] [edk2-platforms: PATCH v2] MinPlatformPkg/SaveMemoryC= onfig: Variable may not be locked. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3829 Fixed the bug that existing variable will not be locked when it is identica= l with hob data by creating LockLargeVariable function, also switched to Va= riablePolicyProtocol for locking variables. This patch also modified SaveMemoryConfig driver to be unloaded after execu= tion because it does not produce any service protocol. To achieve this goal= the DxeRuntimeVariableWriteLib should close registered ExitBootService eve= nts in its DESTRUCTOR. Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Chasel Chiu ---V2 : Created LockLargeVariable function to support locking multiple vari= able case. Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig= .c | 12 +++++++++--- Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWr= iteLib.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++-- Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntim= eVariableWriteLib.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++--= -------------- Platform/Intel/MinPlatformPkg/Include/Library/LargeVariableWriteLib.h = | 23 ++++++++++++++++++++++- Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntim= eVariableWriteLib.inf | 8 +++++--- 5 files changed, 177 insertions(+), 25 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/= SaveMemoryConfig.c index 820585f676..6e521bdce6 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemo +++ ryConfig.c @@ -2,7 +2,7 @@ This is the driver that locates the MemoryConfigurationData HOB, if it = exists, and saves the data to nvRAM. -Copyright (c) 2017 - 2021, Intel Cor= poration. All rights reserved.
+Copyright (c) 2017 - 2022, Intel Corpora= tion. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent= **/@@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include /**@@ -86,6 +87,11 @@= SaveMemoryConfigEntryPoint ( Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVa= riableGuid, &BufferSize, VariableData); if (!EFI_ERROR (Status)= && (BufferSize =3D=3D DataSize) && (0 =3D=3D CompareMem (HobData, Variable= Data, DataSize))) { DataIsIdentical =3D TRUE;+ /= /+ // No need to update Variable, only lock it.+ = //+ Status =3D LockLargeVariable (L"FspNvsBuffer", &gFspNvsBu= fferVariableGuid);+ ASSERT_EFI_ERROR (Status); } = FreePool (VariableData); }@@ -106,7 +112,7 @@ SaveMemo= ryConfigEntryPoint ( } //- // This driver cannot be unloaded because DxeRuntimeVariableWr= iteLib constructor will register ExitBootServices callback.+ // This drive= r does not produce any protocol services, so always unload it. //- retur= n EFI_SUCCESS;+ return EFI_REQUEST_UNLOAD_IMAGE; }diff --git a/Platform/In= tel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c b/P= latform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWrit= eLib.c index e4b97ef1df..5bee2d6751 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVaria= bleWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVa +++ riableWriteLib.c @@ -10,7 +10,7 @@ integer number will be added to the end of the variable name. This numbe= r will be incremented for each variable as needed to store the entire dat= a set. - Copyright (c) 2021, Intel Corporation. All rights reserved.
+ = Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
S= PDX-License-Identifier: BSD-2-Clause-Patent **/@@ -412,7 +412,7 @@ SetLarg= eVariable ( // all data is saved. // if (LockVariable) {- for (Index = =3D 0; Index < VariablesSaved; Index++) {+ for (Index =3D 0; Index <= =3D VariablesSaved; Index++) { ZeroMem (TempVariableName, MAX_VARIA= BLE_NAME_SIZE); UnicodeSPrint (TempVariableName, MAX_VARIABLE_NAME_= SIZE, L"%s%d", VariableName, Index); @@ -448,3 +448,96 @@ Done: DEBUG ((DEBUG_ERROR, "SetLargeVariable: Status =3D %r\n", Status)); re= turn Status; }++/**+ Locks the existing large variable.++ @param[in] Var= iableName A Null-terminated string that is the name of the vendor's v= ariable.+ Each VariableName is unique for e= ach VendorGuid. VariableName must+ contain = 1 or more characters. If VariableName is an empty string,+ = then EFI_INVALID_PARAMETER is returned.+ @param[in] Vendo= rGuid A unique identifier for the vendor.+ @retval EFI_SUCCESS = The firmware has successfully locked the variable.+ @retval EFI_IN= VALID_PARAMETER An invalid combination of variable name and GUID was suppl= ied+ @retval EFI_UNSUPPORTED The service for locking variable is no= t ready.+ @retval EFI_NOT_FOUND The targeting variable for lockin= g is not present.++**/+EFI_STATUS+EFIAPI+LockLargeVariable (+ IN CHAR16 = *VariableName,+ IN EFI_GUID *Ven= dorGuid+ )+{+ CHAR16 TempVariableName[MAX_VARIABLE_NAME_SIZE];+ U= INT64 VariableSize;+ EFI_STATUS Status;+ UINTN Index;++= //+ // Check input parameters.+ //+ if (VariableName =3D=3D NULL || Va= riableName[0] =3D=3D 0 || VendorGuid =3D=3D NULL) {+ return EFI_INVALID_= PARAMETER;+ }++ if (!VarLibIsVariableRequestToLockSupported ()) {+ ret= urn EFI_UNSUPPORTED;+ }++ VariableSize =3D 0;+ Index =3D 0;+ ZeroMem (T= empVariableName, MAX_VARIABLE_NAME_SIZE);+ UnicodeSPrint (TempVariableName= , MAX_VARIABLE_NAME_SIZE, L"%s%d", VariableName, Index);+ Status =3D VarLi= bGetVariable (TempVariableName, VendorGuid, NULL, &VariableSize, NULL);+ i= f (Status =3D=3D EFI_BUFFER_TOO_SMALL) {+ //+ // Lock multiple variab= les.+ //++ //+ // Lock first variable and continue to rest of the = variables.+ //+ DEBUG ((DEBUG_INFO, "Locking %s, Guid =3D %g\n", Temp= VariableName, VendorGuid));+ Status =3D VarLibVariableRequestToLock (Tem= pVariableName, VendorGuid);+ for (Index =3D 1; Index < MAX_VARIABLE_SPLI= T; Index++) {+ ZeroMem (TempVariableName, MAX_VARIABLE_NAME_SIZE);+ = UnicodeSPrint (TempVariableName, MAX_VARIABLE_NAME_SIZE, L"%s%d", Variab= leName, Index);++ VariableSize =3D 0;+ Status =3D VarLibGetVariab= le (TempVariableName, VendorGuid, NULL, &VariableSize, NULL);+ if (Sta= tus =3D=3D EFI_BUFFER_TOO_SMALL) {+ DEBUG ((DEBUG_INFO, "Locking %s,= Guid =3D %g\n", TempVariableName, VendorGuid));+ Status =3D VarLibV= ariableRequestToLock (TempVariableName, VendorGuid);+ ASSERT_EFI_ERR= OR (Status);+ } else if (Status =3D=3D EFI_NOT_FOUND) {+ //+ = // No more variables need to lock.+ //+ return EFI_SUCCE= SS;+ }+ } // End of for loop+ } else if (Status =3D=3D EFI_NOT_F= OUND) {+ //+ // Check if it is single variable scenario.+ //+ V= ariableSize =3D 0;+ Status =3D VarLibGetVariable (VariableName, VendorGu= id, NULL, &VariableSize, NULL);+ if (Status =3D=3D EFI_BUFFER_TOO_SMALL)= {+ //+ // Lock single variable.+ //+ DEBUG ((DEBUG_INF= O, "Locking %s, Guid =3D %g\n", VariableName, VendorGuid));+ Status = =3D VarLibVariableRequestToLock (VariableName, VendorGuid);+ ASSERT_EF= I_ERROR (Status);+ return EFI_SUCCESS;+ }+ }++ //+ // Here proba= bly means variable not present.+ //+ return Status;++}diff --git a/Platfo= rm/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntimeVariab= leWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWrit= eLib/DxeRuntimeVariableWriteLib.c index 9ed59f8827..e7d0c5ec34 100644 --- a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/D +++ xeRuntimeVariableWriteLib.c @@ -10,7 +10,7 @@ Using this library allows code to be written in a generic manner that ca= n be used in DXE or SMM without modification. - Copyright (c) 2021, Inte= l Corporation. All rights reserved.
+ Copyright (c) 2021 - 2022, Intel = Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clau= se-Patent **/@@ -18,14 +18,16 @@ #include #include -#include +#include #include #include #include #include -STATIC EDKII_VA= RIABLE_LOCK_PROTOCOL *mVariableWriteLibVariableLock =3D NULL;+STATIC EDKII= _VARIABLE_POLICY_PROTOCOL *mVariableWriteLibVariablePolicy =3D NULL;+EFI_E= VENT mExitBootServiceEvent;+EFI_EVENT = mLegacyBootEvent; /** Sets the value of a variable.= @@ -144,7 +146,7 @@ VarLibIsVariableRequestToLockSupported ( VOID ) {- if (mVariableWriteLibVariableLock !=3D NULL) {+ if (mVaria= bleWriteLibVariablePolicy !=3D NULL) { return TRUE; } else { retu= rn FALSE;@@ -178,16 +180,46 @@ VarLibVariableRequestToLock ( { EFI_STATUS Status =3D EFI_UNSUPPORTED; - if (mVariableWriteLibVari= ableLock !=3D NULL) {- Status =3D mVariableWriteLibVariableLock->Request= ToLock (- mVariableWriteLibVar= iableLock,- VariableName,- = VendorGuid- = );+ if (mVariableWriteLibVariablePolicy !=3D NULL)= {+ Status =3D RegisterBasicVariablePolicy (+ mVariableWri= teLibVariablePolicy,+ (CONST EFI_GUID*) VendorGuid,+ = (CONST CHAR16 *) VariableName,+ VARIABLE_POLICY_NO_MIN_= SIZE,+ VARIABLE_POLICY_NO_MAX_SIZE,+ VARIABLE_P= OLICY_NO_MUST_ATTR,+ VARIABLE_POLICY_NO_CANT_ATTR,+ = VARIABLE_POLICY_TYPE_LOCK_NOW+ );+ ASSERT_EFI_ERROR (= Status); } return Status; } +/**+ Close events when driver unloaded.++= @param[in] ImageHandle A handle for the image that is initializing this = driver+ @param[in] SystemTable A pointer to the EFI system table++ @retv= al EFI_SUCCESS The initialization finished successfully.+**/+EFI_STATUS= +EFIAPI+DxeRuntimeVariableWriteLibDestructor (+ IN EFI_HANDLE Image= Handle,+ IN EFI_SYSTEM_TABLE *SystemTable+ )+{+ if (mExitBootServiceEve= nt !=3D 0) {+ gBS->CloseEvent (mExitBootServiceEvent);+ }+ if (mLegacy= BootEvent !=3D 0) {+ gBS->CloseEvent (mLegacyBootEvent);+ }+ return EF= I_SUCCESS;+}+ /** Exit Boot Services Event notification handler. @@ -202,= 7 +234,7 @@ DxeRuntimeVariableWriteLibOnExitBootServices ( IN VOID *Context ) {- mVariableWriteLibVaria= bleLock =3D NULL;+ mVariableWriteLibVariablePolicy =3D NULL; } /**@@ -227= ,13 +259,11 @@ DxeRuntimeVariableWriteLibConstructor ( ) { EFI_STATUS Status;- EFI_EVENT ExitBootServiceEvent;- EFI_= EVENT LegacyBootEvent; // // Locate VariableLockProtocol. //- S= tatus =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID= **)&mVariableWriteLibVariableLock);+ Status =3D gBS->LocateProtocol (&gEd= kiiVariablePolicyProtocolGuid, NULL, (VOID **)&mVariableWriteLibVariablePol= icy); ASSERT_EFI_ERROR (Status); //@@ -245,7 +275,7 @@ DxeRuntimeVaria= bleWriteLibConstructor ( DxeRuntimeVariableWriteLibOnExitBootServices, NU= LL, &gEfiEventExitBootServicesGuid,- &ExitBootServ= iceEvent+ &mExitBootServiceEvent ); ASSERT_EFI_E= RROR (Status); @@ -257,7 +287,7 @@ DxeRuntimeVariableWriteLibConstructor ( TPL_NOTIFY, DxeRuntimeVariableWriteLibOnExitBoot= Services, NULL,- &LegacyBootEvent+ &mL= egacyBootEvent ); ASSERT_EFI_ERROR (Status); diff --git a/Pl= atform/Intel/MinPlatformPkg/Include/Library/LargeVariableWriteLib.h b/Platf= orm/Intel/MinPlatformPkg/Include/Library/LargeVariableWriteLib.h index c847d7f152..83b5e78506 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Library/LargeVariableWriteLib.h +++ b/Platform/Intel/MinPlatformPkg/Include/Library/LargeVariableWriteLi +++ b.h @@ -16,7 +16,7 @@ is possible, adjusting the value of PcdMaxVariableSize may provide a sim= pler solution to this problem. - Copyright (c) 2021, Intel Corporation. = All rights reserved.
+ Copyright (c) 2021 - 2022, Intel Corporation. Al= l rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/@= @ -66,4 +66,25 @@ SetLargeVariable ( IN VOID *Data ); +/**+ Locks the existing la= rge variable.++ @param[in] VariableName A Null-terminated string th= at is the name of the vendor's variable.+ E= ach VariableName is unique for each VendorGuid. VariableName must+ = contain 1 or more characters. If VariableName is an= empty string,+ then EFI_INVALID_PARAMETER = is returned.+ @param[in] VendorGuid A unique identifier for the v= endor.+ @retval EFI_SUCCESS The firmware has successfully locke= d the variable.+ @retval EFI_INVALID_PARAMETER An invalid combination of = variable name and GUID was supplied+ @retval EFI_UNSUPPORTED The se= rvice for locking variable is not ready.+ @retval EFI_NOT_FOUND T= he targeting variable for locking is not present.++**/+EFI_STATUS+EFIAPI+Lo= ckLargeVariable (+ IN CHAR16 *VariableName,+ IN E= FI_GUID *VendorGuid+ );+ #endif // _LARGE_VARIABLE_WR= ITE_LIB_H_diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVari= ableWriteLib/DxeRuntimeVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg= /Library/DxeRuntimeVariableWriteLib/DxeRuntimeVariableWriteLib.inf index 704a8ac7cc..f83090c847 100644 --- a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/D +++ xeRuntimeVariableWriteLib.inf @@ -10,7 +10,7 @@ # Using this library allows code to be written in a generic manner that ca= n be # used in DXE or SMM without modification. #-# Copyright (c) 2021, Int= el Corporation. All rights reserved.
+# Copyright (c) 2021 - 2022, Intel= Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-C= lause-Patent #@@ -24,6 +24,7 @@ MODULE_TYPE =3D DXE_RUNTIME_DRIVER LIBRARY_CLASS = =3D VariableWriteLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER = UEFI_APPLICATION UEFI_DRIVER CONSTRUCTOR =3D DxeRuntim= eVariableWriteLibConstructor+ DESTRUCTOR =3D DxeRuntim= eVariableWriteLibDestructor [Packages] MdePkg/MdePkg.dec@@ -37,13 +38,14= @@ UefiLib UefiBootServicesTableLib UefiRuntimeServicesTableLib+ Varia= blePolicyHelperLib [Guids] gEfiEventExitBootServicesGuid ## CONSUM= ES ## Event [Protocols] gEfiVariableWriteArchProtocolGuid ## CONSUMES-= gEdkiiVariableLockProtocolGuid ## CONSUMES+ gEdkiiVariablePolicyPro= tocolGuid ## CONSUMES [Depex]- gEfiVariableWriteArchProtocolGuid AND= gEdkiiVariableLockProtocolGuid+ gEfiVariableWriteArchProtocolGuid AND gEd= kiiVariablePolicyProtocolGuid--=20 2.28.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86549): https://edk2.groups.io/g/devel/message/86549 Mute This Topic: https://groups.io/mt/89041158/1492418 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [isaac.w.oram@intel.com] = -=3D-=3D-=3D-=3D-=3D-=3D