From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.25779.1678727862374666252 for ; Mon, 13 Mar 2023 10:17:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R0VSoy6Y; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) 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 12C32B811B8; Mon, 13 Mar 2023 17:17:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BED9C433A0; Mon, 13 Mar 2023 17:17:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678727858; bh=tAXCVvMMtajrHPRtdNr+XcMESO+HQpv9rQGqU/KTHrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0VSoy6YW1Vb/d2d4zqPEACzCik7/ZlwfFbRm7hRzA9bJgNX7eJoHDdc2bhBAPYJY +EidRDCKAIRN2YPfqqY9a8nRK346bIxrHf0dbjbAuoueyi9EA+a3MSfsbtfFu4ThAP M+mjHMK/K25SCHKuQVWu/aiAtmHrSLjTk8C1ox5DPrq2aoQFc+sIEhcmi2zqi3n0j5 6EXLjhR5vJzGXFy2HZAW9xBxK4j9m0h3AKx3W/z7jU9WfBvbdws3I3o7RMIhJg1kzo nPk2jgEZC7COeB2utfEUG/A1KrXePFXfHNU0eWMeG0Kw7VqA51UP4nlee3YkTs9TA5 LOVV0WMLlfl7w== 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: [PATCH v5 02/38] ArmPkg/ArmMmuLib ARM: Split off XN page descriptor bit from type field Date: Mon, 13 Mar 2023 18:16:38 +0100 Message-Id: <20230313171714.3866151-3-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable With large page support out of the picture, we can treat bits 1 and 0 of the page descriptor as individual valid and XN bits, instead of treating XN as a page type. Doing so aligns the handling of the attribute with the section descriptor layout, as well as the XN handling on AArch64, and this is beneficial for maintainability. Signed-off-by: Ard Biesheuvel --- ArmPkg/Include/Chipset/ArmV7Mmu.h | 8 +++----- ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ArmPkg/Include/Chipset/ArmV7Mmu.h b/ArmPkg/Include/Chipset/Arm= V7Mmu.h index 7501ebfdf97f..6a2584ceb303 100644 --- a/ArmPkg/Include/Chipset/ArmV7Mmu.h +++ b/ArmPkg/Include/Chipset/ArmV7Mmu.h @@ -54,11 +54,9 @@ #define TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Desc) (((Desc) & 3UL) = =3D=3D TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE)=0D =0D // Translation table descriptor types=0D -#define TT_DESCRIPTOR_PAGE_TYPE_MASK (3UL << 0)=0D -#define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 0)=0D -#define TT_DESCRIPTOR_PAGE_TYPE_PAGE (2UL << 0)=0D -#define TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN (3UL << 0)=0D -#define TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE (1UL << 0)=0D +#define TT_DESCRIPTOR_PAGE_TYPE_MASK (1UL << 1)=0D +#define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 1)=0D +#define TT_DESCRIPTOR_PAGE_TYPE_PAGE (1UL << 1)=0D =0D // Section descriptor definitions=0D #define TT_DESCRIPTOR_SECTION_SIZE (0x00100000)=0D diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c b/ArmPkg/Librar= y/ArmMmuLib/Arm/ArmMmuLibUpdate.c index 9ca00c976d5f..12d0f4c30f8e 100644 --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c @@ -104,12 +104,8 @@ UpdatePageEntries ( =0D // EntryMask: bitmask of values to change (1 =3D change this value, 0 = =3D leave alone)=0D // EntryValue: values at bit positions specified by EntryMask=0D - EntryMask =3D TT_DESCRIPTOR_PAGE_TYPE_MASK | TT_DESCRIPTOR_PAGE_AP_MASK;= =0D - if ((Attributes & EFI_MEMORY_XP) !=3D 0) {=0D - EntryValue =3D TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN;=0D - } else {=0D - EntryValue =3D TT_DESCRIPTOR_PAGE_TYPE_PAGE;=0D - }=0D + EntryMask =3D TT_DESCRIPTOR_PAGE_TYPE_MASK | TT_DESCRIPTOR_PAGE_AP_MASK = | TT_DESCRIPTOR_PAGE_XN_MASK;=0D + EntryValue =3D TT_DESCRIPTOR_PAGE_TYPE_PAGE;=0D =0D // Although the PI spec is unclear on this, the GCD guarantees that only= =0D // one Attribute bit is set at a time, so the order of the conditionals = below=0D @@ -148,6 +144,10 @@ UpdatePageEntries ( EntryValue |=3D TT_DESCRIPTOR_PAGE_AP_RW_RW;=0D }=0D =0D + if ((Attributes & EFI_MEMORY_XP) !=3D 0) {=0D + EntryValue |=3D TT_DESCRIPTOR_PAGE_XN_MASK;=0D + }=0D +=0D // Obtain page table base=0D FirstLevelTable =3D (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress= ();=0D =0D --=20 2.39.2