Skip to content

Commit ac51796

Browse files
tlendackybp3tk0v
authored andcommitted
x86/sev: Map only the RMP table entries instead of the full RMP range
In preparation for support of a segmented RMP table, map only the RMP table entries. The RMP bookkeeping area is only ever accessed when first enabling SNP and does not need to remain mapped. To accomplish this, split the initialization of the RMP bookkeeping area and the initialization of the RMP entry area. The RMP bookkeeping area will be mapped only while it is being initialized. Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Nikunj A Dadhania <[email protected]> Reviewed-by: Neeraj Upadhyay <[email protected]> Reviewed-by: Ashish Kalra <[email protected]> Link: https://lore.kernel.org/r/22f179998d319834f49c13a8c01187fbf0fd308d.1733172653.git.thomas.lendacky@amd.com
1 parent e2f3d40 commit ac51796

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

arch/x86/virt/svm/sev.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ void __init snp_fixup_e820_tables(void)
173173
__snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size);
174174
}
175175

176+
static bool __init clear_rmptable_bookkeeping(void)
177+
{
178+
void *bk;
179+
180+
bk = memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB);
181+
if (!bk) {
182+
pr_err("Failed to map RMP bookkeeping area\n");
183+
return false;
184+
}
185+
186+
memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ);
187+
188+
memunmap(bk);
189+
190+
return true;
191+
}
192+
176193
/*
177194
* Do the necessary preparations which are verified by the firmware as
178195
* described in the SNP_INIT_EX firmware command description in the SNP
@@ -210,12 +227,17 @@ static int __init snp_rmptable_init(void)
210227
goto nosnp;
211228
}
212229

213-
rmptable_start = memremap(probed_rmp_base, probed_rmp_size, MEMREMAP_WB);
230+
/* Map only the RMP entries */
231+
rmptable_start = memremap(probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ,
232+
probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ,
233+
MEMREMAP_WB);
214234
if (!rmptable_start) {
215235
pr_err("Failed to map RMP table\n");
216236
goto nosnp;
217237
}
218238

239+
rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ;
240+
219241
/*
220242
* Check if SEV-SNP is already enabled, this can happen in case of
221243
* kexec boot.
@@ -224,7 +246,14 @@ static int __init snp_rmptable_init(void)
224246
if (val & MSR_AMD64_SYSCFG_SNP_EN)
225247
goto skip_enable;
226248

227-
memset(rmptable_start, 0, probed_rmp_size);
249+
/* Zero out the RMP bookkeeping area */
250+
if (!clear_rmptable_bookkeeping()) {
251+
memunmap(rmptable_start);
252+
goto nosnp;
253+
}
254+
255+
/* Zero out the RMP entries */
256+
memset(rmptable_start, 0, rmptable_size);
228257

229258
/* Flush the caches to ensure that data is written before SNP is enabled. */
230259
wbinvd_on_all_cpus();
@@ -235,9 +264,6 @@ static int __init snp_rmptable_init(void)
235264
on_each_cpu(snp_enable, NULL, 1);
236265

237266
skip_enable:
238-
rmptable_start += RMPTABLE_CPU_BOOKKEEPING_SZ;
239-
rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ;
240-
241267
rmptable = (struct rmpentry_raw *)rmptable_start;
242268
rmptable_max_pfn = rmptable_size / sizeof(struct rmpentry_raw) - 1;
243269

0 commit comments

Comments
 (0)