summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2019-06-14 19:22:18 -0400
committerDavid S. Miller <davem@davemloft.net>2019-06-14 23:18:27 -0400
commita8e11e5c5611a9f70470aebeb2c1dd6132f609d7 (patch)
treef63600a91cf14ba2590ab2bad28dfae9729630a8
parent9a33629ba6b26caebd73e3c581ba1e6068c696a7 (diff)
sysctl: define proc_do_static_key()
Convert proc_dointvec_minmax_bpf_stats() into a more generic helper, since we are going to use jump labels more often. Note that sysctl_bpf_stats_enabled is removed, since it is no longer needed/used. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/bpf.h1
-rw-r--r--include/linux/sysctl.h3
-rw-r--r--kernel/bpf/core.c1
-rw-r--r--kernel/sysctl.c44
4 files changed, 26 insertions, 23 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 5df8e9e2a393..b92ef9f73e42 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -600,7 +600,6 @@ void bpf_map_area_free(void *base);
600void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr); 600void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
601 601
602extern int sysctl_unprivileged_bpf_disabled; 602extern int sysctl_unprivileged_bpf_disabled;
603extern int sysctl_bpf_stats_enabled;
604 603
605int bpf_map_new_fd(struct bpf_map *map, int flags); 604int bpf_map_new_fd(struct bpf_map *map, int flags);
606int bpf_prog_new_fd(struct bpf_prog *prog); 605int bpf_prog_new_fd(struct bpf_prog *prog);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index b769ecfcc3bd..aadd310769d0 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -63,6 +63,9 @@ extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
63 void __user *, size_t *, loff_t *); 63 void __user *, size_t *, loff_t *);
64extern int proc_do_large_bitmap(struct ctl_table *, int, 64extern int proc_do_large_bitmap(struct ctl_table *, int,
65 void __user *, size_t *, loff_t *); 65 void __user *, size_t *, loff_t *);
66extern int proc_do_static_key(struct ctl_table *table, int write,
67 void __user *buffer, size_t *lenp,
68 loff_t *ppos);
66 69
67/* 70/*
68 * Register a set of sysctl names by calling register_sysctl_table 71 * Register a set of sysctl names by calling register_sysctl_table
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 7c473f208a10..080e2bb644cc 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2097,7 +2097,6 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
2097 2097
2098DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key); 2098DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
2099EXPORT_SYMBOL(bpf_stats_enabled_key); 2099EXPORT_SYMBOL(bpf_stats_enabled_key);
2100int sysctl_bpf_stats_enabled __read_mostly;
2101 2100
2102/* All definitions of tracepoints related to BPF. */ 2101/* All definitions of tracepoints related to BPF. */
2103#define CREATE_TRACE_POINTS 2102#define CREATE_TRACE_POINTS
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7d1008be6173..1beca96fb625 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -230,11 +230,6 @@ static int proc_dostring_coredump(struct ctl_table *table, int write,
230#endif 230#endif
231static int proc_dopipe_max_size(struct ctl_table *table, int write, 231static int proc_dopipe_max_size(struct ctl_table *table, int write,
232 void __user *buffer, size_t *lenp, loff_t *ppos); 232 void __user *buffer, size_t *lenp, loff_t *ppos);
233#ifdef CONFIG_BPF_SYSCALL
234static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
235 void __user *buffer, size_t *lenp,
236 loff_t *ppos);
237#endif
238 233
239#ifdef CONFIG_MAGIC_SYSRQ 234#ifdef CONFIG_MAGIC_SYSRQ
240/* Note: sysrq code uses its own private copy */ 235/* Note: sysrq code uses its own private copy */
@@ -1253,12 +1248,10 @@ static struct ctl_table kern_table[] = {
1253 }, 1248 },
1254 { 1249 {
1255 .procname = "bpf_stats_enabled", 1250 .procname = "bpf_stats_enabled",
1256 .data = &sysctl_bpf_stats_enabled, 1251 .data = &bpf_stats_enabled_key.key,
1257 .maxlen = sizeof(sysctl_bpf_stats_enabled), 1252 .maxlen = sizeof(bpf_stats_enabled_key),
1258 .mode = 0644, 1253 .mode = 0644,
1259 .proc_handler = proc_dointvec_minmax_bpf_stats, 1254 .proc_handler = proc_do_static_key,
1260 .extra1 = &zero,
1261 .extra2 = &one,
1262 }, 1255 },
1263#endif 1256#endif
1264#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) 1257#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
@@ -3374,26 +3367,35 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
3374 3367
3375#endif /* CONFIG_PROC_SYSCTL */ 3368#endif /* CONFIG_PROC_SYSCTL */
3376 3369
3377#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL) 3370#if defined(CONFIG_SYSCTL)
3378static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write, 3371int proc_do_static_key(struct ctl_table *table, int write,
3379 void __user *buffer, size_t *lenp, 3372 void __user *buffer, size_t *lenp,
3380 loff_t *ppos) 3373 loff_t *ppos)
3381{ 3374{
3382 int ret, bpf_stats = *(int *)table->data; 3375 struct static_key *key = (struct static_key *)table->data;
3383 struct ctl_table tmp = *table; 3376 static DEFINE_MUTEX(static_key_mutex);
3377 int val, ret;
3378 struct ctl_table tmp = {
3379 .data = &val,
3380 .maxlen = sizeof(val),
3381 .mode = table->mode,
3382 .extra1 = &zero,
3383 .extra2 = &one,
3384 };
3384 3385
3385 if (write && !capable(CAP_SYS_ADMIN)) 3386 if (write && !capable(CAP_SYS_ADMIN))
3386 return -EPERM; 3387 return -EPERM;
3387 3388
3388 tmp.data = &bpf_stats; 3389 mutex_lock(&static_key_mutex);
3390 val = static_key_enabled(key);
3389 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 3391 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3390 if (write && !ret) { 3392 if (write && !ret) {
3391 *(int *)table->data = bpf_stats; 3393 if (val)
3392 if (bpf_stats) 3394 static_key_enable(key);
3393 static_branch_enable(&bpf_stats_enabled_key);
3394 else 3395 else
3395 static_branch_disable(&bpf_stats_enabled_key); 3396 static_key_disable(key);
3396 } 3397 }
3398 mutex_unlock(&static_key_mutex);
3397 return ret; 3399 return ret;
3398} 3400}
3399#endif 3401#endif