From nobody Fri May 17 22:27:07 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+91035+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+91035+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957195; cv=none; d=zohomail.com; s=zohoarc; b=Rf/pwuH6Rtd6kMFE9+jA08wkW/U+yGrCYXMUyo50KayMp/kD/Io0dWq9/zQP+j0mPGI8n9tQQqvPWt7C1lWQQAU1yW35t6zQnWXdaA/fZQtA3tlSdCJcz0u0tpNnhKbj9qmmDea6erRbSjHpletcp+hTE8gUkC9aoF/Mia1x/po= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957195; 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=AhRNw/Td74gR+EDVxWgnY6v08r9ijT6njAtQ3jwWcqg=; b=nsr7U93rhKCpRd4d4+EcdOt6LarE/8Xs49HZAcTtWQclXIabbqYIh+dCC11hVPWkJ9KrSm4tVYg7P8pVcx3/xJoeyV8La7WJN5TEUGBdGVululE1E/YKKRLJ/00Gowx8fR/yY1aWjdYpFexMkRruyYM6168manbE2/EvEqGCC80= 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+91035+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 1656957195531773.0526511468381; Mon, 4 Jul 2022 10:53:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 24jwYY1788612x0oRVzOlYdZ; Mon, 04 Jul 2022 10:53:14 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.74762.1656957193825092966 for ; Mon, 04 Jul 2022 10:53:14 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 116EB6152C; Mon, 4 Jul 2022 17:53:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 156F6C341CE; Mon, 4 Jul 2022 17:53:10 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 1/7] ArmPkg/ArmMmuLib: don't replace table entries with block entries Date: Mon, 4 Jul 2022 19:52:46 +0200 Message-Id: <20220704175252.4015120-2-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: sdrnEkp2BX703WY4aXNXAq1sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957194; bh=4IvDdgFLuV7RyYEnj3uYRtq+5cnR1UpsE7RhsUaluoY=; h=Cc:Date:From:Reply-To:Subject:To; b=UhBq6kOwxCfHbOpIGJAcGvlEosz2R5u830OHgzx/ZYsaP37M7OKohujqU65lO4ieysA bYlKoQqMFao9wJ2QLQ2nQrL6gnSPmpTtLe+3jwZrODALNuUu3ZxMeXBFxGIIfcJzDq0fQ 85fOyQf0PDmXnNXHAoVT75J8UDlSlOYc1Tw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957196909100001 Content-Type: text/plain; charset="utf-8" Drop the optimization that replaces table entries with block entries and frees the page tables in the subhierarchy that is being replaced. This rarely occurs in practice anyway, and will require more elaborate TLB maintenance once we switch to a different approach when running at EL1, where we no longer disable the MMU and nuke the TLB entirely every time we update a descriptor in a way that requires break-before-make (BBM). Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index 4a0513392a75..b85ae5a30768 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -197,12 +197,9 @@ UpdateRegionMappingRecursive ( // than a block, and recurse to create the block or page entries at // the next level. No block mappings are allowed at all at level 0, // so in that case, we have to recurse unconditionally. - // If we are changing a table entry and the AttributeClearMask is non-= zero, - // we cannot replace it with a block entry without potentially losing - // attribute information, so keep the table entry in that case. // if ((Level =3D=3D 0) || (((RegionStart | BlockEnd) & BlockMask) !=3D 0= ) || - (IsTableEntry (*Entry, Level) && (AttributeClearMask !=3D 0))) + IsTableEntry (*Entry, Level)) { ASSERT (Level < 3); =20 @@ -294,20 +291,7 @@ UpdateRegionMappingRecursive ( EntryValue |=3D (Level =3D=3D 3) ? TT_TYPE_BLOCK_ENTRY_LEVEL3 : TT_TYPE_BLOCK_ENTRY; =20 - if (IsTableEntry (*Entry, Level)) { - // - // We are replacing a table entry with a block entry. This is only - // possible if we are keeping none of the original attributes. - // We can free the table entry's page table, and all the ones below - // it, since we are dropping the only possible reference to it. - // - ASSERT (AttributeClearMask =3D=3D 0); - TranslationTable =3D (VOID *)(UINTN)(*Entry & TT_ADDRESS_MASK_BLOC= K_ENTRY); - ReplaceTableEntry (Entry, EntryValue, RegionStart, TRUE); - FreePageTablesRecursive (TranslationTable, Level + 1); - } else { - ReplaceTableEntry (Entry, EntryValue, RegionStart, FALSE); - } + ReplaceTableEntry (Entry, EntryValue, RegionStart, FALSE); } } =20 --=20 2.35.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 (#91035): https://edk2.groups.io/g/devel/message/91035 Mute This Topic: https://groups.io/mt/92170201/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- From nobody Fri May 17 22:27:07 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+91037+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+91037+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957196; cv=none; d=zohomail.com; s=zohoarc; b=QzMtUEJSb+CAAD8STi4NUEGE/nveeSRi/B3QxUfW0YEB6nrgQwOniHT6Iiuo97YHp+ewU/0jntHXV+SzzEiORpD6DDccYEEKcvPSKpHciFQHFRH5JcEn2KHsrAizDfAsESCi/420DpTq/TYFefQ6Pu+HJG9dhqPNKyk2nKReV7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957196; 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=7+vtazuA6Dc4rNvbeRmLvggZ5yqdJKjV4Kjko5ABp8o=; b=Rj1+esETalRCvfR2/cBmvhOSflNBDLmIYZzA6uiLC34Guj1arL4A3nigw1sOU63GKKHdVch2I6IpMyl/FYWlKJa9l3ALxdsZmO37pXPR6Bugz0xFvztYh8krPIDXuSOAvSi5teCmUw4+jom6DnWVWOTytsICDvWVIOzixLaKKY4= 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+91037+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 1656957196670513.2398192143596; Mon, 4 Jul 2022 10:53:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TR0kYY1788612xbFpQmHeo0O; Mon, 04 Jul 2022 10:53:16 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.74763.1656957195536778091 for ; Mon, 04 Jul 2022 10:53:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D4928615F6; Mon, 4 Jul 2022 17:53:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9A19C341CB; Mon, 4 Jul 2022 17:53:12 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 2/7] ArmPkg/ArmMmuLib: use shadow page tables for break-before-make at EL1 Date: Mon, 4 Jul 2022 19:52:47 +0200 Message-Id: <20220704175252.4015120-3-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: w4C1bj4fHjep7nBTbDnmZiCCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957196; bh=CFccgsmtRyDoyvnlHq5G4HkZnZZl0LL34bBsNFBuD4w=; h=Cc:Date:From:Reply-To:Subject:To; b=vgKN3GBmLzjTucNHkmmvmPs/gu/SRvhOYN3002C9b4T7Rl6V538MMjkC2Q+9Die0tO+ KZtutDZHZ9mRuc+s6QUwpLTe0t8XrIMH1LiDhpSg0fMzmxxT+igWz68L2KDpM93KgCehQ szP6y5RNawaI/MiVWyPYfrovgpu7R0Kc5Fw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957196959100003 Content-Type: text/plain; charset="utf-8" When executing at EL1, disabling and re-enabling the MMU every time we need to replace a live translation entry is slightly problematic, given that memory accesses performed with the MMU off have non-cacheable attributes and are therefore non-coherent. On bare metal, we can deal with this by adding some barriers and cache invalidation instructions, but when running under virtualization, elaborate trapping and cache maintenance logic is necessary on the part of the hypervisor, and this is better avoided. So let's switch to a different approach when running at EL1, and use two sets of page tables with different ASIDs, and non-global attributes for all mappings. This allows us to switch between those sets without having to care about break-before-make, which means we can manipulate the primary translation while running from the secondary. To avoid splitting block mappings unnecessarily in the shadow page tables, add a special case to the recursive mapping routines to retain a block mapping that already covers a region that we are trying to map, and has the right attributes. Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 3 + ArmPkg/Include/Chipset/AArch64Mmu.h | 1 + ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 112 +++++++++++= +++------ ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S | 15 ++- 4 files changed, 96 insertions(+), 35 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AA= rch64/Mmu.c index 8bb33046e707..1ccd9f7fece8 100644 --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c @@ -313,6 +313,9 @@ EfiAttributeToArmAttribute ( ArmAttributes |=3D TT_PXN_MASK; } =20 + if (ArmReadCurrentEL () =3D=3D AARCH64_EL1) { + ArmAttributes |=3D TT_NG; + } return ArmAttributes; } =20 diff --git a/ArmPkg/Include/Chipset/AArch64Mmu.h b/ArmPkg/Include/Chipset/A= Arch64Mmu.h index 2ea2cc0a874d..763dc53908e2 100644 --- a/ArmPkg/Include/Chipset/AArch64Mmu.h +++ b/ArmPkg/Include/Chipset/AArch64Mmu.h @@ -67,6 +67,7 @@ =20 #define TT_NS BIT5 #define TT_AF BIT10 +#define TT_NG BIT11 =20 #define TT_SH_NON_SHAREABLE (0x0 << 8) #define TT_SH_OUTER_SHAREABLE (0x2 << 8) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index b85ae5a30768..d5c19600dce8 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -25,23 +25,31 @@ ArmMemoryAttributeToPageAttribute ( IN ARM_MEMORY_REGION_ATTRIBUTES Attributes ) { + UINT64 NonGlobal; + + if (ArmReadCurrentEL () =3D=3D AARCH64_EL1) { + NonGlobal =3D TT_NG; + } else { + NonGlobal =3D 0; + } + switch (Attributes) { case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE: case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE: - return TT_ATTR_INDX_MEMORY_WRITE_BACK; + return TT_ATTR_INDX_MEMORY_WRITE_BACK | NonGlobal; =20 case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK: case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK: - return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE; + return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE | NonG= lobal; =20 case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH: case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH: - return TT_ATTR_INDX_MEMORY_WRITE_THROUGH | TT_SH_INNER_SHAREABLE; + return TT_ATTR_INDX_MEMORY_WRITE_THROUGH | TT_SH_INNER_SHAREABLE | N= onGlobal; =20 // Uncached and device mappings are treated as outer shareable by defa= ult, case ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED: case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED: - return TT_ATTR_INDX_MEMORY_NON_CACHEABLE; + return TT_ATTR_INDX_MEMORY_NON_CACHEABLE | NonGlobal; =20 default: ASSERT (0); @@ -50,7 +58,7 @@ ArmMemoryAttributeToPageAttribute ( if (ArmReadCurrentEL () =3D=3D AARCH64_EL2) { return TT_ATTR_INDX_DEVICE_MEMORY | TT_XN_MASK; } else { - return TT_ATTR_INDX_DEVICE_MEMORY | TT_UXN_MASK | TT_PXN_MASK; + return TT_ATTR_INDX_DEVICE_MEMORY | TT_UXN_MASK | TT_PXN_MASK | TT= _NG; } } } @@ -203,7 +211,13 @@ UpdateRegionMappingRecursive ( { ASSERT (Level < 3); =20 - if (!IsTableEntry (*Entry, Level)) { + if (IsBlockEntry (*Entry, Level) && AttributeClearMask =3D=3D 0 && + ((*Entry & TT_ATTRIBUTES_MASK) ^ AttributeSetMask) =3D=3D 0) { + // The existing block entry already covers the region we are + // trying to map with the correct attributes so no need to do + // anything here + continue; + } else if (!IsTableEntry (*Entry, Level)) { // // No table entry exists yet, so we need to allocate a page table // for the next level. @@ -304,7 +318,8 @@ UpdateRegionMapping ( IN UINT64 RegionStart, IN UINT64 RegionLength, IN UINT64 AttributeSetMask, - IN UINT64 AttributeClearMask + IN UINT64 AttributeClearMask, + IN UINT64 *RootTable ) { UINTN T0SZ; @@ -320,7 +335,7 @@ UpdateRegionMapping ( RegionStart + RegionLength, AttributeSetMask, AttributeClearMask, - ArmGetTTBR0BaseAddress (), + RootTable, GetRootTableLevel (T0SZ) ); } @@ -336,7 +351,7 @@ FillTranslationTable ( MemoryRegion->VirtualBase, MemoryRegion->Length, ArmMemoryAttributeToPageAttribute (MemoryRegion->Attributes) | = TT_AF, - 0 + 0, RootTable ); } =20 @@ -380,6 +395,10 @@ GcdAttributeToPageAttribute ( PageAttributes |=3D TT_AP_NO_RO; } =20 + if (ArmReadCurrentEL () =3D=3D AARCH64_EL1) { + PageAttributes |=3D TT_NG; + } + return PageAttributes | TT_AF; } =20 @@ -390,8 +409,9 @@ ArmSetMemoryAttributes ( IN UINT64 Attributes ) { - UINT64 PageAttributes; - UINT64 PageAttributeMask; + UINT64 PageAttributes; + UINT64 PageAttributeMask; + EFI_STATUS Status; =20 PageAttributes =3D GcdAttributeToPageAttribute (Attributes); PageAttributeMask =3D 0; @@ -404,13 +424,22 @@ ArmSetMemoryAttributes ( PageAttributes &=3D TT_AP_MASK | TT_UXN_MASK | TT_PXN_MASK; PageAttributeMask =3D ~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK | TT_PXN_MASK | TT_XN_MASK); + } else if (ArmReadCurrentEL () =3D=3D AARCH64_EL1) { + // Update the shadow page tables + Status =3D UpdateRegionMapping (BaseAddress, Length, + (PageAttributes & ~(TT_AP_MASK | TT_PXN_MASK | TT_UXN_MASK)= ) | TT_AP_NO_RW, + 0, ArmGetTTBR0BaseAddress () + EFI_PAGE_SIZE); + if (EFI_ERROR (Status)) { + return Status; + } } =20 return UpdateRegionMapping ( BaseAddress, Length, PageAttributes, - PageAttributeMask + PageAttributeMask, + ArmGetTTBR0BaseAddress () ); } =20 @@ -423,7 +452,8 @@ SetMemoryRegionAttribute ( IN UINT64 BlockEntryMask ) { - return UpdateRegionMapping (BaseAddress, Length, Attributes, BlockEntryM= ask); + return UpdateRegionMapping (BaseAddress, Length, Attributes, + BlockEntryMask, ArmGetTTBR0BaseAddress ()); } =20 EFI_STATUS @@ -503,13 +533,15 @@ ArmConfigureMmu ( OUT UINTN *TranslationTableSize OPTIONAL ) { - VOID *TranslationTable; - UINTN MaxAddressBits; - UINT64 MaxAddress; - UINTN T0SZ; - UINTN RootTableEntryCount; - UINT64 TCR; - EFI_STATUS Status; + UINT64 *TranslationTable; + UINTN MaxAddressBits; + UINT64 MaxAddress; + UINTN T0SZ; + UINTN RootTableEntryCount; + UINT64 TCR; + EFI_STATUS Status; + ARM_MEMORY_REGION_DESCRIPTOR *MemTab; + UINTN NumRootPages; =20 if (MemoryTable =3D=3D NULL) { ASSERT (MemoryTable !=3D NULL); @@ -538,6 +570,8 @@ ArmConfigureMmu ( // Note: Bits 23 and 31 are reserved(RES1) bits in TCR_EL2 TCR =3D T0SZ | (1UL << 31) | (1UL << 23) | TCR_TG0_4KB; =20 + NumRootPages =3D 1; + // Set the Physical Address Size using MaxAddress if (MaxAddress < SIZE_4GB) { TCR |=3D TCR_PS_4GB; @@ -564,6 +598,8 @@ ArmConfigureMmu ( // Due to Cortex-A57 erratum #822227 we must set TG1[1] =3D=3D 1, rega= rdless of EPD1. TCR =3D T0SZ | TCR_TG0_4KB | TCR_TG1_4KB | TCR_EPD1; =20 + NumRootPages =3D 2; + // Set the Physical Address Size using MaxAddress if (MaxAddress < SIZE_4GB) { TCR |=3D TCR_IPS_4GB; @@ -608,19 +644,11 @@ ArmConfigureMmu ( ArmSetTCR (TCR); =20 // Allocate pages for translation table - TranslationTable =3D AllocatePages (1); + TranslationTable =3D AllocatePages (NumRootPages); if (TranslationTable =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 - // - // We set TTBR0 just after allocating the table to retrieve its location= from - // the subsequent functions without needing to pass this value across the - // functions. The MMU is only enabled after the translation tables are - // populated. - // - ArmSetTTBR0 (TranslationTable); - if (TranslationTableBase !=3D NULL) { *TranslationTableBase =3D TranslationTable; } @@ -639,13 +667,11 @@ ArmConfigureMmu ( ); ZeroMem (TranslationTable, RootTableEntryCount * sizeof (UINT64)); =20 - while (MemoryTable->Length !=3D 0) { - Status =3D FillTranslationTable (TranslationTable, MemoryTable); + for (MemTab =3D MemoryTable; MemTab->Length !=3D 0; MemTab++) { + Status =3D FillTranslationTable (TranslationTable, MemTab); if (EFI_ERROR (Status)) { goto FreeTranslationTable; } - - MemoryTable++; } =20 // @@ -661,16 +687,34 @@ ArmConfigureMmu ( MAIR_ATTR (TT_ATTR_INDX_MEMORY_WRITE_BACK, MAIR_ATTR_NORMAL_MEMORY_WRI= TE_BACK) ); =20 + ArmSetTTBR0 (TranslationTable); + ArmDisableAlignmentCheck (); ArmEnableStackAlignmentCheck (); ArmEnableInstructionCache (); ArmEnableDataCache (); =20 ArmEnableMmu (); + + if (NumRootPages > 1) { + // + // Clone all memory ranges into the shadow page tables that we will use + // to temporarily switch to when manipulating live entries + // + ZeroMem (TranslationTable + TT_ENTRY_COUNT, + RootTableEntryCount * sizeof (UINT64)); + + for (MemTab =3D MemoryTable; MemTab->Length !=3D 0; MemTab++) { + Status =3D FillTranslationTable (TranslationTable + TT_ENTRY_COUNT, = MemTab); + if (EFI_ERROR (Status)) { + goto FreeTranslationTable; + } + } + } return EFI_SUCCESS; =20 FreeTranslationTable: - FreePages (TranslationTable, 1); + FreePages (TranslationTable, NumRootPages); return Status; } =20 diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S b/Arm= Pkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S index 66ebca571e63..6929e081ed8d 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S @@ -59,7 +59,20 @@ ASM_FUNC(ArmReplaceLiveTranslationEntry) dsb nsh =20 EL1_OR_EL2_OR_EL3(x3) -1:__replace_entry 1 +1:mrs x8, ttbr0_el1 + add x9, x8, #0x1000 // advance to shadow page table + orr x9, x9, #1 << 48 // use different ASID for shadow translatio= ns + msr ttbr0_el1, x9 + isb + str x1, [x0] // install the entry and make it observeable + dsb ishst // to the page table walker + isb + lsr x2, x2, #12 + tlbi vae1is, x2 // invalidate the updated entry + dsb ish + isb + msr ttbr0_el1, x8 // switch back to original translation + isb b 4f 2:__replace_entry 2 b 4f --=20 2.35.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 (#91037): https://edk2.groups.io/g/devel/message/91037 Mute This Topic: https://groups.io/mt/92170204/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- From nobody Fri May 17 22:27:07 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+91039+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+91039+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957201; cv=none; d=zohomail.com; s=zohoarc; b=C89LQyORDi8m//lyttTg4lZBlYEsoS5ir5dRzRzehHZIns8N9UoHEifx6PaW+cMpcuCu5a1k2V3k8gmfcMhgCWPauJ4cMnSZftHj5pkDArTknAxAfVUc0GXt/Q2X7T5vhQNOX7MLIRTNgcBZzrijFxiHJHLNbeaxn3R80Sln/rI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957201; 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=VpVS97aE5kkHJSq4eZgDDM22uBFiVJo1p6vf1sBV5TU=; b=bnNW9a20QZKoCRwGmNf6Io7b242CFfooT+FtO+cDjDgQ3W76baOjVFmBP/xdroCLC7+5WHIGSuFcciXHVu0M0U8K0SY5uoM7E2J4ZUHtY0ihRkfyNzFdKsEDK/qOjiCt+Vmm65fDwQdw6gjZJ6JQCS8r0ak7KZ+c7XcU8Y+u4Lw= 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+91039+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 1656957201095516.3755963619383; Mon, 4 Jul 2022 10:53:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id E7X6YY1788612x3Z79dpluWp; Mon, 04 Jul 2022 10:53:20 -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.74764.1656957198560435812 for ; Mon, 04 Jul 2022 10:53:18 -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 467EAB811EF; Mon, 4 Jul 2022 17:53:17 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA3DFC341CD; Mon, 4 Jul 2022 17:53:14 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 3/7] ArmPkg/ArmMmuLib: permit initial configuration with MMU enabled Date: Mon, 4 Jul 2022 19:52:48 +0200 Message-Id: <20220704175252.4015120-4-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: EXvH9DFXEx8hLqIB4nE1IPpMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957200; bh=DKPTwI4kvSMEX9ui+Vz1sTZzKQtBI4Ryo5z/QuQJdXs=; h=Cc:Date:From:Reply-To:Subject:To; b=ewnHuaWOlfe1I/ADG63WAkhbnGThFOJyUkznBqLEYco09BGXmZm8c1zi2Z02eMK1i0J zqR2i2RlyBLkU5KDv11g9GOifdxDbey5MiVJYW8475Ryh0VXRXOyB02sY/RFocm6aMRyy r1cN+9BbxEvEub5ToVzq9B0vO5yYirFSTkQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957202892100006 Content-Type: text/plain; charset="utf-8" Permit the use of this library with the MMU and caches already enabled. This removes the need for any cache maintenance for coherency, and is generally better for robustness and performance, especially when running under virtualization. Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index d5c19600dce8..8934ea6fd420 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -657,14 +657,16 @@ ArmConfigureMmu ( *TranslationTableSize =3D RootTableEntryCount * sizeof (UINT64); } =20 - // - // Make sure we are not inadvertently hitting in the caches - // when populating the page tables. - // - InvalidateDataCacheRange ( - TranslationTable, - RootTableEntryCount * sizeof (UINT64) - ); + if (!ArmMmuEnabled ()) { + // + // Make sure we are not inadvertently hitting in the caches + // when populating the page tables. + // + InvalidateDataCacheRange ( + TranslationTable, + RootTableEntryCount * sizeof (UINT64) + ); + } ZeroMem (TranslationTable, RootTableEntryCount * sizeof (UINT64)); =20 for (MemTab =3D MemoryTable; MemTab->Length !=3D 0; MemTab++) { @@ -689,12 +691,14 @@ ArmConfigureMmu ( =20 ArmSetTTBR0 (TranslationTable); =20 - ArmDisableAlignmentCheck (); - ArmEnableStackAlignmentCheck (); - ArmEnableInstructionCache (); - ArmEnableDataCache (); + if (!ArmMmuEnabled ()) { + ArmDisableAlignmentCheck (); + ArmEnableStackAlignmentCheck (); + ArmEnableInstructionCache (); + ArmEnableDataCache (); =20 - ArmEnableMmu (); + ArmEnableMmu (); + } =20 if (NumRootPages > 1) { // --=20 2.35.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 (#91039): https://edk2.groups.io/g/devel/message/91039 Mute This Topic: https://groups.io/mt/92170206/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- From nobody Fri May 17 22:27:07 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+91038+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+91038+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957200; cv=none; d=zohomail.com; s=zohoarc; b=BCzltVt2gY+olA7wZbl3xSHtoW4kuvbdKG0WM8uo6yUxARcFzN6fJE+46hiGwoG4DwckTGE5hTU5nspgKO2WVsKOp/2jEb1f+xqAHyTnvjNtmptLkVWf9gRVJLJu2cN7hnl67oiZ8iuOzIpewifXrfRPxraShBJOE5ITEjov/1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957200; 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=v6En44U89LdZJMBurLBI0tq3Tfi8P/2QSZcY+3Z3Fu0=; b=WjSvLAY1ZDmVPlepsPyyS6t4oOMB/9eEmIPRDsllHSwZmKlDdBkYb3nrmElpHfE4q743/MNRrpDSktrv+Z0ZFwjiIlMqwXzD39MY1U9T2J8fbaGKPtAHI6/4mt8zOrJc5Bp/8/xDH+o55KMiP2ZxZZ4ar+Ft/BconV0GuRt0r7Q= 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+91038+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 165695720097962.37146919882332; Mon, 4 Jul 2022 10:53:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tctHYY1788612xOaPs5rIVRf; Mon, 04 Jul 2022 10:53:19 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.75328.1656957198518255551 for ; Mon, 04 Jul 2022 10:53:18 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 10825615F4; Mon, 4 Jul 2022 17:53:18 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AB22C341CB; Mon, 4 Jul 2022 17:53:16 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 4/7] ArmPlatformPkg/PrePeiCore: permit entry with the MMU enabled Date: Mon, 4 Jul 2022 19:52:49 +0200 Message-Id: <20220704175252.4015120-5-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: hFEEnaAA603Ubl45oSHeZwmQx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957199; bh=oHNA45857vpevsSKhRsHuqqtIBabnSfDB1JHKjJVUMM=; h=Cc:Date:From:Reply-To:Subject:To; b=H1TDY+qFyP5F+RzvCtrPdbS9t9FV01pjqIgYcnshnDPA16UkRhcsziq/kJ9U4lM+8Fk bHBtlzF4dLbmh4EjXRc5JwcwiUTMF93JQXLymoN4CmaK7tpBm904/0/puk+mKPE4zA2v8 zE4AM+Rbt0mHmsByRMLqozxbXjJ49MyucpY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957202888100005 Content-Type: text/plain; charset="utf-8" Some platforms may set up a preliminary ID map in flash and enter EFI with the MMU and caches enabled, as this removes a lot of the complexity around cache coherency. Let's take this into account, and avoid touching the MMU controls or perform cache invalidation when the MMU is enabled at entry. Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/PrePeiCore/PrePeiCore.c | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ArmPlatformPkg/PrePeiCore/PrePeiCore.c b/ArmPlatformPkg/PrePei= Core/PrePeiCore.c index 6dd9bcdea24f..d56918365f71 100644 --- a/ArmPlatformPkg/PrePeiCore/PrePeiCore.c +++ b/ArmPlatformPkg/PrePeiCore/PrePeiCore.c @@ -58,17 +58,19 @@ CEntryPoint ( IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint ) { - // Data Cache enabled on Primary core when MMU is enabled. - ArmDisableDataCache (); - // Invalidate instruction cache - ArmInvalidateInstructionCache (); - // Enable Instruction Caches on all cores. - ArmEnableInstructionCache (); + if (!ArmMmuEnabled ()) { + // Data Cache enabled on Primary core when MMU is enabled. + ArmDisableDataCache (); + // Invalidate instruction cache + ArmInvalidateInstructionCache (); + // Enable Instruction Caches on all cores. + ArmEnableInstructionCache (); =20 - InvalidateDataCacheRange ( - (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase), - PcdGet32 (PcdCPUCorePrimaryStackSize) - ); + InvalidateDataCacheRange ( + (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase), + PcdGet32 (PcdCPUCorePrimaryStackSize) + ); + } =20 // // Note: Doesn't have to Enable CPU interface in non-secure world, --=20 2.35.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 (#91038): https://edk2.groups.io/g/devel/message/91038 Mute This Topic: https://groups.io/mt/92170205/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- From nobody Fri May 17 22:27:07 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+91040+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+91040+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957203; cv=none; d=zohomail.com; s=zohoarc; b=Fd2q0yG/ecmCXCurWzCl6cbwbqOFgpuINvgRzR6dONCh0TrqvveiJLRVE+OpvwoNlQp1HukPYhtfH40U/bLTKloOpiEOVCGzr7si5lMTiMZxDh5cSvbCyljgFD2o662dCiqDfpRuvQHZc8nAf28+JutPSxjHSAWbhlQKieG/Fy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957203; 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=oVT0dKktYDHjy84VD+qf4nv92Rgqj/F3fWn2TYn+sIw=; b=JhgCmGb7j010DEv5RjoVI0M1W0eFRdXoHWOkjJbq6PmYemerQeQQUzoT72uA1GlmrMnQ2QmRvo+YSMNfErhV9WStvmPUfk/ew+vnQXlwocUNj3Pf8J2jN+oHFQewXbiiSqZDGxIFqMt1u8FyQfaW+W2WUqcCnlFCXfrf7k6KSnQ= 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+91040+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 1656957203640337.2988166840503; Mon, 4 Jul 2022 10:53:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RSnfYY1788612x6XWMNLFFlR; Mon, 04 Jul 2022 10:53:22 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web08.75037.1656957201602219395 for ; Mon, 04 Jul 2022 10:53:22 -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 00552B811F8; Mon, 4 Jul 2022 17:53:20 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B812C341CB; Mon, 4 Jul 2022 17:53:18 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 5/7] ArmVirtPkg/ArmVirtQemu: implement ArmPlatformLib with static ID map Date: Mon, 4 Jul 2022 19:52:50 +0200 Message-Id: <20220704175252.4015120-6-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: Ojezkddt6I19cNygM0sg4uKcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957202; bh=P/fmUzozSF3xb9xcycnPFf+Wr6TZQ0lgB1sjSdprLN8=; h=Cc:Date:From:Reply-To:Subject:To; b=KUP3cfj+mgMgK1UGSxhu7fe61QlHPL60+xaGMzmGXrz3avFY0eD+nvbTrK+0HXNu40I TvyfeYJoVYCChgL4ysvE2ZK5bLyGO/fT/y6UM3HwtaJxeRoa+/byq+dozDjmerZNPXEAd SBbky69BEhOT4WAwcAFF3/h0bgHiPPIChA8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957205034100009 Content-Type: text/plain; charset="utf-8" To substantially reduce the amount of processing that takes place with the MMU and caches off, implemnt a version of ArmPlatformLib specific for QEMU/mach-virt in AArch64 mode that carries a statically allocated and populated ID map that covers the NOR flash and device region, and 128 MiB of DRAM at the base of memory (0x4000_0000). Note that 128 MiB has always been the minimum amount of DRAM we support for this configuration, and the existing code already ASSERT()s in DEBUG mode when booting with less. Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S | 111 ++= ++++++++++++++++++ ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.c | 36 ++= +++++ ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.inf | 36 ++= +++++ ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S | 57 ++= ++++++++ 4 files changed, 240 insertions(+) diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelpe= r.S b/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S new file mode 100644 index 000000000000..7b78e2928710 --- /dev/null +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S @@ -0,0 +1,111 @@ +// +// Copyright (c) 2022, Google LLC. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// + +#include + + .macro mov_i, reg:req, imm:req + movz \reg, :abs_g3:\imm + movk \reg, :abs_g2_nc:\imm + movk \reg, :abs_g1_nc:\imm + movk \reg, :abs_g0_nc:\imm + .endm + + .set MAIR_DEV_nGnRnE, 0x00 + .set MAIR_MEM_NC, 0x44 + .set MAIR_MEM_WT, 0xbb + .set MAIR_MEM_WBWA, 0xff + .set mairval, MAIR_DEV_nGnRnE | (MAIR_MEM_NC << 8) | (MAIR_MEM_WT << 1= 6) | (MAIR_MEM_WBWA << 24) + + .set TCR_TG0_4KB, 0x0 << 14 + .set TCR_TG1_4KB, 0x2 << 30 + .set TCR_IPS_SHIFT, 32 + .set TCR_EPD1, 0x1 << 23 + .set TCR_SH_INNER, 0x3 << 12 + .set TCR_RGN_OWB, 0x1 << 10 + .set TCR_RGN_IWB, 0x1 << 8 + .set tcrval, TCR_TG0_4KB | TCR_TG1_4KB | TCR_EPD1 | TCR_RGN_OWB + .set tcrval, tcrval | TCR_RGN_IWB | TCR_SH_INNER + + .set SCTLR_ELx_I, 0x1 << 12 + .set SCTLR_ELx_SA, 0x1 << 3 + .set SCTLR_ELx_C, 0x1 << 2 + .set SCTLR_ELx_M, 0x1 << 0 + .set SCTLR_EL1_SPAN, 0x1 << 23 + .set SCTLR_EL1_WXN, 0x1 << 19 + .set SCTLR_EL1_SED, 0x1 << 8 + .set SCTLR_EL1_ITD, 0x1 << 7 + .set SCTLR_EL1_RES1, (0x1 << 11) | (0x1 << 20) | (0x1 << 22) | (0= x1 << 28) | (0x1 << 29) + .set sctlrval, SCTLR_ELx_M | SCTLR_ELx_C | SCTLR_ELx_SA | SCTLR_EL1_IT= D | SCTLR_EL1_SED + .set sctlrval, sctlrval | SCTLR_ELx_I | SCTLR_EL1_SPAN | SCTLR_EL1_RES1 + + +ASM_FUNC(ArmPlatformPeiBootAction) + mov_i x0, mairval + mov_i x1, tcrval + adrp x2, idmap + orr x2, x2, #0xff << 48 // set non-zero ASID + mov_i x3, sctlrval + + mrs x6, id_aa64mmfr0_el1 // get the supported PA range + and x6, x6, #0xf // isolate PArange bits + cmp x6, #6 // 0b0110 =3D=3D 52 bits + sub x6, x6, #1 // subtract 1 + cinc x6, x6, ne // add back 1 unless PArange =3D=3D 52 bi= ts + bfi x1, x6, #32, #3 // copy updated PArange into TCR_EL1.IPS + + cmp x6, #3 // 0b0011 =3D=3D 42 bits + sub x6, x6, #1 // subtract 1 + cinc x6, x6, lt // add back 1 unless VA range >=3D 42 + + mov x7, #32 + sub x6, x7, x6, lsl #2 // T0SZ for PArange !=3D 42 + mov x7, #64 - 42 // T0SZ for PArange =3D=3D 42 + csel x6, x6, x7, ne + orr x1, x1, x6 // set T0SZ field in TCR + + cmp x6, #64 - 40 // VA size < 40 bits? + add x4, x2, #0x1000 // advance to level 1 descriptor + csel x2, x4, x2, gt + + msr mair_el1, x0 // set up the 1:1 mapping + msr tcr_el1, x1 + msr ttbr0_el1, x2 + isb + + tlbi vmalle1 // invalidate any cached translations + ic iallu // invalidate the I-cache + dsb nsh + isb + + msr sctlr_el1, x3 // enable MMU and caches + isb + ret + +//UINTN +//ArmPlatformGetCorePosition ( +// IN UINTN MpId +// ); +// With this function: CorePos =3D (ClusterId * 4) + CoreId +ASM_FUNC(ArmPlatformGetCorePosition) + mov x0, xzr + ret + +//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_FUNC(ArmPlatformGetPrimaryCoreMpId) + MOV32 (w0, FixedPcdGet32 (PcdArmPrimaryCore)) + ret + +//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_FUNC(ArmPlatformIsPrimaryCore) + mov x0, #1 + ret diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.c b/A= rmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.c new file mode 100644 index 000000000000..4a5ea82ef5e2 --- /dev/null +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.c @@ -0,0 +1,36 @@ +/** @file + + Copyright (c) 2011-2012, ARM Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +EFI_BOOT_MODE +ArmPlatformGetBootMode ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +RETURN_STATUS +ArmPlatformInitialize ( + IN UINTN MpId + ) +{ + return RETURN_SUCCESS; +} + +VOID +ArmPlatformGetPlatformPpiList ( + OUT UINTN *PpiListSize, + OUT EFI_PEI_PPI_DESCRIPTOR **PpiList + ) +{ + *PpiListSize =3D 0; + *PpiList =3D NULL; +} diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.inf b= /ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.inf new file mode 100644 index 000000000000..d2eaa6be6586 --- /dev/null +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.inf @@ -0,0 +1,36 @@ +#/* @file +# Copyright (c) 2011-2012, ARM Limited. All rights reserved. +# Copyright (c) 2022, Google LLC. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#*/ + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D ArmPlatformLibQemu + FILE_GUID =3D 40af3a25-f02c-4aef-94ef-7ac0282d21d4 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmPlatformLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[LibraryClasses] + ArmLib + DebugLib + +[Sources.common] + ArmPlatformLibQemu.c + IdMap.S + +[Sources.AArch64] + AArch64/ArmPlatformHelper.S + +[FixedPcd] + gArmTokenSpaceGuid.PcdArmPrimaryCoreMask + gArmTokenSpaceGuid.PcdArmPrimaryCore diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S b/ArmVirtPkg/Lib= rary/ArmPlatformLibQemu/IdMap.S new file mode 100644 index 000000000000..9c174bb81dc2 --- /dev/null +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: BSD-2-Clause-Patent +// Copyright 2022 Google LLC +// Author: Ard Biesheuvel + + .set TT_TYPE_BLOCK, 0x1 + .set TT_TYPE_PAGE, 0x3 + .set TT_TYPE_TABLE, 0x3 + + .set TT_AF, 0x1 << 10 + .set TT_NG, 0x1 << 11 + .set TT_RO, 0x2 << 6 + .set TT_XN, 0x3 << 53 + + .set TT_MT_DEV, 0x0 << 2 // MAIR #0 + .set TT_MT_MEM, (0x3 << 2) | (0x3 << 8) // MAIR #3 + + .set PAGE_XIP, TT_TYPE_PAGE | TT_MT_MEM | TT_AF | TT_R= O | TT_NG + .set BLOCK_DEV, TT_TYPE_BLOCK | TT_MT_DEV | TT_AF | TT_X= N | TT_NG + .set BLOCK_MEM, TT_TYPE_BLOCK | TT_MT_MEM | TT_AF | TT_X= N | TT_NG + + .globl idmap + .section ".rodata.idmap", "a", %progbits + .align 12 + + /* level 0 */ +idmap: .quad 1f + TT_TYPE_TABLE + .fill 511, 8, 0x0 + + /* level 1 */ +1: .quad 20f + TT_TYPE_TABLE // 1 GB of flash an= d device mappings + .quad 21f + TT_TYPE_TABLE // up to 1 GB of DR= AM + .fill 510, 8, 0x0 // 510 GB of remain= ing VA space + + /* level 2 */ +20: .quad 3f + TT_TYPE_TABLE // up to 2 MB of fl= ash + .fill 63, 8, 0x0 // 126 MB of unused= flash + .set idx, 64 + .rept 448 + .quad BLOCK_DEV | (idx << 21) // 896 MB of RW- de= vice mappings + .set idx, idx + 1 + .endr + + /* level 2 */ +21: .set idx, 0x40000000 >> 21 + .rept 64 + .quad BLOCK_MEM | (idx << 21) // 128 MB of RW- me= mory mappings + .set idx, idx + 1 + .endr + .fill 448, 8, 0x0 + + /* level 3 */ +3: .quad 0x0 // omit first 4k pa= ge + .set idx, 1 + .rept 511 + .quad PAGE_XIP | (idx << 12) // 2044 KiB of R-X = flash mappings + .set idx, idx + 1 + .endr --=20 2.35.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 (#91040): https://edk2.groups.io/g/devel/message/91040 Mute This Topic: https://groups.io/mt/92170209/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- From nobody Fri May 17 22:27:07 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+91041+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+91041+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957205; cv=none; d=zohomail.com; s=zohoarc; b=GYiPWqv+k0cevS4ARmldVdpsVOVvFDvlPve1GIJYDyiNR87lNC9gY9YbbhjdzMRjGMd7pYG4twKU3EHESnvMhxyXlDEs8jaUFWTCvpYPZeFksd1DPq7JXZWU9LpqauWm5iDls5cilEj5LYrm9odrqVxT6eTc06pS4c8N/zjMgtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957205; 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=0oLb95uful7jy6lE3v24OsODcxBv5f874xelS7P7Np4=; b=YU3eVF2TfCmfqG1jeb+xPhIyhiiCrHnKMJnAigd+rMT0XhRv9pZNMFnjeF4dtWG86WLfwPf8f7QCNe3Pk+KtwogywetKB8TpIZRunDd7oHEdw8n380WDUf7pIqkx/wBrZ+JeR5s04eOyhayiWm8YL/QhvED8IUcKmL9zbfHjCps= 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+91041+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 1656957205414603.1356212809213; Mon, 4 Jul 2022 10:53:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KiMpYY1788612x77SO2bbCY2; Mon, 04 Jul 2022 10:53:24 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.75329.1656957203238433270 for ; Mon, 04 Jul 2022 10:53:23 -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 C1A36B81187; Mon, 4 Jul 2022 17:53:21 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BCE9C341D1; Mon, 4 Jul 2022 17:53:19 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 6/7] ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory Date: Mon, 4 Jul 2022 19:52:51 +0200 Message-Id: <20220704175252.4015120-7-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: 1OwdnVr8rnl9qXbwNeWR5umlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957204; bh=Tr/pcXYL46m/eRvTWTOTE49OhtR9WYONnDev9h0fmf4=; h=Cc:Date:From:Reply-To:Subject:To; b=RXxuBOKCGb2JBzed3v3CTGW1J9gyL8W3K/dXJJkLbOS4seGvCpBx8PlRR4aIoPWBOSP ZKQAU45T228wMlnA/U7d6IHB+hdCadUjdEcyHptIh35ncCderRv0bAfJSRwxrKjUXLWEz jks974vzqaKbBaI1T82FJjeUwpOcIGYYPl4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957206930100014 Content-Type: text/plain; charset="utf-8" In order to allow booting with the MMU and caches enabled really early, we need to ensure that the code that populates the page tables can access those page tables with the statically defined ID map active. So let's put the permanent PEI RAM in the first 128 MiB of memory, which we will cover with this initial ID map (as it is the minimum supported DRAM size for ArmVirtQemu). Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c | 89 ++++++++++++++++++++ ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 66 +++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c b/ArmVirtPkg/MemoryI= nitPei/MemoryInitPeim.c new file mode 100644 index 000000000000..a48830396e48 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c @@ -0,0 +1,89 @@ +/** @file + + Copyright (c) 2011, ARM Limited. All rights reserved. + Copyright (c) 2022, Google LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +MemoryPeim ( + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + IN UINT64 UefiMemorySize + ); + +VOID +EFIAPI +BuildMemoryTypeInformationHob ( + VOID + ) +{ + EFI_MEMORY_TYPE_INFORMATION Info[10]; + + Info[0].Type =3D EfiACPIReclaimMemory; + Info[0].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory); + Info[1].Type =3D EfiACPIMemoryNVS; + Info[1].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS); + Info[2].Type =3D EfiReservedMemoryType; + Info[2].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiReservedMemoryType); + Info[3].Type =3D EfiRuntimeServicesData; + Info[3].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData); + Info[4].Type =3D EfiRuntimeServicesCode; + Info[4].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode); + Info[5].Type =3D EfiBootServicesCode; + Info[5].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesCode); + Info[6].Type =3D EfiBootServicesData; + Info[6].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesData); + Info[7].Type =3D EfiLoaderCode; + Info[7].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiLoaderCode); + Info[8].Type =3D EfiLoaderData; + Info[8].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiLoaderData); + + // Terminator for the list + Info[9].Type =3D EfiMaxMemoryType; + Info[9].NumberOfPages =3D 0; + + BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info)); +} + +EFI_STATUS +EFIAPI +InitializeMemory ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + UINTN UefiMemoryBase; + EFI_STATUS Status; + + ASSERT (PcdGet64 (PcdSystemMemorySize) >=3D SIZE_128MB); + ASSERT (PcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS); + + // + // Put the permanent PEI memory in the first 128 MiB of DRAM so that + // it is covered by the statically configured ID map. + // + UefiMemoryBase =3D (UINTN)PcdGet64 (PcdSystemMemoryBase) + SIZE_128MB + - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + + Status =3D PeiServicesInstallPeiMemory (UefiMemoryBase, + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); + ASSERT_EFI_ERROR (Status); + + Status =3D MemoryPeim (UefiMemoryBase, + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf b/ArmVirtPkg/Memor= yInitPei/MemoryInitPeim.inf new file mode 100644 index 000000000000..4c56b15bd342 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,66 @@ +#/** @file +# +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2022, Google LLC. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D MemoryInit + FILE_GUID =3D 0fbffd44-f98f-4e1c-9922-e9b21f13c3f8 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + + ENTRY_POINT =3D InitializeMemory + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM +# + +[Sources] + MemoryInitPeim.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[LibraryClasses] + PeimEntryPoint + DebugLib + HobLib + ArmLib + ArmPlatformLib + MemoryInitPeiLib + +[Guids] + gEfiMemoryTypeInformationGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob + +[FixedPcd] + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData + +[Pcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + +[Depex] + TRUE --=20 2.35.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 (#91041): https://edk2.groups.io/g/devel/message/91041 Mute This Topic: https://groups.io/mt/92170211/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- From nobody Fri May 17 22:27:07 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+91042+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+91042+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957205; cv=none; d=zohomail.com; s=zohoarc; b=EPguy6xpCfFTs+YNHsBDA8ljh1IPGFiKhB5LrXIwTWi6RDdLb3fQuuekYvn5YzY9bbIWhgn9J4KhHDdDmwNyLZEEFE/nqc3P88ZE+le75yFRqic0CEwILU975G81/cAYvJui4uKgFX/A/76vBEXI3d/79SstT18GKIb4COLqnKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957205; 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=8GA6ees/7aTdczxCQNfDLlBlT2pPVpB5XdNBjb8oDJI=; b=Yhitbi3K4eHLthM2RMFRc9Bk9w6g3u2vDt51tGU34WkkWY95Ze4/uh+ysRmRvbnRQKR64J00zoJjW3mAqSTEVqFKf5PBvSwR60iFEzFSenisBJv0z+e1Jl8GJ8twMCn9zthMmt+cAppz94lJsmMJ5JWofwBU0XQnNV1ZaUQflDA= 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+91042+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 1656957205455728.9238839228655; Mon, 4 Jul 2022 10:53:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CTh7YY1788612xTFvrhB3byr; Mon, 04 Jul 2022 10:53:25 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web08.75038.1656957204463578843 for ; Mon, 04 Jul 2022 10:53:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D9D6C615F4; Mon, 4 Jul 2022 17:53:23 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF514C3411E; Mon, 4 Jul 2022 17:53:21 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 7/7] ArmVirtPkg/ArmVirtQemu: enable initial ID map at early boot Date: Mon, 4 Jul 2022 19:52:52 +0200 Message-Id: <20220704175252.4015120-8-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: u6quRtaYarcz82ib5yJOimKSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957205; bh=g6th5tmXuEEg3Suikw6tbW09WFG4XFkFoSw4ACka85g=; h=Cc:Date:From:Reply-To:Subject:To; b=nBmTkFUl+/MMJKMkqpHB5O+xNuq78Kr8eiGjSgLLairf8nb4YrDr/+wyY2XKdWjHrUy 0wjz6mzzTXW0T2dH9TKVnno4zbDqA8uwz5bGYlboJsY4Lzma/aaOGEllXINq6g0ZBj4yt 9dY0LLdvHJGH0XEbYzmzszfUIE4YjJFxdgw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957206918100013 Content-Type: text/plain; charset="utf-8" Now that we have all the pieces in place, switch the AArch64 version of ArmVirtQemu to a mode where the first thing it does out of reset is enable a preliminary ID map that covers the NOR flash and sufficient DRAM to create the UEFI page tables as usual. The advantage of this is that no manipulation of memory occurs any longer before the MMU is enabled, which removes the need for explicit coherency management, which is cumbersome and bad for performance. Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemu.dsc | 10 +++++++--- ArmVirtPkg/ArmVirtQemu.fdf | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 45c4a8fc84e0..0b673b6cb003 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -63,8 +63,6 @@ [LibraryClasses.common] QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf =20 - ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibN= ull.inf - TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.i= nf =20 @@ -92,6 +90,12 @@ [LibraryClasses.common] TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLi= bNull/PeiDxeTpmPlatformHierarchyLib.inf !endif =20 +[LibraryClasses.AARCH64] + ArmPlatformLib|ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.= inf + +[LibraryClasses.ARM] + ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibN= ull.inf + [LibraryClasses.common.PEIM] ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoP= eiLib.inf =20 @@ -308,7 +312,7 @@ [Components.common] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf } ArmPlatformPkg/PlatformPei/PlatformPeim.inf - ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf + ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf ArmPkg/Drivers/CpuPei/CpuPei.inf =20 MdeModulePkg/Universal/Variable/Pei/VariablePei.inf diff --git a/ArmVirtPkg/ArmVirtQemu.fdf b/ArmVirtPkg/ArmVirtQemu.fdf index b5e2253295fe..7f17aeb3ad0d 100644 --- a/ArmVirtPkg/ArmVirtQemu.fdf +++ b/ArmVirtPkg/ArmVirtQemu.fdf @@ -107,7 +107,7 @@ [FV.FVMAIN_COMPACT] INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf INF MdeModulePkg/Core/Pei/PeiMain.inf INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf - INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf + INF ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf INF ArmPkg/Drivers/CpuPei/CpuPei.inf INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf --=20 2.35.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 (#91042): https://edk2.groups.io/g/devel/message/91042 Mute This Topic: https://groups.io/mt/92170212/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-