diff options
author | Eric Dumazet <edumazet@google.com> | 2019-06-14 19:22:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-06-14 23:18:27 -0400 |
commit | a8e11e5c5611a9f70470aebeb2c1dd6132f609d7 (patch) | |
tree | f63600a91cf14ba2590ab2bad28dfae9729630a8 /kernel/sysctl.c | |
parent | 9a33629ba6b26caebd73e3c581ba1e6068c696a7 (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>
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r-- | kernel/sysctl.c | 44 |
1 files changed, 23 insertions, 21 deletions
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 |
231 | static int proc_dopipe_max_size(struct ctl_table *table, int write, | 231 | static 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 | ||
234 | static 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) |
3378 | static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write, | 3371 | int 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 |