public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
	edk2-devel-groups-io <devel@edk2.groups.io>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Vitaly Cheptsov <vit9696@protonmail.com>
Subject: Re: [PATCH 1/2] ArmPkg/AsmMacroIoLibV8: Introduce ASM_FUNC_ALIGN()
Date: Wed, 19 Apr 2023 17:13:33 +0000	[thread overview]
Message-ID: <F308E6E3-54FB-414C-8C05-88EE134732F7@posteo.de> (raw)
In-Reply-To: <EE155630-B183-40E0-9FC6-068BC98FABA1@posteo.de>

[-- Attachment #1: Type: text/plain, Size: 2595 bytes --]

Hi all,

While testing Ard's suggestion for V3, I noticed I got a broken FD where ArmReplaceLiveTranslationEntry() is misaligned, but does not cross a 4 KB boundary. To not just hide the issue via this patch, can someone please try to explain the exact requirements this function has (the comments read like 0x200 was just the lowest value to guarantee staying within a page)? Why would it be broken if misaligned, but not crossing a page?

Is there any chance the FD is somehow misaligned in memory, thus shifting the function across a page in the process? Or is the FD mapped to a fixed address like with x86? Is code after ArmReplaceLiveTranslationEntry() crossing page boundaries the actual issue (and is implicitly fixed by aligning it)?

For reference, I attached the broken FD. The problematic ArmReplaceLiveTranslationEntry() is located at MemoryInitPei 0x25C10 - 0x25D54.
This is from my arm_corruption-latest branch: https://github.com/mhaeuser/edk2/tree/arm_corruption-latest

Best regards,
Marvin



> On 18. Apr 2023, at 10:18, Marvin Häuser <mhaeuser@posteo.de> wrote:
> 
> 
> 
>> On 18. Apr 2023, at 10:10, Ard Biesheuvel <ardb@kernel.org> wrote:
>> 
>> On Tue, 18 Apr 2023 at 08:40, Marvin Häuser <mhaeuser@posteo.de> wrote:
>>> 
>>> 
>>>> On 17. Apr 2023, at 23:18, Ard Biesheuvel <ardb@kernel.org> wrote:
>>>> 
>>>> Agree with all of this.
>>>> 
>>>> And thanks for tracking this down - must not have been fun :-)
>>> 
>>> No worries - it wasn’t. :) It was mere luck Vitaly discovered early it was an issue that triggered based on the binary layout rather than a bug in the mapping code itself…
>>> 
>>> Speaking of not fun to track down, I initially wanted to add ASSERTs (yes, runtime :( ) to check the alignment guarantee is actually met. Leif basically declined any form of regression-testing at runtime. Do you happen to have a simple(!) idea for how it could be checked at build-time? (It’s less about “which commands do I run?” and more about integration with the build process / BaseTools, cross-OS compatibility, etc.)
>>> 
>> 
>> 
>> I think we should just add another align to the code:
>> 
>> .align xx
>> func:
>> 
>> < code >
>> 
>> .align xx
>> .org func + xx
>> 
>> That way, if the code straddles a xx-aligned boundary, the .org will
>> move backwards and force an error.
> 
> Wow, that's pretty fucking smart... I didn't even know that directive was a thing. I will try to toy with it soon. Do you want it as a separate series, separate commit in the current series, or squashed into the fix?


[-- Attachment #2.1: Type: text/html, Size: 3436 bytes --]

[-- Attachment #2.2: QEMU_EFI.fd --]
[-- Type: application/octet-stream, Size: 2097152 bytes --]

  parent reply	other threads:[~2023-04-19 17:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17 18:09 [PATCH 1/2] ArmPkg/AsmMacroIoLibV8: Introduce ASM_FUNC_ALIGN() Marvin Häuser
2023-04-17 18:09 ` [PATCH 2/2] ArmPkg/ArmMmuLib: Fix ArmReplaceLiveTranslationEntry() alignment Marvin Häuser
2023-04-17 19:53   ` Leif Lindholm
2023-04-17 19:52 ` [PATCH 1/2] ArmPkg/AsmMacroIoLibV8: Introduce ASM_FUNC_ALIGN() Leif Lindholm
2023-04-17 21:18   ` Ard Biesheuvel
2023-04-18  6:40     ` Marvin Häuser
2023-04-18  8:10       ` Ard Biesheuvel
2023-04-18  8:18         ` Marvin Häuser
2023-04-18  8:59           ` Ard Biesheuvel
2023-04-19 17:13           ` Marvin Häuser [this message]
2023-04-19 17:40             ` [edk2-devel] " Ard Biesheuvel
2023-04-19 17:45               ` Marvin Häuser
2023-04-19 18:03                 ` Ard Biesheuvel
2023-04-19 18:25                   ` Marvin Häuser
2023-04-19 18:26                     ` Ard Biesheuvel
2023-04-19 18:31                       ` Marvin Häuser
2023-04-19 19:48                         ` Ard Biesheuvel
2023-04-19 20:10                           ` Marvin Häuser
2023-04-19 21:42                             ` Marvin Häuser
2023-04-19 21:55                             ` Ard Biesheuvel
2023-04-19 22:15                               ` Marvin Häuser
2023-04-19 22:27                               ` Pedro Falcato

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=F308E6E3-54FB-414C-8C05-88EE134732F7@posteo.de \
    --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