From patchwork Fri Nov 11 17:11:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040641 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 35436C433FE for ; Fri, 11 Nov 2022 17:28:28 +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=piFqmlrdBPzkcayx3KyAntKc+RaCJkM6u6JDMPvH4KI=; b=ywOmwXHhOYbtXj qyFtvKx7VD1XjNdE97gX7dJgNHpnr/KILyrFBo5Ba3+v4lTaxUckl9dzHoTY4gzxTQ2tCRhPRvKhp WD3OLDAoQrHNfBhzTWcWDHyhghKjM9tDcPYWNiGMe3yg+VkJAc+yzYYd9QWVsFsTJjRJNESGlCaBP v93agOfTsLY9BQUvSFZN/zuUsftFsFYF7MfhtC9bF4ubAHNbZzPc7tV2aUyndFqVydHICT9vqx3tO +LYZjxT4rBY7loYNJuQHv+lOJ0dIJZvMKGP8mfxO7mCOYPvr+6FogO6prIiZVcOULnukU6zOJMiRT aiJMiiwEvMXmo3UeFThA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXoB-00HFPq-EL; Fri, 11 Nov 2022 17:27:16 +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 1otXaV-00H7vG-Mv for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:13:09 +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 4BC4562068; Fri, 11 Nov 2022 17:13:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDB9AC4347C; Fri, 11 Nov 2022 17:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186786; bh=yeHmNwCi2DjXiIunUjsDLpeU+2aibBavxEszHoOh7S4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ajJdHNRRSoqQE4wlCnC8pAdyNSh2Ca1l1fH7eAybGFecHYq6N4b4GFRe0loOP7+th vU52TFzp6GPLr1zyJdJFS9LYqHHp67JtKiQkrABttPCQWlizOA+agTxXMqnE0axZfx vjcJ4eV2hRHhmggph4En18vqxJKUM+DpN+pzpzdLCwkTBJBSXhIUvCavq/wUhfbplK zgZ/risbYC+jbFDtTeQGLP9I/StGjLmQvbRCpR10MZLw4a2eBKx5LWvJfpblgP91xU GaNFdsYA80OYc3bBVTf+1FPpB9EkgDhKLG/oXMPsULYKARmA4eS0FDuxuz9+2tT0Fs DUux8TyWhe11g== 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 v7 21/33] arm64: head: Run feature override detection before mapping the kernel Date: Fri, 11 Nov 2022 18:11:49 +0100 Message-Id: <20221111171201.2088501-22-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org> References: <20221111171201.2088501-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2887; i=ardb@kernel.org; h=from:subject; bh=yeHmNwCi2DjXiIunUjsDLpeU+2aibBavxEszHoOh7S4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboJMWTQ9o198WCsxSUOlG3E8/hL1g0EiQ6Ba7/AC Xf7aLiOJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CTAAKCRDDTyI5ktmPJKNZDA CTmcY44I9GBzYmpyDiRZdnmn0aPAPP/dyuvv44Y4hEDtX/ABpmt9pxU84d7PvrDMx+NgsRWJInxoKo S0p5Wpgmm8Xc72geCVR5oCiydmby+lSDFsTXc3no8L6QJoTBxCnRJ2pyFYcyXmWp6LvBmtNb6NTqqd Of1YNycrUOtKGXbGf/6e2un646jl7x6DxlOzayahRyIm0zRyss6g2tteIjCulnuIsxw4ZO1jCQXbyE Ox3C8VtkDIGNdTuciprDznL+GQVVrLt5N1TR2/tsfKHe2aRRz9/Dwv1uJ0X9h2HG8OD+Sd8VrwNFci jDI0RMiGI2uZGwc8TdipO0SekEAyvAMBhCMUdBpzh21D+ptOg0qDPzh2wRHCrD/6uTLlxWqh+taSeA KNmF92n4ME7NPlAzgChbabqBAZpBVM0BMQbj3WRwB5c5Z3r+ejBQqLYwPsG44eacLqx2pMN+2XhB8Q 3z0glfu82tlLHquz4SBfXOE/m22HiRC0qiuh3FBXRc6N4= 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-20221111_091307_874150_0A2C1FB3 X-CRM114-Status: GOOD ( 14.65 ) 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 To permit the feature overrides to be taken into account before the KASLR init code runs and the kernel mapping is created, move the detection code to an earlier stage in the boot. In a subsequent patch, this will be taken advantage of by merging the preliminary and permanent mappings of the kernel text and data into a single one that gets created and relocated before start_kernel() is called. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 13 +++++++------ arch/arm64/kernel/pi/idreg-override.c | 2 +- arch/arm64/kernel/vmlinux.lds.S | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 0e7aaa65ea174efc..9ea7f4e355ef5849 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -439,9 +439,6 @@ SYM_FUNC_START_LOCAL(__primary_switched) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif - mov x0, x20 // pass the full boot status - mov x1, x22 // pass the low FDT mapping - bl __pi_init_feature_override // Parse cpu feature overrides #ifdef CONFIG_UNWIND_PATCH_PAC_INTO_SCS bl scs_patch_vmlinux #endif @@ -698,12 +695,16 @@ SYM_FUNC_START_LOCAL(__primary_switch) bl __pi_memset dsb ishst // Make zero page visible to PTW -#ifdef CONFIG_RELOCATABLE - adrp x23, KERNEL_START - and x23, x23, MIN_KIMG_ALIGN - 1 adrp x1, early_init_stack mov sp, x1 mov x29, xzr + mov x0, x20 // pass the full boot status + mov x1, x22 // pass the low FDT mapping + bl __pi_init_feature_override // Parse cpu feature overrides + +#ifdef CONFIG_RELOCATABLE + adrp x23, KERNEL_START + and x23, x23, MIN_KIMG_ALIGN - 1 #ifdef CONFIG_RANDOMIZE_BASE mov x0, x22 bl __pi_kaslr_early_init diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index 86d994424779bc0d..c21d1e9f43a11ba7 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -20,7 +20,7 @@ #define FTR_ALIAS_NAME_LEN 30 #define FTR_ALIAS_OPTION_LEN 116 -static u64 __boot_status __initdata; +static u64 __boot_status; struct ftr_set_desc { s32 override_offset; // must remain first diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index bebb88daf4c52039..3f86a0db2952600c 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -317,10 +317,8 @@ SECTIONS init_pg_dir = .; . += INIT_DIR_SIZE; init_pg_end = .; -#ifdef CONFIG_RELOCATABLE - . += SZ_4K; /* stack for the early relocation code */ + . += SZ_4K; /* stack for the early C runtime */ early_init_stack = .; -#endif . = ALIGN(SEGMENT_ALIGN); __pecoff_data_size = ABSOLUTE(. - __initdata_begin);