Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp501676lqp; Tue, 11 Jun 2024 10:20:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxyMdcPnRuAQX35YavFFA5hHqX7JtajEPOBWqk4dCzA39KAy249sg5ww8MLCuDsIN7A1XzNgArb7n/NFB6VKRi0GeFap8tTWCK25MUeg== X-Google-Smtp-Source: AGHT+IErXwdg0202B4pCaMoiaEuc6IWXf/fNQp6kBR8/99NKFRgGOX6+ZQ2aT2ZnkrZYBv7Ld2yf X-Received: by 2002:a05:6358:c022:b0:19f:17ea:2b49 with SMTP id e5c5f4694b2df-19f1fd15a47mr1621633155d.11.1718126441969; Tue, 11 Jun 2024 10:20:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718126441; cv=pass; d=google.com; s=arc-20160816; b=XOP++Q1tzvPPk/8EKifjEhqFY64yABDlkZ46H6ZES+iXI3zVtHzEpeEg2RCcoRa0Hd kYSzH1+3CPq8s/RNgHDbWAcQfTedaP9tq6Lj2tiOAaBrkclzOzb+K8jbbQLC1LUDoV/S FaU7lYrVreP979a8HBStdMjBquNKreCPN0E6UuNRtLUOePq/qxxSyYVcnL00sDcGhr4+ ZKm0WhQzLgNJcaKmR/OaN1uK61a1Gi7KtYwkgt66KTSQJQFsRTXA3sjt/GbNHj+8SBnr OvXUiKvNwcheYJe0KGXavdtBF/Q46YE3/c/D6/Aoh48Yih9PYBdzhGquQaZZAUboH15Q ZmpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SVgC0VpWNsBDdKqW1XEqhiwTwZmflNnZsaBYptxfMQA=; fh=3N7PuM35xgbBjVAxUpFd2p5kleiLLl9vAiHM+0/Fxcg=; b=QKdKTNyd9ny+4asBbz6QAJU5oclVjH+T+k7cZNNahPIFeWS3X2NzDOjh0T8CvYL8h1 /+TUGQNkj49AmpPADkBUDPMiQlUZFHOahbuasSztxvS08LRTxAHn9JHXO+LRQ2f3Teq2 xwgZHB2o2+Q5XrOaZM4xoJdR90ZFYMDt1S4W1tIJIIIcRudEf7Srio+pGSNfA1q9sHLX cU99sX0dqUNXlrdW8RE0w+SxBXkjw0rAcg2wCzYe7BQJHIpSrP9Hz+TZxEQ3dEBTf4Ac 7KsgaJMmCHeQHq+XNU3XUnRHQT1blDqlg4f6OOjQSyPLoz2kj9yynDMYN2qyXUhxWCFN +poQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=mbvjaAyC; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-210322-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210322-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b08162d6ecsi45318286d6.140.2024.06.11.10.20.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 10:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210322-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=mbvjaAyC; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-210322-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210322-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ABD491C24655 for ; Tue, 11 Jun 2024 17:20:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA8D54CDF9; Tue, 11 Jun 2024 17:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="mbvjaAyC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBB7222086; Tue, 11 Jun 2024 17:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718126434; cv=none; b=JX68yz6/YrrRoF/Mtnk7jqFQFkEgsIrhHUQIRsg6t22zJJEjo5SewlcH6x+xSuW+xfzwJBT0MHAjW6ulWk112UfVWq+0sTft5aSVHoK6LwYZs/pZaiJk36KI8QpleqazrW9mY3PoTiXfDr6N9fBAe11y4ZMXv+OHxrkQLgY1zoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718126434; c=relaxed/simple; bh=LDS+lQ1Dge7tph4L1/rDUIFeOC9KuOHV5hBkAT51FdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pf5fWG5CvkPhaZD2tc0ulBkWt+cOCX8Kk1Kh11qLj0ZEmpb7QpH7eFHNhfIIlBnNXW3i7BOQN41jzI4JAmZEdHm3dikh+PX7wUSyaCfgGwApXLLV/vSUCw4I8yEO8B/v0NMHir0MNPpji0YiSL4dXqONFpG/gYhqhOtOHULpScc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=mbvjaAyC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9C99C2BD10; Tue, 11 Jun 2024 17:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1718126433; bh=LDS+lQ1Dge7tph4L1/rDUIFeOC9KuOHV5hBkAT51FdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mbvjaAyCLpSpQDpTWrsS8DPAXe3ItDtfEu0qBwYlnVTtKMAVM+DPpmZPRK8DGXxCQ uD/2iYklY7z4+PlresI6jmYhtlRpDk0FU44m8N9KOtKc8a25L+VfsHBC+O/ivb3Mpr RaHkcgbZFG9biiGpi72Zc3xU9Ge0K5tv+CRZViGQ= From: Linus Torvalds To: Mark Rutland Cc: Peter Anvin , Ingo Molnar , Borislav Petkov , Thomas Gleixner , Rasmus Villemoes , Josh Poimboeuf , Catalin Marinas , Will Deacon , Linux Kernel Mailing List , the arch/x86 maintainers , linux-arm-kernel@lists.infradead.org, linux-arch , Linus Torvalds Subject: [PATCH 4/7 v2] arm64: add 'runtime constant' support Date: Tue, 11 Jun 2024 10:20:10 -0700 Message-ID: <20240611172010.287427-1-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.45.1.209.gc6f12300df In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This implements the runtime constant infrastructure for arm64, allowing the dcache d_hash() function to be generated using as a constant for hash table address followed by shift by a constant of the hash index. Signed-off-by: Linus Torvalds --- v2: updates as per Mark Rutland arch/arm64/include/asm/runtime-const.h | 83 ++++++++++++++++++++++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 3 ++ 2 files changed, 86 insertions(+) create mode 100644 arch/arm64/include/asm/runtime-const.h diff --git a/arch/arm64/include/asm/runtime-const.h b/arch/arm64/include/asm/runtime-const.h new file mode 100644 index 000000000000..8dc83d48a202 --- /dev/null +++ b/arch/arm64/include/asm/runtime-const.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RUNTIME_CONST_H +#define _ASM_RUNTIME_CONST_H + +#include + +/* Sigh. You can still run arm64 in BE mode */ +#include + +#define runtime_const_ptr(sym) ({ \ + typeof(sym) __ret; \ + asm_inline("1:\t" \ + "movz %0, #0xcdef\n\t" \ + "movk %0, #0x89ab, lsl #16\n\t" \ + "movk %0, #0x4567, lsl #32\n\t" \ + "movk %0, #0x0123, lsl #48\n\t" \ + ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \ + ".long 1b - .\n\t" \ + ".popsection" \ + :"=r" (__ret)); \ + __ret; }) + +#define runtime_const_shift_right_32(val, sym) ({ \ + unsigned long __ret; \ + asm_inline("1:\t" \ + "lsr %w0,%w1,#12\n\t" \ + ".pushsection runtime_shift_" #sym ",\"a\"\n\t" \ + ".long 1b - .\n\t" \ + ".popsection" \ + :"=r" (__ret) \ + :"r" (0u+(val))); \ + __ret; }) + +#define runtime_const_init(type, sym) do { \ + extern s32 __start_runtime_##type##_##sym[]; \ + extern s32 __stop_runtime_##type##_##sym[]; \ + runtime_const_fixup(__runtime_fixup_##type, \ + (unsigned long)(sym), \ + __start_runtime_##type##_##sym, \ + __stop_runtime_##type##_##sym); \ +} while (0) + +/* 16-bit immediate for wide move (movz and movk) in bits 5..20 */ +static inline void __runtime_fixup_16(__le32 *p, unsigned int val) +{ + u32 insn = le32_to_cpu(*p); + insn &= 0xffe0001f; + insn |= (val & 0xffff) << 5; + *p = insn; + *p = cpu_to_le32(insn); +} + +static inline void __runtime_fixup_ptr(void *where, unsigned long val) +{ + __le32 *p = lm_alias(where); + __runtime_fixup_16(p, val); + __runtime_fixup_16(p+1, val >> 16); + __runtime_fixup_16(p+2, val >> 32); + __runtime_fixup_16(p+3, val >> 48); + caches_clean_inval_pou((unsigned long)p, (unsigned long)(p + 4)); +} + +/* Immediate value is 6 bits starting at bit #16 */ +static inline void __runtime_fixup_shift(void *where, unsigned long val) +{ + __le32 *p = lm_alias(where); + u32 insn = le32_to_cpu(*p); + insn &= 0xffc0ffff; + insn |= (val & 63) << 16; + *p = cpu_to_le32(insn); + caches_clean_inval_pou((unsigned long)p, (unsigned long)(p + 1)); +} + +static inline void runtime_const_fixup(void (*fn)(void *, unsigned long), + unsigned long val, s32 *start, s32 *end) +{ + while (start < end) { + fn(*start + (void *)start, val); + start++; + } +} + +#endif diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 755a22d4f840..55a8e310ea12 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -264,6 +264,9 @@ SECTIONS EXIT_DATA } + RUNTIME_CONST(shift, d_hash_shift) + RUNTIME_CONST(ptr, dentry_hashtable) + PERCPU_SECTION(L1_CACHE_BYTES) HYPERVISOR_PERCPU_SECTION