TianoCore EDK2 master
Loading...
Searching...
No Matches
TpmMmioSevDecryptPeim.c
Go to the documentation of this file.
1
10#include <PiPei.h>
11
12#include <Library/DebugLib.h>
14#include <Library/PcdLib.h>
16
17STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmMmioRangeAccessible = {
18 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
19 &gOvmfTpmMmioAccessiblePpiGuid,
20 NULL
21};
22
32EFIAPI
34 IN EFI_PEI_FILE_HANDLE FileHandle,
35 IN CONST EFI_PEI_SERVICES **PeiServices
36 )
37{
38 RETURN_STATUS DecryptStatus;
39 EFI_STATUS Status;
40
41 DEBUG ((DEBUG_INFO, "%a\n", __func__));
42
43 //
44 // If SEV is active, MMIO succeeds against an encrypted physical address
45 // because the nested page fault (NPF) that occurs on access does not
46 // include the encryption bit in the guest physical address provided to the
47 // hypervisor.
48 //
49 // If SEV-ES is active, MMIO would succeed against an encrypted physical
50 // address because the #VC handler uses the virtual address (which is an
51 // identity mapped physical address without the encryption bit) as the guest
52 // physical address of the MMIO target in the VMGEXIT.
53 //
54 // However, if SEV-ES is active, before performing the actual MMIO, an
55 // additional MMIO mitigation check is performed in the #VC handler to ensure
56 // that MMIO is being done to/from an unencrypted address. To prevent guest
57 // termination in this scenario, mark the range unencrypted ahead of access.
58 //
60 DEBUG ((
61 DEBUG_INFO,
62 "%a: mapping TPM MMIO address range unencrypted\n",
63 __func__
64 ));
65
66 DecryptStatus = MemEncryptSevClearMmioPageEncMask (
67 0,
68 FixedPcdGet64 (PcdTpmBaseAddress),
69 EFI_SIZE_TO_PAGES ((UINTN)0x5000)
70 );
71
72 if (RETURN_ERROR (DecryptStatus)) {
73 DEBUG ((
74 DEBUG_ERROR,
75 "%a: failed to map TPM MMIO address range unencrypted\n",
76 __func__
77 ));
78 ASSERT_RETURN_ERROR (DecryptStatus);
79 }
80 }
81
82 //
83 // MMIO range available
84 //
85 Status = PeiServicesInstallPpi (&mTpmMmioRangeAccessible);
86 ASSERT_EFI_ERROR (Status);
87
88 return EFI_ABORTED;
89}
UINT64 UINTN
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define ASSERT_RETURN_ERROR(StatusParameter)
Definition: DebugLib.h:493
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFIAPI MemEncryptSevClearMmioPageEncMask(IN PHYSICAL_ADDRESS Cr3BaseAddress, IN PHYSICAL_ADDRESS BaseAddress, IN UINTN NumPages)
BOOLEAN EFIAPI MemEncryptSevEsIsEnabled(VOID)
#define FixedPcdGet64(TokenName)
Definition: PcdLib.h:106
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
EFI_STATUS EFIAPI TpmMmioSevDecryptPeimEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200