From nobody Fri Oct 25 15:40:51 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+101112+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+101112+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1678727879; cv=none; d=zohomail.com; s=zohoarc; b=GuutItP4ClQsayijpa9G65yldJKKeZiEJp9CwsX1ltC+YfqfnFM1IAlOld4sr+bESl0cuFmaleVI4+1RKcA+la4e5JJyqw+h3Zsa0PzIft7yiRL+vlEe2IqjM6RJBdDCr6i0VDdbDNNCxFAveYt0cSFxuUmUCidLsAPPatEJbLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678727879; 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=O/bze0/9pIY/KoC68sGm2crQ5LvJaYZWRBIehmS1Bkk=; b=j4AgIQmh1Ls3yfM3CeP3XiAVpQKsfxg2KMJ1U5PtU90aENZ9GBNEmpzNyhclEyql0wzG3Ou241ksd0s5H2DTwnwW4to0PGEETE0XEG3B1ym+LXqpo/6MXGcVR8sM/JAAKEF0HMp2JBRh0dfd+Z04pLbPV6/dugvz6cFwyDTJjUQ= 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+101112+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 1678727879144372.1975313704687; Mon, 13 Mar 2023 10:17:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PISrYY1788612xZWlRYYucfW; Mon, 13 Mar 2023 10:17:58 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.26473.1678727877734257378 for ; Mon, 13 Mar 2023 10:17:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id 25897B811B1; Mon, 13 Mar 2023 17:17:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BD37C433A1; Mon, 13 Mar 2023 17:17:52 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe Subject: [edk2-devel] [PATCH v5 08/38] ArmPkg/ArmMmuLib: Avoid splitting block entries if possible Date: Mon, 13 Mar 2023 18:16:44 +0100 Message-Id: <20230313171714.3866151-9-ardb@kernel.org> In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-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: ct11LemkpYLnXnw7qkZIjz6lx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678727878; bh=rBvqlEdpYfCGmcjUooIGeKIPjxJQe9xN7Y0AO8wSl+A=; h=Cc:Date:From:Reply-To:Subject:To; b=BaPyAbqo7xum+E7f4c6lNFGphrC4XbUE1jvFxKQvaw1JoUnsQSswmsm12W+XeRcgbFj vLyco4dL6HRpz7UOyyddkaJolM5UiD2zRWzlAR7/jZasymS0RRX3tbu19jnFvI6mAxmmM 7toiiYVIJNgyIC0tjp7dnH3rvSydTLjH6qc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678727879987100001 Content-Type: text/plain; charset="utf-8" Currently, the ARM MMU page table logic will break down any block entry that overlaps with the region being mapped, even if the block entry in question is using the same attributes as the new region. This means that creating a non-executable mapping inside a region that is already mapped non-executable at a coarser granularity may trigger a call to AllocatePages (), which may recurse back into the page table code to update the attributes on the newly allocated page tables. Let's avoid this, by preserving the block entry if it already covers the region being mapped with the correct attributes. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 10 ++++++++++ ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index 6d21a2e41dd1..1ce200c43c72 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -251,6 +251,16 @@ UpdateRegionMappingRecursive ( ASSERT (Level < 3); =20 if (!IsTableEntry (*Entry, Level)) { + // + // If the region we are trying to map is already covered by a block + // entry with the right attributes, don't bother splitting it up. + // + if (IsBlockEntry (*Entry, Level) && + ((*Entry & TT_ATTRIBUTES_MASK & ~AttributeClearMask) =3D=3D At= tributeSetMask)) + { + continue; + } + // // No table entry exists yet, so we need to allocate a page table // for the next level. diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c b/ArmPkg/Librar= y/ArmMmuLib/Arm/ArmMmuLibUpdate.c index 247cf87bf3d3..299d38ad07e8 100644 --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c @@ -170,6 +170,17 @@ UpdatePageEntries ( =20 // Does this descriptor need to be converted from section entry to 4K = pages? if (!TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE (Descriptor)) { + // + // If the section mapping covers the requested region with the expec= ted + // attributes, splitting it is unnecessary, and should be avoided as= it + // may result in unbounded recursion when using a strict NX policy. + // + if ((EntryValue & ~TT_DESCRIPTOR_PAGE_TYPE_MASK & EntryMask) =3D=3D + (ConvertSectionAttributesToPageAttributes (Descriptor) & EntryMa= sk)) + { + continue; + } + Status =3D ConvertSectionToPages (FirstLevelIdx << TT_DESCRIPTOR_SEC= TION_BASE_SHIFT); if (EFI_ERROR (Status)) { // Exit for loop --=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 (#101112): https://edk2.groups.io/g/devel/message/101112 Mute This Topic: https://groups.io/mt/97585995/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-