From patchwork Tue Mar 7 14:04:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13163800 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 8F3E8C6FD1B for ; Tue, 7 Mar 2023 14:39:19 +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=5ntq+NeBBzVX8oS8Avnj7dJc7aFMO/9+kFZ9qtBWpHs=; b=kc3asWNUISDmnu QCCtcJmsoqcIIsM+S8maK7OXIi3Gg9Otd5uVBJCVelXaTpmC1ZI55EqRu55inBE5SfsShk4Mj9j0H h3e4EueYrrm1VEYWyTSRuRiOgPSc+cyb0NKMh5ObPkx9GJJs3Z37+qe5xOUei4gNG8u4nppPOC3wb QzMM3sUrQBN4dMCOlppKoHrWRa2MggVBE8MPtWTcs1OQsBHhKf7Or6xkhjPb74ZfUXl0i+Cbv5e8s aD6xnBY3qb3ZhsrCQz3Igc4gA07CySNg97OZIpSlmyvyhynqSpFk2ajJ83/RJ2Nf2frmCWFeqEN8/ k7AtK01hhQXL9RKVcRqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZYS6-000rko-60; Tue, 07 Mar 2023 14:38:06 +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 1pZXyw-000eY3-L8 for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 14:08:00 +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 3F956613CA; Tue, 7 Mar 2023 14:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD50DC433A7; Tue, 7 Mar 2023 14:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198077; bh=5NPb4B7DLXdRfGBUFKwsc4EGZ/Nj6237LOVxsKjUH1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W3W34T8rh8RZYuV/7rNzp72cLllzIuLaA7QzKPle0lj3WaPJptvdI2zioMoVebCWv bu6NR7/hneCcKdNele7Hxe2Eht+ZulSb4D1LuQJzHiXJKJFmdyexvM3cuRblMpRT93 qJY6/bWJOyq7Gu6ISZwExtgpUT66owY03eGWzjdlWU3lwMCqGaLmNl7zNtBty4kh9X s9nzzGonQVCPxOdL/E/pJ9E6wz3uzPLKxlAnE4o/65mPCbQkx3uQDEcHXj6cEv5Aoy ADhLH5hUPmfpaZm8Z4z4ImiFtbEv44lNXq61crSY0xUWHWiy3vU8qCHqYV97q+71wo WplSaTarwOAvA== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: [PATCH v3 33/60] arm64: head: move memstart_offset_seed handling to C code Date: Tue, 7 Mar 2023 15:04:55 +0100 Message-Id: <20230307140522.2311461-34-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3180; i=ardb@kernel.org; h=from:subject; bh=5NPb4B7DLXdRfGBUFKwsc4EGZ/Nj6237LOVxsKjUH1g=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdJbBs68xHV729dDdOMVjnwHtLdeu8HsflazifWT7bG 53gVbKoo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAExEjY/hr1j7tCbOj3lvr/Re 3sdScD7jHyeXTj9rdL2LaMtLd8YjUgx/OFvaFKPczIS5K8IX2SU0frvSudJ5Qo3HKvdDfaUvghO 4AA== 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-20230307_060758_816714_10124D7E X-CRM114-Status: GOOD ( 15.38 ) 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 | 1 + arch/arm64/kernel/pi/kaslr_early.c | 4 ++++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 70ad180eed364906..81c2dd06420992ea 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -82,7 +82,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 */ @@ -483,11 +482,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 @@ -777,7 +771,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 5aa914ea919a1149..b7fa7fbf8fa543a6 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -44,6 +44,7 @@ PROVIDE(__pi_id_aa64smfr0_override = id_aa64smfr0_override); PROVIDE(__pi_id_aa64zfr0_override = id_aa64zfr0_override); PROVIDE(__pi_arm64_sw_feature_override = arm64_sw_feature_override); PROVIDE(__pi__ctype = _ctype); +PROVIDE(__pi_memstart_offset_seed = memstart_offset_seed); #ifdef CONFIG_KVM diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index f2305e276ec36803..eeecee7ffd6fa125 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -16,6 +16,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