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]
Message-ID: <1440672142-89311-4-git-send-email-xiakaixu@huawei.com>
Date:	Thu, 27 Aug 2015 10:42:21 +0000
From:	Kaixu Xia <xiakaixu@...wei.com>
To:	<ast@...mgrid.com>, <davem@...emloft.net>, <daniel@...earbox.net>,
	<acme@...nel.org>, <mingo@...hat.com>, <a.p.zijlstra@...llo.nl>,
	<masami.hiramatsu.pt@...achi.com>, <jolsa@...nel.org>
CC:	<linux-kernel@...r.kernel.org>, <wangnan0@...wei.com>,
	<pi3orama@....com>, <xiakaixu@...wei.com>
Subject: [RFC PATCH 3/4] bpf tools: Save the perf event fds from "maps" sections to 'struct bpf_object'

This patch saves the perf_event fds from "maps" sections to struct
bpf_object. So we can enable/disable these perf events at the
appropriate time.

Signed-off-by: Kaixu Xia <xiakaixu@...wei.com>
---
 tools/lib/bpf/libbpf.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 83d79c4..2b3940e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -126,6 +126,8 @@ struct bpf_object {
 	 */
 	size_t nr_map_fds;
 	bool loaded;
+	int *bpf_event_fds;
+	int nr_bpf_event_fds;
 
 	/*
 	 * Information when doing elf related work. Only valid if fd
@@ -629,7 +631,26 @@ bpf_program__collect_reloc(struct bpf_program *prog,
 }
 
 static int
-bpf_object__collect_perf_event_maps(void *data, int **pfd)
+bpf_object__save_event_bpf_fd(struct bpf_object *obj, int event_fd)
+{
+	void *bpf_event = obj->bpf_event_fds;
+	int nr_bpf_event = obj->nr_bpf_event_fds;
+
+	bpf_event = realloc(bpf_event, sizeof(int)*(nr_bpf_event + 1));
+
+	if (!bpf_event) {
+		pr_warning("realloc failed\n");
+		return -ENOMEM;
+	}
+
+	obj->bpf_event_fds = bpf_event;
+	obj->nr_bpf_event_fds = nr_bpf_event + 1;
+	obj->bpf_event_fds[nr_bpf_event] = event_fd;
+	return 0;
+}
+
+static int
+bpf_object__collect_perf_event_maps(struct bpf_object *obj, void *data, int **pfd)
 {
 	int i, event_fd;
 	int maps_fd = **pfd;
@@ -655,6 +676,8 @@ bpf_object__collect_perf_event_maps(void *data, int **pfd)
 			return -EINVAL;
 		}
 		bpf_update_elem(maps_fd, &i, &event_fd, BPF_ANY);
+		if (bpf_object__save_event_bpf_fd(obj, event_fd))
+			return -ENOMEM;
 	}
 	return 0;
 }
@@ -705,7 +728,7 @@ bpf_object__create_maps(struct bpf_object *obj)
 		if (def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY) {
 			void *data = obj->maps_buf + i * sizeof(struct bpf_map_def);
 
-			err = bpf_object__collect_perf_event_maps(data, &pfd);
+			err = bpf_object__collect_perf_event_maps(obj, data, &pfd);
 			if (err < 0) {
 				pr_warning("failed to collect perf_event maps: %s\n",
 					    strerror(errno));
@@ -1074,6 +1097,7 @@ void bpf_object__close(struct bpf_object *obj)
 			bpf_program__exit(&obj->programs[i]);
 	}
 	zfree(&obj->programs);
+	zfree(&obj->bpf_event_fds);
 
 	list_del(&obj->list);
 	free(obj);
-- 
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