Skip to content

Commit

Permalink
sysctl: add and use base directory declarer and registration helper
Browse files Browse the repository at this point in the history
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@kernel.org
Link: https://lkml.kernel.org/r/20211129211943.640266-2-mcgrof@kernel.org
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Xiaoming Ni <nixiaoming@huawei.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Lukas Middendorf <kernel@tuxforce.de>
Cc: Antti Palosaari <crope@iki.fi>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
  • Loading branch information
Luis Chamberlain authored and Stephen Rothwell committed Nov 30, 2021
1 parent d5a4542 commit f00ff38
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
9 changes: 9 additions & 0 deletions fs/proc/proc_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,15 @@ struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
}
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;
Expand Down
23 changes: 23 additions & 0 deletions include/linux/sysctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
41 changes: 10 additions & 31 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit f00ff38

Please sign in to comment.