diff options
Diffstat (limited to 'kernel/bpf/arraymap.c')
-rw-r--r-- | kernel/bpf/arraymap.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 5af30732697b..db1a743e3db2 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c | |||
@@ -390,9 +390,7 @@ static void *prog_fd_array_get_ptr(struct bpf_map *map, | |||
390 | 390 | ||
391 | static void prog_fd_array_put_ptr(void *ptr) | 391 | static void prog_fd_array_put_ptr(void *ptr) |
392 | { | 392 | { |
393 | struct bpf_prog *prog = ptr; | 393 | bpf_prog_put(ptr); |
394 | |||
395 | bpf_prog_put_rcu(prog); | ||
396 | } | 394 | } |
397 | 395 | ||
398 | /* decrement refcnt of all bpf_progs that are stored in this map */ | 396 | /* decrement refcnt of all bpf_progs that are stored in this map */ |
@@ -539,3 +537,46 @@ static int __init register_perf_event_array_map(void) | |||
539 | return 0; | 537 | return 0; |
540 | } | 538 | } |
541 | late_initcall(register_perf_event_array_map); | 539 | late_initcall(register_perf_event_array_map); |
540 | |||
541 | #ifdef CONFIG_SOCK_CGROUP_DATA | ||
542 | static void *cgroup_fd_array_get_ptr(struct bpf_map *map, | ||
543 | struct file *map_file /* not used */, | ||
544 | int fd) | ||
545 | { | ||
546 | return cgroup_get_from_fd(fd); | ||
547 | } | ||
548 | |||
549 | static void cgroup_fd_array_put_ptr(void *ptr) | ||
550 | { | ||
551 | /* cgroup_put free cgrp after a rcu grace period */ | ||
552 | cgroup_put(ptr); | ||
553 | } | ||
554 | |||
555 | static void cgroup_fd_array_free(struct bpf_map *map) | ||
556 | { | ||
557 | bpf_fd_array_map_clear(map); | ||
558 | fd_array_map_free(map); | ||
559 | } | ||
560 | |||
561 | static const struct bpf_map_ops cgroup_array_ops = { | ||
562 | .map_alloc = fd_array_map_alloc, | ||
563 | .map_free = cgroup_fd_array_free, | ||
564 | .map_get_next_key = array_map_get_next_key, | ||
565 | .map_lookup_elem = fd_array_map_lookup_elem, | ||
566 | .map_delete_elem = fd_array_map_delete_elem, | ||
567 | .map_fd_get_ptr = cgroup_fd_array_get_ptr, | ||
568 | .map_fd_put_ptr = cgroup_fd_array_put_ptr, | ||
569 | }; | ||
570 | |||
571 | static struct bpf_map_type_list cgroup_array_type __read_mostly = { | ||
572 | .ops = &cgroup_array_ops, | ||
573 | .type = BPF_MAP_TYPE_CGROUP_ARRAY, | ||
574 | }; | ||
575 | |||
576 | static int __init register_cgroup_array_map(void) | ||
577 | { | ||
578 | bpf_register_map_type(&cgroup_array_type); | ||
579 | return 0; | ||
580 | } | ||
581 | late_initcall(register_cgroup_array_map); | ||
582 | #endif | ||