Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3537486ybz; Mon, 20 Apr 2020 04:55:17 -0700 (PDT) X-Google-Smtp-Source: APiQypLRgjo4fYlCud29cl7uAachXX+ZUvolkbmdXFiFMypPPUHF5G5aKwxZWBkoTZBPglH/qbmQ X-Received: by 2002:a17:906:2511:: with SMTP id i17mr16295975ejb.165.1587383717261; Mon, 20 Apr 2020 04:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383717; cv=none; d=google.com; s=arc-20160816; b=XkVkvogdzRK5gJ3ycScXUS/qRFecOVrpwfLqeIJa/65WyYYfjgV621HZqJd5GA4LSF 46AFZ7/GR7CWJxWi2qrkeWfZq7JnN/ZxsZ2rSzahAupwLcQbyjDDqum174CsJuX47lEZ jdWQjmhj6hGqaaupsE7TYzlzBF6b6JhAxmFYwpl1AC8c4iNpZVCErUvlCiGmgr88IY9i g//IQzT/0gkkhe9Xp6TEr18Ep5LX+iYGYtZfRpWDc9NCcCNJ1YboBPdU35eu/sOpOAN8 0zdOPSskg900a5lizEidGOG1iP3Crgf3aTyu4ZLCi/7+ERRqVUrMqv7WZBKDBkN2+/dq Y/UA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wNFC7zGZ39LRMHRJEpWNO8Ojw7FEouxXkjj4aL/uENA=; b=iPPfBqzs84yuBD1vXLxUbnW1uziEcnNvkMStL8xKdpEAD1hkB5hcsfTEr9WAwtHEdp NMM9YCjYjuWGFCS74+1HTIovzgTSaTtYHXcLda6SwjhbTYo6JhmylY/frVj8EC58CqlJ wdHGOqos/lTsMbNHMBbxvSNeazm6CPs+AetD6n8/2kqz3m6U6F9aZ8Tfwf5dH3PN6v4k Orq07TrsirJFoV8Hz9A6kcoGuIqTXfp709a2i0eoU3hpPYTWLj98dRazftKiuayL62SD GMunr1n1g6Y6FbSR9JcSSc2msfGm2CK7GfCcHM/KkZlZwzqZHZqKX0gAvxdBsdhQWLVu 63Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j7Vh2sPj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id bi9si387275edb.478.2020.04.20.04.54.54; Mon, 20 Apr 2020 04:55:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j7Vh2sPj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726562AbgDTLxo (ORCPT + 99 others); Mon, 20 Apr 2020 07:53:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:36892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgDTLxn (ORCPT ); Mon, 20 Apr 2020 07:53:43 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (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 63115221F4; Mon, 20 Apr 2020 11:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383622; bh=UX2AIXKQ6r0jvUhx10zLTeHYWqsG+eFORiDSNhAyhQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7Vh2sPjTjKecvhj5pbz+rKFrLu397VtAne2PPgJVG/QkpiMb78lJ5Jmrt7AsFDql +QKgyhI07OjKtkcLlknye3+Tlk64V91s2ORFX4KVQfM1tu7kefOJYGRak0iZUNHr2H eCr4Tdn28r5TbHC2bVBTvOk123BYetcmkZPfOij4= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Song Liu , Alexei Starovoitov , Andrii Nakryiko , =?UTF-8?q?Bj=C3=83=C2=B6rn=20T=C3=83=C2=B6pel?= , Daniel Borkmann , "David S . Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Yonghong Song , Arnaldo Carvalho de Melo Subject: [PATCH 04/60] perf annotate: Add basic support for bpf_image Date: Mon, 20 Apr 2020 08:52:20 -0300 Message-Id: <20200420115316.18781-5-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> 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: Jiri Olsa Add the DSO_BINARY_TYPE__BPF_IMAGE dso binary type to recognize BPF images that carry trampoline or dispatcher. Upcoming patches will add support to read the image data, store it within the BPF feature in perf.data and display it for annotation purposes. Currently we only display following message: # ./perf annotate bpf_trampoline_24456 --stdio Percent | Source code & Disassembly of . for cycles (504 ... --------------------------------------------------------------- ... : to be implemented Signed-off-by: Jiri Olsa Acked-by: Song Liu Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Björn Töpel Cc: Daniel Borkmann Cc: David S. Miller Cc: Jakub Kicinski Cc: Jesper Dangaard Brouer Cc: John Fastabend Cc: Martin KaFai Lau Cc: Yonghong Song Link: https://lore.kernel.org/bpf/20200312195610.346362-16-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 20 ++++++++++++++++++++ tools/perf/util/dso.c | 1 + tools/perf/util/dso.h | 1 + tools/perf/util/machine.c | 11 +++++++++++ tools/perf/util/symbol.c | 1 + 5 files changed, 34 insertions(+) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index f1ea0d61eb5b..9760d58e979a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1821,6 +1821,24 @@ static int symbol__disassemble_bpf(struct symbol *sym __maybe_unused, } #endif // defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT) +static int +symbol__disassemble_bpf_image(struct symbol *sym, + struct annotate_args *args) +{ + struct annotation *notes = symbol__annotation(sym); + struct disasm_line *dl; + + args->offset = -1; + args->line = strdup("to be implemented"); + args->line_nr = 0; + dl = disasm_line__new(args); + if (dl) + annotation_line__add(&dl->al, ¬es->src->source); + + free(args->line); + return 0; +} + /* * Possibly create a new version of line with tabs expanded. Returns the * existing or new line, storage is updated if a new line is allocated. If @@ -1920,6 +1938,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) { return symbol__disassemble_bpf(sym, args); + } else if (dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE) { + return symbol__disassemble_bpf_image(sym, args); } else if (dso__is_kcore(dso)) { kce.kcore_filename = symfs_filename; kce.addr = map__rip_2objdump(map, sym->start); diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 91f21239608b..f338990e0fe6 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -191,6 +191,7 @@ int dso__read_binary_type_filename(const struct dso *dso, case DSO_BINARY_TYPE__GUEST_KALLSYMS: case DSO_BINARY_TYPE__JAVA_JIT: case DSO_BINARY_TYPE__BPF_PROG_INFO: + case DSO_BINARY_TYPE__BPF_IMAGE: case DSO_BINARY_TYPE__NOT_FOUND: ret = -1; break; diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 2db64b79617a..9553a1fd9e8a 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -40,6 +40,7 @@ enum dso_binary_type { DSO_BINARY_TYPE__GUEST_KCORE, DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, DSO_BINARY_TYPE__BPF_PROG_INFO, + DSO_BINARY_TYPE__BPF_IMAGE, DSO_BINARY_TYPE__NOT_FOUND, }; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 06aa4e4db63d..09845eae9c03 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -736,6 +736,12 @@ int machine__process_switch_event(struct machine *machine __maybe_unused, return 0; } +static int is_bpf_image(const char *name) +{ + return strncmp(name, "bpf_trampoline_", sizeof("bpf_trampoline_") - 1) || + strncmp(name, "bpf_dispatcher_", sizeof("bpf_dispatcher_") - 1); +} + static int machine__process_ksymbol_register(struct machine *machine, union perf_event *event, struct perf_sample *sample __maybe_unused) @@ -760,6 +766,11 @@ static int machine__process_ksymbol_register(struct machine *machine, map->end = map->start + event->ksymbol.len; maps__insert(&machine->kmaps, map); dso__set_loaded(dso); + + if (is_bpf_image(event->ksymbol.name)) { + dso->binary_type = DSO_BINARY_TYPE__BPF_IMAGE; + dso__set_long_name(dso, "", false); + } } sym = symbol__new(map->map_ip(map, map->start), diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 26bc6a0096ce..8f4300492dc7 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1544,6 +1544,7 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod, return true; case DSO_BINARY_TYPE__BPF_PROG_INFO: + case DSO_BINARY_TYPE__BPF_IMAGE: case DSO_BINARY_TYPE__NOT_FOUND: default: return false; -- 2.21.1