Skip to content

Commit e4c00c4

Browse files
ashkalrabp3tk0v
authored andcommitted
x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
When leaking certain page types, such as Hypervisor Fixed (HV_FIXED) pages, it does not make sense to dump RMP contents for the 2MB range of the page(s) being leaked. In the case of HV_FIXED pages, this is not an error situation where the surrounding 2MB page RMP entries can provide debug information. Add new __snp_leak_pages() API with dump_rmp bool parameter to support continue adding pages to the snp_leaked_pages_list but not issue dump_rmpentry(). Make snp_leak_pages() a wrapper for the common case which also allows existing users to continue to dump RMP entries. Suggested-by: Thomas Lendacky <Thomas.Lendacky@amd.com> Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Acked-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/cover.1758057691.git.ashish.kalra@amd.com
1 parent 85df1cd commit e4c00c4

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

arch/x86/include/asm/sev.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,13 @@ void snp_dump_hva_rmpentry(unsigned long address);
655655
int psmash(u64 pfn);
656656
int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asid, bool immutable);
657657
int rmp_make_shared(u64 pfn, enum pg_level level);
658-
void snp_leak_pages(u64 pfn, unsigned int npages);
658+
void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp);
659659
void kdump_sev_callback(void);
660660
void snp_fixup_e820_tables(void);
661+
static inline void snp_leak_pages(u64 pfn, unsigned int pages)
662+
{
663+
__snp_leak_pages(pfn, pages, true);
664+
}
661665
#else
662666
static inline bool snp_probe_rmptable_info(void) { return false; }
663667
static inline int snp_rmptable_init(void) { return -ENOSYS; }
@@ -670,6 +674,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 as
670674
return -ENODEV;
671675
}
672676
static inline int rmp_make_shared(u64 pfn, enum pg_level level) { return -ENODEV; }
677+
static inline void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp) {}
673678
static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
674679
static inline void kdump_sev_callback(void) { }
675680
static inline void snp_fixup_e820_tables(void) {}

arch/x86/virt/svm/sev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ int rmp_make_shared(u64 pfn, enum pg_level level)
10291029
}
10301030
EXPORT_SYMBOL_GPL(rmp_make_shared);
10311031

1032-
void snp_leak_pages(u64 pfn, unsigned int npages)
1032+
void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp)
10331033
{
10341034
struct page *page = pfn_to_page(pfn);
10351035

@@ -1052,14 +1052,15 @@ void snp_leak_pages(u64 pfn, unsigned int npages)
10521052
(PageHead(page) && compound_nr(page) <= npages))
10531053
list_add_tail(&page->buddy_list, &snp_leaked_pages_list);
10541054

1055-
dump_rmpentry(pfn);
1055+
if (dump_rmp)
1056+
dump_rmpentry(pfn);
10561057
snp_nr_leaked_pages++;
10571058
pfn++;
10581059
page++;
10591060
}
10601061
spin_unlock(&snp_leaked_pages_list_lock);
10611062
}
1062-
EXPORT_SYMBOL_GPL(snp_leak_pages);
1063+
EXPORT_SYMBOL_GPL(__snp_leak_pages);
10631064

10641065
void kdump_sev_callback(void)
10651066
{

0 commit comments

Comments
 (0)