diff mbox series

[1/2] sysctl: Refactor base paths registrations

Message ID 20230518160705.3888592-2-j.granados@samsung.com (mailing list archive)
State New, archived
Headers show
Series sysctl: Remove register_sysctl_table from sources | expand

Commit Message

Joel Granados May 18, 2023, 4:07 p.m. UTC
This is part of the general push to deprecate register_sysctl_paths and
register_sysctl_table. The old way of doing this through
register_sysctl_base and DECLARE_SYSCTL_BASE macro is replaced with a
call to register_sysctl. The 5 base paths affected are: "kernel", "vm",
"debug", "dev" and "fs".

We remove the register_sysctl_base function and the DECLARE_SYSCTL_BASE
macro since they are no longer needed.

In order to quickly acertain that the paths did not actually change I
executed `find /proc/sys/ | sha1sum` and made sure that the sha was the
same before and after the commit.

Signed-off-by: Joel Granados <j.granados@samsung.com>
---
 fs/sysctls.c           |  9 ++++++---
 include/linux/sysctl.h | 23 -----------------------
 kernel/sysctl.c        | 13 ++++---------
 3 files changed, 10 insertions(+), 35 deletions(-)

Comments

Guenter Roeck May 24, 2023, 1:29 p.m. UTC | #1
On Thu, May 18, 2023 at 06:07:04PM +0200, Joel Granados wrote:
> This is part of the general push to deprecate register_sysctl_paths and
> register_sysctl_table. The old way of doing this through
> register_sysctl_base and DECLARE_SYSCTL_BASE macro is replaced with a
> call to register_sysctl. The 5 base paths affected are: "kernel", "vm",
> "debug", "dev" and "fs".
> 
> We remove the register_sysctl_base function and the DECLARE_SYSCTL_BASE
> macro since they are no longer needed.
> 
> In order to quickly acertain that the paths did not actually change I
> executed `find /proc/sys/ | sha1sum` and made sure that the sha was the
> same before and after the commit.
> 
> Signed-off-by: Joel Granados <j.granados@samsung.com>

This patch results in the following warning, seen across almost
all architectures.

sysctl table check failed: kernel/usermodehelper Not a file
sysctl table check failed: kernel/usermodehelper No proc_handler
sysctl table check failed: kernel/usermodehelper bogus .mode 0555
sysctl table check failed: kernel/keys Not a file
sysctl table check failed: kernel/keys No proc_handler
sysctl table check failed: kernel/keys bogus .mode 0555
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.4.0-rc3-next-20230524 #1
Stack : ffffffff 801aed28 80e44644 00000004 81946ba4 00000000 810d3db4 b782f641
        810f0000 81269940 810f0000 810fa610 811bb193 00000001 810d3d58 00000000
        00000000 00000000 810099d8 000000f2 00000001 000000f3 00000000 00000000
        ffffffff 00000002 00000000 fff80000 810f0000 810099d8 00000001 ffffffea
        8013bab4 8113bb14 8013caa8 80fe0000 00000000 807b9d54 00000000 81270000
        ...
Call Trace:
[<8010a558>] show_stack+0x38/0x118
[<80d67edc>] dump_stack_lvl+0xa4/0xf0
[<8039c8e0>] __register_sysctl_table+0x5b4/0x7a0
[<811e55e4>] __register_sysctl_init+0x30/0x68
[<811d5164>] sysctl_init_bases+0x24/0x88
[<811e517c>] proc_root_init+0x94/0xa8
[<811ccebc>] start_kernel+0x704/0x740

failed when register_sysctl kern_table to kernel

Reverting this patch alone results in build failures. Reverting this patch
as well as the second patch in the series (to avoid the build failures)
fixes the problem.

Guenter

---
bisect log:

# bad: [cf09e328589a2ed7f6c8d90f2edb697fb4f8a96b] Add linux-next specific files for 20230524
# good: [44c026a73be8038f03dbdeef028b642880cf1511] Linux 6.4-rc3
git bisect start 'HEAD' 'v6.4-rc3'
# good: [a20d8ab9e26daaeeaf971139b736981cf164ab0a] Merge branch 'for-linux-next' of git://anongit.freedesktop.org/drm/drm-misc
git bisect good a20d8ab9e26daaeeaf971139b736981cf164ab0a
# good: [2714032dfd641b22695e14efd5f9dff08a5e3245] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
git bisect good 2714032dfd641b22695e14efd5f9dff08a5e3245
# good: [b2bc2854ec87557033538aa9290f70b9141a6653] Merge branch 'for-leds-next' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git
git bisect good b2bc2854ec87557033538aa9290f70b9141a6653
# good: [26931c8431566f9bec7d57512e4cad8ebaeb024f] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
git bisect good 26931c8431566f9bec7d57512e4cad8ebaeb024f
# good: [669623b562b5cd308eaa58eabe8c72007dbb37e2] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git
git bisect good 669623b562b5cd308eaa58eabe8c72007dbb37e2
# good: [a0ef85b20ffa65a89dc79b0a22edb80a88199939] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching
git bisect good a0ef85b20ffa65a89dc79b0a22edb80a88199939
# bad: [a64335537001eb6af6e57a82317985441dafe4e7] Merge branch 'sysctl-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git
git bisect bad a64335537001eb6af6e57a82317985441dafe4e7
# good: [ba3ad1554b569888f4a63a2e4a16a9009fdedd4e] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git
git bisect good ba3ad1554b569888f4a63a2e4a16a9009fdedd4e
# good: [3133f141259d7f6e0729db272f22724614472661] Merge branch 'slab/for-6.5/prandom' into slab/for-next
git bisect good 3133f141259d7f6e0729db272f22724614472661
# good: [2716d45c6fdc1ae06e83db28f58f55f7e9415643] sysctl: stop exporting register_sysctl_table
git bisect good 2716d45c6fdc1ae06e83db28f58f55f7e9415643
# good: [8ccb380db3a4bcef9ade852da8b33fdcea01c8a5] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git
git bisect good 8ccb380db3a4bcef9ade852da8b33fdcea01c8a5
# bad: [ee996cff1fb203bffc8de5c87cab6056d60df71d] sysctl: Remove register_sysctl_table
git bisect bad ee996cff1fb203bffc8de5c87cab6056d60df71d
# bad: [7eec88986dce2d85012fbe516def7a2d7d77735c] sysctl: Refactor base paths registrations
git bisect bad 7eec88986dce2d85012fbe516def7a2d7d77735c
# first bad commit: [7eec88986dce2d85012fbe516def7a2d7d77735c] sysctl: Refactor base paths registrations
Luis Chamberlain May 24, 2023, 5:55 p.m. UTC | #2
On Wed, May 24, 2023 at 06:29:06AM -0700, Guenter Roeck wrote:
> On Thu, May 18, 2023 at 06:07:04PM +0200, Joel Granados wrote:
> > This is part of the general push to deprecate register_sysctl_paths and
> > register_sysctl_table. The old way of doing this through
> > register_sysctl_base and DECLARE_SYSCTL_BASE macro is replaced with a
> > call to register_sysctl. The 5 base paths affected are: "kernel", "vm",
> > "debug", "dev" and "fs".
> > 
> > We remove the register_sysctl_base function and the DECLARE_SYSCTL_BASE
> > macro since they are no longer needed.
> > 
> > In order to quickly acertain that the paths did not actually change I
> > executed `find /proc/sys/ | sha1sum` and made sure that the sha was the
> > same before and after the commit.
> > 
> > Signed-off-by: Joel Granados <j.granados@samsung.com>
> 
> This patch results in the following warning, seen across almost
> all architectures.
> 
> sysctl table check failed: kernel/usermodehelper Not a file
> sysctl table check failed: kernel/usermodehelper No proc_handler
> sysctl table check failed: kernel/usermodehelper bogus .mode 0555
> sysctl table check failed: kernel/keys Not a file
> sysctl table check failed: kernel/keys No proc_handler
> sysctl table check failed: kernel/keys bogus .mode 0555
> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.4.0-rc3-next-20230524 #1
> Stack : ffffffff 801aed28 80e44644 00000004 81946ba4 00000000 810d3db4 b782f641
>         810f0000 81269940 810f0000 810fa610 811bb193 00000001 810d3d58 00000000
>         00000000 00000000 810099d8 000000f2 00000001 000000f3 00000000 00000000
>         ffffffff 00000002 00000000 fff80000 810f0000 810099d8 00000001 ffffffea
>         8013bab4 8113bb14 8013caa8 80fe0000 00000000 807b9d54 00000000 81270000
>         ...
> Call Trace:
> [<8010a558>] show_stack+0x38/0x118
> [<80d67edc>] dump_stack_lvl+0xa4/0xf0
> [<8039c8e0>] __register_sysctl_table+0x5b4/0x7a0
> [<811e55e4>] __register_sysctl_init+0x30/0x68
> [<811d5164>] sysctl_init_bases+0x24/0x88
> [<811e517c>] proc_root_init+0x94/0xa8
> [<811ccebc>] start_kernel+0x704/0x740
> 
> failed when register_sysctl kern_table to kernel
> 
> Reverting this patch alone results in build failures. Reverting this patch
> as well as the second patch in the series (to avoid the build failures)
> fixes the problem.
> 
> Guenter

Thanks Guenter! The issue has been fixed on sysct-next, and I suppose
the fix will get into linux-next as of tomorrow.

 Luis
diff mbox series

Patch

diff --git a/fs/sysctls.c b/fs/sysctls.c
index c701273c9432..228420f5fe1b 100644
--- a/fs/sysctls.c
+++ b/fs/sysctls.c
@@ -29,11 +29,14 @@  static struct ctl_table fs_shared_sysctls[] = {
 	{ }
 };
 
-DECLARE_SYSCTL_BASE(fs, fs_shared_sysctls);
-
 static int __init init_fs_sysctls(void)
 {
-	return register_sysctl_base(fs);
+	/*
+	 * We do not check the return code for register_sysctl because the
+	 * original call to register_sysctl_base always returned 0.
+	 */
+	register_sysctl("fs", fs_shared_sysctls);
+	return 0;
 }
 
 early_initcall(init_fs_sysctls);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 218e56a26fb0..653b66c762b1 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -197,20 +197,6 @@  struct ctl_path {
 
 #ifdef CONFIG_SYSCTL
 
-#define DECLARE_SYSCTL_BASE(_name, _table)				\
-static struct ctl_table _name##_base_table[] = {			\
-	{								\
-		.procname	= #_name,				\
-		.mode		= 0555,					\
-		.child		= _table,				\
-	},								\
-	{ },								\
-}
-
-extern int __register_sysctl_base(struct ctl_table *base_table);
-
-#define register_sysctl_base(_name) __register_sysctl_base(_name##_base_table)
-
 void proc_sys_poll_notify(struct ctl_table_poll *poll);
 
 extern void setup_sysctl_set(struct ctl_table_set *p,
@@ -247,15 +233,6 @@  extern struct ctl_table sysctl_mount_point[];
 
 #else /* CONFIG_SYSCTL */
 
-#define DECLARE_SYSCTL_BASE(_name, _table)
-
-static inline int __register_sysctl_base(struct ctl_table *base_table)
-{
-	return 0;
-}
-
-#define register_sysctl_base(table) __register_sysctl_base(table)
-
 static inline void register_sysctl_init(const char *path, struct ctl_table *table)
 {
 }
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index bfe53e835524..f784b0fe5689 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2348,17 +2348,12 @@  static struct ctl_table dev_table[] = {
 	{ }
 };
 
-DECLARE_SYSCTL_BASE(kernel, kern_table);
-DECLARE_SYSCTL_BASE(vm, vm_table);
-DECLARE_SYSCTL_BASE(debug, debug_table);
-DECLARE_SYSCTL_BASE(dev, dev_table);
-
 int __init sysctl_init_bases(void)
 {
-	register_sysctl_base(kernel);
-	register_sysctl_base(vm);
-	register_sysctl_base(debug);
-	register_sysctl_base(dev);
+	register_sysctl("kernel", kern_table);
+	register_sysctl("vm", vm_table);
+	register_sysctl("debug", debug_table);
+	register_sysctl("dev", dev_table);
 
 	return 0;
 }