From nobody Mon Feb 9 06:05:50 2026 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 --- 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-