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 v4 5/7] x86/sev: Register the guest with the SVSM APIC protocol
Date: Wed, 14 Oct 2026 11:43:51 +0200	[thread overview]
Message-ID: <81c6d97f-850e-4f51-919f-cb3a11f47962@app.fastmail.com> (raw)
In-Reply-To: <5ae01ceb58a3fdf6ed9367e236d77b4a21a3363c.1791912902.git.huibo.wang@amd.com>

Hello Melody,

On Tue, 13 Oct 2026, at 19:50, Melody Wang wrote:
> The SVSM APIC protocol supports 5 calls. SVSM_APIC_CONFIGURE_EMULATION
> (shortened to SVSM_APIC_CONFIG_EMULATION for brevity), call 1, provides
> the controls whether the guest can make use of the SVSM APIC protocol.
>
> Implement this call, and register Alternate Injection for the guest by
> default.
>
> Signed-off-by: Melody Wang <huibo.wang@amd.com>
> ---
>  arch/x86/boot/compressed/sev.h          |  2 --
>  arch/x86/include/asm/sev.h              |  2 ++
>  drivers/firmware/efi/libstub/efistub.h  | 11 ++++++++
>  drivers/firmware/efi/libstub/x86-stub.c | 34 +++++++++++++++++++++++++
>  include/linux/efi.h                     |  2 ++
>  5 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/sev.h b/arch/x86/boot/compressed/sev.h
> index 22637b416b46..62e50c2e71ed 100644
> --- a/arch/x86/boot/compressed/sev.h
> +++ b/arch/x86/boot/compressed/sev.h
> @@ -14,7 +14,6 @@
> 
>  void snp_accept_memory(phys_addr_t start, phys_addr_t end);
>  u64 sev_get_status(void);
> -bool early_is_sevsnp_guest(void);
> 
>  static inline u64 sev_es_rd_ghcb_msr(void)
>  {
> @@ -37,7 +36,6 @@ static inline void sev_es_wr_ghcb_msr(u64 val)
> 
>  static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { }
>  static inline u64 sev_get_status(void) { return 0; }
> -static inline bool early_is_sevsnp_guest(void) { return false; }
> 
>  #endif
> 
> diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
> index 93161b663d9b..13f2e8c009b4 100644
> --- a/arch/x86/include/asm/sev.h
> +++ b/arch/x86/include/asm/sev.h
> @@ -471,6 +471,8 @@ static __always_inline void sev_es_nmi_complete(void)
>  extern int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd);
>  extern void sev_enable(struct boot_params *bp);
> 
> +bool early_is_sevsnp_guest(void);
> +
>  /*
>   * RMPADJUST modifies the RMP permissions of a page of a lesser-
>   * privileged (numerically higher) VMPL.
> diff --git a/drivers/firmware/efi/libstub/efistub.h 
> b/drivers/firmware/efi/libstub/efistub.h
> index fd91fc15ec81..d65cdc8f2acd 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -177,6 +177,17 @@ void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
>   */
>  #define EFI_MMAP_NR_SLACK_SLOTS	32
> 
> +typedef union sev_alt_inj_register_protocol sev_alt_inj_register_protocol_t;
> +union sev_alt_inj_register_protocol {
> +	struct {
> +		efi_status_t (__efiapi * sev_register_alt_inj)
> +			(sev_alt_inj_register_protocol_t *);
> +	};
> +	struct {
> +		u32 sev_register_alt_inj;
> +	} mixed_mode;
> +};
> +
>  typedef struct efi_generic_dev_path efi_device_path_protocol_t;
> 
>  union efi_device_path_to_text_protocol {
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
> b/drivers/firmware/efi/libstub/x86-stub.c
> index 2a1fa773d241..b6e58ade4162 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -783,6 +783,36 @@ static efi_status_t exit_boot(struct boot_params 
> *boot_params, void *handle)
>  	return EFI_SUCCESS;
>  }
> 
> +/*
> + * When the guest is running at VMPL2 with Alternate Injection enabled,
> + * register Alternate Injection before ExitBootServices().
> + */
> +static int svsm_register_alt_inj(void)
> +{
> +	efi_guid_t alt_inj_proto = OVMF_SEV_ALT_INJ_REGISTER_PROTOCOL_GUID;
> +	sev_alt_inj_register_protocol_t *proto;
> +	efi_status_t status;
> +
> +	if (early_is_sevsnp_guest() && snp_vmpl) {
> +		if (!(sev_get_status() & MSR_AMD64_SNP_ALTERNATE_INJ))
> +			return 0;
> +	}
> +

I'm struggling to follow the logic here: doesn't this attempt to locate
the protocol on non-SEV/SNP systems as well?

Wouldn't it be sufficient to do

if (!snp_vmpl ||
   !(sev_get_status() & MSR_AMD64_SNP_ALTERNATE_INJ))
       return 0;

and leave the early_is_sevsnp_guest() check alone?


  reply	other threads:[~2026-10-14  9:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 17:50 [PATCH v4 0/7] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
2026-10-13 17:50 ` [PATCH v4 1/7] x86/sev: Add support for Alternate Injection Melody Wang
2026-10-13 17:50 ` [PATCH v4 2/7] x86/apic: Add an SVSM APIC driver Melody Wang
2026-10-13 17:50 ` [PATCH v4 3/7] x86/sev: Route unsupported APIC register accesses to the hypervisor APIC emulation Melody Wang
2026-10-13 17:50 ` [PATCH v4 4/7] x86/sev: Add a function to contain all SEV-specific setup operations Melody Wang
2026-10-13 17:50 ` [PATCH v4 5/7] x86/sev: Register the guest with the SVSM APIC protocol Melody Wang
2026-10-14  9:43   ` Ard Biesheuvel [this message]
2026-10-15  3:56     ` Melody Wang
2026-10-15  6:04       ` Ard Biesheuvel
2026-10-13 17:50 ` [PATCH v4 6/7] x86/sev: Allow the guest to configure interrupt vectors for the hypervisor Melody Wang
2026-10-13 17:50 ` [PATCH v4 7/7] 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=81c6d97f-850e-4f51-919f-cb3a11f47962@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®