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
>
14
#include <
Library/MemEncryptSevLib.h
>
15
#include <
Library/AmdSvsmLib.h
>
16
17
#include "
SnpPageStateChange.h
"
18
19
//
20
// The variable used for the VMPL check.
21
//
22
STATIC
UINT8 gVmpl0Data[4096];
23
30
STATIC
31
BOOLEAN
32
SevSnpIsVmpl0
(
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
63
VOID
64
EFIAPI
65
MemEncryptSevSnpPreValidateSystemRam
(
66
IN
PHYSICAL_ADDRESS BaseAddress,
67
IN
UINTN
NumPages
68
)
69
{
70
SEC_SEV_ES_WORK_AREA
*SevEsWorkArea;
71
72
if
(!
MemEncryptSevSnpIsEnabled
()) {
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
89
InternalSetPageState
(
90
BaseAddress,
91
NumPages,
92
SevSnpPagePrivate,
93
TRUE
,
94
SevEsWorkArea->WorkBuffer,
95
sizeof (SevEsWorkArea->WorkBuffer)
96
);
97
}
UINTN
UINT64 UINTN
Definition:
ProcessorBind.h:112
AmdSvsmIsSvsmPresent
BOOLEAN EFIAPI AmdSvsmIsSvsmPresent(VOID)
Definition:
AmdSvsmLib.c:130
AmdSvsmLib.h
BaseLib.h
STATIC
#define STATIC
Definition:
Base.h:264
TRUE
#define TRUE
Definition:
Base.h:301
FALSE
#define FALSE
Definition:
Base.h:307
IN
#define IN
Definition:
Base.h:279
DebugLib.h
MemEncryptSevLib.h
MemEncryptSevSnpIsEnabled
BOOLEAN EFIAPI MemEncryptSevSnpIsEnabled(VOID)
Definition:
DxeMemEncryptSevLibInternal.c:113
FixedPcdGet32
#define FixedPcdGet32(TokenName)
Definition:
PcdLib.h:92
SevSnpIsVmpl0
STATIC BOOLEAN SevSnpIsVmpl0(VOID)
Definition:
SecSnpSystemRamValidate.c:32
MemEncryptSevSnpPreValidateSystemRam
VOID EFIAPI MemEncryptSevSnpPreValidateSystemRam(IN PHYSICAL_ADDRESS BaseAddress, IN UINTN NumPages)
Definition:
SecSnpSystemRamValidate.c:65
SnpPageStateChange.h
InternalSetPageState
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)
Definition:
SnpPageStateChangeInternal.c:225
UefiBaseType.h
_SEC_SEV_ES_WORK_AREA
Definition:
WorkArea.h:42
OvmfPkg
Library
BaseMemEncryptSevLib
X64
SecSnpSystemRamValidate.c
Generated on Fri Nov 15 2024 18:01:20 for TianoCore EDK2 by
1.9.6