Re: [PATCH v3 2/2] x86/sev: Add SNP-specific unaccepted memory support

From: Borislav Petkov
Date: Thu Aug 18 2022 - 09:41:26 EST


On Mon, Aug 15, 2022 at 10:57:43AM -0500, Tom Lendacky wrote:
> Add SNP-specific hooks to the unaccepted memory support in the boot
> path (__accept_memory()) and the core kernel (accept_memory()) in order
> to support booting SNP guests when unaccepted memory is present. Without
> this support, SNP guests will fail to boot and/or panic() when unaccepted
> memory is present in the EFI memory map.
>
> The process of accepting memory under SNP involves invoking the hypervisor
> to perform a page state change for the page to private memory and then
> issuing a PVALIDATE instruction to accept the page.
>
> Create the new header file arch/x86/boot/compressed/sev.h because adding
> the function declaration to any of the existing SEV related header files
> pulls in too many other header files, causing the build to fail.
>
> Signed-off-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> ---
> arch/x86/Kconfig | 1 +
> arch/x86/boot/compressed/mem.c | 3 +++
> arch/x86/boot/compressed/sev.c | 10 +++++++++-
> arch/x86/boot/compressed/sev.h | 23 +++++++++++++++++++++++
> arch/x86/include/asm/sev.h | 3 +++
> arch/x86/kernel/sev.c | 16 ++++++++++++++++
> arch/x86/mm/unaccepted_memory.c | 4 ++++
> 7 files changed, 59 insertions(+), 1 deletion(-)
> create mode 100644 arch/x86/boot/compressed/sev.h

Looks mostly ok to me...

> diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
> index 730c4677e9db..d4b06c862094 100644
> --- a/arch/x86/boot/compressed/sev.c
> +++ b/arch/x86/boot/compressed/sev.c
> @@ -115,7 +115,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
> /* Include code for early handlers */
> #include "../../kernel/sev-shared.c"
>
> -static inline bool sev_snp_enabled(void)
> +bool sev_snp_enabled(void)
> {
> return sev_status & MSR_AMD64_SEV_SNP_ENABLED;
> }

This is another one of my pet peeves and now it even gets exported but
it is the early decompressor crap so I won't even try to mention cc_*
helpers...

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette