From: Tom Lendacky <thomas.lendacky@amd.com>
To: Ard Biesheuvel <ardb@kernel.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Ard Biesheuvel <ardb+git@google.com>,
linux-efi@vger.kernel.org, linux-coco@lists.linux.dev,
Borislav Petkov <bp@alien8.de>,
Dionna Amalie Glaze <dionnaglaze@google.com>,
Kevin Loughlin <kevinloughlin@google.com>
Subject: Re: [PATCH] efi/libstub: Do not accept parts of memory before ExitBootServices()
Date: Tue, 25 Mar 2025 11:30:46 -0500 [thread overview]
Message-ID: <d6eb83a9-d1b1-7028-9cfd-1ab3fa0d6269@amd.com> (raw)
In-Reply-To: <CAMj1kXFERrdioZ8_07rwDVUAoq=OLDvLCRUS6BN3GXnJoJPuAA@mail.gmail.com>
On 3/25/25 09:39, Ard Biesheuvel wrote:
> On Tue, 25 Mar 2025 at 14:44, Kirill A. Shutemov
> <kirill.shutemov@linux.intel.com> wrote:
>>
>> On Tue, Mar 25, 2025 at 02:09:54PM +0100, Ard Biesheuvel wrote:
>>>> Since the problem happens before ExitBootServices(), can we allocate this
>>>> memory range with EFI API and free it back?
>>>>
>>>
>>> In principle, yes - we could allocate these misaligned chunks as
>>> EfiLoaderData, and it wouldn't even be necessary to free them, as they
>>> would become available to the OS automatically.
>>>
>>> But doing this in setup_e820() is tricky, because every page
>>> allocation modifies the EFI memory map, and we may have to restart
>>> from the beginning. And there is no guarantee that some asynchronous
>>> event in the firmware context does not attempt to allocate some pages,
>>> in a way that might result in another misaligned unaccepted region.
>>
>> Looking again at the code, setup_e820() (and therefore
>> process_unaccepted_memory()) called after efi_exit_boot_services() in
>> exit_boot(), so we can't use EFI API to allocate memory.
>>
>
> Ah yes, I misremembered that. It also means that it is fine in
> principle to take over the communication with the hypervisor.
>
> However, this is still tricky, because on SEV-SNP, accepting memory
> appears to rely on the GHCB page based communication being enabled,
> and this involves mapping it down to a single page so the C bit can be
> cleared. It would be nice if we could simply use the MSR based
> protocol for accepting memory.
We can probably do something along this line since there is an existing
function, __page_state_change(), that performs MSR protocol PSC. If we
change the arch_accept_memory() calls in process_unaccepted_memory() to
arch_accept_memory_early() then we can differentiate between this early
alignment setup timeframe. The early function can also use
sev_get_status() instead of sev_snp_enabled().
Let me mess around with it a bit and see what I come up with.
Thanks,
Tom
>
>> And it bring us back to the issue being platform-specific. It should be
>> able to accept memory in principle.
>>
>
> Indeed.
>
>> I remember testing TDX boot with ridiculously large unit_size, like 256M.
>> And accept logic worked fine for me.
>>
>>> So ideally, firmware would adopt the same granularity when accepting
>>> memory, and we wouldn't have this problem. (Or maybe this is why
>>> nobody noticed until I found it by inspection?)
>>
>> It would be nice, yes, but we need to deal with requirements in current
>> spec.
>>
>
> Yeah :-(
next prev parent reply other threads:[~2025-03-25 16:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 9:16 [PATCH] efi/libstub: Do not accept parts of memory before ExitBootServices() Ard Biesheuvel
2025-03-25 12:36 ` Kirill A. Shutemov
2025-03-25 12:41 ` Ard Biesheuvel
2025-03-25 12:59 ` Kirill A. Shutemov
2025-03-25 13:09 ` Ard Biesheuvel
2025-03-25 13:44 ` Kirill A. Shutemov
2025-03-25 14:39 ` Ard Biesheuvel
2025-03-25 16:30 ` Tom Lendacky [this message]
2025-03-26 9:28 ` Ard Biesheuvel
2025-04-01 15:51 ` Tom Lendacky
2025-04-01 18:45 ` Ard Biesheuvel
2025-04-02 18:32 ` Tom Lendacky
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-all 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=d6eb83a9-d1b1-7028-9cfd-1ab3fa0d6269@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dionnaglaze@google.com \
--cc=kevinloughlin@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-efi@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.