From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.72]) by mx.groups.io with SMTP id smtpd.web09.31905.1650902751459694001 for ; Mon, 25 Apr 2022 09:05:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=vB5UhxPa; spf=pass (domain: arm.com, ip: 40.107.20.72, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X6GDf6xlfHoVQZedpAU9AAkEnq53sg8pMMsYs5LTEtk=; b=vB5UhxPa//Ly+QfAO+7yNn3HQuAgEeLsz1dSAEWujvmEfRPOBbv1MqZQLvMrZ9CypgA5eGBKTZK/d4/bpDNCgF8fpZKlcAhYQDW83E/28b6f2hL7IWpBcfJkosbqRJ36dZ+xr4o7Nr9Gnr/TKom2HzMnlxRQGpc1FXV2dYtLMX8= Received: from AS9PR06CA0314.eurprd06.prod.outlook.com (2603:10a6:20b:45b::16) by AM9PR08MB7103.eurprd08.prod.outlook.com (2603:10a6:20b:41d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.18; Mon, 25 Apr 2022 16:05:46 +0000 Received: from VE1EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45b:cafe::e8) by AS9PR06CA0314.outlook.office365.com (2603:10a6:20b:45b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Mon, 25 Apr 2022 16:05:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT035.mail.protection.outlook.com (10.152.18.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Mon, 25 Apr 2022 16:05:45 +0000 Received: ("Tessian outbound facaf1373bbd:v118"); Mon, 25 Apr 2022 16:05:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1d1aaf0eb774378e X-CR-MTA-TID: 64aa7808 Received: from 722ae3326d88.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0D70F3FA-2411-4C97-A439-97F8FA201FF0.1; Mon, 25 Apr 2022 16:05:38 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 722ae3326d88.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 25 Apr 2022 16:05:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C1QvV9sN2fFDVLJm+lB898jvxb+8y7WcierSfbkoRiGW4y76Syj11QhiqIBcaEvXGfJ1ujLGJ3AoVq3/8LuGYCsG7YfDMNY58Yt93RxQ7PtMwsFB9zLkSP+w8NR0GGe3Tl8XuISLo3Ib6hUYjUVtXEcL6jlt3QkmEKizjcPheL+hce6gB4PqqCEv3oXV5Huv66IohLZJ/n4DV+2YdAEQPzUN9PZBxZRAGYDj1GGnvRr2tyaxHAdMdflFcFUniXZeVPEjiL4UQeNR0rmKUGO6PBXc5yUEuTLepSoep+s7VPoFHfYeABAcFzJvW8EDXMSPZL2PxkV64MowRPss49GyrQ== 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=X6GDf6xlfHoVQZedpAU9AAkEnq53sg8pMMsYs5LTEtk=; b=mHLys2N9TvrBsF7+4IBRrZZxMnX6uRzaTrGj5geYvpWCybRh3eJrrAbMPsGbUQfUutlf6CWHxdl5jnoHAAbiINGVt+QzKXwIm/D8x2+MwdBOiVgvhCA2mC9CE4Kg+Qq6Z/1rvTbC4FHTgRrrB6AVHCcv8nNKz1EZgZnmC4IZWdEuAU94Q6T2ACu3bBmDTQny9kXIR5d/8xhqLFgjqntr67LW1ao9nTfdbzqSJFx4aEmcap0ZZI8yEDpKoRG4aMkUWMIJQFqXzxmkaIOU8YjFW0ISmJ7YaU4aokJjAiilvCmStI+VlQSnLFzWIsoecTC+HLJAR0eK+uUADTeQ9WWj1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X6GDf6xlfHoVQZedpAU9AAkEnq53sg8pMMsYs5LTEtk=; b=vB5UhxPa//Ly+QfAO+7yNn3HQuAgEeLsz1dSAEWujvmEfRPOBbv1MqZQLvMrZ9CypgA5eGBKTZK/d4/bpDNCgF8fpZKlcAhYQDW83E/28b6f2hL7IWpBcfJkosbqRJ36dZ+xr4o7Nr9Gnr/TKom2HzMnlxRQGpc1FXV2dYtLMX8= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by DU0PR08MB7462.eurprd08.prod.outlook.com (2603:10a6:10:355::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Mon, 25 Apr 2022 16:05:35 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::fd9a:40d3:976a:5a95]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::fd9a:40d3:976a:5a95%4]) with mapi id 15.20.5186.021; Mon, 25 Apr 2022 16:05:35 +0000 Message-ID: <04f4a048-4e39-c754-a4f7-10b3db5812bc@arm.com> Date: Mon, 25 Apr 2022 17:05:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [edk2-devel] [PATCH v4 3/8] MdeModulePkg/Variable: Consume Variable Flash Info To: devel@edk2.groups.io, mikuback@linux.microsoft.com Cc: Jian J Wang , Hao A Wu , Liming Gao , nd@arm.com References: <20220412162940.4978-1-mikuback@linux.microsoft.com> <20220412162940.4978-4-mikuback@linux.microsoft.com> From: "Sami Mujawar" In-Reply-To: <20220412162940.4978-4-mikuback@linux.microsoft.com> X-ClientProxiedBy: LO2P265CA0320.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::20) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: d153f901-ec30-4a2a-8d90-08da26d574ec X-MS-TrafficTypeDiagnostic: DU0PR08MB7462:EE_|VE1EUR03FT035:EE_|AM9PR08MB7103:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: v1FW1uIlPWQbXPduGJE35EtaBhb5UoxcU7OdypzqGsii29fG0w03K/pvztM0xm332ngDa9sGDU2AqxDRXR6q/LHDQv76z8kOropS9o0RFBuKZetXKeNPdqUbm3ulsaEQNxyUlQUDIIe1fiJP5YsRZZ4mQkfrpjG0g2zeY/oH6/gHaUgkn2/UzQlI7zjqNBNY+7Z5GKniHHD183PsXpFAeOyS7BQwtrq/YZq2oINzo0nRTW4rISdxK8kKgXrw5jTbi2pvXrxMPjChnf7OZbAf7GiEZ55K1Ghkfh0qoJzxn+Z7UGDZMN7yD35WHevPI6wExvkPaZGlc36nvViSonbFOXCEVjlQ2G/KzGs21TeoFOCrdeL02qdi6YzFEdueG0Hg4L9Q0aG7jfN1+ao0rns4W/LY0XuPuyavXQCBPbeW9PhHCj1aEEO7gyEp1rPt9mehacEku2FHaY/qhwS+PZtR9WWZfU7kmkTWjEQlV1F5IkpBVaRXSCPomKbeYCjH0grfYoRey7vfGnx2lQzvxGDTQni+MiZFzDEqkAzzfs9u5XkeW5QRgK3F3EhWVCfYxqaLSak6NEEEGSotyxCZgPj4qJQpI/ajGVfkUEjJ/wKZOgl3LtY+/ehog9LKgSkjx80+nb5lt/18sPuzq+cTUaf0fTiHTRUSfsMfzkIbB4Y+p+1dHvo6pF07TBTGXXuR/ZMnXuAE2kuPpRqZ2FQ1p6F4CboRr0hC3UDtkRWNNiRgQJqbwp0GbO1vCYBg8yIQGnFbf/XXK9keZj8HpfMsPYMYjjjYImpcK1kv/a3h6eP/fdAmIGDMRIYP5kTtx1ck4MLl X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(44832011)(8936002)(38100700002)(66556008)(8676002)(66946007)(66476007)(30864003)(5660300002)(4326008)(26005)(6506007)(53546011)(2616005)(2906002)(6512007)(186003)(45080400002)(83380400001)(6486002)(508600001)(54906003)(19627235002)(316002)(31686004)(86362001)(36756003)(31696002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7462 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 21d45d32-6afa-40c6-ed93-08da26d56ecb X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LSjTD2eNAv7JH9wBgrF2OjwM7h/6gKHz5KE4xeKMeHrQUw3JS7DSZuyo/S3meONMHsU3uBi1STi+VK5+07d1Jit8SJ538EELzscIIHBvifGPZ/P5dlVaBP6/kc41LGqWu6CaLmdM9wm2TLr04pxanU9bM8jt3OKDBbDr7zr1dLsJNgTfRmc1Q/1Bl3iRGpJ+haHrGHm15KLeNb6dfQjWI0xsl29jbiI8y8quYzV4ySk4KDwaRL8Y1zWDMoYp1I51B9GTgZ/8Z5pHMWNcKDRzFiSBVMzrY/18307hmxpN3aMj0cw40mWJk5e5w7d9V2RUkDyNQudm0vJl1dDsEckXccx7Jxjml3Mq27KVxa8yAv4AdYAoVjsaOlj2+KTE8oNOF8SVClgmgVwOd0D3sMUroHpqZMj8/Xykt0bU0AR1YE7PvEVTNHiZVy5n3fjd64GCOPvWvqcNMV2peXX05dTl+wSeU60aKRe9Qcg8PmLjNd9Qy4lvgVzIV7zcUF7N5yfgbd3kV50TA8HEm37dr959H1nZnHhfBCjo4dpaTBV1WGhefNW39WfWstI4Rbp7J2B4TNXFiDScSAWEf37ZS8ptGBBElEkT7e6tgVmKXtJkZpEduX6uTMjLr+UaKSAw46Uj8ZCfDnPTeueiJlOyl5IQIujvm558/BloLl4BpB5+969ucRYobOD/x0MRs/97xQwk6F259iYGMNk0z5MJ0k8lWf500SV+0P87MLLRPxcu4RGQ5BdkHm7WNFjjZK5dMNC1MQtT2lPgT/WhEAQnm5rsrFxXokSlsaTKRuwM+Bj7lhs= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(6486002)(82310400005)(54906003)(316002)(47076005)(83380400001)(19627235002)(81166007)(86362001)(31696002)(356005)(31686004)(70586007)(8676002)(44832011)(5660300002)(36860700001)(4326008)(36756003)(70206006)(2906002)(336012)(2616005)(186003)(6506007)(26005)(45080400002)(508600001)(6512007)(8936002)(30864003)(40460700003)(53546011)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2022 16:05:45.6489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d153f901-ec30-4a2a-8d90-08da26d574ec X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB7103 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Michael, Thank you for this patch. These changes look good to me. Reviewed-by: Sami Mujawar Regards, Sami Mujawar On 12/04/2022 05:29 pm, Michael Kubacki via groups.io wrote: > From: Michael Kubacki > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479 > > Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm > to acquire variable flash information from the Variable Flash > Information library. > > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Liming Gao > Signed-off-by: Michael Kubacki > --- > MdeModulePkg/Universal/Variable/Pei/Variable.c | 14 +++++++++----- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16 ++++++++++++---- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14 ++++++++++---- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17 +++++++++++++---- > MdeModulePkg/Universal/Variable/Pei/Variable.h | 2 ++ > MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5 ++--- > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7 ++----- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5 ++--- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5 ++--- > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5 ++--- > 10 files changed, 56 insertions(+), 34 deletions(-) > > diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c > index b36dd0de67b2..26a4c73b45a5 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c > +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c > @@ -567,11 +567,13 @@ GetVariableStore ( > OUT VARIABLE_STORE_INFO *StoreInfo > ) > { > + EFI_STATUS Status; > EFI_HOB_GUID_TYPE *GuidHob; > EFI_FIRMWARE_VOLUME_HEADER *FvHeader; > VARIABLE_STORE_HEADER *VariableStoreHeader; > EFI_PHYSICAL_ADDRESS NvStorageBase; > UINT32 NvStorageSize; > + UINT64 NvStorageSize64; > FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; > UINT32 BackUpOffset; > > @@ -591,11 +593,13 @@ GetVariableStore ( > // Emulated non-volatile variable mode is not enabled. > // > > - NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize); > - NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? > - PcdGet64 (PcdFlashNvStorageVariableBase64) : > - PcdGet32 (PcdFlashNvStorageVariableBase) > - ); > + Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64); > + ASSERT_EFI_ERROR (Status); > + > + Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize); > + // This driver currently assumes the size will be UINT32 so assert the value is safe for now. > + ASSERT_EFI_ERROR (Status); > + > ASSERT (NvStorageBase != 0); > > // > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > index 03fec3048dc4..d5c409c914d1 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c > @@ -423,6 +423,8 @@ FtwNotificationEvent ( > EFI_PHYSICAL_ADDRESS VariableStoreBase; > UINT64 VariableStoreLength; > UINTN FtwMaxBlockSize; > + UINT32 NvStorageVariableSize; > + UINT64 NvStorageVariableSize64; > > // > // Ensure FTW protocol is installed. > @@ -432,14 +434,20 @@ FtwNotificationEvent ( > return; > } > > + Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64); > + ASSERT_EFI_ERROR (Status); > + > + Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize); > + // This driver currently assumes the size will be UINT32 so assert the value is safe for now. > + ASSERT_EFI_ERROR (Status); > + > + VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength; > + > Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize); > if (!EFI_ERROR (Status)) { > - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize); > + ASSERT (NvStorageVariableSize <= FtwMaxBlockSize); > } > > - NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE; > - VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength; > - > // > // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready. > // > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > index 5e9d40b67ac2..9e2d8fe0fe0c 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > @@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore ( > EFI_PHYSICAL_ADDRESS NvStorageBase; > UINT8 *NvStorageData; > UINT32 NvStorageSize; > + UINT64 NvStorageSize64; > FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; > UINT32 BackUpOffset; > UINT32 BackUpSize; > @@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore ( > > mVariableModuleGlobal->FvbInstance = NULL; > > + Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64); > + ASSERT_EFI_ERROR (Status); > + > + Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize); > + // This driver currently assumes the size will be UINT32 so assert the value is safe for now. > + ASSERT_EFI_ERROR (Status); > + > + ASSERT (NvStorageBase != 0); > + > // > // Allocate runtime memory used for a memory copy of the FLASH region. > // Keep the memory and the FLASH in sync as updates occur. > // > - NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize); > NvStorageData = AllocateRuntimeZeroPool (NvStorageSize); > if (NvStorageData == NULL) { > return EFI_OUT_OF_RESOURCES; > } > > - NvStorageBase = NV_STORAGE_VARIABLE_BASE; > - ASSERT (NvStorageBase != 0); > - > // > // Copy NV storage data to the memory buffer. > // > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > index 517cae7b00f8..5253c328dcd9 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > @@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent ( > EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; > EFI_PHYSICAL_ADDRESS NvStorageVariableBase; > UINTN FtwMaxBlockSize; > + UINT32 NvStorageVariableSize; > + UINT64 NvStorageVariableSize64; > > if (mVariableModuleGlobal->FvbInstance != NULL) { > return EFI_SUCCESS; > @@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent ( > return Status; > } > > + Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64); > + ASSERT_EFI_ERROR (Status); > + > + Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize); > + // This driver currently assumes the size will be UINT32 so assert the value is safe for now. > + ASSERT_EFI_ERROR (Status); > + > + ASSERT (NvStorageVariableBase != 0); > + VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength; > + > Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize); > if (!EFI_ERROR (Status)) { > - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize); > + ASSERT (NvStorageVariableSize <= FtwMaxBlockSize); > } > > - NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE; > - VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength; > - > // > // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready. > // > diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePkg/Universal/Variable/Pei/Variable.h > index 7f9ad5bfc357..51effbf79987 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/Variable.h > +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h > @@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include > #include > #include > +#include > +#include > > #include > #include > diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > index 7cbdd2385e8f..7264a24bdf71 100644 > --- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > +++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > @@ -39,6 +39,8 @@ [LibraryClasses] > DebugLib > PeiServicesTablePointerLib > PeiServicesLib > + SafeIntLib > + VariableFlashInfoLib > > [Guids] > ## CONSUMES ## GUID # Variable store header > @@ -59,9 +61,6 @@ [Ppis] > gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES > > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## SOMETIMES_CONSUMES > > [Depex] > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > index 31e408976a35..a668abb82b15 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > @@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > #include "PrivilegePolymorphic.h" > > -#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\ > - (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \ > - PcdGet64 (PcdFlashNvStorageVariableBase64) : \ > - PcdGet32 (PcdFlashNvStorageVariableBase)) > - > #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\ > EFI_VARIABLE_BOOTSERVICE_ACCESS | \ > EFI_VARIABLE_RUNTIME_ACCESS | \ > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > index c9434df631ee..3858adf6739d 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > @@ -71,8 +71,10 @@ [LibraryClasses] > TpmMeasurementLib > AuthVariableLib > VarCheckLib > + VariableFlashInfoLib > VariablePolicyLib > VariablePolicyHelperLib > + SafeIntLib > > [Protocols] > gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES > @@ -125,9 +127,6 @@ [Guids] > gEfiImageSecurityDatabaseGuid > > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > index eaa97a01c6e5..8c552b87e080 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > @@ -80,8 +80,10 @@ [LibraryClasses] > AuthVariableLib > VarCheckLib > UefiBootServicesTableLib > + VariableFlashInfoLib > VariablePolicyLib > VariablePolicyHelperLib > + SafeIntLib > > [Protocols] > gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES > @@ -127,9 +129,6 @@ [Guids] > gEdkiiVarErrorFlagGuid > > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > index d8c4f77e7f1f..f09bed40cf51 100644 > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > @@ -73,9 +73,11 @@ [LibraryClasses] > HobLib > MemoryAllocationLib > MmServicesTableLib > + SafeIntLib > StandaloneMmDriverEntryPoint > SynchronizationLib > VarCheckLib > + VariableFlashInfoLib > VariablePolicyLib > VariablePolicyHelperLib > > @@ -120,9 +122,6 @@ [Guids] > gEdkiiVarErrorFlagGuid > > [Pcd] > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES