TianoCore EDK2 master
Loading...
Searching...
No Matches
SecSnpSystemRamValidate.c
Go to the documentation of this file.
1
11#include <Uefi/UefiBaseType.h>
12#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
15#include <Library/AmdSvsmLib.h>
16
17#include "SnpPageStateChange.h"
18
19//
20// The variable used for the VMPL check.
21//
22STATIC UINT8 gVmpl0Data[4096];
23
31BOOLEAN
33 VOID
34 )
35{
36 UINT64 Rdx;
37 UINT32 Status;
38
39 //
40 // There is no straightforward way to query the current VMPL level.
41 // The simplest method is to use the RMPADJUST instruction to change
42 // a page permission to a VMPL level-1, and if the guest kernel is
43 // launched at a level <= 1, then RMPADJUST instruction will return
44 // an error.
45 //
46 Rdx = 1;
47
48 Status = AsmRmpAdjust ((UINT64)gVmpl0Data, 0, Rdx);
49 if (Status != 0) {
50 return FALSE;
51 }
52
53 return TRUE;
54}
55
63VOID
64EFIAPI
66 IN PHYSICAL_ADDRESS BaseAddress,
67 IN UINTN NumPages
68 )
69{
70 SEC_SEV_ES_WORK_AREA *SevEsWorkArea;
71
73 return;
74 }
75
76 //
77 // The page state change uses the PVALIDATE instruction. The instruction
78 // can be run at VMPL-0 only. If its not a VMPL-0 guest, then an SVSM must
79 // be present to perform the operation on behalf of the guest. If the guest
80 // is not running at VMPL-0 and an SVSM is not present, then terminate the
81 // boot.
82 //
83 if (!SevSnpIsVmpl0 () && !AmdSvsmIsSvsmPresent ()) {
84 SnpPageStateFailureTerminate ();
85 }
86
87 SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *)FixedPcdGet32 (PcdSevEsWorkAreaBase);
88
90 BaseAddress,
91 NumPages,
92 SevSnpPagePrivate,
93 TRUE,
94 SevEsWorkArea->WorkBuffer,
95 sizeof (SevEsWorkArea->WorkBuffer)
96 );
97}
UINT64 UINTN
BOOLEAN EFIAPI AmdSvsmIsSvsmPresent(VOID)
Definition: AmdSvsmLib.c:130
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
BOOLEAN EFIAPI MemEncryptSevSnpIsEnabled(VOID)
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
STATIC BOOLEAN SevSnpIsVmpl0(VOID)
VOID EFIAPI MemEncryptSevSnpPreValidateSystemRam(IN PHYSICAL_ADDRESS BaseAddress, IN UINTN NumPages)
VOID InternalSetPageState(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN NumPages, IN SEV_SNP_PAGE_STATE State, IN BOOLEAN UseLargeEntry, IN VOID *PscBuffer, IN UINTN PscBufferSize)