From patchwork Mon Apr 11 09:48:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12808888 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 A5DF2C433F5 for ; Mon, 11 Apr 2022 10:01:44 +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=2RtdSd2L5HeT7nD1BMrjLFXIUyLo8fqxry4RR7xhIEA=; b=isA8VNx/T8YA0L UCTn/86L7Sjr5eeUYgXqhKZGqsnGlNwmNY5bsW8sVA7X7CeyF+xJwAVqznTbz1dDe39lOBProZ/VH UxNoj6Ffs2ejo/WRDQSqGmKs69J0sEALGZMvPp7gtYVGOwiYsToG5ozv2NC2Di7le6HczQt5cmLkh 7x7iblCIZpyu81ouDgCgqC2EUl67dxdVwb7u0MYPNJ60bb0hYzrJUMh3OKg/X51OO97kPShYRGGew g7e7wvrWg1bnZsaBANFXllCKzx6Lq9cuv1DlZa1jABmNSP+x+cpAq4Wqno2F9pdCwT5ITr0T3Nsut 9iSIEQnCkB52zteT6PyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqqK-0087rc-EY; Mon, 11 Apr 2022 10:00:21 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqfW-0082LQ-AJ for linux-arm-kernel@lists.infradead.org; Mon, 11 Apr 2022 09:49:11 +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 A62C8611B3; Mon, 11 Apr 2022 09:49:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28460C385A3; Mon, 11 Apr 2022 09:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649670549; bh=F3be8Bl2OWrM+QxnbwAWqaDIE8d9sl2JmSobwHloz2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G819WruuA9Y9oawya7YT7CWi7+BAX/8v2AuMI/JlC7oVvqE2pgJe4N9Bn9x+6S6/K wQ772tpK6gTTLpJRik5Cjf0wJ+mjcvuL2HgUSMEiyuVPEm3NIHyp56MojF8waPAZo+ VYXpMco1y9857aUZkZaFXuDBjq64Cj0RJHE3bmyeLGCFhJLgFcJydr4yC5FLumkLAI Vw2X+FGUIAaPF52NY0qSz5KYFg0jCQePAsppi775B3O33IxRrQHF9Jyj7a9EAtj6GY ziMOsjDo/tGbbVjBrKxBpRi0aA9Af5TBLtVXQFgXfreWmXkBK5vm1Nky/GiAiV/4XB HNMY2wx6k62+Q== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown Subject: [PATCH v3 11/30] arm64: head: add helper function to remap regions in early page tables Date: Mon, 11 Apr 2022 11:48:05 +0200 Message-Id: <20220411094824.4176877-12-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220411094824.4176877-1-ardb@kernel.org> References: <20220411094824.4176877-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2095; h=from:subject; bh=F3be8Bl2OWrM+QxnbwAWqaDIE8d9sl2JmSobwHloz2Q=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBiU/lHRuF5psCGBCvTqubIc33ylcXyPLqTFqMroy5z 4YTK4gSJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYlP5RwAKCRDDTyI5ktmPJB5YC/ oClu5IeEtRKbfo2BZ7Cy8kmZ9lseFgFG36j3po4xZgFIcueDxqY46svaMfrSYeV/mgBiBkc9sNfklC L7daOcb4W1XFe5O4PEPPaVod1IsQZuDZv5OHzCITmzGIMBKdVcCW8tInJUA7NJH7PkbdOKETg6IDuh BxnYnbA1YiBLvlwYbMmPfnhaeYnCeKkJOc7Slw6cEAGJbPHPWOHlbEWr3GebsEIkbrHjO0HeA1i+bZ HsBrvX2RQRBH1yhgnY+9mhQOIqyFLPeK8roKWNx+hHU7O+K2hwjTvZuSbos9AdIgqGTVlVDQxzHqgl A3ngODVoIqWls3AsM11D56no16yOTYYQSvt6x7xOEKoGrSeHXM9YSJLstnAO1JI3ZFJqf4CV8rIBCE c7reuUXNYjRBK+OxQJOSi/4imPYv4SOtlL46Pv1SYfLv0t1z6IlXh73NYkXh/T1u8pDv7NivhO/BQ1 Qxj+RP4HN4rfdWBTYYOq1EQr7nk9S65cnO4d5xS3v9Pyw= 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-20220411_024910_465773_416ADA3C X-CRM114-Status: GOOD ( 16.00 ) 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 | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 70c462bbd6bf..6fc8f7f88a1a 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -263,6 +263,37 @@ 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 (inclusive) + * 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) + // Get the index offset for the start of the last level table + lsr x1, x1, x6 + bfc x1, #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