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>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Russell King - ARM Linux admin <linux@armlinux.org.uk>,
	Song Liu <songliubraving@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>
Subject: [PATCH 24/24] perf annotate: Don't return -1 for error when doing BPF disassembly
Date: Tue,  1 Oct 2019 08:12:16 -0300	[thread overview]
Message-ID: <20191001111216.7208-25-acme@kernel.org> (raw)
In-Reply-To: <20191001111216.7208-1-acme@kernel.org>

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

Return errno when open_memstream() fails and add two new speciall error
codes for when an invalid, non BPF file or one without BTF is passed to
symbol__disassemble_bpf(), so that its callers can rely on
symbol__strerror_disassemble() to convert that to a human readable error
message that can help figure out what is wrong, with hints even.

Cc: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: Song Liu <songliubraving@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Cc: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/n/tip-usevw9r2gcipfcrbpaueurw0@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 19 +++++++++++++++----
 tools/perf/util/annotate.h |  2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b49ecdd51188..4036c7f7b0fb 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1637,6 +1637,13 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
 	case SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING:
 		scnprintf(buf, buflen, "Problems while parsing the CPUID in the arch specific initialization.");
 		break;
+	case SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE:
+		scnprintf(buf, buflen, "Invalid BPF file: %s.", dso->long_name);
+		break;
+	case SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF:
+		scnprintf(buf, buflen, "The %s BPF file has no BTF section, compile with -g or use pahole -J.",
+			  dso->long_name);
+		break;
 	default:
 		scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
 		break;
@@ -1719,13 +1726,13 @@ static int symbol__disassemble_bpf(struct symbol *sym,
 	char tpath[PATH_MAX];
 	size_t buf_size;
 	int nr_skip = 0;
-	int ret = -1;
 	char *buf;
 	bfd *bfdf;
+	int ret;
 	FILE *s;
 
 	if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
-		return -1;
+		return SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE;
 
 	pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__,
 		  sym->name, sym->start, sym->end - sym->start);
@@ -1738,8 +1745,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
 	assert(bfd_check_format(bfdf, bfd_object));
 
 	s = open_memstream(&buf, &buf_size);
-	if (!s)
+	if (!s) {
+		ret = errno;
 		goto out;
+	}
 	init_disassemble_info(&info, s,
 			      (fprintf_ftype) fprintf);
 
@@ -1748,8 +1757,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
 
 	info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
 						 dso->bpf_prog.id);
-	if (!info_node)
+	if (!info_node) {
+		return SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF;
 		goto out;
+	}
 	info_linear = info_node->info_linear;
 	sub_id = dso->bpf_prog.sub_id;
 
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 116e21f49da6..d76fd0e81f46 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -372,6 +372,8 @@ enum symbol_disassemble_errno {
 	SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
 	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
 	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
+	SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
+	SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
 
 	__SYMBOL_ANNOTATE_ERRNO__END,
 };
-- 
2.21.0


  parent reply	other threads:[~2019-10-01 11:14 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 11:11 [GIT PULL] perf/urgent improvements and fixes Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 01/24] libsubcmd: Make _FORTIFY_SOURCE defines dependent on the feature Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 02/24] perf tests: Avoid raising SEGV using an obvious NULL dereference Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 03/24] perf docs: Allow man page date to be specified Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 04/24] tools headers uapi: Sync drm/i915_drm.h with the kernel sources Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 05/24] tools headers uapi: Sync asm-generic/mman-common.h with the kernel Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 06/24] tools headers uapi: Sync linux/usbdevice_fs.h with the kernel sources Arnaldo Carvalho de Melo
2019-10-01 13:59   ` Alan Stern
2019-10-01 19:23     ` Arnaldo Carvalho de Melo
2019-10-01 11:11 ` [PATCH 07/24] tools headers uapi: Sync linux/fs.h " Arnaldo Carvalho de Melo
2019-10-01 18:45   ` Eric Biggers
2019-10-01 18:57     ` Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 08/24] tools headers kvm: Sync kvm headers " Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 09/24] perf llvm: Don't access out-of-scope array Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 10/24] perf vendor events s390: Add JSON transaction for machine type 8561 Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 11/24] perf vendor events s390: Use s390 machine name instead of " Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 12/24] perf map: Fix overlapped map handling Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 13/24] perf inject jit: Fix JIT_CODE_MOVE filename Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 14/24] perf docs: Correct and clarify jitdump spec Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 15/24] perf script brstackinsn: Fix recovery from LBR/binary mismatch Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 16/24] perf jevents: Fix period for Intel fixed counters Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 17/24] perf tools: Propagate get_cpuid() error Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 18/24] perf evsel: Fall back to global 'perf_env' in perf_evsel__env() Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 19/24] perf annotate: Propagate perf_env__arch() error Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 20/24] perf annotate: Fix the signedness of failure returns Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 21/24] perf annotate: Propagate the symbol__annotate() error return Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 22/24] perf annotate: Fix arch specific ->init() failure errors Arnaldo Carvalho de Melo
2019-10-01 11:12 ` [PATCH 23/24] perf annotate: Return appropriate error code for allocation failures Arnaldo Carvalho de Melo
2019-10-01 11:12 ` Arnaldo Carvalho de Melo [this message]
2019-10-07 13:16 ` [GIT PULL] perf/urgent 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=20191001111216.7208-25-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --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).