From patchwork Fri Nov 11 17:11:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040646 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 A1DAAC433FE for ; Fri, 11 Nov 2022 17:32:06 +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=ejKy35skR77JSEQ2TCt7nkX18oXs/I7uohLNpDcuCS4=; b=DHzLX2CD9ZbdNX 7qlFKG3rPcM7FAQMGpvGEvgOCB1fVFgUzo2MwZr70Ka8X034ZrDIv4ZmvmWfkavrS+xcJCDBLE9ni tZzu0dwMSoCiYjDs9Ciel8DGK1SLk9j3nb9IxC3qr+RV/ZEVrlcWYr2H3ac6WiFKnRw91mipgw9Nj iUyCTCa55p4THMxEzkRY5LocRQ3Pw++NYpONYS/Z8rMIlernC3LXrY8PsY8bbxVaPmxhVEUH8jzVr U+ca+O0KpLii6aX+q1lsCF2tnpO7nrQqMzj8XFUV9pUQw2ilsjxOik8JnJArp6uwub8phuf3Om3+R ZKjqWeRBeH4O5rKB/5bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXrm-00HHLl-36; Fri, 11 Nov 2022 17:30:58 +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 1otXah-00H81v-96 for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:13:21 +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 BA2176205C; Fri, 11 Nov 2022 17:13:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E71BC433D6; Fri, 11 Nov 2022 17:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186798; bh=t0leZ0gGl6DxYzu8y9a9G4oLsChLGyL399/KcQIFWsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Faz+3LPqOTnV+Qdjr2QAy7APFNrwQiWNLSCpLYB3tfKmVtuXXd7+wHUS6tzQYInXk fB7OeXy4Jr73lwzAtrHLqOp4cgdylZ5DtAZ3VVViZvQpJVXKaK/yEEQBYRl1Itwmb7 08mCqAv2+veAuUPQgTFijbQ7fz1q0WUxNMQGICisgAcg2pXGed2K9g143nTCM1d4SD 8aHPtZMXumVzOPvC/j+lT+bTTDF7woKx+vRWSCuF1aJXTU2NRu15dkjBhJSbe2L8i+ wRtbuvG3vdhY5u4hTWvcjPX0OHpaqlYOupPaHHDvzyyNmUYArCyHYBezXmWM+0RjcG BF9cyws4JGj7Q== 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 26/33] arm64: head: move memstart_offset_seed handling to C code Date: Fri, 11 Nov 2022 18:11:54 +0100 Message-Id: <20221111171201.2088501-27-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=3986; i=ardb@kernel.org; h=from:subject; bh=t0leZ0gGl6DxYzu8y9a9G4oLsChLGyL399/KcQIFWsw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboJU7SEjZB7GJlOpE99yYBCB+gDbPNoB00vK4hRp WrgRociJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CVAAKCRDDTyI5ktmPJPjWC/ 43d/dPYLBUCbD7rS/nMbvZmxDrK/r6bIe5jJ15NYks47O70V3jboIrGoCMEuwB87nkF2xhfEcNfvyW eJKr/HTHDJjHEf3AIc9yQeejU86bEzme4uMOi06Cn1GWwtaiagL3hgYRi89zdUG6C6vismE+KZ+EOt IK5yJyxfcpAgv2RaHNQKNPimgg3kS9qInKsNp2nC6M8o4+oJWqRXNKJo14LetLLYxpgrxo3mkApsVS 7yU3XS9nshOEbze9rOR/tjrUoUe6IxgZctRMc+0nEg5lN8BydEk1NccFT2in4HyupoQp6fBMcoPett 1JOFCrlKDF/UfEp+SDkTBAyl7CwRYW83kw7+5Ub94fvoMb6+yB8VuR1Ez6gwSqPzcdADCXC8HzaUPk 1Gt4kySqTssHE3GG1yWdf8Qwjb0eiHrjb6WO4gPXBcqMQsLR9wXDVPNulCJn/sphWaJN73P0839/Yr 7O9BjXiG2AtGtfQVrNHLbu9iEirvlaLoXy7XGeJ9Hkzfo= 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_091319_457180_D3B75DC2 X-CRM114-Status: GOOD ( 15.47 ) 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 Now that we can set BSS variables from the early code running from the ID map, we can set memstart_offset_seed directly from the C code that derives the value instead of passing it back and forth between C and asm code. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 7 ------- arch/arm64/kernel/image-vars.h | 2 ++ arch/arm64/kernel/kaslr.c | 2 +- arch/arm64/kernel/pi/kaslr_early.c | 6 +++++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 5f1476c0f3a33d75..4b88ca8766133fd3 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -81,7 +81,6 @@ * 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_switch() physical misalignment/KASLR offset - * x24 __primary_switch() linear map KASLR seed * x25 primary_entry() .. start_kernel() supported VA size * x28 create_idmap() callee preserved temp register */ @@ -431,11 +430,6 @@ SYM_FUNC_START_LOCAL(__primary_switched) str x25, [x8] // ... observes the correct value dc civac, x8 // Make visible to booting secondaries #endif - -#ifdef CONFIG_RANDOMIZE_BASE - adrp x5, memstart_offset_seed // Save KASLR linear map seed - strh w24, [x5, :lo12:memstart_offset_seed] -#endif #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif @@ -705,7 +699,6 @@ SYM_FUNC_START_LOCAL(__primary_switch) #ifdef CONFIG_RANDOMIZE_BASE mov x0, x22 bl __pi_kaslr_early_init - and x24, x0, #SZ_2M - 1 // capture memstart offset seed bic x0, x0, #SZ_2M - 1 orr x23, x23, x0 // record kernel offset #endif diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 6ff6efbc1ce98ba6..6c6dd100a9cbadf8 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -41,6 +41,8 @@ PROVIDE(__pi___memcpy = __pi_memcpy); PROVIDE(__pi___memmove = __pi_memmove); PROVIDE(__pi___memset = __pi_memset); +PROVIDE(__pi_memstart_offset_seed = memstart_offset_seed); + PROVIDE(__pi_id_aa64isar1_override = id_aa64isar1_override); PROVIDE(__pi_id_aa64isar2_override = id_aa64isar2_override); PROVIDE(__pi_id_aa64mmfr1_override = id_aa64mmfr1_override); diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index 5d4ce7f5f157bb3f..37a9deed2aec9297 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -21,7 +21,7 @@ #include u64 __ro_after_init module_alloc_base; -u16 __initdata memstart_offset_seed; +u16 memstart_offset_seed; static int __init kaslr_init(void) { diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index 934e95fbd4278d0b..c46bccd593f2ff6b 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -15,6 +15,8 @@ #include #include +extern u16 memstart_offset_seed; + static u64 __init get_kaslr_seed(void *fdt) { static char const chosen_str[] __initconst = "chosen"; @@ -51,6 +53,8 @@ asmlinkage u64 __init kaslr_early_init(void *fdt) return 0; } + memstart_offset_seed = seed & U16_MAX; + /* * OK, so we are proceeding with KASLR enabled. Calculate a suitable * kernel image offset from the seed. Let's place the kernel in the @@ -58,5 +62,5 @@ asmlinkage u64 __init kaslr_early_init(void *fdt) * the lower and upper quarters to avoid colliding with other * allocations. */ - return BIT(VA_BITS_MIN - 3) + (seed & GENMASK(VA_BITS_MIN - 3, 0)); + return BIT(VA_BITS_MIN - 3) + (seed & GENMASK(VA_BITS_MIN - 3, 16)); }