Commit 9c016c3f authored by Tom Lendacky's avatar Tom Lendacky Committed by Borislav Petkov (AMD)
Browse files

x86/sev: Create a function to clear/zero the RMP



In preparation for delayed SNP initialization and disablement on shutdown,
create a function, clear_rmp(), that clears the RMP bookkeeping area and the
RMP entries.

Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarTycho Andersen (AMD) <tycho@kernel.org>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260324161301.1353976-2-tycho@kernel.org
parent 531397a8
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -242,6 +242,32 @@ void __init snp_fixup_e820_tables(void)
	}
}

static void 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);
	}
	clear_rmp();

	/* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP. */
	on_each_cpu(mfd_enable, NULL, 1);