[PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/

Tycho Andersen posted 11 patches 8 hours ago
[PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/
Posted by Tycho Andersen 8 hours ago
From: "Tycho Andersen (AMD)" <tycho@kernel.org>

Now that there is snp_prepare_for_snp_init() that indicates when the CCP
driver wants to prepare the architecture for SNP_INIT(_EX), move this
architecture-specific bit of code to a more sensible place.

Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 arch/x86/virt/svm/sev.c      | 8 ++++++++
 drivers/crypto/ccp/sev-dev.c | 8 --------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index aa784542b32d..53bc0c7f2c50 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -509,6 +509,11 @@ static bool __init setup_rmptable(void)
 	return true;
 }
 
+static void snp_set_hsave_pa(void *arg)
+{
+	wrmsrq(MSR_VM_HSAVE_PA, 0);
+}
+
 void snp_prepare_for_snp_init(void)
 {
 	u64 val;
@@ -530,6 +535,9 @@ void snp_prepare_for_snp_init(void)
 	on_each_cpu(mfd_enable, NULL, 1);
 
 	on_each_cpu(snp_enable, NULL, 1);
+
+	/* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
+	on_each_cpu(snp_set_hsave_pa, NULL, 1);
 }
 EXPORT_SYMBOL_FOR_MODULES(snp_prepare_for_snp_init, "ccp");
 
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 5b1a24b11e3e..ef45977b09b6 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1076,11 +1076,6 @@ static inline int __sev_do_init_locked(int *psp_ret)
 		return __sev_init_locked(psp_ret);
 }
 
-static void snp_set_hsave_pa(void *arg)
-{
-	wrmsrq(MSR_VM_HSAVE_PA, 0);
-}
-
 /* Hypervisor Fixed pages API interface */
 static void snp_hv_fixed_pages_state_update(struct sev_device *sev,
 					    enum snp_hv_fixed_pages_state page_state)
@@ -1377,9 +1372,6 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
 
 	snp_prepare_for_snp_init();
 
-	/* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
-	on_each_cpu(snp_set_hsave_pa, NULL, 1);
-
 	/*
 	 * Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list
 	 * of system physical address ranges to convert into HV-fixed page
-- 
2.53.0
Re: [PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/
Posted by Tom Lendacky 6 hours ago
On 3/2/26 13:13, Tycho Andersen wrote:
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
> 
> Now that there is snp_prepare_for_snp_init() that indicates when the CCP
> driver wants to prepare the architecture for SNP_INIT(_EX), move this
> architecture-specific bit of code to a more sensible place.
> 
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  arch/x86/virt/svm/sev.c      | 8 ++++++++
>  drivers/crypto/ccp/sev-dev.c | 8 --------
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index aa784542b32d..53bc0c7f2c50 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -509,6 +509,11 @@ static bool __init setup_rmptable(void)
>  	return true;
>  }
>  
> +static void snp_set_hsave_pa(void *arg)
> +{
> +	wrmsrq(MSR_VM_HSAVE_PA, 0);
> +}
> +
>  void snp_prepare_for_snp_init(void)
>  {
>  	u64 val;
> @@ -530,6 +535,9 @@ void snp_prepare_for_snp_init(void)
>  	on_each_cpu(mfd_enable, NULL, 1);
>  
>  	on_each_cpu(snp_enable, NULL, 1);
> +
> +	/* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
> +	on_each_cpu(snp_set_hsave_pa, NULL, 1);
>  }
>  EXPORT_SYMBOL_FOR_MODULES(snp_prepare_for_snp_init, "ccp");
>  
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 5b1a24b11e3e..ef45977b09b6 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1076,11 +1076,6 @@ static inline int __sev_do_init_locked(int *psp_ret)
>  		return __sev_init_locked(psp_ret);
>  }
>  
> -static void snp_set_hsave_pa(void *arg)
> -{
> -	wrmsrq(MSR_VM_HSAVE_PA, 0);
> -}
> -
>  /* Hypervisor Fixed pages API interface */
>  static void snp_hv_fixed_pages_state_update(struct sev_device *sev,
>  					    enum snp_hv_fixed_pages_state page_state)
> @@ -1377,9 +1372,6 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
>  
>  	snp_prepare_for_snp_init();
>  
> -	/* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
> -	on_each_cpu(snp_set_hsave_pa, NULL, 1);
> -
>  	/*
>  	 * Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list
>  	 * of system physical address ranges to convert into HV-fixed page