From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web10.9831.1592990882491870997 for ; Wed, 24 Jun 2020 02:28:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q9pUZkyI; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592990881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jntjai0GZrnzdmstFnYbrNC3xvSSg+VBp2v/Q3xyNr0=; b=Q9pUZkyISpQ1QiSZzgw1w6V59qctNDN3PShxP3oI6nF5vQFz8Z8li9vys8FLpaW1bT84iU 5Ir0aSIVfS2NJG5VhIv06s7d+v8Z2P+bP6nBl+0o7J2a49Nu7O9zyBPSvLHpwGBXmGmwV3 wNCvnpG0qcfCRi830ObrZviHKkBuPsw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-69-hqj7kRX_O_CDgO7h5qmQJA-1; Wed, 24 Jun 2020 05:27:57 -0400 X-MC-Unique: hqj7kRX_O_CDgO7h5qmQJA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D09AB805EE1; Wed, 24 Jun 2020 09:27:55 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 070EB100238C; Wed, 24 Jun 2020 09:27:53 +0000 (UTC) Subject: Re: [PATCH V2 2/3] MdeModulePkg: Add New Memory Attributes To: Oleksiy Yakovlev , devel@edk2.groups.io Cc: liming.gao@intel.com, michael.d.kinney@intel.com, dandan.bi@intel.com, ray.ni@intel.com, rahul1.kumar@intel.com, Felixp@ami.com References: <20200623215556.80804-1-oleksiyy@ami.com> <20200623215556.80804-3-oleksiyy@ami.com> From: "Laszlo Ersek" Message-ID: <7e581511-5039-34ec-ab6f-74b285da1a51@redhat.com> Date: Wed, 24 Jun 2020 11:27:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200623215556.80804-3-oleksiyy@ami.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 06/23/20 23:55, Oleksiy Yakovlev wrote: > 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); > ); > } > // > Reviewed-by: Laszlo Ersek