From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1DC7F7803D9 for ; Mon, 27 Nov 2023 18:18:44 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eUU547jsCa1aHpiax8zdtFSY7t+PfVnVx5NLzRWlb1M=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701109123; v=1; b=S9JiPDD5x70LDTujnyQAuP095msncQ4JV4ViVIpAP+3yrIFNBLSidlJTFSsBqoDughAKlEfN 3DZebsX9aA0c4I/3+KktOiiZ6g/r/8io1imCkXU4WGcoRX8I1tGnSmAUDvuC6UFw1rIwYgbdbCd rCWIC2ETEpSXBXu6HAHSsv3U= X-Received: by 127.0.0.2 with SMTP id Hpa1YY7687511xKj5cGjwFWa; Mon, 27 Nov 2023 10:18:43 -0800 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web11.102327.1701109119564078720 for ; Mon, 27 Nov 2023 10:18:39 -0800 X-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1ce28faa92dso34187525ad.2 for ; Mon, 27 Nov 2023 10:18:39 -0800 (PST) X-Gm-Message-State: EMYlyTWJSIAO8tSPxVIYPJoix7686176AA= X-Google-Smtp-Source: AGHT+IGp417gXcusB+HVBGvrK6PF0R/IMGLeYTi61vLPAYsiOArrPKoYi0PSg8aR5K2Is3cTd/GD9A== X-Received: by 2002:a17:902:bd46:b0:1cc:1efb:1bab with SMTP id b6-20020a170902bd4600b001cc1efb1babmr12874444plx.38.1701109118918; Mon, 27 Nov 2023 10:18:38 -0800 (PST) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id c6-20020a170902c1c600b001cfd0ed1604sm2013259plc.87.2023.11.27.10.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:18:38 -0800 (PST) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH v5 13/16] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Date: Mon, 27 Nov 2023 10:18:11 -0800 Message-ID: <20231127181818.411-14-taylor.d.beebe@gmail.com> In-Reply-To: <20231127181818.411-1-taylor.d.beebe@gmail.com> References: <20231127181818.411-1-taylor.d.beebe@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=S9JiPDD5; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io PiSmmCore fetches the EFI memory map and calls SplitTable() to split each loaded image section into its own descriptor with EFI_MEMORY_XP marking data sections and EFI_MEMORY_RO marking code sections. The SMM MAT logic is almost identical to the DXE MAT logic but goes a step further and also updates the memory map descriptors which describe image code and data sections to be of type EfiRuntimeServicesCode and EfiRuntimeServicesData respectively. The consolidated MAT logic (present in the new ImagePropertiesRecordLib) more closely follows the DXE MAT logic which identifies image code sections by the presence of the attribute EFI_MEMORY_RO in the descriptor and image data sections by the presence of the attribute EFI_MEMORY_XP. Because of the flow choice of the consolidated MAT logic, the SMM MAT logic should just use the attributes from the table returned by SplitTable(). Additionally, the function EnforceMemoryMapAttribute() in the SMM MAT logic will ensure that the CODE and DATA memory types have the desired attributes so bisecting this patch series at this commit will still function as before. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Laszlo Ersek Signed-off-by: Taylor Beebe Reviewed-by: Laszlo Ersek --- 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 3d445df213ab..15f998e501a2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1047,14 +1047,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.42.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111750): https://edk2.groups.io/g/devel/message/111750 Mute This Topic: https://groups.io/mt/102834921/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-