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: <1461175313-38310-10-git-send-email-wangnan0@huawei.com>
Date:	Wed, 20 Apr 2016 18:01:49 +0000
From:	Wang Nan <wangnan0@...wei.com>
To:	<acme@...nel.org>, <jolsa@...hat.com>, <brendan.d.gregg@...il.com>
CC:	<linux-kernel@...r.kernel.org>, <pi3orama@....com>,
	Wang Nan <wangnan0@...wei.com>,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	"Alexei Starovoitov" <ast@...nel.org>,
	Jiri Olsa <jolsa@...nel.org>, Li Zefan <lizefan@...wei.com>
Subject: [RFC PATCH 09/13] bpf tools: Register extern functions for ubpf programs

Introduce libbpf_register_ubpf_func(), allow caller (perf) to
register extern functions. Registered functions are stored into
an array and registered to each ubpf_vm when loading.

Signed-off-by: Wang Nan <wangnan0@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Brendan Gregg <brendan.d.gregg@...il.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Li Zefan <lizefan@...wei.com>
---
 tools/lib/bpf/libbpf.c | 38 +++++++++++++++++++++++++++++++++++++-
 tools/lib/bpf/libbpf.h |  4 ++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 4045a7e..f6df743 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -951,19 +951,48 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
 }
 
 #ifdef HAVE_UBPF_SUPPORT
+static struct {
+	const char *name;
+	void *func;
+} ubpf_funcs[MAX_UBPF_FUNC];
+
+int libbpf_register_ubpf_func(unsigned int idx, const char *name, void *func)
+{
+	if (idx >= MAX_UBPF_FUNC)
+		return -E2BIG;
+	if (!func)
+		return -EINVAL;
+
+	ubpf_funcs[idx].name = name;
+	ubpf_funcs[idx].func = func;
+	return 0;
+}
+
 static int
 load_ubpf_program(struct bpf_insn *insns, int insns_cnt,
 		  struct ubpf_vm **pvm)
 {
 	struct ubpf_vm *vm = ubpf_create();
 	char *message;
-	int err;
+	int i, err;
 
 	if (!vm) {
 		pr_warning("Failed to create ubpf vm\n");
 		return -LIBBPF_ERRNO__LOADUBPF;
 	}
 
+	for (i = 0; i < MAX_UBPF_FUNC; i++) {
+		if (ubpf_funcs[i].func) {
+			err = ubpf_register(vm, i, ubpf_funcs[i].name,
+					    ubpf_funcs[i].func);
+			if (err) {
+				pr_warning("Failed to register %s\n",
+					   ubpf_funcs[i].name);
+				return -LIBBPF_ERRNO__LOADUBPF;
+			}
+		}
+	}
+
 	err = ubpf_load(vm, insns, insns_cnt * sizeof(insns[0]), &message);
 	if (err < 0) {
 		pr_warning("Failed to load ubpf program: %s\n", message);
@@ -973,6 +1002,13 @@ load_ubpf_program(struct bpf_insn *insns, int insns_cnt,
 	*pvm = vm;
 	return 0;
 }
+#else
+int libbpf_register_ubpf_func(unsigned int idx __maybe_unused,
+			      const char *name __maybe_unused,
+			      void *func __maybe_unused)
+{
+	return -LIBBPF_ERRNO__NOUBPF;
+}
 #endif
 
 static int
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 41c35fd..a764dee 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -45,6 +45,10 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 		      libbpf_print_fn_t info,
 		      libbpf_print_fn_t debug);
 
+#define MAX_UBPF_FUNC	64
+
+int libbpf_register_ubpf_func(unsigned int idx, const char *name, void *func);
+
 /* Hide internal to user */
 struct bpf_object;
 
-- 
1.8.3.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ