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 68CF094134C for ; Tue, 12 Mar 2024 08:33:57 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=vGpETxU6xcutUw/htiFQMCDWlEkvXw2qT30WYVUbE7E=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20240206; t=1710232436; v=1; b=fOArBP62wRQSNMmo992sKuliBUOoivIWwINcRAKBo08bi2+BBtOugNe7bD6iepJxaPOJKGXB 50rpPm0RY8uppJfDfpCZvyWr/5PshBm0u6lEtRWGFf88kzSvvFPYBOG7XrRU/JYca0FlVP675CY cSxQ5o5j3pk0BPK+hWamijUUGj5L77U8Opq/ntFICSpNOzBNYIcJSXmbgWLRrEZN1O7vHlhzfzq MUenqZFKhnlt99LmaSEAba8mturf0jQL40NBv5I5gEAstAhaslYUAcHmVL+iuyJ6vIFw0UaYdYy P1W0vCoxaoE+dWdCytJHNV/icphF+SrDUcTM+5HNs9SlA== X-Received: by 127.0.0.2 with SMTP id JJWiYY7687511xSKqRqgdfVu; Tue, 12 Mar 2024 01:33:56 -0700 X-Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by mx.groups.io with SMTP id smtpd.web11.3878.1710232435121178870 for ; Tue, 12 Mar 2024 01:33:55 -0700 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D2638CE16D0 for ; Tue, 12 Mar 2024 08:33:51 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19EACC43399 for ; Tue, 12 Mar 2024 08:33:51 +0000 (UTC) X-Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51325c38d10so6170912e87.1 for ; Tue, 12 Mar 2024 01:33:51 -0700 (PDT) X-Gm-Message-State: nDtbMWLFjvBgYhfNFyI7ck42x7686176AA= X-Google-Smtp-Source: AGHT+IG5f/8XwJmSA27UMSphl5HU+NddTxheu6pfgR259GyZ8rJs3Jvzz00beCx8PvTnE6V45hlDKELxeXHOU0Lu2w8= X-Received: by 2002:ac2:55a2:0:b0:513:5a00:192e with SMTP id y2-20020ac255a2000000b005135a00192emr2590134lfg.27.1710232429325; Tue, 12 Mar 2024 01:33:49 -0700 (PDT) MIME-Version: 1.0 References: <20240311212924.11633-1-osde@linux.microsoft.com> <20240311212924.11633-2-osde@linux.microsoft.com> In-Reply-To: <20240311212924.11633-2-osde@linux.microsoft.com> From: "Ard Biesheuvel" Date: Tue, 12 Mar 2024 09:33:38 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v2 1/3] MdeModulePkg: ImagePropertiesRecordLib: Use SectionAlignment for CodeSize To: Oliver Smith-Denny Cc: devel@edk2.groups.io, Liming Gao , Leif Lindholm , Sami Mujawar , Taylor Beebe 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: Tue, 12 Mar 2024 01:33:55 -0700 Reply-To: devel@edk2.groups.io,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=fOArBP62; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (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 On Mon, 11 Mar 2024 at 22:29, Oliver Smith-Denny wrote: > > 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 | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > Reviewed-by: Ard Biesheuvel > diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > index e53ce086c54c..763a8d65d565 100644 > --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > @@ -1090,7 +1090,9 @@ CreateImagePropertiesRecord ( > ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE; > > ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageBase + Section[Index].VirtualAddress; > - ImageRecordCodeSection->CodeSegmentSize = Section[Index].SizeOfRawData; > + // We still need to align the VirtualSize to the SectionAlignment because MSVC does not do > + // this when creating a PE image. It expects the loader to do this. > + ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE (Section[Index].Misc.VirtualSize, SectionAlignment); > > InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSection->Link); > ImageRecord->CodeSegmentCount++; > -- > 2.40.1 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116672): https://edk2.groups.io/g/devel/message/116672 Mute This Topic: https://groups.io/mt/104873193/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-