From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 6BEE1350285; Wed, 19 Aug 2026 02:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106552; cv=none; b=rr6KSn/XVCLpGk9c18lEkjXzRUyIGr0XAQ4CzFa+W3xYcow9zbinH40WnSWUmYmmnOBrc/IcInV7LA0PaTo3LuHWuPRLxFIQOBbvSbhjflUAFZfKnAZA8OzbMM2lXrnh0V1un8vOA/YxITqC4W62FEdYlzrrmhqsOZr5nFn1ofE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106552; c=relaxed/simple; bh=hSDaHlp+AtiPrqNRHKQvKu/6PNks2N1dJWDbN7fuL1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M3obCYh3yuV3cLmZLquVY2dZPjBiW1NRdl9M6VCITfSdhHphNAxMcyx29s7CRPvqKBa0ZTUGYG2V8bDMpa//O6zS2EZvmJ28jiYC0UrDzRQSj+Op6VXElFgsEyrrQO3ONauN7G9osrwf9s7ec77g9KF2tJn2nTYQsuSjs4GH4xw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=n2z84/Bk; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="n2z84/Bk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=gXUB1QrnxsrjbOi4xhXBQHCEC2KmzTwW0NuAmy9Ikto=; b=n2z84/Bkg38wflHDu1N8jwEOo2 ZhL3oGXbc/uFEJNt0XoVhkQqsRre2N2fOyTCQuNQcmupM5U4xH/zfSaLtYI1aRIDo/YO0g1gqt4Ju 7p9NoN2QQbxE+l00ISPoz7HIP+7oCZcG92EJgUl3QzGaqJjQh9auxNr8bS4ZA9nATHJaFhzpDvRmO UlKyIzG3ehc7I51bRyD7vFd+x0m4H27sXkgltjUagvY3qf8XeMChZzB0feZbvbrgL7xapazL7ucBq NhoOXUbeOhAb812rK3zQurHa3LPJNqJjitOwEpKMCimzS3v+RLDXhGMeQuH+MLoIeR1UI6irvfMur sXWvDxfA==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW39-005tfG-1g; Wed, 19 Aug 2026 04:29:07 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:00 -0300 Subject: [PATCH RFC v2 01/13] keys, pidns, fs/verity, riscv/vector: reorder '#include ' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-1-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Fix an include loop error in preparation for sysctl.h to include module.h: CC [M] arch/x86/events/amd/uncore.o In file included from .../include/linux/fs.h:44, <<< from .../include/linux/compat.h:17, from .../arch/x86/include/asm/ia32.h:7, from .../arch/x86/include/asm/elf.h:10, from .../include/linux/elf.h:6, from .../include/linux/module.h:20, <<< from .../include/linux/sysctl.h:245, <<< from .../include/linux/key.h:17, <<< from .../include/linux/cred.h:13, <<< from .../include/linux/sched/signal.h:10, from .../include/linux/ptrace.h:7, from .../include/uapi/asm-generic/bpf_perf_event.h:4, from ./arch/x86/include/generated/uapi/asm/ bpf_perf_event.h:1, from .../include/uapi/linux/bpf_perf_event.h:11, from .../include/linux/perf_event.h:18, from .../arch/x86/events/amd/uncore.c:8: .../include/linux/mnt_idmapping.h: In function =E2=80=98mapped_fsuid=E2= =80=99: .../include/linux/mnt_idmapping.h:231:59: error: implicit declaration of function =E2=80=98current_fsuid=E2=80=99 [-Wimplicit-function-declar= ation] Reason: - cred.h includes key.h *before* defining current_fsuid(); - key.h includes sysctl.h; - sysctl.h includes module.h; - module.h includes fs.h via elf.h > asm/elf.h > asm/ia32.h > compat.h; - fs.h includes mnt_idmapping.h, which uses *undefined* current_fsuid(). Note that fs.h does include cred.h (which defines current_fsuid()) right before mnt_idmapping.h (which uses it), but it is not parsed because the include guard of cred.h is defined earlier. Address this by removing sysctl.h from key.h, which does not need it, and adding it to files that actually need it. Signed-off-by: Mauricio Faria de Oliveira --- arch/riscv/kernel/vector.c | 1 + fs/verity/init.c | 1 + include/linux/key.h | 1 - include/linux/pid_namespace.h | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index b112166d51e9f584f84c52d0f84feb92ccd60df1..9eac47c99f114304521fdc53901= 8f3f84507e75f 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include #include diff --git a/fs/verity/init.c b/fs/verity/init.c index 3aa55dec88fc919792a2cb4be476f8481ef78a9e..d460eef74fcfe49f6cf69974a81= 94a65de486819 100644 --- a/fs/verity/init.c +++ b/fs/verity/init.c @@ -9,6 +9,7 @@ #include "fsverity_private.h" =20 #include +#include =20 #ifdef CONFIG_SYSCTL static const struct ctl_table fsverity_sysctl_table[] =3D { diff --git a/include/linux/key.h b/include/linux/key.h index 81b8f05c68985c6f0a5c5bbe0f1fd6661912c618..a74f8f1b7936d6ede584c0a8cd5= 20f858f6a9758 100644 --- a/include/linux/key.h +++ b/include/linux/key.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index b20baaa7e62b755e7e561fcd8018e2b61213503e..94b23471c7dec135e24c4c0c1fd= bf841cea2e5de 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */ #define MAX_PID_NS_LEVEL 32 --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 561E1395AFA; Wed, 19 Aug 2026 02:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106564; cv=none; b=ML0XQBlpOw3KVReLL8na+e+is5wRXSzpIv5rSChJsugZw7MhRDqqgLdGRCLgm2sWj6d09gcvAX/XXRbzJWSL13klbsnkNsepIXx70dx+PFVtnRbE6uA6JZYhLoKvRXkYoxQDAk2D85olX1aorjdZuqLv4cgUbSfyvbB/UsRKQtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106564; c=relaxed/simple; bh=xo2gf3wu4vuqcbt5RW3cYCzb8jBOHYN7pFK1H4VPmAk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BL4h7EJqcmBbs5HrToEfEiFssskcJytmTwWv3cXr4FFUQoHue3WGEuv+4Akc3Ehf+BBOAz5v8bSOfo8j9sIWoeVWadFKZKFYKO4FZRcoRMhsWaStxY9xL+b5VZRpuRS17D2ET/NUS91/PZNfsbFtU9slONd5aNribm2uZ1skGIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=mGygRzJM; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="mGygRzJM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=rX/5Ncw6TkYVmkpNCpB1GzMuhqdAFux3EzHGz3ko38I=; b=mGygRzJMb4At3JlLUZ2Tw5P/gh o5C97RTeg2b/Rt6Q2d8QZ0eJhQSVhJiOv7v3hVBfNQMJ7Cu88OKJxSaWb/AclxAoh5QSctb5l51VP Oxp9QFhBLJ/Ac5uZMDWXW8emG8zspfpKKZadDzAsu9WynmP72ivYHVsHyJKb6c7jIOccteHDDSaQb 8KT+ClPTJdD96fhNbSapoj1mRBnfGUIuOiHM56R6+hkoLIY781acUFmjVAKjlos6AOw/A6X7BoK6p /OBJnCBmnZGAYtPdChJBsxclxsMqBF8xHR+ARRw8ASvt8LYTqbgSfFvfV8F6qE3+LxwkN6hR7hn97 XCDLWwRw==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3G-005tfG-5O; Wed, 19 Aug 2026 04:29:14 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:01 -0300 Subject: [PATCH RFC v2 02/13] proc: add config option SYSCTL_MODULE_ALIASES Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-2-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Add a config option for the 'sysctl:' module aliases feature. Signed-off-by: Mauricio Faria de Oliveira --- fs/proc/Kconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index 24f5a36f45df8b1d6831a0f4011c1f6b1987cb52..e6591ec4bcf0ab2ad96ca7dc90b= 831b2f9873ac2 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -98,6 +98,19 @@ config SYSCTL building a kernel for install/rescue disks or your system is very limited in memory. =20 +config SYSCTL_MODULE_ALIASES + bool "'sysctl:' module aliases (EXPERIMENTAL)" + depends on SYSCTL && MODULES + default n + help + The /proc/sys files registered by a module do not exist until the + module is loaded; meanwhile, userspace cannot find or access them. + + This options adds 'sysctl:*//' module aliases for the + /proc/sys files registered by modules, so modules for nonexistent + files can be loaded with 'modprobe sysctl:/proc/sys//' + by userspace when needed. + config PROC_PAGE_MONITOR default y depends on PROC_FS && MMU --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 9E61637C929; Wed, 19 Aug 2026 02:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106565; cv=none; b=NjCSfDfBMDRjWC66uGtq1sQpWgUhZ5FGodrYXqKrZ0z2y7lABJSEj5LlhfUPCO4OMhuH9TGs3Cni5CI+NiEtddRwjKhlxQLbfYbIXN97JOU6Kz1WdyTMa2DhXqqJ3HZ/tiM/E6jTqRvZyCpHZs1uhgsTXXoT8zTZocpKIqFzRLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106565; c=relaxed/simple; bh=xN9X+x0LVCXMU8bla84/7K1eyKzDVUW3nRlx5tnwr54=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HMJzIqD9g3RFP8YA3CXlIhuXIMPMde0Gigf3SCuqEdFxrpW90uXrUY4jzOP2Lu01nUeYSCotg6UHfE8b+YnFGVaA3NM/50k6zO4gnQ05PD4uvZRH1iAK8GEeL5BSRdSbxOnnildGAnjpN6ntvVe8y5ISVfhwVIWIKaQeZF9C6O0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=EKMiL6l7; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="EKMiL6l7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=8XMspiCxPbUWbTpllZf41awQJ3Mw3QpbFvI9c9w68D0=; b=EKMiL6l7i2vFzePfEAO2CVD3yU N5i1CBib93YzvaDJHmxq0gemL24W2uj12toRiMqyc9JJChOu12oQ6Ty7PI/oPX/daTEy8Iaf9T/8Q ToCUf6C1AgDw0dGJOjDc6nL5IYxWSzP4xzU8sOHtsikCmd7X41894g+TRrYNsQfEUNu7VwZHIKbAC Pr3P8xsP7s+CzDiIkAhAgyORkVvz/zISNVHLTuTiDUASBUSjMx4fGgXakXkUwAMtNx1bj3iLK6QDO vQdfFgCnKO1foUeBsHs8zgopdtuT7uG+qgJKhOusTeeYrDdkS8EwFnJKJ/+zMLzFG1xrg991fOvEd YZtfVE2g==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3N-005tfG-99; Wed, 19 Aug 2026 04:29:21 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:02 -0300 Subject: [PATCH RFC v2 03/13] sysctl, mod_devicetable: add macro MODULE_SYSCTL_TABLE Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-3-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 The MODULE_SYSCTL_TABLE macro emits a struct module_sysctl_table variable with pointers to a sysctl table's path and entries, and table/entry sizes. That symbol will be handled by file2alias.c (modpost) with the changes in mod_devicetable.h and devicetable-offsets.c. The option macros MODULE_SYSCTL_TABLE_{DISABLE,UNIQUE_ID} can be used on a per-file basis to disable the macro and change the symbol name pattern. Signed-off-by: Mauricio Faria de Oliveira --- include/linux/mod_devicetable.h | 7 +++++++ include/linux/sysctl.h | 42 +++++++++++++++++++++++++++++++++++= ++++ scripts/mod/devicetable-offsets.c | 6 ++++++ 3 files changed, 55 insertions(+) diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetabl= e.h index a397213bedace6e81ac600691b3b50ae0f88356b..818a4a53448dba2088e3dbd1ef2= c2d4dbb190fcc 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -78,4 +78,11 @@ struct cpu_feature { __u16 feature; }; =20 +struct module_sysctl_table { + kernel_ulong_t path; + kernel_ulong_t table; + __u16 table_size; + __u16 entry_size; +}; + #endif /* LINUX_MOD_DEVICETABLE_H */ diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index e5d7226ab6f5af34a33829883ad5d1b405e19c86..6960fe22c50bfd8a9acc79870e4= 94c2775fa040a 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -293,6 +293,48 @@ struct ctl_table_root { int (*permissions)(struct ctl_table_header *head, const struct ctl_table = *table); }; =20 +/* + * Creates a symbol so file2alias.c can find the sysctl table. + * + * MODULE_SYSCTL_TABLE() is the sysctl equivalent of MODULE_DEVICE_TABLE(), + * with pointers to a sysctl table's path and entries, and table/entry siz= es. + * + * The parameters 'path' and 'table' must be static (e.g., string literal = or + * static char[]; static struct ctl_table[]) as both are used as initializ= er + * elements for a static struct variable. + * + * The generated symbol name contains 'table' by default. However, if 'tab= le' + * is a struct field (contains '.' or '->'), in order to avoid syntax erro= rs, + * define the macro SYSCTL_MODULE_ALIASES_UNIQUE_ID. + * + * Define the macro SYSCTL_MODULE_ALIASES_DISABLE to disable this. + */ +#if defined(CONFIG_SYSCTL_MODULE_ALIASES) && defined(MODULE) && \ + !defined(SYSCTL_MODULE_ALIASES_DISABLE) + +#include +#include + +#if defined(SYSCTL_MODULE_ALIASES_UNIQUE_ID) +#define __MODULE_SYSCTL_TABLE_NAME(table) \ + __mod_device_table(sysctl, __UNIQUE_ID) +#else +#define __MODULE_SYSCTL_TABLE_NAME(table) \ + __mod_device_table(sysctl, table) +#endif + +#define MODULE_SYSCTL_TABLE(path, table) \ + static struct module_sysctl_table __used \ + __MODULE_SYSCTL_TABLE_NAME(table) =3D { \ + (kernel_ulong_t) path, \ + (kernel_ulong_t) table, \ + (u16) sizeof(table), \ + (u16) sizeof(const struct ctl_table) \ + } +#else +#define MODULE_SYSCTL_TABLE(path, table) +#endif + #define register_sysctl(path, table) \ register_sysctl_sz(path, table, ARRAY_SIZE(table)) =20 diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-of= fsets.c index b4178c42d08f50dfaba4d50d5c1d48b8aff88db4..e3b8855e6ebcf8d16f486f71d62= 900584ee884b1 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -284,5 +284,11 @@ int main(void) DEVID(coreboot_device_id); DEVID_FIELD(coreboot_device_id, tag); =20 + DEVID(module_sysctl_table); + DEVID_FIELD(module_sysctl_table, path); + DEVID_FIELD(module_sysctl_table, table); + DEVID_FIELD(module_sysctl_table, table_size); + DEVID_FIELD(module_sysctl_table, entry_size); + return 0; } --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 7EFCA3BADA9; Wed, 19 Aug 2026 02:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106576; cv=none; b=rhegZn/lCDOgcoDl4DZ8kdjQq/kPx8g7rgNlMhY7URw5MGDzrYj+C4UMd7L2o3JxvArFniGx4ep1BmRNTHvk178IaPmCv9or2nK98gAherTibR65RvO5cevEMYmZyG0Oi29Oh53r7z99uPKSdl2QFqJ+y4CbAilBh30/1hwPh28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106576; c=relaxed/simple; bh=O9XYwa7yAn4nrumcNR9l1To+tQ/PPu/6nFL/o0V1g4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r3EIBVLYUgMqb2X7fOTRg9W8uPJarAG72YrfdF0daousWKubox01B98S5d9PXvJY0oHJb13HqRI7+UlDHq0jdhcwim9ZkG1UaByTQhgmHH02zPWW6vU2QwU5wSA9hUKf+0RKoW+0OpRj1NhgOTlBVqvNwczLJHKTIo/7WPbdcoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=WFIwbDwf; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="WFIwbDwf" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=iJ7zO28rhwgh2iY91IivmtIIfG4kkjgiEZp5znqK2CA=; b=WFIwbDwfSLMv+t0GggmUXvUkEL fuMxSplCr1E6k93B/pmfgDEy4kbcB/VwZew72gwidfjH4bfXp60x2CZgCB43b5Iro41RTRfygfMby fDoIzwDySLE2qe+I47Ehydz1nCwXKOHYuMQGHzyjafQ8ynkvluTPmW/cuI3RUfZLARxft0hPIuF40 M0tfotxNDpG4MGwan8WPum4E5hI4malrjFvopubnaQp5dsyrDq3AX5XbWPA6yKb/lPNT/pE0rxVcD ytr80BMMm/tcOJcV5QbkPaXOfzjg5IGFUvklPVraNO20IUILLisOFVGi4PLaWxKteOzkqfsdu8sq8 9PbEVRuQ==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3U-005tfG-Cs; Wed, 19 Aug 2026 04:29:28 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:03 -0300 Subject: [PATCH RFC v2 04/13] sysctl: add register_sysctl() wrapper for MODULE_SYSCTL_TABLE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-4-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Add a MODULE_SYSCTL_TABLE call into register_sysctl() for existing callers to automatically use it. Add optional 'template arguments' to support a dynamic table/path defined at run-time based on a 'template' table/path available at build-time. Split the update of callers with template arguments into another commit for clarity, disabling them for now. Note: there is no register_sysctl_sz() wrapper, as it is used in even more dynamic cases (e.g., table generated at run-time not based on a template). Signed-off-by: Mauricio Faria de Oliveira --- drivers/parport/procfs.c | 2 ++ include/linux/sysctl.h | 54 ++++++++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index 3880460e67f25a7d8708a734c6f4d9e6c363c726..cda3221e386ed7a4afc898b3d03= 13081dee5b49b 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -13,6 +13,8 @@ * Cleaned up include files - Russell King */ =20 +#define SYSCTL_MODULE_ALIASES_DISABLE + #include #include #include diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 6960fe22c50bfd8a9acc79870e494c2775fa040a..7e05fafd5544e1c4a3283dc13b0= 692f39515d01e 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -335,8 +335,58 @@ struct ctl_table_root { #define MODULE_SYSCTL_TABLE(path, table) #endif =20 -#define register_sysctl(path, table) \ - register_sysctl_sz(path, table, ARRAY_SIZE(table)) +/* + * The register_sysctl() wrapper for the MODULE_SYSCTL_TABLE macro + * automatically creates symbols in sysctl table registration sites. + * + * Usage: + * - register_sysctl(path, table); + * - register_sysctl(path, table, table_tmpl); + * - register_sysctl(path, table, table_tmpl, path_tmpl); + * + * The optional 'template arguments' ('table_tmpl' and 'path_tmpl') + * can support callers with non-static variables: dynamic table/path + * defined at run-time based on a 'template' available at build-time. + * + * For example, a sysctl table, or table and path, which is/are: + * + * - per-namespace: different tables based on a template table + * (i.e., same files in each namespace) with identical path + * (i.e., same path in each namespace). + * + * - per-device: different tables based on a template table + * (i.e., same files for each device) with different paths + * (i.e., diff paths for each device) based on a template path. + * + * The wrapper passes the build-time parameters (templates) to the macro + * and the dynamic/run-time parameters (instances) to the wrapped function. + * + * The wrapper reduces to the wrapped function when either the macro or the + * config option is disabled. + */ +#define _register_sysctl(path, table, table_tmpl, path_tmpl) \ +({ \ + MODULE_SYSCTL_TABLE(path_tmpl, table_tmpl); \ + register_sysctl_sz(path, table, ARRAY_SIZE(table)); \ +}) + +#define register_sysctl(path, table, tmpl_args...) \ + _register_sysctl(path, table, \ + __sysctl_table_tmpl_or_default(table, ## tmpl_args), \ + __sysctl_path_tmpl_or_default(path, ## tmpl_args)) \ + +/* Helper macros for optional template arguments */ +#define __sysctl_table_tmpl(skip, table_tmpl, ...) \ + table_tmpl + +#define __sysctl_path_tmpl(skip, table_tmpl, path_tmpl, ...) \ + path_tmpl + +#define __sysctl_table_tmpl_or_default(default, tmpl_args...) \ + __sysctl_table_tmpl(, ## tmpl_args, default) + +#define __sysctl_path_tmpl_or_default(default, tmpl_args...) \ + __sysctl_path_tmpl(, ## tmpl_args, default, default) =20 #ifdef CONFIG_SYSCTL =20 --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 37375392C3D; Wed, 19 Aug 2026 02:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106579; cv=none; b=BDlJB1fdn+eDFViNzwi3qsbiEJBN0d1MQsl4Dl9CbuMsfA70betJ4e3Td09UEGntZJalN1VYrFgVkG+qxxiYofQ62t6UccOBIzy5gaEnNV+kmc4RBObyY1vYTs0cs2QRkPtYg8OKfyDGR+ommePxAMtchGpC4x9dlNf8aAtVT60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106579; c=relaxed/simple; bh=6sl9aUdgsqr1MH5G5ILk8v03G3sClQ3TxOzzAtQ4RdI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l8idJtAeG2f2U/mrcsuBrB4FeN8oZ7nIaVJ+Pnx3sBc+Q9vooVYHEjF5/xdoxUx17gJMfjayVD5iTKkPxVILXScEjEsR2GxwILAr0DGOIYoz5rGBvqq2OOUBrsL46lBQqHHK4kcmv3xeJemubZCfySn+F0FEMAdX+D/EqfqLcMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=fCgiJSi+; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="fCgiJSi+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=joqvbHqdM9HpjwaYMD+5G7FBevrqRTEc0btSZWyP7jQ=; b=fCgiJSi+uXfD9MWWWckx9j0axB KFZV+FkjgtUWf0pKxS+d6Aa3SKHYUB8L78RI3rbrnA+eNkyWg6blzdLwnoJNbDcKAqHkkBZtKboth Y2g0uii9RA027moEGWvo9xcB7cznm1zHtvZCGHMvEsfy8WUrbyVpY2woPT8VzHLTWRZZ18T/R3Zjc scFrUFehUVjql030yigSWSS8FGRzvFLu7oKMf355M4d5lIuI9P4eWDH9nN0Wd1ec/r1jryp0BTs97 zqtFrld4yqzjwN6slHBg9stZyB1Vv4AUZdOlAMRpuLeyYl4Bi1+Od7Cdv5E6ih4sSAK/E8vbRlC0a DYgCPLbw==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3b-005tfG-G2; Wed, 19 Aug 2026 04:29:35 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:04 -0300 Subject: [PATCH RFC v2 05/13] sysctl, parport: update register_sysctl() callers with template arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-5-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Update callers with dynamic table/path to use template arguments. Signed-off-by: Mauricio Faria de Oliveira --- drivers/parport/procfs.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index cda3221e386ed7a4afc898b3d0313081dee5b49b..7c048e9a973aa96251930e21581= aed045c41cc35 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -13,7 +13,7 @@ * Cleaned up include files - Russell King */ =20 -#define SYSCTL_MODULE_ALIASES_DISABLE +#define SYSCTL_MODULE_ALIASES_UNIQUE_ID =20 #include #include @@ -434,13 +434,17 @@ int parport_proc_register(struct parport *port) #endif /* IEEE 1284 support */ } =20 - tmp_dir_path =3D kasprintf(GFP_KERNEL, "dev/parport/%s/devices", port->na= me); +#define tmp_dir_tmpl "dev/parport/%s/devices" + tmp_dir_path =3D kasprintf(GFP_KERNEL, tmp_dir_tmpl, port->name); if (!tmp_dir_path) { err =3D -ENOMEM; goto exit_free_t; } =20 - t->devices_header =3D register_sysctl(tmp_dir_path, t->device_dir); + t->devices_header =3D register_sysctl(tmp_dir_path, t->device_dir, + parport_sysctl_template.device_dir, + tmp_dir_tmpl); +#undef tmp_dir_tmpl if (t->devices_header =3D=3D NULL) { err =3D -ENOENT; goto exit_free_tmp_dir_path; @@ -448,13 +452,17 @@ int parport_proc_register(struct parport *port) =20 kfree(tmp_dir_path); =20 - tmp_dir_path =3D kasprintf(GFP_KERNEL, "dev/parport/%s", port->name); +#define tmp_dir_tmpl "dev/parport/%s" + tmp_dir_path =3D kasprintf(GFP_KERNEL, tmp_dir_tmpl, port->name); if (!tmp_dir_path) { err =3D -ENOMEM; goto unregister_devices_h; } =20 - t->port_header =3D register_sysctl(tmp_dir_path, t->vars); + t->port_header =3D register_sysctl(tmp_dir_path, t->vars, + parport_sysctl_template.vars, + tmp_dir_tmpl); +#undef tmp_dir_tmpl if (t->port_header =3D=3D NULL) { err =3D -ENOENT; goto unregister_devices_h; @@ -500,7 +508,8 @@ int parport_device_proc_register(struct pardevice *devi= ce) return -ENOMEM; =20 /* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */ - tmp_dir_path =3D kasprintf(GFP_KERNEL, "dev/parport/%s/devices/%s", port-= >name, device->name); +#define tmp_dir_tmpl "dev/parport/%s/devices/%s" + tmp_dir_path =3D kasprintf(GFP_KERNEL, tmp_dir_tmpl, port->name, device->= name); if (!tmp_dir_path) { err =3D -ENOMEM; goto exit_free_t; @@ -508,7 +517,10 @@ int parport_device_proc_register(struct pardevice *dev= ice) =20 t->vars[0].data =3D &device->timeslice; =20 - t->sysctl_header =3D register_sysctl(tmp_dir_path, t->vars); + t->sysctl_header =3D register_sysctl(tmp_dir_path, t->vars, + parport_device_sysctl_template.vars, + tmp_dir_tmpl); +#undef tmp_dir_tmpl if (t->sysctl_header =3D=3D NULL) { kfree(t); t =3D NULL; --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 1D63F35F5E4; Wed, 19 Aug 2026 02:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106587; cv=none; b=tQQ4JIbn1ZDCrcbSDE+UCDu8GEuBepsGeHs1nwG4bq3k4L8EC3iqULbl6HLUMcjCzbqFuPuSFq4AfDNvNxkMISoTX6Cdg1GxfV5mZgBATh4+FWNZRRLQ5R1DwUL3NTmJ+mAZoaqLfVUPWLfuhj2DhYsXDsztFfZ2ZMIM3UtYAXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106587; c=relaxed/simple; bh=iZwaJ3oD8KyUeg6N+UUPwC38Zx2YF2Ev+VgEDruYIo4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cbGPBOmUsQI2th3PZokwgVK2fUi5Sy5Gbi34c1KMhiXNeptK1mtzHgbDAueJH0gomG7aHkJ/NyjIsWPhniuHrTnQmkNjegV8eoMmUOXp12DdU9zFjJp79hhUS7bq0bykjbmO6Ab4ulxPCTvBb3g3zf2+XqAYKzdQC99jM9GyFeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=F02TB5U6; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="F02TB5U6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=H3/V/omVPqP4Gcds9KJ2/iTD0AqO6b8ovtPsauoO5pw=; b=F02TB5U6Jtdvw9GjI/DlMJdVA6 WgdZESCP0ESz8mcgfH2cBSxq1QLo66nufXCxAbTgYXq7Jw0xA2PXJ13tZw79sVkb0687Nbxf1oXfG nb1PeNKdOrGkgUeJjSgurgLoLonvot5NVK7zAVdcjA+1z8o6F5ObHclXoAV59OLFvhiCnp4Lz5SW/ DTKEzrYhnGOp3/wc2hUvsyE0Ax/J8d58ENGeNhxlara+KhUqn9SeHJ69+os0/kk+n/euedei5caij RuaDPuRWYjtxmF4zAZTKu9tbDL5t0qOBirnjurvu084nDJmi4BWstyzBB+PQ+XtqsSiqcmU6wGcln GkkVegIg==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3i-005tfG-JG; Wed, 19 Aug 2026 04:29:42 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:05 -0300 Subject: [PATCH RFC v2 06/13] sysctl, net: add register_net_sysctl{_sz}() wrappers for MODULE_SYSCTL_TABLE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-6-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Add a MODULE_SYSCTL_TABLE call into register_net_sysctl{_sz}() for existing callers to automatically use it. Add optional 'template arguments' to support a dynamic table/path defined at run-time based on a 'template' available at build-time. Split the update of callers with template arguments into separate commits, disabling the macro for now. Signed-off-by: Mauricio Faria de Oliveira --- include/linux/sysctl.h | 3 +++ include/net/net_namespace.h | 45 ++++++++++++++++++++++++++++++++++++++++-= ---- net/sysctl_net.c | 10 +++++----- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 7e05fafd5544e1c4a3283dc13b0692f39515d01e..9e00a086ff1d47ab18021b3d79b= 0e8a93037cb2d 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -309,6 +309,9 @@ struct ctl_table_root { * * Define the macro SYSCTL_MODULE_ALIASES_DISABLE to disable this. */ + +#define SYSCTL_MODULE_ALIASES_DISABLE + #if defined(CONFIG_SYSCTL_MODULE_ALIASES) && defined(MODULE) && \ !defined(SYSCTL_MODULE_ALIASES_DISABLE) =20 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index e5ee673b9fcf846aefcc309d4cca1a8fc870aae2..2127049c71cedade45922d7f0d3= b7a3ce0af67e0 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -520,13 +520,48 @@ void unregister_pernet_device(struct pernet_operation= s *); =20 struct ctl_table; =20 -#define register_net_sysctl(net, path, table) \ - register_net_sysctl_sz(net, path, table, ARRAY_SIZE(table)) +/* + * The register_net_sysctl{_sz}() wrappers for MODULE_SYSCTL_TABLE + * automatically create symbols in sysctl registration sites. + * + * See register_sysctl() and MODULE_SYSCTL_TABLE() in + * for information about template arguments and options for the macro. + * + * Usage: + * - register_net_sysctl(net, path, table); + * - register_net_sysctl(net, path, table, table_tmpl); + * - register_net_sysctl(net, path, table, table_tmpl, path_tmpl); + * - register_net_sysctl_sz(net, path, table, size); + * - register_net_sysctl_sz(net, path, table, size, table_tmpl); + * - register_net_sysctl_sz(net, path, table, size, table_tmpl, path_tmpl); + */ +#define _register_net_sysctl_sz(net, path, table, size, table_tmpl, path_t= mpl) \ +({ \ + MODULE_SYSCTL_TABLE(path_tmpl, table_tmpl); \ + __register_net_sysctl_sz(net, path, table, size); \ +}) + +#define register_net_sysctl_sz(net, path, table, size, tmpl_args...) \ + _register_net_sysctl_sz(net, path, table, size, \ + __sysctl_table_tmpl_or_default(table, \ + ## tmpl_args), \ + __sysctl_path_tmpl_or_default(path, \ + ## tmpl_args)) +#define register_net_sysctl(net, path, table, tmpl_args...) \ + register_net_sysctl_sz(net, path, table, \ + __sysctl_table_array_size(table, ## tmpl_args), \ + ## tmpl_args) + +/* Helper macro for optional template arguments */ +#define __sysctl_table_array_size(table, tmpl_args...) \ + ARRAY_SIZE(__sysctl_table_tmpl_or_default(table, ## tmpl_args)) + #ifdef CONFIG_SYSCTL int net_sysctl_init(void); -struct ctl_table_header *register_net_sysctl_sz(struct net *net, const cha= r *path, - const struct ctl_table *table, - size_t table_size); +struct ctl_table_header *__register_net_sysctl_sz(struct net *net, + const char *path, + const struct ctl_table *table, + size_t table_size); void unregister_net_sysctl_table(struct ctl_table_header *header); #else static inline int net_sysctl_init(void) { return 0; } diff --git a/net/sysctl_net.c b/net/sysctl_net.c index e190a639eef2f6929c4aed85ad625aaf8a6ebd6a..e003210e0917760b707dae1e738= c50d7c3969deb 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -160,10 +160,10 @@ static int ensure_safe_net_sysctl(struct net *net, co= nst char *path, return 0; } =20 -struct ctl_table_header *register_net_sysctl_sz(struct net *net, - const char *path, - const struct ctl_table *table, - size_t table_size) +struct ctl_table_header *__register_net_sysctl_sz(struct net *net, + const char *path, + const struct ctl_table *table, + size_t table_size) { if (!net_eq(net, &init_net)) if (ensure_safe_net_sysctl(net, path, table, table_size)) @@ -171,7 +171,7 @@ struct ctl_table_header *register_net_sysctl_sz(struct = net *net, =20 return __register_sysctl_table(&net->sysctls, path, table, table_size); } -EXPORT_SYMBOL_GPL(register_net_sysctl_sz); +EXPORT_SYMBOL_GPL(__register_net_sysctl_sz); =20 void unregister_net_sysctl_table(struct ctl_table_header *header) { --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 102803BA25F; Wed, 19 Aug 2026 02:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106594; cv=none; b=t6WwFG4nPzZ5CTbu28AgVDItZBBathL8oZt503IUub9Hyy3rmx5dpbXG+Fni1v2wpTZsrFI+C6xxpzK5uSTh7DCp+8MuYOvJeHn0YdwyNyNuAB7wf3hJowGVMEkvZksMz05ju7dDv/rApcftoQNxyh9eVICELTw1EzdLMskPSV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106594; c=relaxed/simple; bh=n+W4IN1RE67dW3Yf1B+QZ7ClT/9QwQfu0/tR3wzZCsE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Lk7TSUxzWIJYASLXw01AfIr5bSS4QamCRhthdETl28aGkXJMPEF4UuXxn7dl0aT7TXPSSlFSYNKc42pr/ZjqynCUPSEePkW8db4/PTI1ly8JDW1EHYDS3ZujvQTyKCkfj1EFTPkqs7y2myUQsZ3e1Ktn6ICpUoBj7Dix1FrFXbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=QdjFWa3z; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="QdjFWa3z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=WSGsNXeWAE/lPx5m93/UJiI7JZPSsRCHYegj4bfx/3o=; b=QdjFWa3zks8uLCL9fWsr/W4KXy H6YxpmZerUa7mu8YUSrbQpbjV3f9fTL3XLp6c2WAJaJipG1ep81gVhry1KzoTbDbtRfaSlntnLTzD Mk+4pkWWb5VygcTnUN/0zy+0yhz7Pf0Z/NjMNeu00+K6HHy6N5XNI9FMxyXnU4W0QpusSSXrQz6/b 5lrWx7c+wjLQ1H6q/uHosUdm/nd71gUf4F3J15xd10DIoU6mm3h5PNUDZhEoHlpKM4qcWu61huapp GAwUvmHHLgzeoQCjlCcZA5Qnv3sZlMdwE3Bf5iww0McPqYX9T2xbb2PM/eTVkHzvyvaTTKC7xMbn+ dt8fH+tA==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3p-005tfG-Mx; Wed, 19 Aug 2026 04:29:49 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:06 -0300 Subject: [PATCH RFC v2 07/13] sysctl, net: update register_net_sysctl{_sz}() callers with template arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-7-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Update most callers with dynamic table/path to use template arguments. Signed-off-by: Mauricio Faria de Oliveira --- net/core/neighbour.c | 11 ++++++++--- net/core/sysctl_net_core.c | 3 ++- net/ieee802154/6lowpan/reassembly.c | 2 +- net/ipv4/devinet.c | 9 +++++++-- net/ipv4/route.c | 3 ++- net/ipv4/sysctl_net_ipv4.c | 2 +- net/ipv6/addrconf.c | 7 +++++-- net/ipv6/sysctl_net_ipv6.c | 3 ++- net/mpls/af_mpls.c | 9 ++++++--- net/netfilter/ipvs/ip_vs_lblc.c | 3 ++- net/netfilter/ipvs/ip_vs_lblcr.c | 3 ++- net/sctp/sysctl.c | 3 ++- net/smc/smc_sysctl.c | 2 +- net/xfrm/xfrm_sysctl.c | 2 +- 14 files changed, 42 insertions(+), 20 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 1349c0eedb642539b28391390fd82f543e004353..bdd67dd879d24f41c95c454ca26= d63fd6d8e112b 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -12,6 +12,7 @@ */ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#define SYSCTL_MODULE_ALIASES_UNIQUE_ID =20 #include #include @@ -3910,11 +3911,15 @@ int neigh_sysctl_register(struct net_device *dev, s= truct neigh_parms *p, BUG(); } =20 - snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s", - p_name, dev_name_source); +#define path_template "net/%s/neigh/%s" + snprintf(neigh_path, sizeof(neigh_path), path_template, + p_name, dev_name_source); t->sysctl_header =3D register_net_sysctl_sz(neigh_parms_net(p), neigh_path, t->neigh_vars, - neigh_vars_size); + neigh_vars_size, + neigh_sysctl_template.neigh_vars, + path_template); +#undef path_template if (!t->sysctl_header) goto free; =20 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index eb35da3556f4aa00cecd4582ab94e339d2518506..d8dfce6babc337749cde653fb13= 08f977ba28ef5 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -821,7 +821,8 @@ static __net_init int sysctl_core_net_init(struct net *= net) goto err_dup; } =20 - net->core.sysctl_hdr =3D register_net_sysctl_sz(net, "net/core", tbl, tab= le_size); + net->core.sysctl_hdr =3D register_net_sysctl_sz(net, "net/core", tbl, tab= le_size, + netns_core_table); if (net->core.sysctl_hdr =3D=3D NULL) goto err_reg; =20 diff --git a/net/ieee802154/6lowpan/reassembly.c b/net/ieee802154/6lowpan/r= eassembly.c index ddb6a5817d098eda6b22d802b5f59604b2145ff2..28914524bd0c389877533ed689e= af5af58c46bdd 100644 --- a/net/ieee802154/6lowpan/reassembly.c +++ b/net/ieee802154/6lowpan/reassembly.c @@ -386,7 +386,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(s= truct net *net) table[2].data =3D &ieee802154_lowpan->fqdir->timeout; =20 hdr =3D register_net_sysctl_sz(net, "net/ieee802154/6lowpan", table, - table_size); + table_size, lowpan_frags_ns_ctl_table); if (hdr =3D=3D NULL) goto err_reg; =20 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index a90be57c63be1565b2dff51e8264668fd71b9e58..a466163dad7fe7f8b5b1c2897dd= 5fe548c288442 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -21,6 +21,7 @@ * if no match found. */ =20 +#define SYSCTL_MODULE_ALIASES_UNIQUE_ID =20 #include #include @@ -2739,9 +2740,13 @@ static int __devinet_sysctl_register(struct net *net= , char *dev_name, t->devinet_vars[i].extra2 =3D net; } =20 - snprintf(path, sizeof(path), "net/ipv4/conf/%s", dev_name); +#define path_template "net/ipv4/conf/%s" + snprintf(path, sizeof(path), path_template, dev_name); =20 - t->sysctl_header =3D register_net_sysctl(net, path, t->devinet_vars); + t->sysctl_header =3D register_net_sysctl(net, path, t->devinet_vars, + devinet_sysctl.devinet_vars, + path_template); +#undef path_template if (!t->sysctl_header) goto free; =20 diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 604cc51dfd9bc5e7351a93140a9e0699a71e6a4e..d5464c7ef7dacdd47c5cb59ca14= f605004c43b49 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -3661,7 +3661,8 @@ static __net_init int sysctl_route_net_init(struct ne= t *net) tbl[0].extra1 =3D net; =20 net->ipv4.route_hdr =3D register_net_sysctl_sz(net, "net/ipv4/route", - tbl, table_size); + tbl, table_size, + ipv4_route_netns_table); if (!net->ipv4.route_hdr) goto err_reg; return 0; diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 2f0363bca2a88d68276670cfce6fb04398f82bc5..879651f4a57bc1206494a9eb1dd= 6a3fb752169c9 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -1696,7 +1696,7 @@ static __net_init int ipv4_sysctl_init_net(struct net= *net) } =20 net->ipv4.ipv4_hdr =3D register_net_sysctl_sz(net, "net/ipv4", table, - table_size); + table_size, ipv4_net_table); if (!net->ipv4.ipv4_hdr) goto err_reg; =20 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 9d89be7e0544befb979526fa4f0c4f0ab90582f0..e87c5d2e6e2f49ef4041faa4d8d= f85f69cabad36 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -7347,10 +7347,13 @@ static int __addrconf_sysctl_register(struct net *n= et, char *dev_name, } } =20 - snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name); +#define path_template "net/ipv6/conf/%s" + snprintf(path, sizeof(path), path_template, dev_name); =20 p->sysctl_header =3D register_net_sysctl_sz(net, path, table, - table_size); + table_size, addrconf_sysctl, + path_template); +#undef path_template if (!p->sysctl_header) goto free; =20 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index 1a0a36dcdabc1be961d0ab69e5c93b05c53f46a8..75ba17cb7c0ccb4769d61e74220= c75d0b3e2bcd9 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c @@ -275,7 +275,8 @@ static int __net_init ipv6_sysctl_net_init(struct net *= net) goto out_ipv6_route_table; =20 net->ipv6.sysctl.hdr =3D register_net_sysctl_sz(net, "net/ipv6", - ipv6_table, table_size); + ipv6_table, table_size, + ipv6_table_template); if (!net->ipv6.sysctl.hdr) goto out_ipv6_icmp_table; =20 diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index 961be5054a039b3d8bcfd22851beb69c21954bc3..f2025bedc543b5b50eb3c7275e2= 6e6adcdf27ae5 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -1446,9 +1446,12 @@ static int mpls_dev_sysctl_register(struct net_devic= e *dev, table[i].extra2 =3D net; } =20 - snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name); +#define path_template "net/mpls/conf/%s" + snprintf(path, sizeof(path), path_template, dev->name); =20 - mdev->sysctl =3D register_net_sysctl_sz(net, path, table, table_size); + mdev->sysctl =3D register_net_sysctl_sz(net, path, table, table_size, + mpls_dev_table, path_template); +#undef path_template if (!mdev->sysctl) goto free; =20 @@ -2765,7 +2768,7 @@ static __net_init int mpls_net_init(struct net *net) table[i].data =3D (char *)net + (uintptr_t)table[i].data; =20 net->mpls.ctl =3D register_net_sysctl_sz(net, "net/mpls", table, - table_size); + table_size, mpls_table); if (net->mpls.ctl =3D=3D NULL) { kfree(table); return -ENOMEM; diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lbl= c.c index 693bcc82ccb77b49bfa28a7facac946f0223aba2..efad701b096341dfe44e621ed64= 7e21fd3bfa486 100644 --- a/net/netfilter/ipvs/ip_vs_lblc.c +++ b/net/netfilter/ipvs/ip_vs_lblc.c @@ -572,7 +572,8 @@ static int __net_init __ip_vs_lblc_init(struct net *net) =20 ipvs->lblc_ctl_header =3D register_net_sysctl_sz(net, "net/ipv4/vs", ipvs->lblc_ctl_table, - vars_table_size); + vars_table_size, + vs_vars_table); if (!ipvs->lblc_ctl_header) { if (!net_eq(net, &init_net)) kfree(ipvs->lblc_ctl_table); diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lb= lcr.c index f53f05ceea36f02d6d1d435882484005829fe6de..3498e6db6f0d7e9af29a95f1f8c= cecd7c8d45cfd 100644 --- a/net/netfilter/ipvs/ip_vs_lblcr.c +++ b/net/netfilter/ipvs/ip_vs_lblcr.c @@ -757,7 +757,8 @@ static int __net_init __ip_vs_lblcr_init(struct net *ne= t) =20 ipvs->lblcr_ctl_header =3D register_net_sysctl_sz(net, "net/ipv4/vs", ipvs->lblcr_ctl_table, - vars_table_size); + vars_table_size, + vs_vars_table); if (!ipvs->lblcr_ctl_header) { if (!net_eq(net, &init_net)) kfree(ipvs->lblcr_ctl_table); diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index 2b94c211427de7b2e9aa374033eac26ddd874e14..891fb447ea480ec95fb66a02bf8= e086b3efa58c7 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -605,7 +605,8 @@ int sctp_sysctl_net_register(struct net *net) table[SCTP_PS_RETRANS_IDX].extra1 =3D &net->sctp.pf_retrans; =20 net->sctp.sysctl_header =3D register_net_sysctl_sz(net, "net/sctp", - table, table_size); + table, table_size, + sctp_net_table); if (net->sctp.sysctl_header =3D=3D NULL) { kfree(table); return -ENOMEM; diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c index 09dad48337f6164f5765fa793412bdebf47e61ca..4b1dc109afa6c62b4640513336d= 0862bdcd00f8c 100644 --- a/net/smc/smc_sysctl.c +++ b/net/smc/smc_sysctl.c @@ -235,7 +235,7 @@ int __net_init smc_sysctl_net_init(struct net *net) } =20 net->smc.smc_hdr =3D register_net_sysctl_sz(net, "net/smc", table, - table_size); + table_size, smc_table); if (!net->smc.smc_hdr) goto err_reg; =20 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c index 357152a50faf10e5c33468c034dd1777e0bed079..34bb2097930b61f711a2cafd614= e63b5caac0013 100644 --- a/net/xfrm/xfrm_sysctl.c +++ b/net/xfrm/xfrm_sysctl.c @@ -60,7 +60,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table_size =3D 0; =20 net->xfrm.sysctl_hdr =3D register_net_sysctl_sz(net, "net/core", table, - table_size); + table_size, xfrm_table); if (!net->xfrm.sysctl_hdr) goto out_register; return 0; --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 2C69C3BA25F; Wed, 19 Aug 2026 02:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106601; cv=none; b=axzeoLze9qS8EQYhRk/0UTIkOuXrBStZBJ4ztDxrVqXZBtODngSSIEMMhliXMlRedvhapOTtdby1/1EtnITEmR9rUw9pvesaDWpY75XXDQHwdSKQwNBZ47kfbDjoe3C/x0O+Dz97hLOu3IsMeSjm7ow3TmsjzMXZrj5FLavaJMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106601; c=relaxed/simple; bh=ghXZ0pNg3bc/gxhG0S2yq9sZf92+3XHOPiwZNweiMFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pnlfvh1NMkSYOKjCD4RHXl24MOaW74pF8d3Inc1jPEOwuVtb/XvCMAwSac9nM+iva3/7DshHSoFQQm/HI6PrJrT814d2N+ARTHI3l06cJZS0i0dAIBGdvSpHoBR/Q7a6mGzXxytAf2c91466peagNT3p1tewsnUEL7EDoUaerJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=XPk4rLYY; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="XPk4rLYY" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=/zj38NG0Jtad2NvlMhx+0HTiUM61a7Li0ehqHM7SWK0=; b=XPk4rLYYea+UjJ3gc10vX9S0V0 7vACMIblrAKfnZtCbh/Qp1UmLOJf7Lz8Pzu9HsmWEY3RxGpRxfn5VWSCih7uA7my0XFnrEILGCHjg XgpAJrKDuCPQMfsNqqHwwrVN5LCKtjwNqLroEeu2R6Z4f3VnzuQtTthCtjbFYtQ/VtxN1N00CKdyB heVH+v3DcYYNnl5tt8fBmK/784dmDAxk+Q4COfOQM9+a8riijWTFT3IElPHkjba3cJmwfviTbJnAn gyVDPWk9YnCbMZZogfMQP/PkqSZQzYzFFWZ6aU4ztxOGeX6A1n79N9F1P9aX6/1XS+/wTC+UdaLwB R4m/0GCQ==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW3w-005tfG-Pt; Wed, 19 Aug 2026 04:29:57 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:07 -0300 Subject: [PATCH RFC v2 08/13] sysctl, net: update register_net_sysctl_sz(ARRAY_SIZE(table_tmpl)) with template arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-8-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Reduce register_net_sysctl_sz(net, path, table, ARRAY_SIZE(table_tmpl)) to register_net_sysctl(net, path, table, table_tmpl) which does it internally. Signed-off-by: Mauricio Faria de Oliveira --- drivers/net/vrf.c | 3 +-- net/bridge/br_netfilter_hooks.c | 3 +-- net/ipv4/devinet.c | 3 +-- net/ipv4/ip_fragment.c | 3 +-- net/ipv4/xfrm4_policy.c | 3 +-- net/ipv6/netfilter/nf_conntrack_reasm.c | 4 ++-- net/ipv6/reassembly.c | 3 +-- net/ipv6/xfrm6_policy.c | 3 +-- net/mptcp/ctrl.c | 3 +-- net/netfilter/ipvs/ip_vs_ctl.c | 4 +--- net/netfilter/nf_conntrack_standalone.c | 5 ++--- net/rds/tcp.c | 4 ++-- net/unix/sysctl_net_unix.c | 3 +-- net/vmw_vsock/af_vsock.c | 4 ++-- 14 files changed, 18 insertions(+), 30 deletions(-) diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index a0557a3a70260a404b2c2c6262e8466aec5be391..19dacbe69d6de81e2cf5cd2b6e7= 50a25f9cef092 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -1875,8 +1875,7 @@ static int vrf_netns_init_sysctl(struct net *net, str= uct netns_vrf *nn_vrf) /* init the extra1 parameter with the reference to current netns */ table[0].extra1 =3D net; =20 - nn_vrf->ctl_hdr =3D register_net_sysctl_sz(net, "net/vrf", table, - ARRAY_SIZE(vrf_table)); + nn_vrf->ctl_hdr =3D register_net_sysctl(net, "net/vrf", table, vrf_table); if (!nn_vrf->ctl_hdr) { kfree(table); return -ENOMEM; diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hook= s.c index 0a394e5f439168fc32f3beb08721bee063ca5f17..ce5deb724608cf01103581f7f3e= 57210ffb85657 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -1251,8 +1251,7 @@ static int br_netfilter_sysctl_init_net(struct net *n= et) =20 br_netfilter_sysctl_default(brnet); =20 - brnet->ctl_hdr =3D register_net_sysctl_sz(net, "net/bridge", table, - ARRAY_SIZE(brnf_table)); + brnet->ctl_hdr =3D register_net_sysctl(net, "net/bridge", table, brnf_tab= le); if (!brnet->ctl_hdr) { if (!net_eq(net, &init_net)) kfree(table); diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index a466163dad7fe7f8b5b1c2897dd5fe548c288442..fad5483287c29f75a0c09aa833a= f389e51f36cfb 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2884,8 +2884,7 @@ static __net_init int devinet_init_net(struct net *ne= t) goto err_reg_dflt; =20 err =3D -ENOMEM; - forw_hdr =3D register_net_sysctl_sz(net, "net/ipv4", tbl, - ARRAY_SIZE(ctl_forward_entry)); + forw_hdr =3D register_net_sysctl(net, "net/ipv4", tbl, ctl_forward_entry); if (!forw_hdr) goto err_reg_ctl; net->ipv4.forw_hdr =3D forw_hdr; diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index c790d2f494870e1debd7e73b2d67df017a29f8a8..122aae5b4a384c12db5786bc343= 14107b4794b63 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -604,8 +604,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct = net *net) table[2].data =3D &net->ipv4.fqdir->timeout; table[3].data =3D &net->ipv4.fqdir->max_dist; =20 - hdr =3D register_net_sysctl_sz(net, "net/ipv4", table, - ARRAY_SIZE(ip4_frags_ns_ctl_table)); + hdr =3D register_net_sysctl(net, "net/ipv4", table, ip4_frags_ns_ctl_tabl= e); if (!hdr) goto err_reg; =20 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c index ab7a01029d490416d36482f7a3189f83d6670f42..cdd69d31a2757b0a23d65fb4b7d= 6d7de97c08706 100644 --- a/net/ipv4/xfrm4_policy.c +++ b/net/ipv4/xfrm4_policy.c @@ -177,8 +177,7 @@ static __net_init int xfrm4_net_sysctl_init(struct net = *net) goto err_alloc; } =20 - hdr =3D register_net_sysctl_sz(net, "net/ipv4", table, - ARRAY_SIZE(xfrm4_policy_table)); + hdr =3D register_net_sysctl(net, "net/ipv4", table, xfrm4_policy_table); if (!hdr) goto err_reg; =20 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/n= f_conntrack_reasm.c index 599c49bf0a0afd5054e926a5f2b1f0677bcd8b4d..09c98f2b9c3a04f622b232987db= c6a72f41238b4 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c @@ -86,8 +86,8 @@ static int nf_ct_frag6_sysctl_register(struct net *net) table[2].data =3D &nf_frag->fqdir->high_thresh; table[2].extra1 =3D &nf_frag->fqdir->low_thresh; =20 - hdr =3D register_net_sysctl_sz(net, "net/netfilter", table, - ARRAY_SIZE(nf_ct_frag6_sysctl_table)); + hdr =3D register_net_sysctl(net, "net/netfilter", table, + nf_ct_frag6_sysctl_table); if (hdr =3D=3D NULL) goto err_reg; =20 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 05c51f669754a1a10e944bb7c4433565bcaacb40..372c85b253fa1c2fe1f54765e2d= ea02f8ba047f9 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -471,8 +471,7 @@ static int __net_init ip6_frags_ns_sysctl_register(stru= ct net *net) table[1].extra2 =3D &net->ipv6.fqdir->high_thresh; table[2].data =3D &net->ipv6.fqdir->timeout; =20 - hdr =3D register_net_sysctl_sz(net, "net/ipv6", table, - ARRAY_SIZE(ip6_frags_ns_ctl_table)); + hdr =3D register_net_sysctl(net, "net/ipv6", table, ip6_frags_ns_ctl_tabl= e); if (!hdr) goto err_reg; =20 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c index 5ec063cb4aa4378e70fff002dd03abf2029b247f..1c5a0ba14a7d03542d0691ea4c0= f6a60443c20f6 100644 --- a/net/ipv6/xfrm6_policy.c +++ b/net/ipv6/xfrm6_policy.c @@ -223,8 +223,7 @@ static int __net_init xfrm6_net_sysctl_init(struct net = *net) goto err_alloc; } =20 - hdr =3D register_net_sysctl_sz(net, "net/ipv6", table, - ARRAY_SIZE(xfrm6_policy_table)); + hdr =3D register_net_sysctl(net, "net/ipv6", table, xfrm6_policy_table); if (!hdr) goto err_reg; =20 diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index 63c5747f0f63cf75e516f68ac6cdde5ba5522278..df87f20f72ab86506b69ea40b40= 3002ebf828348 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -406,8 +406,7 @@ static int mptcp_pernet_new_table(struct net *net, stru= ct mptcp_pernet *pernet) /* table[12] is for available_path_managers which is read-only info */ table[13].data =3D &pernet->add_addr_v6_port_drop_ts; =20 - hdr =3D register_net_sysctl_sz(net, MPTCP_SYSCTL_PATH, table, - ARRAY_SIZE(mptcp_sysctl_table)); + hdr =3D register_net_sysctl(net, MPTCP_SYSCTL_PATH, table, mptcp_sysctl_t= able); if (!hdr) goto err_reg; =20 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 4c1c739446b76ea455dab2958a844d05e31a46a7..c65ccdebc285926ed993aeddc21= d17b0e2cbef40 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -5048,7 +5048,6 @@ static int __net_init ip_vs_control_net_init_sysctl(s= truct netns_ipvs *ipvs) struct net *net =3D ipvs->net; struct ctl_table *tbl; int idx, ret; - size_t ctl_table_size =3D ARRAY_SIZE(vs_vars); bool unpriv =3D net->user_ns !=3D &init_user_ns; =20 atomic_set(&ipvs->dropentry, 0); @@ -5166,8 +5165,7 @@ static int __net_init ip_vs_control_net_init_sysctl(s= truct netns_ipvs *ipvs) #endif =20 ret =3D -ENOMEM; - ipvs->sysctl_hdr =3D register_net_sysctl_sz(net, "net/ipv4/vs", tbl, - ctl_table_size); + ipvs->sysctl_hdr =3D register_net_sysctl(net, "net/ipv4/vs", tbl, vs_vars= ); if (!ipvs->sysctl_hdr) goto err; ipvs->sysctl_tbl =3D tbl; diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_con= ntrack_standalone.c index f4f2d82192d54ed9831b9677743f1139820e5a2e..a2f70cf4cd665e55f8e182bdf45= da89b39434e11 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -1043,9 +1043,8 @@ static int nf_conntrack_standalone_init_sysctl(struct= net *net) table[NF_SYSCTL_CT_BUCKETS].mode =3D 0444; } =20 - cnet->sysctl_header =3D register_net_sysctl_sz(net, "net/netfilter", - table, - ARRAY_SIZE(nf_ct_sysctl_table)); + cnet->sysctl_header =3D register_net_sysctl(net, "net/netfilter", table, + nf_ct_sysctl_table); if (!cnet->sysctl_header) goto out_unregister_netfilter; =20 diff --git a/net/rds/tcp.c b/net/rds/tcp.c index b263634ac750d204a0d5726db6abe04023aa9c17..37fadb675faddf8e21f0aac04b9= 6985ce3709bff 100644 --- a/net/rds/tcp.c +++ b/net/rds/tcp.c @@ -588,8 +588,8 @@ static __net_init int rds_tcp_init_net(struct net *net) } tbl[RDS_TCP_SNDBUF].data =3D &rtn->sndbuf_size; tbl[RDS_TCP_RCVBUF].data =3D &rtn->rcvbuf_size; - rtn->rds_tcp_sysctl =3D register_net_sysctl_sz(net, "net/rds/tcp", tbl, - ARRAY_SIZE(rds_tcp_sysctl_table)); + rtn->rds_tcp_sysctl =3D register_net_sysctl(net, "net/rds/tcp", tbl, + rds_tcp_sysctl_table); if (!rtn->rds_tcp_sysctl) { pr_warn("could not register sysctl\n"); err =3D -ENOMEM; diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index 47660d5726bbd7d812762f4feffa9a0a42499d7d..6d3d8d6905ace1c1b022951fab9= b3f26c4a87c0a 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -48,8 +48,7 @@ int __net_init unix_sysctl_register(struct net *net) goto err_alloc; } =20 - net->unx.ctl =3D register_net_sysctl_sz(net, "net/unix", table, - ARRAY_SIZE(unix_table)); + net->unx.ctl =3D register_net_sysctl(net, "net/unix", table, unix_table); if (net->unx.ctl =3D=3D NULL) goto err_reg; =20 diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index caebef73ea58d2b6043ca3fe3b6872f92fbe9fa6..b1fe08249050e95d4c945a8b670= f21d5c444ebf4 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -2952,8 +2952,8 @@ static int __net_init vsock_sysctl_register(struct ne= t *net) goto err_alloc; } =20 - net->vsock.sysctl_hdr =3D register_net_sysctl_sz(net, "net/vsock", table, - ARRAY_SIZE(vsock_table)); + net->vsock.sysctl_hdr =3D register_net_sysctl(net, "net/vsock", table, + vsock_table); if (!net->vsock.sysctl_hdr) goto err_reg; =20 --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 469DB3C1400; Wed, 19 Aug 2026 02:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106608; cv=none; b=YDcgu4OipCdh+wJ+g1Gbl3b67R9snSygzDqukm8y2RaLqTvq+XJAXrMzBODpxDsFqBucZ1p4l7psBHijNVCUV26jui5meVtY9aZwpYmOv2cAG6vUQTx6a5A6LD72C9UtwK8i/zNoBRLtXYl3SvRIvsO6VzFRsSXvgbTA73ijsYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106608; c=relaxed/simple; bh=wRLwCiuqMttYVsCHPxBkzo19GaoHrSC1wLITrsCEBiI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GfRC/e5hccSnGnit8X28mfWTS9UUWAFi/Lsd7wpex/gHwpxB254vVw0HF2dW193y12UjD8le5/nvxfJwK0W/VnV5NR+mTeZUk5IZLBI/o9IaJ8UctRjS7Lcf33CWzmadbCfkdaZjk7qp4i/ttFSJHmQnVVz5FhcqSpS1ZKafOXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=KCSNnzlH; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="KCSNnzlH" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=JxjRhJ2z8K0GvxyVrmaAYfCElgRxeZGrAv21+ElqaE4=; b=KCSNnzlH7WW2uHebELEkI9D3mx wmFxgNFJZaGBJMPOJonDX3s8XGQCgmdDpBs3uNMTurfuP8O0TY6cyF5jHYPfJm5mcwDHJeyY+hi0s ikJ07LGeBqEPE85gz4EDS/ffIRUssPl1h5WP+ReKkx+XWTSSOBtTcS8Edc92vzF4zp6LEIgu2+OPW QmXnydsWCWxKtBzAxiGD7xDhU6Pb6J57WDSlLMdD6Z8avCevz2f1qbu1CtT5i9Z5pDgwumD9gVmfu xlgdUvKkMqozthYYuugheU5F42FKImsBBcwSJ5teKqAY0qaPtNWolcu0bFXJwUCepaFAc5dJERxfC Aerc4tdw==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW43-005tfG-Ti; Wed, 19 Aug 2026 04:30:04 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:08 -0300 Subject: [PATCH RFC v2 09/13] sysctl, ipv6: update register_net_sysctl{_sz}() callers with template arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-9-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 The sysctl table definition and registration must be in the same file, in order for the macro to work. Add plumbing to register ipv6_{route,icmp}_table in their own files. With this, ipv6_{route,icmp}_sysctl_table_size() can be removed. Signed-off-by: Mauricio Faria de Oliveira --- include/net/ipv6.h | 6 ++++-- net/ipv6/icmp.c | 6 ++++-- net/ipv6/route.c | 10 +++++++--- net/ipv6/sysctl_net_ipv6.c | 10 ++-------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 3de07e738538f783e0fb4628c92ce50a7e36f9f5..29a095798abe8f5730ab0a04693= 1ebf78f481bdf 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1220,9 +1220,11 @@ static inline int snmp6_unregister_dev(struct inet6_= dev *idev) { return 0; } =20 #ifdef CONFIG_SYSCTL struct ctl_table *ipv6_icmp_sysctl_init(struct net *net); -size_t ipv6_icmp_sysctl_table_size(void); +struct ctl_table_header *ipv6_icmp_sysctl_register(struct net *net, + const struct ctl_table *table); struct ctl_table *ipv6_route_sysctl_init(struct net *net); -size_t ipv6_route_sysctl_table_size(struct net *net); +struct ctl_table_header *ipv6_route_sysctl_register(struct net *net, + const struct ctl_table *table); int ipv6_sysctl_register(void); void ipv6_sysctl_unregister(void); #endif diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index a95b0351824f3237815e43bf8448110070955884..bb170b8c867c3c6eaccc41aab8a= b1c65eb0aa24b 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -1450,8 +1450,10 @@ struct ctl_table * __net_init ipv6_icmp_sysctl_init(= struct net *net) return table; } =20 -size_t ipv6_icmp_sysctl_table_size(void) +struct ctl_table_header *ipv6_icmp_sysctl_register(struct net *net, + const struct ctl_table *table) { - return ARRAY_SIZE(ipv6_icmp_table_template); + return register_net_sysctl(net, "net/ipv6/icmp", table, + ipv6_icmp_table_template); } #endif diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 16dfac54a259a11410ba736535f0462070979276..9e3f849d3564f4312d7b6415747= 1f50c8168aafd 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -6698,13 +6698,17 @@ struct ctl_table * __net_init ipv6_route_sysctl_ini= t(struct net *net) return table; } =20 -size_t ipv6_route_sysctl_table_size(struct net *net) +struct ctl_table_header *ipv6_route_sysctl_register(struct net *net, + const struct ctl_table *table) { + size_t table_size =3D ARRAY_SIZE(ipv6_route_table_template); + /* Don't export sysctls to unprivileged users */ if (net->user_ns !=3D &init_user_ns) - return 1; + table_size =3D 1; =20 - return ARRAY_SIZE(ipv6_route_table_template); + return register_net_sysctl_sz(net, "net/ipv6/route", table, + table_size, ipv6_route_table_template); } #endif =20 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index 75ba17cb7c0ccb4769d61e74220c75d0b3e2bcd9..88138fbd42b85d54d00cd15dfd7= d6848ebabd607 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c @@ -280,17 +280,11 @@ static int __net_init ipv6_sysctl_net_init(struct net= *net) if (!net->ipv6.sysctl.hdr) goto out_ipv6_icmp_table; =20 - net->ipv6.sysctl.route_hdr =3D register_net_sysctl_sz(net, - "net/ipv6/route", - ipv6_route_table, - ipv6_route_sysctl_table_size(net)); + net->ipv6.sysctl.route_hdr =3D ipv6_route_sysctl_register(net, ipv6_route= _table); if (!net->ipv6.sysctl.route_hdr) goto out_unregister_ipv6_table; =20 - net->ipv6.sysctl.icmp_hdr =3D register_net_sysctl_sz(net, - "net/ipv6/icmp", - ipv6_icmp_table, - ipv6_icmp_sysctl_table_size()); + net->ipv6.sysctl.icmp_hdr =3D ipv6_icmp_sysctl_register(net, ipv6_icmp_ta= ble); if (!net->ipv6.sysctl.icmp_hdr) goto out_unregister_route_table; =20 --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 501A43BBA0F; Wed, 19 Aug 2026 02:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106615; cv=none; b=Q+qyLUm8ibMhT9a+PZTGFqG/u4yfxYfZQgwpVuPNx9CDDf7/P9EQRMA2avnVyiJd43dAjanvx87T1m7dAdZA1j0c4NlbPmggGqP1ohatyWWmCRI8jUytsOxF7YXbLgWofTkSMzQNcX/pNmO8sN+nMLYUuSBHdoQUZI0maD8ghfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106615; c=relaxed/simple; bh=8ufdlGQoDs+51tVl3N2x5MnJ7S98wl7FolVU0AHZNNA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oKbZM/ZNb8ZTgzsZR3HAdpp1ZtjYHE8o9iC4OAmur2uWdAKSre51icF2ytlgItGp9ce/9veD/4NcWLMt9KRJec65dWFSVTPF+sqRylxfGIN1ZZOKn2BUuQ87rZJccGhmsVyZqE71DrCiMaPvMc/NoJtstY/WzMoyaDl6+Mk1iW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=GNwOgvD1; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="GNwOgvD1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=IuE38fL6h7PEmzt/UNWdPfgVu72Lk4CiXzTD+qO+pWo=; b=GNwOgvD1AZmUImC0F5BHb4J4CH J4W97Eo0NkLvb5hoXYMflby0Bjo1H2wBsJFdmKWDTh869qriEPgapAimR58yHbMEIt8eAU8WIdMFD Beq0RuAkALqd6jSDkwAmeC9JafZ037OIGKKfczG4HnQqy0lP8dLDffdZ9n7Ooc+wmWeKZF7rdicud keGSVF7hEkO2GLVq7tToxxmSj/Aq6vkBYY4UvPxBmpZTbjlyekrRFJC5axfOKE3VLoF40QnFI31Aq nvlFuRiaeB/SLm0R1MVCeEVWlvSFEW6CkHiRr7MqI+ah6buGMEfc6jhXXFHXKHmiWazlZai3FLQ77 Pr1VBPQg==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW4B-005tfG-0q; Wed, 19 Aug 2026 04:30:11 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:09 -0300 Subject: [PATCH RFC v2 10/13] sysctl, net: update register_net_sysctl_sz() edge case Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-10-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Handle the last (edge) case: - nf_log.c: ignore sysctl table with template set at run-time. And re-enable the macro. Signed-off-by: Mauricio Faria de Oliveira --- include/linux/sysctl.h | 3 --- net/netfilter/nf_log.c | 9 +++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 9e00a086ff1d47ab18021b3d79b0e8a93037cb2d..7e05fafd5544e1c4a3283dc13b0= 692f39515d01e 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -309,9 +309,6 @@ struct ctl_table_root { * * Define the macro SYSCTL_MODULE_ALIASES_DISABLE to disable this. */ - -#define SYSCTL_MODULE_ALIASES_DISABLE - #if defined(CONFIG_SYSCTL_MODULE_ALIASES) && defined(MODULE) && \ !defined(SYSCTL_MODULE_ALIASES_DISABLE) =20 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c index f4d80654dfe6ab6abd886e224f400e4444bcd29b..ed4a5a6b8d95b82676397f6747e= f5d988c9060ea 100644 --- a/net/netfilter/nf_log.c +++ b/net/netfilter/nf_log.c @@ -518,10 +518,11 @@ static int netfilter_log_sysctl_init(struct net *net) for (i =3D NFPROTO_UNSPEC; i < NFPROTO_NUMPROTO; i++) table[i].extra2 =3D net; =20 - net->nf.nf_log_dir_header =3D register_net_sysctl_sz(net, - "net/netfilter/nf_log", - table, - ARRAY_SIZE(nf_log_sysctl_table)); + /* MODULE_SYSCTL_TABLE(): template table's .procname set at run-time. */ + net->nf.nf_log_dir_header =3D __register_net_sysctl_sz(net, + "net/netfilter/nf_log", + table, + ARRAY_SIZE(nf_log_sysctl_table)); if (!net->nf.nf_log_dir_header) goto err_reg; =20 --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 6A524481B1; Wed, 19 Aug 2026 02:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106622; cv=none; b=I303VjCtYg2oUbEJDqPt8NgnUetX6pWcdfDNSB2IDNiNu5uTFznym6Isi6j7nwl8xUDi6F7SniVrrZes4d/GxzLTNIeqNJB0ovmVCgMj1jqiP9y+2ZMc90vCkQD2BabiS1HFVefmqahp3VB/VIZ+SumzlFMofQ5wl/aHJWZKy+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106622; c=relaxed/simple; bh=WnJK16aZlJCfl4caW7N9hPaZqf5/RToHwGPjPgIoN7A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IU0Co4Cp6z95FoDHKKttbqJC1awIyCGjU/mCHOKF22jJhA4lwulnegKF8E8X8LmJJsUOk0C5VAytqCW7+ShEziBF63AhjiLn/h5uFqecuDFCi1X0goK5YZ0nDItb0c9L6rRloKjahPTACyGNBbozRdtZOyzPWG8s+1pT1/dt7t4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=BEOtuYvk; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="BEOtuYvk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=jcWdQbXP/kHWb1xcpo26FcJ2qHm9uH6N5DjjZNrZnS8=; b=BEOtuYvkZx34qtwPCbyxsdAsY6 wt1vEcZkneUIRDRvOjlvxWGKMLwGz4LB5AulnRi+hi2VF/YgQJMigWj0G6OcRTrnRRPIc+u6lHxVh 99019UvHalg7deeX6cY5LcGi0gXIBYrLkTjmdTrJYnpVZT9fHkcr9vwcCQC2P5RHnhEyleMv/iMRE 0b5a0cSslBLc+6mj05KF9pvvh0jLjS6JdJY9ktYVFg09l74rRgKv9MJ3cLq153lIfP3dnq0tPLyfe T/8v3hIBd+X+5ToJ4s7UaHrOB4QhkU3y7ZFvMM++E59w9yj7Vl+gJa2tbVAEv9aYQeGp+IdxQEzSj 5vaLg+wQ==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW4I-005tfG-44; Wed, 19 Aug 2026 04:30:18 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:10 -0300 Subject: [PATCH RFC v2 11/13] sysctl: unrandomize struct ctl_table.procname Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-11-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 The 'struct ctl_table.procname' field (sysctl filename) cannot be accessed by scripts since it is defined in kernel headers (see "don't include kernel headers into userspace" in file2alias.c) and its offset may be randomized. Unrandomize '.procname' as the first field so its offset is always zero and match the 'struct ctl_table' symbol address, which can be found by scripts. Originally-by: Mauricio Faria de Oliveira Signed-off-by: Mauricio Faria de Oliveira --- include/linux/sysctl.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 7e05fafd5544e1c4a3283dc13b0692f39515d01e..120c0f05bd083e08d8104ff0513= 6138f2e8cdb07 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -220,7 +220,14 @@ static inline void *proc_sys_poll_event(struct ctl_tab= le_poll *poll) =20 /* A sysctl table is an array of struct ctl_table: */ struct ctl_table { + + /* This must be the first field for module aliases (file2alias.c) */ const char *procname; /* Text ID for /proc/sys */ + +#ifdef CONFIG_SYSCTL_MODULE_ALIASES + /* This begins the randomizable portion of the struct. */ + randomized_struct_fields_start +#endif void *data; int maxlen; umode_t mode; @@ -228,7 +235,14 @@ struct ctl_table { struct ctl_table_poll *poll; void *extra1; void *extra2; +#ifdef CONFIG_SYSCTL_MODULE_ALIASES + /* New fields go above here, so they are in the randomized portion. */ + randomized_struct_fields_end +}; +static_assert(offsetof(const struct ctl_table, procname) =3D=3D 0); +#else } __randomize_layout; +#endif =20 struct ctl_node { struct rb_node node; --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 CA9CA481B1; Wed, 19 Aug 2026 02:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106629; cv=none; b=qOF1GR3pjBoLrLL1s2CbufriXXJ3eQ2SZujERF5nQon+C9PvN75bi+PXo3ou1GPSgtB0fSLNG0Hrp5PMXJ+QZbQPm9onK0RJr113JGm+pVWRXDzGr8P57d4oOuoNGaH/JhqgZRGhqyCZ4nnEOXL3Xk20CIu80W6qhgLBzqP2ouM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106629; c=relaxed/simple; bh=vUfOIiG3lMRcheFBBxX0asKqrhYKFq5a+zslU3lY20g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RohJ8yap7uzYSSRCgIJnXmUlTW9EYm0YlqfDZGTiofHrrCzTKebxubVbjon9OHJmnUzCJbGCkJ2iX+uspz4f19wRTxjoa9B076kF+HRSyVPhUcR5WD7fKUMx7nxK56ZR3M+vH3fQJoKOYiwYmkP9B/rI9R/eZagtl3+5tDeIuK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=HrkMDY4X; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="HrkMDY4X" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=bnDCW7/LrZXWETxlVsz0e02k5adMYu/+BGoT1rCaICg=; b=HrkMDY4X+Oq+jraZDgmYtUHhyI XP6vLHO8FI0DPZqaCBwosC+1lXhJdekxfcPmQv1a5VRzntv+U9GIFt9AVPuvSrmTzaVRfVs+AevP4 s5XXLBRqXpgS3rnpYII8tWoSfrKvbvZDzQFUt2N6jjsxBlQfNZBA8kDodC2bXCs+GIP5aITQc03ne 0MvKYn2y1uzQOZ5xCef/wrdxiO0wsHP/euJ0p2OCtqYB0xAHgKj0iAia/m6qBxkN1xmEDDTkeuScl LIB+NVBL1u2O0c2mMjahoMywUOmHtLDyfOnvP7p2KMLWvIVTtiUSj6Lh4pX3FjGo4SN1q0q9RTyNE CMQHvKkA==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW4P-005tfG-7k; Wed, 19 Aug 2026 04:30:25 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:11 -0300 Subject: [PATCH RFC v2 12/13] modpost: move addend_*_rel() calls into addend_rel() Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-12-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Move the arch-based addend_*_rel() calls into addend_rel() to be reused. Signed-off-by: Mauricio Faria de Oliveira --- scripts/mod/modpost.c | 35 +++++++++++++++++++---------------- scripts/mod/modpost.h | 2 ++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 75374c64b8cc78bb4d01fa4c64254c7d7cd80e8f..d18a87b882a67f06d5f75ee92f4= c26dc713d83b8 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1296,6 +1296,24 @@ static Elf_Addr addend_mips_rel(uint32_t *location, = unsigned int r_type) return (Elf_Addr)(-1); } =20 +Elf_Addr addend_rel(struct elf_info *elf, unsigned int secndx, + unsigned int r_type, Elf_Addr r_offset, Elf_Sym *tsym) +{ + void *loc =3D sym_get_data_by_offset(elf, secndx, r_offset); + + switch (elf->hdr->e_machine) { + case EM_386: + return addend_386_rel(loc, r_type); + case EM_ARM: + return addend_arm_rel(loc, tsym, r_type); + case EM_MIPS: + return addend_mips_rel(loc, r_type); + } + + fatal("Please add code to calculate addend for this architecture\n"); + return (Elf_Addr)(-1); +} + #ifndef EM_RISCV #define EM_RISCV 243 #endif @@ -1402,27 +1420,12 @@ static void section_rel(struct module *mod, struct = elf_info *elf, Elf_Sym *tsym; Elf_Addr taddr, r_offset; unsigned int r_type, r_sym; - void *loc; =20 r_offset =3D TO_NATIVE(rel->r_offset); get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); =20 - loc =3D sym_get_data_by_offset(elf, fsecndx, r_offset); tsym =3D elf->symtab_start + r_sym; - - switch (elf->hdr->e_machine) { - case EM_386: - taddr =3D addend_386_rel(loc, r_type); - break; - case EM_ARM: - taddr =3D addend_arm_rel(loc, tsym, r_type); - break; - case EM_MIPS: - taddr =3D addend_mips_rel(loc, r_type); - break; - default: - fatal("Please add code to calculate addend for this architecture\n"); - } + taddr =3D addend_rel(elf, fsecndx, r_type, r_offset, tsym); =20 check_section_mismatch(mod, elf, tsym, fsecndx, fromsec, r_offset, taddr); diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index d5f6d82837d5b4fbd671ff9dab9bbe353442f6cf..a98811552bd2996c31cf73fd361= 9e6c58bac8a6d 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -222,6 +222,8 @@ const char *get_basename(const char *path); char *read_text_file(const char *filename); char *get_line(char **stringp); void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym); +Elf_Addr addend_rel(struct elf_info *elf, unsigned int secndx, + unsigned int r_type, Elf_Addr r_offset, Elf_Sym *tsym); =20 void __attribute__((format(printf, 3, 4))) modpost_log(bool is_error, struct module *mod, const char *fmt, ...); --=20 2.47.3 From nobody Sat Sep 26 12:28:32 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 AEAB72E888A; Wed, 19 Aug 2026 02:30:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106636; cv=none; b=qiH46Y6T8QTdtl4fAlhGvh02RdDKA5i4numzoyckglTQsGImeDI1QA/H5NEEjYvzoA7bpFveOOX9JxUQk2pgCnNXL3pJByE05S7F3d+h0tnuLyzYLkGnqH1JVT8I7W/uJKZYJpUnWGlqr8BQob1L3kjh/N/b/Jx6Do0LSP72lDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787106636; c=relaxed/simple; bh=f5o2O9UPHv5pX2VWOxwFtCNED6SACshLVdHxs505Pu8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jCRkZn2Wg4jwLS+1bl4MFS3QyjGhpCS56p3nOggZkkv16Co4BsFEJa9H1MjLq0US4qCSrBEp5hyVQ6+1Quw9r927ZUb9FlsHkBLohr3+M0hSryuQy/CdrICx/xPO100itJxeZeYwSC6L+RAzgx22572hDfhJ+ezZIbFZuAiRZAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=giJOjMqU; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="giJOjMqU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=wddugAF1IEM+cZdWDVa5PB4xseG8bsMauhbh/5skNPc=; b=giJOjMqUhmbHyNS+EgzZmF35wF ORFZgD/3YorjInbQI8oHNtL6VUZzZaDvelmiT4s7DmbmAKhQjMJRu3fjqqAA6pAUQZv0xrla2k8/A oc4ZNUzP6xTkwASejvoefETSBHm9I+J6S9lDuinbYAeVXnuSYQShxIx6ys7nktysLLq5zcGcM2mYj WjvdyfO8WL489Tf/YtFncC3dj8B1EI5bwPW8kAE9iyuEpgblK4AKH+mZlQQTCXC/yAzKXJB0A3bZG oY6KeZy3VpEba6Sqsib/YR1CnpLtdf+JoEYHjGnWXmVshPCIokphl8tuQmEhCoedfSVynLKFpTyP5 0ZrTKzjg==; Received: from 186-249-144-28.shared.desktop.com.br ([186.249.144.28] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wwW4W-005tfG-BK; Wed, 19 Aug 2026 04:30:32 +0200 From: Mauricio Faria de Oliveira Date: Tue, 18 Aug 2026 23:28:12 -0300 Subject: [PATCH RFC v2 13/13] modpost: handle MODULE_SYSCTL_TABLE symbols Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260818-sysctl-module-aliases-v2-13-d5a69dae5798@igalia.com> References: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com> To: Kees Cook , Joel Granados , Nathan Chancellor , Nicolas Schier , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: kernel-dev@igalia.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, fsverity@lists.linux.dev, keyrings@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, bridge@lists.linux.dev, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, virtualization@lists.linux.dev, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Update file2alias.c to handle 'mod_devicetable' symbols with type 'sysctl'. The key operation is to iterate over relocation entries, so add the helper for_each_reloc() with a function callback, and the functions to: 1) Find the sysctl path and table in the 'sysctl' module symbol. 2) Find the sysctl table's entries and their '.procname' field, adding a module alias 'sysctl:*//' for each. Originally-by: Mauricio Faria de Oliveira Signed-off-by: Mauricio Faria de Oliveira --- scripts/mod/file2alias.c | 230 +++++++++++++++++++++++++++++++++++++++++++= ++++ scripts/mod/modpost.c | 11 ++- scripts/mod/modpost.h | 23 +++++ 3 files changed, 262 insertions(+), 2 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 8d36c74dec2d55840de60b3f8ec22b646d16ff8b..797cfc2f478e25dd2ba5f9a5a06= 3a2919fe58cc5 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1531,6 +1531,231 @@ static const struct devtable devtable[] =3D { {"pnp_card", SIZE_pnp_card_device_id, do_pnp_card_entry}, }; =20 +// Looks like: sysctl:*/path/procname +static void do_sysctl_entry(const char *procname, const char *path, + struct module *mod) +{ + const char *src; + char *dst, buf[256], *end =3D buf + sizeof(buf) - 1; /* -1 for NUL byte */ + + /* Replace '%s' from path template with '*' for wildcard in modprobe. */ + for (src =3D path, dst =3D buf; *src && dst < end; src++, dst++) + *dst =3D (*src =3D=3D '%') ? (src++, '*') : *src; + *dst =3D '\0'; + + module_alias_printf(mod, false, "sysctl:*/%s/%s", buf, procname); +} + +/* + * Execute a callback function for each relocation entry in relocation sec= tion. + * The caller must ensure sechdr->sh_type is SHT_RELA or SHT_REL. + */ +static void for_each_reloc(struct elf_info *elf, unsigned int shndx, + bool (*fn)(struct elf_info *elf, Elf_Shdr *sechdr, + Elf_Sym *sym, Elf_Addr r_offset, + Elf_Addr r_addend, void *data), + void *data) +{ + Elf_Shdr *sechdr =3D &elf->sechdrs[shndx]; + const Elf_Rela *rela; /* used as Elf_Rel[a] on SHT_REL[A] */ + const Elf_Rela *start =3D (void *) elf->hdr + sechdr->sh_offset; + const Elf_Rela *stop =3D (void *) start + sechdr->sh_size; + size_t size =3D (sechdr->sh_type =3D=3D SHT_RELA) ? sizeof(Elf_Rela) + : sizeof(Elf_Rel); + + for (rela =3D start; rela < stop; rela =3D (Elf_Rela *)((void *) rela + s= ize)) { + Elf_Sym *sym; + Elf_Addr r_offset, r_addend; + unsigned int r_type, r_sym; + + r_offset =3D TO_NATIVE(rela->r_offset); + get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); + + sym =3D elf->symtab_start + r_sym; + r_addend =3D (sechdr->sh_type =3D=3D SHT_RELA) + ? TO_NATIVE(rela->r_addend) + : addend_rel(elf, sechdr->sh_info, + r_type, r_offset, sym); + + if (fn(elf, sechdr, sym, r_offset, r_addend, data)) + break; + } +} + +/* + * Callback parameters and function to loop over the sysctl entries in str= uct + * module_sysctl_table's .table symbol (found below) in its reloction sect= ion. + */ +struct sysctl_entries { + Elf_Addr table_offset; + ssize_t table_size; + ssize_t entry_size; + const char *path; + const char *modsymname; + struct module *mod; +}; + +static bool do_sysctl_entries(struct elf_info *elf, Elf_Shdr *sechdr, Elf_= Sym *sym, + Elf_Addr r_offset, Elf_Addr r_addend, void *data) +{ + struct sysctl_entries *sysctl_entries =3D (struct sysctl_entries *) data; + + /* Skip until .table starts */ + if (r_offset < sysctl_entries->table_offset) + return false; + + /* Stop after .table ends */ + if (r_offset >=3D sysctl_entries->table_offset + sysctl_entries->table_si= ze) + return true; + + /* Check for alignment with an array entry (.procname at offset zero) */ + if ((r_offset - sysctl_entries->table_offset) % sysctl_entries->entry_siz= e =3D=3D 0) { + + /* The symbol for .procname points to a string */ + const char *procname =3D (const char *) + sym_get_data_addend(elf, sym, r_addend); + + if (!procname) { + warn("%s [%s] found entry with NULL .procname (skip)\n", + sysctl_entries->modsymname, sysctl_entries->mod->name); + return false; + } + + do_sysctl_entry(procname, sysctl_entries->path, sysctl_entries->mod); + } + + /* Continue at next entry */ + return false; +} + +/* + * Callback parameters and function to search for struct module_sysctl_tab= le's + * pointers (.path and .table) in relocation entries of a relocation secti= on. + */ +struct sysctl_pointers { + /* Input: offsets */ + Elf_Addr path_offset; + Elf_Addr table_offset; + + /* Output: symbols and relocation addends */ + Elf_Sym *path_sym; + Elf_Sym *table_sym; + Elf_Addr path_r_addend; + Elf_Addr table_r_addend; +}; + +static bool do_sysctl_pointers(struct elf_info *elf, Elf_Shdr *sechdr, Elf= _Sym *sym, + Elf_Addr r_offset, Elf_Addr r_addend, void *data) +{ + struct sysctl_pointers *sysctl_pointers =3D (struct sysctl_pointers *) da= ta; + + /* Check for relocation entry's offset matching .path or .table */ + if (!sysctl_pointers->path_sym && + sysctl_pointers->path_offset =3D=3D r_offset) { + sysctl_pointers->path_sym =3D sym; + sysctl_pointers->path_r_addend =3D r_addend; + } else if (!sysctl_pointers->table_sym && + sysctl_pointers->table_offset =3D=3D r_offset) { + sysctl_pointers->table_sym =3D sym; + sysctl_pointers->table_r_addend =3D r_addend; + } + + /* Stop once both .path and .table are found */ + return (sysctl_pointers->path_sym && sysctl_pointers->table_sym); +} + +static void do_sysctl_table(const char *modsymname, void *modsymval, + Elf_Sym *modsym, struct module *mod, + struct elf_info *info) +{ + /* + * The struct module_sysctl_table symbol contains 4 fields: + * .path: pointer to string with the dirname in /proc/sys + * .table: pointer to struct ctl_table array with filenames (.procname) + * .table_size: size of struct ctl_table array + * .entry_size: size of struct ctl_table entry in the array + */ + + /* The size values can be read directly. */ + DEF_FIELD(modsymval, module_sysctl_table, table_size); + DEF_FIELD(modsymval, module_sysctl_table, entry_size); + + struct sysctl_entries sysctl_entries =3D { + .table_size =3D table_size, + .entry_size =3D entry_size, + .modsymname =3D modsymname, + .mod =3D mod, + }; + + /* + * Step 1: + * + * Each pointer has a relocation entry in a relocation section, + * that links the pointer with the symbol it points to. + * + * In order to access the symbols pointed to by .path and .table pointers: + * 1) find the relocation section of the struct module_sysctl_table symbo= l; + * 2) find the relocation entries for these pointers by their field offse= t; + * 3) then use the symbols found in these relocation entries. + */ + + struct sysctl_pointers sysctl_pointers =3D { + .path_offset =3D modsym->st_value + OFF_module_sysctl_table_path, + .path_sym =3D NULL, + .table_offset =3D modsym->st_value + OFF_module_sysctl_table_table, + .table_sym =3D NULL, + }; + + unsigned int shndx; + + /* Find the relocation section for struct module_sysctl_table symbol. */ + shndx =3D get_reloc_secindex(info, modsym); + if (shndx =3D=3D SHN_UNDEF) { + error("%s [%s.ko] cannot find relocation section for symbol\n", + modsymname, mod->name); + return; + } + + /* Find the relocation entries for the .path and .table pointers. */ + for_each_reloc(info, shndx, do_sysctl_pointers, &sysctl_pointers); + if (!sysctl_pointers.path_sym || !sysctl_pointers.table_sym) { + error("%s [%s.ko] cannot find relocation entry for path/table\n", + modsymname, mod->name); + return; + } + + /* + * Step 2: + * + * The .table symbol is the struct ctl_table array where each entry has + * a .procname pointer with a relocation entry for the filename string. + * + * In order to access the strings pointed to by .procname pointers: + * 1) Find the relocation section of the struct ctl_table array symbol; + * 2) Find the relocation entries for these pointers by their field offse= t; + * 3) Then use the symbols found in these relocation entries. + */ + + /* Find the relocation section for the struct ctl_table array. */ + shndx =3D get_reloc_secindex(info, sysctl_pointers.table_sym); + if (shndx =3D=3D SHN_UNDEF) { + /* Edge case: empty .table: no relocation section. */ + return; + } + + /* The .path symbol can be read directly. */ + sysctl_entries.path =3D (const char *) + sym_get_data_addend(info, sysctl_pointers.path_sym, + sysctl_pointers.path_r_addend); + + /* The .table symbol is the struct ctl_table array. */ + sysctl_entries.table_offset =3D sysctl_pointers.table_sym->st_value + + sysctl_pointers.table_r_addend; + + /* Add module aliases for entries in the struct ctl_table array. */ + for_each_reloc(info, shndx, do_sysctl_entries, &sysctl_entries); +} + /* Create MODULE_ALIAS() statements. * At this time, we cannot write the actual output C source yet, * so we write into the mod->dev_table_buf buffer. */ @@ -1542,6 +1767,7 @@ void handle_moddevtable(struct module *mod, struct el= f_info *info, const char *type, *name, *modname; size_t typelen, modnamelen; static const char *prefix =3D "__mod_device_table__"; + bool sym_is_devtable =3D false; =20 /* We're looking for a section relative symbol */ if (!sym->st_shndx || get_secindex(info, sym) >=3D info->num_sections) @@ -1586,10 +1812,14 @@ void handle_moddevtable(struct module *mod, struct = elf_info *info, if (sym_is(type, typelen, p->device_id)) { do_table(name, symval, sym->st_size, p->id_size, p->device_id, p->do_entry, mod); + sym_is_devtable =3D true; break; } } =20 + if (!sym_is_devtable && sym_is(type, typelen, "sysctl")) + do_sysctl_table(name, symval, sym, mod, info); + if (mod->is_vmlinux) { struct module_alias *alias; =20 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index d18a87b882a67f06d5f75ee92f4c26dc713d83b8..10eb7273cdd817da788fa3bce87= d695661dd1b93 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -340,6 +340,13 @@ void *sym_get_data(const struct elf_info *info, const = Elf_Sym *sym) sym->st_value); } =20 +void *sym_get_data_addend(const struct elf_info *info, const Elf_Sym *sym, + Elf_Addr r_addend) +{ + return sym_get_data_by_offset(info, get_secindex(info, sym), + sym->st_value + r_addend); +} + static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr) { return sym_get_data_by_offset(info, info->secindex_strings, @@ -1338,8 +1345,8 @@ Elf_Addr addend_rel(struct elf_info *elf, unsigned in= t secndx, #define R_LARCH_ALIGN 102 #endif =20 -static void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, - unsigned int *r_type, unsigned int *r_sym) +void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, + unsigned int *r_type, unsigned int *r_sym) { typedef struct { Elf64_Word r_sym; /* Symbol index */ diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index a98811552bd2996c31cf73fd3619e6c58bac8a6d..409fdfc844c4bfcea30fd6ae758= f4042384e3e56 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -186,6 +186,25 @@ static inline unsigned int get_secindex(const struct e= lf_info *info, return index; } =20 +/* Find the relocation section for the section of a symbol */ +static inline unsigned int get_reloc_secindex(const struct elf_info *info, + const Elf_Sym *sym) +{ + unsigned int sym_secindex =3D get_secindex(info, sym); + unsigned int secindex; + + for (secindex =3D 0; secindex < info->num_sections; secindex++) { + Elf_Shdr *shdr =3D &info->sechdrs[secindex]; + + if ((shdr->sh_type =3D=3D SHT_RELA || shdr->sh_type =3D=3D SHT_REL) && + (shdr->sh_flags & SHF_INFO_LINK) && + shdr->sh_info =3D=3D sym_secindex) + return secindex; + } + + return SHN_UNDEF; +} + /* * If there's no name there, ignore it; likewise, ignore it if it's * one of the magic symbols emitted used by current tools. @@ -222,8 +241,12 @@ const char *get_basename(const char *path); char *read_text_file(const char *filename); char *get_line(char **stringp); void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym); +void *sym_get_data_addend(const struct elf_info *info, const Elf_Sym *sym, + Elf_Addr r_addend); Elf_Addr addend_rel(struct elf_info *elf, unsigned int secndx, unsigned int r_type, Elf_Addr r_offset, Elf_Sym *tsym); +void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, + unsigned int *r_type, unsigned int *r_sym); =20 void __attribute__((format(printf, 3, 4))) modpost_log(bool is_error, struct module *mod, const char *fmt, ...); --=20 2.47.3