Skip to content

Commit a737a3c

Browse files
nixiaomingtorvalds
authored andcommitted
kprobe: move sysctl_kprobes_optimization to kprobes.c
kernel/sysctl.c is a kitchen sink where everyone leaves their dirty dishes, this makes it very difficult to maintain. To help with this maintenance let's start by moving sysctls to places where they actually belong. The proc sysctl maintainers do not want to know what sysctl knobs you wish to add for your own piece of code, we just care about the core logic. Move sysctl_kprobes_optimization from kernel/sysctl.c to kernel/kprobes.c. Use register_sysctl() to register the sysctl interface. [mcgrof@kernel.org: fix compile issue when CONFIG_OPTPROBES is disabled] Link: https://lkml.kernel.org/r/20211129211943.640266-7-mcgrof@kernel.org Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Cc: Antti Palosaari <crope@iki.fi> Cc: Christian Brauner <christian.brauner@ubuntu.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Eric Biggers <ebiggers@google.com> Cc: Iurii Zaikin <yzaikin@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Lukas Middendorf <kernel@tuxforce.de> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com> Cc: Stephen Kitt <steve@sk2.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f0bc21b commit a737a3c

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

include/linux/kprobes.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
348348

349349
DEFINE_INSN_CACHE_OPS(optinsn);
350350

351-
#ifdef CONFIG_SYSCTL
352-
extern int sysctl_kprobes_optimization;
353-
extern int proc_kprobes_optimization_handler(struct ctl_table *table,
354-
int write, void *buffer,
355-
size_t *length, loff_t *ppos);
356-
#endif /* CONFIG_SYSCTL */
357351
extern void wait_for_kprobe_optimizer(void);
358352
#else /* !CONFIG_OPTPROBES */
359353
static inline void wait_for_kprobe_optimizer(void) { }

kernel/kprobes.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#define KPROBE_HASH_BITS 6
4949
#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
5050

51+
#if !defined(CONFIG_OPTPROBES) || !defined(CONFIG_SYSCTL)
52+
#define kprobe_sysctls_init() do { } while (0)
53+
#endif
5154

5255
static int kprobes_initialized;
5356
/* kprobe_table can be accessed by
@@ -938,10 +941,10 @@ static void unoptimize_all_kprobes(void)
938941
}
939942

940943
static DEFINE_MUTEX(kprobe_sysctl_mutex);
941-
int sysctl_kprobes_optimization;
942-
int proc_kprobes_optimization_handler(struct ctl_table *table, int write,
943-
void *buffer, size_t *length,
944-
loff_t *ppos)
944+
static int sysctl_kprobes_optimization;
945+
static int proc_kprobes_optimization_handler(struct ctl_table *table,
946+
int write, void *buffer,
947+
size_t *length, loff_t *ppos)
945948
{
946949
int ret;
947950

@@ -957,6 +960,24 @@ int proc_kprobes_optimization_handler(struct ctl_table *table, int write,
957960

958961
return ret;
959962
}
963+
964+
static struct ctl_table kprobe_sysctls[] = {
965+
{
966+
.procname = "kprobes-optimization",
967+
.data = &sysctl_kprobes_optimization,
968+
.maxlen = sizeof(int),
969+
.mode = 0644,
970+
.proc_handler = proc_kprobes_optimization_handler,
971+
.extra1 = SYSCTL_ZERO,
972+
.extra2 = SYSCTL_ONE,
973+
},
974+
{}
975+
};
976+
977+
static void __init kprobe_sysctls_init(void)
978+
{
979+
register_sysctl_init("debug", kprobe_sysctls);
980+
}
960981
#endif /* CONFIG_SYSCTL */
961982

962983
/* Put a breakpoint for a probe. */
@@ -2584,6 +2605,7 @@ static int __init init_kprobes(void)
25842605
err = register_module_notifier(&kprobe_module_nb);
25852606

25862607
kprobes_initialized = (err == 0);
2608+
kprobe_sysctls_init();
25872609
return err;
25882610
}
25892611
early_initcall(init_kprobes);

kernel/sysctl.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include <linux/reboot.h>
5757
#include <linux/ftrace.h>
5858
#include <linux/perf_event.h>
59-
#include <linux/kprobes.h>
6059
#include <linux/oom.h>
6160
#include <linux/kmod.h>
6261
#include <linux/capability.h>
@@ -2818,17 +2817,6 @@ static struct ctl_table debug_table[] = {
28182817
.mode = 0644,
28192818
.proc_handler = proc_dointvec
28202819
},
2821-
#endif
2822-
#if defined(CONFIG_OPTPROBES)
2823-
{
2824-
.procname = "kprobes-optimization",
2825-
.data = &sysctl_kprobes_optimization,
2826-
.maxlen = sizeof(int),
2827-
.mode = 0644,
2828-
.proc_handler = proc_kprobes_optimization_handler,
2829-
.extra1 = SYSCTL_ZERO,
2830-
.extra2 = SYSCTL_ONE,
2831-
},
28322820
#endif
28332821
{ }
28342822
};

0 commit comments

Comments
 (0)