Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp91802lqm; Mon, 10 Jun 2024 13:50:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3BJB4s3OfRPf+Wk8XHNk5w2sWzRG6uA1XyvAlBdT35iqtpDg/z5J/UZbJxlUNwsUWWPaeytC1X59KQazoLpjUjijC21RMd1HC0QyS2Q== X-Google-Smtp-Source: AGHT+IEDsoU+ue0y0APg3Bk+najpHC9Jhfl4jhPXzIAXEZzgoDUTgJKMKCpDTALaLZXdmPuKjHtu X-Received: by 2002:a17:90a:c48:b0:2bf:c6fb:ec34 with SMTP id 98e67ed59e1d1-2c2bc9bc84cmr9977872a91.8.1718052604897; Mon, 10 Jun 2024 13:50:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718052604; cv=pass; d=google.com; s=arc-20160816; b=hhCpC5T5s6u5whmZPdUK8/x3SJ9goxYxlZEuttHo6GXua02qc2vLz3qhAE5JEUMm4u 6gH/sGvBcnCnEqWijc8XLzs+1FEg+sQUBSyyaswn4/mjeeODb5Wb1LBYmIOWez+aYe3R HnJCr2NnlunwR20mWql3TVSj4cSdImbroDcXpRVa8pDuR6eE+JqKP5bipbdTX7C5DmAB ave7Xm9iPn/woHzfWO5ZMXCeiWDwbGtQaELZFQ1GyVOG/RHuySBxssfXnVDyMIH1tXrM ss+TRgMqkxVas6FHKb3k/ulgcj2LGmNRM5364iz4q3c9AsY1f4/vX+J01M9ecKqRK4JP P4pw== 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=4qfyjvbDWrpefy/IccuU+mysaPiaDQ5iZokqr2UwBLY=; fh=gOiB6O4qTz0lnjzVhoJ4fPMl6n+fqzmQ+latPH+Ar/Q=; b=k3vBoAwPLFjXT/9ARX8CTNfeSDE1D2DsVQ2T7Q+MPROdz/ju1izkW/Pt0teBo9mK50 k/1vL3MXqrMaep4sc4DQevGAtWyt5uEFUPj7DzTVT1poMPZfcjjfc0T2+D4wA/5s0QUk w4F3H1Je2HUdI1cojBylDnpaegAiHTpDCL6WBBvqXrtI+o9nLNKW3WtRGQJCAeD6gqQh kyVm3SSOv/cjcYpAzV/vAWIBYkBibbXpGtndEtVKYbtTf/4SigqTwmXIDZ/Eqc2RKt1C Lx7xqKLzHKSbf0hC5/TRHdN4ZQFjeqSa6ktaZ8roTYm80zpD1qpKop5qiz1qaLLh3Uvg B8UA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=oNUVm+WZ; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-208881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208881-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2daf47aafsi4446321a91.190.2024.06.10.13.50.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 13:50:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=oNUVm+WZ; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-208881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208881-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 28B232857E7 for ; Mon, 10 Jun 2024 20:49:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4EE9146D54; Mon, 10 Jun 2024 20:48:50 +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="oNUVm+WZ" 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 CF1A8132117; Mon, 10 Jun 2024 20:48:49 +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=1718052530; cv=none; b=nxBhLC37elo6eICj5KF9dpMQq10IwBwJigx+HHPvuZdqirDX94WdLK8uYJTzT0iZL3phR+4Ho5H/dS2VJexYRwqXsn+ROah6giK0u1qbdvk8/2kb5csxpnUwgxMZHcU0fQn0L/DqkYirtnOkuh6EOiaJI4TmtvkCt0Za42vGut0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718052530; c=relaxed/simple; bh=MfMv4iuvVtYp4fD/Tz2vUcjF5O+YDb2bOLk4u2a4UXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HSEYMow6p0P3hW5SY60u5eogdurcoXqg4GSv2ef+329AERUcM9cLjlNQGRP2X5Tf5zX4aoq7QLHy+f/fY4A2qspOT8m7ad+3EiGpxnWchMhfRv53DPx3lE6HDr0617mwr+fywslgP7t8rANmAnG2ooJotzmycr2e5rwz0EcLwvk= 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=oNUVm+WZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12469C2BBFC; Mon, 10 Jun 2024 20:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1718052529; bh=MfMv4iuvVtYp4fD/Tz2vUcjF5O+YDb2bOLk4u2a4UXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oNUVm+WZChQbUcGuxj0iePgzWN/STCk1UDe6eSft6fNqLQzRWj+cEg6N7Iub4DgQT gFmRbO2VfLFjfkDGuPpTzofcmjldor6JMmMVNRboHNJ+QDhCRD1vXvPcqriY2jlZwk nb0xo8U5Gn6m4lnOBGwcfoDV9Lp536H4cH2d1m6E= From: Linus Torvalds To: Peter Anvin , Ingo Molnar , Borislav Petkov , Thomas Gleixner , Rasmus Villemoes , Josh Poimboeuf , Catalin Marinas , Will Deacon Cc: Linux Kernel Mailing List , the arch/x86 maintainers , linux-arm-kernel@lists.infradead.org, linux-arch , Linus Torvalds Subject: [PATCH 2/7] add default dummy 'runtime constant' infrastructure Date: Mon, 10 Jun 2024 13:48:16 -0700 Message-ID: <20240610204821.230388-3-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.45.1.209.gc6f12300df In-Reply-To: <20240610204821.230388-1-torvalds@linux-foundation.org> References: <20240610204821.230388-1-torvalds@linux-foundation.org> 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 adds the initial dummy support for 'runtime constants' for when an architecture doesn't actually support an implementation of fixing up said runtime constants. This ends up being the fallback to just using the variables as regular __ro_after_init variables, and changes the dcache d_hash() function to use this model. Signed-off-by: Linus Torvalds --- fs/dcache.c | 11 ++++++++++- include/asm-generic/Kbuild | 1 + include/asm-generic/runtime-const.h | 15 +++++++++++++++ include/asm-generic/vmlinux.lds.h | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 include/asm-generic/runtime-const.h diff --git a/fs/dcache.c b/fs/dcache.c index 8b4382f5c99d..5d3a5b315692 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -35,6 +35,8 @@ #include "internal.h" #include "mount.h" +#include + /* * Usage: * dcache->d_inode->i_lock protects: @@ -102,7 +104,8 @@ static struct hlist_bl_head *dentry_hashtable __ro_after_init; static inline struct hlist_bl_head *d_hash(unsigned long hashlen) { - return dentry_hashtable + ((u32)hashlen >> d_hash_shift); + return runtime_const_ptr(dentry_hashtable) + + runtime_const_shift_right_32(hashlen, d_hash_shift); } #define IN_LOOKUP_SHIFT 10 @@ -3129,6 +3132,9 @@ static void __init dcache_init_early(void) 0, 0); d_hash_shift = 32 - d_hash_shift; + + runtime_const_init(shift, d_hash_shift); + runtime_const_init(ptr, dentry_hashtable); } static void __init dcache_init(void) @@ -3157,6 +3163,9 @@ static void __init dcache_init(void) 0, 0); d_hash_shift = 32 - d_hash_shift; + + runtime_const_init(shift, d_hash_shift); + runtime_const_init(ptr, dentry_hashtable); } /* SLAB cache for __getname() consumers */ diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild index b20fa25a7e8d..052e5c98c105 100644 --- a/include/asm-generic/Kbuild +++ b/include/asm-generic/Kbuild @@ -46,6 +46,7 @@ mandatory-y += pci.h mandatory-y += percpu.h mandatory-y += pgalloc.h mandatory-y += preempt.h +mandatory-y += runtime-const.h mandatory-y += rwonce.h mandatory-y += sections.h mandatory-y += serial.h diff --git a/include/asm-generic/runtime-const.h b/include/asm-generic/runtime-const.h new file mode 100644 index 000000000000..670499459514 --- /dev/null +++ b/include/asm-generic/runtime-const.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RUNTIME_CONST_H +#define _ASM_RUNTIME_CONST_H + +/* + * This is the fallback for when the architecture doesn't + * support the runtime const operations. + * + * We just use the actual symbols as-is. + */ +#define runtime_const_ptr(sym) (sym) +#define runtime_const_shift_right_32(val, sym) ((u32)(val)>>(sym)) +#define runtime_const_init(type,sym) do { } while (0) + +#endif diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 5703526d6ebf..389a78415b9b 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -944,6 +944,14 @@ #define CON_INITCALL \ BOUNDED_SECTION_POST_LABEL(.con_initcall.init, __con_initcall, _start, _end) +#define RUNTIME_NAME(t,x) runtime_##t##_##x + +#define RUNTIME_CONST(t,x) \ + . = ALIGN(8); \ + RUNTIME_NAME(t,x) : AT(ADDR(RUNTIME_NAME(t,x)) - LOAD_OFFSET) { \ + *(RUNTIME_NAME(t,x)); \ + } + /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */ #define KUNIT_TABLE() \ . = ALIGN(8); \ -- 2.45.1.209.gc6f12300df