From nobody Mon May 6 11:58:41 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+78893+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+78893+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=posteo.de ARC-Seal: i=1; a=rsa-sha256; t=1628451642; cv=none; d=zohomail.com; s=zohoarc; b=kaUoyb9CtJ92Zgf4ZkTY6mSFpuQ6KIwvbfDroCB3SLAKS3E8/vjT4VcC4+n8UvZCV7GNx4R7jjXhC7USUbXwjPuct+LZVTm9nxLA85Y7PPlHjiA93rIhv75+LuINvvaf3nEZ/cvbWoIxIGgb8Si6/AkOG+pF6gJtHSScL6OCpwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628451642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=iRXeEEwdTDbptObNim2dKnDlwMyhVPRx4qiUyR1fmqY=; b=P/g6oqVqNA5z6fefxlmpTVZeE8D4bNMFB9KVXDzjdT1XNhK7p/wlRpqCBiaW0Qb0KfdrKWY9ZP/Y9WsamGXq+QokDgcKa3maomhAekAaDocCf/xGZEyIl26Ln348ZkxCIv+hwxxIUa5PyQA3n7f6UFJc3J3ecl4bzqs8kjEvEtk= 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+78893+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 1628451642102157.6997731058409; Sun, 8 Aug 2021 12:40:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BWzqYY1788612x2WZRvgJAd2; Sun, 08 Aug 2021 12:40:41 -0700 X-Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by mx.groups.io with SMTP id smtpd.web11.13766.1628451640783311574 for ; Sun, 08 Aug 2021 12:40:41 -0700 X-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 1DCFD240107 for ; Sun, 8 Aug 2021 21:40:39 +0200 (CEST) X-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GjV1f3ZHfz6tmF; Sun, 8 Aug 2021 21:40:38 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh , Vitaly Cheptsov Subject: [edk2-devel] [PATCH] StandaloneMmPkg/StandaloneMmCore: Drop unused fixed address feature Date: Sun, 8 Aug 2021 19:39:51 +0000 Message-Id: <398e430d3f91d0ebdce59bb62968eb33ca91ac07.1628359181.git.mhaeuser@posteo.de> In-Reply-To: <5df11a13422732b9c03c120775a2b4dd0a49182f.1628444003.git.mhaeuser@posteo.de> References: <5df11a13422732b9c03c120775a2b4dd0a49182f.1628444003.git.mhaeuser@posteo.de> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,mhaeuser@posteo.de X-Gm-Message-State: fWjHqP5aYE153rMvm7GtvRWbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628451641; bh=PQJB++/D7tpuizwHT0D8hzpauW120c5tdFBogablkrI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=sBu5i0JsORSQdLJrdTwIR/x7i1/eCrhOF2uHAEHviqUhikNfGxtQrpBwBnO/cAaM3re b9drED4APun5aBhoqnD7rDtZ5Tv7FNTMNEQwnktSL1y34pqWQjluf77PwNcYNSHbnoZmy duEtkwjnM+b1dYBWW80dipsTTeLX0R6cZkY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628451643822100065 Content-Type: text/plain; charset="utf-8" StandaloneMmCore does not support fixed load addresses for modules. Remove the unreferenced functions that are used in other dispatchers to implement this feature. Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Jiewen Yao Cc: Supreeth Venkatesh Cc: Vitaly Cheptsov Signed-off-by: Marvin H=C3=A4user --- StandaloneMmPkg/Core/Dispatcher.c | 167 -------------------- 1 file changed, 167 deletions(-) diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispa= tcher.c index 7e4bf5e94025..d5631f47be68 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -109,173 +109,6 @@ BOOLEAN gRequestDispatch =3D FALSE; // GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRange= UsageBitMap=3DNULL; =20 -/** - 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 > Im= ageBase) { - 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* )ImageContext->Ha= ndle + 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.Po= interToRelocations); - 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 modul= e at fixed address %x, Status =3D %r\n", - FixLoadingAddress, Status)); - return Status; -} /** Loads an EFI image into SMRAM. =20 --=20 2.31.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 (#78893): https://edk2.groups.io/g/devel/message/78893 Mute This Topic: https://groups.io/mt/84754067/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-