From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 8A2D9740054 for ; Fri, 17 May 2024 09:49:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=+TbFcOovlhXiVOeaXzkEDejNz/iJSC0is5kLQ4xD160=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1715939393; v=1; b=CS0AXo1OSUPVuN0EhsvAPqKvvs0schoYQbgf/Gv5yExee1S6PcinHfhu2ZS+mvIMGaXzJwwW WDoBciWimVDdSD4msE3HnhbdKNTEEswbE7IBwWKYz3eGsYTBUJfbhWWE8b095JEv9SH758tt3TQ 7vzYgRN3ckLq2famgZRmu+McXYTapzWvc0mzUgJCcclX9WXM8uGS4zHWeh7MnkBNV5EOwRXYh0j LMY59iD4X0kYSElwIMjqY31l8mizqwSifrz69BCCkkJWZS2gTTmBwo4jpj+eEvlXkQvrcVx2BPU +ofvHd4lg1pYuNXsRfq41orh4EAAk0nlp+3kj6lQpEXLQ== X-Received: by 127.0.0.2 with SMTP id WQ0tYY7687511x3c1gPRN9gF; Fri, 17 May 2024 02:49:53 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mx.groups.io with SMTP id smtpd.web10.36016.1715939370910548931 for ; Fri, 17 May 2024 02:49:52 -0700 X-CSE-ConnectionGUID: HgzcNpN+SOamYYX0OuodMQ== X-CSE-MsgGUID: 9jfZ3N16SoCuZwbUJ0yGyA== X-IronPort-AV: E=McAfee;i="6600,9927,11074"; a="11570309" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="11570309" X-Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 02:49:52 -0700 X-CSE-ConnectionGUID: hgmRuy/nRT+6wgGuqH6S+w== X-CSE-MsgGUID: aD1LzpVKQkezVRVNA1yuag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31739375" X-Received: from unknown (HELO shwdeopenlab702.ccr.corp.intel.com) ([10.239.55.43]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 02:49:51 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Ray Ni , Liming Gao , Jiaxin Wu Subject: [edk2-devel] [PATCH 9/9] MdeModulePkg:Add global variable mVariableRtCacheInfo Date: Fri, 17 May 2024 17:49:17 +0800 Message-Id: <20240517094917.513-10-dun.tan@intel.com> In-Reply-To: <20240517094917.513-1-dun.tan@intel.com> References: <20240517094917.513-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Fri, 17 May 2024 02:49:52 -0700 Resent-From: dun.tan@intel.com Reply-To: devel@edk2.groups.io,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gHv8lZHpOiOmDUvcXq5MTR4vx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=CS0AXo1O; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io Add global variable mVariableRtCacheInfo to save the content in gEdkiiVariableRuntimeCacheInfoHobGuid. With this new global variable, 7 global variables can be removed. Signed-off-by: Dun Tan Cc: Ray Ni Cc: Liming Gao Cc: Jiaxin Wu --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 97 +++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------- 1 file changed, 41 insertions(+), 56 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index 6efe5cee10..de39462d68 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -44,26 +44,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "PrivilegePolymorphic.h" #include "VariableParsing.h" -EFI_HANDLE mHandle = NULL; -EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL; -EFI_EVENT mVirtualAddressChangeEvent = NULL; -EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL; -UINT8 *mVariableBuffer = NULL; -UINT8 *mVariableBufferPhysical = NULL; -VARIABLE_INFO_ENTRY *mVariableInfo = NULL; -VARIABLE_STORE_HEADER *mVariableRuntimeHobCacheBuffer = NULL; -VARIABLE_STORE_HEADER *mVariableRuntimeNvCacheBuffer = NULL; -VARIABLE_STORE_HEADER *mVariableRuntimeVolatileCacheBuffer = NULL; +EFI_HANDLE mHandle = NULL; +EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL; +EFI_EVENT mVirtualAddressChangeEvent = NULL; +EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL; +UINT8 *mVariableBuffer = NULL; +UINT8 *mVariableBufferPhysical = NULL; +VARIABLE_INFO_ENTRY *mVariableInfo = NULL; UINTN mVariableBufferSize; -UINTN mVariableRuntimeHobCacheBufferSize; UINTN mVariableBufferPayloadSize; -BOOLEAN *mVariableRuntimeCachePendingUpdate; -BOOLEAN *mVariableRuntimeCacheReadLock; BOOLEAN mVariableAuthFormat; -BOOLEAN *mHobFlushComplete; EFI_LOCK mVariableServicesLock; EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock; EDKII_VAR_CHECK_PROTOCOL mVarCheck; +VARIABLE_RUNTIME_CACHE_INFO mVariableRtCacheInfo; /** The logic to initialize the VariablePolicy engine is in its own file. @@ -500,21 +494,21 @@ CheckForRuntimeCacheSync ( VOID ) { - if (*mVariableRuntimeCachePendingUpdate) { + if (mVariableRtCacheInfo.CacheInfoFlag->PendingUpdate) { SyncRuntimeCache (); } - ASSERT (!(*mVariableRuntimeCachePendingUpdate)); + ASSERT (!(mVariableRtCacheInfo.CacheInfoFlag->PendingUpdate)); // // The HOB variable data may have finished being flushed in the runtime cache sync update // - if ((*mHobFlushComplete) && (mVariableRuntimeHobCacheBuffer != NULL)) { + if ((mVariableRtCacheInfo.CacheInfoFlag->HobFlushComplete) && (mVariableRtCacheInfo.RuntimeHobCacheBuffer != 0)) { if (!EfiAtRuntime ()) { - FreePages (mVariableRuntimeHobCacheBuffer, EFI_SIZE_TO_PAGES (mVariableRuntimeHobCacheBufferSize)); + FreePages ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer, mVariableRtCacheInfo.RuntimeHobCachePages); } - mVariableRuntimeHobCacheBuffer = NULL; + mVariableRtCacheInfo.RuntimeHobCacheBuffer = 0; } } @@ -565,20 +559,20 @@ FindVariableInRuntimeCache ( // a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime // cache read lock should always be free when entering this function. // - ASSERT (!(*mVariableRuntimeCacheReadLock)); + ASSERT (!(mVariableRtCacheInfo.CacheInfoFlag->ReadLock)); - *mVariableRuntimeCacheReadLock = TRUE; + mVariableRtCacheInfo.CacheInfoFlag->ReadLock = TRUE; CheckForRuntimeCacheSync (); - if (!(*mVariableRuntimeCachePendingUpdate)) { + if (!(mVariableRtCacheInfo.CacheInfoFlag->PendingUpdate)) { // // 0: Volatile, 1: HOB, 2: Non-Volatile. // The index and attributes mapping must be kept in this order as FindVariable // makes use of this mapping to implement search algorithm. // - VariableStoreList[VariableStoreTypeVolatile] = mVariableRuntimeVolatileCacheBuffer; - VariableStoreList[VariableStoreTypeHob] = mVariableRuntimeHobCacheBuffer; - VariableStoreList[VariableStoreTypeNv] = mVariableRuntimeNvCacheBuffer; + VariableStoreList[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer; + VariableStoreList[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer; + VariableStoreList[VariableStoreTypeNv] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer; for (StoreType = (VARIABLE_STORE_TYPE)0; StoreType < VariableStoreTypeMax; StoreType++) { if (VariableStoreList[StoreType] == NULL) { @@ -630,7 +624,7 @@ Done: } } - *mVariableRuntimeCacheReadLock = FALSE; + mVariableRtCacheInfo.CacheInfoFlag->ReadLock = FALSE; return Status; } @@ -853,20 +847,20 @@ GetNextVariableNameInRuntimeCache ( // a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime // cache read lock should always be free when entering this function. // - ASSERT (!(*mVariableRuntimeCacheReadLock)); + ASSERT (!(mVariableRtCacheInfo.CacheInfoFlag->ReadLock)); CheckForRuntimeCacheSync (); - *mVariableRuntimeCacheReadLock = TRUE; - if (!(*mVariableRuntimeCachePendingUpdate)) { + mVariableRtCacheInfo.CacheInfoFlag->ReadLock = TRUE; + if (!(mVariableRtCacheInfo.CacheInfoFlag->PendingUpdate)) { // // 0: Volatile, 1: HOB, 2: Non-Volatile. // The index and attributes mapping must be kept in this order as FindVariable // makes use of this mapping to implement search algorithm. // - VariableStoreHeader[VariableStoreTypeVolatile] = mVariableRuntimeVolatileCacheBuffer; - VariableStoreHeader[VariableStoreTypeHob] = mVariableRuntimeHobCacheBuffer; - VariableStoreHeader[VariableStoreTypeNv] = mVariableRuntimeNvCacheBuffer; + VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer; + VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer; + VariableStoreHeader[VariableStoreTypeNv] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer; Status = VariableServiceGetNextVariableInternal ( VariableName, @@ -890,7 +884,7 @@ GetNextVariableNameInRuntimeCache ( } } - *mVariableRuntimeCacheReadLock = FALSE; + mVariableRtCacheInfo.CacheInfoFlag->ReadLock = FALSE; return Status; } @@ -1345,9 +1339,9 @@ VariableAddressChangeEvent ( { EfiConvertPointer (0x0, (VOID **)&mVariableBuffer); EfiConvertPointer (0x0, (VOID **)&mMmCommunication2); - EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeHobCacheBuffer); - EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeNvCacheBuffer); - EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeVolatileCacheBuffer); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeHobCacheBuffer); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeNvCacheBuffer); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeVolatileCacheBuffer); } /** @@ -1576,17 +1570,10 @@ InitVariableCache ( (AllocatedVolatileCacheSize >= ExpectedVolatileCacheSize) ); - mVariableRuntimeHobCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeHobCacheBuffer; - mVariableRuntimeNvCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeNvCacheBuffer; - mVariableRuntimeVolatileCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeVolatileCacheBuffer; - mVariableRuntimeCachePendingUpdate = &VariableRuntimeCacheHob->CacheInfoFlag->PendingUpdate; - mVariableRuntimeCacheReadLock = &VariableRuntimeCacheHob->CacheInfoFlag->ReadLock; - mHobFlushComplete = &VariableRuntimeCacheHob->CacheInfoFlag->HobFlushComplete; - mVariableRuntimeHobCacheBufferSize = AllocatedHobCacheSize; - - InitVariableStoreHeader (mVariableRuntimeHobCacheBuffer, AllocatedHobCacheSize); - InitVariableStoreHeader (mVariableRuntimeNvCacheBuffer, AllocatedNvCacheSize); - InitVariableStoreHeader (mVariableRuntimeVolatileCacheBuffer, AllocatedVolatileCacheSize); + CopyMem (&mVariableRtCacheInfo, VariableRuntimeCacheHob, sizeof (VARIABLE_RUNTIME_CACHE_INFO)); + InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer, AllocatedHobCacheSize); + InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer, AllocatedNvCacheSize); + InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer, AllocatedVolatileCacheSize); } return Status; @@ -1637,12 +1624,12 @@ SendRuntimeVariableCacheContextToSmm ( SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT; SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data; - SmmRuntimeVarCacheContext->RuntimeHobCache = mVariableRuntimeHobCacheBuffer; - SmmRuntimeVarCacheContext->RuntimeVolatileCache = mVariableRuntimeVolatileCacheBuffer; - SmmRuntimeVarCacheContext->RuntimeNvCache = mVariableRuntimeNvCacheBuffer; - SmmRuntimeVarCacheContext->PendingUpdate = mVariableRuntimeCachePendingUpdate; - SmmRuntimeVarCacheContext->ReadLock = mVariableRuntimeCacheReadLock; - SmmRuntimeVarCacheContext->HobFlushComplete = mHobFlushComplete; + SmmRuntimeVarCacheContext->RuntimeHobCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer; + SmmRuntimeVarCacheContext->RuntimeVolatileCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer; + SmmRuntimeVarCacheContext->RuntimeNvCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer; + SmmRuntimeVarCacheContext->PendingUpdate = &mVariableRtCacheInfo.CacheInfoFlag->PendingUpdate; + SmmRuntimeVarCacheContext->ReadLock = &mVariableRtCacheInfo.CacheInfoFlag->ReadLock; + SmmRuntimeVarCacheContext->HobFlushComplete = &mVariableRtCacheInfo.CacheInfoFlag->HobFlushComplete; // // Send data to SMM. @@ -1712,9 +1699,7 @@ SmmVariableReady ( } if (EFI_ERROR (Status)) { - mVariableRuntimeHobCacheBuffer = NULL; - mVariableRuntimeNvCacheBuffer = NULL; - mVariableRuntimeVolatileCacheBuffer = NULL; + ZeroMem (&mVariableRtCacheInfo, sizeof (VARIABLE_RUNTIME_CACHE_INFO)); } ASSERT_EFI_ERROR (Status); -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119026): https://edk2.groups.io/g/devel/message/119026 Mute This Topic: https://groups.io/mt/106150807/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-