lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 22 Jul 2015 08:09:29 +0000
From:	Kaixu Xia <xiakaixu@...wei.com>
To:	<ast@...mgrid.com>, <davem@...emloft.net>, <acme@...nel.org>,
	<mingo@...hat.com>, <a.p.zijlstra@...llo.nl>,
	<masami.hiramatsu.pt@...achi.com>, <jolsa@...nel.org>
CC:	<xiakaixu@...wei.com>, <wangnan0@...wei.com>,
	<linux-kernel@...r.kernel.org>, <pi3orama@....com>,
	<hekuang@...wei.com>
Subject: [PATCH v2 2/5] bpf: Add function map->ops->map_traverse_elem() to traverse map elems

We want to traverse the map elements and make use
of the map value one by one. So add new function
map->ops->map_traverse_elem() to traverse map elements.

Signed-off-by: Kaixu Xia <xiakaixu@...wei.com>
---
 include/linux/bpf.h   |  3 +++
 kernel/bpf/arraymap.c | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index f6a2442..257149c 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -15,6 +15,8 @@
 
 struct bpf_map;
 
+typedef int (*bpf_map_traverse_callback)(void *value);
+
 /* map is generic key/value storage optionally accesible by eBPF programs */
 struct bpf_map_ops {
 	/* funcs callable from userspace (via syscall) */
@@ -26,6 +28,7 @@ struct bpf_map_ops {
 	void *(*map_lookup_elem)(struct bpf_map *map, void *key);
 	int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
 	int (*map_delete_elem)(struct bpf_map *map, void *key);
+	int (*map_traverse_elem)(bpf_map_traverse_callback func, struct bpf_map *map);
 };
 
 struct bpf_map {
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 183c1f7..410bc40 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -276,12 +276,29 @@ static int perf_event_array_map_get_next_key(struct bpf_map *map, void *key,
 	return -EINVAL;
 }
 
+static int perf_event_array_map_traverse_elem(bpf_map_traverse_callback func,
+					      struct bpf_map *map)
+{
+	struct bpf_array *array = container_of(map, struct bpf_array, map);
+	void *value;
+	int i;
+
+	for(i = 0; i < array->map.max_entries; i++) {
+		value = array->value + array->elem_size * i;
+
+		func(value);
+	}
+
+	return 0;
+}
+
 static const struct bpf_map_ops perf_event_array_ops = {
 	.map_alloc = perf_event_array_map_alloc,
 	.map_free = array_map_free,
 	.map_get_next_key = perf_event_array_map_get_next_key,
 	.map_lookup_elem = array_map_lookup_elem,
 	.map_delete_elem = array_map_delete_elem,
+	.map_traverse_elem = perf_event_array_map_traverse_elem,
 };
 
 static struct bpf_map_type_list perf_event_array_type __read_mostly = {
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ