aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-06-15 16:47:12 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-16 02:42:57 -0400
commit61d1b6a42fec61c5065f54cc62cef02b483c69fb (patch)
treeeb4b02ef08e8f73fd394fadb0b5e15008394c142
parentb478af0cd7957faca83779fe6832abae163f7159 (diff)
bpf, maps: add release callback
Add a release callback for maps that is invoked when the last reference to its struct file is gone and the struct file about to be released by vfs. The handler will be used by fd array maps. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/bpf.h3
-rw-r--r--kernel/bpf/syscall.c7
2 files changed, 8 insertions, 2 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 1bcae82c6cb1..29b5a1ae22cb 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -19,7 +19,8 @@ struct bpf_map;
19struct bpf_map_ops { 19struct bpf_map_ops {
20 /* funcs callable from userspace (via syscall) */ 20 /* funcs callable from userspace (via syscall) */
21 struct bpf_map *(*map_alloc)(union bpf_attr *attr); 21 struct bpf_map *(*map_alloc)(union bpf_attr *attr);
22 void (*map_free)(struct bpf_map *); 22 void (*map_release)(struct bpf_map *map, struct file *map_file);
23 void (*map_free)(struct bpf_map *map);
23 int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key); 24 int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
24 25
25 /* funcs callable from userspace and from eBPF programs */ 26 /* funcs callable from userspace and from eBPF programs */
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 46ecce4b79ed..fc3adcd064b1 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -124,7 +124,12 @@ void bpf_map_put_with_uref(struct bpf_map *map)
124 124
125static int bpf_map_release(struct inode *inode, struct file *filp) 125static int bpf_map_release(struct inode *inode, struct file *filp)
126{ 126{
127 bpf_map_put_with_uref(filp->private_data); 127 struct bpf_map *map = filp->private_data;
128
129 if (map->ops->map_release)
130 map->ops->map_release(map, filp);
131
132 bpf_map_put_with_uref(map);
128 return 0; 133 return 0;
129} 134}
130 135