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: <1432456091-73384-16-git-send-email-hekuang@huawei.com>
Date:	Sun, 24 May 2015 08:28:11 +0000
From:	He Kuang <hekuang@...wei.com>
To:	<wangnan0@...wei.com>, <paulus@...ba.org>,
	<a.p.zijlstra@...llo.nl>, <mingo@...hat.com>, <acme@...nel.org>,
	<namhyung@...nel.org>, <jolsa@...nel.org>, <ast@...mgrid.com>,
	<masami.hiramatsu.pt@...achi.com>, <dsahern@...il.com>,
	<brendan.d.gregg@...il.com>, <daniel@...earbox.net>
CC:	<lizefan@...wei.com>, <linux-kernel@...r.kernel.org>
Subject: [RFC PATCH v2 15/15] samples/bpf: Add sample for no-debuginfo case

Sample code for testing bpf fetch args without debuginfo.

Works as following steps:

  $ perf bpf record --object /mnt/9p/sample_bpf_fetch_args_without_debug.o -- dd if=/dev/zero of=/mnt/data/test bs=4k count=3

show result in ringbuffer:
  $ perf script
  dd  1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x0 arg4=0x0 arg5=0x55617215 arg6=0x1839010
  dd  1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x1000 arg4=0x0 arg5=0x55617215 arg6=0x1839010
  dd  1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x2000 arg4=0x0 arg5=0x55617215 arg6=0x1839010
  dd  1183 [000] 88000.240137: perf_bpf_probe:submit_bio: (ffffffff81310ca0) arg1=0x1 arg2=0xffff88007c9d8000 arg3=0x8b9 arg4=0x8ba arg5=0x1b8e0 arg6=0xffff88007fc1b8e0

show result in bpf prog:

  $ cat /sys/kernel/debug/tracing/trace | grep dd-
  dd-1183  [000] d... 88072.038971: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=0
  dd-1183  [000] d... 88072.039625: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=4096
  dd-1183  [000] d... 88072.039833: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=8192
  dd-1183  [000] d... 88072.040533: : submit_bio rw=1, bio=ffff88007c9d8000

Signed-off-by: He Kuang <hekuang@...wei.com>
---
 samples/bpf/Makefile                              |  1 +
 samples/bpf/sample_bpf_fetch_args_without_debug.c | 49 +++++++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 samples/bpf/sample_bpf_fetch_args_without_debug.c

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index dc0b0e8..282c959 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -31,6 +31,7 @@ always += tracex3_kern.o
 always += tracex4_kern.o
 always += tcbpf1_kern.o
 always += sample_bpf_fetch_args.o
+always += sample_bpf_fetch_args_without_debug.o
 
 HOSTCFLAGS += -I$(objtree)/usr/include
 
diff --git a/samples/bpf/sample_bpf_fetch_args_without_debug.c b/samples/bpf/sample_bpf_fetch_args_without_debug.c
new file mode 100644
index 0000000..69519ed
--- /dev/null
+++ b/samples/bpf/sample_bpf_fetch_args_without_debug.c
@@ -0,0 +1,49 @@
+/*
+  Sample code for bpf_fetch_args() without debuginfo.
+*/
+
+#include <linux/writeback.h>
+#include <linux/blkdev.h>
+
+#include <uapi/linux/bpf.h>
+#include <linux/version.h>
+#include "bpf_helpers.h"
+
+/*
+ * Prototype:
+ * ssize_t generic_perform_write(struct file *file,
+ *			struct iov_iter *i, loff_t pos)
+ */
+SEC("generic_perform_write=generic_perform_write $params")
+int NODE_generic_perform_write(struct pt_regs *ctx,
+			void *file,
+			void *i,
+			void *pos)
+{
+	char fmt[] = "generic_perform_write: file=%p, i=%p, pos=%lu\n";
+
+	bpf_trace_printk(fmt, sizeof(fmt),
+			file, i, (unsigned long)pos);
+
+	return 1;
+}
+
+/*
+ * Prototype:
+ * void submit_bio(int rw, struct bio *bio)
+ */
+SEC("submit_bio=submit_bio $params")
+int NODE_submit_bio(struct pt_regs *ctx,
+			void *rw,
+			void *bio)
+{
+	char fmt[] = "submit_bio rw=%d, bio=%p\n";
+
+	bpf_trace_printk(fmt, sizeof(fmt),
+			(int)rw, bio);
+
+	return 1;
+}
+
+char _license[] SEC("license") = "GPL";
+u32 _version SEC("version") = LINUX_VERSION_CODE;
-- 
1.8.5.2

--
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