public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB
@ 2024-01-22 19:52 Rebecca Cran
  2024-01-22 20:24 ` Oliver Smith-Denny
  2024-01-22 21:31 ` Michael D Kinney
  0 siblings, 2 replies; 4+ messages in thread
From: Rebecca Cran @ 2024-01-22 19:52 UTC (permalink / raw)
  To: devel@edk2.groups.io

I've been working on updating the T32 script EfiLoadDxe.cmm in 
EmbeddedPkg/Scripts/LauterbachT32 and one of the issues I've run into is 
that the EFI_SYSTEM_TABLE - pointed to by `gST` and `gDxeCoreST` - isn't 
aligned to 4KB like the script expects.

Instead, I'm seeing AllocateRuntimeCopyPool return 0xFB7D0018 in 
MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c:

//
// Allocate the EFI System Table and EFI Runtime Service Table from 
EfiRuntimeServicesData
// Use the templates to initialize the contents of the EFI System Table 
and EFI Runtime Services Table
//
gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), 
&mEfiSystemTableTemplate);
ASSERT (gDxeCoreST != NULL);

I'm wondering which is wrong: should AllocateRuntimeCopyPool be 
returning a 4KB-aligned pointer, or is the script's assumption wrong?


-- 
Rebecca Cran



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114146): https://edk2.groups.io/g/devel/message/114146
Mute This Topic: https://groups.io/mt/103894456/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB
  2024-01-22 19:52 [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB Rebecca Cran
@ 2024-01-22 20:24 ` Oliver Smith-Denny
  2024-01-22 21:40   ` Rebecca Cran
  2024-01-22 21:31 ` Michael D Kinney
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver Smith-Denny @ 2024-01-22 20:24 UTC (permalink / raw)
  To: devel, rebecca

On 1/22/2024 11:52 AM, Rebecca Cran wrote:
> I've been working on updating the T32 script EfiLoadDxe.cmm in 
> EmbeddedPkg/Scripts/LauterbachT32 and one of the issues I've run into is 
> that the EFI_SYSTEM_TABLE - pointed to by `gST` and `gDxeCoreST` - isn't 
> aligned to 4KB like the script expects.
> 
> Instead, I'm seeing AllocateRuntimeCopyPool return 0xFB7D0018 in 
> MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c:
> 
> //
> // Allocate the EFI System Table and EFI Runtime Service Table from 
> EfiRuntimeServicesData
> // Use the templates to initialize the contents of the EFI System Table 
> and EFI Runtime Services Table
> //
> gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), 
> &mEfiSystemTableTemplate);
> ASSERT (gDxeCoreST != NULL);
> 
> I'm wondering which is wrong: should AllocateRuntimeCopyPool be 
> returning a 4KB-aligned pointer, or is the script's assumption wrong?
> 
> 

Allocating pool memory will never be 4KB aligned because of the
POOL_HEAD. See: 
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Mem/Pool.c#L463-L537.

The allocated page is 4KB aligned, of course, but we store the POOL_HEAD
at the beginning of that page and return Head->Data to the caller.

In addition, this is only in the case where you allocate a new page for
the pool. In the case where the pool has the pages it needs, you don't
have any alignment guarantee, I believe, it is just offset further
into one of the already allocated pages.

Oliver


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114147): https://edk2.groups.io/g/devel/message/114147
Mute This Topic: https://groups.io/mt/103894456/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB
  2024-01-22 19:52 [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB Rebecca Cran
  2024-01-22 20:24 ` Oliver Smith-Denny
@ 2024-01-22 21:31 ` Michael D Kinney
  1 sibling, 0 replies; 4+ messages in thread
From: Michael D Kinney @ 2024-01-22 21:31 UTC (permalink / raw)
  To: devel@edk2.groups.io, rebecca@bsdio.com; +Cc: Kinney, Michael D

Hi Rebecca,

I do not recall any statements in the EFI Spec that require 4KB
alignment of the UEFI System Table, Boot Services Table, 
or Runtime Services Table.

Mike

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rebecca
> Cran
> Sent: Monday, January 22, 2024 11:53 AM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] EFI_SYSTEM_TABLE allocated by
> AllocateRuntimeCopyPool isn't aligned to 4KB
> 
> I've been working on updating the T32 script EfiLoadDxe.cmm in
> EmbeddedPkg/Scripts/LauterbachT32 and one of the issues I've run into is
> that the EFI_SYSTEM_TABLE - pointed to by `gST` and `gDxeCoreST` - isn't
> aligned to 4KB like the script expects.
> 
> Instead, I'm seeing AllocateRuntimeCopyPool return 0xFB7D0018 in
> MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c:
> 
> //
> // Allocate the EFI System Table and EFI Runtime Service Table from
> EfiRuntimeServicesData
> // Use the templates to initialize the contents of the EFI System Table
> and EFI Runtime Services Table
> //
> gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE),
> &mEfiSystemTableTemplate);
> ASSERT (gDxeCoreST != NULL);
> 
> I'm wondering which is wrong: should AllocateRuntimeCopyPool be
> returning a 4KB-aligned pointer, or is the script's assumption wrong?
> 
> 
> --
> Rebecca Cran
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114148): https://edk2.groups.io/g/devel/message/114148
Mute This Topic: https://groups.io/mt/103894456/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB
  2024-01-22 20:24 ` Oliver Smith-Denny
@ 2024-01-22 21:40   ` Rebecca Cran
  0 siblings, 0 replies; 4+ messages in thread
From: Rebecca Cran @ 2024-01-22 21:40 UTC (permalink / raw)
  To: Oliver Smith-Denny, devel

On 1/22/2024 1:24 PM, Oliver Smith-Denny wrote:
> Allocating pool memory will never be 4KB aligned because of the
> POOL_HEAD. See: 
> https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Mem/Pool.c#L463-L537.
>
> The allocated page is 4KB aligned, of course, but we store the POOL_HEAD
> at the beginning of that page and return Head->Data to the caller.
>
> In addition, this is only in the case where you allocate a new page for
> the pool. In the case where the pool has the pages it needs, you don't
> have any alignment guarantee, I believe, it is just offset further
> into one of the already allocated pages.

Thanks. I'll update the script to require users to pass in the address 
of the EFI_SYSTEM_TABLE instead of searching for it!


-- 
Rebecca Cran



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114149): https://edk2.groups.io/g/devel/message/114149
Mute This Topic: https://groups.io/mt/103894456/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-22 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 19:52 [edk2-devel] EFI_SYSTEM_TABLE allocated by AllocateRuntimeCopyPool isn't aligned to 4KB Rebecca Cran
2024-01-22 20:24 ` Oliver Smith-Denny
2024-01-22 21:40   ` Rebecca Cran
2024-01-22 21:31 ` Michael D Kinney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox