From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105650+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105650+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719086; cv=none; d=zohomail.com; s=zohoarc; b=BmtljnFqxZju4NVkBUrqDf8Hvx04rIeCD5yP8ZdfRc3YbrymMO/vZcxsennG5oO5IuEIkoIA/EIvodBNHQbfdntYfC77LAQDRJxfsr9Rt49XF1WvmSqWaSbjsOR08URhFmhnE/UvhHG6cvVIcezqSjZf7jwpenilGJQCI0Yunmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719086; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gfJPNAZx0ZWbqcLRrP0YeyasX1GdizBQOo5xKMJBV5A=; b=X8aXzphXMhqMthc8pl5pE5Q+xdQHn9zRbePa8Sd7hRGixfW8/XRE6vEUx4i6v0v8Y5qO28G5aEXyVKdfyT66If7rGVBKDvJV1cNqDNXpyIo73VGivYIwR+l1HHj5vx2K7/b8b92+eBMUbsrA2w+8r4Su0C9WzUbgnqNI8KlSTGM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105650+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719086313412.6674084807613; Fri, 2 Jun 2023 08:18:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id L1RTYY1788612xdZvLFzfQ5B; Fri, 02 Jun 2023 08:18:06 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.1817.1685719085029695977 for ; Fri, 02 Jun 2023 08:18:05 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 60BE460AB7; Fri, 2 Jun 2023 15:18:04 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BA45C433EF; Fri, 2 Jun 2023 15:18:01 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 1/7] MdeModulePkg: Define memory attribute PPI Date: Fri, 2 Jun 2023 17:17:33 +0200 Message-Id: <20230602151739.3600820-2-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: 1qhN4PrXPtu1MDJKbRfpyi8hx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719086; bh=C+KxgBpwriLaWo9OAmXLuriUbEwTCoQVU6SPBIi3ESA=; h=Cc:Date:From:Reply-To:Subject:To; b=R0IJMyM+k/v4EZCpV67T/EcwvdLrEskCkDSCW5hCHEaLs4tNXVkY7l6Pxf1/Abh2bl9 qA05VpifCmIQwTlU9WCkskZa6lalPjdpFbHvkUaTvbhHOeceF/HgZv+jMQvefiU00cWad XWxMeUHqC59e23fJ70auo998MMEZ8Lc3XTA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719086591100005 Content-Type: text/plain; charset="utf-8" Define a PPI interface that may be used by the PEI core or other PEIMs to manage permissions on memory ranges. This is primarily intended for restricting permissions to what is actually needed for correct execution by the code in question, and for limiting the use of memory mappings that are both writable and executable at the same time. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- MdeModulePkg/Include/Ppi/MemoryAttribute.h | 83 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 + 2 files changed, 86 insertions(+) diff --git a/MdeModulePkg/Include/Ppi/MemoryAttribute.h b/MdeModulePkg/Incl= ude/Ppi/MemoryAttribute.h new file mode 100644 index 0000000000000000..83bcc33a76719712 --- /dev/null +++ b/MdeModulePkg/Include/Ppi/MemoryAttribute.h @@ -0,0 +1,83 @@ +/** @file + +Copyright (c) 2023, Google LLC. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_MEMORY_ATTRIBUTE_PPI_H_ +#define EDKII_MEMORY_ATTRIBUTE_PPI_H_ + +#include + +/// +/// Global ID for the EDKII_MEMORY_ATTRIBUTE_PPI. +/// +#define EDKII_MEMORY_ATTRIBUTE_PPI_GUID \ + { \ + 0x1be840de, 0x2d92, 0x41ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51= , 0xfb } \ + } + +/// +/// Forward declaration for the EDKII_MEMORY_ATTRIBUTE_PPI. +/// +typedef struct _EDKII_MEMORY_ATTRIBUTE_PPI EDKII_MEMORY_ATTRIBUTE_PPI; + +/** + Set the requested memory permission attributes on a region of memory. + + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. + + Attributes must contain a combination of EFI_MEMORY_RP, EFI_MEMORY_RO and + EFI_MEMORY_XP, and specifies the attributes that must be set for the + region in question. Attributes that are omitted will be cleared from the + region only if they are set in AttributeMask. + + AttributeMask must contain a combination of EFI_MEMORY_RP, EFI_MEMORY_RO= and + EFI_MEMORY_XP, and specifies the attributes that the call will operate o= n. + AttributeMask must not be 0x0, and must contain at least the bits set in + Attributes. + + @param[in] This The protocol instance pointer. + @param[in] BaseAddress The physical address that is the start add= ress + of a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] Attributes Memory attributes to set or clear. + @param[in] AttributeMask Mask of memory attributes to operate on. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER Length is zero. + AttributeMask is zero. + AttributeMask lacks bits set in Attributes. + BaseAddress or Length is not suitably alig= ned. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specifi= ed + by BaseAddress and Length. + The bit mask of attributes is not supporte= d for + the memory resource range specified by + BaseAddress and Length. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS)( + IN EDKII_MEMORY_ATTRIBUTE_PPI *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes, + IN UINT64 AttributeMask + ); + +/// +/// This PPI contains a set of services to manage memory permission attrib= utes. +/// +struct _EDKII_MEMORY_ATTRIBUTE_PPI { + EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS SetPermissions; +}; + +extern EFI_GUID gEdkiiMemoryAttributePpiGuid; + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 95dd077e19b3a901..d65dae18aa81e569 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -528,6 +528,9 @@ [Ppis] gEdkiiPeiCapsuleOnDiskPpiGuid =3D { 0x71a9ea61, 0x5a35, 0x4a= 5d, { 0xac, 0xef, 0x9c, 0xf8, 0x6d, 0x6d, 0x67, 0xe0 } } gEdkiiPeiBootInCapsuleOnDiskModePpiGuid =3D { 0xb08a11e4, 0xe2b7, 0x4b= 75, { 0xb5, 0x15, 0xaf, 0x61, 0x6, 0x68, 0xbf, 0xd1 } } =20 + ## Include/Ppi/MemoryAttribute.h + gEdkiiMemoryAttributePpiGuid =3D { 0x1be840de, 0x2d92, 0x41= ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51, 0xfb } } + [Protocols] ## Load File protocol provides capability to load and unload EFI image i= nto memory and execute it. # Include/Protocol/LoadPe32Image.h --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105650): https://edk2.groups.io/g/devel/message/105650 Mute This Topic: https://groups.io/mt/99288478/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105651+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105651+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719089; cv=none; d=zohomail.com; s=zohoarc; b=cgnBui2MJA3bSOSRbJ+rnJEy2CiYhq/wbXb4LzddwbiPHYziQP7+ewMonKgWXC6YaQXSMs6d189OCVb2sV9FDr4rHFgbqqQFZY4Nzt22hBe6VqKRAEdzLtBKI9rUbJjxoE1V9EVSYqrgjrcDAgO4yOINUNsnN9TJDls3TF7TK3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719089; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AzwKTFPqieKSqAn+Ifco/vft7bTQ/TsTGnGwrBKQkFs=; b=CUDFKkjRVTAkBPld1qRnYM5U+DOswqgctT/P9jSwfJdjDxArgWCKB9DQR5qihdNKQDLhE0F3hjW8dwkx8GwGNxIDzgQUyZl1onuIqZ8rpj863eL4fYXheBOU138/YLsSwDFwOi396MwKuAHLFVPVttMgEvoPRqIDoa7Gq+Z9Ovs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105651+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719089750188.2695223606704; Fri, 2 Jun 2023 08:18:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mOwjYY1788612xtHFggkQACl; Fri, 02 Jun 2023 08:18:09 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.16075.1685719088093088205 for ; Fri, 02 Jun 2023 08:18:08 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 83D8961638; Fri, 2 Jun 2023 15:18:07 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4354AC433D2; Fri, 2 Jun 2023 15:18:04 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 2/7] MdeModulePkg/DxeIpl: Merge EBC, RISCV64 and LOONGARCH code Date: Fri, 2 Jun 2023 17:17:34 +0200 Message-Id: <20230602151739.3600820-3-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: QxCPqoKTXbuhbgbU6g4HX8N5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719089; bh=3FJrJVVhxNxc0PzWPDWL146o0knoHHif8+gyfGigIaQ=; h=Cc:Date:From:Reply-To:Subject:To; b=p6v2s/eIotbpeEKpBfDNhNvUu+pAyHP8vvFp/sbsK6GJ6+rG/ZZZYcIAJHgud0A0Jtt 6zFOQcBm4dF2efkTROoS+N7P69d6596K1W5LNf2p0IKNxq7m7bc/azacYv6Jdf+sSSIHZ tMFRDhHxTQTROhdsHBbwF/5hV2E5i8CP7Xo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719090577100001 Content-Type: text/plain; charset="utf-8" The Risc-V and LoongArch specific versions of the DXE core handoff code in DxeIpl are essentially copies of the EBC version (modulo the copyright in the header and some debug prints in the code). In preparation for introducing a generic PPI based method to implement the non-executable stack, let's merge these versions, so we only need to add this logic once. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- MdeModulePkg/Core/DxeIplPeim/{Ebc/DxeLoadFunc.c =3D> DxeHandoff.c} | 2 +- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 10 +-- MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c | 63 ----= ------------ MdeModulePkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c | 75 ----= ---------------- 4 files changed, 3 insertions(+), 147 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/Ebc/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/DxeHandoff.c similarity index 92% rename from MdeModulePkg/Core/DxeIplPeim/Ebc/DxeLoadFunc.c rename to MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c index c1a16b602452218e..a0f85ebea56e6cba 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ebc/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c @@ -1,5 +1,5 @@ /** @file - EBC-specific functionality for DxeLoad. + Generic version of arch-specific functionality for DxeLoad. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 052ea0ec1a6f2771..60c998be6c1bad01 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -45,17 +45,11 @@ [Sources.X64] X64/VirtualMemory.c X64/DxeLoadFunc.c =20 -[Sources.EBC] - Ebc/DxeLoadFunc.c - [Sources.ARM, Sources.AARCH64] Arm/DxeLoadFunc.c =20 -[Sources.RISCV64] - RiscV64/DxeLoadFunc.c - -[Sources.LOONGARCH64] - LoongArch64/DxeLoadFunc.c +[Sources.LOONGARCH64,Sources.RISCV64,Sources.EBC] + DxeHandoff.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c b/MdeMo= dulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c deleted file mode 100644 index 95d3af19ea4c9f00..0000000000000000 --- a/MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - LoongArch specifc functionality for DxeLoad. - - Copyright (c) 2022, Loongson Technology Corporation Limited. All rights = reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "DxeIpl.h" - -/** - Transfers control to DxeCore. - - This function performs a CPU architecture specific operations to execute - the entry point of DxeCore with the parameters of HobList. - It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. - - @param[in] DxeCoreEntryPoint The entry point of DxeCore. - @param[in] HobList The start of HobList passed to Dxe= Core. - -**/ -VOID -HandOffToDxeCore ( - IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList - ) -{ - VOID *BaseOfStack; - VOID *TopOfStack; - EFI_STATUS Status; - - // - // Allocate 128KB for the Stack - // - BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); - ASSERT (BaseOfStack !=3D NULL); - - // - // Compute the top of the stack we were allocated. Pre-allocate a UINTN - // for safety. - // - TopOfStack =3D (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SI= ZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); - TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); - - // - // End of PEI phase signal - // - Status =3D PeiServicesInstallPpi (&gEndOfPeiSignalPpi); - ASSERT_EFI_ERROR (Status); - - // - // Update the contents of BSP stack HOB to reflect the real stack info p= assed to DxeCore. - // - UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE); - - SwitchStack ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, - HobList.Raw, - NULL, - TopOfStack - ); -} diff --git a/MdeModulePkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c b/MdeModule= Pkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c deleted file mode 100644 index b3567d88f73467e7..0000000000000000 --- a/MdeModulePkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c +++ /dev/null @@ -1,75 +0,0 @@ -/** @file - RISC-V specific functionality for DxeLoad. - - Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All right= s reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "DxeIpl.h" - -/** - Transfers control to DxeCore. - - This function performs a CPU architecture specific operations to execute - the entry point of DxeCore with the parameters of HobList. - It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. - - @param DxeCoreEntryPoint The entry point of DxeCore. - @param HobList The start of HobList passed to DxeCore. - -**/ -VOID -HandOffToDxeCore ( - IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList - ) -{ - VOID *BaseOfStack; - VOID *TopOfStack; - EFI_STATUS Status; - - // - // - // Allocate 128KB for the Stack - // - BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); - if (BaseOfStack =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "%a: Can't allocate memory for stack.", __func__)= ); - ASSERT (FALSE); - } - - // - // Compute the top of the stack we were allocated. Pre-allocate a UINTN - // for safety. - // - TopOfStack =3D (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SI= ZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); - TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); - - // - // End of PEI phase signal - // - Status =3D PeiServicesInstallPpi (&gEndOfPeiSignalPpi); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Fail to signal End of PEI event.", __func__)= ); - ASSERT (FALSE); - } - - // - // Update the contents of BSP stack HOB to reflect the real stack info p= assed to DxeCore. - // - UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE); - - DEBUG ((DEBUG_INFO, "DXE Core new stack at %x, stack pointer at %x\n", B= aseOfStack, TopOfStack)); - - // - // Transfer the control to the entry point of DxeCore. - // - SwitchStack ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, - HobList.Raw, - NULL, - TopOfStack - ); -} --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105651): https://edk2.groups.io/g/devel/message/105651 Mute This Topic: https://groups.io/mt/99288479/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105652+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105652+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719092; cv=none; d=zohomail.com; s=zohoarc; b=eqt+a7oA1+DdZGqNqykfhByDqMc3D7oT6FTRHLh4X6cdiOdPTMtKoXb4MyWMOaN6EubhJj/AuzOkgYmMfGFAzleEc+/EqB2DfBQ7MFXdpc4w2Awobjucs0OmIBZXe6X5bkGVcIxJMKUDerJXBI5U7XgwCwCX3y8FADoijYng9ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719092; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MAeHvXTNqNRClUPWAFBu26+P21C7z0sWwrZmo67IF4U=; b=Dn4r5KFs9Bsn+mRZA3KtfayWGzzQrg+SwQp9j+sX9c95sT1joh911LdqYGXh9fRMVxhIlRdY1HKNup2+ElujNVldP+8chJmqPb3Gbm2T8qzPIyqK7IR4tJNNgSslROgkwpAbPxcZsZXT0+JS8fOoKSnhKeksEaXPdxlKcgmRAFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105652+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719092387723.4843664516422; Fri, 2 Jun 2023 08:18:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vGMXYY1788612xoz7IWCEOsZ; Fri, 02 Jun 2023 08:18:11 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.16077.1685719091051603987 for ; Fri, 02 Jun 2023 08:18:11 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 97CCE60C40; Fri, 2 Jun 2023 15:18:10 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 616A0C433A0; Fri, 2 Jun 2023 15:18:07 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 3/7] MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX Date: Fri, 2 Jun 2023 17:17:35 +0200 Message-Id: <20230602151739.3600820-4-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: 23X6F2aJaYqPHuzu15I8SZjFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719091; bh=BR3f0Tr8p+bvWcu0G2DHezkNSFYXkbhIFKE8osOywxQ=; h=Cc:Date:From:Reply-To:Subject:To; b=kexMqn0XTwztDEyyDCmW9ZSHZaPYS4hz/VzUewIlvy9B2/cId03uriC0XFQuMvZd11+ nNRZRo4ivtcJWfh4S+lbE7GmsB4pDmST0sozWSUkRk8IabSVOsI6f4UVBlFLNjbHpavvK O8m9wEnjxsyKLyhMBLCtRRwsN2NPYa+HjSM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719094586100003 Content-Type: text/plain; charset="utf-8" If the associated PCD is set to TRUE, use the memory attribute PPI to remap the stack non-executable. This provides a generic method for doing so, which will be used by ARM and AArch64 as well once they move to the generic DxeIpl handoff implementation. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c | 29 ++++++++++++++++++-- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 5 +++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c b/MdeModulePkg/Core/= DxeIplPeim/DxeHandoff.c index a0f85ebea56e6cba..60400da3521a8272 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c @@ -2,12 +2,15 @@ Generic version of arch-specific functionality for DxeLoad. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2023, Google, LLC. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 #include "DxeIpl.h" =20 +#include + /** Transfers control to DxeCore. =20 @@ -25,9 +28,10 @@ HandOffToDxeCore ( IN EFI_PEI_HOB_POINTERS HobList ) { - VOID *BaseOfStack; - VOID *TopOfStack; - EFI_STATUS Status; + VOID *BaseOfStack; + VOID *TopOfStack; + EFI_STATUS Status; + EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; =20 // // Allocate 128KB for the Stack @@ -35,6 +39,25 @@ HandOffToDxeCore ( BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); ASSERT (BaseOfStack !=3D NULL); =20 + if (PcdGetBool (PcdSetNxForStack)) { + Status =3D PeiServicesLocatePpi ( + &gEdkiiMemoryAttributePpiGuid, + 0, + NULL, + (VOID **)&MemoryPpi + ); + ASSERT_EFI_ERROR (Status); + + Status =3D MemoryPpi->SetPermissions ( + MemoryPpi, + (UINTN)BaseOfStack, + STACK_SIZE, + EFI_MEMORY_XP, + EFI_MEMORY_XP + ); + ASSERT_EFI_ERROR (Status); + } + // // Compute the top of the stack we were allocated. Pre-allocate a UINTN // for safety. diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 60c998be6c1bad01..7126a96d8378d1f8 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -91,6 +91,7 @@ [Ppis] gEfiPeiMemoryDiscoveredPpiGuid ## SOMETIMES_CONSUMES gEdkiiPeiBootInCapsuleOnDiskModePpiGuid ## SOMETIMES_CONSUMES gEdkiiPeiCapsuleOnDiskPpiGuid ## SOMETIMES_CONSUMES # Consume= d on firmware update boot path + gEdkiiMemoryAttributePpiGuid ## SOMETIMES_CONSUMES =20 [Guids] ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation" @@ -117,10 +118,12 @@ [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES =20 +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES + [Depex] gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid =20 --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105652): https://edk2.groups.io/g/devel/message/105652 Mute This Topic: https://groups.io/mt/99288482/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105653+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105653+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719095; cv=none; d=zohomail.com; s=zohoarc; b=gK7lFh7PvaRRVVQH9RrbQ5v4Kwjdy3xqkSVWpO15ssygRU8HTmDnX2vJOuu3as3c5djs9RZa/t+5j+DV7htS9aCY6nWgpflcx7AztUzeY665LzlGCbDgc3s5go3Kvcp9NS2s+Y/qxNWE2JPxRzejl1r72h8DMos1HQxeo8i9l/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719095; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=qW9iGcfhQ+nBPN/ub8VG9MsE2r35uPf/NgUhlds0maE=; b=jg1CtWFj0SEK0nBFsWPRTlTc50i9uqyKEKhS6UagxlcK99wka5lAFMfN8pCON0RSXJ9wehm99jzCv6R8FVPiDVVW3aGmDRGi3au3raK/QueP05SDbJNkz3J7ndU0zChgN6qySj+GZeSpcu6tGmtPV9JSXBqUc1vh/emwRW8kfS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105653+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719095525970.470478951353; Fri, 2 Jun 2023 08:18:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cQ7cYY1788612xe69RyaE7rx; Fri, 02 Jun 2023 08:18:15 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.1818.1685719094305701288 for ; Fri, 02 Jun 2023 08:18:14 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B2B5560C6D; Fri, 2 Jun 2023 15:18:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B02BC433D2; Fri, 2 Jun 2023 15:18:10 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 4/7] ArmPkg/ArmMmuLib: Extend API to manage memory permissions better Date: Fri, 2 Jun 2023 17:17:36 +0200 Message-Id: <20230602151739.3600820-5-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: CukWciZip9Yn2Sfm984tQkpcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719095; bh=5aKP3WRI0Bel5z0ThDRUHSrRExMTnfmsGDttze21n8E=; h=Cc:Date:From:Reply-To:Subject:To; b=gw7Pgof8ASCaEYARqRFlImqAhi0VfzlEscCBJKRM8uffIYK3zrBsbcS8P0PUjQY9pAm BHxyrlDMj+aO9Qcrx/C/eCZwguB3INtSKmZtoyapRCFryy516G83wCwURdxb+rJWLmEdp 8VG7vRQ9O3y46c56ds8sPuPRBS7Tv55iZL0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719096643100007 Content-Type: text/plain; charset="utf-8" Currently, ArmSetMemoryAttributes () takes a combination of EFI_MEMORY_xx constants describing the memory type and permission attributes that should be set on a region of memory. In cases where the memory type is omitted, we assume that the memory permissions being set are final, and that existing memory permissions can be discarded. This is problematic, because we aim to map memory non-executable (EFI_MEMORY_XP) by default, and only relax this requirement for code regions that are mapped read-only (EFI_MEMORY_RO). Currently, setting one permission clears the other, and so code managing these permissions has to be aware of the existing permissions in order to be able to preserve them, and this is not always tractable (e.g., the UEFI memory attribute protocol implements an abstraction that promises to preserve memory permissions that it is not operating on explicitly). So let's add an AttributeMask parameter to ArmSetMemoryAttributes(), which is permitted to be non-zero if no memory type is being provided, in which case only memory permission attributes covered in the mask will be affected by the update. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c | 2 +- ArmPkg/Include/Library/ArmMmuLib.h | 36 +++++++- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 52 +++++++++++- ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c | 88 +++++++++++++++++--- ArmPkg/Library/OpteeLib/Optee.c | 2 +- 5 files changed, 165 insertions(+), 15 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c b/ArmPkg/Drivers/CpuDxe/C= puMmuCommon.c index 2e73719dce04ceb5..2d60c7d24dc05ee9 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c +++ b/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c @@ -217,7 +217,7 @@ CpuSetMemoryAttributes ( if (EFI_ERROR (Status) || (RegionArmAttributes !=3D ArmAttributes) || ((BaseAddress + Length) > (RegionBaseAddress + RegionLength))) { - return ArmSetMemoryAttributes (BaseAddress, Length, EfiAttributes); + return ArmSetMemoryAttributes (BaseAddress, Length, EfiAttributes, 0); } else { return EFI_SUCCESS; } diff --git a/ArmPkg/Include/Library/ArmMmuLib.h b/ArmPkg/Include/Library/Ar= mMmuLib.h index 4cf59a1e376b123c..91d112314fdf4859 100644 --- a/ArmPkg/Include/Library/ArmMmuLib.h +++ b/ArmPkg/Include/Library/ArmMmuLib.h @@ -92,11 +92,45 @@ ArmReplaceLiveTranslationEntry ( IN BOOLEAN DisableMmu ); =20 +/** + Set the requested memory permission attributes on a region of memory. + + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. + + If Attributes contains a memory type attribute (EFI_MEMORY_UC/WC/WT/WB),= the + region is mapped according to this memory type, and additional memory + permission attributes (EFI_MEMORY_RP/RO/XP) are taken into account as we= ll, + discarding any permission attributes that are currently set for the regi= on. + AttributeMask is ignored in this case, and must be set to 0x0. + + If Attributes contains only a combination of memory permission attributes + (EFI_MEMORY_RP/RO/XP), each page in the region will retain its existing + memory type, even if it is not uniformly set across the region. In this = case, + AttributesMask may be set to a mask of permission attributes, and memory + permissions omitted from this mask will not be updated for any page in t= he + region. All attributes appearing in Attributes must appear in AttributeM= ask + as well. (Attributes & ~AttributeMask must produce 0x0) + + @param[in] BaseAddress The physical address that is the start addre= ss of + a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] Attributes Mask of memory attributes to set. + @param[in] AttributeMask Mask of memory attributes to take into accou= nt. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER BaseAddress or Length is not suitably alig= ned. + Invalid combination of Attributes and + AttributeMask. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. + +**/ EFI_STATUS ArmSetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, - IN UINT64 Attributes + IN UINT64 Attributes, + IN UINT64 AttributeMask ); =20 #endif // ARM_MMU_LIB_H_ diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index 7ed758fbbc699732..22623572b9cb931c 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -469,11 +469,45 @@ GcdAttributeToPageAttribute ( return PageAttributes; } =20 +/** + Set the requested memory permission attributes on a region of memory. + + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. + + If Attributes contains a memory type attribute (EFI_MEMORY_UC/WC/WT/WB),= the + region is mapped according to this memory type, and additional memory + permission attributes (EFI_MEMORY_RP/RO/XP) are taken into account as we= ll, + discarding any permission attributes that are currently set for the regi= on. + AttributeMask is ignored in this case, and must be set to 0x0. + + If Attributes contains only a combination of memory permission attributes + (EFI_MEMORY_RP/RO/XP), each page in the region will retain its existing + memory type, even if it is not uniformly set across the region. In this = case, + AttributesMask may be set to a mask of permission attributes, and memory + permissions omitted from this mask will not be updated for any page in t= he + region. All attributes appearing in Attributes must appear in AttributeM= ask + as well. (Attributes & ~AttributeMask must produce 0x0) + + @param[in] BaseAddress The physical address that is the start addre= ss of + a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] Attributes Mask of memory attributes to set. + @param[in] AttributeMask Mask of memory attributes to take into accou= nt. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER BaseAddress or Length is not suitably alig= ned. + Invalid combination of Attributes and + AttributeMask. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. + +**/ EFI_STATUS ArmSetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, - IN UINT64 Attributes + IN UINT64 Attributes, + IN UINT64 AttributeMask ) { UINT64 PageAttributes; @@ -490,6 +524,22 @@ ArmSetMemoryAttributes ( PageAttributes &=3D TT_AP_MASK | TT_UXN_MASK | TT_PXN_MASK | TT_AF; PageAttributeMask =3D ~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK | TT_PXN_MASK | TT_XN_MASK | TT_AF); + if (AttributeMask !=3D 0) { + if (((AttributeMask & ~(UINT64)(EFI_MEMORY_RP|EFI_MEMORY_RO|EFI_MEMO= RY_XP)) !=3D 0) || + ((Attributes & ~AttributeMask) !=3D 0)) + { + return EFI_INVALID_PARAMETER; + } + + // Add attributes omitted from AttributeMask to the set of attribute= s to preserve + PageAttributeMask |=3D GcdAttributeToPageAttribute (~AttributeMask) & + (TT_AP_MASK | TT_UXN_MASK | TT_PXN_MASK | TT_AF= ); + } + } else { + ASSERT (AttributeMask =3D=3D 0); + if (AttributeMask !=3D 0) { + return EFI_INVALID_PARAMETER; + } } =20 return UpdateRegionMapping ( diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c b/ArmPkg/Librar= y/ArmMmuLib/Arm/ArmMmuLibUpdate.c index 299d38ad07e85059..61405965a73eaeb8 100644 --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c @@ -10,6 +10,7 @@ #include =20 #include +#include #include #include #include @@ -451,31 +452,96 @@ SetMemoryAttributes ( } =20 /** - Update the permission or memory type attributes on a range of memory. + Set the requested memory permission attributes on a region of memory. =20 - @param BaseAddress The start of the region. - @param Length The size of the region. - @param Attributes A mask of EFI_MEMORY_xx constants. + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. =20 - @retval EFI_SUCCESS The attributes were set successfully. - @retval EFI_OUT_OF_RESOURCES The operation failed due to insufficient m= emory. + If Attributes contains a memory type attribute (EFI_MEMORY_UC/WC/WT/WB),= the + region is mapped according to this memory type, and additional memory + permission attributes (EFI_MEMORY_RP/RO/XP) are taken into account as we= ll, + discarding any permission attributes that are currently set for the regi= on. + AttributeMask is ignored in this case, and must be set to 0x0. + + If Attributes contains only a combination of memory permission attributes + (EFI_MEMORY_RP/RO/XP), each page in the region will retain its existing + memory type, even if it is not uniformly set across the region. In this = case, + AttributesMask may be set to a mask of permission attributes, and memory + permissions omitted from this mask will not be updated for any page in t= he + region. All attributes appearing in Attributes must appear in AttributeM= ask + as well. (Attributes & ~AttributeMask must produce 0x0) + + @param[in] BaseAddress The physical address that is the start addre= ss of + a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] Attributes Mask of memory attributes to set. + @param[in] AttributeMask Mask of memory attributes to take into accou= nt. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER BaseAddress or Length is not suitably alig= ned. + Invalid combination of Attributes and + AttributeMask. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. =20 **/ EFI_STATUS ArmSetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, - IN UINT64 Attributes + IN UINT64 Attributes, + IN UINT64 AttributeMask ) { + UINT32 TtEntryMask; + + if (((BaseAddress | Length) & EFI_PAGE_MASK) !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + if ((Attributes & EFI_MEMORY_CACHETYPE_MASK) =3D=3D 0) { + // + // No memory type was set in Attributes, so we are going to update the + // permissions only. + // + if (AttributeMask !=3D 0) { + if (((AttributeMask & ~(UINT64)(EFI_MEMORY_RP|EFI_MEMORY_RO|EFI_MEMO= RY_XP)) !=3D 0) || + ((Attributes & ~AttributeMask) !=3D 0)) + { + return EFI_INVALID_PARAMETER; + } + } else { + AttributeMask =3D EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMORY_XP; + } + + TtEntryMask =3D 0; + if ((AttributeMask & EFI_MEMORY_RP) !=3D 0) { + TtEntryMask |=3D TT_DESCRIPTOR_SECTION_AF; + } + + if ((AttributeMask & EFI_MEMORY_RO) !=3D 0) { + TtEntryMask |=3D TT_DESCRIPTOR_SECTION_AP_MASK; + } + + if ((AttributeMask & EFI_MEMORY_XP) !=3D 0) { + TtEntryMask |=3D TT_DESCRIPTOR_SECTION_XN_MASK; + } + } else { + ASSERT (AttributeMask =3D=3D 0); + if (AttributeMask !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + TtEntryMask =3D TT_DESCRIPTOR_SECTION_TYPE_MASK | + TT_DESCRIPTOR_SECTION_XN_MASK | + TT_DESCRIPTOR_SECTION_AP_MASK | + TT_DESCRIPTOR_SECTION_AF; + } + return SetMemoryAttributes ( BaseAddress, Length, Attributes, - TT_DESCRIPTOR_SECTION_TYPE_MASK | - TT_DESCRIPTOR_SECTION_XN_MASK | - TT_DESCRIPTOR_SECTION_AP_MASK | - TT_DESCRIPTOR_SECTION_AF + TtEntryMask ); } =20 diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Opte= e.c index 48e33cb3d5ee4ab6..46464f17ef06653e 100644 --- a/ArmPkg/Library/OpteeLib/Optee.c +++ b/ArmPkg/Library/OpteeLib/Optee.c @@ -86,7 +86,7 @@ OpteeSharedMemoryRemap ( return EFI_BUFFER_TOO_SMALL; } =20 - Status =3D ArmSetMemoryAttributes (PhysicalAddress, Size, EFI_MEMORY_WB); + Status =3D ArmSetMemoryAttributes (PhysicalAddress, Size, EFI_MEMORY_WB,= 0); if (EFI_ERROR (Status)) { return Status; } --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105653): https://edk2.groups.io/g/devel/message/105653 Mute This Topic: https://groups.io/mt/99288483/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105654+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105654+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719098; cv=none; d=zohomail.com; s=zohoarc; b=bS3UOCDTIjKgMJXBEyYJJDf0UmzwBCN+3iwoPM2/W6xvZbj+Zly5BmcjEzZyNu2a38duPlJsQvfzzaJGFuigZJXWpbpB1H6Gp9Un1W+OJOVxiTnp5+fBmAbzay1+zBNlBHeXbT9dQq1Vr0wsfO6z+dqQpelUTMQIGTy9O06CWIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719098; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gsBi9Y5hW+q/tKPtObvqZIV9HK0iq0f5dl/HzybhWxI=; b=GrzL1GIKCYNREwoYQnnX0GDw8Mm+PTBZx+bEwE2ZU0WmnzKfe0Q3SMU1WGg9/87ZYLe3bgwlmnEo0g7Ny8nNssVlP61EhjxLNy2rhgPKNEDDRwF/vUK/qqomYtAOC08q6/Pg9IeFI7QkBddgVVY2IxBduMwINFh2LdVUqbMimow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105654+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719098558559.6545479304143; Fri, 2 Jun 2023 08:18:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id oJ3ZYY1788612xh71zla0qAE; Fri, 02 Jun 2023 08:18:18 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.16081.1685719097281785613 for ; Fri, 02 Jun 2023 08:18:17 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9FCF616FD; Fri, 2 Jun 2023 15:18:16 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91E77C433EF; Fri, 2 Jun 2023 15:18:13 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 5/7] ArmPkg/CpuPei: Implement the memory attributes PPI Date: Fri, 2 Jun 2023 17:17:37 +0200 Message-Id: <20230602151739.3600820-6-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: rNSxf6fokbZPh2Kh9tNNhthZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719098; bh=Y0UFS8WL8be2g+YlVuZZwJEPBHleS8KfpL7i1nlAa+4=; h=Cc:Date:From:Reply-To:Subject:To; b=nor88SPoEgWqmQnuKRjHpjHo6ERslUxRFaXJObsnyudt6nyLOvFeUGmkq2ajf86VbyU 8WwVtY2lnn47+eumCb5K+VmOP2DFZq8gKUpysYrn33XlPr+znm7ypDPDsv6XJ+WPIF0jH W6WhSQ32ILniDZmTiVbiRk44UKwGlQe1yRw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719099499100001 Content-Type: text/plain; charset="utf-8" Implement the newly defined PPI that permits the PEI core and DXE IPL to manage memory permissions on ranges of DRAM, for doing things like mapping the stack non-executable, or granting executable permissions to shadowed PEIMs. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- ArmPkg/Drivers/CpuPei/CpuPei.c | 76 ++++++++++++++++++++ ArmPkg/Drivers/CpuPei/CpuPei.inf | 4 ++ 2 files changed, 80 insertions(+) diff --git a/ArmPkg/Drivers/CpuPei/CpuPei.c b/ArmPkg/Drivers/CpuPei/CpuPei.c index 85ef5ec07b9fdafa..1c2b53100f6a424e 100644 --- a/ArmPkg/Drivers/CpuPei/CpuPei.c +++ b/ArmPkg/Drivers/CpuPei/CpuPei.c @@ -3,6 +3,7 @@ Copyright (c) 2006, Intel Corporation. All rights reserved.
Copyright (c) 2011 Hewlett Packard Corporation. All rights reserved.
Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+Copyright (c) 2023, Google, LLC. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -24,6 +25,7 @@ Module Name: // The protocols, PPI and GUID definitions for this module // #include +#include =20 // // The Library classes this module consumes @@ -34,6 +36,77 @@ Module Name: #include #include #include +#include + +/** + Set the requested memory permission attributes on a region of memory. + + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. + + Attributes must contain a combination of EFI_MEMORY_RP, EFI_MEMORY_RO and + EFI_MEMORY_XP, and specifies the attributes that must be set for the + region in question. Attributes that are omitted will be cleared from the + region only if they are set in AttributeMask. + + AttributeMask must contain a combination of EFI_MEMORY_RP, EFI_MEMORY_RO= and + EFI_MEMORY_XP, and specifies the attributes that the call will operate o= n. + AttributeMask must not be 0x0, and must contain at least the bits set in + Attributes. + + @param[in] This The protocol instance pointer. + @param[in] BaseAddress The physical address that is the start add= ress + of a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] Attributes Memory attributes to set or clear. + @param[in] AttributeMask Mask of memory attributes to operate on. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER Length is zero. + AttributeMask is zero. + AttributeMask lacks bits set in Attributes. + BaseAddress or Length is not suitably alig= ned. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specifi= ed + by BaseAddress and Length. + The bit mask of attributes is not supporte= d for + the memory resource range specified by + BaseAddress and Length. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. + +**/ +STATIC +EFI_STATUS +EFIAPI +SetMemoryPermissions ( + IN EDKII_MEMORY_ATTRIBUTE_PPI *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes, + IN UINT64 AttributeMask + ) +{ + if ((Length =3D=3D 0) || + (AttributeMask =3D=3D 0) || + ((AttributeMask & (EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMORY_XP)) = =3D=3D 0) || + ((Attributes & ~AttributeMask) !=3D 0) || + (((BaseAddress | Length) & EFI_PAGE_MASK) !=3D 0)) + { + return EFI_INVALID_PARAMETER; + } + + return ArmSetMemoryAttributes (BaseAddress, Length, Attributes, Attribut= eMask); +} + +STATIC CONST EDKII_MEMORY_ATTRIBUTE_PPI mMemoryAttributePpi =3D { + SetMemoryPermissions +}; + +STATIC CONST EFI_PEI_PPI_DESCRIPTOR mMemoryAttributePpiDesc =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEdkiiMemoryAttributePpiGuid, + (VOID *)&mMemoryAttributePpi +}; =20 /*++ =20 @@ -79,5 +152,8 @@ InitializeCpuPeim ( } } =20 + Status =3D PeiServicesInstallPpi (&mMemoryAttributePpiDesc); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; } diff --git a/ArmPkg/Drivers/CpuPei/CpuPei.inf b/ArmPkg/Drivers/CpuPei/CpuPe= i.inf index a9f85cbc68b1c52e..49b67077ec6166f1 100644 --- a/ArmPkg/Drivers/CpuPei/CpuPei.inf +++ b/ArmPkg/Drivers/CpuPei/CpuPei.inf @@ -3,6 +3,7 @@ # # This module provides platform specific function to detect boot mode. # Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2023, Google, LLC. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -28,6 +29,7 @@ [Sources] CpuPei.c =20 [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec EmbeddedPkg/EmbeddedPkg.dec ArmPkg/ArmPkg.dec @@ -37,9 +39,11 @@ [LibraryClasses] DebugLib HobLib ArmLib + ArmMmuLib =20 [Ppis] gArmMpCoreInfoPpiGuid + gEdkiiMemoryAttributePpiGuid =20 [Guids] gArmMpCoreInfoGuid --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105654): https://edk2.groups.io/g/devel/message/105654 Mute This Topic: https://groups.io/mt/99288484/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105655+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105655+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719101; cv=none; d=zohomail.com; s=zohoarc; b=MeKxAwHGAg7wmorRrXM35AWCbpQitklEfho76i3uDvr6VEDJJFCRW73fzWATvZKVFIjbBeloqnluj+a/d3R/9laCqycd9p7cqKABw1u+jKrbCbCw2J5Nu1aC30XHmoYd0SdsKEO2UsRlWRWAU635LXr2/aD2eEnlpyRueqyXvpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719101; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wJCf1bCgGIqGrmb66gTXN5cq0jxEOtQ1OeWA7cyNGVo=; b=iD4ZnhMo52YaUmJ+VYFkRvbRduciYlEN+8Mn2STd11f+DTa5Gx7tKWhAmrldRdLDrPTP0MB+wqCAJbKG2UH64Nq4FCRqcst1mBQ49spBIE3Cy3BMq6GNwD4ScV7e6N/EzCD0QcSjCvmX0GjWmL3TzC4Tx9TV1ywVbZzBtiOgD1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105655+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719101595101.72383903431967; Fri, 2 Jun 2023 08:18:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id stCUYY1788612xat3pjMlW8h; Fri, 02 Jun 2023 08:18:21 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.1820.1685719100327578962 for ; Fri, 02 Jun 2023 08:18:20 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DBD6760C40; Fri, 2 Jun 2023 15:18:19 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8D61C433A0; Fri, 2 Jun 2023 15:18:16 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 6/7] MdeModulePkg/DxeIpl ARM AARCH64: Switch to generic handoff code Date: Fri, 2 Jun 2023 17:17:38 +0200 Message-Id: <20230602151739.3600820-7-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: RYdlmKSFaFwFuYo4TV24DAnlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719101; bh=8DkUFIT2+RdbFPLeDgno7oiDpV+QXpBXSg4SJD2dcVI=; h=Cc:Date:From:Reply-To:Subject:To; b=uSZGzkOH+3AnThNs1Dkw/xx7nTS09+DcHcPhw9MjwJ75rqWCHObstVA+m3FFSZbOOFD us5dRJkJSSs2yaCo/8jqnT5lrcyNsicxvnmFNaeFUn7eSAsukTD/ecUzDxlzw98eLrFN8 0H1ZyUmX0wFWLA6nsv4WsGcZOt6CY4SHRBo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719102643100001 Content-Type: text/plain; charset="utf-8" Now that we have a generic method to manage memory permissions using a PPI, we can switch to the generic version of the DXE handoff code in DxeIpl, and drop the ARM specific version. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- MdeModulePkg/Core/DxeIplPeim/Arm/DxeLoadFunc.c | 71 -------------------- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 11 +-- 2 files changed, 1 insertion(+), 81 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/Arm/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/Arm/DxeLoadFunc.c deleted file mode 100644 index f62b6dcb38a702d7..0000000000000000 --- a/MdeModulePkg/Core/DxeIplPeim/Arm/DxeLoadFunc.c +++ /dev/null @@ -1,71 +0,0 @@ -/** @file - ARM specifc functionality for DxeLoad. - -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
-Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "DxeIpl.h" - -#include - -/** - Transfers control to DxeCore. - - This function performs a CPU architecture specific operations to execute - the entry point of DxeCore with the parameters of HobList. - It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. - - @param DxeCoreEntryPoint The entry point of DxeCore. - @param HobList The start of HobList passed to DxeCore. - -**/ -VOID -HandOffToDxeCore ( - IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList - ) -{ - VOID *BaseOfStack; - VOID *TopOfStack; - EFI_STATUS Status; - - // - // Allocate 128KB for the Stack - // - BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); - ASSERT (BaseOfStack !=3D NULL); - - if (PcdGetBool (PcdSetNxForStack)) { - Status =3D ArmSetMemoryRegionNoExec ((UINTN)BaseOfStack, STACK_SIZE); - ASSERT_EFI_ERROR (Status); - } - - // - // Compute the top of the stack we were allocated. Pre-allocate a UINTN - // for safety. - // - TopOfStack =3D (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SI= ZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); - TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); - - // - // End of PEI phase singal - // - Status =3D PeiServicesInstallPpi (&gEndOfPeiSignalPpi); - ASSERT_EFI_ERROR (Status); - - // - // Update the contents of BSP stack HOB to reflect the real stack info p= assed to DxeCore. - // - UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE); - - SwitchStack ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, - HobList.Raw, - NULL, - TopOfStack - ); -} diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 7126a96d8378d1f8..f1990eac77607854 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -45,19 +45,13 @@ [Sources.X64] X64/VirtualMemory.c X64/DxeLoadFunc.c =20 -[Sources.ARM, Sources.AARCH64] - Arm/DxeLoadFunc.c - -[Sources.LOONGARCH64,Sources.RISCV64,Sources.EBC] +[Sources.LOONGARCH64,Sources.RISCV64,Sources.EBC,Sources.ARM,Sources.AARCH= 64] DxeHandoff.c =20 [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec =20 -[Packages.ARM, Packages.AARCH64] - ArmPkg/ArmPkg.dec - [LibraryClasses] PcdLib MemoryAllocationLib @@ -74,9 +68,6 @@ [LibraryClasses] PeiServicesTablePointerLib PerformanceLib =20 -[LibraryClasses.ARM, LibraryClasses.AARCH64] - ArmMmuLib - [Ppis] gEfiDxeIplPpiGuid ## PRODUCES gEfiPeiDecompressPpiGuid ## PRODUCES --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105655): https://edk2.groups.io/g/devel/message/105655 Mute This Topic: https://groups.io/mt/99288485/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 15:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105656+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105656+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685719104; cv=none; d=zohomail.com; s=zohoarc; b=ivV3eK27uUSEp8iDI8vVPFC5vxILzEFznm27sQNR0NwVI01J3Fzhb4kxtjlpm5ysmDVcGajUOx36uP9BXNXXq5eYYvRE6zxehVz4xL7Bw9Lk8uZeVa00QyTrDxElzZdQ3cF+d3HTMBwWrCvjfrJu2cjXd66MRuRbEq+4uYJe1Y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685719104; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MUFCLaSmCb9Om+efHJVviAYExanQ+n+dWOy5DRJ74Z4=; b=oDaekKVTwi9CIU1ALScZIHoxpgk29tJWGAAb4VlQl/RMcsX7MPglynRLgjnioRRSDV5cPzfaKaT4L1zoQB5Ep9mBe3iUuXsyKE5AVhF4Y9M4qJG0xr2HwsNki5pIdWvDG/a+a3077qLpWTRcVzfTIaQL51T8V67ssLN5HqFiwMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105656+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685719104842615.4325302796047; Fri, 2 Jun 2023 08:18:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CwPqYY1788612x0DePyl8BRN; Fri, 02 Jun 2023 08:18:24 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.16087.1685719103459950585 for ; Fri, 02 Jun 2023 08:18:23 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04A0961638; Fri, 2 Jun 2023 15:18:23 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD870C4339C; Fri, 2 Jun 2023 15:18:19 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [PATCH v2 7/7] ArmPkg/CpuDxe: Simplify memory attributes protocol implementation Date: Fri, 2 Jun 2023 17:17:39 +0200 Message-Id: <20230602151739.3600820-8-ardb@kernel.org> In-Reply-To: <20230602151739.3600820-1-ardb@kernel.org> References: <20230602151739.3600820-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: mdNxQLQ9m6IMb9VzKdr0FW0wx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685719104; bh=Dl47kaD+H19b5cfhb/UhQlZDXK26zepwZxk6pjAeQpg=; h=Cc:Date:From:Reply-To:Subject:To; b=uhIOelXW6OfQYy+upgmDk2eY7qAZL/aS66dRixf4WojefFBLlKpx7LCNLxZnB59BH2G Us9eX2xMJC1mLLYPdXqccH6arCEW4k1w0sIdudoexqq+5l1lFx3rRH5AFwAQBS3R8ZpyW 4s8otR9L1kvACFEXtP7y5j3wg9DUqUyhAbs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685719105368100005 Content-Type: text/plain; charset="utf-8" Now that ArmSetMemoryAttributes() permits a mask to be provided, we can simplify the implementation the UEFI memory attribute protocol substantially, and just pass on the requested mask to be set or cleared directly. Signed-off-by: Ard Biesheuvel Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny --- ArmPkg/Drivers/CpuDxe/MemoryAttribute.c | 50 +------------------- 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c b/ArmPkg/Drivers/CpuDx= e/MemoryAttribute.c index 61ba8fbbae4ee795..16cc4ef474f9772b 100644 --- a/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c +++ b/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c @@ -183,8 +183,6 @@ SetMemoryAttributes ( IN UINT64 Attributes ) { - EFI_STATUS Status; - DEBUG (( DEBUG_INFO, "%a: BaseAddress =3D=3D 0x%lx, Length =3D=3D 0x%lx, Attributes =3D=3D = 0x%lx\n", @@ -204,28 +202,7 @@ SetMemoryAttributes ( return EFI_UNSUPPORTED; } =20 - if ((Attributes & EFI_MEMORY_RP) !=3D 0) { - Status =3D ArmSetMemoryRegionNoAccess (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - if ((Attributes & EFI_MEMORY_RO) !=3D 0) { - Status =3D ArmSetMemoryRegionReadOnly (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - if ((Attributes & EFI_MEMORY_XP) !=3D 0) { - Status =3D ArmSetMemoryRegionNoExec (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - return EFI_SUCCESS; + return ArmSetMemoryAttributes (BaseAddress, Length, Attributes, Attribut= es); } =20 /** @@ -267,8 +244,6 @@ ClearMemoryAttributes ( IN UINT64 Attributes ) { - EFI_STATUS Status; - DEBUG (( DEBUG_INFO, "%a: BaseAddress =3D=3D 0x%lx, Length =3D=3D 0x%lx, Attributes =3D=3D = 0x%lx\n", @@ -288,28 +263,7 @@ ClearMemoryAttributes ( return EFI_UNSUPPORTED; } =20 - if ((Attributes & EFI_MEMORY_RP) !=3D 0) { - Status =3D ArmClearMemoryRegionNoAccess (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - if ((Attributes & EFI_MEMORY_RO) !=3D 0) { - Status =3D ArmClearMemoryRegionReadOnly (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - if ((Attributes & EFI_MEMORY_XP) !=3D 0) { - Status =3D ArmClearMemoryRegionNoExec (BaseAddress, Length); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - return EFI_SUCCESS; + return ArmSetMemoryAttributes (BaseAddress, Length, 0, Attributes); } =20 EFI_MEMORY_ATTRIBUTE_PROTOCOL mMemoryAttribute =3D { --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105656): https://edk2.groups.io/g/devel/message/105656 Mute This Topic: https://groups.io/mt/99288489/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-