From nobody Mon Sep 16 19:19:20 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+101106+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+101106+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1678727863; cv=none; d=zohomail.com; s=zohoarc; b=WpzBOzHyOrQdOCDjDnNlP4GRKgdj4kssdyTFTh7yYwO9aDdSZkDJO4pvvjp0Q7ltoz58Ha+puYmkWWbyVAhrioreAGzbe1L2gyLkkUjxQMTO8p9YlvHKlIh4zG7KHFM5So3PmyYjc7CY2ypHXURv8/97Y2H/n0oNNBZYnGBE5fM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678727863; 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=WtKOxNX6JIWy3x/ALEV3eQPuCRThCkFZYWx1Z6Vfn2A=; b=OtN74Fd7oUHIIosleEF4G3bQpjjMhf7ElCvBWbYFTRU/lPjkOW64pVk5CJpQ1jXEQgtPGoEJm7/sI5WfwRN3HEA2g7+qh8lyAOlpRqixh/reodzzo1yx+p3vZOg2ukXsR7ci795D3nICwnfFsbtuZYYpU4nEuTyMl1ZWz/xoJjM= 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+101106+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 1678727863255412.2122454856128; Mon, 13 Mar 2023 10:17:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yd41YY1788612xX1Kbd1Re7H; Mon, 13 Mar 2023 10:17:42 -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.26466.1678727862241630309 for ; Mon, 13 Mar 2023 10:17:42 -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 A49696142D; Mon, 13 Mar 2023 17:17:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42D4EC433A4; Mon, 13 Mar 2023 17:17:39 +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 v5 03/38] ArmPkg/CpuDxe ARM: Fix page-to-section attribute conversion Date: Mon, 13 Mar 2023 18:16:39 +0100 Message-Id: <20230313171714.3866151-4-ardb@kernel.org> In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-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: V8uMWKxfD7Z0kP1pJL8TxSKGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678727862; bh=e/w5Qrt6xymZWbWwS+dYD8e+hLNN97t7ym4baUpR0V8=; h=Cc:Date:From:Reply-To:Subject:To; b=hIx4idkjxXAZgw4Htv+DGMqRsK0CchJII8tCtOWher2KV8vSsrixasxWS9kADYDVsWu Lv6jd2pbYXlPHgV2CVrHGDcIVnRPUt6S5jErUpY2hRDxa4mL0xpdvAaLB9K5TVIDMCN2R 2h+Ef6uNmw1RTmRqqfd6yfO6IkrrwJtUOGI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678727863942100002 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 ea856f5cdd26..8eb1f71395f5 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) | + 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 6a2584ceb303..e0219747df86 100644 --- a/ArmPkg/Include/Chipset/ArmV7Mmu.h +++ b/ArmPkg/Include/Chipset/ArmV7Mmu.h @@ -128,6 +128,8 @@ #define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc) ((((Desc) & (0x3= << 12)) >> 6) | (Desc & (0x3 << 2))) =20 #define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & T= T_DESCRIPTOR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK) +#define TT_DESCRIPTOR_CONVERT_TO_SECTION_S(Desc) ((((Desc) & T= T_DESCRIPTOR_PAGE_S_MASK) << 6) & TT_DESCRIPTOR_SECTION_S_MASK) +#define TT_DESCRIPTOR_CONVERT_TO_SECTION_XN(Desc) ((((Desc) & T= T_DESCRIPTOR_PAGE_XN_MASK) << 4) & TT_DESCRIPTOR_SECTION_XN_MASK) #define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc) ((((Desc) & (= 0x3 << 6)) << 6) | (Desc & (0x3 << 2))) =20 #define TT_DESCRIPTOR_SECTION_ATTRIBUTE_MASK (TT_DESCRIPTOR_SECTION_NS_MA= SK | TT_DESCRIPTOR_SECTION_NG_MASK | \ --=20 2.39.2 -=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 (#101106): https://edk2.groups.io/g/devel/message/101106 Mute This Topic: https://groups.io/mt/97585983/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-