From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.24927.1683610750751751455 for ; Mon, 08 May 2023 22:39:10 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=a4D1Ryk3; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: xiaoqiang.zhang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683610750; x=1715146750; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=9Yjh9OC+sNCMVWydSxVcSzwOHCZGDM7ztvd2HUiUBpo=; b=a4D1Ryk3OM65d9BrFv13gqkv1ycL0tfGD07SFInlI2mNHmQXH7YmrHyl uQDWdJF8m5L+x1WlS82wufUA4CaTeC/at9PQDYfqAEZjttbbNr8hiPBbh mCNCaBcJBLvok1wqJzdv9IBvtA2vIFTsNcgF+MOVYPGW2z7eh++wz55wR NDiJXzJkWfEWIlRvGn98xqnlJYcKbKFzAQi+R6T/iLQ5pDC29q9XPytRf RUBQHPsyg2V+Ew1AFvhDnrGNjcqK6uU/Fo2U9Lfk2nn2cuYmQAaZwTMNi MTYJWRcRmusVHWvka34hVVHK/HTTEOt+sReSbeuaawk10aI2BHSvJHKzp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10704"; a="330173363" X-IronPort-AV: E=Sophos;i="5.99,261,1677571200"; d="scan'208";a="330173363" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2023 22:39:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10704"; a="945135189" X-IronPort-AV: E=Sophos;i="5.99,261,1677571200"; d="scan'208";a="945135189" Received: from xzhang-desk.ccr.corp.intel.com ([10.240.102.162]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2023 22:39:00 -0700 From: Xiaoqiang Zhang To: devel@edk2.groups.io Cc: Xiaoqiang Zhang , Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [PATCH v1] MinPlatformPkg: Fix SetLargeVariable fail issue Date: Tue, 9 May 2023 13:38:34 +0800 Message-Id: <20230509053834.379-1-xiaoqiang.zhang@intel.com> X-Mailer: git-send-email 2.39.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4454 On Server platform, when the large variable "FspNvsBuffer" is already in the 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 the 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 store 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/LargeVariableWriteLib.c | 10 +++++++++- Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariableWriteLib.inf | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c index de23ae6160..da820f65b9 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c @@ -22,7 +22,7 @@ #include #include #include - +#include #include "LargeVariableCommon.h" /** @@ -270,6 +270,7 @@ SetLargeVariable ( UINT8 *OffsetPtr; UINTN BytesRemaining; UINTN SizeToSave; + UINTN BufferSize = 0; // // Check input parameters. @@ -365,6 +366,13 @@ SetLargeVariable ( // Non-Volatile storage to store the data. // RemainingVariableStorage = GetRemainingVariableStorageSpace (); + // + // Check if current variable already existed in NV storage variable space + // + Status = GetLargeVariable (VariableName, VendorGuid, &BufferSize, NULL); + if ((Status == EFI_BUFFER_TOO_SMALL) && (BufferSize != 0)) { + RemainingVariableStorage = RemainingVariableStorage + BufferSize; + } if (DataSize > RemainingVariableStorage) { DEBUG ((DEBUG_ERROR, "SetLargeVariable: Not enough NV storage space to store the data\n")); Status = EFI_OUT_OF_RESOURCES; diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariableWriteLib.inf index 2493a94596..cbc2a5d93a 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariableWriteLib.inf @@ -49,3 +49,4 @@ PrintLib VariableReadLib VariableWriteLib + LargeVariableReadLib -- 2.39.1.windows.1