sysctl: slowly deprecate register_sysctl_table()
Subsystems (9)
cover sysctl: slowly deprecate register_sysctl_table()
As the large array of sysctls in kernel/sysctl.c is reduced we get to the point of wanting to optimize how we register sysctls by only dealing with flat simple structures, with no subdirectories. In particular the last empty element should not be needed. We'll get there, and save some memory, but as we move forward that path will be come the more relevant path to use in the sysctl registration. It is much simpler as it avoids recursion.
Turns out we can also convert existing users of register_sysctl_table() which just need their subdirectories created for them. This effort addresses most users of register_sysctl_table() in drivers/ except parport -- that needs a bit more review.
This is part of the process to deprecate older sysctl users which uses APIs which can incur recursion, but don't need it [0]. This is the second effort.
Yes -- we'll get to the point *each* of these conversions means saving one empty syctl, but that change needs a bit more careful review before merging. But since these conversion are also deleting tables for subdirectories, the delta in size of the kernel should not incrase really.
The most complex change is the sgi-xp change which does deal with a case where we have a subdirectory with an entry, I just split that in two registrations. No point in keeping recursion just for a few minor if we can simplify code around. More eyeballs / review / testing on that change is appreciated.
Sending these out early so they can get tested properly early on linux-next. I'm happy to take these via sysctl-next [0] but since I don' think register_sysctl_table() will be nuked on v6.4 I think it's fine for each of these to go into each respective tree. I can pick up last stragglers on sysctl-next. If you want me to take this via sysctl-next too, just let me know and I'm happy to do that. Either way works.
[0] https://lkml.kernel.org/r/[email protected]
Luis Chamberlain (7):
scsi: simplify sysctl registration with register_sysctl()
ipmi: simplify sysctl registration
hv: simplify sysctl registration
md: simplify sysctl registration
sgi-xp: simplify sysctl registration
tty: simplify sysctl registration
xen: simplify sysctl registration for balloon
drivers/char/ipmi/ipmi_poweroff.c | 16 +--------------- drivers/hv/vmbus_drv.c | 11 +---------- drivers/md/md.c | 22 +--------------------- drivers/misc/sgi-xp/xpc_main.c | 24 ++++++++++-------------- drivers/scsi/scsi_sysctl.c | 16 +--------------- drivers/tty/tty_io.c | 20 +------------------- drivers/xen/balloon.c | 20 +------------------- 7 files changed, 16 insertions(+), 113 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/7 scsi: simplify sysctl registration with register_sysctl()
register_sysctl_table() is a deprecated compatibility wrapper. register_sysctl() can do the directory creation for you so just use that.
--- drivers/scsi/scsi_sysctl.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/scsi/scsi_sysctl.c +1 -15
@@ -21,25 +21,11 @@ static struct ctl_table scsi_table[] = { { } }; -static struct ctl_table scsi_dir_table[] = { - { .procname ="scsi" , - .mode =0555 , - .child = scsi_table }, - { } -}; - -static struct ctl_table scsi_root_table[] = { - { .procname ="dev" , - .mode =0555 , - .child = scsi_dir_table }, - { } -}; -static struct ctl_table_header *scsi_table_header;int __init scsi_init_sysctl (void ) { - scsi_table_header =register_sysctl_table (scsi_root_table); + scsi_table_header =register_sysctl ("dev/scsi" , scsi_table);if (!scsi_table_header)return -ENOMEM ;return 0 ;
Signature · 1 line
2.39.1
PATCH 2/7 ipmi: simplify sysctl registration
In reply to Luis Chamberlainregister_sysctl_table() is a deprecated compatibility wrapper. register_sysctl() can do the directory creation for you so just use that.
--- drivers/char/ipmi/ipmi_poweroff.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/char/ipmi/ipmi_poweroff.c +1 -15
@@ -659,20 +659,6 @@ static struct ctl_table ipmi_table[] = { { } }; -static struct ctl_table ipmi_dir_table[] = { - { .procname ="ipmi" , - .mode =0555 , - .child = ipmi_table }, - { } -}; - -static struct ctl_table ipmi_root_table[] = { - { .procname ="dev" , - .mode =0555 , - .child = ipmi_dir_table }, - { } -}; -static struct ctl_table_header *ipmi_table_header;#endif /* CONFIG_PROC_FS */
@@ -689,7 +675,7 @@ static int __init ipmi_poweroff_init(void)pr_info ("Power cycle is enabled\n" );#ifdef CONFIG_PROC_FS - ipmi_table_header =register_sysctl_table (ipmi_root_table); + ipmi_table_header =register_sysctl ("dev/ipmi" , ipmi_table);if (!ipmi_table_header) {pr_err ("Unable to register powercycle sysctl\n" ); rv = -ENOMEM ;
Signature · 1 line
2.39.1
PATCH 3/7 hv: simplify sysctl registration
In reply to Luis Chamberlainregister_sysctl_table() is a deprecated compatibility wrapper. register_sysctl() can do the directory creation for you so just use that.
--- drivers/hv/vmbus_drv.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/hv/vmbus_drv.c +1 -10
@@ -1460,15 +1460,6 @@ static struct ctl_table hv_ctl_table[] = { {} }; -static struct ctl_table hv_root_table[] = { - { - .procname ="kernel" , - .mode =0555 , - .child = hv_ctl_table - }, - {} -}; -/* * vmbus_bus_init -Main vmbus driver initialization routine. *
@@ -1547,7 +1538,7 @@ static int vmbus_bus_init(void)* message recording won't be available in isolated * guests should the following registration fail. */ - hv_ctl_table_hdr =register_sysctl_table (hv_root_table); + hv_ctl_table_hdr =register_sysctl ("kernel" , hv_ctl_table);if (!hv_ctl_table_hdr)pr_err ("Hyper-V: sysctl table register error" );
Signature · 1 line
2.39.1
PATCH 4/7 md: simplify sysctl registration
In reply to Luis Chamberlainregister_sysctl_table() is a deprecated compatibility wrapper. register_sysctl() can do the directory creation for you so just use that.
--- drivers/md/md.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/md/md.c +1 -21
@@ -322,26 +322,6 @@ static struct ctl_table raid_table[] = { { } }; -static struct ctl_table raid_dir_table[] = { - { - .procname ="raid" , - .maxlen =0 , - .mode =S_IRUGO |S_IXUGO , - .child = raid_table, - }, - { } -}; - -static struct ctl_table raid_root_table[] = { - { - .procname ="dev" , - .maxlen =0 , - .mode =0555 , - .child = raid_dir_table, - }, - { } -}; -static int start_readonly;/*
@@ -9650,7 +9630,7 @@ static int __init md_init(void) mdp_major = ret;register_reboot_notifier (&md_notifier); - raid_table_header =register_sysctl_table (raid_root_table); + raid_table_header =register_sysctl ("dev/raid" , raid_table);md_geninit ();return 0 ;
Signature · 1 line
2.39.1
PATCH 5/7 sgi-xp: simplify sysctl registration
In reply to Luis ChamberlainAlthough this driver is a good use case for having a directory that is not other directories and then subdirectories with more entries, the usage of register_sysctl_table() can recurse and increases complexity so to avoid that just split out the registration to each directory with its own entries.
register_sysctl_table() is a deprecated compatibility wrapper. register_sysctl() can do the directory creation for you so just use that.
--- drivers/misc/sgi-xp/xpc_main.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/misc/sgi-xp/xpc_main.c +10 -14
@@ -93,7 +93,7 @@ int xpc_disengage_timelimit = XPC_DISENGAGE_DEFAULT_TIMELIMIT;static int xpc_disengage_min_timelimit;/* = 0 */ static int xpc_disengage_max_timelimit =120 ; -static struct ctl_table xpc_sys_xpc_hb_dir[] = { +static struct ctl_table xpc_sys_xpc_hb[] = { { .procname ="hb_interval" , .data = &xpc_hb_interval,
@@ -112,11 +112,7 @@ static struct ctl_table xpc_sys_xpc_hb_dir[] = { .extra2 = &xpc_hb_check_max_interval}, {} }; -static struct ctl_table xpc_sys_xpc_dir[] = { - { - .procname ="hb" , - .mode =0555 , - .child = xpc_sys_xpc_hb_dir}, +static struct ctl_table xpc_sys_xpc[] = { { .procname ="disengage_timelimit" , .data = &xpc_disengage_timelimit,
@@ -127,14 +123,9 @@ static struct ctl_table xpc_sys_xpc_dir[] = { .extra2 = &xpc_disengage_max_timelimit}, {} }; -static struct ctl_table xpc_sys_dir[] = { - { - .procname ="xpc" , - .mode =0555 , - .child = xpc_sys_xpc_dir}, - {} -}; +static struct ctl_table_header *xpc_sysctl; +static struct ctl_table_header *xpc_sysctl_hb;/* non-zero if any remote partition disengage was timed out */ int xpc_disengage_timedout;
@@ -1041,6 +1032,8 @@ xpc_do_exit(enum xp_retval reason)if (xpc_sysctl)unregister_sysctl_table (xpc_sysctl); +if (xpc_sysctl_hb) +unregister_sysctl_table (xpc_sysctl_hb);xpc_teardown_partitions ();
@@ -1243,7 +1236,8 @@ xpc_init(void) goto out_1; } - xpc_sysctl =register_sysctl_table (xpc_sys_dir); + xpc_sysctl =register_sysctl ("xpc" , xpc_sys_xpc); + xpc_sysctl_hb =register_sysctl ("xpc/hb" , xpc_sys_xpc_hb);/* * Fill the partition reserved page with the information needed by
@@ -1308,6 +1302,8 @@ xpc_init(void) (void )unregister_die_notifier (&xpc_die_notifier); (void )unregister_reboot_notifier (&xpc_reboot_notifier); out_2: +if (xpc_sysctl_hb) +unregister_sysctl_table (xpc_sysctl_hb);if (xpc_sysctl)unregister_sysctl_table (xpc_sysctl);
Signature · 1 line
2.39.1
PATCH 6/7 tty: simplify sysctl registration
In reply to Luis Chamberlainregister_sysctl_table() is a deprecated compatibility wrapper. register_sysctl_init() can do the directory creation for you so just use that
--- drivers/tty/tty_io.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/tty/tty_io.c +1 -19
@@ -3614,31 +3614,13 @@ static struct ctl_table tty_table[] = { { } }; -static struct ctl_table tty_dir_table[] = { - { - .procname ="tty" , - .mode =0555 , - .child = tty_table, - }, - { } -}; - -static struct ctl_table tty_root_table[] = { - { - .procname ="dev" , - .mode =0555 , - .child = tty_dir_table, - }, - { } -}; -/* * Ok, now we can initialize the rest of the tty devices and can count * on memory allocations, interrupts etc.. */ int __init tty_init (void ) { -register_sysctl_table (tty_root_table); +register_sysctl_init ("dev/tty" , tty_table);cdev_init (&tty_cdev, &tty_fops);if (cdev_add (&tty_cdev,MKDEV (TTYAUX_MAJOR ,0 ),1 ) ||register_chrdev_region (MKDEV (TTYAUX_MAJOR ,0 ),1 ,"/dev/tty" ) <0 )
Signature · 1 line
2.39.1
PATCH 7/7 xen: simplify sysctl registration for balloon
In reply to Luis Chamberlainregister_sysctl_table() is a deprecated compatibility wrapper. register_sysctl_init() can do the directory creation for you so just use that.
--- drivers/xen/balloon.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/xen/balloon.c +1 -19
@@ -97,24 +97,6 @@ static struct ctl_table balloon_table[] = { { } }; -static struct ctl_table balloon_root[] = { - { - .procname ="balloon" , - .mode =0555 , - .child = balloon_table, - }, - { } -}; - -static struct ctl_table xen_root[] = { - { - .procname ="xen" , - .mode =0555 , - .child = balloon_root, - }, - { } -}; -#else #define xen_hotplug_unpopulated 0#endif
@@ -747,7 +729,7 @@ static int __init balloon_init(void)#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG set_online_page_callback (&xen_online_page);register_memory_notifier (&xen_memory_nb); -register_sysctl_table (xen_root); +register_sysctl_init ("xen/balloon" , balloon_table);#endif balloon_add_regions ();
Signature · 1 line
2.39.1
Re: [PATCH 2/7] ipmi: simplify sysctl registration
In reply to Luis ChamberlainQuoted 3 lines · Luis Chamberlain
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl()can do the directory creation for you so just use that.
Thanks, I have included this in my tree for the next merge window.
-corey
Quoted 43 lines
Signed-off-by Luis Chamberlain <[email protected]>--- drivers/char/ipmi/ipmi_poweroff.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)drivers/char/ipmi/ipmi_poweroff.c +1
-15@@ -659,20 +659,6 @@ static struct ctl_table ipmi_table[] = { { } }; -static struct ctl_table ipmi_dir_table[] = { - { .procname ="ipmi" , - .mode =0555 , - .child = ipmi_table }, - { } -}; - -static struct ctl_table ipmi_root_table[] = { - { .procname ="dev" , - .mode =0555 , - .child = ipmi_dir_table }, - { } -}; -static struct ctl_table_header *ipmi_table_header;#endif /* CONFIG_PROC_FS */ @@ -689,7 +675,7 @@ static int __init ipmi_poweroff_init(void)pr_info ("Power cycle is enabled\n" );#ifdef CONFIG_PROC_FS - ipmi_table_header =register_sysctl_table (ipmi_root_table); + ipmi_table_header =register_sysctl ("dev/ipmi" , ipmi_table);if (!ipmi_table_header) {pr_err ("Unable to register powercycle sysctl\n" ); rv = -ENOMEM ;Signature · 1 line
2.39.1
RE: [PATCH 3/7] hv: simplify sysctl registration
In reply to Luis ChamberlainFrom: Luis Chamberlain <[email protected]> On Behalf Of Luis Chamberlain Sent: Thursday, March 2, 2023 12:46 PM
Quoted 40 lines
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl()can do the directory creation for you so just use that.Signed-off-by Luis Chamberlain <[email protected]>--- drivers/hv/vmbus_drv.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)drivers/hv/vmbus_drv.c +1
-11@@ -1460,15 +1460,6 @@ static struct ctl_table hv_ctl_table[] = { {} }; -static struct ctl_table hv_root_table[] = { - { - .procname ="kernel" , - .mode =0555 , - .child = hv_ctl_table - }, - {} -}; -/* * vmbus_bus_init -Main vmbus driver initialization routine. * @@ -1547,7 +1538,7 @@ static int vmbus_bus_init(void)* message recording won't be available in isolated * guests should the following registration fail. */ - hv_ctl_table_hdr =register_sysctl_table (hv_root_table); + hv_ctl_table_hdr =register_sysctl ("kernel" , hv_ctl_table);if (!hv_ctl_table_hdr)pr_err ("Hyper-V: sysctl table register error" ); --
Quoted 1 line
2.39.1
Re: [PATCH 4/7] md: simplify sysctl registration
In reply to Luis ChamberlainQuoted 6 lines · Luis Chamberlain
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl()can do the directory creation for you so just use that.Signed-off-by Luis Chamberlain <[email protected]>
Thanks!
Re: [PATCH 7/7] xen: simplify sysctl registration for balloon
In reply to Luis ChamberlainQuoted 5 lines · Luis Chamberlain
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl_init()can do the directory creation for you so just use that.Signed-off-by Luis Chamberlain <[email protected]>
Juergen
Re: [PATCH 3/7] hv: simplify sysctl registration
In reply to Luis ChamberlainQuoted 5 lines · Luis Chamberlain
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl()can do the directory creation for you so just use that.Signed-off-by Luis Chamberlain <[email protected]>
Re: [PATCH 5/7] sgi-xp: simplify sysctl registration
In reply to Luis ChamberlainQuoted 11 lines · Luis Chamberlain
Although this driver is a good use case for having a directory that is not other directories and then subdirectories with more entries, the usage of
register_sysctl_table()can recurse and increases complexity so to avoid that just split out the registration to each directory with its own entries.
register_sysctl_table()is a deprecated compatibility wrapper.register_sysctl()can do the directory creation for you so just use that.Signed-off-by Luis Chamberlain <[email protected]>
Quoted 78 lines
--- drivers/misc/sgi-xp/xpc_main.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)drivers/misc/sgi-xp/xpc_main.c +10
-14@@ -93,7 +93,7 @@ int xpc_disengage_timelimit = XPC_DISENGAGE_DEFAULT_TIMELIMIT;static int xpc_disengage_min_timelimit;/* = 0 */ static int xpc_disengage_max_timelimit =120 ; -static struct ctl_table xpc_sys_xpc_hb_dir[] = { +static struct ctl_table xpc_sys_xpc_hb[] = { { .procname ="hb_interval" , .data = &xpc_hb_interval,@@ -112,11 +112,7 @@ static struct ctl_table xpc_sys_xpc_hb_dir[] = { .extra2 = &xpc_hb_check_max_interval}, {} }; -static struct ctl_table xpc_sys_xpc_dir[] = { - { - .procname ="hb" , - .mode =0555 , - .child = xpc_sys_xpc_hb_dir}, +static struct ctl_table xpc_sys_xpc[] = { { .procname ="disengage_timelimit" , .data = &xpc_disengage_timelimit,@@ -127,14 +123,9 @@ static struct ctl_table xpc_sys_xpc_dir[] = { .extra2 = &xpc_disengage_max_timelimit}, {} }; -static struct ctl_table xpc_sys_dir[] = { - { - .procname ="xpc" , - .mode =0555 , - .child = xpc_sys_xpc_dir}, - {} -}; +static struct ctl_table_header *xpc_sysctl; +static struct ctl_table_header *xpc_sysctl_hb;/* non-zero if any remote partition disengage was timed out */ int xpc_disengage_timedout;@@ -1041,6 +1032,8 @@ xpc_do_exit(enum xp_retval reason)if (xpc_sysctl)unregister_sysctl_table (xpc_sysctl); +if (xpc_sysctl_hb) +unregister_sysctl_table (xpc_sysctl_hb);xpc_teardown_partitions ();@@ -1243,7 +1236,8 @@ xpc_init(void) goto out_1; } - xpc_sysctl =register_sysctl_table (xpc_sys_dir); + xpc_sysctl =register_sysctl ("xpc" , xpc_sys_xpc); + xpc_sysctl_hb =register_sysctl ("xpc/hb" , xpc_sys_xpc_hb);/* * Fill the partition reserved page with the information needed by @@ -1308,6 +1302,8 @@ xpc_init(void) (void )unregister_die_notifier (&xpc_die_notifier); (void )unregister_reboot_notifier (&xpc_reboot_notifier); out_2: +if (xpc_sysctl_hb) +unregister_sysctl_table (xpc_sysctl_hb);if (xpc_sysctl)unregister_sysctl_table (xpc_sysctl);Signature · 1 line
2.39.1
Signature · 1 line
Steve Wahl, Hewlett Packard Enterprise
Quoted 6 lines · Luis Chamberlain
I'm happy to take these via sysctl-next [0] but since
I don' thinkregister_sysctl_table()will be nuked on v6.4 I think it's fine for each of these to go into each respective tree. I can pick up last stragglers on sysctl-next. If you want me to take this via sysctl-next too, just let me know and I'm happy to do that. Either way works.
As I noted I've dropped the following already-picked-up patches from my queue:
ipmi: simplify sysctl registration
sgi-xp: simplify sysctl registration
tty: simplify sysctl registration
I've taken the rest now through sysctl-next:
scsi: simplify sysctl registration with register_sysctl()
hv: simplify sysctl registration
md: simplify sysctl registration
xen: simplify sysctl registration for balloon
If a maintainer would prefer to take one on through their tree fine by me too, just let me know and I'll drop the patch.
Luis