File ovmf-OvmfPkg-CcExitLib-Use-the-proper-register-when-filte.patch of Package ovmf-edk2-stable202408
From 856bdc8eec0fd450ffb582808ad9649a5d02b480 Mon Sep 17 00:00:00 2001
From: Tom Lendacky <thomas.lendacky@amd.com>
Date: Fri, 25 Apr 2025 12:49:52 -0500
Subject: [PATCH] OvmfPkg/CcExitLib: Use the proper register when filtering
MSRs
The MsrExit() routine uses an incorrect register to check for the CAA MSR.
Instead of checking RCX, the input register for RDMSR/WRMSR that holds the
MSR value, it is checking RAX, which results in failure to detect the CAA
MSR request. The check should only be checking the lower 32-bits of the
register (ECX), too.
Change the check in MsrExit() to check the MSR value contained in ECX.
Fixes: 47001ab98914 ("Ovmfpkg/CcExitLib: Provide SVSM discovery support")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
index 2031fa9e22..2c12f78f8d 100644
--- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
+++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
@@ -701,6 +701,7 @@ MsrExit (
MSR_SVSM_CAA_REGISTER Msr;
UINT64 ExitInfo1;
UINT64 Status;
+ UINT32 EcxIn;
ExitInfo1 = 0;
@@ -708,7 +709,8 @@ MsrExit (
// The SVSM CAA MSR is a software implemented MSR and not supported
// by the hardware, handle it directly.
//
- if (Regs->Rax == MSR_SVSM_CAA) {
+ EcxIn = (UINT32)(UINTN)Regs->Rcx;
+ if (EcxIn == MSR_SVSM_CAA) {
// Writes to the SVSM CAA MSR are ignored
if (*(InstructionData->OpCodes + 1) == 0x30) {
return 0;
--
2.43.0