public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Oliver Smith-Denny" <osde@linux.microsoft.com>
To: devel@edk2.groups.io, rebecca@os.amperecomputing.com
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Dandan Bi <dandan.bi@intel.com>
Subject: Re: [edk2-devel] AArch64 with HeapGuard: page allocations wrongly aligned
Date: Mon, 22 Jan 2024 17:53:58 -0800	[thread overview]
Message-ID: <bc69eb0f-f1b4-4406-91b0-10b09103d58b@linux.microsoft.com> (raw)
In-Reply-To: <9696df58-283c-447d-b801-c3bb57b3787d@os.amperecomputing.com>

On 1/22/2024 2:06 PM, Rebecca Cran via groups.io wrote:
> On 1/19/2024 1:03 PM, Oliver Smith-Denny wrote:
> 
>> Thanks for trying. In lieu of being able to test myself, all I can offer
>> is adding some more prints, when the memory gets allocated, making sure
>> it is 64k aligned then. I'd be curious to see what the address is that
>> is attempting to be freed.
>>
>> My guess (as it was earlier) is that it is going to be aligned to
>> 64k but + 4k. I.e the guard page at the front is throwing it off. There
>> may have just been an error in my attempt to fix the check for that.
>>
>> If however that address is not 64k + 4k aligned, then something else is
>> afoot.
>>
>> Happy to look at some more data if you get it or can engineer an example
>> on an open source system (can you force the system to call this function
>> twice even without the extra SMBIOS entries, etc.).
> 
> These are the addresses it's allocating with and without HeapGuard (with 
> the original, upstream Page.c code).
> 
> 
> Without HeapGuard:
> 
> SmbiosCreate64BitTable() re-allocate SMBIOS 64-bit table
> Allocated 0x00000000EF110000 with gBS->AllocatePages (AllocateAnyPages, 
> EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (55), 0x00000000FB7C0000)
> ...
> SmbiosCreate64BitTable() re-allocate SMBIOS 64-bit table
> SmbiosCreate64BitTable: calling FreePages (0x00000000EF110000, 1)
> Allocated 0x00000000EF110000 with gBS->AllocatePages (AllocateAnyPages, 
> EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (4153), 0x00000000FB8AEC8E)
> 
> ------------------------------------------------------
> 
> WITH HeapGuard:
> 
> SmbiosCreate64BitTable() re-allocate SMBIOS 64-bit table
> Allocated 0x00000000ED36F000 with gBS->AllocatePages (AllocateAnyPages, 
> EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (55), 0x00000000ED38F000)
> ...
> SmbiosCreate64BitTable() re-allocate SMBIOS 64-bit table
> SmbiosCreate64BitTable: calling FreePages (0x00000000ED36F000, 1)
> <ASSERT>
> 

I was able to repro your bug (by just turning on page guards on
ArmVirtQemu, allocating runtime mem and freeing it). I think you
are the first person to free runtime mem on ARM64 with page guards
enabled (and to care when it failed :).

The heap guard code is not written with ARM64 in mind (nor is much of
the codebase, of course). Specifically in this case the heap guard code
only wishes to preserve 4 KB alignment, it knows nothing of ARM64's
runtime page granularity required.

Let me take a look at this, I'm working on a solution here, but I want
to test this out further. I'll try to send a patch later this week or
next.

Oliver


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



  reply	other threads:[~2024-01-23  1:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18 15:27 [edk2-devel] AArch64 with HeapGuard: page allocations wrongly aligned Rebecca Cran via groups.io
2024-01-18 16:48 ` Oliver Smith-Denny
2024-01-18 17:42   ` Rebecca Cran via groups.io
2024-01-18 18:38     ` Oliver Smith-Denny
2024-01-18 18:45       ` Rebecca Cran via groups.io
2024-01-18 19:04         ` Oliver Smith-Denny
2024-01-18 19:26           ` Rebecca Cran via groups.io
     [not found]     ` <17AB84FD31479E00.28523@groups.io>
2024-01-18 19:26       ` Oliver Smith-Denny
2024-01-19 16:34         ` Rebecca Cran via groups.io
2024-01-19 20:03           ` Oliver Smith-Denny
2024-01-22 22:06             ` Rebecca Cran via groups.io
2024-01-23  1:53               ` Oliver Smith-Denny [this message]
2024-01-23  2:14                 ` Rebecca Cran via groups.io
2024-01-24 18:29                   ` Oliver Smith-Denny
     [not found]               ` <17ACD713D9397BBF.18300@groups.io>
2024-02-03  0:59                 ` Oliver Smith-Denny
2024-02-05 17:22                   ` Rebecca Cran via groups.io
2024-02-05 17:51                     ` Oliver Smith-Denny
2024-02-05 17:58                       ` Rebecca Cran via groups.io
2024-02-05 20:36                         ` Oliver Smith-Denny
     [not found]                         ` <17B111E492D567BB.26550@groups.io>
2024-02-06  4:20                           ` Oliver Smith-Denny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bc69eb0f-f1b4-4406-91b0-10b09103d58b@linux.microsoft.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox