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>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Luis Cláudio Gonçalves" <lclaudio@redhat.com>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Wang Nan" <wangnan0@huawei.com>
Subject: [PATCH 56/63] perf trace beauty: Beautify arch_prctl()'s arguments
Date: Tue, 18 Dec 2018 19:07:26 -0300	[thread overview]
Message-ID: <20181218220733.15839-57-acme@kernel.org> (raw)
In-Reply-To: <20181218220733.15839-1-acme@kernel.org>

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

This actually so far, AFAIK is available only in x86, so the code was
put in place with x86 prefixes, in arches where it is not available it
will just not be called, so no further mechanisms are needed at this
time.

Later, when other arches wire this up, we'll just look at the uname
(live sessions) or perf_env data in the perf.data header to auto-wire
the right beautifier.

With this the output is the same as produced by 'strace' when used with
the following ~/.perfconfig:

  # cat ~/.perfconfig
  [llvm]
	dump-obj = true
  [trace]
	  add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
	  show_zeros = yes
	  show_duration = no
	  no_inherit = yes
	  show_timestamp = no
	  show_arg_names = no
	  args_alignment = -40
	  show_prefix = yes
  #

And, on fedora 29, since the string tables are generated from the kernel
sources, we don't know about 0x3001, just like strace:

  --- /tmp/strace 2018-12-17 11:22:08.707586721 -0300
  +++ /tmp/trace  2018-12-18 11:11:32.037512729 -0300
  @@ -1,49 +1,49 @@
  -arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc8a92dc80) = -1 EINVAL (Invalid argument)
  +arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe4eb93ae0) = -1 EINVAL (Invalid argument)
  -arch_prctl(ARCH_SET_FS, 0x7faf6700f540) = 0
  +arch_prctl(ARCH_SET_FS, 0x7fb507364540) = 0

And that seems to be related to the CET/Shadow Stack feature, that
userland in Fedora 29 (glibc 2.28) are querying the kernel about, that
0x3001 seems to be ARCH_CET_STATUS, I'll check the situation and test
with a fedora 29 kernel to see if the other codes are used.

A diff that ignores the different pointers for different runs needs to
be put in place in the upcoming regression tests comparing 'perf trace's
output to strace's.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-73a9prs8ktkrt97trtdmdjs8@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c           |  5 ++++-
 tools/perf/trace/beauty/Build        |  1 +
 tools/perf/trace/beauty/arch_prctl.c | 33 ++++++++++++++++++++++++++++
 tools/perf/trace/beauty/beauty.h     |  3 +++
 4 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/trace/beauty/arch_prctl.c

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6d9be952e3a7..2cc62ca75b2e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -664,6 +664,9 @@ static struct syscall_fmt {
 } syscall_fmts[] = {
 	{ .name	    = "access",
 	  .arg = { [1] = { .scnprintf = SCA_ACCMODE,  /* mode */ }, }, },
+	{ .name	    = "arch_prctl",
+	  .arg = { [0] = { .scnprintf = SCA_X86_ARCH_PRCTL_CODE, /* code */ },
+		   [1] = { .scnprintf = SCA_PTR, /* arg2 */ }, }, },
 	{ .name	    = "bind",
 	  .arg = { [1] = { .scnprintf = SCA_SOCKADDR, /* umyaddr */ }, }, },
 	{ .name	    = "bpf",
@@ -793,7 +796,7 @@ static struct syscall_fmt {
 		   [3] = { .scnprintf = SCA_INT,	/* pkey */ }, }, },
 	{ .name	    = "poll", .timeout = true, },
 	{ .name	    = "ppoll", .timeout = true, },
-	{ .name	    = "prctl", .alias = "arch_prctl",
+	{ .name	    = "prctl",
 	  .arg = { [0] = { .scnprintf = SCA_PRCTL_OPTION, /* option */ },
 		   [1] = { .scnprintf = SCA_PRCTL_ARG2, /* arg2 */ },
 		   [2] = { .scnprintf = SCA_PRCTL_ARG3, /* arg3 */ }, }, },
diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build
index 10c85cd3eb4f..637365099b7d 100644
--- a/tools/perf/trace/beauty/Build
+++ b/tools/perf/trace/beauty/Build
@@ -7,6 +7,7 @@ endif
 libperf-y += kcmp.o
 libperf-y += mount_flags.o
 libperf-y += pkey_alloc.o
+libperf-y += arch_prctl.o
 libperf-y += prctl.o
 libperf-y += renameat.o
 libperf-y += sockaddr.o
diff --git a/tools/perf/trace/beauty/arch_prctl.c b/tools/perf/trace/beauty/arch_prctl.c
new file mode 100644
index 000000000000..fe022ca67e60
--- /dev/null
+++ b/tools/perf/trace/beauty/arch_prctl.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * trace/beauty/arch_prctl.c
+ *
+ *  Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
+ */
+
+#include "trace/beauty/beauty.h"
+#include <linux/kernel.h>
+
+#include "trace/beauty/generated/x86_arch_prctl_code_array.c"
+
+static DEFINE_STRARRAY_OFFSET(x86_arch_prctl_codes_1, "ARCH_", x86_arch_prctl_codes_1_offset);
+static DEFINE_STRARRAY_OFFSET(x86_arch_prctl_codes_2, "ARCH_", x86_arch_prctl_codes_2_offset);
+
+static struct strarray *x86_arch_prctl_codes[] = {
+	&strarray__x86_arch_prctl_codes_1,
+	&strarray__x86_arch_prctl_codes_2,
+};
+
+static DEFINE_STRARRAYS(x86_arch_prctl_codes);
+
+static size_t x86_arch_prctl__scnprintf_code(int option, char *bf, size_t size, bool show_prefix)
+{
+	return strarrays__scnprintf(&strarrays__x86_arch_prctl_codes, bf, size, "%#x", show_prefix, option);
+}
+
+size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg)
+{
+	unsigned long code = arg->val;
+
+	return x86_arch_prctl__scnprintf_code(code, bf, size, arg->show_string_prefix);
+}
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 58e734b27958..83c5b202e00e 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -155,6 +155,9 @@ size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, st
 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg);
 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
 
+size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg);
+#define SCA_X86_ARCH_PRCTL_CODE syscall_arg__scnprintf_x86_arch_prctl_code
+
 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg);
 #define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option
 
-- 
2.19.2


  parent reply	other threads:[~2018-12-18 22:16 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-18 22:06 [GIT PULL 00/63] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 01/63] perf dso: Export data_file_size() method there are no symbols Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 02/63] perf auxtrace: Alter addr_filter__entire_dso() to work if " Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 03/63] perf tests: Use shebangs in the shell scripts Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 04/63] perf stat: Avoid segfaults caused by negated options Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 05/63] tools lib traceevent: Fix processing of dereferenced args in bprintk events Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 06/63] perf trace: Rename delivery functions to ease making ordered_events selectable Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 07/63] perf trace: Allow selecting use the use of the ordered_events code Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 08/63] perf trace beauty: Beautify renameat2's fd arg wrt AT_FDCWD Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 09/63] perf beauty: Add a string table generator for renameat2's flags constants Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 10/63] perf beauty: Wire up the renameat flags table generator to the Makefile Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 11/63] perf trace: Beautify renameat2's flags argument Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 12/63] perf trace beauty: renameat's newdirfd may also be AT_FDCWD Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 13/63] tools lib subcmd: Don't add the kernel sources to the include path Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 14/63] perf tools: Add missing sigqueue() prototype for systems lacking it Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 15/63] perf header: Fix up argument to ctime() Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 16/63] perf tools: Add missing open_memstream() prototype for systems lacking it Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 17/63] perf tools: Cast off_t to s64 to avoid warning on bionic libc Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 18/63] tools lib traceevent: Use LDFLAGS in the build commands Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 19/63] perf tools: Link libperf-jvmti.so with LDFLAGS variable Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 20/63] perf trace: Rename set_ev_qualifier_filter to clarify its a tracepoint filter Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 21/63] perf trace: Avoid using raw_syscalls in duplicity with eBPF augmentation Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 22/63] perf trace: Implement syscall filtering in augmented_syscalls Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 23/63] perf bpf: Move perf_event_output() from stdio.h to bpf.h Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 24/63] perf augmented_syscalls: Switch to using a struct for the syscalls map values Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 25/63] perf trace: Switch to using a struct for the aumented_raw_syscalls " Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 26/63] perf cs-etm: Correct packets swapping in cs_etm__flush() Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 27/63] perf cs-etm: Avoid stale branch samples when flush packet Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 28/63] perf cs-etm: Remove unused 'trace_on' in cs_etm_decoder Arnaldo Carvalho de Melo
2018-12-18 22:06 ` [PATCH 29/63] perf cs-etm: Refactor enumeration cs_etm_sample_type Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 30/63] perf cs-etm: Rename CS_ETM_TRACE_ON to CS_ETM_DISCONTINUITY Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 31/63] perf cs-etm: Treat NO_SYNC element as trace discontinuity Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 32/63] perf cs-etm: Treat EO_TRACE " Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 33/63] perf cs-etm: Generate branch sample for exception packet Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 34/63] perf augmented_raw_syscalls: Do not include stdio.h Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 35/63] perf trace: Allow specifying a set of events to add in perfconfig Arnaldo Carvalho de Melo
2018-12-19  8:40   ` Namhyung Kim
2018-12-19 12:50     ` Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 36/63] perf trace: Allow configuring if zeroed syscall args should be printed Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 37/63] perf trace: Allow configuring if the syscall duration " Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 38/63] perf config: Show the configuration when no arguments are provided Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 39/63] perf trace: Allow configuring default for perf_event_attr.inherit Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 40/63] perf trace: Allow configuring if the syscall start timestamp should be printed Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 41/63] perf trace: Allow suppressing the syscall argument names Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 42/63] perf trace: Make the alignment of the syscall args be configurable Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 43/63] perf trace: Enclose strings with double quotes Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 44/63] perf trace: Add a prefix member to the strarray class Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 45/63] perf trace: Allow asking for not suppressing common string prefixes Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 46/63] perf trace beauty: Print O_RDONLY when (flags & O_ACCMODE) == 0 Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 47/63] perf trace: Add alignment spaces after the closing parens Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 48/63] perf augmented_raw_syscalls: Copy 'access' arg as well Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 49/63] perf trace: Enclose the errno strings with () Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 50/63] perf trace: Show NULL when syscall pointer args are 0 Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 51/63] tools include arch: Grab a copy of x86's prctl.h Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 52/63] perf beauty: Add a string table generator for x86's 'arch_prctl' codes Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 53/63] perf beauty: Wire up the x86_arch prctl code table generator Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 54/63] perf trace: Move strarrays to beauty.h for further reuse Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 55/63] perf trace: When showing string prefixes show prefix + ??? for unknown entries Arnaldo Carvalho de Melo
2018-12-18 22:07 ` Arnaldo Carvalho de Melo [this message]
2018-12-18 22:07 ` [PATCH 57/63] perf beauty mmap: Print PROT_READ before PROT_EXEC to match strace output Arnaldo Carvalho de Melo
2018-12-19  9:15   ` Namhyung Kim
2018-12-19 13:10     ` Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 58/63] perf beauty mmap: Print mmap's 'offset' arg in hexadecimal Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 59/63] tools headers uapi: Grab a copy of fadvise.h Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 60/63] perf beauty: Add generator for fadvise64's 'advice' arg constants Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 61/63] perf trace: Wire up the fadvise 'advice' table generator Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 62/63] perf symbols: Relax checks on perf-PID.map ownership Arnaldo Carvalho de Melo
2018-12-18 22:07 ` [PATCH 63/63] tools uapi asm: Update asm-generic/unistd.h copy Arnaldo Carvalho de Melo
2018-12-20 17:53 ` [GIT PULL 00/63] perf/core improvements and fixes Ingo Molnar

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=20181218220733.15839-57-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=lclaudio@redhat.com \
    --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).