Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tdvf One Binary #8

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9ef8bc0
ArmVirtPkg: disable list length checks in NOOPT and DEBUG builds
lersek Jan 13, 2021
3e58db8
OvmfPkg: Update OvmfPkgX64 image layout to add Mailbox for TDX guest
mxu9 Mar 18, 2021
07d5465
MdePkg: Implement library support to probe Td or Non-Td guest
mxu9 Mar 18, 2021
10e3845
OvmfPkg: Implement TdxProbLib instance in OvmfPkg
mxu9 Mar 18, 2021
62dc827
MdePkg: Add Tdx support library
mxu9 Mar 18, 2021
f7c572d
MdePkg: Add BaseIoLibIntrinsicTdx to support Td guest
mxu9 Mar 18, 2021
7b0424d
OvmfPkg: Update IoLib in OvmfPkgX64.dsc to support both Td and Non-Td
mxu9 Mar 18, 2021
0e8e351
OvmfPkg: Update PCD for TDX and the layout in OvmfPkgX64.fdf
mxu9 Mar 18, 2021
16c0bce
OvmfPkg/MdePkg: Update ResetVector for Tdx
mxu9 Mar 18, 2021
dd59e93
OvmfPkg: Update SecEntry.nasm to support Tdx
mxu9 Mar 18, 2021
ca855b2
UefiCpuPkg: Add NULL instance of VmTdExitLib
mxu9 Mar 18, 2021
a00c241
OvmfPkg: Add VmTdExitLib in OvmfPkg
mxu9 Mar 18, 2021
24e5a51
UefiCpuPkg: Update CpuExceptionHandlerLib to support Tdx
mxu9 Mar 18, 2021
bc8b5ee
UefiCpuPkg: Update BaseXApicX2ApicLib to support Tdx
mxu9 Mar 18, 2021
0d8ca6e
MdePkg: Add SecHobLib
mxu9 Mar 18, 2021
ada5e63
MdePkg: Add SecMemoryAllocationLib
mxu9 Mar 18, 2021
d4ecf58
OvmfPkg: Add TdvfPlatformLib
mxu9 Mar 18, 2021
942d5ab
OvmfPkg: Add PrePiLibTdx
mxu9 Mar 18, 2021
64dd543
OvmfPkg: Add TdxStartupLib
mxu9 Mar 18, 2021
6047863
OvmfPkg: Update SecMain.c to startup Td guest
mxu9 Mar 18, 2021
6dfd41a
OvmfPkg: Enable DEBUG_ON_SERIAL_PORT to logout debug info
mxu9 Mar 18, 2021
f738993
MdeModulePkg: Update Core/Dxe to support Tdx
mxu9 Mar 18, 2021
817e28f
MdeModulePkg: Update PciBusDxe for Tdx
mxu9 Mar 18, 2021
c789c22
MdeModulePkg: Tdx doesn't support Smbios
mxu9 Mar 18, 2021
d985e2e
UefiCpuPkg: Update MpInitLib to support Tdx
mxu9 Mar 18, 2021
b16fea8
OvmfPkg: Add TdxDxe driver
mxu9 Mar 18, 2021
102fae1
OvmfPkg: Add MemEncryptTdxLib
mxu9 Mar 18, 2021
1d4ae55
OvmfPkg: Update IoMmuDxe to support both TDX and SEV
mxu9 Mar 18, 2021
75abea5
OvmfPkg: Update QemuFwCfgDxeLib to support Tdx
mxu9 Mar 18, 2021
7a8ba5d
OvmfPkg: Update QemuFwCfgS3Lib for Tdx
mxu9 Mar 18, 2021
485dcf0
OvmfPkg: Update AcpiPlatformDxe to support Tdx
mxu9 Mar 18, 2021
5fd7a41
OvmfPkg: Update LocalApicTimerDxe
mxu9 Mar 18, 2021
ceee9b1
OvmfPkg: Update IncompatiblePciDeviceSupportDxe to support Tdx
mxu9 Mar 18, 2021
5830b42
OvmfPkg: Disable 8254/8259 timer in Td guest
mxu9 Mar 18, 2021
18886fb
MdePkg: Add TDX Protocol Guid and ACPI table definition
mxu9 Mar 31, 2021
4b2cc22
SecurityPkg/Tcg: Tcg2Dxe return EFI_UNSUPPORTED in Td guest
mxu9 Mar 31, 2021
a2ae7d0
OvmfPkg: Add HashLibBaseCryptoRouterTdx for Tdx
mxu9 Mar 31, 2021
91581db
OvmfPkg/Tcg: Add TdTcg2Dxe for Tdx guest
mxu9 Mar 31, 2021
3ac8321
SecurityPkg: Update DxeTpmMeasurementLib to support Tdx guest
mxu9 Mar 31, 2021
cdcf0bb
SecurityPkg: Update DxeTpm2MeasureBootLib to support Tdx
mxu9 Mar 31, 2021
b01f23c
OvmfPkg: Update EmuVariableFvbRuntimeDxe to support Tdx
mxu9 Mar 31, 2021
41b1e24
OvmfPkg: Enable secure boot and measure boot in OvmfPkgX64.dsc
mxu9 Mar 31, 2021
b460a07
MdePkg: Delete TdxLibNull
mxu9 Apr 2, 2021
062cb4a
OvmfPkg: Delete PcdTdxSharedPageMask
mxu9 Apr 6, 2021
4dc23f8
OvmfPkg: Fix the exception in GCC5/VS2019 Release build on Td guest
mxu9 Apr 12, 2021
a8648bb
OvmfPkg: Measure firware configuration from Qemu in DXE phase
mxu9 Apr 14, 2021
75d6d78
OvmfPkg: Measure QemuCfg SystemStates in SEC
mxu9 Apr 15, 2021
ba06323
OvmfPkg: Fix the failure of GCC Debug build
mxu9 Apr 19, 2021
82f3768
CryptoPkg: Add SecCryptLib
mxu9 Apr 20, 2021
c517f32
OvmfPkg: Do hash in SEC phase and record the eventlog in DXE
mxu9 Apr 20, 2021
2f5ffb4
OvmfPkg: Add PcdTdxAcceptPageSize
mxu9 Apr 20, 2021
d603c5d
OvmfPkg: MADT force edge trigger mode
mxu9 Apr 21, 2021
b782518
OvmfPkg: Support 2M page accept size
mxu9 Apr 22, 2021
96ddbad
OvmfPkg: Delete the PCD for Td temp Stack/Heap
mxu9 Apr 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ArmVirtPkg/ArmVirt.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
[PcdsFixedAtBuild.common]
gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0
gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

Expand Down
68 changes: 68 additions & 0 deletions CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## @file
# Cryptographic Library Instance for SEC.
#
# Caution: This module requires additional review when modified.
# This library will have external input - signature.
# This external input must be validated carefully to avoid security issues such as
# buffer overflow or integer overflow.
#
# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = SecCryptLib
MODULE_UNI_FILE = SecCryptLib.uni
FILE_GUID = 3689D343-0D32-4284-8053-BF10537990E8
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = BaseCryptLib|SEC

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = X64
#

[Sources]
InternalCryptLib.h
Hash/CryptSha512.c

SysCall/CrtWrapper.c
SysCall/ConstantTimeClock.c
SysCall/BaseMemAllocation.c

[Packages]
MdePkg/MdePkg.dec
CryptoPkg/CryptoPkg.dec

[LibraryClasses]
BaseLib
BaseMemoryLib
MemoryAllocationLib
DebugLib
OpensslLib
IntrinsicLib

#
# Remove these [BuildOptions] after this library is cleaned up
#
[BuildOptions]
#
# suppress the following warnings so we do not break the build with warnings-as-errors:
# C4090: 'function' : different 'const' qualifiers
# C4718: 'function call' : recursive call has no side effects, deleting
#
MSFT:*_*_*_CC_FLAGS = /wd4090 /wd4718

# -JCryptoPkg/Include : To disable the use of the system includes provided by RVCT
# --diag_remark=1 : Reduce severity of "#1-D: last line of file ends without a newline"
RVCT:*_*_ARM_CC_FLAGS = -JCryptoPkg/Include --diag_remark=1

GCC:*_CLANG35_*_CC_FLAGS = -std=c99
GCC:*_CLANG38_*_CC_FLAGS = -std=c99
GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types

XCODE:*_*_*_CC_FLAGS = -std=c99
25 changes: 25 additions & 0 deletions CryptoPkg/Library/BaseCryptLib/SecCryptLib.uni
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// /** @file
// Cryptographic Library Instance for PEIM.
//
// Caution: This module requires additional review when modified.
// This library will have external input - signature.
// This external input must be validated carefully to avoid security issues such as
// buffer overflow or integer overflow.
//
// Note: AES
// functions, RSA external functions, PKCS#7 SignedData sign functions,
// Diffie-Hellman functions, X.509 certificate handler functions, authenticode
// signature verification functions, PEM handler functions, and pseudorandom number
// generator functions are not supported in this instance.
//
// Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/


#string STR_MODULE_ABSTRACT #language en-US "Cryptographic Library Instance for PEIM"

#string STR_MODULE_DESCRIPTION #language en-US "Caution: This module requires additional review when modified. This library will have external input - signature. This external input must be validated carefully to avoid security issues such as buffer overflow or integer overflow. Note: AES functions, RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, X.509 certificate handler functions, authenticode signature verification functions, PEM handler functions, and pseudorandom number generator functions are not supported in this instance."

1 change: 1 addition & 0 deletions MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
BaseLib
UefiDriverEntryPoint
DebugLib
TdxProbeLib

[Protocols]
gEfiPciHotPlugRequestProtocolGuid ## SOMETIMES_PRODUCES
Expand Down
5 changes: 5 additions & 0 deletions MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include "PciBus.h"

#include <Library/TdxProbeLib.h>

/**
This routine is used to enumerate entire pci bus system
in a given platform.
Expand Down Expand Up @@ -533,6 +535,9 @@ GetMaxOptionRomSize (
UINT32 TempOptionRomSize;

MaxOptionRomSize = 0;
if(ProbeTdGuest()) {
return 0;
}

//
// Go through bridges to reach all devices
Expand Down
2 changes: 2 additions & 0 deletions MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate;

extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable;
extern BOOLEAN gLoadFixedAddressCodeMemoryReady;

extern BOOLEAN gTdGuest;
//
// Service Initialization Functions
//
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Core/Dxe/DxeMain.inf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
DebugAgentLib
CpuExceptionHandlerLib
PcdLib
TdxProbeLib

[Guids]
gEfiEventMemoryMapChangeGuid ## PRODUCES ## Event
Expand Down
8 changes: 8 additions & 0 deletions MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "DxeMain.h"
#include <Library/TdxProbeLib.h>

BOOLEAN gTdGuest = FALSE;

//
// DXE Core Global Variables for Protocols from PEI
Expand Down Expand Up @@ -244,6 +247,11 @@ DxeMain (
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
VOID *EntryPoint;

//
// Check whether it is of Td guest
//
gTdGuest = ProbeTdGuest();

//
// Setup the default exception handlers
//
Expand Down
14 changes: 12 additions & 2 deletions MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Implements functions to read firmware file

Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
Expand Down Expand Up @@ -128,6 +128,7 @@ FvGetNextFile (
UINTN *KeyValue;
LIST_ENTRY *Link;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
UINTN MaxFileType;

FvDevice = FV_DEVICE_FROM_THIS (This);

Expand All @@ -143,7 +144,16 @@ FvGetNextFile (
return EFI_ACCESS_DENIED;
}

if (*FileType > EFI_FV_FILETYPE_MM_CORE_STANDALONE) {
//
// Td guest doesn't support SMM
//
if(gTdGuest) {
MaxFileType = EFI_FV_FILETYPE_SMM_CORE;
} else {
MaxFileType = EFI_FV_FILETYPE_MM_CORE_STANDALONE;
}

if (*FileType > MaxFileType) {
//
// File type needs to be in 0 - 0x0F
//
Expand Down
36 changes: 31 additions & 5 deletions MdeModulePkg/Core/Dxe/Gcd/Gcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)

// TDX
#define EXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_UC | EFI_MEMORY_WC | \
EFI_MEMORY_WT | EFI_MEMORY_WB | \
EFI_MEMORY_WP | EFI_MEMORY_UCE)

#define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \
EFI_MEMORY_RO)

//
// Module Variables
//
Expand Down Expand Up @@ -74,6 +82,9 @@ EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
NULL,
NULL
};
// TD
#define EFI_RESOURCE_ATTRIBUTE_ENCRYPTED 0x04000000


GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
{ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, EFI_MEMORY_UC, TRUE },
Expand All @@ -90,6 +101,7 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
{ EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_MEMORY_TESTED, FALSE },
{ EFI_RESOURCE_ATTRIBUTE_PERSISTABLE, EFI_MEMORY_NV, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE, EFI_MEMORY_MORE_RELIABLE, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_ENCRYPTED, EFI_MEMORY_CPU_CRYPTO, TRUE }, // TDX
{ 0, 0, FALSE }
};

Expand Down Expand Up @@ -658,7 +670,11 @@ ConverToCpuArchAttributes (
{
UINT64 CpuArchAttributes;

CpuArchAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;
if(gTdGuest) {
CpuArchAttributes = Attributes & NONEXCLUSIVE_MEMORY_ATTRIBUTES;
} else {
CpuArchAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;
}

if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {
CpuArchAttributes |= EFI_MEMORY_UC;
Expand Down Expand Up @@ -944,7 +960,11 @@ CoreConvertSpace (
// Keep original CPU arch attributes when caller just calls
// SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
//
Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
if(gTdGuest) {
Attributes |= (Entry->Attributes & (EXCLUSIVE_MEMORY_ATTRIBUTES | NONEXCLUSIVE_MEMORY_ATTRIBUTES));
} else {
Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
}
}
Entry->Attributes = Attributes;
break;
Expand Down Expand Up @@ -2289,7 +2309,9 @@ CoreInitializeMemoryServices (
Attributes = PhitResourceHob->ResourceAttribute;
BaseAddress = PageAlignAddress (PhitHob->EfiMemoryTop);
Length = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if(!gTdGuest) {
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
}
if (Length < MinimalMemorySizeNeeded) {
//
// If that range is not large enough to intialize the DXE Core, then
Expand All @@ -2305,7 +2327,9 @@ CoreInitializeMemoryServices (
//
BaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
Length = PageAlignLength ((UINT64)((UINTN)*HobStart - BaseAddress));
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if(!gTdGuest) {
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
}
}
}
break;
Expand Down Expand Up @@ -2369,7 +2393,9 @@ CoreInitializeMemoryServices (
//
TestedMemoryBaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
FindLargestFreeRegion (&TestedMemoryBaseAddress, &TestedMemoryLength, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if(!gTdGuest) {
FindLargestFreeRegion (&TestedMemoryBaseAddress, &TestedMemoryLength, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
}
if (TestedMemoryLength < MinimalMemorySizeNeeded) {
continue;
}
Expand Down
23 changes: 20 additions & 3 deletions MdeModulePkg/Core/Dxe/Mem/Page.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,14 @@ CoreGetMemoryMap (
MemoryMap->PhysicalStart = MergeGcdMapEntry.BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
if(gTdGuest) {
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
(MergeGcdMapEntry.Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));
} else {
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
(MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
}

if (MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
Expand Down Expand Up @@ -1890,8 +1896,14 @@ CoreGetMemoryMap (
MemoryMap->PhysicalStart = MergeGcdMapEntry.BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
if(gTdGuest) {
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
(MergeGcdMapEntry.Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));
} else {
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
(MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
}
MemoryMap->Type = EfiPersistentMemory;

//
Expand Down Expand Up @@ -1933,7 +1945,12 @@ CoreGetMemoryMap (
MemoryMapEnd = MemoryMap;
MemoryMap = MemoryMapStart;
while (MemoryMap < MemoryMapEnd) {
MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ACCESS_MASK;
if(gTdGuest) {
MemoryMap->Attribute &= ~(UINT64)(EFI_MEMORY_RP | EFI_MEMORY_RO |
EFI_MEMORY_XP);
} else {
MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ACCESS_MASK;
}
MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}
MergeMemoryMap (MemoryMapStart, &BufferSize, Size);
Expand Down
17 changes: 15 additions & 2 deletions MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "Mem/HeapGuard.h"

// TD
#define CACHE_ATTRIBUTE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB | EFI_MEMORY_UCE | EFI_MEMORY_WP)
#define MEMORY_ATTRIBUTE_MASK (EFI_MEMORY_RP | EFI_MEMORY_XP | EFI_MEMORY_RO)

//
// Image type definitions
//
Expand Down Expand Up @@ -218,7 +222,11 @@ SetUefiImageMemoryAttributes (
Status = CoreGetMemorySpaceDescriptor(BaseAddress, &Descriptor);
ASSERT_EFI_ERROR(Status);

FinalAttributes = (Descriptor.Attributes & EFI_CACHE_ATTRIBUTE_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
if(gTdGuest) {
FinalAttributes = (Descriptor.Attributes & CACHE_ATTRIBUTE_MASK) | (Attributes & MEMORY_ATTRIBUTE_MASK);
} else {
FinalAttributes = (Descriptor.Attributes & EFI_CACHE_ATTRIBUTE_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
}

DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", BaseAddress, Length, FinalAttributes));

Expand Down Expand Up @@ -920,8 +928,13 @@ InitializeDxeNxMemoryProtectionPolicy (
(Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {

Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) |
if(gTdGuest) {
Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) |
(Entry->Attributes & CACHE_ATTRIBUTE_MASK);
} else {
Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) |
(Entry->Attributes & EFI_CACHE_ATTRIBUTE_MASK);
}

DEBUG ((DEBUG_INFO,
"Untested GCD memory space region: - 0x%016lx - 0x%016lx (0x%016lx)\n",
Expand Down
Loading