From patchwork Tue Jan 23 14:53:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527543 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 860F5C47258 for ; Tue, 23 Jan 2024 14:57:02 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/6tqMSPehbNfqAt0noVQad9CpHD2ilVtoFnCNyt2K1M=; b=l6BTktV+geoMxAslRrQ5fjI8Uv fCEXdDcJ54mbICoi5Q0tUQXoLxcjXz9TIWh4MQ9uq9ZgLOrFacmWiNstctnQeQ2nVU/OX0ytdpLLw mJ5x95/bTOQKGtEnEupCoFT/xr71NMdzQh60Apr0n+wvOoADLYQonjPWs6+t6Cx4OJ7F+tGEIVhRp ih4Y+6F7gdxho9uWAsXGNUE/cWQX6vsBrNx1Q6MEVoATiny80iIpfv4tk66D5tofbcIQl7ST3q+de GLXCfWqjRQCT9LG670GjA9i4Y77xQX0SPgNktjxGkoiko6KS0QME9KZIfb5WqZ1JPAZfk3lhItGOW P/LwiDXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSICT-00Gue9-10; Tue, 23 Jan 2024 14:56:29 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIBZ-00GuCt-29 for linux-arm-kernel@bombadil.infradead.org; Tue, 23 Jan 2024 14:55:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GdG6OVFnEQ+dH+HNISsEfMCC9piil90r9HvYsrUMWtA=; b=VfZXW3ef9XDzoIqEqWJHyDwVJJ OhP/2cPyL0UFUZA5b0c+483/B8vpffdeb4Zwr7GBDW0zVGcuZp+oO99fUI0DEzx+JqGiPAIs+9MGy ZiMKbjL2A6bHe/7AOXxwZNN5twl5UAst5NPvGqehHW/2rgE8+vOZXLJ1iLoprbxfNQ4vsfZAvx4hV TDTHhdrmIjLQqQbcSYnJP1K0z6uILZw38UUR/2IYHy0ZofyWetqzj5aYDbz3Ryv4zTzVMuS56nof+ qBjW0Cz9RWBg52OQ0UocJNBjwaVCHIkat6ryV9NCAM+vM1jFalqWFVqT9Bus00aGw5LBBnKyDD9yb ulKBk3zg==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSIBR-00000003vON-0ewd for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:55:32 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5e6fe91c706so74933557b3.2 for ; Tue, 23 Jan 2024 06:55:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021713; x=1706626513; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GdG6OVFnEQ+dH+HNISsEfMCC9piil90r9HvYsrUMWtA=; b=oSuPcK4THvO79qf6+aQhG2etJsiPDMGBnoNaRcmIcsc0eSLMcRSJLz1cLUYPGiHv5E 6uIenKNzM0EkTj14s8MSPjkVDRenEcOtqUAR49ebp9qNZCK7ICtRpXgjyuj7MMu+ROiO jHfxZLR4GK2FtkNuYOBracZl5Bn0tQ8AJwNA/iPp6PpKJZCCqj+HtCS2t/M4YWtkcRlV IDEcS2Lo2SXsMFWmoU0z59f7IlgTuNJtQ1xCkdeEX9hwMi4zi/vDy3z9ZmLA2uMOxxe+ OI8+4W5zLSzIFck6ueP/a+ilI9KX6FmJ8AzzR5GXPblB1UyilV/sVsnTNfGzAYtmc5yO 7kTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021713; x=1706626513; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GdG6OVFnEQ+dH+HNISsEfMCC9piil90r9HvYsrUMWtA=; b=MhvEA11h4Pp4z9wpdkHPbFXvZICMc+8OmjS+8MtxViXZK14P5BpREpJO56kcsDnpQU 1aCGEBo+7XnmcCcqhuJZXn8WAE8tlQoIz2rx7cLsfEhduLGV3er7yF1keem1PZOiB+zT mveYWj6udbjCwPT5Ds7yz7UKWcffb/Vj2OYiX3bgFt6l8pwNkUbT9TuuZgPc1LxgsYnY Gv81bN+MIm+ATkaj9gYq5W1xb25wnflQiaGPYAuy+om8QJVJEQQKT8Pk6UuDoMIIxK1k 8Zfj5wsaTF1x14sYNbiP03Yde3K5zuPz3bS8P0jwWtYUEXltG4/GZJce/dH13bVxSFa0 1bGQ== X-Gm-Message-State: AOJu0YyND28RzDGFfkcMu4pcgg/x6w11rEhDDg2SbV3hHhqCPvvE1VX5 E4pxMha8LLK2MHIBNMDWwfpLoupIoW4U0D/GKw4PY+cKBeQ+RpHbMgujDl3Cwgb7sgNkb0pOUJ4 xwJiUAs8xymQUx3LLRZrTAH7GIz9Aj9NZOAmaBo6rkpqW8ucQR1LimHbfu/GQMlJDRGaolBAlrf vmXTH5SDZKHrJ43en5qTGFujHuvLS+YAeE9VBmKwHt X-Google-Smtp-Source: AGHT+IFb6HrsrThLPxS5Q4MyDJdhAdoBDbf5JN+4R/F0o8MmciXNnwLzCKVdeszHAGTVn/sgG9UBrj+B X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:8487:0:b0:5ff:a62d:e2a with SMTP id u129-20020a818487000000b005ffa62d0e2amr2937895ywf.4.1706021713059; Tue, 23 Jan 2024 06:55:13 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:21 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3177; i=ardb@kernel.org; h=from:subject; bh=msHSAl0RyM+v/A+LmM2ZEJKkw9FXy9rp8/sq2Dz3h4o=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pUdx0ywmlKa+mSMpWl1Ut+5tpTzLm3CmNrFnjrEz6 7/ZTTfqKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABPh42FkmCFw5NvcrabzPWbf 61hv6X5pjsfl1nQGpYcfKqS/ys4KKWRkeMokXjvzZcSr5uq9i4VZSrRkGKu3Vq1iT9S9uG7pUb+ 3zAA= X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-74-ardb+git@google.com> Subject: [PATCH v7 22/50] arm64: head: move memstart_offset_seed handling to C code From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_145525_728103_1A1C34B3 X-CRM114-Status: GOOD ( 13.86 ) 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 From: Ard Biesheuvel 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 b320702032a7..aa7766dc64d9 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 @@ -779,7 +773,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 eacc3d167733..8d96052079e8 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -46,6 +46,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 f2305e276ec3..eeecee7ffd6f 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