From ce781cf8bb5e72d130b1db6a242c3bd312f5eb40 Mon Sep 17 00:00:00 2001 From: "Roth, Michael via groups.io" Date: Wed, 26 Apr 2023 04:32:57 +0800 Subject: OvmfPkg/CcExitLib: Fix SEV-SNP XSave area size calculation CPUID leaf 0xD sub-leafs 0x0 and 0x1 contain cumulative sizes for the enabled XSave areas. Those sizes are calculated by tallying up all the other sub-leafs that contain per-area size information for XSave areas that are currently enabled in XCr0/XSS. The current check has the logic inverted. Fix that. This doesn't seem to cause problems currently, but could in the future if OVMF made more extensive use of XSave areas. It was noticed while implementing SNP-related tests for KVM Unit Tests, which re-uses the OVMF #VC handler in some cases. Reported-by: Pavan Kumar Paluri Cc: Pavan Kumar Paluri Reviewed-by: Tom Lendacky Acked-by: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Michael Roth --- OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c index 7fe11c5324..94f0c4872c 100644 --- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c +++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c @@ -1145,9 +1145,7 @@ GetCpuidXSaveSize ( for (Idx = 0; Idx < CpuidInfo->Count; Idx++) { SEV_SNP_CPUID_FUNCTION *CpuidFn = &CpuidInfo->function[Idx]; - if (!((CpuidFn->EaxIn == 0xD) && - ((CpuidFn->EcxIn == 0) || (CpuidFn->EcxIn == 1)))) - { + if (!((CpuidFn->EaxIn == 0xD) && (CpuidFn->EcxIn > 1))) { continue; } -- cgit