From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atlmailgw2.ami.com (atlmailgw2.ami.com []) by mx.groups.io with SMTP id smtpd.web10.563.1592949414388132273 for ; Tue, 23 Jun 2020 14:56:55 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: ami.com, ip: , mailfrom: oleksiyy@ami.com) X-AuditID: ac10606f-4dbff70000003ed3-ff-5ef27aa414ea Received: from atlms1.us.megatrends.com (atlms1.us.megatrends.com [172.16.96.144]) (using TLS with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client did not present a certificate) by atlmailgw2.ami.com (Symantec Messaging Gateway) with SMTP id 09.45.16083.4AA72FE5; Tue, 23 Jun 2020 17:56:52 -0400 (EDT) Received: from Oleksiy77.us.megatrends.com (172.16.97.158) by atlms1.us.megatrends.com (172.16.96.144) with Microsoft SMTP Server id 14.3.468.0; Tue, 23 Jun 2020 17:56:00 -0400 From: "Oleksiy Yakovlev" To: CC: , , , , , , , Subject: [PATCH V2 2/3] MdeModulePkg: Add New Memory Attributes Date: Tue, 23 Jun 2020 17:55:55 -0400 Message-ID: <20200623215556.80804-3-oleksiyy@ami.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20200623215556.80804-1-oleksiyy@ami.com> References: <20200623215556.80804-1-oleksiyy@ami.com> MIME-Version: 1.0 Return-Path: oleksiyy@ami.com X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsWyRiBhgu6Sqk9xBqtW6Vps3aZu0T5hNpvF smM7WCxW3NvAbtHR8Y/JYvp2F4svq98zOrB7bP9+gdFj8Z6XTB7v911lC2COamC0SczLyy9J LElVSEktTrZVCijKLEtMrlRSyEyxVTJUUijISUxOzU3NK7FVSiwoSM1LUbLjUsAANkBlmXkK qXnJ+SmZeem2Sp7B/roWFqaWuoZKdiEZqQqZeWn5RbmJJZn5eQrJ+XklQNWpKUBRhYRuzozN n6cxFZyyrDg64T1TA+MenS5GTg4JAROJBUvvsnUxcnEICexikmi5P40dwtnCKNG+cycrSBWb gKbEgWNTGEFsEQEpiSkHZjKBFDEL7GGU6Hl9CqxIWMBe4ubeV2wgNouAqkTb9Y1MIDavgKnE 2mebmCDWaUhMW3MXyObg4BQwk3j+MgAkLARU0r76HlS5oMTJmU9YQGxmAQmJgy9eMEPUyEq0 HX/OPoGRfxaSsllIyhYwMq1iFEosyclNzMxJLzfSS8zN1EvOz93ECInF/B2MHz+aH2Jk4mA8 xCjBwawkwhvi9ilOiDclsbIqtSg/vqg0J7X4EKMT0P0TmaW4QSEIjJJ4YwMDKVEYx9DEzMTc yNzQ0sTc2FhJnHfS2jVxQgLpwKjNTk0tSC2CGcLEwSnVwLj6ZiyH3zmh+YzCGjsn7X7DWXp+ ZZOyUnKLrgDT2x+7S28dSOOODXz3pLIsriafe8s++f11SuWnWh+YLmr9+XvNdxNzG+nEDcm7 TrhbmlTW76rO/RcZylgtXXH1zc3nk54xtDhOtP2qsN85/wVfpAHrr1iXxXXGliXH0q90lflE i/D3Z0xaqcRSnJFoqMVcVJwIABCfZD3aAgAA Content-Type: text/plain Add usage of EFI_MEMORY_SP and EFI_MEMORY_CPU_CRYPTO attributes introduced in UEFI 2.8. (UEFI 2.8, mantis 1919 and 1872). Use attributes bitmasks, defined in MdePkg. Signed-off-by: Oleksiy Yakovlev --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 11 ++--------- MdeModulePkg/Core/Dxe/Mem/Page.c | 9 +++------ MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 7 ++----- MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 10 ++-------- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 74f3b1b..2d8c076 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -35,13 +35,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT) -#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 // @@ -665,7 +658,7 @@ ConverToCpuArchAttributes ( { UINT64 CpuArchAttributes; - CpuArchAttributes = Attributes & NONEXCLUSIVE_MEMORY_ATTRIBUTES; + CpuArchAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK; if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) { CpuArchAttributes |= EFI_MEMORY_UC; @@ -951,7 +944,7 @@ CoreConvertSpace ( // Keep original CPU arch attributes when caller just calls // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME). // - Attributes |= (Entry->Attributes & (EXCLUSIVE_MEMORY_ATTRIBUTES | NONEXCLUSIVE_MEMORY_ATTRIBUTES)); + Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK)); } Entry->Attributes = Attributes; break; diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 1f0e3d9..2c2c9cd 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1857,8 +1857,7 @@ CoreGetMemoryMap ( MemoryMap->VirtualStart = 0; MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT); 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)); + (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK)); if (MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) { MemoryMap->Type = EfiReservedMemoryType; @@ -1892,8 +1891,7 @@ CoreGetMemoryMap ( MemoryMap->VirtualStart = 0; MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT); 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)); + (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK)); MemoryMap->Type = EfiPersistentMemory; // @@ -1935,8 +1933,7 @@ CoreGetMemoryMap ( MemoryMapEnd = MemoryMap; MemoryMap = MemoryMapStart; while (MemoryMap < MemoryMapEnd) { - MemoryMap->Attribute &= ~(UINT64)(EFI_MEMORY_RP | EFI_MEMORY_RO | - EFI_MEMORY_XP); + MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ATTRIBUTE_MASK; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size); } MergeMemoryMap (MemoryMapStart, &BufferSize, Size); diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 92a442f..7d1daf0 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -42,9 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h" #include "Mem/HeapGuard.h" -#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 // @@ -221,7 +218,7 @@ SetUefiImageMemoryAttributes ( Status = CoreGetMemorySpaceDescriptor(BaseAddress, &Descriptor); ASSERT_EFI_ERROR(Status); - FinalAttributes = (Descriptor.Attributes & CACHE_ATTRIBUTE_MASK) | (Attributes & MEMORY_ATTRIBUTE_MASK); + 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)); @@ -924,7 +921,7 @@ InitializeDxeNxMemoryProtectionPolicy ( (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) { Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) | - (Entry->Attributes & CACHE_ATTRIBUTE_MASK); + (Entry->Attributes & EFI_CACHE_ATTRIBUTE_MASK); DEBUG ((DEBUG_INFO, "Untested GCD memory space region: - 0x%016lx - 0x%016lx (0x%016lx)\n", diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index 0385f1d..599a0cd 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -39,12 +39,6 @@ #define SMRAM_CAPABILITIES (EFI_MEMORY_WB | EFI_MEMORY_UC) -#define MEMORY_CACHE_ATTRIBUTES (EFI_MEMORY_UC | EFI_MEMORY_WC | \ - EFI_MEMORY_WT | EFI_MEMORY_WB | \ - EFI_MEMORY_WP | EFI_MEMORY_UCE) - -#define MEMORY_PAGE_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | EFI_MEMORY_RO) - // // Function prototypes from produced protocols // @@ -1710,7 +1704,7 @@ SmmIplEntry ( CpuArch = NULL; Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch); if (!EFI_ERROR (Status)) { - MemDesc.Attributes &= ~(MEMORY_CACHE_ATTRIBUTES | MEMORY_PAGE_ATTRIBUTES); + MemDesc.Attributes &= ~(EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK); MemDesc.Attributes |= EFI_MEMORY_WB; Status = gDS->SetMemorySpaceAttributes ( mSmramCacheBase, @@ -1727,7 +1721,7 @@ SmmIplEntry ( &MemDesc ); DEBUG ((DEBUG_INFO, "SMRAM attributes: %016lx\n", MemDesc.Attributes)); - ASSERT ((MemDesc.Attributes & MEMORY_PAGE_ATTRIBUTES) == 0); + ASSERT ((MemDesc.Attributes & EFI_MEMORY_ATTRIBUTE_MASK) == 0); ); } // -- 2.9.0.windows.1 Please consider the environment before printing this email. The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.