From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Kees Cook <kees@kernel.org>,
Joel Granados <joel.granados@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
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 <mfo@igalia.com>
Subject: [PATCH RFC v2 04/13] sysctl: add register_sysctl() wrapper for MODULE_SYSCTL_TABLE
Date: Tue, 18 Aug 2026 23:28:03 -0300 [thread overview]
Message-ID: <20260818-sysctl-module-aliases-v2-4-d5a69dae5798@igalia.com> (raw)
In-Reply-To: <20260818-sysctl-module-aliases-v2-0-d5a69dae5798@igalia.com>
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 <mfo@igalia.com>
---
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..cda3221e386ed7a4afc898b3d0313081dee5b49b 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -13,6 +13,8 @@
* Cleaned up include files - Russell King <linux@arm.uk.linux.org>
*/
+#define SYSCTL_MODULE_ALIASES_DISABLE
+
#include <linux/string.h>
#include <linux/init.h>
#include <linux/module.h>
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 6960fe22c50bfd8a9acc79870e494c2775fa040a..7e05fafd5544e1c4a3283dc13b0692f39515d01e 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
-#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)
#ifdef CONFIG_SYSCTL
--
2.47.3
next prev parent reply other threads:[~2026-08-19 2:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 2:27 [PATCH RFC v2 00/13] sysctl: add module aliases Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 01/13] keys, pidns, fs/verity, riscv/vector: reorder '#include <linux/sysctl.h>' Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 02/13] proc: add config option SYSCTL_MODULE_ALIASES Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 03/13] sysctl, mod_devicetable: add macro MODULE_SYSCTL_TABLE Mauricio Faria de Oliveira
2026-08-19 2:28 ` Mauricio Faria de Oliveira [this message]
2026-08-19 2:28 ` [PATCH RFC v2 05/13] sysctl, parport: update register_sysctl() callers with template arguments Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 06/13] sysctl, net: add register_net_sysctl{_sz}() wrappers for MODULE_SYSCTL_TABLE Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 07/13] sysctl, net: update register_net_sysctl{_sz}() callers with template arguments Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 08/13] sysctl, net: update register_net_sysctl_sz(ARRAY_SIZE(table_tmpl)) " Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 09/13] sysctl, ipv6: update register_net_sysctl{_sz}() callers " Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 10/13] sysctl, net: update register_net_sysctl_sz() edge case Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 11/13] sysctl: unrandomize struct ctl_table.procname Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 12/13] modpost: move addend_*_rel() calls into addend_rel() Mauricio Faria de Oliveira
2026-08-19 2:28 ` [PATCH RFC v2 13/13] modpost: handle MODULE_SYSCTL_TABLE symbols Mauricio Faria de Oliveira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818-sysctl-module-aliases-v2-4-d5a69dae5798@igalia.com \
--to=mfo@igalia.com \
--cc=bpf@vger.kernel.org \
--cc=bridge@lists.linux.dev \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fsverity@lists.linux.dev \
--cc=horms@kernel.org \
--cc=joel.granados@kernel.org \
--cc=kees@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=keyrings@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sctp@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=lvs-devel@vger.kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=nsc@kernel.org \
--cc=pabeni@redhat.com \
--cc=rds-devel@oss.oracle.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox