mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-23 05:34:31 +02:00
OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
In the next three patches, we're going to modify three modules under OvmfPkg. When OVMF is built with -D SMM_REQUIRE and runs in an SEV guest, each affected module will have to know the page range that covers the initial (pre-SMBASE relocation) SMRAM save state map. Add a helper function to MemEncryptSevLib that calculates the "base address" and "number of pages" constants for this page range. (In a RELEASE build -- i.e., with assertions disabled and optimization enabled --, the helper function can be compiled to store two constants determined at compile time.) Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Brijesh Singh <brijesh.singh@amd.com> Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
This commit is contained in:
parent
cd66bd7316
commit
61a044c6c1
@ -86,4 +86,27 @@ MemEncryptSevSetPageEncMask (
|
|||||||
IN UINTN NumPages,
|
IN UINTN NumPages,
|
||||||
IN BOOLEAN Flush
|
IN BOOLEAN Flush
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
|
||||||
|
Save State Map.
|
||||||
|
|
||||||
|
@param[out] BaseAddress The base address of the lowest-address page that
|
||||||
|
covers the initial SMRAM Save State Map.
|
||||||
|
|
||||||
|
@param[out] NumberOfPages The number of pages in the page range that covers
|
||||||
|
the initial SMRAM Save State Map.
|
||||||
|
|
||||||
|
@retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
|
||||||
|
output.
|
||||||
|
|
||||||
|
@retval RETURN_UNSUPPORTED SMM is unavailable.
|
||||||
|
**/
|
||||||
|
RETURN_STATUS
|
||||||
|
EFIAPI
|
||||||
|
MemEncryptSevLocateInitialSmramSaveStateMapPages (
|
||||||
|
OUT UINTN *BaseAddress,
|
||||||
|
OUT UINTN *NumberOfPages
|
||||||
|
);
|
||||||
#endif // _MEM_ENCRYPT_SEV_LIB_H_
|
#endif // _MEM_ENCRYPT_SEV_LIB_H_
|
||||||
|
@ -51,3 +51,7 @@
|
|||||||
CpuLib
|
CpuLib
|
||||||
DebugLib
|
DebugLib
|
||||||
MemoryAllocationLib
|
MemoryAllocationLib
|
||||||
|
PcdLib
|
||||||
|
|
||||||
|
[FeaturePcd]
|
||||||
|
gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
|
||||||
|
@ -17,9 +17,13 @@
|
|||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/MemEncryptSevLib.h>
|
#include <Library/MemEncryptSevLib.h>
|
||||||
|
#include <Library/PcdLib.h>
|
||||||
#include <Register/Amd/Cpuid.h>
|
#include <Register/Amd/Cpuid.h>
|
||||||
#include <Register/Amd/Msr.h>
|
#include <Register/Amd/Msr.h>
|
||||||
#include <Register/Cpuid.h>
|
#include <Register/Cpuid.h>
|
||||||
|
#include <Register/QemuSmramSaveStateMap.h>
|
||||||
|
#include <Register/SmramSaveStateMap.h>
|
||||||
|
#include <Uefi/UefiBaseType.h>
|
||||||
|
|
||||||
STATIC BOOLEAN mSevStatus = FALSE;
|
STATIC BOOLEAN mSevStatus = FALSE;
|
||||||
STATIC BOOLEAN mSevStatusChecked = FALSE;
|
STATIC BOOLEAN mSevStatusChecked = FALSE;
|
||||||
@ -87,3 +91,50 @@ MemEncryptSevIsEnabled (
|
|||||||
|
|
||||||
return mSevStatus;
|
return mSevStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
|
||||||
|
Save State Map.
|
||||||
|
|
||||||
|
@param[out] BaseAddress The base address of the lowest-address page that
|
||||||
|
covers the initial SMRAM Save State Map.
|
||||||
|
|
||||||
|
@param[out] NumberOfPages The number of pages in the page range that covers
|
||||||
|
the initial SMRAM Save State Map.
|
||||||
|
|
||||||
|
@retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
|
||||||
|
output.
|
||||||
|
|
||||||
|
@retval RETURN_UNSUPPORTED SMM is unavailable.
|
||||||
|
**/
|
||||||
|
RETURN_STATUS
|
||||||
|
EFIAPI
|
||||||
|
MemEncryptSevLocateInitialSmramSaveStateMapPages (
|
||||||
|
OUT UINTN *BaseAddress,
|
||||||
|
OUT UINTN *NumberOfPages
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN MapStart;
|
||||||
|
UINTN MapEnd;
|
||||||
|
UINTN MapPagesStart; // MapStart rounded down to page boundary
|
||||||
|
UINTN MapPagesEnd; // MapEnd rounded up to page boundary
|
||||||
|
UINTN MapPagesSize; // difference between MapPagesStart and MapPagesEnd
|
||||||
|
|
||||||
|
if (!FeaturePcdGet (PcdSmmSmramRequire)) {
|
||||||
|
return RETURN_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapStart = SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET;
|
||||||
|
MapEnd = MapStart + sizeof (QEMU_SMRAM_SAVE_STATE_MAP);
|
||||||
|
MapPagesStart = MapStart & ~(UINTN)EFI_PAGE_MASK;
|
||||||
|
MapPagesEnd = ALIGN_VALUE (MapEnd, EFI_PAGE_SIZE);
|
||||||
|
MapPagesSize = MapPagesEnd - MapPagesStart;
|
||||||
|
|
||||||
|
ASSERT ((MapPagesSize & EFI_PAGE_MASK) == 0);
|
||||||
|
|
||||||
|
*BaseAddress = MapPagesStart;
|
||||||
|
*NumberOfPages = MapPagesSize >> EFI_PAGE_SHIFT;
|
||||||
|
|
||||||
|
return RETURN_SUCCESS;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user