linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 12/44] perf bpf: Add 'syscall_enter' probe helper for syscall enter tracepoints
Date: Thu,  9 Aug 2018 11:57:50 -0300	[thread overview]
Message-ID: <20180809145822.21391-13-acme@kernel.org> (raw)
In-Reply-To: <20180809145822.21391-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Allowing one to hook into the syscalls:sys_enter_NAME tracepoints,
an example is provided that hooks into the 'openat' syscall.

Using it with the probe:vfs_getname probe into getname_flags to get the
filename args as it is copied from userspace:

  # perf probe -l
  probe:vfs_getname    (on getname_flags:73@acme/git/linux/fs/namei.c with pathname)
  # perf trace -e probe:*getname,tools/perf/examples/bpf/sys_enter_openat.c cat /etc/passwd > /dev/null
     0.000 probe:vfs_getname:(ffffffffbd2a8983) pathname="/etc/ld.so.preload"
     0.022 syscalls:sys_enter_openat:dfd: CWD, filename: 0xafbe8da8, flags: CLOEXEC
     0.027 probe:vfs_getname:(ffffffffbd2a8983) pathname="/etc/ld.so.cache"
     0.054 syscalls:sys_enter_openat:dfd: CWD, filename: 0xafdf0ce0, flags: CLOEXEC
     0.057 probe:vfs_getname:(ffffffffbd2a8983) pathname="/lib64/libc.so.6"
     0.316 probe:vfs_getname:(ffffffffbd2a8983) pathname="/usr/lib/locale/locale-archive"
     0.375 syscalls:sys_enter_openat:dfd: CWD, filename: 0xe2b2b0b4
     0.379 probe:vfs_getname:(ffffffffbd2a8983) pathname="/etc/passwd"
  #

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-2po9jcqv1qgj0koxlg8kkg30@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/examples/bpf/sys_enter_openat.c | 33 ++++++++++++++++++++++++++++++
 tools/perf/include/bpf/bpf.h               |  3 +++
 2 files changed, 36 insertions(+)
 create mode 100644 tools/perf/examples/bpf/sys_enter_openat.c

diff --git a/tools/perf/examples/bpf/sys_enter_openat.c b/tools/perf/examples/bpf/sys_enter_openat.c
new file mode 100644
index 000000000000..9cd124b09392
--- /dev/null
+++ b/tools/perf/examples/bpf/sys_enter_openat.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Hook into 'openat' syscall entry tracepoint
+ *
+ * Test it with:
+ *
+ * perf trace -e tools/perf/examples/bpf/sys_enter_openat.c cat /etc/passwd > /dev/null
+ *
+ * It'll catch some openat syscalls related to the dynamic linked and
+ * the last one should be the one for '/etc/passwd'.
+ *
+ * The syscall_enter_openat_args can be used to get the syscall fields
+ * and use them for filtering calls, i.e. use in expressions for
+ * the return value.
+ */
+
+#include <bpf.h>
+
+struct syscall_enter_openat_args {
+	unsigned long long unused;
+	long		   syscall_nr;
+	long		   dfd;
+	char		   *filename_ptr;
+	long		   flags;
+	long		   mode;
+};
+
+int syscall_enter(openat)(struct syscall_enter_openat_args *args)
+{
+	return 1;
+}
+
+license(GPL);
diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
index a63aa6241b7f..2873cdde293f 100644
--- a/tools/perf/include/bpf/bpf.h
+++ b/tools/perf/include/bpf/bpf.h
@@ -9,6 +9,9 @@
 #define probe(function, vars) \
 	SEC(#function "=" #function " " #vars) function
 
+#define syscall_enter(name) \
+	SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
+
 #define license(name) \
 char _license[] SEC("license") = #name; \
 int _version SEC("version") = LINUX_VERSION_CODE;
-- 
2.14.4


  parent reply	other threads:[~2018-08-09 14:59 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-09 14:57 [GIT PULL 00/44] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 01/44] perf trace: Associate vfs_getname()'ed pathname with fd returned from 'openat' Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 02/44] perf trace: Use beautifiers on syscalls:sys_enter_ handlers Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 03/44] perf trace: Rename some syscall_tp methods to raw_syscall Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 04/44] perf trace: Allow setting up a syscall_tp struct without a format_field Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 05/44] perf trace: Setup struct syscall_tp for syscalls:sys_{enter,exit}_NAME events Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 06/44] perf trace: Use perf_evsel__sc_tp_{uint,ptr} for "id"/"args" handling syscalls:* events Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 07/44] perf auxtrace: Support for perf report -D for s390 Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 08/44] perf report: Add raw report support for s390 auxiliary trace Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 09/44] perf report: Add GUI " Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 10/44] perf vendor events arm64: Enable JSON events for eMAG Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 11/44] perf tools: Drop unneeded bitmap_zero() calls Arnaldo Carvalho de Melo
2018-08-09 14:57 ` Arnaldo Carvalho de Melo [this message]
2018-08-09 14:57 ` [PATCH 13/44] perf annotate: Make symbol__annotate_fprintf2() local Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 14/44] perf annotate: Make annotation_line__max_percent static Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 15/44] perf annotate: Get rid of annotation__scnprintf_samples_period() Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 16/44] perf annotate: Rename struct annotation_line::samples* to data* Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 17/44] perf annotate: Rename local sample variables to data Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 18/44] perf annotate: Rename hist to sym_hist in annotation__calc_percent Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 19/44] perf annotate: Loop group events directly in annotation__calc_percent() Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 20/44] perf annotate: Switch struct annotation_data::percent to array Arnaldo Carvalho de Melo
2018-08-09 14:57 ` [PATCH 21/44] perf annotate: Add PERCENT_HITS_GLOBAL percent value Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 22/44] perf annotate: Add PERCENT_PERIOD_LOCAL " Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 23/44] perf annotate: Add PERCENT_PERIOD_GLOBAL " Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 24/44] perf annotate: Add percent_type to struct annotation_options Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 25/44] perf annotate: Pass struct annotation_options to symbol__calc_lines() Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 26/44] perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump() Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 27/44] perf annotate: Pass browser percent_type in annotate_browser__calc_percent() Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 28/44] perf annotate: Add support to toggle percent type Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 29/44] perf annotate: Make local period the default " Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 30/44] perf annotate: Display percent type in stdio output Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 31/44] perf annotate: Add --percent-type option Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 32/44] perf report: " Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 33/44] perf bpf: Add struct bpf_map struct Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 34/44] perf bpf: Add bpf/stdio.h wrapper to bpf_perf_event_output function Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 35/44] perf bpf: Make bpf__for_each_stdout_map() generic Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 36/44] perf bpf: Generalize bpf__setup_stdout() Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 37/44] perf bpf: Add bpf__setup_output_event() strerror() counterpart Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 38/44] perf bpf: Add wrappers to BPF_FUNC_probe_read(_str) functions Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 39/44] perf trace: Handle "bpf-output" events associated with "__augmented_syscalls__" BPF map Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 40/44] perf bpf: Make bpf__setup_output_event() return the bpf-output event Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 41/44] perf trace: Setup the augmented syscalls bpf-output event fields Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 42/44] perf trace: Wire up the augmented syscalls with the syscalls:sys_enter_FOO beautifier Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 43/44] perf map: Synthesize maps only for thread group leader Arnaldo Carvalho de Melo
2018-08-09 14:58 ` [PATCH 44/44] perf map: Optimize maps__fixup_overlappings() Arnaldo Carvalho de Melo
2018-08-09 15:27 ` [GIT PULL 00/44] perf/core improvements and fixes Kim Phillips

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180809145822.21391-13-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).