[PATCH v5 02/22] x86/sev: Use MSR protocol for remapping SVSM calling area

Ard Biesheuvel posted 22 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH v5 02/22] x86/sev: Use MSR protocol for remapping SVSM calling area
Posted by Ard Biesheuvel 1 month, 3 weeks ago
From: Ard Biesheuvel <ardb@kernel.org>

As the preceding code comment already indicates, remapping the SVSM
calling area occurs long before the GHCB page is configured, and so
calling svsm_perform_call_protocol() is guaranteed to result in a call
to svsm_perform_msr_protocol().

So just call the latter directly. This allows most of the GHCB based API
infrastructure to be moved out of the startup code in a subsequent
patch.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 arch/x86/boot/startup/sev-shared.c  | 11 +++++++++++
 arch/x86/boot/startup/sev-startup.c |  5 ++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
index c401d0391537..60ab09b3149d 100644
--- a/arch/x86/boot/startup/sev-shared.c
+++ b/arch/x86/boot/startup/sev-shared.c
@@ -723,6 +723,17 @@ static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
 	}
 }
 
+static int __head svsm_call_msr_protocol(struct svsm_call *call)
+{
+	int ret;
+
+	do {
+		ret = svsm_perform_msr_protocol(call);
+	} while (ret == -EAGAIN);
+
+	return ret;
+}
+
 static void __head svsm_pval_4k_page(unsigned long paddr, bool validate)
 {
 	struct svsm_pvalidate_call *pc;
diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/sev-startup.c
index 0b7e3b950183..c30e0eed0131 100644
--- a/arch/x86/boot/startup/sev-startup.c
+++ b/arch/x86/boot/startup/sev-startup.c
@@ -295,7 +295,6 @@ static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
 static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
 {
 	struct svsm_call call = {};
-	int ret;
 	u64 pa;
 
 	/*
@@ -325,8 +324,8 @@ static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
 	call.caa = svsm_get_caa();
 	call.rax = SVSM_CORE_CALL(SVSM_CORE_REMAP_CA);
 	call.rcx = pa;
-	ret = svsm_perform_call_protocol(&call);
-	if (ret)
+
+	if (svsm_perform_msr_protocol(&call))
 		sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CA_REMAP_FAIL);
 
 	boot_svsm_caa = (struct svsm_ca *)pa;
-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH v5 02/22] x86/sev: Use MSR protocol for remapping SVSM calling area
Posted by Tom Lendacky 1 month, 2 weeks ago
On 7/15/25 22:18, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
> 
> As the preceding code comment already indicates, remapping the SVSM
> calling area occurs long before the GHCB page is configured, and so
> calling svsm_perform_call_protocol() is guaranteed to result in a call
> to svsm_perform_msr_protocol().
> 
> So just call the latter directly. This allows most of the GHCB based API
> infrastructure to be moved out of the startup code in a subsequent
> patch.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>  arch/x86/boot/startup/sev-shared.c  | 11 +++++++++++
>  arch/x86/boot/startup/sev-startup.c |  5 ++---
>  2 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
> index c401d0391537..60ab09b3149d 100644
> --- a/arch/x86/boot/startup/sev-shared.c
> +++ b/arch/x86/boot/startup/sev-shared.c
> @@ -723,6 +723,17 @@ static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
>  	}
>  }
>  
> +static int __head svsm_call_msr_protocol(struct svsm_call *call)
> +{
> +	int ret;
> +
> +	do {
> +		ret = svsm_perform_msr_protocol(call);
> +	} while (ret == -EAGAIN);
> +
> +	return ret;
> +}
> +
>  static void __head svsm_pval_4k_page(unsigned long paddr, bool validate)
>  {
>  	struct svsm_pvalidate_call *pc;
> diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/sev-startup.c
> index 0b7e3b950183..c30e0eed0131 100644
> --- a/arch/x86/boot/startup/sev-startup.c
> +++ b/arch/x86/boot/startup/sev-startup.c
> @@ -295,7 +295,6 @@ static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
>  static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
>  {
>  	struct svsm_call call = {};
> -	int ret;
>  	u64 pa;
>  
>  	/*
> @@ -325,8 +324,8 @@ static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
>  	call.caa = svsm_get_caa();
>  	call.rax = SVSM_CORE_CALL(SVSM_CORE_REMAP_CA);
>  	call.rcx = pa;
> -	ret = svsm_perform_call_protocol(&call);
> -	if (ret)
> +
> +	if (svsm_perform_msr_protocol(&call))

This should be svsm_call_msr_protocol().

Thanks,
Tom

>  		sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CA_REMAP_FAIL);
>  
>  	boot_svsm_caa = (struct svsm_ca *)pa;
Re: [PATCH v5 02/22] x86/sev: Use MSR protocol for remapping SVSM calling area
Posted by Ard Biesheuvel 1 month, 2 weeks ago
On Thu, 17 Jul 2025 at 03:03, Tom Lendacky <thomas.lendacky@amd.com> wrote:
>
> On 7/15/25 22:18, Ard Biesheuvel wrote:
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > As the preceding code comment already indicates, remapping the SVSM
> > calling area occurs long before the GHCB page is configured, and so
> > calling svsm_perform_call_protocol() is guaranteed to result in a call
> > to svsm_perform_msr_protocol().
> >
> > So just call the latter directly. This allows most of the GHCB based API
> > infrastructure to be moved out of the startup code in a subsequent
> > patch.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
> > Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> > ---
> >  arch/x86/boot/startup/sev-shared.c  | 11 +++++++++++
> >  arch/x86/boot/startup/sev-startup.c |  5 ++---
> >  2 files changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
> > index c401d0391537..60ab09b3149d 100644
> > --- a/arch/x86/boot/startup/sev-shared.c
> > +++ b/arch/x86/boot/startup/sev-shared.c
> > @@ -723,6 +723,17 @@ static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
> >       }
> >  }
> >
> > +static int __head svsm_call_msr_protocol(struct svsm_call *call)
> > +{
> > +     int ret;
> > +
> > +     do {
> > +             ret = svsm_perform_msr_protocol(call);
> > +     } while (ret == -EAGAIN);
> > +
> > +     return ret;
> > +}
> > +
> >  static void __head svsm_pval_4k_page(unsigned long paddr, bool validate)
> >  {
> >       struct svsm_pvalidate_call *pc;
> > diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/sev-startup.c
> > index 0b7e3b950183..c30e0eed0131 100644
> > --- a/arch/x86/boot/startup/sev-startup.c
> > +++ b/arch/x86/boot/startup/sev-startup.c
> > @@ -295,7 +295,6 @@ static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
> >  static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
> >  {
> >       struct svsm_call call = {};
> > -     int ret;
> >       u64 pa;
> >
> >       /*
> > @@ -325,8 +324,8 @@ static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
> >       call.caa = svsm_get_caa();
> >       call.rax = SVSM_CORE_CALL(SVSM_CORE_REMAP_CA);
> >       call.rcx = pa;
> > -     ret = svsm_perform_call_protocol(&call);
> > -     if (ret)
> > +
> > +     if (svsm_perform_msr_protocol(&call))
>
> This should be svsm_call_msr_protocol().
>

OK will fix