From nobody Tue Mar 3 03:20:24 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 4BECF31B131; Mon, 2 Mar 2026 19:14:32 +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=1772478872; cv=none; b=XXlMk6e7ESo9pAqjnjDzuazLj5CbsuRJccn7ThtS47oPXjSZCs6BRVyznydnTkVqtDFiua+Guk3gmM5GIy0K9LwaQk517LIukzBy3u44q7ISyW3ohUK+xk93MNIA8V98ChgeO71cS1RpnpOau9paxaootc+jsHg7P0JVm+OQIjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478872; c=relaxed/simple; bh=mr8fnQHScadkR4uCG8Cf45gkFhDtXzkKMTtJf6PxiUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elUaVWIwqgLdt/7MW31L84nztI6hzWdm5UzTi6++68Po3xAPI1G2Vw4mL8RzzgK7iOfYgXrWciD5+/43R17jEZk4/HlilMEva7XxvW5furW54x9z1WtoAAgUrkkGeMiYSK8ACh/VFMpMtH46sVg1ghXOUhcxTzI5GAoopf3r75E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ek69pEVr; 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="Ek69pEVr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C63D9C2BC9E; Mon, 2 Mar 2026 19:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478872; bh=mr8fnQHScadkR4uCG8Cf45gkFhDtXzkKMTtJf6PxiUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ek69pEVrM5DLnyG1fkSNDUUmECUKMulNQ4QjxEUBdO8/I7c7cWbxw+o4ASmFeh6YQ 13VJVP3169mx4aLEYT+cPiDvbTijzhkO/1P8L6464dfjm3npMs9/6isr8Kp9VqQO0N b7FHbrqAP5MM5RAMmD4/Fq1Bd074h5a6zjC4HToAMHMHwqxL8QhL2xX/wPwLxT5rL6 Y64HRQNc4Tg25Dqmf4xGGwUytQ/Xf08j2nlUEc9l+D7UW9ZwvFaOzhv3nLdObjNP+8 2tBU+OspJFwobxxMOcgUs9bn5Lfc+NZtSJja0DZzKDl76rQYkWVqcCq35pzirUjszw 8ZkP7jsIzCmjg== 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 Subject: [PATCH 01/11] x86/snp: drop support for SNP hotplug Date: Mon, 2 Mar 2026 12:13:24 -0700 Message-ID: <20260302191334.937981-2-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" During an SNP_INIT(_EX), the SEV firmware checks that all CPUs have SNPEn set, and fails if they do not. As such, it does not make sense to have offline CPUs: the firmware will fail initialization because of the offlined ones that the kernel did not initialize. Futher, there is a bug: SNP_INIT(_EX) require MFDM to be set in addition to SNPEn which the previous hotplug code did not do. Since k8_check_syscfg_dram_mod_en() enforces this be cleared, hotplug wouldn't work. Drop the hotplug code. Collapse the __{mfd,snp}__enable() wrappers into their non-__ versions, since the cpu number argument is no longer needed. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/virt/svm/sev.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index a4f3a364fb65..1446011c6337 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -130,33 +130,26 @@ static unsigned long snp_nr_leaked_pages; #undef pr_fmt #define pr_fmt(fmt) "SEV-SNP: " fmt =20 -static int __mfd_enable(unsigned int cpu) +static __init void mfd_enable(void *arg) { u64 val; =20 if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) - return 0; + return; =20 rdmsrq(MSR_AMD64_SYSCFG, val); =20 val |=3D MSR_AMD64_SYSCFG_MFDM; =20 wrmsrq(MSR_AMD64_SYSCFG, val); - - return 0; } =20 -static __init void mfd_enable(void *arg) -{ - __mfd_enable(smp_processor_id()); -} - -static int __snp_enable(unsigned int cpu) +static __init void snp_enable(void *arg) { u64 val; =20 if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) - return 0; + return; =20 rdmsrq(MSR_AMD64_SYSCFG, val); =20 @@ -164,13 +157,6 @@ static int __snp_enable(unsigned int cpu) val |=3D MSR_AMD64_SYSCFG_SNP_VMPL_EN; =20 wrmsrq(MSR_AMD64_SYSCFG, val); - - return 0; -} - -static __init void snp_enable(void *arg) -{ - __snp_enable(smp_processor_id()); } =20 static void __init __snp_fixup_e820_tables(u64 pa) @@ -553,8 +539,6 @@ int __init snp_rmptable_init(void) on_each_cpu(snp_enable, NULL, 1); =20 skip_enable: - cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_= enable, NULL); - /* * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic * notifier is invoked to do SNP IOMMU shutdown before kdump. --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 BABF7366DB7; Mon, 2 Mar 2026 19:14:34 +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=1772478874; cv=none; b=Trt7e/PdIeNMCIJbIqrSIpSf9LDs0L8UvdCb/S9astKrpe3DCs8cu2icrUrXomv1JaRh+tQK0l/nj1JbLgPTDECGZsZ7Pm3CIlKCP5pqPCqQByAgbmTAs5oQC7aT6CROPTclQ10zd9JmfcIMHiJOO8zZgLbGQ3E7D+o2U6jf8Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478874; c=relaxed/simple; bh=fFDjbzQSB9XtQHzqU10kxCoVxNcp9uM4c+YvBs9ZhlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aJhro4J31JRqkDAAtSZN4UrcsbLppX3oezH9/7jP5nufQX86aD1OedTkwJieWzSPmjoj44CVgnWwr77fG3BR25+B+2PJNSNAzAXKFkIi4PNCGSVusDANceldLe1bGSNXn8OIENY5qDHYV7zTat/wY4qeTwBdD29IKI5Y47CBenE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hWP/dQip; 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="hWP/dQip" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40357C19425; Mon, 2 Mar 2026 19:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478874; bh=fFDjbzQSB9XtQHzqU10kxCoVxNcp9uM4c+YvBs9ZhlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWP/dQipIRxAY+GJ2m/uU6alZOvnIgH/bEFHR1CNTMHyJxhl6xUnMJYzc5BaROTcB IUaFe4WBAUEnh1kCa7n4DKWDWc5zg6xZCMbr2Iitg16JjFPK5+gsK8ekx/27WBqkdE u9pC8GyB18eO27iRjo/+n7CSTXRknvnBdvAKSPGbILB+p94z3rwmvWyvrBfX+k+F2c jVy41AQyTHEFDjeI50OT527JW5+PQfnWdjBPwh+vmfgLKs/sl/BvB4uHxo2lo0EPrw 28WyQ2LReUrYRFRfDgvaM0Nfw0dwoko1qLzgXlrO5nNQZZ/AJiQj3NR8uPfd9Ypgde QH9nRRl6ozmyw== 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 Subject: [PATCH 02/11] x86/snp: Keep the RMP table bookkeeping area mapped Date: Mon, 2 Mar 2026 12:13:25 -0700 Message-ID: <20260302191334.937981-3-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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: Tom Lendacky In prep for delayed SNP initialization and disablement on shutdown, the RMP will need to be cleared each time SNP is disabled. Maintain the the mapping to the RMP bookkeeping area to avoid mapping and unmapping it each time and any possible errors that may arise from that. Signed-off-by: Tom Lendacky Signed-off-by: Tycho Andersen (AMD) --- arch/x86/virt/svm/sev.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 1446011c6337..232a385f11cb 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -117,6 +117,8 @@ static u64 rmp_segment_mask; =20 static u64 rmp_cfg; =20 +static void *rmp_bookkeeping __ro_after_init; + /* Mask to apply to a PFN to get the first PFN of a 2MB page */ #define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT) =20 @@ -246,23 +248,6 @@ void __init snp_fixup_e820_tables(void) } } =20 -static bool __init clear_rmptable_bookkeeping(void) -{ - void *bk; - - bk =3D memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB= ); - if (!bk) { - pr_err("Failed to map RMP bookkeeping area\n"); - return false; - } - - memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); - - memunmap(bk); - - return true; -} - static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size= , u64 pa) { u64 rst_index, rmp_segment_size_max; @@ -480,10 +465,22 @@ static bool __init setup_segmented_rmptable(void) static bool __init setup_rmptable(void) { if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) { - return setup_segmented_rmptable(); + if (!setup_segmented_rmptable()) + return false; } else { - return setup_contiguous_rmptable(); + if (!setup_contiguous_rmptable()) + return false; } + + rmp_bookkeeping =3D memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ= , MEMREMAP_WB); + if (!rmp_bookkeeping) { + pr_err("Failed to map RMP bookkeeping area\n"); + free_rmp_segment_table(); + + return false; + } + + return true; } =20 /* @@ -514,10 +511,7 @@ int __init snp_rmptable_init(void) goto skip_enable; =20 /* Zero out the RMP bookkeeping area */ - if (!clear_rmptable_bookkeeping()) { - free_rmp_segment_table(); - return -ENOSYS; - } + memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); =20 /* Zero out the RMP entries */ for (i =3D 0; i < rst_max_index; i++) { --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 512EC3563EB; Mon, 2 Mar 2026 19:14:37 +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=1772478879; cv=none; b=ihO3/j5CBQpTXRxcyHd05K69ChfzxPpQlK9hWpP+qAG8rULZWeBrxKfu4MT1rvzzOCrlZdx8JhpTWnW164UaKidfpDZVU5sILjvL1ViClhjUTbKQVOU8RKLewbXEW8BIzV8fqJxCV/hI+2MvVESpyn+OgL4BSHLV6eJ+Ur8h4+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478879; c=relaxed/simple; bh=2z0Z9xVg31c45Rdglcx0+GgzDD4kLyMnXSQlC9yF054=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mxdWHEAQaV72E/5tX8VroL4pkiNqP30wGlIdGK04jNGqwRYh4WgREV890xFFDZx1glnWjuAcdmi8U+UAedKGxAy9uFbi0ZGAAD+T8G6lzKDHsOdQq49fXfv/EmHj5cOy3hfBgo3m4nb5bjCdsM49xH5HdKf2o372aCskMKy7a78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=puDxrI8J; 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="puDxrI8J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFD49C4AF09; Mon, 2 Mar 2026 19:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478876; bh=2z0Z9xVg31c45Rdglcx0+GgzDD4kLyMnXSQlC9yF054=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=puDxrI8Jx8JtkkcTEEBLGrhPcEZ3a5vy42q7zKCps9sOABqwVyEfEvONTmgcBe3mb /8Ue20jQKXjG7cpn7/tuDgM/uVMQdT9l2gZv7IBgEvGiONhMsBmQVpB3TUFfSHTRxG cZLFs32szMX/g0hd/ZHO9UCgpnZ+g5Y22LXiNQJDg150bVcwgaPZrFoVKJObmiyuS8 mReiZ2/QpBbVfHMcDTJo/D+iEzSpHbxPKx4qFo71XKrNXMIiU+p0DOZDELSc9qt93n U39gJlYDWBN9MANxZEgcYia6WYZQq4i7B9bgT0RkhlYXdlUQ7UCd+sx/64Tnh8dbHD oP2I4Z8mp8B7w== 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 Subject: [PATCH 03/11] x86/snp: Create a function to clear/zero the RMP Date: Mon, 2 Mar 2026 12:13:26 -0700 Message-ID: <20260302191334.937981-4-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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: Tom Lendacky In prep for delayed SNP initialization and disablement on shutdown, create a function, snp_clear_rmp(), that clears the RMP bookkeeping area and the RMP entries. Signed-off-by: Tom Lendacky Signed-off-by: Tycho Andersen (AMD) --- arch/x86/virt/svm/sev.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 232a385f11cb..e7fbbf1cdf8e 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -248,6 +248,32 @@ void __init snp_fixup_e820_tables(void) } } =20 +static void snp_clear_rmp(void) +{ + unsigned int i; + u64 val; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return; + + /* Clearing the RMP while SNP is enabled will cause an exception */ + rdmsrq(MSR_AMD64_SYSCFG, val); + if (WARN_ON_ONCE(val & MSR_AMD64_SYSCFG_SNP_EN)) + return; + + memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); + + for (i =3D 0; i < rst_max_index; i++) { + struct rmp_segment_desc *desc; + + desc =3D rmp_segment_table[i]; + if (!desc) + continue; + + memset(desc->rmp_entry, 0, desc->size); + } +} + static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size= , u64 pa) { u64 rst_index, rmp_segment_size_max; @@ -490,7 +516,6 @@ static bool __init setup_rmptable(void) */ int __init snp_rmptable_init(void) { - unsigned int i; u64 val; =20 if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP))) @@ -510,19 +535,7 @@ int __init snp_rmptable_init(void) if (val & MSR_AMD64_SYSCFG_SNP_EN) goto skip_enable; =20 - /* Zero out the RMP bookkeeping area */ - memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); - - /* Zero out the RMP entries */ - for (i =3D 0; i < rst_max_index; i++) { - struct rmp_segment_desc *desc; - - desc =3D rmp_segment_table[i]; - if (!desc) - continue; - - memset(desc->rmp_entry, 0, desc->size); - } + snp_clear_rmp(); =20 /* Flush the caches to ensure that data is written before SNP is enabled.= */ wbinvd_on_all_cpus(); --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 74904332EBB; Mon, 2 Mar 2026 19:14:39 +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=1772478879; cv=none; b=Hc0NM3B6yG4hWLuX9DpamMds3fyOTpDFxTguK3+Dean8YNqzjik9uxkYtwKZtelES4gNl5+KTebkTogd8Ibodlyvgr/+L4Xkk2yAqSWCiFVcY618+SVxDJ69SZDQsUOR7R1d87++4jO2qXRijmPt6zVq2kvsq53sDw5CjMe53fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478879; c=relaxed/simple; bh=QefM6wT7TMbEzCC+rnX/XKIAXqXoIDMmEo0TgMSkPQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhL9i51SjAtIKfCnxNFNsWVmHvNcf9PM/Cj3nVKbY315+3yCW9CF5SBZN4/fzDFEqSuovFZGjBy/HlXdB/Wtx0NImPuY8hDoE3s4gQDh6o6HHDDDY+FbH5yrkPhC2FDhfjfSYcv7oBOcxVGKvFdhXAbM7dHEXuwx5YytiaQwNdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WW8NAKCr; 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="WW8NAKCr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A84AC19423; Mon, 2 Mar 2026 19:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478879; bh=QefM6wT7TMbEzCC+rnX/XKIAXqXoIDMmEo0TgMSkPQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WW8NAKCr19V1kjv0+BjUuKouHv5b9GXGFFIY+D0X3kRWz+v9uYAEQkCuDQEGAC9SX lAaWffaSMLGoyZPLp9SUADYGeArODqjtycgQLudxxRe2U4sNJlwbK23SbnlIhBjAtb 8ksXDbgAXmnYy36/dRflHK5pR/B8vWwBpG8fGgS2/bvc4xDRY9XwLhSDUBcYmMK6Fh MuHX53xTTt6ahDE8xEB63UddASELagagMlU9RUTChSFhsjteDLuTXnkK3inI2s5lBN Sr6Zy+lcExokGn+qNNtAnszctBtQLothQunkaW3ixSucheT3P8BClA7uFBDWQHUqfV pOO7P8rAhXA9Q== 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 Subject: [PATCH 04/11] x86/snp: drop WBINVD before setting SNPEn Date: Mon, 2 Mar 2026 12:13:27 -0700 Message-ID: <20260302191334.937981-5-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" WBINVD is required before SNP_INIT(_EX), but not before setting SNPEn, since the ccp driver already does its own WBINVD before SNP_INIT (and this one would be too early for that anyway...). Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/virt/svm/sev.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index e7fbbf1cdf8e..258e67ba7415 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -537,9 +537,6 @@ int __init snp_rmptable_init(void) =20 snp_clear_rmp(); =20 - /* Flush the caches to ensure that data is written before SNP is enabled.= */ - wbinvd_on_all_cpus(); - /* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP= . */ on_each_cpu(mfd_enable, NULL, 1); =20 --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 CB8B7375AA3; Mon, 2 Mar 2026 19:14:41 +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=1772478881; cv=none; b=oSH+DAuUMhZRWfwvsfRCIii/+Vy8C4BZWxWxaT2VfSvx1cy6YACX0Sn8GMtuSURsHd6MJaxZEwdZs8BojXhxlWpDy9/u/uwL032rKJGk/JyHxkUlujX+kqSwuBM1PHMREQ5E0yPe8dWYXKPFnRFSLC565OH4q6rQup7YyJs7k2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478881; c=relaxed/simple; bh=QJxRtbkiC5rPJpKBs/xYtXpiY4rVpiXxaROoLldlmQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U6PsV3Hdnaencp4S9VSPPZN6D1TTJl6CNey7HRM4Bhpw/Cl4sDvu5j8YmGGCjVzgRAKpS6h1mGbOahgTPkDJJk9Tu9JzignU62wU//1AORGvOjYJ06EfY3GgEc1gbEP9k2JbspqlMAgvbI9NZG+icWOg7ns54oXKJJ+UhLr3dHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DBnwwcQm; 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="DBnwwcQm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99BB6C4AF09; Mon, 2 Mar 2026 19:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478881; bh=QJxRtbkiC5rPJpKBs/xYtXpiY4rVpiXxaROoLldlmQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DBnwwcQmkjQgG8rQh9UNx2cNPubvSk2SHrDigyFawO2f/i66AZy6e2IBgoWLtHV5P lZRVNNsrD8dpxqRVHJsXDwmvGAe1PsuqugOYTgb57qBhCBpFg7ForjNNJXQ37ERHAC NKeEguxKNe56Fv4ac239/WOAsspNGbMUAzx3UVSoXZ6+oMtSAxK8vx+bvpAuiwWhMZ tnonQ4r7ei+w8R43QXc9Byp8aRVYfFb1rBUo8z7O/SBrx52G1BKi6NgVVD721LseOP 4JvXapazmwa4pekK5ajHuQD0gdk2kuV4JtOg1z2LOVMXqefblb7eJ106hiObJFAWZ5 nbIp6lykIHa3g== 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 Subject: [PATCH 05/11] x86/snp: create snp_prepare_for_snp_init() Date: Mon, 2 Mar 2026 12:13:28 -0700 Message-ID: <20260302191334.937981-6-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" In preparation for delayed SNP initialization, create a function snp_prepare_for_snp_init() that does the necessary architecture setup. Export this function for the ccp module to allow it to do the setup as necessary. Also move {mfd,snp}_enable out of the __init section, since these will be called later. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 46 ++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 0e6c0940100f..0bcd89d4fe90 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -661,6 +661,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= pages) { __snp_leak_pages(pfn, pages, true); } +void snp_prepare_for_snp_init(void); #else static inline bool snp_probe_rmptable_info(void) { return false; } static inline int snp_rmptable_init(void) { return -ENOSYS; } @@ -677,6 +678,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_for_snp_init(void) {} #endif =20 #endif diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 258e67ba7415..8f50538baf7b 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -132,7 +132,7 @@ static unsigned long snp_nr_leaked_pages; #undef pr_fmt #define pr_fmt(fmt) "SEV-SNP: " fmt =20 -static __init void mfd_enable(void *arg) +static void mfd_enable(void *arg) { u64 val; =20 @@ -146,7 +146,7 @@ static __init void mfd_enable(void *arg) wrmsrq(MSR_AMD64_SYSCFG, val); } =20 -static __init void snp_enable(void *arg) +static void snp_enable(void *arg) { u64 val; =20 @@ -509,6 +509,30 @@ static bool __init setup_rmptable(void) return true; } =20 +void snp_prepare_for_snp_init(void) +{ + u64 val; + + /* + * Check if SEV-SNP is already enabled, this can happen in case of + * kexec boot. + */ + rdmsrq(MSR_AMD64_SYSCFG, val); + if (val & MSR_AMD64_SYSCFG_SNP_EN) + return; + + snp_clear_rmp(); + + /* + * MtrrFixDramModEn is not shared between threads on a core, + * therefore it must be set on all CPUs prior to enabling SNP. + */ + on_each_cpu(mfd_enable, NULL, 1); + + on_each_cpu(snp_enable, NULL, 1); +} +EXPORT_SYMBOL_FOR_MODULES(snp_prepare_for_snp_init, "ccp"); + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP @@ -516,8 +540,6 @@ static bool __init setup_rmptable(void) */ int __init snp_rmptable_init(void) { - u64 val; - if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP))) return -ENOSYS; =20 @@ -527,22 +549,8 @@ int __init snp_rmptable_init(void) if (!setup_rmptable()) return -ENOSYS; =20 - /* - * Check if SEV-SNP is already enabled, this can happen in case of - * kexec boot. - */ - rdmsrq(MSR_AMD64_SYSCFG, val); - if (val & MSR_AMD64_SYSCFG_SNP_EN) - goto skip_enable; - - snp_clear_rmp(); - - /* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP= . */ - on_each_cpu(mfd_enable, NULL, 1); - - on_each_cpu(snp_enable, NULL, 1); + snp_prepare_for_snp_init(); =20 -skip_enable: /* * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic * notifier is invoked to do SNP IOMMU shutdown before kdump. --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 844213859FD; Mon, 2 Mar 2026 19:14:44 +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=1772478884; cv=none; b=fQKVQBY+qyLQGApuNj3lnKDBmZN1/KrR30oNQaR5C9+SzUtVGCQzTibgtlxc9oYxrm+BDt449VPaxkeRYo0o9YWh/8RmaQJ1KzQb90TaaInqsr2Bb0FzkPxC4blxkvBXhIxE0HkMzCOsGaIRG/4voNHuyFmH/PHDAmStOCq4ExE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478884; c=relaxed/simple; bh=scqSkI1wuci+U/aGIgSppjWdI7sQBnMTjpRIS4c6EVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sxlJ5L4k9vfP0ANKRZOzbWUEorvcRhXaKf60/ICVcI0kS/9vdsTePh2uz6MlWsXDGL6LG0giNjqJybnv6zA51JysjGwe7soVQHg9A0lMK1C7gveKqLjZfc6DKZQ4Nl7uUr5cJQApC3sUv2C/QxAzpvkadtMfOiqgiAZoeLgSpmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sb8NCgph; 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="Sb8NCgph" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2E1FC2BC87; Mon, 2 Mar 2026 19:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478884; bh=scqSkI1wuci+U/aGIgSppjWdI7sQBnMTjpRIS4c6EVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sb8NCgphYlCeUd/mSHzZDsHBuFknF5UnGuGenyTOsoIIbQT2XvZy+tBJdpI40aV18 wxlT8kmJ9FRfyLbFWNuxAwS0suHU9VJxRpQ21xkAP7tgK/3UOnHqMVhCXj1CmDvtea nx3w9Cc757Xd2jO6yZifCUYJ3ynEwUeAiWBgK50jwe4NCJ9yBBnPZIDFw7/r6RxMoO P8xF3UthUxZ4tZXE5w0eToDdGz9b+GcJzAv1rapvF99C/cVKCRxy1GpK/LuIYhtRUV fZlcd7fWVeFh5v2ev9Afnkfbzb670N5i7xIRKsoY5XYhNo5kXnXEXDz4Xb9FgW5qkq EEOT5ueX+MguQ== 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 Subject: [PATCH 06/11] x86/snp, crypto: move SNP init to ccp driver Date: Mon, 2 Mar 2026 12:13:29 -0700 Message-ID: <20260302191334.937981-7-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" Use the new snp_prepare_for_snp_init() to initialize SNP from the ccp driver instead of at boot time. This means that SNP is not enabled unless it is really going to be used (i.e. kvm_amd loads the ccp driver automatically). Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/virt/svm/sev.c | 2 -- drivers/crypto/ccp/sev-dev.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 8f50538baf7b..aa784542b32d 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -549,8 +549,6 @@ int __init snp_rmptable_init(void) if (!setup_rmptable()) return -ENOSYS; =20 - snp_prepare_for_snp_init(); - /* * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic * notifier is invoked to do SNP IOMMU shutdown before kdump. diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 096f993974d1..5b1a24b11e3e 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1375,6 +1375,8 @@ static int __sev_snp_init_locked(int *error, unsigned= int max_snp_asid) return -EOPNOTSUPP; } =20 + 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); =20 --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 378E83E0C4B; Mon, 2 Mar 2026 19:14:46 +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=1772478887; cv=none; b=Uh9aUoCdrJftvhm5QTIO4wKtzhzG9wPYPVbBgrOTpzZ5bh/faP1p8l0wCvJcfvv/1YkGmxpBkXi/ErDmT5SmcaC9Td0c8hViF6iZ+bzpmMfEz7B4nl/JwKkxHwwZ1ciiQXp5gLl2ZHoy4ghxfsGKkSs1P0DbCiNuq/zyxQt+6Z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478887; c=relaxed/simple; bh=UFroV8mauc76cWxH7swPjhVFjeW5UFWPeFCqSXmtJJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BeywJs7YwDfrb/VTarupAGu0qORTLCd/0OA/kI/sc7QpY8YSkP5CWeJMq30ZExo5KxjTu4Xz1wgiJekBP3SA7yhm63OltoQixtmbUEYqmcM7oTyDsRaWHh1mtBJHQXryRLJ9152pmaQfDEDO1C12JBEDJ2AA+BznuD49ZLHEU7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CbzdbfOg; 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="CbzdbfOg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70072C2BC9E; Mon, 2 Mar 2026 19:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478886; bh=UFroV8mauc76cWxH7swPjhVFjeW5UFWPeFCqSXmtJJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbzdbfOgQmocbWi0A2sz3VRTX3m6zmsdHQUvZP1oxbl32S5QZpF/KmhA4vnLKbazT FixfPD/+dU3QE6dEWwEtnL9LYfweJqap2agTBLxlRcHN3itltHwzTDieQvot/EyC/5 U2CxanvRO4I+gDbq/+LPNCKZ75v5iDo8IY6I1SSCeRrX/oTgxNq7AInV4rgpHWOsEj 79tAspZsC9JGhOYPrrYjyxUzaJvZG4EZNWOlknW39zLqRf5jyMH3F5FwKm7iO6PP1f cRmDsnJ8/bJW5Ga/wvrigdRXjYpuOcnT3axmNtSFYexM+QD9klNSOOntPm+SkXJrmC ArE8fNDBP3UHw== 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 Subject: [PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/ Date: Mon, 2 Mar 2026 12:13:30 -0700 Message-ID: <20260302191334.937981-8-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" 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) Reviewed-by: Tom Lendacky --- 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; } =20 +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); =20 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"); =20 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); } =20 -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) =20 snp_prepare_for_snp_init(); =20 - /* 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 --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 30FEF3E7146; Mon, 2 Mar 2026 19:14:49 +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=1772478889; cv=none; b=q/FNOmBL06itnF/ao2r/A15NADnlqDBAK9cllT9v2kJ2K7UAabFsD7Asoj7iHk4WrzTTg8scM9gpaQWyE1+1ej/ESeivdcyyHd/Ts49QCYUKBSmhHEC1K6kGdKZfAfNCXDkQhEfQcEBnmkdGTWRgdChNV9tQSPpfvnBTFJgz0uQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478889; c=relaxed/simple; bh=qAQttDEXuNN5uevUynuFwNEoZIIiao4qqyUzO8+IfTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkxkHgjwADDfhsa/Akv/F8PLiDml9L4pJ392pymqMY4wrbMAMGHDnRtNXYgzAU4Cl7Ssc1OF2u9/4nrtjnL1jyARNSqTtLZQfVhHKIxZBGxnDBxq8izKeLlnfjRkSBB+nelb5WsZJvyWSGQcbLtWrl+74llFYWFbmFEIIYaal/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BT74g3Av; 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="BT74g3Av" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DED95C19423; Mon, 2 Mar 2026 19:14:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478889; bh=qAQttDEXuNN5uevUynuFwNEoZIIiao4qqyUzO8+IfTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BT74g3AvvTBZdWue2nx3S10fGYbGqF7ZTO+PVZ3YMYF6yosRS8zrbCIyBQlIhojK4 uDsDRp2uoAVmQC0BD/4/sZm2wvmsUKHIQ2LlLEG2sWdbOxL1CmvzirW64pDWVhakUt r05VXWDKaDNFh+GySBBlMcNKwSUQehv8CwrRDMwv9g1cIF8LGw33or3KJmfOHXplar RD6SrMGKdmMf5+d5HC6IP9gpJy8nfuZ9gZvzSUV5ae3H6IjtFpfvnvl5QHbQccweh9 gyGu7fajujQOWlEP7Dj39C1Xm/xzohibTh3GZDIB2ByFTrxE4xSQV0YlcNjERDMi5j bkq1keD3IlxsA== 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 Subject: [PATCH 08/11] x86/snp: allow disabling MFDM Date: Mon, 2 Mar 2026 12:13:31 -0700 Message-ID: <20260302191334.937981-9-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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 SNP x86 shutdown path needs to disable MFDM, since as the comment for k8_check_syscfg_dram_mod_en(), the "BIOS" is supposed clear it, or the kernel in the case of module unload and shutdown followed by kexec. Change this helper to allow for disabling it. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/virt/svm/sev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 53bc0c7f2c50..cf984b8f4493 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -132,7 +132,7 @@ static unsigned long snp_nr_leaked_pages; #undef pr_fmt #define pr_fmt(fmt) "SEV-SNP: " fmt =20 -static void mfd_enable(void *arg) +static void mfd_reconfigure(void *arg) { u64 val; =20 @@ -141,7 +141,10 @@ static void mfd_enable(void *arg) =20 rdmsrq(MSR_AMD64_SYSCFG, val); =20 - val |=3D MSR_AMD64_SYSCFG_MFDM; + if (arg) + val |=3D MSR_AMD64_SYSCFG_MFDM; + else + val &=3D ~MSR_AMD64_SYSCFG_MFDM; =20 wrmsrq(MSR_AMD64_SYSCFG, val); } @@ -532,7 +535,7 @@ void snp_prepare_for_snp_init(void) * MtrrFixDramModEn is not shared between threads on a core, * therefore it must be set on all CPUs prior to enabling SNP. */ - on_each_cpu(mfd_enable, NULL, 1); + on_each_cpu(mfd_reconfigure, (void *)1, 1); =20 on_each_cpu(snp_enable, NULL, 1); =20 --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 D99913EBF0B; Mon, 2 Mar 2026 19:14:51 +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=1772478891; cv=none; b=eAQyIIOPQWcO+L2hMtmtt1IvFTHUqO9EXJ2Ndf2WyjHvRfBueY3rpnehN04FrnVP72LT5PKudBHMmmR15vYxKHFzMg5t1znNDVziYT++vzyKkTqVcdobNgVkmrp770NgXpDwBVTazmpoXgbfz+NOYOSparxH/6qmNTQL8p7fdvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478891; c=relaxed/simple; bh=S7O9Pwkij2Awxqvl2IdvidJkvTEayDKdMv2IpZS7iJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6mvYha9ZVBJbqWiSfKP555LcsWYyyVPZgnJ07h7QIZX16Z7VPIKIOgTDFPGXsn0cC5Fj7WEHK+TI2521TJPf+EJ7VCsR637WmSVNg3EB8HSMAdOqhXoJwFENC5e+Uqcin0bwjRDpIpbLpWCuYQ4CcLs5pW2vWcv6c9hz1ITtpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P8wneOhP; 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="P8wneOhP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A0C6C19423; Mon, 2 Mar 2026 19:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478891; bh=S7O9Pwkij2Awxqvl2IdvidJkvTEayDKdMv2IpZS7iJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8wneOhP+zXAuZCvpw9yuabiGrOyLiz9dBMW4cZ+pPFFC3g1eO5um/M7eDfN8k0nX v+9kx8TjQxnexlfcSeoY1wjHgywzuHGXYhg2QXS/AD0Fgwck9mqahHVvSGoJB46smR tMPcFv/LbG0Pmo9qB7atsSoN4ZbC33yjk50fdxflRzUb8K3Ys0hrUqP52lWdt+mXWz eovC/3H7BgYN4Q4HaF3xpkmUm06jOHIdfLgBHf0UyrxinmI0rrZiUTdhyJ67pMhjV/ ph8l7g/quWv1dWl8RXx+6WFZ8T3/axHh6bF8BL3781idPvcxqNEW7zItS6SWodetB7 fbtwMIxVt19Tw== 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 Subject: [PATCH 09/11] x86/snp: create snp_x86_shutdown() Date: Mon, 2 Mar 2026 12:13:32 -0700 Message-ID: <20260302191334.937981-10-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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)" After SNP_SHUTDOWN, two architecture-level things should be done: 1. clear the RMP table 2. disable MFDM to prevent the FW_WARN in k8_check_syscfg_dram_mod_en() in the event of a kexec Create and export to the CCP driver a function that does them. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 0bcd89d4fe90..36d2b1ea19c0 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -662,6 +662,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= pages) __snp_leak_pages(pfn, pages, true); } void snp_prepare_for_snp_init(void); +void snp_x86_shutdown(void); #else static inline bool snp_probe_rmptable_info(void) { return false; } static inline int snp_rmptable_init(void) { return -ENOSYS; } @@ -679,6 +680,7 @@ 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_for_snp_init(void) {} +static inline void snp_x86_shutdown(void) {} #endif =20 #endif diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index cf984b8f4493..0524fc77b44d 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -544,6 +544,13 @@ void snp_prepare_for_snp_init(void) } EXPORT_SYMBOL_FOR_MODULES(snp_prepare_for_snp_init, "ccp"); =20 +void snp_x86_shutdown(void) +{ + snp_clear_rmp(); + on_each_cpu(mfd_reconfigure, 0, 1); +} +EXPORT_SYMBOL_FOR_MODULES(snp_x86_shutdown, "ccp"); + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 34BEF309F09; Mon, 2 Mar 2026 19:14:54 +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=1772478894; cv=none; b=DMiroMaoBbO4+DBudXDWBPZ+daGIOg0L6BuN15eJzZC6QRHY1u3Pkc23CbioexdYe5tncKtmppIEhWUJO07t04450UnVjmqecxdaWH2Y5El1+hChs6jRXEOlyrR/+vrDLgHKIlfEEUFP59VwLZKH5MQFUYayBEmS45bwRVHSfKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478894; c=relaxed/simple; bh=21Ry7jjWIzbqzER/hdAupJ4NZhWr92e6AyaCs3rFQlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AcHB9QLebCTtg3bq1H5Bt8TxlWXqgsBhHI8vcKzqBSP9iO9LUFV8cXr5gFplbWu+VE5mtb6N8mYOXFTpJ6x/F/PUKBk0tM0rS4I5xcBM3iXdhkBCAQNXpFG3/paoP75gtWZATAqwjtcU53p/+aeK7R42pOJxjPNfxv0f/qMq3nQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mz0UrFJ8; 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="Mz0UrFJ8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9113C2BC87; Mon, 2 Mar 2026 19:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478894; bh=21Ry7jjWIzbqzER/hdAupJ4NZhWr92e6AyaCs3rFQlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mz0UrFJ8CfJpIQMb1hyfCwv0EAwfJboNF0nWpWKhkJh9L5/iWO92aMEa1DcSGF2KP DSZMJYuGN+AQXFeZ9NaXf/FH2MS6KDPbrBt5TaLUF7qv8UnSrsqm5pCi6rP2qX/V1C DycMuIlDzbG0tj6BEbUOIrdBH7bKq0+aXRX+gE0cNg1/KGv50NYaL9CF9Q4OwXn0qm eaLCLdTry9nelMUUH3YTWXd5r6pQCZw0ECduUBOcos8ObuwqSNZ+UcNsSCsk+BiGuV gwwRGOzrhOTI6f1XG4WydKndzE8nVS8xHiiJvA7I+R5cDNgB9B2ia0XgfhLnt1tK/x 9BxBk/x6W/lKQ== 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 Subject: [PATCH 10/11] crypto: ccp - implement SNP x86 shutdown Date: Mon, 2 Mar 2026 12:13:33 -0700 Message-ID: <20260302191334.937981-11-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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 has support to disable SNP during an SNP_SHUTDOWN_EX command. Verify that this support is available and set the flag so that SNP is disabled when it is not being used. In cases where SNP is disabled, skip the call to amd_iommu_snp_disable(), as all of the IOMMU pages have already been made shared. Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 44 ++++++++++++++++++++++-------------- include/linux/psp-sev.h | 4 +++- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index ef45977b09b6..665fe0615b06 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2028,6 +2028,7 @@ static int __sev_snp_shutdown_locked(int *error, bool= panic) struct psp_device *psp =3D psp_master; struct sev_device *sev; struct sev_data_snp_shutdown_ex data; + u64 syscfg; int ret; =20 if (!psp || !psp->sev_data) @@ -2041,6 +2042,8 @@ static int __sev_snp_shutdown_locked(int *error, bool= panic) memset(&data, 0, sizeof(data)); data.len =3D sizeof(data); data.iommu_snp_shutdown =3D 1; + if (sev->snp_feat_info_0.ecx & SNP_X86_SHUTDOWN_SUPPORTED) + data.x86_snp_shutdown =3D 1; =20 /* * If invoked during panic handling, local interrupts are disabled @@ -2074,23 +2077,30 @@ static int __sev_snp_shutdown_locked(int *error, bo= ol panic) return ret; } =20 - /* - * SNP_SHUTDOWN_EX with IOMMU_SNP_SHUTDOWN set to 1 disables SNP - * enforcement by the IOMMU and also transitions all pages - * associated with the IOMMU to the Reclaim state. - * Firmware was transitioning the IOMMU pages to Hypervisor state - * before version 1.53. But, accounting for the number of assigned - * 4kB pages in a 2M page was done incorrectly by not transitioning - * to the Reclaim state. This resulted in RMP #PF when later accessing - * the 2M page containing those pages during kexec boot. Hence, the - * firmware now transitions these pages to Reclaim state and hypervisor - * needs to transition these pages to shared state. SNP Firmware - * version 1.53 and above are needed for kexec boot. - */ - ret =3D amd_iommu_snp_disable(); - if (ret) { - dev_err(sev->dev, "SNP IOMMU shutdown failed\n"); - return ret; + rdmsrq(MSR_AMD64_SYSCFG, syscfg); + if (data.x86_snp_shutdown && + !WARN_ON_ONCE(syscfg & MSR_AMD64_SYSCFG_SNP_EN)) { + if (!panic) + snp_x86_shutdown(); + } else { + /* + * SNP_SHUTDOWN_EX with IOMMU_SNP_SHUTDOWN set to 1 disables SNP + * enforcement by the IOMMU and also transitions all pages + * associated with the IOMMU to the Reclaim state. + * Firmware was transitioning the IOMMU pages to Hypervisor state + * before version 1.53. But, accounting for the number of assigned + * 4kB pages in a 2M page was done incorrectly by not transitioning + * to the Reclaim state. This resulted in RMP #PF when later accessing + * the 2M page containing those pages during kexec boot. Hence, the + * firmware now transitions these pages to Reclaim state and hypervisor + * needs to transition these pages to shared state. SNP Firmware + * version 1.53 and above are needed for kexec boot. + */ + ret =3D amd_iommu_snp_disable(); + if (ret) { + dev_err(sev->dev, "SNP IOMMU shutdown failed\n"); + return ret; + } } =20 snp_leak_hv_fixed_pages(); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 69ffa4b4d1fa..2adb990189c1 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -834,7 +834,8 @@ struct sev_data_range_list { struct sev_data_snp_shutdown_ex { u32 len; u32 iommu_snp_shutdown:1; - u32 rsvd1:31; + u32 x86_snp_shutdown:1; + u32 rsvd1:30; } __packed; =20 /** @@ -891,6 +892,7 @@ struct snp_feature_info { } __packed; =20 /* Feature bits in ECX */ +#define SNP_X86_SHUTDOWN_SUPPORTED BIT(1) #define SNP_RAPL_DISABLE_SUPPORTED BIT(2) #define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3) #define SNP_AES_256_XTS_POLICY_SUPPORTED BIT(4) --=20 2.53.0 From nobody Tue Mar 3 03:20:24 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 BD1BF379EC4; Mon, 2 Mar 2026 19:14:56 +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=1772478896; cv=none; b=fvXO9B74aHlB3oXEn7TL5SGTPTDbq2cuHCStWw4ED0UWM8w1X2+aFq9turzgywSpS88HNivPz/vO4Cd/XicUJbJlwj5PUiC81KAQvxsOXc7p6BQGMfGYGXtp+5zDVh+zYROP4JNSz53TOveUxiFOTdoTSp4uCOOeZCo2N/mPdw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772478896; c=relaxed/simple; bh=kyd4qRfbfq/KxyUYFLuDBOx54KDX2SAP4aqIvXfmEUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bYAcwzs+MnAFUzE8ojSNQxxuHNhkm9cFEaFr7IFDCmJaOIWrz33rj7ppPeeZEUtXday+cWioH5szFNpn8JxwsP/aAiqq8g5Q5W3kRIMnNmVgeEj2Ef+6ayySURxRFkZsGazcHkbg0sa9zZxCl1S0l1slC7q9hmAS/kIyVGRqTHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UeAkL8Yf; 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="UeAkL8Yf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45F4DC19425; Mon, 2 Mar 2026 19:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772478896; bh=kyd4qRfbfq/KxyUYFLuDBOx54KDX2SAP4aqIvXfmEUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UeAkL8YfJhDOoM7xK5rB1pCAkk+1G1qH0SRWWppQujtbdqT7XuRuECRve+/KasnPo PH9+wB7rNlZ4nkWDtrtL3fZaMP3rrWBZoi9wljowiyJuBAbRNdcCuKujfDeg2HiBor WHPI6XztZdCrRLP37mJMiIPFex1QtgYtzUIMTFllrsP2oTeSKTzJs5A3m1LRn+X5AB hTA8d0dsfMGCC4vVlsnqOZokVHbYffrqP1RsEI1XxlNwdHLDYlMNnOUejkK2ZN3Dm9 gzW2pz41mKV+INn4SIjy6oO6IZMiwItAOMymK8TjP1KQM0QlDABAXCPMGJ0vrt5SKK 8NJav87WAuZ8A== 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 Subject: [PATCH 11/11] crypto: ccp - Update HV_FIXED page states to allow freeing of memory Date: Mon, 2 Mar 2026 12:13:34 -0700 Message-ID: <20260302191334.937981-12-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302191334.937981-1-tycho@kernel.org> References: <20260302191334.937981-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: Tom Lendacky After SNP is disabled, any pages allocated as HV_FIXED can now be freed. Update the page state of these pages and the snp_leak_hv_fixed_pages() function to free pages on SNP_SHUTDOWN. Signed-off-by: Tom Lendacky Signed-off-by: Tycho Andersen (AMD) --- drivers/crypto/ccp/sev-dev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 665fe0615b06..930fe98993d7 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1221,7 +1221,7 @@ static void snp_add_hv_fixed_pages(struct sev_device = *sev, struct sev_data_range =20 static void snp_leak_hv_fixed_pages(void) { - struct snp_hv_fixed_pages_entry *entry; + struct snp_hv_fixed_pages_entry *entry, *nentry; =20 /* List is protected by sev_cmd_mutex */ lockdep_assert_held(&sev_cmd_mutex); @@ -1229,10 +1229,16 @@ static void snp_leak_hv_fixed_pages(void) if (list_empty(&snp_hv_fixed_pages)) return; =20 - list_for_each_entry(entry, &snp_hv_fixed_pages, list) - if (entry->page_state =3D=3D HV_FIXED) + list_for_each_entry_safe(entry, nentry, &snp_hv_fixed_pages, list) { + if (entry->free && entry->page_state !=3D HV_FIXED) + __free_pages(entry->page, entry->order); + else __snp_leak_pages(page_to_pfn(entry->page), 1 << entry->order, false); + + list_del(&entry->list); + kfree(entry); + } } =20 bool sev_is_snp_ciphertext_hiding_supported(void) @@ -2082,6 +2088,7 @@ static int __sev_snp_shutdown_locked(int *error, bool= panic) !WARN_ON_ONCE(syscfg & MSR_AMD64_SYSCFG_SNP_EN)) { if (!panic) snp_x86_shutdown(); + snp_hv_fixed_pages_state_update(sev, ALLOCATED); } else { /* * SNP_SHUTDOWN_EX with IOMMU_SNP_SHUTDOWN set to 1 disables SNP --=20 2.53.0