From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web08.10280.1664382557019529579 for ; Wed, 28 Sep 2022 09:29:17 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gdwfCQBh; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A3FF61E82 for ; Wed, 28 Sep 2022 16:29:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEBDDC4347C for ; Wed, 28 Sep 2022 16:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664382555; bh=W0ksmVC39PFvsYtae291rCi7EUhRk3HjWXu1wG5sdkY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gdwfCQBhLmLV7/AejhYTGbr6qIiMxL+Qt8FUhWKT9dkvGx/nWkxj+CDNU/XSggeLr 8y00hzguohEhkDOVStbhYgqtw0RKrr2JOo5YQyXPcn8JU8/RhPft5ageq6snO0n19R cfLrGDEdO4QCQFx99p81PZBw4eGz4o+VfjBkV01j8as0cI8uACHvFmiEM7gb9mlBPJ h1pQCGxkkeelOfbZMYyR0HbXd42PwcnpYaf+/yb2Vz7qbPsYvIa/GkxciFwgITVcDv Fdtfkru5WV2P3pdHA0rhME6AX4IV5DlL4L0Of5Mky1BhytTS31TR/Ztdd2aP1Ql23H qzP2+HjXcuzvw== Received: by mail-lj1-f182.google.com with SMTP id g20so14920544ljg.7 for ; Wed, 28 Sep 2022 09:29:15 -0700 (PDT) X-Gm-Message-State: ACrzQf0so5kmacnI50296Q+IDCQk3Z+hCFQUGe/V+c396ZKQht+vbxGa FHFqpTy96WB6JgbNjOvBOSSWpTZv3UMxJ+fQiZQ= X-Google-Smtp-Source: AMsMyM6WzZEKzhFR1WA1qyeAFrOsqEzG/zwkqMSgVb9xrnb/EJvuvlc0wNjP3gQ8jhqtUV/B3TPea3apUUthRdSH+8k= X-Received: by 2002:a05:651c:239c:b0:26d:94b8:781d with SMTP id bk28-20020a05651c239c00b0026d94b8781dmr6426970ljb.189.1664382553875; Wed, 28 Sep 2022 09:29:13 -0700 (PDT) MIME-Version: 1.0 References: <20220928153323.2583389-1-dionnaglaze@google.com> <20220928153323.2583389-2-dionnaglaze@google.com> In-Reply-To: <20220928153323.2583389-2-dionnaglaze@google.com> From: "Ard Biesheuvel" Date: Wed, 28 Sep 2022 18:29:02 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v4 1/6] OvmfPkg: Realize EfiMemoryAcceptProtocol in AmdSevDxe To: devel@edk2.groups.io, dionnaglaze@google.com Cc: Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Sophia Wolf Content-Type: text/plain; charset="UTF-8" On Wed, 28 Sept 2022 at 17:33, Dionna Glaze via groups.io wrote: > > From: Sophia Wolf > > When a guest OS does not support unaccepted memory, the unaccepted > memory must be accepted before returning a memory map to the caller. > > EfiMemoryAcceptProtocol is defined in MdePkg and is implemented / > Installed in AmdSevDxe for AMD SEV-SNP memory acceptance. > > Cc: Gerd Hoffmann > Cc: James Bottomley > Cc: Jiewen Yao > Cc: Tom Lendacky > > Signed-off-by: Sophia Wolf A signoff is an assertion by the contributor that the contribution is compatible with the license. It is *not* a statement of authorship. This means that you can keep the from: line, and credit the author in another way in the commit log, but the signed-off-by needs to mention the contributor of the patch not the author. > --- > OvmfPkg/AmdSevDxe/AmdSevDxe.c | 34 ++++++++++++++++++++ > OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 3 ++ > OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c | 24 +++++++++++--- > 3 files changed, 57 insertions(+), 4 deletions(-) > > diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c > index 662d3c4ccb..09aa15165d 100644 > --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c > +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION mSnpBootDxeTable = { > SIGNATURE_32 ('A', 'M', 'D', 'E'), > @@ -31,6 +32,29 @@ STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION mSnpBootDxeTable = { > FixedPcdGet32 (PcdOvmfCpuidSize), > }; > > +STATIC EFI_HANDLE mAmdSevDxeHandle = NULL; > + > +STATIC > +EFI_STATUS > +EFIAPI > +AmdSevMemoryAccept ( > + IN EFI_MEMORY_ACCEPT_PROTOCOL *This, > + IN EFI_PHYSICAL_ADDRESS StartAddress, > + IN UINTN Size > +) > +{ > + MemEncryptSevSnpPreValidateSystemRam ( > + StartAddress, > + EFI_SIZE_TO_PAGES (Size) > + ); > + > + return EFI_SUCCESS; > +} > + > +STATIC EFI_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = { > + AmdSevMemoryAccept > +}; > + > EFI_STATUS > EFIAPI > AmdSevDxeEntryPoint ( > @@ -147,6 +171,16 @@ AmdSevDxeEntryPoint ( > } > } > > + Status = gBS->InstallProtocolInterface ( > + &mAmdSevDxeHandle, > + &gEfiMemoryAcceptProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mMemoryAcceptProtocol > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Install EfiMemoryAcceptProtocol failed.\n")); > + } > + > // > // If its SEV-SNP active guest then install the CONFIDENTIAL_COMPUTING_SEV_SNP_BLOB. > // It contains the location for both the Secrets and CPUID page. > diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > index 9acf860cf2..5ddddabc32 100644 > --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > @@ -47,6 +47,9 @@ > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize > > +[Protocols] > + gEfiMemoryAcceptProtocolGuid > + > [Guids] > gConfidentialComputingSevSnpBlobGuid > > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > index d3a95e4913..ee3710f7b3 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > @@ -14,6 +14,7 @@ > #include > > #include "SnpPageStateChange.h" > +#include "VirtualMemory.h" > > /** > Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. > @@ -29,12 +30,27 @@ MemEncryptSevSnpPreValidateSystemRam ( > IN UINTN NumPages > ) > { > + EFI_STATUS Status; > + > if (!MemEncryptSevSnpIsEnabled ()) { > return; > } > > - // > - // All the pre-validation must be completed in the PEI phase. > - // > - ASSERT (FALSE); > + // DXE pre-validation may happen with the memory accept protocol. > + // The protocol should only be called outside the prevalidated ranges > + // that the PEI stage code explicitly skips. Specifically, only memory > + // ranges that are classified as unaccepted. > + if (BaseAddress >= SIZE_4GB) { > + Status = InternalMemEncryptSevCreateIdentityMap1G ( > + 0, > + BaseAddress, > + EFI_PAGES_TO_SIZE (NumPages) > + ); > + if (EFI_ERROR (Status)) { > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > + } > + > + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); > } > -- > 2.37.3.998.g577e59143f-goog > > > > > >