Skip to content

Commit cdaa0a4

Browse files
tlendackysuryasaimadhu
authored andcommitted
x86/sev: Don't use cc_platform_has() for early SEV-SNP calls
When running identity-mapped and depending on the kernel configuration, it is possible that the compiler uses jump tables when generating code for cc_platform_has(). This causes a boot failure because the jump table uses un-mapped kernel virtual addresses, not identity-mapped addresses. This has been seen with CONFIG_RETPOLINE=n. Similar to sme_encrypt_kernel(), use an open-coded direct check for the status of SNP rather than trying to eliminate the jump table. This preserves any code optimization in cc_platform_has() that can be useful post boot. It also limits the changes to SEV-specific files so that future compiler features won't necessarily require possible build changes just because they are not compatible with running identity-mapped. [ bp: Massage commit message. ] Fixes: 5e5ccff ("x86/sev: Add helper for validating pages in early enc attribute changes") Reported-by: Sean Christopherson <[email protected]> Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: <[email protected]> # 5.19.x Link: https://lore.kernel.org/all/[email protected]/
1 parent 4b1c742 commit cdaa0a4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arch/x86/kernel/sev.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,13 @@ static void __init early_set_pages_state(unsigned long paddr, unsigned int npage
701701
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
702702
unsigned int npages)
703703
{
704-
if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
704+
/*
705+
* This can be invoked in early boot while running identity mapped, so
706+
* use an open coded check for SNP instead of using cc_platform_has().
707+
* This eliminates worries about jump tables or checking boot_cpu_data
708+
* in the cc_platform_has() function.
709+
*/
710+
if (!(sev_status & MSR_AMD64_SEV_SNP_ENABLED))
705711
return;
706712

707713
/*
@@ -717,7 +723,13 @@ void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long padd
717723
void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
718724
unsigned int npages)
719725
{
720-
if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
726+
/*
727+
* This can be invoked in early boot while running identity mapped, so
728+
* use an open coded check for SNP instead of using cc_platform_has().
729+
* This eliminates worries about jump tables or checking boot_cpu_data
730+
* in the cc_platform_has() function.
731+
*/
732+
if (!(sev_status & MSR_AMD64_SEV_SNP_ENABLED))
721733
return;
722734

723735
/* Invalidate the memory pages before they are marked shared in the RMP table. */

0 commit comments

Comments
 (0)