public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/kvm: Override default caching mode for SEV-SNP and TDX
@ 2024-10-15  9:58 Kirill A. Shutemov
  2024-10-15 10:12 ` Jürgen Groß
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Kirill A. Shutemov @ 2024-10-15  9:58 UTC (permalink / raw)
  To: Paolo Bonzini, Vitaly Kuznetsov, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
  Cc: kvm, linux-kernel, Kirill A. Shutemov, Binbin Wu, Juergen Gross,
	Tom Lendacky

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@linux.intel.com>
Suggested-by: Binbin Wu <binbin.wu@intel.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Tom Lendacky <thomas.lendacky@amd.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 263f8aed4e2c..21e9e4845354 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/ptrace.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.45.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-01-28  9:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-15  9:58 [PATCH] x86/kvm: Override default caching mode for SEV-SNP and TDX Kirill A. Shutemov
2024-10-15 10:12 ` Jürgen Groß
2024-10-15 12:31   ` Kirill A. Shutemov
2024-10-15 12:37     ` Jürgen Groß
2024-10-15 13:14   ` Dave Hansen
2024-10-15 13:54     ` Kirill A. Shutemov
2024-10-15 14:00       ` Juergen Gross
2024-10-16 10:50 ` [PATCH] x86/mtrr: Rename mtrr_overwrite_state() to guest_force_mtrr_state() Kirill A. Shutemov
2024-10-19  5:11   ` Michael Kelley
2024-10-29 15:13   ` Kirill A. Shutemov
2024-10-29 17:37     ` Dave Hansen
2024-10-29 19:32       ` Kirill A. Shutemov
2024-10-20 11:07 ` [PATCH] x86/kvm: Override default caching mode for SEV-SNP and TDX Paolo Bonzini
2025-01-24 20:59 ` Sean Christopherson
2025-01-28  9:40   ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox