mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Melody Wang" <huibo.wang@amd.com>, x86@kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	"Tom Lendacky" <thomas.lendacky@amd.com>
Subject: Re: [PATCH v2 5/8] x86/sev: Add a function to contain all SEV-specific setup operations
Date: Mon, 14 Sep 2026 22:04:27 +0200	[thread overview]
Message-ID: <db8bceb5-b72a-4742-aa44-9cf21a8c95b8@app.fastmail.com> (raw)
In-Reply-To: <8b651e078329193ef458757696ea54a314519427.1789345277.git.huibo.wang@amd.com>


On Mon, 14 Sep 2026, at 02:57, Melody Wang wrote:
> To make the code clean in the boot phase, add a sev_prepare() wrapper
> which contains early SEV-specific checks in order to have all that code
> in a single place.
>
> No functional changes.
>
> Signed-off-by: Melody Wang <huibo.wang@amd.com>
> ---
>  arch/x86/boot/compressed/sev.c          | 11 +++++++++++
>  arch/x86/include/asm/sev.h              |  3 +++
>  drivers/firmware/efi/libstub/x86-stub.c | 17 +++--------------
>  3 files changed, 17 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
> index fc2029746c50..c935a97f72e9 100644
> --- a/arch/x86/boot/compressed/sev.c
> +++ b/arch/x86/boot/compressed/sev.c
> @@ -511,3 +511,14 @@ bool early_is_sevsnp_guest(void)
>  	}
>  	return true;
>  }
> +
> +bool sev_prepare(void)
> +{
> +	u64 unsupported = snp_get_unsupported_features(sev_get_status());
> +	if (unsupported) {
> +		error("Unsupported SEV-SNP features detected\n");

The EFI stub will call this while running under the boot services, so
error() should not be used here.

Also, error() never returns - it is the decompressor's pseudo-panic()
so whatever you return to will never execute.


> +		return true;
> +	}
> +
> +	return false;
> +}
> diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
> index 3cb6c5d6a6e0..95f9a5084c45 100644
> --- a/arch/x86/include/asm/sev.h
> +++ b/arch/x86/include/asm/sev.h
> @@ -605,6 +605,8 @@ static inline void sev_evict_cache(void *va, int npages)
>  	}
>  }
> 
> +bool sev_prepare(void);
> +
>  #else	/* !CONFIG_AMD_MEM_ENCRYPT */
> 
>  #define snp_vmpl 0
> @@ -652,6 +654,7 @@ static inline enum es_result savic_register_gpa(u64 
> gpa) { return ES_UNSUPPORTED
>  static inline enum es_result savic_unregister_gpa(u64 *gpa) { return 
> ES_UNSUPPORTED; }
>  static inline void sev_apic_ghcb_msr_write(u32 reg, u64 value) { }
>  static inline u64 sev_apic_ghcb_msr_read(u32 reg) { return 0; }
> +static inline bool sev_prepare(void) { return false; }
> 
>  #endif	/* CONFIG_AMD_MEM_ENCRYPT */
> 
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
> b/drivers/firmware/efi/libstub/x86-stub.c
> index cef32e2c82d8..fae3a7dfb8b3 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -783,19 +783,6 @@ static efi_status_t exit_boot(struct boot_params 
> *boot_params, void *handle)
>  	return EFI_SUCCESS;
>  }
> 
> -static bool have_unsupported_snp_features(void)
> -{
> -	u64 unsupported;
> -
> -	unsupported = snp_get_unsupported_features(sev_get_status());
> -	if (unsupported) {
> -		efi_err("Unsupported SEV-SNP features detected: 0x%llx\n",
> -			unsupported);
> -		return true;
> -	}
> -	return false;
> -}
> -
>  static void efi_get_seed(void *seed, int size)
>  {
>  	efi_get_random_bytes(size, seed);
> @@ -919,6 +906,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
>  	unsigned long kernel_entry;
>  	struct setup_header *hdr;
>  	efi_status_t status;
> +	bool err;
> 
>  	efi_system_table = sys_table_arg;
>  	/* Check if we were booted by the EFI firmware */
> @@ -933,7 +921,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
> 
>  	hdr = &boot_params->hdr;
> 
> -	if (have_unsupported_snp_features())
> +	err = sev_prepare();
> +	if (err)
>  		efi_exit(handle, EFI_UNSUPPORTED);
> 
>  	if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES)) {
> -- 
> 2.43.0

  reply	other threads:[~2026-09-14 20:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14  0:57 [PATCH v2 0/8] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
2026-09-14  0:57 ` [PATCH v2 1/8] x86/sev: Make SVSM calls preemption-safe Melody Wang
2026-09-22  3:14   ` [tip: x86/urgent] x86/sev: Make vTPM " tip-bot2 for Melody Wang
2026-09-14  0:57 ` [PATCH v2 2/8] x86/sev: Add support for Alternate Injection Melody Wang
2026-09-14  0:57 ` [PATCH v2 3/8] x86/apic: Add an SVSM APIC driver Melody Wang
2026-09-14  0:57 ` [PATCH v2 4/8] x86/sev: Route unsupported APIC register accesses to the hypervisor APIC emulation Melody Wang
2026-09-14  0:57 ` [PATCH v2 5/8] x86/sev: Add a function to contain all SEV-specific setup operations Melody Wang
2026-09-14 20:04   ` Ard Biesheuvel [this message]
2026-09-14  0:57 ` [PATCH v2 6/8] x86/sev: Register the guest with the SVSM APIC protocol Melody Wang
2026-09-14 20:06   ` Ard Biesheuvel
2026-09-15  2:04     ` Melody Wang
2026-09-15  7:44       ` Ard Biesheuvel
2026-09-16 18:45         ` Melody Wang
2026-09-18  8:14           ` Ard Biesheuvel
2026-09-20 17:55             ` Melody Wang
2026-09-14  0:57 ` [PATCH v2 7/8] x86/sev: Allow the guest to configure interrupt vectors for the hypervisor Melody Wang
2026-09-14  0:57 ` [PATCH v2 8/8] x86/sev: Indicate that Alternate Injection is supported in the guest Melody Wang

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=db8bceb5-b72a-4742-aa44-9cf21a8c95b8@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=huibo.wang@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@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

all inboxes | Powered by JetHome®