[SRU][Q:gcp][PATCH 1/5] x86/kvm: Override default caching mode for SEV-SNP and TDX

Tim Whisonant tim.whisonant at canonical.com
Thu Dec 4 00:56:28 UTC 2025


From: "Kirill A. Shutemov" <kirill.shutemov at linux.intel.com>

BugLink: https://bugs.launchpad.net/bugs/2133834

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 <kirill.shutemov at linux.intel.com>
Suggested-by: Binbin Wu <binbin.wu at intel.com>
Cc: Juergen Gross <jgross at suse.com>
Cc: Tom Lendacky <thomas.lendacky at amd.com>
Reviewed-by: Juergen Gross <jgross at suse.com>
Message-ID: <20241015095818.357915-1-kirill.shutemov at linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
(cherry picked from commit 8e690b817e38769dc2fa0e7473e5a5dc1fc25795)
Signed-off-by: Tim Whisonant <tim.whisonant at canonical.com>
---
 arch/x86/kernel/kvm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 26d5643f565c..0dae054a9321 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -37,6 +37,7 @@
 #include <asm/apic.h>
 #include <asm/apicdef.h>
 #include <asm/hypervisor.h>
+#include <asm/mtrr.h>
 #include <asm/tlb.h>
 #include <asm/cpuidle_haltpoll.h>
 #include <asm/msr.h>
@@ -980,6 +981,9 @@ static void __init kvm_init_platform(void)
 	}
 	kvmclock_init();
 	x86_platform.apic_post_init = kvm_apic_init;
+
+	/* Set WB as the default cache mode for SEV-SNP and TDX */
+	mtrr_overwrite_state(NULL, 0, MTRR_TYPE_WRBACK);
 }
 
 #if defined(CONFIG_AMD_MEM_ENCRYPT)
-- 
2.43.0




More information about the kernel-team mailing list