Changeset 89983 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei
- Timestamp:
- Jul 1, 2021 8:17:41 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 145450
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-139864 /vendor/edk2/current 103735-103757,103769-103776,129194-145445
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/AmdSev.c
r85718 r89983 2 2 Initialize Secure Encrypted Virtualization (SEV) support 3 3 4 Copyright (c) 2017 , Advanced Micro Devices. All rights reserved.<BR>4 Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<BR> 5 5 6 6 SPDX-License-Identifier: BSD-2-Clause-Patent … … 11 11 // 12 12 #include <IndustryStandard/Q35MchIch9.h> 13 #include <Library/BaseMemoryLib.h> 13 14 #include <Library/DebugLib.h> 14 15 #include <Library/HobLib.h> 15 16 #include <Library/MemEncryptSevLib.h> 17 #include <Library/MemoryAllocationLib.h> 16 18 #include <Library/PcdLib.h> 17 19 #include <PiPei.h> 18 #include <Register/Amd/Cpuid.h> 19 #include <Register/Cpuid.h> 20 #include <Register/Amd/Msr.h> 20 21 #include <Register/Intel/SmramSaveStateMap.h> 21 22 22 23 #include "Platform.h" 24 25 /** 26 27 Initialize SEV-ES support if running as an SEV-ES guest. 28 29 **/ 30 STATIC 31 VOID 32 AmdSevEsInitialize ( 33 VOID 34 ) 35 { 36 UINT8 *GhcbBase; 37 PHYSICAL_ADDRESS GhcbBasePa; 38 UINTN GhcbPageCount; 39 UINT8 *GhcbBackupBase; 40 UINT8 *GhcbBackupPages; 41 UINTN GhcbBackupPageCount; 42 SEV_ES_PER_CPU_DATA *SevEsData; 43 UINTN PageCount; 44 RETURN_STATUS PcdStatus, DecryptStatus; 45 IA32_DESCRIPTOR Gdtr; 46 VOID *Gdt; 47 48 if (!MemEncryptSevEsIsEnabled ()) { 49 return; 50 } 51 52 PcdStatus = PcdSetBoolS (PcdSevEsIsEnabled, TRUE); 53 ASSERT_RETURN_ERROR (PcdStatus); 54 55 // 56 // Allocate GHCB and per-CPU variable pages. 57 // Since the pages must survive across the UEFI to OS transition 58 // make them reserved. 59 // 60 GhcbPageCount = mMaxCpuCount * 2; 61 GhcbBase = AllocateReservedPages (GhcbPageCount); 62 ASSERT (GhcbBase != NULL); 63 64 GhcbBasePa = (PHYSICAL_ADDRESS)(UINTN) GhcbBase; 65 66 // 67 // Each vCPU gets two consecutive pages, the first is the GHCB and the 68 // second is the per-CPU variable page. Loop through the allocation and 69 // only clear the encryption mask for the GHCB pages. 70 // 71 for (PageCount = 0; PageCount < GhcbPageCount; PageCount += 2) { 72 DecryptStatus = MemEncryptSevClearPageEncMask ( 73 0, 74 GhcbBasePa + EFI_PAGES_TO_SIZE (PageCount), 75 1, 76 TRUE 77 ); 78 ASSERT_RETURN_ERROR (DecryptStatus); 79 } 80 81 ZeroMem (GhcbBase, EFI_PAGES_TO_SIZE (GhcbPageCount)); 82 83 PcdStatus = PcdSet64S (PcdGhcbBase, GhcbBasePa); 84 ASSERT_RETURN_ERROR (PcdStatus); 85 PcdStatus = PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); 86 ASSERT_RETURN_ERROR (PcdStatus); 87 88 DEBUG ((DEBUG_INFO, 89 "SEV-ES is enabled, %lu GHCB pages allocated starting at 0x%p\n", 90 (UINT64)GhcbPageCount, GhcbBase)); 91 92 // 93 // Allocate #VC recursion backup pages. The number of backup pages needed is 94 // one less than the maximum VC count. 95 // 96 GhcbBackupPageCount = mMaxCpuCount * (VMGEXIT_MAXIMUM_VC_COUNT - 1); 97 GhcbBackupBase = AllocatePages (GhcbBackupPageCount); 98 ASSERT (GhcbBackupBase != NULL); 99 100 GhcbBackupPages = GhcbBackupBase; 101 for (PageCount = 1; PageCount < GhcbPageCount; PageCount += 2) { 102 SevEsData = 103 (SEV_ES_PER_CPU_DATA *)(GhcbBase + EFI_PAGES_TO_SIZE (PageCount)); 104 SevEsData->GhcbBackupPages = GhcbBackupPages; 105 106 GhcbBackupPages += EFI_PAGE_SIZE * (VMGEXIT_MAXIMUM_VC_COUNT - 1); 107 } 108 109 DEBUG ((DEBUG_INFO, 110 "SEV-ES is enabled, %lu GHCB backup pages allocated starting at 0x%p\n", 111 (UINT64)GhcbBackupPageCount, GhcbBackupBase)); 112 113 AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); 114 115 // 116 // The SEV support will clear the C-bit from non-RAM areas. The early GDT 117 // lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT 118 // will be read as un-encrypted even though it was created before the C-bit 119 // was cleared (encrypted). This will result in a failure to be able to 120 // handle the exception. 121 // 122 AsmReadGdtr (&Gdtr); 123 124 Gdt = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1)); 125 ASSERT (Gdt != NULL); 126 127 CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1); 128 Gdtr.Base = (UINTN) Gdt; 129 AsmWriteGdtr (&Gdtr); 130 } 23 131 24 132 /** … … 33 141 ) 34 142 { 35 CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx;36 143 UINT64 EncryptionMask; 37 144 RETURN_STATUS PcdStatus; … … 45 152 46 153 // 47 // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position)48 //49 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL);50 EncryptionMask = LShiftU64 (1, Ebx.Bits.PtePosBits);51 52 //53 154 // Set Memory Encryption Mask PCD 54 155 // 156 EncryptionMask = MemEncryptSevGetEncryptionMask (); 55 157 PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask); 56 158 ASSERT_RETURN_ERROR (PcdStatus); … … 104 206 } 105 207 } 208 209 // 210 // Check and perform SEV-ES initialization if required. 211 // 212 AmdSevEsInitialize (); 106 213 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/MemDetect.c
r85718 r89983 28 28 #include <Library/HobLib.h> 29 29 #include <Library/IoLib.h> 30 #include <Library/MemEncryptSevLib.h> 30 31 #include <Library/PcdLib.h> 31 32 #include <Library/PciLib.h> … … 939 940 EfiACPIMemoryNVS 940 941 ); 942 943 if (MemEncryptSevEsIsEnabled ()) { 944 // 945 // If SEV-ES is enabled, reserve the GHCB-related memory area. This 946 // includes the extra page table used to break down the 2MB page 947 // mapping into 4KB page entries where the GHCB resides and the 948 // GHCB area itself. 949 // 950 // Since this memory range will be used by the Reset Vector on S3 951 // resume, it must be reserved as ACPI NVS. 952 // 953 BuildMemoryAllocationHob ( 954 (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBase), 955 (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), 956 EfiACPIMemoryNVS 957 ); 958 BuildMemoryAllocationHob ( 959 (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), 960 (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), 961 EfiACPIMemoryNVS 962 ); 963 BuildMemoryAllocationHob ( 964 (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupBase), 965 (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupSize), 966 EfiACPIMemoryNVS 967 ); 968 } 941 969 #endif 942 970 } … … 996 1024 } 997 1025 } 998 } 999 } 1026 1027 #ifdef MDE_CPU_X64 1028 if (MemEncryptSevEsIsEnabled ()) { 1029 // 1030 // If SEV-ES is enabled, reserve the SEV-ES work area. 1031 // 1032 // Since this memory range will be used by the Reset Vector on S3 1033 // resume, it must be reserved as ACPI NVS. 1034 // 1035 // If S3 is unsupported, then various drivers might still write to the 1036 // work area. We ought to prevent DXE from serving allocation requests 1037 // such that they would overlap the work area. 1038 // 1039 BuildMemoryAllocationHob ( 1040 (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase), 1041 (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), 1042 mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData 1043 ); 1044 } 1045 #endif 1046 } 1047 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/PlatformPei.inf
r85718 r89983 77 77 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase 78 78 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize 79 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase 80 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize 81 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase 82 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize 79 83 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase 80 84 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize … … 101 105 gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable 102 106 gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask 107 gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase 108 gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize 103 109 gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy 104 110 gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress … … 106 112 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber 107 113 gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize 114 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled 108 115 109 116 #[FixedPcd] … … 114 121 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode 115 122 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData 123 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase 124 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize 125 gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase 126 gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize 116 127 117 128 [FeaturePcd]
Note:
See TracChangeset
for help on using the changeset viewer.