Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260324161301.1353976-2-tycho@kernel.org

authored by

Tom Lendacky and committed by
Borislav Petkov (AMD)
9c016c3f 531397a8

+27 -14
+27 -14
arch/x86/virt/svm/sev.c
··· 242 242 } 243 243 } 244 244 245 + static void clear_rmp(void) 246 + { 247 + unsigned int i; 248 + u64 val; 249 + 250 + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) 251 + return; 252 + 253 + /* Clearing the RMP while SNP is enabled will cause an exception */ 254 + rdmsrq(MSR_AMD64_SYSCFG, val); 255 + if (WARN_ON_ONCE(val & MSR_AMD64_SYSCFG_SNP_EN)) 256 + return; 257 + 258 + memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); 259 + 260 + for (i = 0; i < rst_max_index; i++) { 261 + struct rmp_segment_desc *desc; 262 + 263 + desc = rmp_segment_table[i]; 264 + if (!desc) 265 + continue; 266 + 267 + memset(desc->rmp_entry, 0, desc->size); 268 + } 269 + } 270 + 245 271 static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size, u64 pa) 246 272 { 247 273 u64 rst_index, rmp_segment_size_max; ··· 510 484 */ 511 485 int __init snp_rmptable_init(void) 512 486 { 513 - unsigned int i; 514 487 u64 val; 515 488 516 489 if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP))) ··· 529 504 if (val & MSR_AMD64_SYSCFG_SNP_EN) 530 505 goto skip_enable; 531 506 532 - /* Zero out the RMP bookkeeping area */ 533 - memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); 534 - 535 - /* Zero out the RMP entries */ 536 - for (i = 0; i < rst_max_index; i++) { 537 - struct rmp_segment_desc *desc; 538 - 539 - desc = rmp_segment_table[i]; 540 - if (!desc) 541 - continue; 542 - 543 - memset(desc->rmp_entry, 0, desc->size); 544 - } 507 + clear_rmp(); 545 508 546 509 /* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP. */ 547 510 on_each_cpu(mfd_enable, NULL, 1);