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/virt/sev: Keep the RMP table bookkeeping area mapped

In preparation for delayed SNP initialization and disablement on shutdown, the
RMP will need to be cleared each time SNP is disabled. Maintain 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 <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/20260309180053.2389118-4-tycho@kernel.org

authored by

Tom Lendacky and committed by
Borislav Petkov (AMD)
cca14942 99cf1fb5

+17 -23
+17 -23
arch/x86/virt/svm/sev.c
··· 117 117 118 118 static u64 rmp_cfg; 119 119 120 + static void *rmp_bookkeeping __ro_after_init; 121 + 120 122 /* Mask to apply to a PFN to get the first PFN of a 2MB page */ 121 123 #define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT) 122 124 ··· 240 238 } else { 241 239 fixup_e820_tables_for_contiguous_rmp(); 242 240 } 243 - } 244 - 245 - static bool __init clear_rmptable_bookkeeping(void) 246 - { 247 - void *bk; 248 - 249 - bk = memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB); 250 - if (!bk) { 251 - pr_err("Failed to map RMP bookkeeping area\n"); 252 - return false; 253 - } 254 - 255 - memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); 256 - 257 - memunmap(bk); 258 - 259 - return true; 260 241 } 261 242 262 243 static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size, u64 pa) ··· 459 474 static bool __init setup_rmptable(void) 460 475 { 461 476 if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) { 462 - return setup_segmented_rmptable(); 477 + if (!setup_segmented_rmptable()) 478 + return false; 463 479 } else { 464 - return setup_contiguous_rmptable(); 480 + if (!setup_contiguous_rmptable()) 481 + return false; 465 482 } 483 + 484 + rmp_bookkeeping = memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB); 485 + if (!rmp_bookkeeping) { 486 + pr_err("Failed to map RMP bookkeeping area\n"); 487 + free_rmp_segment_table(); 488 + 489 + return false; 490 + } 491 + 492 + return true; 466 493 } 467 494 468 495 /* ··· 505 508 goto skip_enable; 506 509 507 510 /* Zero out the RMP bookkeeping area */ 508 - if (!clear_rmptable_bookkeeping()) { 509 - free_rmp_segment_table(); 510 - return -ENOSYS; 511 - } 511 + memset(rmp_bookkeeping, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); 512 512 513 513 /* Zero out the RMP entries */ 514 514 for (i = 0; i < rst_max_index; i++) {