From nobody Mon Feb 9 00:31:02 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+99702+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+99702+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1675722077; cv=none; d=zohomail.com; s=zohoarc; b=QqI/OYHjLWa00YiyfqLS03QolPLOtfdeIt9lC4e4TEOmDH8sHq0ISZnTul4UgAtuZvSJ3J5OzDf6cjhDZ8fioCp/kQyRUk3BCUIIkXbsYtcH82mVAnOjXE/men/zQFUcj8wIKE/VrTA+d0/0teY7AZYYQ9zbPL3F2/xFiZwBLvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675722077; 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=2ULRj+beRbosl/nZdOP9qnQGmo9zKCzBPI7AY90BcyE=; b=X8mSvBrFu/igEuVjspNZd1yUIByPUieocMS44V28t0om7Z7ulOSRGoa0pYTJcaYgrP8U5Ega3tk4IY5ujMMHWz6o6Q4C2m2kMn/syjnn9qQmrJ2UDj3wGMUqCJmm5zsfmJQ1RAj18ZFsBmNgZJsw7VE5kGQ9U5HGgvrV+9weqaM= 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+99702+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 1675722077086829.9918775576505; Mon, 6 Feb 2023 14:21:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9vTtYY1788612xp7sZf9C1GT; Mon, 06 Feb 2023 14:21:16 -0800 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.68444.1675722075988001796 for ; Mon, 06 Feb 2023 14:21:16 -0800 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 721D2B81630; Mon, 6 Feb 2023 22:21:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB469C4339C; Mon, 6 Feb 2023 22:21:10 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe Subject: [edk2-devel] [PATCH v3 2/5] ArmPkg/CpuDxe ARM: Fix page-to-section attribute conversion Date: Mon, 6 Feb 2023 23:20:57 +0100 Message-Id: <20230206222100.411169-3-ardb@kernel.org> In-Reply-To: <20230206222100.411169-1-ardb@kernel.org> References: <20230206222100.411169-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: nJhCPwdaS0lxALazwLmB3FNux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675722076; bh=5xCLcZu85p7IlwGV5EUGKXKXdd7+eBf0m447Pbe71M4=; h=Cc:Date:From:Reply-To:Subject:To; b=Hj69nSZDA/Csf151M/VCvU8+WbDrlRbc+y0WYCq9rsJLj3snpSSXG0TfiuWq3iNAezb xLzTqcwNFd5c3EuyMtmHqPAjg4IOOKFWXukbhi+3IJXt2Kdl0w2KZVaP2ClPS3cvvmAaa wIrkZxYxk19rB2f2sp21d48D02DWSn2fUow= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675722078410100006 Content-Type: text/plain; charset="utf-8" The section-to-page attribute conversion takes the shareability and execute-never attributes into account, whereas the page-to-section counterpart does not. The result is that GetMemoryRegionPage () -which takes a section attribute argument (via *RegionAttributes) that is ostensibly based on the first page in the range, but differs from the actual page attributes when converted back- may return with a RegionLength of zero. This is incorrect, and confuses code that scans a region by calling GetMemoryRegion () in sequence. So fix the conversion, and ASSERT () on a non-zero region length. Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 3 +++ ArmPkg/Include/Chipset/ArmV7Mmu.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c index 2daf47ba6fe5..e7acd84b8af9 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -480,6 +480,8 @@ GetMemoryRegion ( =20 PageAttributes =3D PageTable[PageTableIndex] & TT_DESCRIPTOR_PAGE_A= TTRIBUTE_MASK; *RegionAttributes =3D TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY (P= ageAttributes, 0) | + TT_DESCRIPTOR_CONVERT_TO_SECTION_S (PageAttributes= ) | + TT_DESCRIPTOR_CONVERT_TO_SECTION_XN (PageAttribute= s) | TT_DESCRIPTOR_CONVERT_TO_SECTION_AP (PageAttribute= s); } =20 @@ -494,6 +496,7 @@ GetMemoryRegion ( =20 // Scan the page table to find the end of the region. Status =3D GetMemoryRegionPage (PageTable, BaseAddress, RegionLength= , RegionAttributes); + ASSERT (*RegionLength > 0); =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) { diff --git a/ArmPkg/Include/Chipset/ArmV7Mmu.h b/ArmPkg/Include/Chipset/Arm= V7Mmu.h index db99527d6efa..4f51041e29ed 100644 --- a/ArmPkg/Include/Chipset/ArmV7Mmu.h +++ b/ArmPkg/Include/Chipset/ArmV7Mmu.h @@ -144,6 +144,8 @@ (((((D= esc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2))))) =20 #define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & TT_DESCRIPT= OR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK) +#define TT_DESCRIPTOR_CONVERT_TO_SECTION_S(Desc) ((((Desc) & TT_DESCRIPT= OR_PAGE_S_MASK) << 6) & TT_DESCRIPTOR_SECTION_S_MASK) +#define TT_DESCRIPTOR_CONVERT_TO_SECTION_XN(Desc) ((((Desc) & TT_DESCRIPT= OR_PAGE_XN_MASK) << 4) & TT_DESCRIPTOR_SECTION_XN_MASK) =20 #define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc, IsLargePage) = (IsLargePage? \ (((Des= c) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK) & TT_DESCRIPTOR_SECTION_CAC= HE_POLICY_MASK): \ --=20 2.39.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 (#99702): https://edk2.groups.io/g/devel/message/99702 Mute This Topic: https://groups.io/mt/96795073/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-