From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.13754.1684874180750142495 for ; Tue, 23 May 2023 13:36:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=r5jo66+P; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: osde@linux.microsoft.com) Received: from OSD-Desktop.redmond.corp.microsoft.com (unknown [131.107.1.171]) by linux.microsoft.com (Postfix) with ESMTPSA id 4A55820FB9E3; Tue, 23 May 2023 13:36:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4A55820FB9E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1684874180; bh=DRV6ZNUxJWRuAA6F+EgwLII12BtI/9H7/C2kSSqBnsM=; h=From:To:Cc:Subject:Date:From; b=r5jo66+P+rMzMM8HEpdc9vAYf0Pv00rCNpdBOvMg6wLHY+aEiFlxRF1MbjYBWjshL SEUD861hthUCiyW/FUkBk8KFaHmRs7IEfXesfnAHU/h/L/SEao9SAl+v+C7KCliwf0 FVoVXA8I+vlgfoOrEJskMGBCVuyqvcOLlBAKKjX4= From: "Oliver Smith-Denny" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Taylor Beebe , Michael Kubacki , Sean Brogan Subject: [edk2-devel][PATCH v1 1/1] ArmPkg: CpuDxe: Report AARCH64 Memory Protections Attributes To GCD Date: Tue, 23 May 2023 13:36:23 -0700 Message-Id: <20230523203623.2387-1-osde@linux.microsoft.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable When the AARCH64 CpuDxe attempts to SyncCacheConfig() with the GCD, it collects the page attributes as: EntryAttribute =3D Entry & TT_ATTR_INDX_MASK However, TT_ATTR_INDX_MASK only masks the cacheability attributes and drops the memory protections attributes. Importantly, it also drops the TT_AF (access flag) which is now wired up in EDK2 to represent EFI_MEMORY_RP, so by default all SystemMem pages will report as EFI_MEMORY_RP to the GCD. The GCD currently drops that silently, because the Capabilities field in the GCD does not support EFI_MEMORY_RP by default. However, some ranges may support EFI_MEMORY_RP and incorrectly mark those ranges as read protected. In conjunction with another change on the mailing list (see: https://edk2.groups.io/g/devel/topic/98505340#:~:text=3DThis%20patch%20fo= llows%20the%20UefiCpuPkg%20pattern%20and%20adds%3D0D,between%20the%20GCD%= 20and%20the%20page%20table.%3D0D%20%3D0D), this causes an access flag fault incorrectly. See the linked BZ below for full details. This patch exposes all memory protections attributes to the GCD layer so it can correctly set pages as EFI_MEMORY[RP|XP|RO] when it initially syncs. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4463 Personal GitHub PR: https://github.com/tianocore/edk2/pull/4423 Github branch: https://github.com/os-d/edk2/tree/aarch64_report_af_v1 Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Taylor Beebe Cc: Michael Kubacki Cc: Sean Brogan Signed-off-by: Oliver Smith-Denny --- ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/= AArch64/Mmu.c index 0859c7418a1f..1d02e41e18d8 100644 --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c @@ -120,7 +120,7 @@ GetFirstPageAttribute ( } else if (((FirstEntry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY) || ((TableLevel =3D=3D 3) && ((FirstEntry & TT_TYPE_MASK) =3D=3D= TT_TYPE_BLOCK_ENTRY_LEVEL3))) { - return FirstEntry & TT_ATTR_INDX_MASK; + return FirstEntry & TT_ATTRIBUTES_MASK; } else { return INVALID_ENTRY; } @@ -158,7 +158,7 @@ GetNextEntryAttribute ( for (Index =3D 0; Index < EntryCount; Index++) { Entry =3D TableAddress[Index]; EntryType =3D Entry & TT_TYPE_MASK; - EntryAttribute =3D Entry & TT_ATTR_INDX_MASK; + EntryAttribute =3D Entry & TT_ATTRIBUTES_MASK; =20 // If Entry is a Table Descriptor type entry then go through the sub= -level table if ((EntryType =3D=3D TT_TYPE_BLOCK_ENTRY) || --=20 2.40.1