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: 65546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2457592wrd; Tue, 7 Mar 2023 06:22:36 -0800 (PST) X-Google-Smtp-Source: AK7set+ki3q2qAoru0ciUJDU3f/6am+fVTarfE+yv5H4BpGGPOq1bfFN4bsPP7V2gmwo6DGgXz4/ X-Received: by 2002:a17:90a:c:b0:237:161d:f5ac with SMTP id 12-20020a17090a000c00b00237161df5acmr15597594pja.36.1678198956164; Tue, 07 Mar 2023 06:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678198956; cv=none; d=google.com; s=arc-20160816; b=N1FTlW4n6XGmHrKyEyjKsTM+hQDXvGF7KzGpCjv4/WcXKGBeh+zgV4SvBI/vToOch1 h9gN8xO6WM7kZjQ0Y8QELzA3q7jwEaelM7g7UVYSwllf2vPoCFINofyhCNmnRcVYHYC2 O1Xh424eEs0bFudvglpkTuKtbDrpZ8b9pFuXHbthWvDZZ125LpiffeAKA6rcBnmk+qDt WMbxaK4kMpE+nzXcKqWWr90+V7NfKPmD7pz+iP3Wq1uWenatK71xUPNtxiamVcvUoYwU SnC/sNagowcEYypCIycCSSE3v4Mcl3WeVHviCgOxan7I+w8G7cEOvFFsUx5A02MeVzIx Bfbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hbHuzZflIJ5k8jMOKMrYVtkeyuvYe+LcXtv5hg2MZDM=; b=FaAYQ0pMCF1W6fHfqaPIgdYjT9J3hq9xW11z5wZluEjyc4DczNkLesS/g49NE2ePPm 1MNO4LwBxsKPl2ZFksIxO3crph2PbU5wbwG2vixCisA6QFkImKszBXaMrPWU5ZJqIEOi WmLEht3T7GAY1OuUjFo/b4dR0I8cWr9u+BASAzXtXKxJ1JKvWU9HmsrGQCs665xPetQ2 c5sKzxscdHp3uKAknJ4oLNADWzZZnvvGgqtylELSaLcZyK/JXJwkLHYH5vXul0CrMODR lP+odLr0DKM0TfHzsAkiQUxWrqRskRsISgfTZL/9VDX2vzcg/hxiMLnDnyrv4hyMzsX4 1Vuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3W34T8r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 134-20020a63078c000000b004faee2d046esi11737764pgh.582.2023.03.07.06.22.23; Tue, 07 Mar 2023 06:22:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3W34T8r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231280AbjCGOJt (ORCPT + 99 others); Tue, 7 Mar 2023 09:09:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjCGOJG (ORCPT ); Tue, 7 Mar 2023 09:09:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED1B815CA7 for ; Tue, 7 Mar 2023 06:07:58 -0800 (PST) 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 3FCC961455 for ; 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-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759719149008407238?= X-GMAIL-MSGID: =?utf-8?q?1759719149008407238?= 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