diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c index bcc0798d6b..f1883239a6 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -145,6 +145,7 @@ BuildPageStateBuffer ( UINTN RmpPageSize; UINTN Index; UINTN IndexMax; + UINTN PscIndexMax; // Clear the page state structure SetMem (Info, InfoSize, 0); @@ -153,6 +154,16 @@ BuildPageStateBuffer ( IndexMax = (InfoSize - sizeof (Info->Header)) / sizeof (Info->Entry[0]); NextAddress = EndAddress; + // + // Make the use of the work area as efficient as possible relative to + // exiting from the guest to the hypervisor. Maximize the number of entries + // that can be processed per exit. + // + PscIndexMax = (IndexMax / SNP_PAGE_STATE_MAX_ENTRY) * SNP_PAGE_STATE_MAX_ENTRY; + if (PscIndexMax > 0) { + IndexMax = MIN (IndexMax, PscIndexMax); + } + // // Populate the page state entry structure //