From nobody Sun Dec 22 06:05:26 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+105306+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+105306+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685025078; cv=none; d=zohomail.com; s=zohoarc; b=LW80HeRhpEs7oAkhBFG4x42ZU3PyFjXyrBwH//LvvWGQB0oiEPfn9n/eskmPZdz5iJKwRr7uMdBS3kS+q6wJhAgsw6+9Xlb0GehYqFsAEz9GoslTRyTfdQhjAwROiLOYhann9wVG4548oyfdVmlHZi2ljWAivavCnBav44NKkek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685025078; 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=BXL8XF6PG75V+vCTnWU+uCdo+/F1ES7D/mzKrmu6BzU=; b=DUUMaMyEkjNsmsGh8D3049A72WQFFo37lRMFCWDSWNRzr9WWqMv8W7tLqkEEEY6XiIpynLh4c7p/3t+xKSDUPtGBBIYd9S8+QW5I/uiMq6lMhNvuAZHP+QvJhyglJ+ibUvcdGVWbd8OuHlDnY3YR4ODReZNT5MC13RUDtvmJS3U= 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+105306+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 1685025078307206.64222416825328; Thu, 25 May 2023 07:31:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1oaOYY1788612xZRnPyPAIEf; Thu, 25 May 2023 07:31:17 -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.13537.1685025077145265617 for ; Thu, 25 May 2023 07:31: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 AD34864623; Thu, 25 May 2023 14:31:16 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9298EC4339B; Thu, 25 May 2023 14:31: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 , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Sunil V L , Andrei Warkentin Subject: [edk2-devel] [RFC PATCH 06/10] ArmPkg/CpuPei: Implement the memory attributes PPI Date: Thu, 25 May 2023 16:30:37 +0200 Message-Id: <20230525143041.1172989-7-ardb@kernel.org> In-Reply-To: <20230525143041.1172989-1-ardb@kernel.org> References: <20230525143041.1172989-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: 3vbdXUAJdHt7mTmjjKCUh3IRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685025077; bh=RAGg27twRNVupyuwDtwLXqQaRlGY4fz6HTi3ummX6ck=; h=Cc:Date:From:Reply-To:Subject:To; b=EkJ0UkeXZzZyDl9RiJS4T+GxiyRu+iZbh4+SB+SU9JMgn6Jf3KDholBas/D0Vqahrzn HIjPFPUDOv86yc9gGfXLk2m82qiO7XyVClRUe3WU2IKaPUHKJBpDG3DN4ou2ovqKa2NnG NsR6JdL7ic8UMBwBoX9ix3n1t+POMvVazz4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685025078603100009 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 | 78 ++++++++++++++++++-- ArmPkg/Drivers/CpuPei/CpuPei.inf | 4 + 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/ArmPkg/Drivers/CpuPei/CpuPei.c b/ArmPkg/Drivers/CpuPei/CpuPei.c index 85ef5ec07b9fdafa..d5996673260544c8 100644 --- a/ArmPkg/Drivers/CpuPei/CpuPei.c +++ b/ArmPkg/Drivers/CpuPei/CpuPei.c @@ -3,17 +3,10 @@ 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 -Module Name: - - MemoryInit.c - -Abstract: - - PEIM to provide fake memory init - **/ =20 // @@ -24,6 +17,7 @@ Module Name: // The protocols, PPI and GUID definitions for this module // #include +#include =20 // // The Library classes this module consumes @@ -34,6 +28,71 @@ 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. + + Both SetMask and ClearMask may contain any combination of EFI_MEMORY_RP, + EFI_MEMORY_RO and EFI_MEMORY_XP, with the following restrictions: + - each constant may appear in either SetMask or ClearMask, but not in bo= th; + - SetMask or ClearMask may be 0x0, but not both. + + @param[in] This The protocol instance pointer. + @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] SetMask Mask of memory attributes to set. + @param[in] ClearMask Mask of memory attributes to clear. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER Length is zero. + Invalid combination of SetMask and ClearMa= sk. + 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 SetMask, + IN UINT64 ClearMask + ) +{ + if ((Length =3D=3D 0) || + ((SetMask & ClearMask) !=3D 0) || + (((SetMask | ClearMask) & (EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMOR= Y_XP)) =3D=3D 0) || + (((SetMask | ClearMask) & ~(UINT64)(EFI_MEMORY_RP | EFI_MEMORY_RO | = EFI_MEMORY_XP)) !=3D 0) || + (((BaseAddress | Length) & EFI_PAGE_MASK) !=3D 0)) + { + return EFI_INVALID_PARAMETER; + } + + return ArmSetMemoryAttributes (BaseAddress, Length, SetMask, SetMask | C= learMask); +} + +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 +138,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 648f27adf9402435..2ca4f795c62de394 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 (#105306): https://edk2.groups.io/g/devel/message/105306 Mute This Topic: https://groups.io/mt/99131185/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-