From nobody Mon Jun 15 02:45:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D23E133D4EC; Thu, 9 Apr 2026 19:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775764582; cv=none; b=krRMZ8jVARuxk/Jfmuzl9WBGTMf/43KumDInEOjgn6V3NsY1QWUru9kygXEW6fMIS8QVb9uWO1ZVqOL9KlvvZiMaGxR8jTsX3QK/ZkIwHEzq1njEWT/mFa29ibcfVK3xiQI4E7RLLFc3d5948GIBO6bRIe0Wh5m5TV8ny7hinZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775764582; c=relaxed/simple; bh=rCqi6vQv9Me+wTUELzy67PDJCYo31sK7SZuE6K2LtBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZnUQQ+mVO4oOaSA/DyBHpZ5yu4IIlg3N2lg75G56tPh04PCIWy7BBt65PPYSpS3BQRdR/zSsjrqH1l5uMkWoeplvXLxbLikLijcBgNuSqC3z5sULh5OhQfWWEfYmliDQYxeXY8C2Iq6nywZA4wY5bdAFjKgO7ZCKRmnypAKinCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GfDb21CO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GfDb21CO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07623C19424; Thu, 9 Apr 2026 19:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775764582; bh=rCqi6vQv9Me+wTUELzy67PDJCYo31sK7SZuE6K2LtBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfDb21CO08n90pItVr8ybUfTRqfRJEZJpPnU6D9FK/yIch5v20GyeHP/MiYS3akT8 c6+p5wvjjObuuTJE/s2wL2VJbm6QOpg927El3yGGAxfjLPoySJcy9z+4hIE2IjqkyY fygesqYNUvfmWJw2REjSQvfWYN5GGHFz2CppZ70wVESjknFhDXDwrkIPQ3AbrCs1gX GhcSu3jexq7k0kNu2KyixjN+VTCQ6fPND4CPgSTI875Fm3f7khxQ7R1n1YfCusureL 8/L6CRwdi+VFhibsdpIigQZdYDBqas5J+j9XqelLXd3PEKrxO7bFogcWRwiScmn5AG uFMio83a6igvg== From: Tycho Andersen To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "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@vger.kernel.org, linux-crypto@vger.kernel.org, "Tycho Andersen (AMD)" , Tom Lendacky Subject: [PATCH v3 1/2] x86/sev: Do not initialize SNP if missing CPUs Date: Thu, 9 Apr 2026 13:56:01 -0600 Message-ID: <20260409195602.851513-2-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260409195602.851513-1-tycho@kernel.org> References: <20260409195602.851513-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" 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) Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 4 ++-- arch/x86/virt/svm/sev.c | 18 ++++++++++++++++-- 2 files changed, 18 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 i= nt 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 =20 diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 41f76f15caa1..95e5127816dc 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); } =20 -void snp_prepare(void) +int snp_prepare(void) { + int ret; u64 val; =20 /* @@ -521,12 +522,20 @@ void snp_prepare(void) */ rdmsrq(MSR_AMD64_SYSCFG, val); if (val & MSR_AMD64_SYSCFG_SNP_EN) - return; + return 0; =20 clear_rmp(); =20 cpus_read_lock(); =20 + if (!cpumask_equal(cpu_online_mask, cpu_present_mask)) { + ret =3D -EOPNOTSUPP; + 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 +546,12 @@ 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); =20 + ret =3D 0; + +unlock: cpus_read_unlock(); + + return ret; } EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 --=20 2.53.0 From nobody Mon Jun 15 02:45:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8064133AD9C; Thu, 9 Apr 2026 19:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775764585; cv=none; b=KViFu8q3IpsgDGaqvm7PUYwFZCxKzbR/sfGLm6hSAYQ8Wky7b2VGh4LaAym0+GSabdIZES2oazuvszEPz256ld2zPXqMYQ0MIdqCRI1xDRRGLq4ERwTcTRQR8yIdGUM5/kPUtqYJhmySmBgEodAPKmgSjhrowvf1IlkFxqeGpnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775764585; c=relaxed/simple; bh=C1phezGZwkRgf4uFqBgxEKHVwDzHoZcG/lLLp/65be4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p/8RMK29ewFmeTJK3xj+mvev7XxFhNBXjY6Aihr1yS4UIcuURfcFafN0YiaB2pIT4P8ao0GJd0HwammCG+NG50x4w5IRH6p9zSVH0lvhoFU1ZLXlG7Zc8FCOHrDMw/u2FBxEpdEbf2hHuwW9QwhiL+PMi0pQVKeomIUms51rSiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PVDk47wy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PVDk47wy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCEA4C2BCB1; Thu, 9 Apr 2026 19:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775764585; bh=C1phezGZwkRgf4uFqBgxEKHVwDzHoZcG/lLLp/65be4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVDk47wyJ/VDXJqfDBQLLZQqzaLVeAZsZGFk87u8jcvQlRa1Bl8r9v73em66opv70 nBktqqZ3s0CvW2Dq2hAEZG/xaPQpAcCln8WhVqSa2lgKNED8QgxXp9SvFzEQtxizLw gFYlOzXUvIA3buoT2HSfApSlVHrqhloh803sZ3KLUnzLkYI7y0onfhMonPxIiAEaAf NmXdhhC2jouf0/qKgeXkHAcCgMPwCubEgJsw40Ls8qTUTqDDS0J7lvI2G1C+0gtkFR AvqtCzN4hECaN71c88NZNZsEVpqpG5b2OH39idNoT2jgkt7Zn1pEpNiGyVY6r5OhIJ OZm0aVKGWExJg== From: Tycho Andersen To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "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@vger.kernel.org, linux-crypto@vger.kernel.org, "Tycho Andersen (AMD)" Subject: [PATCH v3 2/2] crypto/ccp: Skip SNP_INIT if preparation fails Date: Thu, 9 Apr 2026 13:56:02 -0600 Message-ID: <20260409195602.851513-3-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260409195602.851513-1-tycho@kernel.org> References: <20260409195602.851513-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" If snp_prepare() failed SNP_INIT will fail, so skip it and return early. Note that this is not a change in initialization behavior: if SNP_INIT failed before this patch, it will still return an error __sev_snp_init_locked() and fail initialization of other SEV modes. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Nikunj A Dadhania --- 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..a37922d3d230 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; } =20 - snp_prepare(); + rc =3D snp_prepare(); + if (rc) + return rc; =20 /* * Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list --=20 2.53.0