From 3a3b12cbdae2e89b0e365eb01c378891d0d9037c Mon Sep 17 00:00:00 2001 From: Min M Xu Date: Mon, 9 Sep 2024 13:33:51 +0800 Subject: [PATCH] UefiCpuPkg/MtrrLib: MtrrLibIsMtrrSupported always return FALSE in TD-Guest Currently, TDX exposes MTRR CPUID bit to TDX VM. So based on the CPUID, the guest software components (OVMF/TDVF and guest kernel) will access MTRR MSRs. One problem for guest to use of MTRR is the change of MTRR setting needs to set CR0.CD=1, which will case #VE for TDX. For Linux kernel, there is a mechanism called SW defined MTRR introduced by the patch https://lore.kernel.org/all/20230502120931. 20719-4-jgross@suse.com/. If this is integrated for TDX guest, then Linux kernel will not access any MTRR MSRs. So we update MtrrLibIsMtrrSupported() to always return false for TD-Guest, then TDVF will not access MTRR MSRs at all. Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Jiaxin Wu Cc: Jiewen Yao Cc: Binbin Wu Signed-off-by: Min Xu --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 4d4b52a4c3..61af77d9de 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -161,6 +161,13 @@ MtrrLibIsMtrrSupported ( CPUID_VERSION_INFO_EDX Edx; MSR_IA32_MTRRCAP_REGISTER MtrrCap; + // + // MTRR is not supported in TD-Guest. + // + if (TdIsEnabled ()) { + return FALSE; + } + // // Check CPUID(1).EDX[12] for MTRR capability //