This is the last series to relocate sysctl tables from kernel/sysctl.c into their respective subsystems. After the move of two ctl_tables (uevent_helper & overflow{uid,gid}), five remain. They either handle variables defined within sysctl.c or serve as a common place for variables that are defined in different architectures. These five will not be moved. Note that this series includes two auxiliary changes: Removal of an unused variable and Nix-based rework of sysctl.sh test script
By decentralizing sysctl registrations, subsystem maintainers regain control over their sysctl interfaces, improving maintainability and reducing the likelihood of merge conflicts. All this is made possible by the work done to reduce the ctl_table memory footprint in commit d7a76ec87195 ("sysctl: Remove check for sentinel element in ctl_table arrays").
A few comments on the process: 1. If you prefer to merge this through a non-sysctl tree, please let me know so I can avoid conflicts in linux-next. 2. Apologies if you were copied by mistake—let me know if you'd like to be removed. 3. This series builds on [1], so please rebase accordingly for clean application. 4. Testing done by running sysctl selftests on x86_64 and 0-day.
Comments/Suggestions greatly appreciated
[1] https://lore.kernel.org/20250509-jag-mv_ctltables_iter2-v1-0-d0ad83f5f4c3@ke...
Signed-off-by: Joel Granados joel.granados@kernel.org --- Joel Granados (5): sysctl: Nixify sysctl.sh sysctl: Removed unused variable uevent: mv uevent_helper into kobject_uevent.c kernel/sys.c: Move overflow{uid,gid} sysctl into kernel/sys.c sysctl: rename kern_table -> sysctl_subsys_table
include/linux/sysctl.h | 1 - kernel/sys.c | 29 +++++++++++++++++++ kernel/sysctl.c | 49 +++++++------------------------- lib/kobject_uevent.c | 20 +++++++++++++ tools/testing/selftests/sysctl/sysctl.sh | 2 +- 5 files changed, 61 insertions(+), 40 deletions(-) --- base-commit: 501dd0fbc76bcae57902ea000d9c6ccd9d5f226e change-id: 20250627-jag-sysctl-823adf5732be
Best regards,
Use "#!/usr/bin/env bash" instead of "#!/bin/bash". Needed for testing in nix environments as they only provide /usr/bin/env at the standard location.
Signed-off-by: Joel Granados joel.granados@kernel.org --- tools/testing/selftests/sysctl/sysctl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index a10350c8a46e42691f4f89763bc3e2d3dc270097..b2d8bd9026a721e96c26be20069f7f87b06a5cf7 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1 # Copyright (C) 2017 Luis R. Rodriguez mcgrof@kernel.org
Remove unaligned_dump_stack from sysctl.h; it is no longer used or defined.
Signed-off-by: Joel Granados joel.granados@kernel.org --- include/linux/sysctl.h | 1 - 1 file changed, 1 deletion(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 30bcbc59d12d2f4cec7545e7ee3f5ea5f0eefbd7..92e9146b1104123d3dc0ff004bd681861e297581 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -243,7 +243,6 @@ int do_proc_douintvec(const struct ctl_table *table, int write, void *data);
extern int unaligned_enabled; -extern int unaligned_dump_stack; extern int no_unaligned_warning;
#else /* CONFIG_SYSCTL */
Move both uevent_helper table into lib/kobject_uevent.c. Place the registration early in the initcall order with postcore_initcall.
This is part of a greater effort to move ctl tables into their respective subsystems which will reduce the merge conflicts in kernel/sysctl.c.
Signed-off-by: Joel Granados joel.granados@kernel.org --- kernel/sysctl.c | 9 --------- lib/kobject_uevent.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 0716c7df7243dc38f0a49c7cae78651c3f75f5a3..2df63b69edf6fd21a58584d670e75e6f26a6e5cc 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1474,15 +1474,6 @@ static const struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, -#endif -#ifdef CONFIG_UEVENT_HELPER - { - .procname = "hotplug", - .data = &uevent_helper, - .maxlen = UEVENT_HELPER_PATH_LEN, - .mode = 0644, - .proc_handler = proc_dostring, - }, #endif { .procname = "overflowuid", diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index b7f2fa08d9c82c2838b703f3fd25f6e43b88b68a..78e16b95d2101a01c442f62ad9b9133f3f8533c2 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -826,3 +826,23 @@ static int __init kobject_uevent_init(void)
postcore_initcall(kobject_uevent_init); #endif + +#ifdef CONFIG_UEVENT_HELPER +static const struct ctl_table uevent_helper_sysctl_table[] = { + { + .procname = "hotplug", + .data = &uevent_helper, + .maxlen = UEVENT_HELPER_PATH_LEN, + .mode = 0644, + .proc_handler = proc_dostring, + }, +}; + +static int __init init_uevent_helper_sysctl(void) +{ + register_sysctl_init("kernel", uevent_helper_sysctl_table); + return 0; +} + +postcore_initcall(init_uevent_helper_sysctl); +#endif
Moved ctl_tables elements for overflowuid and overflowgid into in kernel/sys.c. Create a register function that keeps them under "kernel" and run it after core with postcore_initcall.
This is part of a greater effort to move ctl tables into their respective subsystems which will reduce the merge conflicts in kernel/sysctl.c.
Signed-off-by: Joel Granados joel.granados@kernel.org --- kernel/sys.c | 30 ++++++++++++++++++++++++++++++ kernel/sysctl.c | 18 ------------------ 2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/kernel/sys.c b/kernel/sys.c index adc0de0aa364aebb23999f621717a5d32599921c..bbeee62f9abcdf18cdf5cdb06271476b048357ae 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -181,6 +181,36 @@ int fs_overflowgid = DEFAULT_FS_OVERFLOWGID; EXPORT_SYMBOL(fs_overflowuid); EXPORT_SYMBOL(fs_overflowgid);
+static const struct ctl_table overflow_sysctl_table[] = { + { + .procname = "overflowuid", + .data = &overflowuid, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_MAXOLDUID, + }, + { + .procname = "overflowgid", + .data = &overflowgid, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_MAXOLDUID, + }, +}; + +static int __init init_overflow_sysctl(void) +{ + register_sysctl_init("kernel", overflow_sysctl_table); + return 0; +} + +postcore_initcall(init_overflow_sysctl); + + /* * Returns true if current's euid is same as p's uid or euid, * or has CAP_SYS_NICE to p's user_ns. diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 2df63b69edf6fd21a58584d670e75e6f26a6e5cc..21b70443aea75ae3212f70e5ce7efbfdf8a4f75b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1475,24 +1475,6 @@ static const struct ctl_table kern_table[] = { .proc_handler = proc_dointvec, }, #endif - { - .procname = "overflowuid", - .data = &overflowuid, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_MAXOLDUID, - }, - { - .procname = "overflowgid", - .data = &overflowgid, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_MAXOLDUID, - }, { .procname = "ngroups_max", .data = (void *)&ngroups_max,
Renamed sysctl table from kern_table to sysctl_subsys_table and grouped the two arch specific ctls to the end of the array.
This is part of a greater effort to move ctl tables into their respective subsystems which will reduce the merge conflicts in kernel/sysctl.c.
Signed-off-by: Joel Granados joel.granados@kernel.org --- kernel/sys.c | 1 - kernel/sysctl.c | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/kernel/sys.c b/kernel/sys.c index bbeee62f9abcdf18cdf5cdb06271476b048357ae..18a037cc6f61a339f1f21af9c26b25ecca1ae43c 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -210,7 +210,6 @@ static int __init init_overflow_sysctl(void)
postcore_initcall(init_overflow_sysctl);
- /* * Returns true if current's euid is same as p's uid or euid, * or has CAP_SYS_NICE to p's user_ns. diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 21b70443aea75ae3212f70e5ce7efbfdf8a4f75b..cb6196e3fa993daa21704d190baf366084e014f7 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1454,7 +1454,7 @@ int proc_do_static_key(const struct ctl_table *table, int write, return ret; }
-static const struct ctl_table kern_table[] = { +static const struct ctl_table sysctl_subsys_table[] = { #ifdef CONFIG_PROC_SYSCTL { .procname = "sysctl_writes_strict", @@ -1465,15 +1465,6 @@ static const struct ctl_table kern_table[] = { .extra1 = SYSCTL_NEG_ONE, .extra2 = SYSCTL_ONE, }, -#endif -#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW - { - .procname = "unaligned-trap", - .data = &unaligned_enabled, - .maxlen = sizeof (int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, #endif { .procname = "ngroups_max", @@ -1489,6 +1480,15 @@ static const struct ctl_table kern_table[] = { .mode = 0444, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW + { + .procname = "unaligned-trap", + .data = &unaligned_enabled, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, +#endif #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN { .procname = "ignore-unaligned-usertrap", @@ -1502,7 +1502,7 @@ static const struct ctl_table kern_table[] = {
int __init sysctl_init_bases(void) { - register_sysctl_init("kernel", kern_table); + register_sysctl_init("kernel", sysctl_subsys_table);
return 0; }
linux-kselftest-mirror@lists.linaro.org