From nobody Wed May 15 16:33:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112752+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112752+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1703063478; cv=none; d=zohomail.com; s=zohoarc; b=Z4c8ZrwqIoe40ffJmXwvvqjJdjsfr4Iqc8MaQloovPHGZmbLvVc3gpuzYTwGiFYOHhAldRg0HR0XePVZddbw5M1KzGDpJttUWLpzey3yYeaB4YmstKuuItOGMLnlQzDiq2/fEw/HcV40qT+VdlKFnNAPn/QpXQh6es9sgkP7wDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703063478; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=bHl6OZQPnwrMXRycgh9bhnDkreGrNUgx6YHgRxwb/Pk=; b=KnVv45X4LoiLcBjl+0VsVphEU51ggL5PI1PGeWGPxE0M0BcUFWS5dg7gFc/NYXxSIOpKsBnzH7YNSGJ9WJuTyRJ8ObOFlh71Y8cxrIMS4bfyudjmrVBBVML1Ibr4JQ7HVbyx7fG88gx83pMHqMUMGRtZPYlcTa0LtdjVnfz55OE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112752+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1703063478067675.7121570486726; Wed, 20 Dec 2023 01:11:18 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=bnzEz9BymqAwQDaF+xsZtyTEtEAQHK9aEHU9QLJEFUA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1703063477; v=1; b=ilGSSAyqiA4vtMg7Hjy3jIvRy8qYXH2IYaMiuJjr/D7yHPWnQzHUIM0Zc+XllHmUhs5+D2eC K78SgRsMs1tMgioyPLUcSBrju+czQizVQhRFO6WR4Nf5HwhIg96XSa8FFE9tOuF4bZsdZCBimt/ 7UxuvLkh/vg/vPctKRZHlH4I= X-Received: by 127.0.0.2 with SMTP id u2MoYY1788612xQTfpNU39gJ; Wed, 20 Dec 2023 01:11:17 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.18175.1703063476570822769 for ; Wed, 20 Dec 2023 01:11:17 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="395513221" X-IronPort-AV: E=Sophos;i="6.04,290,1695711600"; d="scan'208";a="395513221" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2023 01:11:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="805192500" X-IronPort-AV: E=Sophos;i="6.04,291,1695711600"; d="scan'208";a="805192500" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.158.139]) by orsmga008.jf.intel.com with ESMTP; 20 Dec 2023 01:11:14 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar Subject: [edk2-devel] [PATCH] StandaloneMmPkg/Core: Remove dead code Date: Wed, 20 Dec 2023 17:10:32 +0800 Message-Id: <20231220091032.1985-1-ray.ni@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 Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: nVzlfLHpIoYHnlbV6djPdjhkx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1703063480227100003 Content-Type: text/plain; charset="utf-8" Load-module-at-fixed-address feature does not work in standalone MM core. The patch removes the 2 dead functions and related global variables that are related to the feature. Signed-off-by: Ray Ni Cc: Ard Biesheuvel Cc: Sami Mujawar Reviewed-by: Ard Biesheuvel --- StandaloneMmPkg/Core/Dispatcher.c | 185 +----------------------- StandaloneMmPkg/Core/StandaloneMmCore.h | 3 +- 2 files changed, 2 insertions(+), 186 deletions(-) diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispa= tcher.c index 7b4a3c4c55..6d43e53851 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -29,7 +29,7 @@ Depex - Dependency Expresion. =20 Copyright (c) 2014, Hewlett-Packard Development Company, L.P. - Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -97,189 +97,6 @@ BOOLEAN gDispatcherRunning =3D FALSE; // BOOLEAN gRequestDispatch =3D FALSE; =20 -// -// The global variable is defined for Loading modules at fixed address fea= ture to track the MM code -// memory range usage. It is a bit mapped array in which every bit indicat= es the correspoding -// memory page available or not. -// -GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRangeUsageBitMap = =3D NULL; - -/** - To check memory usage bit map array to figure out if the memory range in= which the image will be loaded - is available or not. If memory range is avaliable, the function will mar= k the corresponding bits to 1 - which indicates the memory range is used. The function is only invoked w= hen load modules at fixed address - feature is enabled. - - @param ImageBase The base addres the image will be loade= d at. - @param ImageSize The size of the image - - @retval EFI_SUCCESS The memory range the image will be load= ed in is available - @retval EFI_NOT_FOUND The memory range the image will be load= ed in is not available -**/ -EFI_STATUS -CheckAndMarkFixLoadingMemoryUsageBitMap ( - IN EFI_PHYSICAL_ADDRESS ImageBase, - IN UINTN ImageSize - ) -{ - UINT32 MmCodePageNumber; - UINT64 MmCodeSize; - EFI_PHYSICAL_ADDRESS MmCodeBase; - UINTN BaseOffsetPageNumber; - UINTN TopOffsetPageNumber; - UINTN Index; - - // - // Build tool will calculate the smm code size and then patch the PcdLoa= dFixAddressMmCodePageNumber - // - MmCodePageNumber =3D 0; - MmCodeSize =3D EFI_PAGES_TO_SIZE (MmCodePageNumber); - MmCodeBase =3D gLoadModuleAtFixAddressMmramBase; - - // - // If the memory usage bit map is not initialized, do it. Every bit in = the array - // indicate the status of the corresponding memory page, available or not - // - if (mMmCodeMemoryRangeUsageBitMap =3D=3D NULL) { - mMmCodeMemoryRangeUsageBitMap =3D AllocateZeroPool (((MmCodePageNumber= / 64) + 1) * sizeof (UINT64)); - } - - // - // If the Dxe code memory range is not allocated or the bit map array al= location failed, return EFI_NOT_FOUND - // - if (mMmCodeMemoryRangeUsageBitMap =3D=3D NULL) { - return EFI_NOT_FOUND; - } - - // - // see if the memory range for loading the image is in the MM code range. - // - if ((MmCodeBase + MmCodeSize < ImageBase + ImageSize) || (MmCodeBase > = ImageBase)) { - return EFI_NOT_FOUND; - } - - // - // Test if the memory is available or not. - // - BaseOffsetPageNumber =3D (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - = MmCodeBase)); - TopOffsetPageNumber =3D (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + = ImageSize - MmCodeBase)); - for (Index =3D BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index+= +) { - if ((mMmCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64 (1, (Index = % 64))) !=3D 0) { - // - // This page is already used. - // - return EFI_NOT_FOUND; - } - } - - // - // Being here means the memory range is available. So mark the bits for= the memory range - // - for (Index =3D BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index+= +) { - mMmCodeMemoryRangeUsageBitMap[Index / 64] |=3D LShiftU64 (1, (Index % = 64)); - } - - return EFI_SUCCESS; -} - -/** - Get the fixed loading address from image header assigned by build tool. = This function only be called - when Loading module at Fixed address feature enabled. - - @param ImageContext Pointer to the image context structure= that describes the PE/COFF - image that needs to be examined by thi= s function. - @retval EFI_SUCCESS An fixed loading address is assigned t= o this image by build tools . - @retval EFI_NOT_FOUND The image has no assigned fixed loaddi= ng address. - -**/ -EFI_STATUS -GetPeCoffImageFixLoadingAssignedAddress ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - UINTN SectionHeaderOffset; - EFI_STATUS Status; - EFI_IMAGE_SECTION_HEADER SectionHeader; - EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr; - EFI_PHYSICAL_ADDRESS FixLoadingAddress; - UINT16 Index; - UINTN Size; - UINT16 NumberOfSections; - UINT64 ValueInSectionHeader; - - FixLoadingAddress =3D 0; - Status =3D EFI_NOT_FOUND; - - // - // Get PeHeader pointer - // - ImgHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)Ima= geContext->Handle + ImageContext->PeCoffHeaderOffset); - SectionHeaderOffset =3D ImageContext->PeCoffHeaderOffset + sizeof (UINT3= 2) + sizeof (EFI_IMAGE_FILE_HEADER) + - ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader; - NumberOfSections =3D ImgHdr->Pe32.FileHeader.NumberOfSections; - - // - // Get base address from the first section header that doesn't point to = code section. - // - for (Index =3D 0; Index < NumberOfSections; Index++) { - // - // Read section header from file - // - Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); - Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - SectionHeaderOffset, - &Size, - &SectionHeader - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D EFI_NOT_FOUND; - - if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) =3D=3D 0)= { - // - // Build tool will save the address in PointerToRelocations & Pointe= rToLineNumbers fields - // in the first section header that doesn't point to code section in= image header. So there - // is an assumption that when the feature is enabled, if a module wi= th a loading address - // assigned by tools, the PointerToRelocations & PointerToLineNumber= s fields should not be - // Zero, or else, these 2 fields should be set to Zero - // - ValueInSectionHeader =3D ReadUnaligned64 ((UINT64 *)&SectionHeader.P= ointerToRelocations); - if (ValueInSectionHeader !=3D 0) { - // - // Found first section header that doesn't point to code section i= n which build tool saves the - // offset to SMRAM base as image base in PointerToRelocations & Po= interToLineNumbers fields - // - FixLoadingAddress =3D (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddre= ssMmramBase + (INT64)ValueInSectionHeader); - // - // Check if the memory range is available. - // - Status =3D CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddr= ess, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment)); - if (!EFI_ERROR (Status)) { - // - // The assigned address is valid. Return the specified loading a= ddress - // - ImageContext->ImageAddress =3D FixLoadingAddress; - } - } - - break; - } - - SectionHeaderOffset +=3D sizeof (EFI_IMAGE_SECTION_HEADER); - } - - DEBUG (( - DEBUG_INFO|DEBUG_LOAD, - "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status= =3D %r\n", - FixLoadingAddress, - Status - )); - return Status; -} - /** Loads an EFI image into SMRAM. =20 diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.h b/StandaloneMmPkg/Core= /StandaloneMmCore.h index da23b8dc3c..3d71bc84f8 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.h +++ b/StandaloneMmPkg/Core/StandaloneMmCore.h @@ -2,7 +2,7 @@ The internal header file includes the common header files, defines internal structure and functions used by MmCore module. =20 - Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -177,7 +177,6 @@ typedef struct { extern MM_CORE_PRIVATE_DATA *gMmCorePrivate; extern EFI_MM_SYSTEM_TABLE gMmCoreMmst; extern LIST_ENTRY gHandleList; -extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase; =20 /** Called to initialize the memory service. --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112752): https://edk2.groups.io/g/devel/message/112752 Mute This Topic: https://groups.io/mt/103278283/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-