From patchwork Fri Jun 24 15:06:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12894751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC13FC43334 for ; Fri, 24 Jun 2022 15:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IJz3jXCTLVA5Cq3bebVbp6Gc31RIfjUpqT/PjsR9Hjk=; b=OZ5DF5F4WT0FY4 hRU6aZdSGY1rBK/VMsLOsyTT4TK63Lop8dBlgc6VM9GEzxvUJ+KW7zC0cQL1YJpqaL0y7x0a9HXiR 6+6IQLN8BC31elTeOJLLuIkBZkJ0Kh6pooLL/9UTe3IZ+zQtfNKmdQIiNf3pRxNlSZuy4kWzESIZk m57fKv3IQMElEa+dUJ98f+BVA6xFAltbMJrbYoPAgj5373thmXjophuBU3NHLErJT647onLXo5yhV xRMaESm3Ne1jwaJ7UrkFCtgoVoBSv3kdja5LiLX3M9t7jXdfyyRTUM5bF9Q+97nhU6F9hezKTzPgq xbbLi349UeNt44Z6Ziyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kxT-002k6F-9u; Fri, 24 Jun 2022 15:10:55 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kuF-002iRX-U4 for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2022 15:07:37 +0000 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 7F91D621CF; Fri, 24 Jun 2022 15:07:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AD7AC341C6; Fri, 24 Jun 2022 15:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656083254; bh=ATMp2RpRB2PDdPIzVcMeparFt7O9V0QyNBWnaeS/YG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCvmJDKPp1jF/3fwf0BPzhWNCk85ULVd+8r0gwZpWxZSGemGn9+IytIB9qboAaU8C KBTYYAW7+KCVH/3arzL277cBnAgmd3Fp71zSuqwEgSoyCpr0dyR+xN2kI3a/qjZC5J tRV1RWcbeEiTMMuUsZ2Afe9GxqUAUeZn6iNViCyjjc8AftUjOwul85Drp2/mTi1xQM hlHnVWVaDleEWeTN/AHMeiJnT9zGG4nloFS8vdEf30tqKRIT7+m1Tkx+czK7b9HGvS 7PjZAPMEt5H8n9KVxNJMBOZz0E79KziTI7maXtZLJj/ewg+qBjma0gSPxjGJiPeHnE r/aA9kYvgbp9w== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v5 11/21] arm64: head: add helper function to remap regions in early page tables Date: Fri, 24 Jun 2022 17:06:41 +0200 Message-Id: <20220624150651.1358849-12-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220624150651.1358849-1-ardb@kernel.org> References: <20220624150651.1358849-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2144; h=from:subject; bh=ATMp2RpRB2PDdPIzVcMeparFt7O9V0QyNBWnaeS/YG8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBitdL5w39YLBMwRoAQYQhZ2j8SZ/RBgRyKcPuKtY9O g1sfmsGJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYrXS+QAKCRDDTyI5ktmPJHadDA C9YP0GUsr6OQfW4UVDp+8dvFYQXQbJ4FzkPXGvWmMDH9gYtzTKGrgYYiIju4wApKKCPLPbJwGeRfON UkTgrOs3nXT93rCtuDqk95+/lZW7D9Jm5/rkYxEVWl2YNt8OPjPzcJLRCK2EKNwxwLVciUN01ZVZje 4UATyV05Ak6OBR1xlivv58K8xBXIrEIGFi/i1Bv3hcynJn49f3rRy7i2tx73VqyP6p4xHys6J4gBlT DlDuYFNYgZOS9ns7nhWs330jKGM+n/Ve6Bijr8TZUWmS739VHIK1XheVoGO8MALvZYR7lYjWQxk7te zN3KB8uZMYLw4tffh3DWMugu5QWx83h4DmY9SwAFTeWxJHgfVd61L57TxMmcBGppJMhwa8Py3HckCk xpuotr/Y7ES0tRg55lAJDWSiZ61r425mW88GZC33y0LpU8/wATFppWYkOpqVr2cTh2GCJZa2BnB3fF crJbCtjAKlf1ZPQSVESwKcGD6VG1xqp1txiBpFfomA0ek= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220624_080736_087876_8CF449E9 X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The asm macros used to create the initial ID map and kernel mappings don't support randomly remapping parts of the address space after it has been populated. What we can do, however, given that all block or page mappings are created at the final level, is take a subset of the mapped range and update its attributes or output address. This will permit us to make parts of these page tables read-only, or remap a part of it to cover the device tree. So add a helper that encapsulates this. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 70c462bbd6bf..7397555f8437 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -263,6 +263,39 @@ SYM_FUNC_END(clear_page_tables) populate_entries \tbl, \rtbl, \istart, \iend, \flags, #SWAPPER_BLOCK_SIZE, \tmp .endm +/* + * Remap a subregion created with the map_memory macro with modified attributes + * or output address. The entire remapped region must have been covered in the + * invocation of map_memory. + * + * x0: last level table address (returned in first argument to map_memory) + * x1: start VA of the existing mapping + * x2: start VA of the region to update + * x3: end VA of the region to update (exclusive) + * x4: start PA associated with the region to update + * x5: attributes to set on the updated region + * x6: order of the last level mappings + */ +SYM_FUNC_START_LOCAL(remap_region) + sub x3, x3, #1 // make end inclusive + + // Get the index offset for the start of the last level table + lsr x1, x1, x6 + bfi x1, xzr, #0, #PAGE_SHIFT - 3 + + // Derive the start and end indexes into the last level table + // associated with the provided region + lsr x2, x2, x6 + lsr x3, x3, x6 + sub x2, x2, x1 + sub x3, x3, x1 + + mov x1, #1 + lsl x6, x1, x6 // block size at this level + + populate_entries x0, x4, x2, x3, x5, x6, x7 + ret +SYM_FUNC_END(remap_region) SYM_FUNC_START_LOCAL(create_idmap) adrp x0, idmap_pg_dir