public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Tycho Andersen <tycho@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Ashish Kalra <ashish.kalra@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	John Allen <john.allen@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Ard Biesheuvel <ardb@kernel.org>,
	Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>,
	Kishon Vijay Abraham I <kvijayab@amd.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Kim Phillips <kim.phillips@amd.com>,
	Sean Christopherson <seanjc@google.com>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: [PATCH v2 04/10] x86/snp: Create a function to clear/zero the RMP
Date: Mon,  9 Mar 2026 12:00:46 -0600	[thread overview]
Message-ID: <20260309180053.2389118-5-tycho@kernel.org> (raw)
In-Reply-To: <20260309180053.2389118-1-tycho@kernel.org>

From: Tom Lendacky <thomas.lendacky@amd.com>

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 <thomas.lendacky@amd.com>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 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 e35fac0a8a3d..f41b92e40014 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -242,6 +242,32 @@ void __init snp_fixup_e820_tables(void)
 	}
 }
 
+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 = 0; i < rst_max_index; i++) {
+		struct rmp_segment_desc *desc;
+
+		desc = 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;
@@ -484,7 +510,6 @@ static bool __init setup_rmptable(void)
  */
 int __init snp_rmptable_init(void)
 {
-	unsigned int i;
 	u64 val;
 
 	if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP)))
@@ -504,19 +529,7 @@ int __init snp_rmptable_init(void)
 	if (val & MSR_AMD64_SYSCFG_SNP_EN)
 		goto skip_enable;
 
-	/* Zero out the RMP bookkeeping area */
-	memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ);
-
-	/* Zero out the RMP entries */
-	for (i = 0; i < rst_max_index; i++) {
-		struct rmp_segment_desc *desc;
-
-		desc = rmp_segment_table[i];
-		if (!desc)
-			continue;
-
-		memset(desc->rmp_entry, 0, desc->size);
-	}
+	snp_clear_rmp();
 
 	/* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP. */
 	on_each_cpu(mfd_enable, NULL, 1);
-- 
2.53.0


  parent reply	other threads:[~2026-03-09 18:01 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 19:13 [PATCH 00/11] Move SEV-SNP initialization to ccp driver Tycho Andersen
2026-03-02 19:13 ` [PATCH 01/11] x86/snp: drop support for SNP hotplug Tycho Andersen
2026-03-02 19:56   ` Tom Lendacky
2026-03-05 12:57   ` Borislav Petkov
2026-03-06 15:38   ` Borislav Petkov
2026-03-09 18:00     ` [PATCH v2 00/10] Move SNP initialization to the CCP driver Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 01/10] x86/snp: drop support for SNP hotplug Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 02/10] x86/snp: drop WBINVD before setting SNPEn Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 03/10] x86/snp: Keep the RMP table bookkeeping area mapped Tycho Andersen
2026-03-09 18:00       ` Tycho Andersen [this message]
2026-03-13 16:17         ` [PATCH v2 04/10] x86/snp: Create a function to clear/zero the RMP Borislav Petkov
2026-03-09 18:00       ` [PATCH v2 05/10] x86/snp: create snp_prepare_for_snp_init() Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 06/10] x86/snp, crypto: move SNP init to ccp driver Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 07/10] x86/snp, crypto: move HSAVE_PA setup to arch/ Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 08/10] x86/snp: create snp_x86_shutdown() Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 09/10] crypto: ccp - implement SNP x86 shutdown Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 10/10] crypto: ccp - Update HV_FIXED page states to allow freeing of memory Tycho Andersen
2026-03-02 19:13 ` [PATCH 02/11] x86/snp: Keep the RMP table bookkeeping area mapped Tycho Andersen
2026-03-06 15:55   ` Borislav Petkov
2026-03-02 19:13 ` [PATCH 03/11] x86/snp: Create a function to clear/zero the RMP Tycho Andersen
2026-03-02 19:13 ` [PATCH 04/11] x86/snp: drop WBINVD before setting SNPEn Tycho Andersen
2026-03-02 20:00   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 05/11] x86/snp: create snp_prepare_for_snp_init() Tycho Andersen
2026-03-02 20:03   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 06/11] x86/snp, crypto: move SNP init to ccp driver Tycho Andersen
2026-03-02 20:25   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/ Tycho Andersen
2026-03-02 20:27   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 08/11] x86/snp: allow disabling MFDM Tycho Andersen
2026-03-02 20:29   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 09/11] x86/snp: create snp_x86_shutdown() Tycho Andersen
2026-03-02 20:35   ` Tom Lendacky
2026-03-02 21:20     ` Tycho Andersen
2026-03-02 19:13 ` [PATCH 10/11] crypto: ccp - implement SNP x86 shutdown Tycho Andersen
2026-03-02 20:47   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 11/11] crypto: ccp - Update HV_FIXED page states to allow freeing of memory Tycho Andersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260309180053.2389118-5-tycho@kernel.org \
    --to=tycho@kernel.org \
    --cc=Neeraj.Upadhyay@amd.com \
    --cc=aik@amd.com \
    --cc=ardb@kernel.org \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=john.allen@amd.com \
    --cc=kim.phillips@amd.com \
    --cc=kvijayab@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox