public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Skip SNP initialization if CPUs are offlined
@ 2026-04-07 17:47 Tycho Andersen
  2026-04-07 17:47 ` [PATCH v2 1/2] x86/sev: Do not initialize SNP if missing CPUs Tycho Andersen
  2026-04-07 17:47 ` [PATCH v2 2/2] crypto/ccp: Skip SNP_INIT if preparation fails Tycho Andersen
  0 siblings, 2 replies; 3+ messages in thread
From: Tycho Andersen @ 2026-04-07 17:47 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Ashish Kalra, Tom Lendacky, John Allen,
	Herbert Xu, David S. Miller, Ard Biesheuvel, Neeraj Upadhyay,
	Kishon Vijay Abraham I, Alexey Kardashevskiy, Nikunj A Dadhania,
	Peter Zijlstra (Intel), Kim Phillips, Sean Christopherson
  Cc: linux-kernel, linux-crypto, Tycho Andersen (AMD)

From: "Tycho Andersen (AMD)" <tycho@kernel.org>

Here's a v2 of the series. Changes are:

* propagate the error from snp_prepare() through __sev_snp_init_locked()
* use cpus_present_mask instead of cpus_possible_mask to reason about
  the set of available CPUs
* print the CPU masks for easier debugging

It turns out that CONFIG_INIT_ALL_POSSIBLE is not user-settable, and
only parisc selects it, so it shouldn't be a problem here.

v1 is here: https://lore.kernel.org/all/20260401143552.3038979-1-tycho@kernel.org/

Tycho Andersen (AMD) (2):
  x86/sev: Do not initialize SNP if missing CPUs
  crypto/ccp: Skip SNP_INIT if preparation fails

 arch/x86/include/asm/sev.h   |  4 ++--
 arch/x86/virt/svm/sev.c      | 15 +++++++++++++--
 drivers/crypto/ccp/sev-dev.c |  4 +++-
 3 files changed, 18 insertions(+), 5 deletions(-)


base-commit: 6c927e5ca9d238f8ae40b453a8382eb9cf4ee855
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] x86/sev: Do not initialize SNP if missing CPUs
  2026-04-07 17:47 [PATCH v2 0/2] Skip SNP initialization if CPUs are offlined Tycho Andersen
@ 2026-04-07 17:47 ` Tycho Andersen
  2026-04-07 17:47 ` [PATCH v2 2/2] crypto/ccp: Skip SNP_INIT if preparation fails Tycho Andersen
  1 sibling, 0 replies; 3+ messages in thread
From: Tycho Andersen @ 2026-04-07 17:47 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Ashish Kalra, Tom Lendacky, John Allen,
	Herbert Xu, David S. Miller, Ard Biesheuvel, Neeraj Upadhyay,
	Kishon Vijay Abraham I, Alexey Kardashevskiy, Nikunj A Dadhania,
	Peter Zijlstra (Intel), Kim Phillips, Sean Christopherson
  Cc: linux-kernel, linux-crypto, Tycho Andersen (AMD)

From: "Tycho Andersen (AMD)" <tycho@kernel.org>

The SEV firmware checks that the SNP enable bit is set on each CPU during
SNP initialization, and will fail if it is not. If there are some CPUs
offline, they will not run the setup functions, so SNP initialization will
always fail.

Skip the IPIs in this case and return an error so that the CCP driver can
skip the SNP_INIT that will fail. Also print the CPU masks as a breadcrumb
so people can figure out what happened.

Suggested-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 arch/x86/include/asm/sev.h |  4 ++--
 arch/x86/virt/svm/sev.c    | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index 09e605c85de4..594cfa19cbd4 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -661,7 +661,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int pages)
 {
 	__snp_leak_pages(pfn, pages, true);
 }
-void snp_prepare(void);
+int snp_prepare(void);
 void snp_shutdown(void);
 #else
 static inline bool snp_probe_rmptable_info(void) { return false; }
@@ -679,7 +679,7 @@ static inline void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp)
 static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
 static inline void kdump_sev_callback(void) { }
 static inline void snp_fixup_e820_tables(void) {}
-static inline void snp_prepare(void) {}
+static inline int snp_prepare(void) { return -ENODEV; }
 static inline void snp_shutdown(void) {}
 #endif
 
diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index 41f76f15caa1..160e60f5f3fb 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -511,8 +511,9 @@ static void clear_hsave_pa(void *arg)
 	wrmsrq(MSR_VM_HSAVE_PA, 0);
 }
 
-void snp_prepare(void)
+int snp_prepare(void)
 {
+	int ret = -EOPNOTSUPP;
 	u64 val;
 
 	/*
@@ -521,12 +522,19 @@ void snp_prepare(void)
 	 */
 	rdmsrq(MSR_AMD64_SYSCFG, val);
 	if (val & MSR_AMD64_SYSCFG_SNP_EN)
-		return;
+		return 0;
 
 	clear_rmp();
 
 	cpus_read_lock();
 
+	if (!cpumask_equal(cpu_online_mask, cpu_present_mask)) {
+		pr_warn("Skipping SNP initialization. CPUs online %*pbl, present %*pbl\n",
+			cpumask_pr_args(cpu_online_mask),
+			cpumask_pr_args(cpu_present_mask));
+		goto unlock;
+	}
+
 	/*
 	 * MtrrFixDramModEn is not shared between threads on a core,
 	 * therefore it must be set on all CPUs prior to enabling SNP.
@@ -537,7 +545,10 @@ void snp_prepare(void)
 	/* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */
 	on_each_cpu(clear_hsave_pa, NULL, 1);
 
+	ret = 0;
+unlock:
 	cpus_read_unlock();
+	return ret;
 }
 EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp");
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] crypto/ccp: Skip SNP_INIT if preparation fails
  2026-04-07 17:47 [PATCH v2 0/2] Skip SNP initialization if CPUs are offlined Tycho Andersen
  2026-04-07 17:47 ` [PATCH v2 1/2] x86/sev: Do not initialize SNP if missing CPUs Tycho Andersen
@ 2026-04-07 17:47 ` Tycho Andersen
  1 sibling, 0 replies; 3+ messages in thread
From: Tycho Andersen @ 2026-04-07 17:47 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Ashish Kalra, Tom Lendacky, John Allen,
	Herbert Xu, David S. Miller, Ard Biesheuvel, Neeraj Upadhyay,
	Kishon Vijay Abraham I, Alexey Kardashevskiy, Nikunj A Dadhania,
	Peter Zijlstra (Intel), Kim Phillips, Sean Christopherson
  Cc: linux-kernel, linux-crypto, Tycho Andersen (AMD)

From: "Tycho Andersen (AMD)" <tycho@kernel.org>

During SNP_INIT, the firmware checks to see that the SNP enable bit is set
on all CPUs. If snp_prepare() failed because not all CPUs were online,
SNP_INIT will fail, so skip it.

Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 drivers/crypto/ccp/sev-dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 939fa8aa155c..854263cbb256 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1374,7 +1374,9 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
 		return -EOPNOTSUPP;
 	}
 
-	snp_prepare();
+	rc = snp_prepare();
+	if (rc < 0)
+		return rc;
 
 	/*
 	 * Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-07 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 17:47 [PATCH v2 0/2] Skip SNP initialization if CPUs are offlined Tycho Andersen
2026-04-07 17:47 ` [PATCH v2 1/2] x86/sev: Do not initialize SNP if missing CPUs Tycho Andersen
2026-04-07 17:47 ` [PATCH v2 2/2] crypto/ccp: Skip SNP_INIT if preparation fails Tycho Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox