From 18fdffe825683df40d7a4a9eba11b8630bcef050 Mon Sep 17 00:00:00 2001 From: Tom Lendacky Date: Fri, 8 Mar 2024 07:32:32 -0800 Subject: [PATCH] OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654 Similar to the Page State Change optimization added previously, also take into account the possiblity of using the SVSM for PVALIDATE instructions. Conditionally adjust the maximum number of entries based on how many entries the SVSM calling area can support. Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Laszlo Ersek Cc: Michael Roth Cc: Min Xu Acked-by: Gerd Hoffmann Signed-off-by: Tom Lendacky --- .../BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c index c8c0c4ef0e..e073f3937c 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -18,6 +18,7 @@ #include #include +#include #include "SnpPageStateChange.h" @@ -78,6 +79,7 @@ BuildPageStateBuffer ( UINTN Index; UINTN IndexMax; UINTN PscIndexMax; + UINTN SvsmIndexMax; // Clear the page state structure SetMem (Info, InfoSize, 0); @@ -96,6 +98,11 @@ BuildPageStateBuffer ( IndexMax = MIN (IndexMax, PscIndexMax); } + SvsmIndexMax = (IndexMax / SVSM_PVALIDATE_MAX_ENTRY) * SVSM_PVALIDATE_MAX_ENTRY; + if (SvsmIndexMax > 0) { + IndexMax = MIN (IndexMax, SvsmIndexMax); + } + // // Populate the page state entry structure //