From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 39BE5740041 for ; Wed, 20 Dec 2023 09:11:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=qZCRwcJSIrKYdHL+gLgz9Efh6DSlT1dnsW1y4ReurMM=; 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=b1FrJsQBiS3PBfAD6w4TCr3MDVvYs3AHffXSkECtBjxcgD8Hhui4dBfXli6jmdbbNi6XX+Eb UW49W4WN0FhKSEkHSsfMo2FWNiW5g47c2uotknpYIeJB+KpJRtKQAFwKQlI1N4Rd0K+Wr7/uMm7 38bHEh4fHJmPhUzkoRldhVc8= X-Received: by 127.0.0.2 with SMTP id FWPVYY7687511xA67VEsSJtW; 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: qdUxeFZc2TYL48bDMNhLizasx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=b1FrJsQB; 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 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 --- 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.=0D =0D Copyright (c) 2014, Hewlett-Packard Development Company, L.P.=0D - Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
=0D Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -97,189 +97,6 @@ BOOLEAN gDispatcherRunning =3D FALSE; //=0D BOOLEAN gRequestDispatch =3D FALSE;=0D =0D -//=0D -// The global variable is defined for Loading modules at fixed address fea= ture to track the MM code=0D -// memory range usage. It is a bit mapped array in which every bit indicat= es the correspoding=0D -// memory page available or not.=0D -//=0D -GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRangeUsageBitMap = =3D NULL;=0D -=0D -/**=0D - To check memory usage bit map array to figure out if the memory range in= which the image will be loaded=0D - is available or not. If memory range is avaliable, the function will mar= k the corresponding bits to 1=0D - which indicates the memory range is used. The function is only invoked w= hen load modules at fixed address=0D - feature is enabled.=0D -=0D - @param ImageBase The base addres the image will be loade= d at.=0D - @param ImageSize The size of the image=0D -=0D - @retval EFI_SUCCESS The memory range the image will be load= ed in is available=0D - @retval EFI_NOT_FOUND The memory range the image will be load= ed in is not available=0D -**/=0D -EFI_STATUS=0D -CheckAndMarkFixLoadingMemoryUsageBitMap (=0D - IN EFI_PHYSICAL_ADDRESS ImageBase,=0D - IN UINTN ImageSize=0D - )=0D -{=0D - UINT32 MmCodePageNumber;=0D - UINT64 MmCodeSize;=0D - EFI_PHYSICAL_ADDRESS MmCodeBase;=0D - UINTN BaseOffsetPageNumber;=0D - UINTN TopOffsetPageNumber;=0D - UINTN Index;=0D -=0D - //=0D - // Build tool will calculate the smm code size and then patch the PcdLoa= dFixAddressMmCodePageNumber=0D - //=0D - MmCodePageNumber =3D 0;=0D - MmCodeSize =3D EFI_PAGES_TO_SIZE (MmCodePageNumber);=0D - MmCodeBase =3D gLoadModuleAtFixAddressMmramBase;=0D -=0D - //=0D - // If the memory usage bit map is not initialized, do it. Every bit in = the array=0D - // indicate the status of the corresponding memory page, available or no= t=0D - //=0D - if (mMmCodeMemoryRangeUsageBitMap =3D=3D NULL) {=0D - mMmCodeMemoryRangeUsageBitMap =3D AllocateZeroPool (((MmCodePageNumber= / 64) + 1) * sizeof (UINT64));=0D - }=0D -=0D - //=0D - // If the Dxe code memory range is not allocated or the bit map array al= location failed, return EFI_NOT_FOUND=0D - //=0D - if (mMmCodeMemoryRangeUsageBitMap =3D=3D NULL) {=0D - return EFI_NOT_FOUND;=0D - }=0D -=0D - //=0D - // see if the memory range for loading the image is in the MM code range= .=0D - //=0D - if ((MmCodeBase + MmCodeSize < ImageBase + ImageSize) || (MmCodeBase > = ImageBase)) {=0D - return EFI_NOT_FOUND;=0D - }=0D -=0D - //=0D - // Test if the memory is available or not.=0D - //=0D - BaseOffsetPageNumber =3D (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - = MmCodeBase));=0D - TopOffsetPageNumber =3D (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + = ImageSize - MmCodeBase));=0D - for (Index =3D BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index+= +) {=0D - if ((mMmCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64 (1, (Index = % 64))) !=3D 0) {=0D - //=0D - // This page is already used.=0D - //=0D - return EFI_NOT_FOUND;=0D - }=0D - }=0D -=0D - //=0D - // Being here means the memory range is available. So mark the bits for= the memory range=0D - //=0D - for (Index =3D BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index+= +) {=0D - mMmCodeMemoryRangeUsageBitMap[Index / 64] |=3D LShiftU64 (1, (Index % = 64));=0D - }=0D -=0D - return EFI_SUCCESS;=0D -}=0D -=0D -/**=0D - Get the fixed loading address from image header assigned by build tool. = This function only be called=0D - when Loading module at Fixed address feature enabled.=0D -=0D - @param ImageContext Pointer to the image context structure= that describes the PE/COFF=0D - image that needs to be examined by thi= s function.=0D - @retval EFI_SUCCESS An fixed loading address is assigned t= o this image by build tools .=0D - @retval EFI_NOT_FOUND The image has no assigned fixed loaddi= ng address.=0D -=0D -**/=0D -EFI_STATUS=0D -GetPeCoffImageFixLoadingAssignedAddress (=0D - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext=0D - )=0D -{=0D - UINTN SectionHeaderOffset;=0D - EFI_STATUS Status;=0D - EFI_IMAGE_SECTION_HEADER SectionHeader;=0D - EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;=0D - EFI_PHYSICAL_ADDRESS FixLoadingAddress;=0D - UINT16 Index;=0D - UINTN Size;=0D - UINT16 NumberOfSections;=0D - UINT64 ValueInSectionHeader;=0D -=0D - FixLoadingAddress =3D 0;=0D - Status =3D EFI_NOT_FOUND;=0D -=0D - //=0D - // Get PeHeader pointer=0D - //=0D - ImgHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)Ima= geContext->Handle + ImageContext->PeCoffHeaderOffset);=0D - SectionHeaderOffset =3D ImageContext->PeCoffHeaderOffset + sizeof (UINT3= 2) + sizeof (EFI_IMAGE_FILE_HEADER) +=0D - ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;=0D - NumberOfSections =3D ImgHdr->Pe32.FileHeader.NumberOfSections;=0D -=0D - //=0D - // Get base address from the first section header that doesn't point to = code section.=0D - //=0D - for (Index =3D 0; Index < NumberOfSections; Index++) {=0D - //=0D - // Read section header from file=0D - //=0D - Size =3D sizeof (EFI_IMAGE_SECTION_HEADER);=0D - Status =3D ImageContext->ImageRead (=0D - ImageContext->Handle,=0D - SectionHeaderOffset,=0D - &Size,=0D - &SectionHeader=0D - );=0D - if (EFI_ERROR (Status)) {=0D - return Status;=0D - }=0D -=0D - Status =3D EFI_NOT_FOUND;=0D -=0D - if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) =3D=3D 0)= {=0D - //=0D - // Build tool will save the address in PointerToRelocations & Pointe= rToLineNumbers fields=0D - // in the first section header that doesn't point to code section in= image header. So there=0D - // is an assumption that when the feature is enabled, if a module wi= th a loading address=0D - // assigned by tools, the PointerToRelocations & PointerToLineNumber= s fields should not be=0D - // Zero, or else, these 2 fields should be set to Zero=0D - //=0D - ValueInSectionHeader =3D ReadUnaligned64 ((UINT64 *)&SectionHeader.P= ointerToRelocations);=0D - if (ValueInSectionHeader !=3D 0) {=0D - //=0D - // Found first section header that doesn't point to code section i= n which build tool saves the=0D - // offset to SMRAM base as image base in PointerToRelocations & Po= interToLineNumbers fields=0D - //=0D - FixLoadingAddress =3D (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddre= ssMmramBase + (INT64)ValueInSectionHeader);=0D - //=0D - // Check if the memory range is available.=0D - //=0D - Status =3D CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddr= ess, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));=0D - if (!EFI_ERROR (Status)) {=0D - //=0D - // The assigned address is valid. Return the specified loading a= ddress=0D - //=0D - ImageContext->ImageAddress =3D FixLoadingAddress;=0D - }=0D - }=0D -=0D - break;=0D - }=0D -=0D - SectionHeaderOffset +=3D sizeof (EFI_IMAGE_SECTION_HEADER);=0D - }=0D -=0D - DEBUG ((=0D - DEBUG_INFO|DEBUG_LOAD,=0D - "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status= =3D %r\n",=0D - FixLoadingAddress,=0D - Status=0D - ));=0D - return Status;=0D -}=0D -=0D /**=0D Loads an EFI image into SMRAM.=0D =0D 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=0D internal structure and functions used by MmCore module.=0D =0D - Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
=0D Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -177,7 +177,6 @@ typedef struct { extern MM_CORE_PRIVATE_DATA *gMmCorePrivate;=0D extern EFI_MM_SYSTEM_TABLE gMmCoreMmst;=0D extern LIST_ENTRY gHandleList;=0D -extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase;=0D =0D /**=0D Called to initialize the memory service.=0D --=20 2.39.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-