Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4478381ybx; Mon, 4 Nov 2019 14:06:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzBN8Kk34rYp8C4/04H/7lUe0Xng9nt+Su71wwZiwC+31o9ljClxlPtn34YaldJQ6TqHXJC X-Received: by 2002:a17:906:f154:: with SMTP id gw20mr65271ejb.279.1572905167962; Mon, 04 Nov 2019 14:06:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905167; cv=none; d=google.com; s=arc-20160816; b=KS8VGPBdX0LrG9O4J1qXAAEt82XsPr+IXm1+XPbFzPR9o0596dQ8qvFIcPisUQfpAW +S2AntzKL8fwuDG1xMcBELKkfppyWPVpSrNCfJ68QliQ/9vsswiPN5Gt7RzKMw+7A6B0 q9HqfPgpe+hDtTP7EHkHzThOBbEYpvaIeAe7OQ8WkQlm4hvnoVuaWxy+CcZEFQCZ9XSZ Va/QYk7wlv5WsAyXLpYuNGWcYL2VWQm33s7V2KJipUikjQCPlPo7exwMh2mwYims9IVx mq6hzguIrWe2c+N+HlputIY6PHQAw0m2tqdHEzgds8166q1oQn/ye/EkT7Rh7+8QbZuD RUYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ayBUVjrRieLLVc4ot4H/hi2Uy7+hpxnnEDmuM/0IgZc=; b=dxyZhWLTkXaN81pz/XUxs5UPoVA3G1zFKKhfJdQtC3teXdiwshhlW2xSWlLDqB6mCZ qShwIPkYTNnCBMQpVxdbVLHxI8zXaV26QgvowEqvkR0ASEW1uwKG3VTT1ES/V433iysw Zrh+zOIz6U086vHf19sRRaN/SRZb/WB/sLsEh50QwfyzI2gCjy3UsnQ9AfwpnWux9L7O QNI0ZNLcBsGHGyZQ9LW2UzmdzB367aFf1Hf3Ve9jsFZvW1XoS+yPhcanLwarRTiP/4aq QrArRlM41vUSm+EtmMG8x+h8e2yelIMwq3UBb7qtLhSn+TRzdN/Gx1/CFclXUY2uy0R+ mcXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AbonSPmI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a25si11984780ejy.285.2019.11.04.14.05.44; Mon, 04 Nov 2019 14:06:07 -0800 (PST) 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=AbonSPmI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387678AbfKDWEc (ORCPT + 99 others); Mon, 4 Nov 2019 17:04:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:35256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389683AbfKDWEb (ORCPT ); Mon, 4 Nov 2019 17:04:31 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 CD1DF214D8; Mon, 4 Nov 2019 22:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905070; bh=oVOeKJXMi/4L8ddaH2Ou/ffyVHk8XoU2AZ/+BO6rhXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AbonSPmIrERasShx0EE7Cebx9QMLEVTpa3c2XuaGzOPWTxLiho4lA8koNswGZfK/d ZZqZQ6ONTVCHV2h4E07P8b3iCsi0vI4Jiw80Pg9tKtrUshU/dcWmhd1vTebdaGBtGQ EK1Iv484fdfOXwma9+tlucwd6SCmuGjv9Ekppz58= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell King - ARM Linux admin , Song Liu , Alexei Starovoitov , Daniel Borkmann , Adrian Hunter , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Will Deacon , Arnaldo Carvalho de Melo , Sasha Levin , Peter Zijlstra Subject: [PATCH 5.3 019/163] perf annotate: Dont return -1 for error when doing BPF disassembly Date: Mon, 4 Nov 2019 22:43:29 +0100 Message-Id: <20191104212141.810505019@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo [ Upstream commit 11aad897f6d1a28eae3b7e5b293647c522d65819 ] 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 Cc: Song Liu Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra , Cc: Will Deacon Link: https://lkml.kernel.org/n/tip-usevw9r2gcipfcrbpaueurw0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 ab7851ec0ce53..fb8756026a805 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1631,6 +1631,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; @@ -1713,13 +1720,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); @@ -1732,8 +1739,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); @@ -1742,8 +1751,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 a1191995fe77e..2004e2cf0211b 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.20.1