From nobody Sat Sep 26 12:28:43 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 4146A3CEB98; Wed, 19 Aug 2026 18:15: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=1787163367; cv=none; b=ADOKWlX2bhQ2f6dXTExkAusvZl4ZNPwi3tNJr3hTgNojvwM+vbv5jj8+rovdWRK0EBTsQPauAH0CdMfvUeDag23l+dYE99vEFNK+JB7U3rLVJlPfgSS5SdKex/xWadGwH+CShIDmOkZlIkGTrZ7kQTUmpnGVp8wZS19oWfPx0dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163367; c=relaxed/simple; bh=hSDaHlp+AtiPrqNRHKQvKu/6PNks2N1dJWDbN7fuL1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QkGoKpRsGusXVhcBYiuZlwxxiqBrpVgbHegCvV3vRhcqN8RLibGT+pfLOXCQirJXp1ntQ/B2/UYv9QefAz9fxKBkuGtYPmPulTFVibhPcFuc68UEthfgWvJxi1xTvOShtCwGFMWaFL+8Z6ufu31f3iw/57r4x3FbpZ9FpSu84Jk= 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=p76lPrys; 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="p76lPrys" 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=p76lPryssuRkpTwSeXIKI/EndK P7rVMyteRtpS/Hvs5QrpVSay0RpXX1SKfAOzvEPCEdB+2xm3b8XgYEbsm7Yy+zXzV5KHxqq2HFpTV Oce43cOvr2kd824oS0q+QLhyBKQo+6qviKodT08xWnBnQ2z09YsvkdjLEEP3QeaO+ksmI8jvhJsVA ehO/QVfPUQsMc+dpzW6Y30TFrwGcjSJqAmsmHAhDtEGHbwUxTOu7eDp8puClffGIE9SqS9793Ha9g YGIiZw6ZFmgQDgmzn4vZ3o2bs92g2qbHRDlxvTOG3NpFoZflKm0mBIYHZYUrPar9qdtcTdVmYPdKt c/mRZGfw==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpO-006ENH-PG; Wed, 19 Aug 2026 20:15:55 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:14 -0300 Subject: [PATCH RFC v3 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: <20260819-sysctl-module-aliases-v3-1-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 C16F54A2E21; Wed, 19 Aug 2026 18:16: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=1787163370; cv=none; b=cBIJyl5e+NoJdUaTCXxvw8S+vpg9N2NcmRBgFYuqdo9bYib8PB+EciPSAEt5HVBVtp0lZD7Fj4IwHMvJf6Wi3REW6UZTeTR99EL9mJ9GbcSbw/9jgWmVJzW8PwTSSGWDEUOAe9yD9H+9UWH5zdqYOhkEvUEtstqfuInSoHEdt+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163370; c=relaxed/simple; bh=YGnndkyJz+5FcFnyiRJNeZgq4ppwAqnOYIuLjGZwL9I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rsQiebV1MAQxUgrp3U91rY6dgF7Tx2As0MCT63GsP/lDTFryBunC3pjnwGJd1MBLHQ3CiKhG/i6Pbbo0AxvpUOfe+5owggj0k+B9AFxrGCqbL6LEZ7PN1bRMROQ5pcODQ3hcHsgWZeuzqE5msGcfqkOz0i/s2Q6J5viuUBDZGUA= 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=qC3QekU8; 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="qC3QekU8" 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=ejMylrBJLD/RiSl9pzRqjWJL0id2KLBq0dPByhCupIc=; b=qC3QekU8LcLUtIfZnNeTZcPd71 p5zsUzeyCNS89SPyLFrKlih+UqpUsSnE1uYZQbCbJm4vLP80WBnOBfjuV+wOfWgWlZKCJ23fG7wIt MPNUl6u3dh5ohGQ9foDpzunb6pkidUsf4fFsBi3OjT41Ce0hEAcoR2SyZy/3lM05AaaIKQ2kFd+bt nfBElxipJVjzC6lbIGPtHN/ymdTmDBwXhrGF4NwPH4JZr5BbjlccQ+p9xodwaJRSTb1goQJo9umDb fcQ8+1iimu5Cr1rXCzQD+owsME2B+gArhPqTOelPBQ1c9ER0sOt52+dllNt8l722BfEvhNne2xk7/ +9C2q/FA==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpV-006ENH-W9; Wed, 19 Aug 2026 20:16:02 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:15 -0300 Subject: [PATCH RFC v3 02/13] proc: add config option SYSCTL_MODULE_ALIASES 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: <20260819-sysctl-module-aliases-v3-2-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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..ea77cb2b0b0e3e52ff2d19d9bb1= 6d5a3f5ab8162 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 option 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:43 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 C681948EBF3; Wed, 19 Aug 2026 18:16:12 +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=1787163379; cv=none; b=gJdGUEwrLNySLPSUkJoyi8sSJuCSnF1fcjTjK2yFACL8ceilJKPvRL1+lMJh0QUc+LAsVF4wKR2S2qtCWO0s6Q0D/Fie3X6TJQHUcFuXawXiOPBvN1k5rpP+e4Ej99pgh6f3McNw1+eNeUvq+iMPkFWpA8huzkeRm5/KNHMZPfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163379; c=relaxed/simple; bh=RxzO2M6rN+H/ytlw4MDw0CINZz2xTYppSZUTyip3o2Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ifk2SZtncxuqwPNF/TeB0MHHqbbFfeeH+tq6NewXV3LYIXgHHJTTxoonoYO7lITkvSqmRL5GBrqCrOwFPAGb4BzrHqPhnycor1Oi3p6RaJSN7S6nZRGFm1M34T3EhuFJlfSN11oeEzcOcHA1tNSOpVTlqHmj8V1E8rHREZqzyLc= 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=GHUD+eSq; 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="GHUD+eSq" 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=AtbmO4sa1oP/x2/XURayQU2LL3evZi0sG28P1WYB6lk=; b=GHUD+eSqTJFBG8gtCXuG49kvMx 4GJsACyzrHb3fWzJJY7y/D/5eq6nn/U3ZNu1Tka3B1PBHsDGsI2GaD0szzqcJ6iMMGqF8i5AgbjNj tHleJ9w365Klk2yMAkuKzctw3WNTGzFMmCq0lvQNIURqsg8QEVE/j+wxXw7peByZjQX0Sblp8Dr1R FmC/5GyNzCe7I6ZyPBx0xJeUmQjYZa/F3e6Zfn1mzVtaxLkonUNTYkDedCjGdhzQwZMUBVasfL2c7 C+prvWhkaEltCrnJ71Wo9H/CDjBVL047v+PgaYl29id1EUcy6Cb4GFfF1gvK0oqXI7Jctx49iqChA 3RpNymkg==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpd-006ENH-64; Wed, 19 Aug 2026 20:16:09 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:16 -0300 Subject: [PATCH RFC v3 03/13] sysctl, mod_devicetable: add macro 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: <20260819-sysctl-module-aliases-v3-3-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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..0adc056ff54d895500c376361fe= 966bfa5126a3e 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(sysctl)) +#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) + __must_be_array(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:43 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 1B3764C8FFA; Wed, 19 Aug 2026 18:16:18 +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=1787163381; cv=none; b=EM8mjC4MVOrqlt7JeqDRmBHn2NEjmCJmdAVp98lgdkTB6TBEPstZX0tdKp0vbzDeKzYYmzshJbXDA9Ur3f19Y3k9aBzAtV62twoN5Sj0CcAjS49jmbQuXm8wSvtAi5JJr6qbl/oBD5aZEJ2k4HQAEXkSaQQ5T8kcnxp1e+ULrRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163381; c=relaxed/simple; bh=PRtGzu74CeOxQAJAh9C/zLwsPu+uZamwYvVSP1RP4d0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cNEAWkq84XgOiEv+Vj92ZeTQsCvOJZBhR86qb4yoJG/mi4DqqILaBDFt3v8xTz5bh4SLWeIGLwHeUEMzMhmwDam9IzhB9ijQQL6Pj/WhJsKtyGQCT/CK8Uf4yf4jMupY3gb+mri2XTj/5Vs0s2YV9cb70jGqZGs5SAcBBratLSw= 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=Mzi3TkBe; 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="Mzi3TkBe" 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=QKxY/gFZnQu4jxWnpEu3gzJTE7ZyPsLaoqObnd0OYGg=; b=Mzi3TkBeeBV8mL+FYrlmLuIT/U FZdRFy43Lt23SSkImSMa2y2bkcjKvPT3+yR7t+VjX+C4kzlPNY1ZcvcTmNs1cJZ60UNDoZGfc1KGx wkFHFbtsOLHgvp80D40Deet11YpPlm+5H0KuRAW49v1FDUdaRJMbuyYDWntZx91jRATLiHbXAdC8l lZzZgWaVfwvbuKk30WQha2Yn4+8LOLU2OYUW5HTAEneASF/hSGN79hN5es4+gYpX9/AhAXsK9rAkx EJ64/DHGVkb6+zUsR4q+oViVus0+CCUiTHV3HZfA0J/JSKx7Krd+Q7NN5V94pGh06RB4Hz89x3faQ P1xSt6LQ==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpk-006ENH-CO; Wed, 19 Aug 2026 20:16:16 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:17 -0300 Subject: [PATCH RFC v3 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: <20260819-sysctl-module-aliases-v3-4-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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 0adc056ff54d895500c376361fe966bfa5126a3e..b808fbc1d964f453db8e354825f= d8800db1eecd3 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:43 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 71B064B8DDA; Wed, 19 Aug 2026 18:16:26 +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=1787163388; cv=none; b=I5WB/iBLEfJNmkn0dSFFyeaJ1MeEGdKjTruaBcpZnEgvBjPlNoFBGBdwOztrHXMuq+Qpt8HQp1qklmebrfDlTENt+8D6OZTC/Um3tlmg2SiwEdi3fZn85gF7ezk5WGqAoLfg1UhYEjI6cMO+CdW7083YOWuTc4n13r0iLZd3oMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163388; c=relaxed/simple; bh=6sl9aUdgsqr1MH5G5ILk8v03G3sClQ3TxOzzAtQ4RdI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=putuNIWa9/xnAgJ9uDDUFsSnIglDpcHN4VOvZzdmfUg6jIBPExz5IwB2LMIFt0om1+mAWd0adEq99oaEout5Sd3uKxKLp5PW4KlaSDZqxLALU4vlsWJ3mNUjPlca0rfaf17+RmA3+OY/iVTVKIMfLUZdN+ThUP6gy70JBfIWX4s= 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=FDOOVmnE; 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="FDOOVmnE" 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=FDOOVmnEQUiY/vACI1d5qtUYpE L4yHNPeTmCytvNHHbIcvv+Yp03iI8RpOe8mEW9LqX+tIRa774tmLLgCG2KSW9q/oA1jK3fI1ow9yA U94MJCsZyG3xSiOtUAN/8KikJ/hoZOXhWq9ZfxUxwpT+MehaeOdKScINDMNzW3P4WRG0+lftHhyB7 4xmfXmBa5oaF5ALkEHCVD6olVN7IcueXx/aypnA2nkREVfJpE2Y2n0BQI+Cs2pTMJW2Gmk70OucwW tHlQeqjYCanmvCTkPwDkPSiX4RUn/OA/a+RCffMtM4gvXx5i39FYab6cZKyM4lCfjxwMi1PH2Pfcj h4ihah+Q==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpr-006ENH-JA; Wed, 19 Aug 2026 20:16:23 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:18 -0300 Subject: [PATCH RFC v3 05/13] sysctl, parport: update register_sysctl() callers with template arguments 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: <20260819-sysctl-module-aliases-v3-5-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 3D1184B8DDA; Wed, 19 Aug 2026 18:16:33 +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=1787163394; cv=none; b=bG2GYryg5wbZdcbBHRgHtVeoPOrRA70OV55IUEHBgwv3B75I/00XGFFpfVTiRBZK+kBCSUVsqNPB1mK7HjidUt8hUS4hj8Tt7hJvw6KEmzEeily/sCtW2Nqfoz1+Zmzj/WKdADTPfSYe79Cj9dNxaB/XaRyy1dG7TCP3GTk0ipA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163394; c=relaxed/simple; bh=TGS8JrPjXAoBKDAl/mlNITsrhTwiuneA68Wy0j9sKr4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EykE2yrKLHT5KctmAV2Vw4eXsMHdR4/qZbDJH3SPdbyvfLgbFgpMG0woEzy9ZhKiONBLh6ES5f7EEMS1EBTcyGHeq1ei+vrwjYWdT+zfj4f7+N+9l21BH82II2eL4FL3AKv0DD8y3U7BdM9/52kjxMrjx/UKdseovzFGCSLKZOE= 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=MyutY6rG; 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="MyutY6rG" 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=XU8q8BLh95waaYKBoAp1NCJxsyOka/nIGvWcgZihLBw=; b=MyutY6rGyDy4+3kvV6rPdLKv9M D0/9MW1r/dP6TUCnj9F40ajpfDYKq2YViQWLUCY6QbB3tb29teaDGzTTRbgkE4/65ViBK40pu7UvG 37x3TLBBVDAz/fgir0WDKIXcJcESDBPL2FtagvSpA376Ek+1jVeQLJsEIx4qyrwjsE2OJs6lyEfTy Hwb/OFc/djVkQF5ODKaZ+wAVbsGd7dP+9jCEO56JqfGBpHxy1ZCGUxO3m/qzvMEBNBCE4iIGhk0K8 ebljwMilvJ6AUc9wrVPDXww7BY1TjHspnjXPomaZPTM9f6QvdJtqhcj1n5FLw0r1Csm7j+KAcUxnU vM02QDZg==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkpy-006ENH-Pi; Wed, 19 Aug 2026 20:16:31 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:19 -0300 Subject: [PATCH RFC v3 06/13] sysctl, net: add register_net_sysctl{_sz}() wrappers for 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: <20260819-sysctl-module-aliases-v3-6-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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 | 47 +++++++++++++++++++++++++++++++++++++++--= ---- net/sysctl_net.c | 10 +++++----- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index b808fbc1d964f453db8e354825fd8800db1eecd3..7241dbf7eb81ce9f906e33645d0= 3944671c5e6f1 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..c38ea2de35fe85c7ab8f1153a5c= 5681880b84840 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -520,17 +520,52 @@ 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; } -static inline struct ctl_table_header *register_net_sysctl_sz(struct net *= net, +static inline struct ctl_table_header *__register_net_sysctl_sz(struct net= *net, const char *path, const struct ctl_table *table, size_t table_size) { return NULL; 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:43 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 C21004BCAA9; Wed, 19 Aug 2026 18:16:40 +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=1787163403; cv=none; b=kSzrsc1J7hE6aEvnY0WP7HoAhkwQcUQFYrk4FkEd8iF7A7hwNs5ryh8J35Z7ntBSkORSupfMhXa/5oq3UE0eMImmcXDzPg2B0fbEZO/fNDQ6lsPNmzPIGLP5p7WWV60+t8hEaRvO2JYXHRbJCp1yUKvILBM4wWxGy0u4oNzxt+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163403; 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=LTD17xK6GiGj+IV+bdFwRladzy3KW8BKYN2RYSlB8TdrNDdbUJZs7/+iAhIgPBhYs5UHYKRILwyMbqN5ka1/9UGEl0iNQRMTJEa6KsGN6rPFROA5InnjW4HhY0sacXZ2O5H3Ado44BEIFqAyotFLccgukUcmMnoC9LrhFz0+9rg= 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=mYIud6Z1; 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="mYIud6Z1" 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=mYIud6Z1KrWl42S4eUQGcTqd3A uT4jzZMKNoCWFiXvF2MFFbVWFTUd+Nbs0E/qWvvVARMD0ZyoS6i6VRFTzilDgaO4yaQGwWToi4aa4 tvS1b1DPOek2kif+q5a96VXfVtPCJcevIjFFiZZngbbRE2Q4A8EPlBXNnhoTF8QIEUoKeEdmisjOW tJAt5TBs1glKFRl44+qwamerP/0w5T4PSNo/mr23cGO+++L/QRNId6xZRHcopfPJrr/T7LOdr8sqA DWUDYcVKEhdWFvRTdCtfZ99PpLw7FgqM2AcXXXyjvIsRGPjfrXYb6UBV7O9xLrFt07tHXvJN8SujD 7XzsdtHQ==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkq6-006ENH-0H; Wed, 19 Aug 2026 20:16:38 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:20 -0300 Subject: [PATCH RFC v3 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: <20260819-sysctl-module-aliases-v3-7-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 AC6104BCAA9; Wed, 19 Aug 2026 18:16:47 +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=1787163409; cv=none; b=Spt7HfYgjmF+XFIBDV65zRImD8MFUbwFL1nGOCqviGGB3kIUQC4CAIfqlRIYZBQTDdRD1PRlJGMIbzb9NVoMdPRXg8zlm+NMA1hnTa0nKWoYhInWENOwZptkFilGUy9iX49svkir7LTRs4tBMiVZuL+bLSqabQDfNT3LDpunIbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163409; c=relaxed/simple; bh=ghXZ0pNg3bc/gxhG0S2yq9sZf92+3XHOPiwZNweiMFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qI0wV1xTV/rGRKpFS+rzlFc1sjt22GEnnIAAfjTA3sp0tYvpDxnrGP+ZwnP5CzxEm8POXowQ9etNJNVEXC99LAIgrpcI/g5TtApHt3+0mSbVxbD9KWJNtMzG0tgDBzjjcXZe9QNfGzYymCjTkOabK7o55Vi4a0V+E0ZqEZwq2p8= 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=fY2hWMl9; 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="fY2hWMl9" 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=fY2hWMl9Buh+eGqIGMOtOcKqBR I27G4cDHfHxplGJ+f4SuPft3vJsSlFI4MryHdoGkV5oh/37feb31SamacRnx/lXtFDVauNCCLBDdF Yao8hJPoD1jEAw3zIHWFeGlWspIKFt8mP8fzlQnnnIm7nW+aDgzIkyzWM6VFxzFsFR6JRaM9YTw/h F0A8NYNDE917h7Bd5ENPfCm1HmBdDyDFS2y/GC4RlKpo0SyzQ9BnNdJfdju56zVmY+4ONLuCM2FpQ gen/hdyJxWwg2bpC+W8tnC1+UZegPuIpuA0dkjrMBh0fKWD4yKG8f12dH5a2Se1+tvdZYda/HL2af uDdBC7xw==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqD-006ENH-6W; Wed, 19 Aug 2026 20:16:45 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:21 -0300 Subject: [PATCH RFC v3 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: <20260819-sysctl-module-aliases-v3-8-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 DD5B34BC002; Wed, 19 Aug 2026 18:16:54 +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=1787163416; cv=none; b=XhSsVKSTf76HppgeL+wccqUDoU8sp5fEq9k7xnIYif4B7RF+jASDNivyyDTy5YWVNcfL1znri9F2C8ITzF+X9FgMpdIHhxIvu425HUKsRgLWSzHKAFMbc2pbomFr2bHtiFUFE/kDfJiY1gQhAFxo7nZcz+DgxRqXuyteDxt2ciw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163416; c=relaxed/simple; bh=wRLwCiuqMttYVsCHPxBkzo19GaoHrSC1wLITrsCEBiI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ORLS5CALRS/o7w5aDZPh2max97gHvQrK+OCgWRMAY2Jz7iI5Iu8hdl7tQ3jrrQ0Q6OwmSJG/l5yxz3oeD0/Jwc8ANkTGv2lodeZuUg/y3pfsLjNAlmzjgpSRxnPOZTrxG3X2fuWJZMUhHGIUKl5FWWNPTVXIr3jLnKuKDPMx0wk= 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=iWuYsS5t; 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="iWuYsS5t" 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=iWuYsS5tm52pjQ4kgmlptYTgtd aifA9yQgQdT+nxm3VOjYbywN6MsP1YBHVg3VDWxMP95M75P//gjgSE/tCcLHxdYSJPQJwL7Zey+08 s5aNQLAqT1CKIgkEh9e4hdchMruAE6HyUHcm91q8zvnio4vZSyZJYqGoFIlO0/OrpPx5+xn1ST2JT S9jo+yqtNq88/mklFXnw3sCwDGuTtwESCA0etBxC1XhX23NEv6Kv36US6yvqzLp1dMNYB6pM+i6dz KsdX4yL/MP6ijbKTU9LOyc3VqhqMooKawKNoTKa4ueXetef9dCeDK+l36m8P3uyb7MrWguAGbk8Ki oISyBZFg==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqK-006ENH-D5; Wed, 19 Aug 2026 20:16:52 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:22 -0300 Subject: [PATCH RFC v3 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: <20260819-sysctl-module-aliases-v3-9-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 5C3344A2E27; Wed, 19 Aug 2026 18:17:02 +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=1787163424; cv=none; b=u4Y9ekpDAoS1VM1RlnnCHif4HLz0g9F3GqfEay35hSPmWRXBkKOiVETK1CObO5BGtP37HfzQejRfVAXI4jkW1Ti6T+jV8XyqIAjV8KrE+GCuh52EZQ7YydJYt/m+wFaGN9UKb9oKBZKo4BH7rskTkbSjm+3THMrvAp4HZVit+u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163424; c=relaxed/simple; bh=vFnsgdfm+Ez1FVcoXh/WpI0AqAZzytkPHB4D3sXGHrY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TES5unrZLTpcYjGpFO+sstEJN4iJEvlRg5elSnaG6yv7M2kJXWMyZeSYjplH/bkQP7+p2sXSRWzEb677ZVRSGo943Mx0oC+a+YXQ9TxzvPNCdVnitxSQeJGkNMko9B+Wx2y4Bo+/fmuUhyjoIMmoZM+qyriZ3z5GVc1gN5gdSBw= 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=lYzkzf1N; 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="lYzkzf1N" 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=tQqqNi/yFOJx7LxHx0ugW5QhRFDQCKpFVzx/5PXbrcs=; b=lYzkzf1NaKmAELu1yafK3W+x+V oGdrM9zBjAFWyqADLV6q58FDgLa4N219iK9fDvirIdC8ydA2VwVGS9zgacLmIbHxVDRHAe5TMHYLX VBTQROh7W10FE7EQz7noq9hTrlsn2tOYtJi6OpYPnuHx8NVeeepTMv6uLNdVMRnAiv2ahKzFbtv7d uTuIgLQhMnoH4USfXP/vGV3qvU/heEOAfGXqmluLU7H0THUvhXRbVxPQB5Tx/S1SjPzu5sN6qivET 0ZEGng167tVdBnv8wP8WHH9uv0XzNxyZjveSnpe15MZZhi90rufObQunqfUnPnDiz4++88ZzVCEGR Qfdd3kfg==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqR-006ENH-Jd; Wed, 19 Aug 2026 20:16:59 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:23 -0300 Subject: [PATCH RFC v3 10/13] sysctl, net: update register_net_sysctl_sz() edge case 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: <20260819-sysctl-module-aliases-v3-10-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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 7241dbf7eb81ce9f906e33645d03944671c5e6f1..b808fbc1d964f453db8e354825f= d8800db1eecd3 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:43 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 56B494078CB; Wed, 19 Aug 2026 18:17: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=1787163430; cv=none; b=XICzgv8ZVN6OeaQsVZqxLtv/LIGMCj6X0rwLkGI2yFJlGQBzy1ou5p7VHEM9yT9xYgpaeetP9xo2UHpqNpl5+JVyBtnx/wM/7OUH9L6c58tRp0pgYAksTtKXt7r6m+8K9GVl5heTdkr2CB1RtDUkyitZMm6pzDS47RzG1PjqWpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163430; c=relaxed/simple; bh=ODFaAlYjAIKhqtF7rrOMrwhagt8MEmMADJR+9fzON34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b7sZu/prF5xD5yLmXMB1d2Rw620QDZpitemFl7G1tlOtNoaX7KhJL1Re2UT1D/FMBTJoFrhYYpy/vs3rgubEy6k6X6XLde7emYlnjWl0f2jnN3OAW2bYOwi2Odsc/2byByybH99rZ2a5CXO7OB13N6qgfCI2muotQWJMm+cNCRs= 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=AfLsSoBT; 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="AfLsSoBT" 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=47xAFsvg306prpgVajo74hEldqY7N4ca2VW9wdN3GaU=; b=AfLsSoBTiH5F9ZSQRAuAXOY1fp bb0y3sYHYFgwyVE6oEAVALFM3R21RF1jwvNv0UbRizwinPs4PkbEA5Rwkx0SFbcYbFbgb45B8Nzmz /3rOV3BebiA2wdR8Pl7X9CtORxSnoQiycjNEWBt2c4r2W4kmZ75rQPKk+CJLpai4v9s1afAAGD8nU oUO/5t+8EtcAglBFC75PabhKO74r0T6Ja5AveNM6odcKjOovuoslzTOHtsK66tGS52ArovowVe+Vm YQjbA+FgflQbpRMbn/6ufY5Scz8/w+WYVUq1cSDUtubabcsEQEF9rzRHM5xPmZEw87jFoyBWwoSK2 +N2sZ4aQ==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqY-006ENH-QS; Wed, 19 Aug 2026 20:17:07 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:24 -0300 Subject: [PATCH RFC v3 11/13] sysctl: unrandomize struct ctl_table.procname 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: <20260819-sysctl-module-aliases-v3-11-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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 b808fbc1d964f453db8e354825fd8800db1eecd3..ccc77bb918614b1de1e44fbef70= 471c85fb55c09 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:43 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 B8EBF415B6C; Wed, 19 Aug 2026 18:17: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=1787163438; cv=none; b=DKPfdhD6BlAjc0yDqIhF5a4izavH0hQ6eAzT4t7cVCdsTNpImhsYdM3lbZxvhL+tS6Pwf9pJoLjUI5BGkZEZX5c8Tsz2jtIG1KsKPsgZz+H+arqCfsljllvIbA2FN8QSNvoT+s7Botd31mdv08EIPirChQ52FAOCckg8I0+bAuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163438; c=relaxed/simple; bh=vUfOIiG3lMRcheFBBxX0asKqrhYKFq5a+zslU3lY20g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m3x2nD4CsAilwkVDB3Rf/rx5mjHeecmfc0PKUcJwp67PxhzjguyS+M2qLE5kQ9r3MG+Gh0dnRibDl2ifUQRP7nJNQp3Nb5nV7gBwI93wpC5rLA2/C9HNbhmh2e0ZOojOMKfopI0L+Oqy4jdLGKPREkgMnKfFdhqDtnXPf1t354M= 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=oBGbw0t3; 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="oBGbw0t3" 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=oBGbw0t3FHxrW1LvQvHvsKnuz2 M97XEKa1cu10N3eaVs1S7lPRFzvNZeCzlqwpN7OgC9P7IeRF1TJIcf6JguJgXUKV2OIOgoEM/kf8q T1LXmcoiKqfkgF2uC5AuBHbOFW6w5ooKcgiO/IhKyp/GGKMPwfHjUwAvLOtER5GZ8AyO41RbdGdsw U5ftvELHATXaV012sqP5g3dfsnZPVBWxjJBH0fT3LkYNB90kB2D8imhdpIUYYbl3sgG0ji2ZLqdiw aZ903J8GL8ZhBhdO9dZJxBvky5op5p1YXFU8Nw51cg+60PgWnZ5vCVkqFe7EJ1Pxi0D6E5qf26Eb0 lXq+FUTA==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqg-006ENH-14; Wed, 19 Aug 2026 20:17:14 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:25 -0300 Subject: [PATCH RFC v3 12/13] modpost: move addend_*_rel() calls into addend_rel() 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: <20260819-sysctl-module-aliases-v3-12-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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:43 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 CC5E73B47E0; Wed, 19 Aug 2026 18:17: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=1787163445; cv=none; b=M49MnuhJYm13Bzg6Og+gz/LLBawU03/z507F6Y33Ka2DaIWLuQEQNIF3bWnr+r5TP0RAmpE8wqcYSym58yfGBrjEG8W5ZfkLoLJ/1xppoD5verCSfzwBwOpFr3Kzg44lbEY1cJ+VQyhQFcHxh64mAuem1T1URLSEt3lWhw9l0ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787163445; c=relaxed/simple; bh=WQRS2RHH2akgWDVpelBmiZG1coEA2yQ3av12m9vmhk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fOtTMMRm2ztIGrpW0OkSdiG/1cKylhDZH9DWVOiyXui7e/R8rAOUEQfbQTYj7L0pi84BFLUom7aRb+xu+N6PKM6bgIrY6rAMQgUE+34tbF9sxArt2S0aByqsXFQgQ8akK0M5Yc+RnpJ5f7nCgFYAQKEZQApgcROodMgGjWA79dQ= 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=rIAa4iWO; 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="rIAa4iWO" 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=jKOtxlRf7QwQPlRJp8elszSh59Tvs6EEuFjMe2Gw8W0=; b=rIAa4iWOu300Mt0xJf/kHgsZxB wwc8d4w2ZzpPAguxJYkf9Efsz9XPxW+CrpDnxK9np0s+2sFX667qE7+008RASjD9kCLI89C3oIugG ap2k9horEn1ErTZvHVp2nrd07Rd82KEhzag3VltGdsJWKrfP05PE/Gp7aPk26ALy4oKAEzh8gB5DC v4vzgUNX3jwzoT7r2ZJZfCFHZXC52qU6Bduieb8vVP6u/QyeStQ0KRg26BppZsbtRf1wLLg1uczJA czhwMwL3kaRxR5H6o5NaxdnScHzifbt9bVHqKiupBXdW9Hcj3weQrrIHAquk/TbMzSRrYz94sB1KE RP5a0xkQ==; Received: from 186-249-147-181.shared.desktop.com.br ([186.249.147.181] 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 1wwkqn-006ENH-88; Wed, 19 Aug 2026 20:17:21 +0200 From: Mauricio Faria de Oliveira Date: Wed, 19 Aug 2026 15:16:26 -0300 Subject: [PATCH RFC v3 13/13] modpost: handle MODULE_SYSCTL_TABLE symbols 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: <20260819-sysctl-module-aliases-v3-13-aab90569365d@igalia.com> References: <20260819-sysctl-module-aliases-v3-0-aab90569365d@igalia.com> In-Reply-To: <20260819-sysctl-module-aliases-v3-0-aab90569365d@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 | 237 +++++++++++++++++++++++++++++++++++++++++++= ++++ scripts/mod/modpost.c | 11 ++- scripts/mod/modpost.h | 23 +++++ 3 files changed, 269 insertions(+), 2 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 8d36c74dec2d55840de60b3f8ec22b646d16ff8b..abf6ce69831e2ed80a72e38df13= 53e44d886562c 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1531,6 +1531,238 @@ 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, *end_src =3D path + strlen(path); + char *dst, buf[256], *end_dst =3D buf + sizeof(buf) - 1; /* -1 for NUL. */ + + /* Replace '%s' from path template with '*' for wildcard in modprobe. */ + for (src =3D path, dst =3D buf; src < end_src && *src && dst < end_dst; s= rc++, 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; + + /* The .entry_size value must not be zero. */ + if (sysctl_entries.entry_size =3D=3D 0) { + error("%s [%s.ko] invalid entry size (zero)\n", + modsymname, mod->name); + return; + } + + /* 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 +1774,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 +1819,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