From nobody Tue Feb 10 22:17:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55644+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55644+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583588065; cv=none; d=zohomail.com; s=zohoarc; b=RaiVxzpmWl/0AUM/HFiCrOvayOlwdJOvYsSqhnYnfLQ0TSEkb6aiTAx8kQx351+D0Z8NC6CKTdQswlS7xkmRpWOfEZYzO6cC+4WWB38BPPUeHVJRZbsl4p7LDxvq0jeVSAtqmaqO/wpUkMd1A+VRTTNVFrbXg/a3mvjWBTwYINE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583588065; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=YRXDlHE4M0FM+tRpxEYXHvE07lQ7gSfbHV3JiBu47qs=; b=h6PnYnto5K9yjcRzKFQMTByNA4tO8I4BZG/bQfhKnJOMTMERoQdE6saZ2qSJlAtfCc1Ygbzx0AqVW0bVjs7mLif0xX0xUh/wua3i6KbQTdwFpfWMsLSZ0RWgcSoPVRjlT3OPIYOb0kZHCEhPfa/394TyR5pWkuC0z7sslycCizA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55644+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583588065558970.3946928849241; Sat, 7 Mar 2020 05:34:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id r329YY1788612x6KcyV4hYkx; Sat, 07 Mar 2020 05:34:25 -0800 X-Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by mx.groups.io with SMTP id smtpd.web10.13254.1583588064606852027 for ; Sat, 07 Mar 2020 05:34:24 -0800 X-Received: by mail-oi1-f193.google.com with SMTP id p125so5517732oif.10 for ; Sat, 07 Mar 2020 05:34:24 -0800 (PST) X-Gm-Message-State: 2vteiokYtUqUy7LzE9dwbRWax1787277AA= X-Google-Smtp-Source: ADFU+vvYDDYMJxuc/mfHoPxKBgThdpBbH3Xnv+3Y0pCLLPQFbeb0tnudcJzOClKaShp/twOqFQZHIg== X-Received: by 2002:a54:468a:: with SMTP id k10mr6046894oic.3.1583588063481; Sat, 07 Mar 2020 05:34:23 -0800 (PST) X-Received: from cam-smtp0.cambridge.arm.com ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id l15sm7775815otf.12.2020.03.07.05.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2020 05:34:22 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH 1/2] ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types Date: Sat, 7 Mar 2020 14:34:14 +0100 Message-Id: <20200307133415.18857-2-ard.biesheuvel@linaro.org> In-Reply-To: <20200307133415.18857-1-ard.biesheuvel@linaro.org> References: <20200307133415.18857-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583588065; bh=cc4ex/4aOnMol+qgEOFx+e1vLby9F9DdifVFpQ7BkIs=; h=Cc:Date:From:Reply-To:Subject:To; b=HwwAPavPPg/IdkOuf7ri4uP7HoIzE9AapP3UgcaJJvfwRgweqHqZKGmEdER9fmuaZWv EDP+am7nPCYLJIEXC5IJ0+o2l25hawJK4k31SBXSnUJSZb96wW0dsEdkyb43Jh/PswlyW rh+WsGE7lOJwqFKKMrvSii+ygQx+OtBmFpw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Given how the meaning of the attribute bits for page table entry types is slightly awkward, and changes between levels, add some helpers to abstract from this. Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 40 +++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index a43d468b73ca..6f6ef5b05fbc 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -156,6 +156,36 @@ FreePageTablesRecursive ( FreePages (TranslationTable, 1); } =20 +STATIC +BOOLEAN +IsBlockEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level =3D=3D 3) { + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY_LEVEL3; + } + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY; +} + +STATIC +BOOLEAN +IsTableEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level =3D=3D 3) { + // + // TT_TYPE_TABLE_ENTRY aliases TT_TYPE_BLOCK_ENTRY_LEVEL3 + // so we need to take the level into account as well. + // + return FALSE; + } + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_TABLE_ENTRY; +} + STATIC EFI_STATUS UpdateRegionMappingRecursive ( @@ -197,7 +227,7 @@ UpdateRegionMappingRecursive ( if (Level =3D=3D 0 || ((RegionStart | BlockEnd) & BlockMask) !=3D 0) { ASSERT (Level < 3); =20 - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { // // No table entry exists yet, so we need to allocate a page table // for the next level. @@ -215,7 +245,7 @@ UpdateRegionMappingRecursive ( InvalidateDataCacheRange (TranslationTable, EFI_PAGE_SIZE); } =20 - if ((*Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY) { + if (IsBlockEntry (*Entry, Level)) { // // We are splitting an existing block entry, so we have to popul= ate // the new table with the attributes of the block entry it repla= ces. @@ -246,7 +276,7 @@ UpdateRegionMappingRecursive ( AttributeSetMask, AttributeClearMask, TranslationTable, Level + 1); if (EFI_ERROR (Status)) { - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { // // We are creating a new table entry, so on failure, we can free= all // allocations we made recursively, given that the whole subhier= archy @@ -259,10 +289,10 @@ UpdateRegionMappingRecursive ( return Status; } =20 - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { EntryValue =3D (UINTN)TranslationTable | TT_TYPE_TABLE_ENTRY; ReplaceTableEntry (Entry, EntryValue, RegionStart, - (*Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_EN= TRY); + IsBlockEntry (*Entry, Level)); } } else { EntryValue =3D (*Entry & AttributeClearMask) | AttributeSetMask; --=20 2.17.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 (#55644): https://edk2.groups.io/g/devel/message/55644 Mute This Topic: https://groups.io/mt/71795103/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-