From nobody Mon Feb 9 09:33:38 2026 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 --- 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-