public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Taylor Beebe" <t@taylorbeebe.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [edk2-devel] [PATCH v1 8/9] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero
Date: Tue, 18 Jul 2023 11:40:04 -0700	[thread overview]
Message-ID: <20230718184006.534-9-t@taylorbeebe.com> (raw)
In-Reply-To: <20230718184006.534-1-t@taylorbeebe.com>

The function EnforceMemoryMapAttribute() in the SMM MAT logic will
ensure that the CODE and DATA memory types have the desired attributes.
The consumer of the SMM MAT should only override the Attributes field
in the MAT if it is nonzero. This also allows the UEFI and SMM MAT
logic to use ImagePropertiesRecordLib instead of carrying two copies
of the image properties record manipulation.

Signed-off-by: Taylor Beebe <t@taylorbeebe.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
index 6f498666157e..d302a9b0cbcf 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
@@ -1062,14 +1062,17 @@ SetMemMapAttributes (
   MemoryMap = MemoryMapStart;
   for (Index = 0; Index < MemoryMapEntryCount; Index++) {
     DEBUG ((DEBUG_VERBOSE, "SetAttribute: Memory Entry - 0x%lx, 0x%x\n", MemoryMap->PhysicalStart, MemoryMap->NumberOfPages));
-    if (MemoryMap->Type == EfiRuntimeServicesCode) {
-      MemoryAttribute = EFI_MEMORY_RO;
-    } else {
-      ASSERT ((MemoryMap->Type == EfiRuntimeServicesData) || (MemoryMap->Type == EfiConventionalMemory));
-      //
-      // Set other type memory as NX.
-      //
-      MemoryAttribute = EFI_MEMORY_XP;
+    MemoryAttribute = MemoryMap->Attribute & EFI_MEMORY_ACCESS_MASK;
+    if (MemoryAttribute == 0) {
+      if (MemoryMap->Type == EfiRuntimeServicesCode) {
+        MemoryAttribute = EFI_MEMORY_RO;
+      } else {
+        ASSERT ((MemoryMap->Type == EfiRuntimeServicesData) || (MemoryMap->Type == EfiConventionalMemory));
+        //
+        // Set other type memory as NX.
+        //
+        MemoryAttribute = EFI_MEMORY_XP;
+      }
     }
 
     //
-- 
2.41.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107029): https://edk2.groups.io/g/devel/message/107029
Mute This Topic: https://groups.io/mt/100221564/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-07-18 18:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 18:39 [edk2-devel] [PATCH v1 0/9] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-07-18 18:39 ` [edk2-devel] [PATCH v1 1/9] MdeModulePkg: Add ImagePropertiesRecordLib Taylor Beebe
2023-07-18 18:39 ` [edk2-devel] [PATCH v1 2/9] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Taylor Beebe
2023-07-18 18:39 ` [edk2-devel] [PATCH v1 3/9] MdeModulePkg: Fix Bugs in MAT Logic Taylor Beebe
2023-07-18 18:40 ` [edk2-devel] [PATCH v1 4/9] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe
2023-07-18 18:40 ` [edk2-devel] [PATCH v1 5/9] EmulatorPkg: " Taylor Beebe
2023-07-18 18:40 ` [edk2-devel] [PATCH v1 6/9] OvmfPkg: " Taylor Beebe
2023-07-18 18:40 ` [edk2-devel] [PATCH v1 7/9] UefiPayloadPkg: " Taylor Beebe
2023-07-18 22:16   ` Guo, Gua
2023-07-18 18:40 ` Taylor Beebe [this message]
2023-07-18 18:40 ` [edk2-devel] [PATCH v1 9/9] MdeModulePkg: Update UEFI and SMM MAT Logic To Use ImagePropertiesRecordLib Taylor Beebe
2023-07-18 20:17 ` [edk2-devel] [PATCH v1 0/9] Add ImagePropertiesRecordLib and Fix MAT Bugs Ard Biesheuvel
2023-07-19  5:23   ` 回复: " gaoliming via groups.io
2023-07-19 23:33     ` Taylor Beebe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230718184006.534-9-t@taylorbeebe.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox