[tip: x86/sev] x86/sev, crypto/ccp: Move HSAVE_PA setup to arch/x86/

From: tip-bot2 for Tycho Andersen (AMD)

Date: Mon Mar 30 2026 - 06:47:02 EST


The following commit has been merged into the x86/sev branch of tip:

Commit-ID: 7b2bc5f0ab983a7aad7fa5180cede4b3e91fc164
Gitweb: https://git.kernel.org/tip/7b2bc5f0ab983a7aad7fa5180cede4b3e91fc164
Author: Tycho Andersen (AMD) <tycho@xxxxxxxxxx>
AuthorDate: Tue, 24 Mar 2026 10:12:59 -06:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Sun, 29 Mar 2026 19:59:58 +02:00

x86/sev, crypto/ccp: Move HSAVE_PA setup to arch/x86/

Now that there is snp_prepare() 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@xxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
Link: https://patch.msgid.link/20260324161301.1353976-6-tycho@xxxxxxxxxx
---
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 423fe77..41f76f1 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -506,6 +506,11 @@ static bool __init setup_rmptable(void)
return true;
}

+static void clear_hsave_pa(void *arg)
+{
+ wrmsrq(MSR_VM_HSAVE_PA, 0);
+}
+
void snp_prepare(void)
{
u64 val;
@@ -529,6 +534,9 @@ void snp_prepare(void)
on_each_cpu(mfd_reconfigure, (void *)1, 1);
on_each_cpu(snp_enable, NULL, 1);

+ /* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
+ on_each_cpu(clear_hsave_pa, NULL, 1);
+
cpus_read_unlock();
}
EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp");
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 024eab2..0d0c09a 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)
@@ -1375,9 +1370,6 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)

snp_prepare();

- /* 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