Skip to content

Commit 8e690b8

Browse files
kirylbonzini
authored andcommitted
x86/kvm: Override default caching mode for SEV-SNP and TDX
AMD SEV-SNP and Intel TDX have limited access to MTRR: either it is not advertised in CPUID or it cannot be programmed (on TDX, due to #VE on CR0.CD clear). This results in guests using uncached mappings where it shouldn't and pmd/pud_set_huge() failures due to non-uniform memory type reported by mtrr_type_lookup(). Override MTRR state, making it WB by default as the kernel does for Hyper-V guests. Signed-off-by: Kirill A. Shutemov <[email protected]> Suggested-by: Binbin Wu <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Tom Lendacky <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent bc07eea commit 8e690b8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/x86/kernel/kvm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <asm/apic.h>
3838
#include <asm/apicdef.h>
3939
#include <asm/hypervisor.h>
40+
#include <asm/mtrr.h>
4041
#include <asm/tlb.h>
4142
#include <asm/cpuidle_haltpoll.h>
4243
#include <asm/ptrace.h>
@@ -980,6 +981,9 @@ static void __init kvm_init_platform(void)
980981
}
981982
kvmclock_init();
982983
x86_platform.apic_post_init = kvm_apic_init;
984+
985+
/* Set WB as the default cache mode for SEV-SNP and TDX */
986+
mtrr_overwrite_state(NULL, 0, MTRR_TYPE_WRBACK);
983987
}
984988

985989
#if defined(CONFIG_AMD_MEM_ENCRYPT)

0 commit comments

Comments
 (0)