From patchwork Fri Jun 24 15:06:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12894754 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 62CCFC43334 for ; Fri, 24 Jun 2022 15:13:36 +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=Mi0bMt1DD5mhEvc0PI2q1brtA2xYXMhEcA6q6XvG1QE=; b=fLmCzLqTB8ZE/g 2jIWAwdDU3XPf0jdmADXKB/QlU3LmWFvfLacX6LLqsNLqnTMka4U/gv2yFHlkT0V7llCHIphfsMVQ NokwknHAez308KVjGAhfCCr2+y9keI8bywlVSzU6BmzY2iCL+i6uUU9hExF32+rPK6gBF7JJWKfhQ xeby7TXgAcTc4BoU2RDW2Vfb8zPElVi0IxP+7mVl+YPv2Hqt2F0FKjK050HxC3QB72+YQJ4/tNhYX dnFj5chLrqzNt5NOop5xwdWCO8GhdLUbPfDi/Gsg1MeJU8Vj3jffMVUtPFHAWVxM7aAc4JIAbcmHJ tAkK/2YQ3I7onBXvfKIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kyw-002kpw-2h; Fri, 24 Jun 2022 15:12:26 +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 1o4kuM-002iTz-QO for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2022 15:07:44 +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 6AAD5621D5; Fri, 24 Jun 2022 15:07:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F2DC341CC; Fri, 24 Jun 2022 15:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656083261; bh=3M3w1vJqY9mv8D4SlAcYAqDWgq2ma+xNAc+sGP2xOWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HwhrtEfbZuqcDNyMlAaLa5GnKmTsixP3/mdPxCGDsZr3z69sYpcMr5p+ngogUAp+U VUAC1kmxPpYM17DH6i6v9k4yW0FqRqw/oOuk3iuQ6Oh4Uz3ghVf9T0R7HlbMg43DBC 6Ea9uEre39Cu3tCMz1ldKzp6r/syh4HcHLXf34GOEeIx1B839CeVtmCnqCd6j3+2VF QmqIq+3zvKqqGQWnxvRbjUwtfVfIlsURk2Kxryz+UCkIE+bBdLH3BuF4HK8Bo6DmFk q7hnqeyLkPaXm6XTo+pcjFWpCMj8ZgVLWl8U7WDyhf1Ne3In1s3aj34eHJFyToWvXt KXLT6u6jtAnoA== 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 14/21] arm64: head: create a temporary FDT mapping in the initial ID map Date: Fri, 24 Jun 2022 17:06:44 +0200 Message-Id: <20220624150651.1358849-15-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=3280; h=from:subject; bh=3M3w1vJqY9mv8D4SlAcYAqDWgq2ma+xNAc+sGP2xOWc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBitdL+Ijj/1XmmfyvHFzVRuLziz1o8TEy6KFnBQyZN PWEkwFeJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYrXS/gAKCRDDTyI5ktmPJKYoC/ 9vOEJKzv6p1FdqZLxdBas+3Q2HsQcZ7/DXkrVHGg0alY1VLh26Sw2ZIU6pOdVGLfeeuiWwh2VmvBDL vl7R7YAJ0w4MA7WVQ+EKGwjYv0ob9Sy7cxrmMSMkXnvGnAkOPfv33dEuD78pGaeqPorVnRwJ80O/mj xxh/18Pc+kMbwXKYGIRn0QTXPLu7U0ytHGP0iH9NBIYXyXsVTeL1PMVXhmcoirzIxZdsuqr3AWj1ih uujl+C+mQUo86+CcMEAzrw44p7LNm+WA1H+UTf9o6wIHIXtq2vEMVG6Dgngj3kynbiixRYPruIPguM ArN9D0vAJ+RVf8TwEEFFXE3vhEWqLKomvqKFNFnu+plqRkvmHBsB/GJmddpqgWAtWCuRvdV5yYudkZ 8WIcXIKZgHnINsOPMx+rq/CDOHgHkc71pLZj1YFt+njRoTNnqspkJCXwEy1q553eU9VLsYedyRogHv 5IjfvolSB6nyUIEb/Zg2FmatR8DluKn271mROL5LVF8us= 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_080742_994385_120C203A X-CRM114-Status: GOOD ( 15.82 ) 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 We need to access the DT very early to get at the command line and the KASLR seed, which currently means we rely on some hacks to call into the kernel before really calling into the kernel, which is undesirable. So instead, let's create a mapping for the FDT in the initial ID map, which is feasible now that it has been extended to cover more than a single page or block, and can be updated in place to remap other output addresses. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/kernel-pgtable.h | 6 ++++-- arch/arm64/kernel/head.S | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 5395e5a04f35..02e59fa8f293 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -8,6 +8,7 @@ #ifndef __ASM_KERNEL_PGTABLE_H #define __ASM_KERNEL_PGTABLE_H +#include #include #include @@ -88,10 +89,11 @@ /* the initial ID map may need two extra pages if it needs to be extended */ #if VA_BITS < 48 -#define INIT_IDMAP_DIR_SIZE (INIT_DIR_SIZE + (2 * PAGE_SIZE)) +#define INIT_IDMAP_DIR_SIZE ((INIT_IDMAP_DIR_PAGES + 2) * PAGE_SIZE) #else -#define INIT_IDMAP_DIR_SIZE INIT_DIR_SIZE +#define INIT_IDMAP_DIR_SIZE (INIT_IDMAP_DIR_PAGES * PAGE_SIZE) #endif +#define INIT_IDMAP_DIR_PAGES EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE) /* Initial memory map size */ #if ARM64_KERNEL_USES_PMD_MAPS diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index f1497f7b4da0..8283ff848328 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -83,6 +83,7 @@ * * Register Scope Purpose * x21 primary_entry() .. start_kernel() FDT pointer passed at boot in x0 + * x22 create_idmap() .. start_kernel() ID map VA of the DT blob * x23 primary_entry() .. start_kernel() physical misalignment/KASLR offset * x28 clear_page_tables() callee preserved temp register * x19/x20 __primary_switch() callee preserved temp registers @@ -348,7 +349,7 @@ SYM_FUNC_START_LOCAL(create_idmap) #endif adrp x0, init_idmap_pg_dir adrp x3, _text - adrp x6, _end + adrp x6, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE mov x7, SWAPPER_RX_MMUFLAGS map_memory x0, x1, x3, x6, x7, x3, IDMAP_PGD_ORDER, x10, x11, x12, x13, x14, EXTRA_SHIFT @@ -362,6 +363,17 @@ SYM_FUNC_START_LOCAL(create_idmap) mov x6, #SWAPPER_BLOCK_SHIFT bl remap_region + /* Remap the FDT after the kernel image */ + adrp x1, _text + adrp x22, _end + SWAPPER_BLOCK_SIZE + bic x2, x22, #SWAPPER_BLOCK_SIZE - 1 + bfi x22, x21, #0, #SWAPPER_BLOCK_SHIFT // remapped FDT address + add x3, x2, #MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE + bic x4, x21, #SWAPPER_BLOCK_SIZE - 1 + mov x5, SWAPPER_RW_MMUFLAGS + mov x6, #SWAPPER_BLOCK_SHIFT + bl remap_region + /* * Since the page tables have been populated with non-cacheable * accesses (MMU disabled), invalidate those tables again to