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 2C79F78003C for ; Tue, 27 Feb 2024 20:27:28 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=t0n64PRfieOy812KaJrKtH9hTpq6cGMnAJW7U7dN/pY=; c=relaxed/simple; d=groups.io; h=DKIM-Filter: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:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1709065646; v=1; b=uO5WEwWMRs21rP7dzmLSRcYXEujOV1m96rhaVsDlaxHbnL176NehCxdpN+SNea7GDgisl3HN WOoXiz1oqp1uAm4YMLijAnZi2V82AVeHuGlPAQVXgdm3/jgcY7eXSFBBZGA5eOcAAGMtWxuSVYS zu7GPBtFqizZMTTxq55hpRQE= X-Received: by 127.0.0.2 with SMTP id HhjLYY7687511x6wheetsbJg; Tue, 27 Feb 2024 12:27:26 -0800 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.4630.1709065646318110247 for ; Tue, 27 Feb 2024 12:27:26 -0800 X-Received: from OSD-Desktop.redmond.corp.microsoft.com (unknown [131.107.160.171]) by linux.microsoft.com (Postfix) with ESMTPSA id D3DD720B74C1; Tue, 27 Feb 2024 12:27:25 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D3DD720B74C1 From: "Oliver Smith-Denny" To: devel@edk2.groups.io Cc: Liming Gao , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Taylor Beebe Subject: [edk2-devel][PATCH v1 1/3] MdeModulePkg: ImagePropertiesRecordLib: Use SectionAlignment for CodeSize Date: Tue, 27 Feb 2024 12:27:19 -0800 Message-Id: <20240227202721.30070-2-osde@linux.microsoft.com> In-Reply-To: <20240227202721.30070-1-osde@linux.microsoft.com> References: <20240227202721.30070-1-osde@linux.microsoft.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,osde@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: uKB5YHDkIEGRS4HJl3nJD2eNx7686176AA= 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=uO5WEwWM; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.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 When an ImageRecord is stored by ImagePropertiesRecordLib, it reports the CodeSegmentSize as the SizeOfRawData from the image. However, the image as loaded into memory is aligned to the SectionAlignment, so SizeOfRawData is under the actual size in memory. This is important, because the memory attributes table uses these image records to create its entries and it will report that the alignment of an image is incorrect, even though the actual image is correct. This was discovered on ARM64, which has a 64k runtime page granularity alignment, which is backed by a 64k section alignment for DXE_RUNTIME_DRIVERs. The runtime code and data was correctly being loaded into memory, however the memory attribute table was incorrectly reporting misaligned ranges to the OS, causing attributes to be ignored for these sections for OSes using greater than 4k pages. This patch correctly aligns the CodeSegmentSize to the SectionAlignment and the corresponding memory attribute table entries are now correctly aligned and pointing to the right places in memory. Cc: Liming Gao Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Taylor Beebe Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c= | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropert= iesRecordLib.c index e53ce086c54c..07ced0e54e38 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecord= Lib.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecord= Lib.c @@ -1090,7 +1090,7 @@ CreateImagePropertiesRecord ( ImageRecordCodeSection->Signature =3D IMAGE_PROPERTIES_RECORD_CODE= _SECTION_SIGNATURE; =20 ImageRecordCodeSection->CodeSegmentBase =3D (UINTN)ImageBase + Sec= tion[Index].VirtualAddress; - ImageRecordCodeSection->CodeSegmentSize =3D Section[Index].SizeOfR= awData; + ImageRecordCodeSection->CodeSegmentSize =3D ALIGN_VALUE (Section[I= ndex].SizeOfRawData, SectionAlignment); =20 InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSec= tion->Link); ImageRecord->CodeSegmentCount++; --=20 2.40.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116060): https://edk2.groups.io/g/devel/message/116060 Mute This Topic: https://groups.io/mt/104610770/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-