3 SEV-SNP Page Validation functions.
5 Copyright (c) 2021 AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Uefi/UefiBaseType.h>
12 #include <Library/BaseLib.h>
13 #include <Library/MemEncryptSevLib.h>
15 #include "SnpPageStateChange.h"
18 // The variable used for the VMPL check.
20 STATIC UINT8 gVmpl0Data
[4096];
23 The function checks whether SEV-SNP guest is booted under VMPL0.
25 @retval TRUE The guest is booted under VMPL0
26 @retval FALSE The guest is not booted under VMPL0
38 // There is no straightforward way to query the current VMPL level.
39 // The simplest method is to use the RMPADJUST instruction to change
40 // a page permission to a VMPL level-1, and if the guest kernel is
41 // launched at a level <= 1, then RMPADJUST instruction will return
46 Status
= AsmRmpAdjust ((UINT64
)gVmpl0Data
, 0, Rdx
);
47 if (EFI_ERROR (Status
)) {
55 Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.
57 @param[in] BaseAddress Base address
58 @param[in] NumPages Number of pages starting from the base address
63 MemEncryptSevSnpPreValidateSystemRam (
64 IN PHYSICAL_ADDRESS BaseAddress
,
68 if (!MemEncryptSevSnpIsEnabled ()) {
73 // The page state change uses the PVALIDATE instruction. The instruction
74 // can be run on VMPL-0 only. If its not VMPL-0 guest then terminate
77 if (!SevSnpIsVmpl0 ()) {
78 SnpPageStateFailureTerminate ();
81 InternalSetPageState (BaseAddress
, NumPages
, SevSnpPagePrivate
, TRUE
);