From patchwork Wed Feb 14 12:29:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13556544 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 DEDF0C48BC1 for ; Wed, 14 Feb 2024 13:45:56 +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=BRHhyoO2AGJwzLEn0unfTNx3qbt8KuYB7iMDfU1Rpf8=; b=PT7a3EBjXEZb5giC34qiyLPgrQ qaFL/7+A/j3DSxkHhHPLRhUgS8mGz+YNxFfzfKUaCZnfjVzihm6XWFGS3/4wOGVoUqxnTSHoFVgIg mTvst2n+fZzQLwyWjJGo58hh/7xKWE/WZZ0+pv/JVSlBFkGGNWQVWFrqJRs6rpiY95VfKFMrEde+v 2Ycb/zAMGcdzc8NOeX6FYf5PYDc4APjpuEi3eIyOQ1eL3+nloXOKnZIHjVf1Gj1wO0siLr2QGWRRx tTxx00P00ETnfFmnGLzUzIzgOfuzzElgngu43lwQNnD4b+HuP9E7/wTZopSrEqfcjBIqwKN+rP6PG QTTWDi4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raFa5-0000000D3fG-3Elk; Wed, 14 Feb 2024 13:45:45 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEP1-0000000CoTL-3zJI for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 12:30:23 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-33ce2ba4ee6so327722f8f.0 for ; Wed, 14 Feb 2024 04:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707913812; x=1708518612; 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=ruvNrUrxPHYFlNpK26kQcD/B9UWA+NHp79ghm3N4TPw=; b=rEpU55nqCzUbSwPCfkQAQ9rH3arbW7h1IugvpglHzLVoV1rH1EwkuwKjEox7aNWFNt nl6BUUWlI/XbQ1M/HlIxPcXVZc3DEOMR7ppmKsh04RMWoKz/1/znQYd8KHRXUKrChJFB L++LKMKfkCpUgNh+S6MENFDN0wdK7cQdQjI9dmV4cHQZH1fRol0ZG1rkeZnVLeBlNm1k defqb3P72UdJpJkuKDwyJf4TrSyEtJDOL0VnyFGlZ3r1/4vZyf4BwEHlbCo/AKDaVlW4 9ijIPv6yxMSfnyrOfqRhhll4XpN/12meP9Np/UssTf3xMozLVyIE8QiTW4s5h+et8frL sepw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707913812; x=1708518612; 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=ruvNrUrxPHYFlNpK26kQcD/B9UWA+NHp79ghm3N4TPw=; b=lq6kPQWdtAAlZsolXkq5B2fv80fPIQTHyalef3+LsU1ypl++iy+/Cj+5IUQ/pUAMtt SibOyv7le7bI1LUVJReaJjra8HPRqk4Vt1oXlQ6v31CoUZkNqnVnbahaSOxjw7yzOLKF jKe2UHy5JSHBGgmGM7nyyWi2P7N9gej50HT57wcbRWnAuX4kch3N7klnfa3OvXYhOche cba4MH6XQ/CuzPIRb/iDQeAZ7QSqcIHQewyYZX6GJ9anBgfSDnHC5IFbMglIGpbtff2Q 2vFMmrDC/T8JLCUDBCfATQ1zZQYQ0rVt6dHcEX7cVy9OHNV74+GZffsjNCAYKAN/+xqe 1T3g== X-Gm-Message-State: AOJu0YxOFbStSbDnt7OqvCRdGAg44l10bEQHRX3TjeGNz/GoZcCipB12 YuMgBG2VE93Yvk1ZVcALtS0EqPo4J2sNRDh3qTmFMJ/uNhm1XrzxeGnS9fE2nSre6LkzBpwBkc4 x8KT92yryUevGysMW7eJsEUVRDG1w//LbWjDEX6VyQerXg+xuTbUanfvqKZOR471dWKW2BiAdxH 8odzv7ATwZ9SYlNEYXh9Fcf2xH/NMXcbQ6M4tFVVp8 X-Google-Smtp-Source: AGHT+IHVARgn30CiKknQ//jlLpFzTrA6E49oduOJKYbxNsyPry4qTVXmSI7wnDCwoFeb8VZhPnGsu7zn X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:a45d:0:b0:33c:e728:c88a with SMTP id e29-20020adfa45d000000b0033ce728c88amr3396wra.3.1707913812670; Wed, 14 Feb 2024 04:30:12 -0800 (PST) Date: Wed, 14 Feb 2024 13:29:01 +0100 In-Reply-To: <20240214122845.2033971-45-ardb+git@google.com> Mime-Version: 1.0 References: <20240214122845.2033971-45-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=ZqGi+ki4hTr1X+TLcrERZLO6aUgrgkKOKJLRLKyMpck=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXMJr5HWyT2JRw8dpBjn9Ome9UHjl98JnWLp+jhiheRK 6rat5podJSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJFE1gZJj69tWdqruTbz8y lbevzp2WyR4r0W8n09N4fV9OV3N2tgojw3ZBRsHKlsk38hW14kX2qWaf5/rw3P95Qi3v+x9NOXJ NjAA= X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214122845.2033971-60-ardb+git@google.com> Subject: [PATCH v8 15/43] 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-20240214_043016_429271_D756AA9A X-CRM114-Status: GOOD ( 13.88 ) 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