The patch titled Subject: sysctl: add and use base directory declarer and registration helper has been added to the -mm tree. Its filename is sysctl-add-and-use-base-directory-declarer-and-registration-helper.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/sysctl-add-and-use-base-directory-declarer-and-registration-helper.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/sysctl-add-and-use-base-directory-declarer-and-registration-helper.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Luis Chamberlain <mcgrof@xxxxxxxxxx> Subject: sysctl: add and use base directory declarer and registration helper Patch series "sysctl: add and use base directory declarer and registration helper". In this patch series we start addressing base directories, and so we start with the "fs" sysctls. The end goal is we end up completely moving all "fs" sysctl knobs out from kernel/sysctl. This patch (of 6): Add a set of helpers which can be used to declare and register base directory sysctls on their own. We do this so we can later move each of the base sysctl directories like "fs", "kernel", etc, to their own respective files instead of shoving the declarations and registrations all on kernel/sysctl.c. The lazy approach has caught up and with this, we just end up extending the list of base directories / sysctls on one file and this makes maintenance difficult due to merge conflicts from many developers. The declarations are used first by kernel/sysctl.c for registration its own base which over time we'll try to clean up. It will be used in the next patch to demonstrate how to cleanly deal with base sysctl directories. Link: https://lkml.kernel.org/r/20211129211943.640266-1-mcgrof@xxxxxxxxxx Link: https://lkml.kernel.org/r/20211129211943.640266-2-mcgrof@xxxxxxxxxx Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Iurii Zaikin <yzaikin@xxxxxxxxxx> Cc: Xiaoming Ni <nixiaoming@xxxxxxxxxx> Cc: Eric Biederman <ebiederm@xxxxxxxxxxxx> Cc: Stephen Kitt <steve@xxxxxxx> Cc: Lukas Middendorf <kernel@xxxxxxxxxxx> Cc: Antti Palosaari <crope@xxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx> Cc: Christian Brauner <christian.brauner@xxxxxxxxxx> Cc: Eric Biggers <ebiggers@xxxxxxxxxx> Cc: "Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxx> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/proc_sysctl.c | 9 ++++++++ include/linux/sysctl.h | 23 +++++++++++++++++++++ kernel/sysctl.c | 41 +++++++++------------------------------ 3 files changed, 42 insertions(+), 31 deletions(-) --- a/fs/proc/proc_sysctl.c~sysctl-add-and-use-base-directory-declarer-and-registration-helper +++ a/fs/proc/proc_sysctl.c @@ -1646,6 +1646,15 @@ struct ctl_table_header *register_sysctl } EXPORT_SYMBOL(register_sysctl_table); +int __register_sysctl_base(struct ctl_table *base_table) +{ + struct ctl_table_header *hdr; + + hdr = register_sysctl_table(base_table); + kmemleak_not_leak(hdr); + return 0; +} + static void put_links(struct ctl_table_header *header) { struct ctl_table_set *root_set = &sysctl_table_root.default_set; --- a/include/linux/sysctl.h~sysctl-add-and-use-base-directory-declarer-and-registration-helper +++ a/include/linux/sysctl.h @@ -194,6 +194,19 @@ 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, @@ -236,6 +249,16 @@ extern int no_unaligned_warning; 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 struct ctl_table_header *register_sysctl_table(struct ctl_table * table) { return NULL; --- a/kernel/sysctl.c~sysctl-add-and-use-base-directory-declarer-and-registration-helper +++ a/kernel/sysctl.c @@ -2850,41 +2850,20 @@ static struct ctl_table dev_table[] = { { } }; -static struct ctl_table sysctl_base_table[] = { - { - .procname = "kernel", - .mode = 0555, - .child = kern_table, - }, - { - .procname = "vm", - .mode = 0555, - .child = vm_table, - }, - { - .procname = "fs", - .mode = 0555, - .child = fs_table, - }, - { - .procname = "debug", - .mode = 0555, - .child = debug_table, - }, - { - .procname = "dev", - .mode = 0555, - .child = dev_table, - }, - { } -}; +DECLARE_SYSCTL_BASE(kernel, kern_table); +DECLARE_SYSCTL_BASE(vm, vm_table); +DECLARE_SYSCTL_BASE(fs, fs_table); +DECLARE_SYSCTL_BASE(debug, debug_table); +DECLARE_SYSCTL_BASE(dev, dev_table); int __init sysctl_init(void) { - struct ctl_table_header *hdr; + register_sysctl_base(kernel); + register_sysctl_base(vm); + register_sysctl_base(fs); + register_sysctl_base(debug); + register_sysctl_base(dev); - hdr = register_sysctl_table(sysctl_base_table); - kmemleak_not_leak(hdr); return 0; } #endif /* CONFIG_SYSCTL */ _ Patches currently in -mm which might be from mcgrof@xxxxxxxxxx are zram-use-attribute_groups.patch hpet-simplify-subdirectory-registration-with-register_sysctl.patch i915-simplify-subdirectory-registration-with-register_sysctl.patch macintosh-mac_hidc-simplify-subdirectory-registration-with-register_sysctl.patch ocfs2-simplify-subdirectory-registration-with-register_sysctl.patch test_sysctl-simplify-subdirectory-registration-with-register_sysctl.patch inotify-simplify-subdirectory-registration-with-register_sysctl-fix.patch cdrom-simplify-subdirectory-registration-with-register_sysctl.patch sysctl-add-helper-to-register-a-sysctl-mount-point.patch fs-move-binfmt_misc-sysctl-to-its-own-file.patch sysctl-share-unsigned-long-const-values.patch fs-move-inode-sysctls-to-its-own-file.patch fs-move-fs-stat-sysctls-to-file_tablec.patch fs-move-dcache-sysctls-to-its-own-file.patch sysctl-move-maxolduid-as-a-sysctl-specific-const.patch fs-move-shared-sysctls-to-fs-sysctlsc.patch fs-move-locking-sysctls-where-they-are-used.patch fs-move-namei-sysctls-to-its-own-file.patch fs-move-fs-execc-sysctls-into-its-own-file.patch fs-move-pipe-sysctls-to-is-own-file.patch sysctl-add-and-use-base-directory-declarer-and-registration-helper.patch fs-move-namespace-sysctls-and-declare-fs-base-directory.patch kernel-sysctlc-rename-sysctl_init-to-sysctl_init_bases.patch