Linux EFI development
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Ard Biesheuvel <ardb@kernel.org>,
	linux-efi <linux-efi@vger.kernel.org>,
	linux-coco@lists.linux.dev
Cc: Borislav Petkov <bp@alien8.de>,
	Dionna Amalie Glaze <dionnaglaze@google.com>,
	Kevin Loughlin <kevinloughlin@google.com>
Subject: Re: query regarding SEV logic in early boot
Date: Mon, 24 Mar 2025 14:14:48 -0500	[thread overview]
Message-ID: <874299e9-eb4f-7775-4ea4-69d449ca1e05@amd.com> (raw)
In-Reply-To: <CAMj1kXHacRusnpmGJecMU3L2CCyQtopBL6KqoSVuF7tDW85TUg@mail.gmail.com>

On 3/24/25 12:28, Ard Biesheuvel wrote:
> L.S.,
> 
> As I am trying to disentangle the Linux early SEV boot code, the
> legacy decompressor and the EFI stub, I noticed something that looks
> broken to me, but I'm not quite sure how to fix it.
> 
> When booting via the EFI stub, the following call chain may occur:
> 
> setup_e820()
>  process_unaccepted_memory()
>   arch_accept_memory()
>    snp_accept_memory()
>     early_setup_ghcb()
>      set_page_decrypted()
>       set_clr_page_flags()
> 
> where the latter function relies on mapping_info to remap the GHCB
> page as unencrypted. However, when entering via the EFI stub, this
> struct is never initialized, and so I am struggling to see why this
> works at all.

The latter function reads from the target page so that the page gets
faulted in via do_boot_page_fault(). do_boot_page_fault() calls
kernel_add_identity_map(), which calls kernel_ident_mapping_init() and
initializes the mapping_info struct.

At least that is how it is supposed to happen coming through the
decompressor. I couldn't recreate the path you sited until I tried an odd
size memory argument that was not 2M aligned (using 4097M on the qemu
command line fixed that). However, even that causes issues, because the
SEV_STATUS MSR doesn't get read until sev_enable() is called, which is
called after setup_e820(), so we actually can't even take the
snp_accept_memory() path.

But faking the SEV_STATUS MSR value does cause the code to get down to the
set_clr_page_flags() function and reading the input address contents
doesn't trigger do_boot_page_fault() to run because load_stage2_idt()
hasn't been called, which probably wouldn't matter anyway since the code
is running under the EFI page tables.

So, yes, this does appear broken.

Thanks,
Tom

> 
> For context, I am looking into splitting/refactoring the decompressor
> SEV startup code and the kernel proper's SEV startup code, in order to
> a) use PIC codegen properly, and b) allow building a EFI-only bootable
> image that does not include all the exception handling and demand
> paging.
> 
> Any ideas?

  reply	other threads:[~2025-03-24 19:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 17:28 query regarding SEV logic in early boot Ard Biesheuvel
2025-03-24 19:14 ` Tom Lendacky [this message]
2025-03-25  7:22   ` Ard Biesheuvel
2025-03-25 12:32     ` Kirill A. Shutemov
2025-03-25 17:03     ` 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=874299e9-eb4f-7775-4ea4-69d449ca1e05@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dionnaglaze@google.com \
    --cc=kevinloughlin@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox