From nobody Sun Feb 8 03:57:56 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+99893+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+99893+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1675951213; cv=none; d=zohomail.com; s=zohoarc; b=TzT/9z/sNUCeWpp8ffAsJ7QHGCgARuz4lSHPTPUdTgZCPYpku/8wnxQLCagG+ndEv6mnAZXNde3VD9HTJ4q3AgXANU0TfrWTEiBng5Pno6ksTfeHL5vt95dMty6xIkqFRKy7NG0o4db3vnVGxpttC28shjZNMLF+uRZ+HGT9YYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675951213; 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=3dYO84A+cW/VjPKntLhTMRNGcZBkxjDDXF8rQgUivps=; b=mUc7rsL8XP6M5JBlnjwAh/XGXTQQv2jdUn5H5l1AN/IpgtEELcbtInuIlNqyOtrKRu/5Oi7tLZFviJFWrjmkjIJyBU/a/A3I8Coujwo5hmZWeAnorPIYdC4YN0RImWg1okmcgdFNmn5RUlvtH4JHLqBXyWS49qCESp3SQHbEWko= 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+99893+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 167595121312129.85275403765195; Thu, 9 Feb 2023 06:00:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kE6zYY1788612xxUzQ1nzXQS; Thu, 09 Feb 2023 06:00:12 -0800 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.15553.1675951211850480313 for ; Thu, 09 Feb 2023 06:00:12 -0800 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 4BC13B82081; Thu, 9 Feb 2023 14:00:10 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC8F1C433A4; Thu, 9 Feb 2023 14:00:06 +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 v4 08/11] ArmPkg/ArmMmuLib: Avoid splitting block entries if possible Date: Thu, 9 Feb 2023 14:59:33 +0100 Message-Id: <20230209135936.789983-9-ardb@kernel.org> In-Reply-To: <20230209135936.789983-1-ardb@kernel.org> References: <20230209135936.789983-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: 4tE7JF3Vca3KAmRN9aXF4hgRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675951212; bh=/MFWahVlfuPjLEjPN5hznPCqQmzQogbrLHrxwmTbAOU=; h=Cc:Date:From:Reply-To:Subject:To; b=SUDrzxVKooyRuN+aTtWwFI4R/P+1bLJajBUmF2ni4w9Avp2xIVVrn9RoJVky+f0OE2u BRvcCgROIZ0iZFHntWtcp9B2lD2OChu7fcJq8Gc4Wdvgv2GznmvyG/i7+EmdXYsJ/nZy1 dL7hnNkFSLeOhWGmX+Tja2MAj1Ba173rtiE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675951214154100001 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 --- 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.1 -=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 (#99893): https://edk2.groups.io/g/devel/message/99893 Mute This Topic: https://groups.io/mt/96853180/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-