From nobody Fri May 17 09:38: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+106518+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+106518+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1688055634; cv=none; d=zohomail.com; s=zohoarc; b=lvYfJoh5f4lsTlwq6AgKz0+LW92blf8yvPUyAe0BU7njyHdQIGlRHOf3m9a94HaFcfOo9/jXyHngoBNzlEF8UmuKGFFgGx2sN+hdij0thWKDni675FpPITfL2wIDZwh5WY/KP/jDGI+vfoZgefAV1+ZdnuZfN9qOH4n5CwiuRPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688055634; 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=dQFzGZ39Xl2OGOnqiOOtZX6L9fNHu6RO9Nwn7pcdps8=; b=ZSC1yJXZQYZPKHlLp5QHgWRIq1Rbd7jGKmuYHjxJvOYj/5HRRTkyFTG6H2PO5r7piOLnyAKt/2IJ1CjBe3jIkMFZRZViK8r7Z6LBhtIH3hYD/2Gk/HGvYgXrSknMujn96HbuCfNz6qhoHRgrLIca1NmyNDW+RRmenQQBq940uYg= 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+106518+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1688055634385830.7064371061368; Thu, 29 Jun 2023 09:20:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3fMbYY1788612xsvvhRzmDhv; Thu, 29 Jun 2023 09:20:34 -0700 X-Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mx.groups.io with SMTP id smtpd.web10.1394.1688055633179943356 for ; Thu, 29 Jun 2023 09:20:33 -0700 X-Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-66c729f5618so868760b3a.1 for ; Thu, 29 Jun 2023 09:20:33 -0700 (PDT) X-Gm-Message-State: 6xjvSogq9HpRlG1uao5pBgB0x1787277AA= X-Google-Smtp-Source: ACHHUZ547zaD7ObhlD2y3D6OaCBNL4NKFdQJQtOK7tep8QfAg1vFH+vQ59Cch7to3UwRRmN9AQcCYA== X-Received: by 2002:a05:6a20:6a0f:b0:12b:6898:2986 with SMTP id p15-20020a056a206a0f00b0012b68982986mr302838pzk.1.1688055632438; Thu, 29 Jun 2023 09:20:32 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0064f7c56d8b7sm6993578pfo.219.2023.06.29.09.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 09:20:31 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Taylor Beebe , Leif Lindholm , Ard Biesheuvel , Taylor Beebe Subject: [edk2-devel] [PATCH 1/4] ArmPkg: Apply Uncrustify to Non-Compliant Files Date: Thu, 29 Jun 2023 09:17:55 -0700 Message-ID: <515e0f28b1aaa5599bc976fcf34dc07c26e36368.1687989723.git.t@taylorbeebe.com> In-Reply-To: References: 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,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688055634; bh=g+rwJUMNCWQKgLth0OiFLsqQ2VrA0wFTQ06VHwkCTQs=; h=Cc:Date:From:Reply-To:Subject:To; b=I4/+eeyLLMBilYt9NgKiBi7kk1/O9kFwClLYdnvLzWV26G0T3zKnYb4KNfGIHU0fjMW ae4iyt5ayZrCUhpjd4BtS0mNwBSCs4MIiozkk6S+bvmBCpmTNhPNbuQvGP8MkLcz93A1R CKK6Jvz0rGQ+QezM1u87iGGFql8ZGWItjb4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688055635476100001 Content-Type: text/plain; charset="utf-8" From: Taylor Beebe This patch applies Uncrustify to the following files: ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c ArmPkg/Include/IndustryStandard/ArmStdSmc.h Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Taylor Beebe Reviewed-by: Ard Biesheuvel --- ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c | 6 +++--- ArmPkg/Include/IndustryStandard/ArmStdSmc.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c b/ArmPk= g/Drivers/MmCommunicationPei/MmCommunicationPei.c index 5dbe99fc3134..ccb182668d6a 100644 --- a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c @@ -159,8 +159,8 @@ MmCommunicationPeim ( } =20 CopyMem (CommBuffer, CommunicateHeader, BufferSize); - *CommSize =3D BufferSize; - Status =3D EFI_SUCCESS; + *CommSize =3D BufferSize; + Status =3D EFI_SUCCESS; break; =20 case ARM_SMC_MM_RET_INVALID_PARAMS: @@ -197,7 +197,7 @@ STATIC CONST EFI_PEI_MM_COMMUNICATION_PPI mPeiMmCommun= ication =3D { STATIC CONST EFI_PEI_PPI_DESCRIPTOR mPeiMmCommunicationPpi =3D { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiPeiMmCommunicationPpiGuid, - (VOID*)&mPeiMmCommunication + (VOID *)&mPeiMmCommunication }; =20 /** diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/I= ndustryStandard/ArmStdSmc.h index 616c650d07c8..f3d78d8e789b 100644 --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h @@ -248,9 +248,9 @@ * SMC64 SiP Service Calls */ =20 -#define SMC_FASTCALL 0x80000000 -#define SMC64_FUNCTION (SMC_FASTCALL | 0x40000000) -#define SMC_SIP_FUNCTION (SMC64_FUNCTION | 0x02000000) -#define SMC_SIP_FUNCTION_ID(n) (SMC_SIP_FUNCTION | (n)) +#define SMC_FASTCALL 0x80000000 +#define SMC64_FUNCTION (SMC_FASTCALL | 0x40000000) +#define SMC_SIP_FUNCTION (SMC64_FUNCTION | 0x02000000) +#define SMC_SIP_FUNCTION_ID(n) (SMC_SIP_FUNCTION | (n)) =20 #endif // ARM_STD_SMC_H_ --=20 2.41.0.windows.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 (#106518): https://edk2.groups.io/g/devel/message/106518 Mute This Topic: https://groups.io/mt/99854261/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 09:38: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+106519+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+106519+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1688055636; cv=none; d=zohomail.com; s=zohoarc; b=HsbPrJBfTjy8px1/t6iGUveHz4VURj2qSi1Pujwl8lLou+w4KmcUlAnUB4WrNap4A5OsuwDqWHgFvNMOwI9BTDgN0WAQGWFKmUXnp9bgRE7CgYfnSH9o2Ue+kb5Lrw7grO1LDWoWJ0h1l9HJYs1CKBB/l4g5KPny6J/y0r8e0ys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688055636; 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=zbl287RvjjV9ZPJtdKw3KaMq5RaKFyAcMcdOYFOKhBg=; b=LaWCQjBqs4g7o5Y3X5MkbfzZc9NGZpSktpvm0MMtcLbauKxeuaXeZZPRnmie7Mm0iEf2mPKN+MtkzLe8zFG2T1melxN5D+qrZU0l3WOXBwT3Nx6Q86yg7LjDmGGxRXhjr83dJ78KR1PxbipAu1gKISPdP9gEL6nPVH2liomy4sQ= 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+106519+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1688055636188930.7614384073277; Thu, 29 Jun 2023 09:20:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gVAvYY1788612x4MeySjOPAI; Thu, 29 Jun 2023 09:20:35 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web10.1396.1688055635317406557 for ; Thu, 29 Jun 2023 09:20:35 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-666fb8b1bc8so825919b3a.1 for ; Thu, 29 Jun 2023 09:20:35 -0700 (PDT) X-Gm-Message-State: UxFRAAAbjgJ0SfiCHXQKP5Tpx1787277AA= X-Google-Smtp-Source: APBJJlG8MXBsTm+g+HWrR6SmnzjeYefysr5KKJZIYMYw8dzHhg3I+raDuD62NCMPpJLx9G0jCU6ImA== X-Received: by 2002:a05:6a00:148b:b0:668:9fb6:b311 with SMTP id v11-20020a056a00148b00b006689fb6b311mr435347pfu.32.1688055634578; Thu, 29 Jun 2023 09:20:34 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0064f7c56d8b7sm6993578pfo.219.2023.06.29.09.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 09:20:34 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Taylor Beebe , Leif Lindholm , Ard Biesheuvel , Taylor Beebe Subject: [edk2-devel] [PATCH 2/4] ArmPkg: Update GetMemoryRegion() to Handle No mapping Date: Thu, 29 Jun 2023 09:17:56 -0700 Message-ID: <20032a1dfef2d6b83e40821532038f186420d318.1687989723.git.t@taylorbeebe.com> In-Reply-To: References: 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,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688055635; bh=T2QFPvwoizcsYN7v99E3vVdWVhi0odLn8/zPRZwR/mo=; h=Cc:Date:From:Reply-To:Subject:To; b=Wap5aWFq+WjcIPhpBaA3r+pR0XRg8lANiOmxEO01n5686QSftCcE7F801VPmnFbNFG+ T4tIUKwrdOgRqE+rAyt/fRb3ZuSDQQDCHbOMG3OvWbhfZu9q8p76L/BLm9wXLocZUG/H6 Z+ITDL+O9cWU/xTrOHMve9qI6yCCPAUIIag= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688055637731100006 Content-Type: text/plain; charset="utf-8" From: Taylor Beebe This patch updates the GetMemoryRegion() function to handle the case where there is no mapping for the requested address. The original logic for the ARM would hit an ASSERT after GetMemoryRegionPage() returned EFI_SUCCESS but did not update The RegionLength parameter. The original logic for the AARCH64 would never initialize the RegionLength parameter to zero and return EFI_SUCCESS after traversing an unknown number of pages. To fix this, the logic for both architecture has updated to return EFI_NO_MAPPING if the BaseAddress being checked is unmapped. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Taylor Beebe Reviewed-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 30 +++++++------ ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 65 +++++++++++++++++++---------- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AA= rch64/Mmu.c index 1d02e41e18d8..0d3bc2809682 100644 --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c @@ -380,10 +380,10 @@ GetMemoryRegionRec ( RegionAttributes ); =20 - // In case of 'Success', it means the end of the block region has been= found into the upper - // level translation table - if (!EFI_ERROR (Status)) { - return EFI_SUCCESS; + // EFI_SUCCESS: The end of the end of the region was found. + // EFI_NO_MAPPING: The translation entry associated with BaseAddress = is invalid. + if (Status !=3D EFI_NOT_FOUND) { + return Status; } =20 // Now we processed the table move to the next entry @@ -395,12 +395,13 @@ GetMemoryRegionRec ( *RegionLength =3D 0; *RegionAttributes =3D *BlockEntry & TT_ATTRIBUTES_MASK; } else { - // We have an 'Invalid' entry - return EFI_UNSUPPORTED; + return EFI_NO_MAPPING; } =20 while (BlockEntry <=3D LastBlockEntry) { - if ((*BlockEntry & TT_ATTRIBUTES_MASK) =3D=3D *RegionAttributes) { + if (((*BlockEntry & TT_TYPE_MASK) =3D=3D BlockEntryType) && + ((*BlockEntry & TT_ATTRIBUTES_MASK) =3D=3D *RegionAttributes)) + { *RegionLength =3D *RegionLength + TT_BLOCK_ENTRY_SIZE_AT_LEVEL (Tabl= eLevel); } else { // In case we have found the end of the region we return success @@ -412,7 +413,7 @@ GetMemoryRegionRec ( =20 // If we have reached the end of the TranslationTable and we have not fo= und the end of the region then // we return EFI_NOT_FOUND. - // The caller will continue to look for the memory region at its level + // The caller will continue to look for the memory region at its level. return EFI_NOT_FOUND; } =20 @@ -433,6 +434,11 @@ GetMemoryRegion ( =20 TranslationTable =3D ArmGetTTBR0BaseAddress (); =20 + // Initialize the output parameters. These paramaters are only valid if = the + // result is EFI_SUCCESS. + *RegionLength =3D 0; + *RegionAttributes =3D 0; + T0SZ =3D ArmGetTCR () & TCR_T0SZ_MASK; // Get the Table info from T0SZ GetRootTranslationTableInfo (T0SZ, &TableLevel, &EntryCount); @@ -447,10 +453,10 @@ GetMemoryRegion ( ); =20 // If the region continues up to the end of the root table then GetMemor= yRegionRec() - // will return EFI_NOT_FOUND - if (Status =3D=3D EFI_NOT_FOUND) { + // will return EFI_NOT_FOUND. Check if the region length was updated. + if ((Status =3D=3D EFI_NOT_FOUND) && (*RegionLength > 0)) { return EFI_SUCCESS; - } else { - return Status; } + + return Status; } diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c index afd6aab60204..268c0bf3f9ae 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -427,17 +427,20 @@ EfiAttributeToArmAttribute ( EFI_STATUS GetMemoryRegionPage ( IN UINT32 *PageTable, - IN OUT UINTN *BaseAddress, - OUT UINTN *RegionLength, - OUT UINTN *RegionAttributes + IN UINTN *BaseAddress, + IN UINTN *RegionAttributes, + OUT UINTN *RegionLength ) { - UINT32 PageAttributes; - UINT32 TableIndex; - UINT32 PageDescriptor; + UINT32 PageAttributes; + UINT32 TableIndex; + UINT32 PageDescriptor; + EFI_STATUS Status; =20 // Convert the section attributes into page attributes PageAttributes =3D ConvertSectionAttributesToPageAttributes (*RegionAttr= ibutes); + Status =3D EFI_NOT_FOUND; + *RegionLength =3D 0; =20 // Calculate index into first level translation table for start of modif= ication TableIndex =3D ((*BaseAddress) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_D= ESCRIPTOR_PAGE_BASE_SHIFT; @@ -449,23 +452,24 @@ GetMemoryRegionPage ( PageDescriptor =3D PageTable[TableIndex]; =20 if ((PageDescriptor & TT_DESCRIPTOR_PAGE_TYPE_MASK) =3D=3D TT_DESCRIPT= OR_PAGE_TYPE_FAULT) { - // Case: End of the boundary of the region - return EFI_SUCCESS; + Status =3D (*RegionLength > 0) ? EFI_SUCCESS : EFI_NO_MAPPING; + break; } else if ((PageDescriptor & TT_DESCRIPTOR_PAGE_TYPE_PAGE) =3D=3D TT_D= ESCRIPTOR_PAGE_TYPE_PAGE) { - if ((PageDescriptor & TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK) =3D=3D Page= Attributes) { - *RegionLength =3D *RegionLength + TT_DESCRIPTOR_PAGE_SIZE; - } else { - // Case: End of the boundary of the region - return EFI_SUCCESS; + if ((PageDescriptor & TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK) !=3D PageAt= tributes) { + Status =3D EFI_SUCCESS; + break; } + + *RegionLength +=3D TT_DESCRIPTOR_PAGE_SIZE; } else { - // We do not support Large Page yet. We return EFI_SUCCESS that mean= s end of the region. + // Large pages are unsupported. + Status =3D EFI_UNSUPPORTED; ASSERT (0); - return EFI_SUCCESS; + break; } } =20 - return EFI_NOT_FOUND; + return Status; } =20 EFI_STATUS @@ -482,6 +486,7 @@ GetMemoryRegion ( UINT32 SectionDescriptor; ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable; UINT32 *PageTable; + UINTN Length; =20 // Initialize the arguments *RegionLength =3D 0; @@ -491,7 +496,11 @@ GetMemoryRegion ( =20 // Calculate index into first level translation table for start of modif= ication TableIndex =3D TT_DESCRIPTOR_SECTION_BASE_ADDRESS (*BaseAddress) >> TT_D= ESCRIPTOR_SECTION_BASE_SHIFT; - ASSERT (TableIndex < TRANSLATION_TABLE_SECTION_COUNT); + + if (TableIndex >=3D TRANSLATION_TABLE_SECTION_COUNT) { + ASSERT (TableIndex < TRANSLATION_TABLE_SECTION_COUNT); + return EFI_INVALID_PARAMETER; + } =20 // Get the section at the given index SectionDescriptor =3D FirstLevelTable[TableIndex]; @@ -524,6 +533,8 @@ GetMemoryRegion ( TT_DESCRIPTOR_CONVERT_TO_SECTION_AP (PageAttribute= s); } =20 + Status =3D EFI_NOT_FOUND; + for ( ; TableIndex < TRANSLATION_TABLE_SECTION_COUNT; TableIndex++) { // Get the section at the given index SectionDescriptor =3D FirstLevelTable[TableIndex]; @@ -532,15 +543,18 @@ GetMemoryRegion ( if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE (SectionDescriptor)) { // Extract the page table location from the descriptor PageTable =3D (UINT32 *)(SectionDescriptor & TT_DESCRIPTOR_SECTION_P= AGETABLE_ADDRESS_MASK); + Length =3D 0; =20 // Scan the page table to find the end of the region. - Status =3D GetMemoryRegionPage (PageTable, BaseAddress, RegionLength= , RegionAttributes); - ASSERT (*RegionLength > 0); + Status =3D GetMemoryRegionPage (PageTable, BaseAddress, Regi= onAttributes, &Length); + *RegionLength +=3D Length; =20 - // If we have found the end of the region (Status =3D=3D EFI_SUCCESS= ) then we exit the for-loop - if (Status =3D=3D EFI_SUCCESS) { - break; + // Status =3D=3D EFI_NOT_FOUND implies we have not reached the end o= f the region. + if ((Status =3D=3D EFI_NOT_FOUND) && (Length > 0)) { + continue; } + + break; } else if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) =3D= =3D TT_DESCRIPTOR_SECTION_TYPE_SECTION) || ((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) =3D= =3D TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION)) { @@ -556,5 +570,10 @@ GetMemoryRegion ( } } =20 - return EFI_SUCCESS; + // Check if the region length was updated. + if (*RegionLength > 0) { + Status =3D EFI_SUCCESS; + } + + return Status; } --=20 2.41.0.windows.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 (#106519): https://edk2.groups.io/g/devel/message/106519 Mute This Topic: https://groups.io/mt/99854263/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 09:38: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+106520+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+106520+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1688055638; cv=none; d=zohomail.com; s=zohoarc; b=kg8WkWz+4QBABx6Hb74x2i5cEnRpWTmHOtLIe8Uq1i9uAvfEBltAFchdbqm6fT20KjhLQ7KouQbi5so6mhWz3/2x5SmWV0Ib9yuiLAG1/IyQDRo3uBL5V/G3iDW1cRt8Tl+wjk0iZJfZtheY5W5mkAL6pO6+h6DIUGPAqJYvpSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688055638; 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=K6qHJGzKlOSs/SJScX7S1tn4BxafFMLvNpxY3cw6fwY=; b=ZM7oM5N+ZjJ7pYYKEx5G28qrLzz70nVOguXyeLc/BU52o421lmiAiIanYgpceq99quvgx5ZM3OXZDPAVJVYZfyzqUj/1hyA5zxjo8fZ+CWaFyr05fuQA2/dxxCSgAJopgtIH3SOJAdi7Z+DNabqITO2ObCTJ2b6Cs5THn6yYJJE= 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+106520+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1688055638159583.1467695737837; Thu, 29 Jun 2023 09:20:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id nPcwYY1788612xdYdPtKjK76; Thu, 29 Jun 2023 09:20:37 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web10.1398.1688055636938762346 for ; Thu, 29 Jun 2023 09:20:37 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-666eb03457cso600901b3a.1 for ; Thu, 29 Jun 2023 09:20:36 -0700 (PDT) X-Gm-Message-State: eFK5xEJKcyVFCRn9h5F9Y16Lx1787277AA= X-Google-Smtp-Source: APBJJlFlEz623kFAdVpx0kYXFAbfm2ZWf0U6Np0ty71MM+mwySHW30TTbyvbvMVNymVRMm4y9++W3Q== X-Received: by 2002:a05:6a00:2346:b0:673:5d1e:6657 with SMTP id j6-20020a056a00234600b006735d1e6657mr471408pfj.7.1688055636262; Thu, 29 Jun 2023 09:20:36 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0064f7c56d8b7sm6993578pfo.219.2023.06.29.09.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 09:20:35 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Taylor Beebe , Leif Lindholm , Ard Biesheuvel , Taylor Beebe Subject: [edk2-devel] [PATCH 3/4] ArmPkg: Fix Unsafe ASSERTs in MMU Logic Date: Thu, 29 Jun 2023 09:17:57 -0700 Message-ID: <580bf85d35a2f301cb5b99e88f58ac4af696cae1.1687989723.git.t@taylorbeebe.com> In-Reply-To: References: 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,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688055637; bh=egV6Y1TweXmibDlaKAs4KEDtONA09R/NQT7IXgiFtBs=; h=Cc:Date:From:Reply-To:Subject:To; b=UjMdiJn9yZMu+/jsJP50ZHsd2vT4trCM93Sh+ztsWZz2Mz+Dr3aVV9TU409n5wkZ4ha umGZqKAdNDxQJAoqr9nwJA2kBPsFNvI3RbTy/kYk9kZz7i6c0drgNkDP0czu4/YZAwk/s 3VEsibW72VTWgDpM9viFHUoZor7Ck9WFWD8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688055640288100011 Content-Type: text/plain; charset="utf-8" From: Taylor Beebe There are ASSERTs present in the MMU logic to ensure various functions return successfully, but these ASSERTs may be ignored on release builds causing unsafe behavior. This patch updates the logic to handle unexpected return values and branch safely. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Taylor Beebe Reviewed-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 21 ++++++++++++----- ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 36 ++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AA= rch64/Mmu.c index 0d3bc2809682..d9d386dbed6b 100644 --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c @@ -148,10 +148,12 @@ GetNextEntryAttribute ( // Get the memory space map from GCD MemorySpaceMap =3D NULL; Status =3D gDS->GetMemorySpaceMap (&NumberOfDescriptors, &Memory= SpaceMap); - ASSERT_EFI_ERROR (Status); =20 - // We cannot get more than 3-level page table - ASSERT (TableLevel <=3D 3); + if (EFI_ERROR (Status) || (TableLevel > 3)) { + ASSERT_EFI_ERROR (Status); + ASSERT (TableLevel <=3D 3); + return 0; + } =20 // While the top level table might not contain TT_ENTRY_COUNT entries; // the subsequent ones should be filled up @@ -243,7 +245,11 @@ SyncCacheConfig ( // MemorySpaceMap =3D NULL; Status =3D gDS->GetMemorySpaceMap (&NumberOfDescriptors, &Memory= SpaceMap); - ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } =20 // The GCD implementation maintains its own copy of the state of memory = space attributes. GCD needs // to know what the initial memory space attributes are. The CPU Arch. = Protocol does not provide a @@ -277,7 +283,7 @@ SyncCacheConfig ( ); =20 // Update GCD with the last region if valid - if (PageAttribute !=3D INVALID_ENTRY) { + if ((PageAttribute !=3D INVALID_ENTRY) && (EndAddressGcdRegion > BaseAdd= ressGcdRegion)) { SetGcdMemorySpaceAttributes ( MemorySpaceMap, NumberOfDescriptors, @@ -430,7 +436,10 @@ GetMemoryRegion ( UINTN EntryCount; UINTN T0SZ; =20 - ASSERT ((BaseAddress !=3D NULL) && (RegionLength !=3D NULL) && (RegionAt= tributes !=3D NULL)); + if ((BaseAddress =3D=3D NULL) || (RegionLength =3D=3D NULL) || (RegionAt= tributes =3D=3D NULL)) { + ASSERT ((BaseAddress !=3D NULL) && (RegionLength !=3D NULL) && (Region= Attributes !=3D NULL)); + return EFI_INVALID_PARAMETER; + } =20 TranslationTable =3D ArmGetTTBR0BaseAddress (); =20 diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c index 268c0bf3f9ae..5a2f36d06086 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -217,7 +217,10 @@ SyncCacheConfigPage ( } else if (PageAttributes !=3D NextPageAttributes) { // Convert Section Attributes into GCD Attributes Status =3D PageToGcdAttributes (NextPageAttributes, &GcdAttributes= ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + GcdAttributes =3D 0; + } =20 // update GCD with these changes (this will recurse into our own C= puSetMemoryAttributes below which is OK) SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, = *NextRegionBase, *NextRegionLength, GcdAttributes); @@ -230,7 +233,10 @@ SyncCacheConfigPage ( } else if (NextPageAttributes !=3D 0) { // Convert Page Attributes into GCD Attributes Status =3D PageToGcdAttributes (NextPageAttributes, &GcdAttributes); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + GcdAttributes =3D 0; + } =20 // update GCD with these changes (this will recurse into our own Cpu= SetMemoryAttributes below which is OK) SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, *N= extRegionBase, *NextRegionLength, GcdAttributes); @@ -278,7 +284,12 @@ SyncCacheConfig ( // MemorySpaceMap =3D NULL; Status =3D gDS->GetMemorySpaceMap (&NumberOfDescriptors, &Memory= SpaceMap); - ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SyncCacheConfig - GetMemorySpaceMap() failed! St= atus: %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; + } =20 // The GCD implementation maintains its own copy of the state of memory = space attributes. GCD needs // to know what the initial memory space attributes are. The CPU Arch. = Protocol does not provide a @@ -307,7 +318,12 @@ SyncCacheConfig ( } else if (SectionAttributes !=3D NextSectionAttributes) { // Convert Section Attributes into GCD Attributes Status =3D SectionToGcdAttributes (NextSectionAttributes, &GcdAttr= ibutes); - ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SyncCacheConfig - SectionToGcdAttributes()= failed! Status: %r\n", Status)); + ASSERT_EFI_ERROR (Status); + GcdAttributes =3D 0; + } =20 // update GCD with these changes (this will recurse into our own C= puSetMemoryAttributes below which is OK) SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, = NextRegionBase, NextRegionLength, GcdAttributes); @@ -343,7 +359,11 @@ SyncCacheConfig ( if (NextSectionAttributes !=3D 0) { // Convert Section Attributes into GCD Attributes Status =3D SectionToGcdAttributes (NextSectionAttributes, &GcdAttr= ibutes); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SyncCacheConfig - SectionToGcdAttributes()= failed! Status: %r\n", Status)); + ASSERT_EFI_ERROR (Status); + GcdAttributes =3D 0; + } =20 // update GCD with these changes (this will recurse into our own C= puSetMemoryAttributes below which is OK) SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, = NextRegionBase, NextRegionLength, GcdAttributes); @@ -360,7 +380,11 @@ SyncCacheConfig ( if (NextSectionAttributes !=3D 0) { // Convert Section Attributes into GCD Attributes Status =3D SectionToGcdAttributes (NextSectionAttributes, &GcdAttribut= es); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SyncCacheConfig - SectionToGcdAttributes() fai= led! Status: %r\n", Status)); + ASSERT_EFI_ERROR (Status); + GcdAttributes =3D 0; + } =20 // update GCD with these changes (this will recurse into our own CpuSe= tMemoryAttributes below which is OK) SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, Next= RegionBase, NextRegionLength, GcdAttributes); --=20 2.41.0.windows.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 (#106520): https://edk2.groups.io/g/devel/message/106520 Mute This Topic: https://groups.io/mt/99854265/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 09:38: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+106521+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+106521+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1688055640; cv=none; d=zohomail.com; s=zohoarc; b=iDCd4dRxplk8OgiqWrku0U8kbuR2PdCpv1lo20PKp/6KxLkkhHndPh0nLCM43BqYkBELTyiP1KeAO1tkqUTJgM/BaO/GVlheMG2notf/UipETxulCwk2LTZ8TFJ/Qa23XMiv8sUiNK6cckDVVOLThP56w+Im6mRLV34KxhI9Jtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688055640; 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=+iTDlbe3Q4I6XxHZHjVJbJYKqPZqP8Lirwo8FIBdfe8=; b=FQ6FI6hG0m7wGo1bOmbz2xx/MAHA5NudiKGSTIdBqcIc8mWkhOoGMVfLGxtbM7LLtGYBFvQJOBCpk4/KuxVn/5SWkhgq/hck0EsmZHi8IrjseNWa41j98d/eiXy9DOchrbkzsQnSeN3A26Pj0fQH/LS+pV0yP8pjK6uhpgyifdM= 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+106521+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1688055640050961.3966668797851; Thu, 29 Jun 2023 09:20:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DLLWYY1788612x4Nyos3Uzwt; Thu, 29 Jun 2023 09:20:39 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web10.1400.1688055638948995921 for ; Thu, 29 Jun 2023 09:20:39 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-666eec46206so860800b3a.3 for ; Thu, 29 Jun 2023 09:20:38 -0700 (PDT) X-Gm-Message-State: E4VfrjtvtNP89JwKyJ8wn5k6x1787277AA= X-Google-Smtp-Source: APBJJlF7GXg64hJUL/LFuFIKemi3YgGHx6er+bl6OrE+SEMGCPMqy8UvwgxS0ln44vdaZhnw1QRGWA== X-Received: by 2002:a05:6a00:1352:b0:67e:45ab:b86b with SMTP id k18-20020a056a00135200b0067e45abb86bmr410488pfu.28.1688055638158; Thu, 29 Jun 2023 09:20:38 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0064f7c56d8b7sm6993578pfo.219.2023.06.29.09.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 09:20:37 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Taylor Beebe , Leif Lindholm , Ard Biesheuvel , Taylor Beebe Subject: [edk2-devel] [PATCH 4/4] ArmPkg: Add Function Headers to MMU Logic Date: Thu, 29 Jun 2023 09:17:58 -0700 Message-ID: <389dd0904fc75321dc307834f735874ffe43e9ab.1687989723.git.t@taylorbeebe.com> In-Reply-To: References: 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,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688055639; bh=RrZU/kKXMvoXe/PJ2O1x7LYH3Ly7737Gb+AOaSoqbt0=; h=Cc:Date:From:Reply-To:Subject:To; b=pGWxRQQKCp9Jc3bB2zCt46iLM6Nru3tRzDFdvr2xk78h7Z15XseGLf7SFmbgptY8NUs x7Qa9+r9E/mixVuXtrifqPWImI4FEbkd/TpkpBerIjGwLOHogAE/0g26+15VkMbWcOSPY cag+lKwQCwiTf+6+ayuzuDM2PfcFnaHqKJ8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688055641683100015 Content-Type: text/plain; charset="utf-8" From: Taylor Beebe Much of the MMU logic was written without function headers. This patch adds function headers where absent and updates function headers which do not match the EDK2 standard. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Taylor Beebe Reviewed-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 92 ++++++++++++++++++++++++++++- ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 86 ++++++++++++++++++++++++--- 2 files changed, 169 insertions(+), 9 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AA= rch64/Mmu.c index d9d386dbed6b..e14eb47ce4c6 100644 --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c @@ -18,6 +18,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define MIN_T0SZ 16 #define BITS_PER_LEVEL 9 =20 +/** + Parses T0SZ to determine the level and number of entries at the root + of the translation table. + + @param T0SZ The T0SZ value to be parsed. + @param RootTableLevel The level of the root table. + @param RootTableEntryCount The number of entries in the root table. +**/ STATIC VOID GetRootTranslationTableInfo ( @@ -30,6 +38,13 @@ GetRootTranslationTableInfo ( *RootTableEntryCount =3D TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_= LEVEL; } =20 +/** + Converts ARM translation table attributes to GCD attributes. + + @param PageAttributes The translation table attributes to be converted. + + @retval The analogous GCD attributes. +**/ STATIC UINT64 PageAttributeToGcdAttribute ( @@ -100,6 +115,14 @@ RegionAttributeToGcdAttribute ( return PageAttributeToGcdAttribute (PageAttributes); } =20 +/** + Retrieves the attribute of the first page entry in the translation table. + + @param[in] FirstLevelTableAddress The base address of the translation = table. + @param[in] TableLevel The current level being traversed. + + @retval The attributes of the first page entry found, or INVALID_ENTRY. +**/ STATIC UINT64 GetFirstPageAttribute ( @@ -126,6 +149,19 @@ GetFirstPageAttribute ( } } =20 +/** + This function recursively traverses the translation table heirarchy to + synchronise the GCD with the translation table. + + @param[in] TableAddress The address of the table being pro= cessed. + @param[in] EntryCount The number of entries in the curre= nt level of the table. + @param[in] TableLevel The current level of the memory ta= ble being processed. + @param[in] BaseAddress The starting address of the region. + @param[in, out] PrevEntryAttribute The attributes of the previous reg= ion. + @param[in, out] StartGcdRegion The start of the GCD region. + + @retval The address at the end of the last region processed. +**/ STATIC UINT64 GetNextEntryAttribute ( @@ -220,6 +256,15 @@ GetNextEntryAttribute ( return BaseAddress + (EntryCount * TT_ADDRESS_AT_LEVEL (TableLevel)); } =20 +/** + Sync the GCD memory space attributes with the translation table. + + @param[in] CpuProtocol The CPU architectural protocol instance. + + @retval EFI_SUCCESS The GCD memory space attributes are synced with + the MMU page table. + @retval Others The return value of GetMemorySpaceMap(). +**/ EFI_STATUS SyncCacheConfig ( IN EFI_CPU_ARCH_PROTOCOL *CpuProtocol @@ -298,6 +343,13 @@ SyncCacheConfig ( return EFI_SUCCESS; } =20 +/** + Convert EFI memory attributes to ARM translation table attributes. + + @param[in] EfiAttributes EFI memory attributes. + + @retval The analogous translation table attributes. +**/ UINT64 EfiAttributeToArmAttribute ( IN UINT64 EfiAttributes @@ -345,8 +397,25 @@ EfiAttributeToArmAttribute ( return ArmAttributes; } =20 -// This function will recursively go down the page table to find the first= block address linked to 'BaseAddress'. -// And then the function will identify the size of the region that has the= same page table attribute. +/** + This function returns the attributes of the memory region containing the + specified address. + + RegionLength and RegionAttributes are only valid if the result is EFI_SU= CCESS. + + @param[in] TranslationTable The translation table base address. + @param[in] TableLevel The level of the translation table. + @param[in] LastBlockEntry The last block address of the table = level. + @param[in, out] BaseAddress The base address of the memory regio= n. + @param[out] RegionLength The length of the memory region. + @param[out] RegionAttributes The attributes of the memory region. + + @retval EFI_SUCCESS The attributes of the memory region were + returned successfully. + @retval EFI_NOT_FOUND The memory region was not found. + @retval EFI_NO_MAPPING The translation table entry associated with + BaseAddress is invalid. +**/ EFI_STATUS GetMemoryRegionRec ( IN UINT64 *TranslationTable, @@ -423,6 +492,25 @@ GetMemoryRegionRec ( return EFI_NOT_FOUND; } =20 +/** + Retrieves a memory region from a given base address. + + This function retrieves a memory region starting from a given base addre= ss. + + @param[in, out] BaseAddress The base address from which to retrieve + the memory region. On successful retur= n, this is + updated to the end address of the retr= ieved region. + @param[out] RegionLength The length of the retrieved memory reg= ion. + @param[out] RegionAttributes The attributes of the retrieved memory= region. + + @retval EFI_STATUS Returns EFI_SUCCESS if the memory region= is + retrieved successfully, or the status of= the + recursive call to GetMemoryRegionRec. + @retval EFI_NOT_FOUND The memory region was not found. + @retval EFI_NO_MAPPING The translation table entry associated w= ith + BaseAddress is invalid. + @retval EFI_INVALID_PARAMETER One of the input parameters was NULL. +**/ EFI_STATUS GetMemoryRegion ( IN OUT UINTN *BaseAddress, diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c index 5a2f36d06086..8c4de284e160 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -17,9 +17,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent Convert a set of ARM short descriptor section attributes into a mask of EFI_MEMORY_xx constants. =20 - @param SectionAttributes The set of page attributes. - @param GcdAttributes Pointer to the return value. + @param[in] SectionAttributes The set of page attributes. + @param[out] GcdAttributes Pointer to the return value. =20 + @retval EFI_SUCCESS The attributes were converted successfully. + @retval EFI_UNSUPPORTED The section attributes did not have a + GCD transation. **/ STATIC EFI_STATUS @@ -87,10 +90,11 @@ SectionToGcdAttributes ( Convert an arch specific set of page attributes into a mask of EFI_MEMORY_xx constants. =20 - @param PageAttributes The set of page attributes. - - @retval The mask of EFI_MEMORY_xx constants. + @param[in] PageAttributes The set of page attributes. =20 + @retval EFI_SUCCESS The attributes were converted successfully. + @retval EFI_UNSUPPORTED The section attributes did not have a + GCD transation. **/ UINT64 RegionAttributeToGcdAttribute ( @@ -107,9 +111,11 @@ RegionAttributeToGcdAttribute ( Convert a set of ARM short descriptor page attributes into a mask of EFI_MEMORY_xx constants. =20 - @param PageAttributes The set of page attributes. - @param GcdAttributes Pointer to the return value. + @param[in] PageAttributes The set of page attributes. + @param[out] GcdAttributes Pointer to the return value. =20 + @retval EFI_SUCCESS The attributes were converted successfully. + @retval EFI_UNSUPPORTED The page attributes did not have a GCD transat= ion. **/ STATIC EFI_STATUS @@ -173,6 +179,23 @@ PageToGcdAttributes ( return EFI_SUCCESS; } =20 +/** + Synchronizes the GCD with the translation table for a specified page. + + This function synchronizes cache configuration for a given page based on= its section index + and the first level descriptor. It traverses the second level table entr= ies of the page and + updates the GCD attributes accordingly for each entry. + + @param[in] SectionIndex The index of the section where= the page resides. + @param[in] FirstLevelDescriptor The first translation table le= vel of the page. + @param[in] NumberOfDescriptors The number of descriptors in t= he GCD memory space map. + @param[in] MemorySpaceMap The GCD memory space descripto= r. + @param[in, out] NextRegionBase The next region base address. + @param[in, out] NextRegionLength The next region length. + @param[in, out] NextSectionAttributes The next section attributes. + + @retval EFI_STATUS Always return success +**/ EFI_STATUS SyncCacheConfigPage ( IN UINT32 SectionIndex, @@ -258,6 +281,14 @@ SyncCacheConfigPage ( return EFI_SUCCESS; } =20 +/** + Sync the GCD memory space attributes with the translation table. + + @param[in] CpuProtocol The CPU architectural protocol instance. + + @retval EFI_SUCCESS The GCD memory space attributes are synced with th= e MMU page table. + @retval Others The return value of GetMemorySpaceMap(). +**/ EFI_STATUS SyncCacheConfig ( IN EFI_CPU_ARCH_PROTOCOL *CpuProtocol @@ -395,6 +426,13 @@ SyncCacheConfig ( return EFI_SUCCESS; } =20 +/** + Convert EFI memory attributes to ARM translation table attributes. + + @param[in] EfiAttributes EFI memory attributes. + + @retval The analogous translation table attributes. +**/ UINT64 EfiAttributeToArmAttribute ( IN UINT64 EfiAttributes @@ -448,6 +486,22 @@ EfiAttributeToArmAttribute ( return ArmAttributes; } =20 +/** + This function finds the end of a memory region in a translation table. A + memory region is defined as a contiguous set of pages with the same attr= ibutes. + + @param[in] PageTable The translation table to traverse. + @param[in] BaseAddress The address from which to start the sear= ch + @param[in] RegionAttributes The attributes of the start of the regio= n. + @param[out] RegionLength The length of the region found. + + @retval EFI_SUCCESS The region was found. + @retval EFI_NOT_FOUND The end of the region was not found. + @retval EFI_NO_MAPPING The region specified by BaseAddress is not map= ped + in the input translation table. + @retval EFI_UNSUPPORTED Large pages are not supported. +**/ +STATIC EFI_STATUS GetMemoryRegionPage ( IN UINT32 *PageTable, @@ -496,6 +550,24 @@ GetMemoryRegionPage ( return Status; } =20 +/** + Get the memory region that contains the specified address. A memory regi= on is defined + as a contiguous set of pages with the same attributes. + + RegionLength and RegionAttributes are only valid if EFI_SUCCESS is retur= ned. + + @param[in, out] BaseAddress On input, the address to search for. + On output, the base address of the r= egion found. + @param[out] RegionLength The length of the region found. + @param[out] RegionAttributes The attributes of the region found. + + @retval EFI_SUCCESS Region found + @retval EFI_NOT_FOUND Region not found + @retval EFI_UNSUPPORTED Large pages are unsupported + @retval EFI_NO_MAPPING The page specified by BaseAddress is u= nmapped + @retval EFI_INVALID_PARAMETER The BaseAddress exceeds the addressabl= e range of + the translation table. +**/ EFI_STATUS GetMemoryRegion ( IN OUT UINTN *BaseAddress, --=20 2.41.0.windows.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 (#106521): https://edk2.groups.io/g/devel/message/106521 Mute This Topic: https://groups.io/mt/99854268/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-