Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp75211imm; Wed, 5 Sep 2018 15:15:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZCksLvCP2Uwp688h52FaKFOgD7FhS4SAna3kU6V4Jkbj/vUHLln2wP1c1mhxCjQXXapi45 X-Received: by 2002:a63:b258:: with SMTP id t24-v6mr12214690pgo.317.1536185721103; Wed, 05 Sep 2018 15:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536185721; cv=none; d=google.com; s=arc-20160816; b=te8b+VL75jmHbYOmbgsiVJVKjTONNgi/kYlNtOPxpZgaNKay14eny3Cg6qHAqnhkJG pIVUq3WC5lFqOVsARwk6pcbwEHoLNRMSvigOaU8PKirL54ux/4ZKHlbq/5YIyuDDex30 s5q9l8MoO5gKNel3N2cmNw2qesk8l7/CUutCU2AKRVYK8s6C3TIOdNQRsX5GnhfIFdSi 8c/QBGJ6b17h9UILemPlTXPm1CdBWmypm5RXzWjqYaaCJSn3mKnacSMHptiQOcwVEkCs pY41JDzyHve2wwBb6PYUMY3P9JvsPuTAUmSGG80pUPUKHLJQJZgIKcM6bj9p5y0GGM4b gj1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=hz9o956HPY2qtb56peyNTFdNWp6Ebo4LLkpH9PLfwqo=; b=lBE+Ekp6PvVy3fupA5/JHhctK8w+RK+GiIJg93Lh8iHw47xvNpgaTboVtbT82ELlba UW6PwXBFdswzVSwKIcOnhGPWP/fNQAPqasFuS5XEUcjz3vM31IsJEOeXNHXMfIV/uLh1 spSdeaXs1S34V2bkEd79txXQeuam5a0W0yBcgo8NjL5zhD5HI5fhKlco4YMW4KL3ksua qLRrL5YupAZHbOEyGnKEKN8aF6Jw1n2pEfDH++6pVC2wbp7MXMBs4W4hPdeSrGdQYjyn gmW1DJSZZZMel7YQsE/SxWEcCjaaGEGji+yaN+fieSc9H41MD9XPgnqxc87xfXfMiD+x NZlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAZAxpF7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9-v6si3141185pgj.430.2018.09.05.15.15.01; Wed, 05 Sep 2018 15:15:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAZAxpF7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbeIFChJ (ORCPT + 99 others); Wed, 5 Sep 2018 22:37:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:50990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727518AbeIFChI (ORCPT ); Wed, 5 Sep 2018 22:37:08 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E5BF92083E; Wed, 5 Sep 2018 22:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536185096; bh=eldVP5gMj/MFCmVmOSqTDz+eXaAbDBwW5Z+SehRBtZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HAZAxpF7AmrmwRJ+W8e0HkFG5RihMypI1Hd0dpuws06OGPQHuBVYBEVzj84d18Yz2 HVU/of/r3uDgg42Aq9XTj8Zt4NmxQ819KFvwIsiNS4Y8a7EOpGA+/0Nvi7x1F+E3Ks 1GAZFAXmSGAasoZiIrvJGLg69qhbUAgYqGaSwj2I= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 01/77] perf trace: Pass augmented args to the arg formatters when available Date: Wed, 5 Sep 2018 19:03:24 -0300 Message-Id: <20180905220440.20256-2-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180905220440.20256-1-acme@kernel.org> References: <20180905220440.20256-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo If the tracepoint payload is bigger than what a syscall expected from what is in its format file in tracefs, then that will be used as augmented args, i.e. the expansion of syscall arg pointers, with things like a filename, structs, etc. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-bsbqx7xi2ot4q9bf570f7tqs@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 28 ++++++++++++++++++++++------ tools/perf/trace/beauty/beauty.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 22ab8e67c760..7deae6c8cb25 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -856,10 +856,12 @@ static struct syscall_fmt *syscall_fmt__find(const char *name) /* * is_exit: is this "exit" or "exit_group"? * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter. + * args_size: sum of the sizes of the syscall arguments, anything after that is augmented stuff: pathname for openat, etc. */ struct syscall { struct event_format *tp_format; int nr_args; + int args_size; bool is_exit; bool is_open; struct format_field *args; @@ -1258,10 +1260,12 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args) static int syscall__set_arg_fmts(struct syscall *sc) { - struct format_field *field; + struct format_field *field, *last_field = NULL; int idx = 0, len; for (field = sc->args; field; field = field->next, ++idx) { + last_field = field; + if (sc->fmt && sc->fmt->arg[idx].scnprintf) continue; @@ -1292,6 +1296,9 @@ static int syscall__set_arg_fmts(struct syscall *sc) } } + if (last_field) + sc->args_size = last_field->offset + last_field->size; + return 0; } @@ -1472,14 +1479,18 @@ static size_t syscall__scnprintf_val(struct syscall *sc, char *bf, size_t size, } static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, - unsigned char *args, struct trace *trace, - struct thread *thread) + unsigned char *args, void *augmented_args, int augmented_args_size, + struct trace *trace, struct thread *thread) { size_t printed = 0; unsigned long val; u8 bit = 1; struct syscall_arg arg = { .args = args, + .augmented = { + .size = augmented_args_size, + .args = augmented_args, + }, .idx = 0, .mask = 0, .trace = trace, @@ -1692,7 +1703,7 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name); printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed, - args, trace, thread); + args, NULL, 0, trace, thread); if (sc->is_exit) { if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { @@ -1723,7 +1734,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evse int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; struct syscall *sc = trace__syscall_info(trace, evsel, id); char msg[1024]; - void *args; + void *args, *augmented_args = NULL; + int augmented_args_size; if (sc == NULL) return -1; @@ -1738,7 +1750,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evse goto out_put; args = perf_evsel__sc_tp_ptr(evsel, args, sample); - syscall__scnprintf_args(sc, msg, sizeof(msg), args, trace, thread); + augmented_args_size = sample->raw_size - sc->args_size; + if (augmented_args_size > 0) + augmented_args = sample->raw_data + sc->args_size; + + syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); fprintf(trace->output, "%s", msg); err = 0; out_put: diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h index 9615af5d412b..6ca044d3d851 100644 --- a/tools/perf/trace/beauty/beauty.h +++ b/tools/perf/trace/beauty/beauty.h @@ -30,9 +30,34 @@ struct thread; size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size); +/** + * augmented_arg: extra payload for syscall pointer arguments + + * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts, + * then its the arguments contents, so that we can show more than just a + * pointer. This will be done initially with eBPF, the start of that is at the + * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but + * will eventually be done automagically caching the running kernel tracefs + * events data into an eBPF C script, that then gets compiled and its .o file + * cached for subsequent use. For char pointers like the ones for 'open' like + * syscalls its easy, for the rest we should use DWARF or better, BTF, much + * more compact. + * + * @size: 8 if all we need is an integer, otherwise all of the augmented arg. + * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen' + * @value: u64 aligned, for structs, pathnames + */ +struct augmented_arg { + int size; + int int_arg; + u64 value[]; +}; + /** * @val: value of syscall argument being formatted * @args: All the args, use syscall_args__val(arg, nth) to access one + * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc + * @augmented_args_size: augmented_args total payload size * @thread: tid state (maps, pid, tid, etc) * @trace: 'perf trace' internals: all threads, etc * @parm: private area, may be an strarray, for instance @@ -43,6 +68,10 @@ size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_ struct syscall_arg { unsigned long val; unsigned char *args; + struct { + struct augmented_arg *args; + int size; + } augmented; struct thread *thread; struct trace *trace; void *parm; -- 2.14.4