From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.9009.1683693284720110932 for ; Tue, 09 May 2023 21:34:45 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Ae4j4ES3; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: nathaniel.l.desimone@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683693284; x=1715229284; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=+1O3TE2tQt7UgKtoawVHJe4KPrX1/0BXVWEFIZhe96M=; b=Ae4j4ES3XU32CXGpIihI0jzboFs8TPWRHTytHd3e/18izxLSNy/rVxC5 XP5LPB45uzrZCCzrMO8Asm8oTN19WNES5sGzqaq2A8XUnf771z+AzPV0q UpLGjVOsq15Zp32K2MlrEPUEqevoCQBKAoYBL5yIWHskcnyt0wBH4hamc Y17KhfJPtIAT45O5+fvXICnZqwsZzpILmdJW30y7EslVw4hImUqp3YGlg KZMKBLAW/Dd146nXK/icFVoJJqRb/r1E3DkdffcORUpcPsidGKVRkwtnT DKeS0+eDEUexkhBjCjeFfpbr9zUjVWC9HFPho/WWv/nkSNzo6nDzcaT0d g==; X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="329741995" X-IronPort-AV: E=Sophos;i="5.99,263,1677571200"; d="scan'208";a="329741995" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2023 21:34:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="810991846" X-IronPort-AV: E=Sophos;i="5.99,263,1677571200"; d="scan'208";a="810991846" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga002.fm.intel.com with ESMTP; 09 May 2023 21:34:42 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 9 May 2023 21:34:42 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 9 May 2023 21:34:41 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Tue, 9 May 2023 21:34:41 -0700 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.45) 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.2507.23; Tue, 9 May 2023 21:34:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYSo+rNMDm6lYAwbf6TJsejOK/mV82xC9VnZRPzw/8ttTo+m3K/sltoAzZzUjrq6pUcXWwvoukfRr75zor6AreSY+kgRn4lxFeXtJJcaZGsM6fqPdtSSFbtgzOrSNCm5DAN0GhLDVoLqVvSoUjOHmnSVc6DCB/3zJWrWkcoIFzgECoRJHrZgizJcD+J+KCKY0EERpa987KXOFgO/MPdyz0bVqIWw53GP2X7sSIc2nl6yVpXZhFQNXgr3KMxl5/I5OJdLxzn5YRRl/zSkYF1uQF2zGpkct8Zioid48cvwIecJEMBRGxAI+/sh8tUBgsxPdzUQd4Iil1P82Wr99HCZkA== 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=LB11chQ82dnM5V7V1IF1fiy6sMaFUkdWqm2VDODz6aw=; b=bQS4aVKCcRXAnamGkWaMj6F17qUqAzo32OtvnBnVl8zogtTadAetggZ5KwryqMVM5PvldvMs3KYTHjVsJe3M0Vo1ID2JAUYmyHOyYuN3cIqN3dKINzUdSKOEU4Hzu2Sker3KkA/YYpl/0UzkhI4TA3iMUOEklliYMKyT+OsqAJHLoDMSWBFEowNbRIQqqjYuX+w7yVeM1N7efsHG4KWwLz6Z8xZVyqbQbRXGe6HisPO2Bp/wbVT2fXVwPVjExIF6KUkMYJgs36MBDHUz6j8FIvml2XAynfJ1HSEbgwo/SOwAbIjNK6l0yjkGtfonoKV8+k1Qc1FXQ3S7CU70LXrobQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW4PR11MB5821.namprd11.prod.outlook.com (2603:10b6:303:184::5) by DM4PR11MB8178.namprd11.prod.outlook.com (2603:10b6:8:18f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 04:34:39 +0000 Received: from MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::c8e1:6df6:9662:e42a]) by MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::c8e1:6df6:9662:e42a%7]) with mapi id 15.20.6363.032; Wed, 10 May 2023 04:34:39 +0000 From: "Nate DeSimone" To: "Zhang, Xiaoqiang" , "devel@edk2.groups.io" CC: "Chiu, Chasel" , "Gao, Liming" , "Dong, Eric" Subject: Re: [PATCH v1] MinPlatformPkg: Fix SetLargeVariable fail issue Thread-Topic: [PATCH v1] MinPlatformPkg: Fix SetLargeVariable fail issue Thread-Index: AQHZgjiUWWgS214fZUCrv4oINcJJua9S5NJA Date: Wed, 10 May 2023 04:34:38 +0000 Message-ID: References: <20230509053834.379-1-xiaoqiang.zhang@intel.com> In-Reply-To: <20230509053834.379-1-xiaoqiang.zhang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5821:EE_|DM4PR11MB8178:EE_ x-ms-office365-filtering-correlation-id: bcd5af6c-6888-49bb-c255-08db510fddbb x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: H+oSya+FXicpVaT+mtr8JGbAFjAzH7Re57zPCFoo4kF/jJ+c25gGfXOPlnTVpYkU2G8QyqukKiuaehDPg1jT+aEYHXZ2lsMbmIBSA/W9NziVaYsQcuCxB6+U4+s6q2Bh9BsWnkLErvgHja5LdqNmpr/NxDvcojxFEmmfvndRprUvCxKKq/24MjjH6NugsENDxa44APKNtXnV7CXEIDnEcVHsRPJhXgcXwX2qT011TuEHSpKBx06mnSaD9GSnWhq/RLeMHymaO9qtk8l8aovzTgUyKcH56418HkTEmoiRk1gmy+SVgifptUuqQIl1hLB8SnKVP2yodl43vGrDxxFdTiijfkkTHNGhSLkD9f1PIKi2b/lPN6RCmSlBFwBuZ1TOt04O+4wYa6Y4ouoPkDsBxyp0J9yCtSnA+h71O76009C/k/f+tFZpiSDTrfkh3N5Jmho1d7U7j1i0jvx/reDk0a+vUO3JcHkCHQnKQxG0/5Vjk7BvkSjvLkKXNuug8LuKWPA4PNdIqvSRtz6D53oXryczASo70fBrz/a8C9DKHxRG4/VpZaTvGcPuqelomE6pvKFEXdFIaVRNOb+R4DjkGxRh3zicpn1L3QmqgmBttqU= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5821.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(346002)(136003)(366004)(376002)(451199021)(9686003)(26005)(6506007)(107886003)(53546011)(966005)(55016003)(83380400001)(38100700002)(33656002)(86362001)(122000001)(38070700005)(186003)(82960400001)(7696005)(41300700001)(110136005)(2906002)(66556008)(54906003)(66476007)(5660300002)(8936002)(66446008)(64756008)(4326008)(316002)(8676002)(478600001)(76116006)(52536014)(66946007)(71200400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?9yzpkSbQsztD/Z3S8fqPXovjMO0TxNNtAjp3asvIvVZSD/UqmUQh8q2FjWV6?= =?us-ascii?Q?3KIkfrVj8anXBAmXp+Kn8nFKRiQ9Rex48Lu2lJLuFilK32T2vz3FKdupFxyu?= =?us-ascii?Q?8XObYyd9l+2t8a0VBHR8/92lozg1tHGe9MeTfEEz5ubOnm5FDKMaU6GCEU+u?= =?us-ascii?Q?5xDo5CHFH1L5J50CNw4qOH9p70AAkJX2vvyDzyl/uZ9vLeDuuKeePGpU4qiH?= =?us-ascii?Q?rN1ALvd+kenI8h8jj3tZrcD8/ytOIC7+4yU95/NkTjW2mwtkcTwSRG8baeJq?= =?us-ascii?Q?qn1w5h+AmtzoKJq2OR4QYJyoeNt27M/6VVHWmEfHrfnrBqW8aKe8dScX4tKm?= =?us-ascii?Q?gagDMztIxjaj3wklJ5cozgKPHF3QWkvWIWzj5IK+x79PtI+LxYbgenPwLuKQ?= =?us-ascii?Q?F9jf6shv+NqMCja/UVCVWi6Rc1E61yX7sytTRrjHTtoS8Qb6G3n6sEB/nrR/?= =?us-ascii?Q?O9JUko6mUuSyqxcjSXI85HKhN4/5hcEXcLtNF9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?Q?k8TUnUypa7Mup+d39oKZUmHb7zzOL2wchaIG6K9xlwyEY/gRttkkZHjGjgDO?= =?us-ascii?Q?wbLdKQUDFYvJpVt+G1YI18+AG436hDDqqjyxaa7cem709GpqBuHwqAM1MsG/?= =?us-ascii?Q?52SMPm6UwSaTLfUPMlvvFVafmJRXFlNfq+wreJ7FlE+xsSXqpzvXvCKVfsLS?= =?us-ascii?Q?JQsIX/ML3556/jr/yoGR8j7wydZlUhk0Mi7xerjp18aHfUV3gm+Qd8TpzZQ9?= =?us-ascii?Q?hw=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5821.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcd5af6c-6888-49bb-c255-08db510fddbb X-MS-Exchange-CrossTenant-originalarrivaltime: 10 May 2023 04:34:38.9340 (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: iO2lbzZaxPG04p43W/o4qL713i6cjGbG9vVa7mffLRAh7gBSvzYbpMU+MftAKspLGv70rBQi1VaRI5wc81ShnYMrHpj13x+91y9MVq6ooOI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB8178 Return-Path: nathaniel.l.desimone@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Great catch Xiaoqiang! Only issue I see is that for 100% correctness we will need to add a check t= o see if we are past ExitBootServices().=20 This issue is if we are in OS runtime and we try to overwrite an existing v= ariable when there isn't enough space to do so without a reclaim... the cur= rent value of the large variable will be deleted and it will be impossible = to store the new value until after a platform reset. To do this check you will need to add an AtOsRuntime() API to the VariableW= riteLib implemented in MinPlatformPkg/Library/DxeRuntimeVariableWriteLib an= d MinPlatformPkg/Library/SmmVariableWriteLib to check for OS runtime. The D= XE implementation can just be a passthrough to EfiAtRuntime() in MdePkg/Lib= rary/UefiRuntimeLib. But the SMM one will need to add a notification callba= ck for gEdkiiSmmExitBootServicesProtocolGuid and set a global variable to i= ndicate whether that event has been triggered yet. Because UefiRuntimeLib c= an only be used by DXE_RUNTIME drivers, you will need to make a separate ve= rsion of this library for boot time only DXE_DRIVERs that has an implementa= tion of AtOsRuntime() that always returns FALSE. -----Original Message----- From: Zhang, Xiaoqiang =20 Sent: Monday, May 8, 2023 10:39 PM To: devel@edk2.groups.io Cc: Zhang, Xiaoqiang ; Chiu, Chasel ; Desimone, Nathaniel L ; Gao, L= iming ; Dong, Eric Subject: [PATCH v1] MinPlatformPkg: Fix SetLargeVariable fail issue REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4454 On Server platform, when the large variable "FspNvsBuffer" is already in th= e UEFI variable store and the remaining variable storage space is less than= the large variable size. And also not in OS runtime then we need to add th= e size of the current data that will end up being replaced by the new data = to the remaining space before we decide that there is not enough space to s= tore the large variable. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Xiaoqiang Zhang --- Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWr= iteLib.c | 10 +++++++++- Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariab= leWriteLib.inf | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/Lar= geVariableWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVaria= bleLib/LargeVariableWriteLib.c index de23ae6160..da820f65b9 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVaria= bleWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVa +++ riableWriteLib.c @@ -22,7 +22,7 @@ #include #include #include - +#include #include "LargeVariableCommon.h" =20 /** @@ -270,6 +270,7 @@ SetLargeVariable ( UINT8 *OffsetPtr; UINTN BytesRemaining; UINTN SizeToSave; + UINTN BufferSize =3D 0; =20 // // Check input parameters. @@ -365,6 +366,13 @@ SetLargeVariable ( // Non-Volatile storage to store the data. // RemainingVariableStorage =3D GetRemainingVariableStorageSpace (); + // + // Check if current variable already existed in NV storage variable sp= ace + // + Status =3D GetLargeVariable (VariableName, VendorGuid, &BufferSize, NU= LL); + if ((Status =3D=3D EFI_BUFFER_TOO_SMALL) && (BufferSize !=3D 0)) { + RemainingVariableStorage =3D RemainingVariableStorage + BufferSize; + } if (DataSize > RemainingVariableStorage) { DEBUG ((DEBUG_ERROR, "SetLargeVariable: Not enough NV storage space = to store the data\n")); Status =3D EFI_OUT_OF_RESOURCES; diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/Bas= eLargeVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/BaseLarg= eVariableLib/BaseLargeVariableWriteLib.inf index 2493a94596..cbc2a5d93a 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeV= ariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLar +++ geVariableWriteLib.inf @@ -49,3 +49,4 @@ PrintLib VariableReadLib VariableWriteLib + LargeVariableReadLib -- 2.39.1.windows.1