From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Aditya Gupta <adityag@linux.ibm.com>,
"Steinar H. Gunderson" <sesse@google.com>,
Charlie Jenkins <charlie@rivosinc.com>,
Changbin Du <changbin.du@huawei.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
James Clark <james.clark@linaro.org>,
Kajol Jain <kjain@linux.ibm.com>,
Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
Li Huafei <lihuafei1@huawei.com>,
Dmitry Vyukov <dvyukov@google.com>,
Andi Kleen <ak@linux.intel.com>,
Chaitanya S Prakash <chaitanyas.prakash@arm.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
llvm@lists.linux.dev, Song Liu <song@kernel.org>,
bpf@vger.kernel.org
Subject: [PATCH v3 10/18] perf dso: Support BPF programs in dso__read_symbol
Date: Wed, 22 Jan 2025 09:43:00 -0800 [thread overview]
Message-ID: <20250122174308.350350-11-irogers@google.com> (raw)
In-Reply-To: <20250122174308.350350-1-irogers@google.com>
Set the buffer to the code in the BPF linear info. This enables BPF
JIT code disassembly by LLVM and capstone. Move the disassmble_bpf
calls to disassemble_objdump so that they are only called after
falling back to the objdump option.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/disasm.c | 12 +++---
tools/perf/util/dso.c | 85 +++++++++++++++++++++++++---------------
2 files changed, 60 insertions(+), 37 deletions(-)
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index a9cc588a3006..99b9c21e02b0 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -1500,6 +1500,12 @@ static int symbol__disassemble_objdump(const char *filename, struct symbol *sym,
struct child_process objdump_process;
int err;
+ if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_PROG_INFO)
+ return symbol__disassemble_bpf(sym, args);
+
+ if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_IMAGE)
+ return symbol__disassemble_bpf_image(sym, args);
+
err = asprintf(&command,
"%s %s%s --start-address=0x%016" PRIx64
" --stop-address=0x%016" PRIx64
@@ -1681,11 +1687,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
pr_debug("annotating [%p] %30s : [%p] %30s\n", dso, dso__long_name(dso), sym, sym->name);
- if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_PROG_INFO) {
- return symbol__disassemble_bpf(sym, args);
- } else if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_IMAGE) {
- return symbol__disassemble_bpf_image(sym, args);
- } else if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
+ if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
} else if (dso__is_kcore(dso)) {
kce.addr = map__rip_2objdump(map, sym->start);
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 0285904ed26d..a90799bed230 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1686,48 +1686,69 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
const struct map *map, const struct symbol *sym,
u8 **out_buf, u64 *out_buf_len, bool *is_64bit)
{
- struct nscookie nsc;
u64 start = map__rip_2objdump(map, sym->start);
u64 end = map__rip_2objdump(map, sym->end);
- int fd, count;
- u8 *buf = NULL;
- size_t len;
- struct find_file_offset_data data = {
- .ip = start,
- };
+ const u8 *buf;
+ size_t len = end - start;
*out_buf = NULL;
*out_buf_len = 0;
*is_64bit = false;
- nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
- fd = open(symfs_filename, O_RDONLY);
- nsinfo__mountns_exit(&nsc);
- if (fd < 0)
+ if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_IMAGE) {
+ pr_debug("No BPF image disassembly support\n");
return NULL;
+ } else if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_PROG_INFO) {
+#ifdef HAVE_LIBBPF_SUPPORT
+ struct bpf_prog_info_node *info_node;
+ struct perf_bpil *info_linear;
+
+ *is_64bit = sizeof(void *) == sizeof(u64);
+ info_node = perf_env__find_bpf_prog_info(dso__bpf_prog(dso)->env,
+ dso__bpf_prog(dso)->id);
+ if (!info_node) {
+ errno = SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF;
+ return NULL;
+ }
+ info_linear = info_node->info_linear;
+ buf = (const u8 *)(uintptr_t)(info_linear->info.jited_prog_insns);
+ assert(len <= info_linear->info.jited_prog_len);
+#else
+ pr_debug("No BPF program disassembly support\n");
+ return NULL;
+#endif
+ } else {
+ struct nscookie nsc;
+ int fd;
+ ssize_t count;
+ struct find_file_offset_data data = {
+ .ip = start,
+ };
+ u8 *code_buf = NULL;
- if (file__read_maps(fd, /*exe=*/true, find_file_offset, &data, is_64bit) == 0)
- goto err;
-
- len = end - start;
- buf = malloc(len);
- if (buf == NULL)
- goto err;
-
- count = pread(fd, buf, len, data.offset);
- close(fd);
- fd = -1;
-
- if ((u64)count != len)
- goto err;
+ nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
+ fd = open(symfs_filename, O_RDONLY);
+ nsinfo__mountns_exit(&nsc);
+ if (fd < 0)
+ return NULL;
- *out_buf = buf;
+ if (file__read_maps(fd, /*exe=*/true, find_file_offset, &data, is_64bit) == 0) {
+ close(fd);
+ return NULL;
+ }
+ buf = code_buf = malloc(len);
+ if (buf == NULL) {
+ close(fd);
+ return NULL;
+ }
+ count = pread(fd, code_buf, len, data.offset);
+ close(fd);
+ if ((u64)count != len) {
+ free(code_buf);
+ return NULL;
+ }
+ *out_buf = code_buf;
+ }
*out_buf_len = len;
return buf;
-
-err:
- if (fd >= 0)
- close(fd);
- free(buf);
- return NULL;
}
--
2.48.1.262.g85cc9f2d1e-goog
next prev parent reply other threads:[~2025-01-22 17:43 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 17:42 [PATCH v3 00/18] Support dynamic opening of capstone/llvm remove BUILD_NONDISTRO Ian Rogers
2025-01-22 17:42 ` [PATCH v3 01/18] perf build: Remove libtracefs configuration Ian Rogers
2025-01-22 17:42 ` [PATCH v3 02/18] perf map: Constify objdump offset/address conversion APIs Ian Rogers
2025-01-22 17:42 ` [PATCH v3 03/18] perf capstone: Move capstone functionality into its own file Ian Rogers
2025-01-24 21:58 ` Namhyung Kim
2025-01-25 0:59 ` Ian Rogers
2025-01-28 20:56 ` Namhyung Kim
2025-01-28 22:16 ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 04/18] perf llvm: Move llvm " Ian Rogers
2025-01-24 22:04 ` Namhyung Kim
2025-01-22 17:42 ` [PATCH v3 05/18] perf capstone: Remove open_capstone_handle Ian Rogers
2025-01-22 17:42 ` [PATCH v3 06/18] perf capstone: Support for dlopen-ing libcapstone.so Ian Rogers
2025-01-24 22:22 ` Namhyung Kim
2025-01-25 5:20 ` Ian Rogers
2025-01-28 20:58 ` Namhyung Kim
2025-01-28 22:13 ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 07/18] perf llvm: Support for dlopen-ing libLLVM.so Ian Rogers
2025-01-24 22:54 ` Namhyung Kim
2025-01-25 1:21 ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 08/18] perf llvm: Mangle libperf-llvm.so function names Ian Rogers
2025-01-22 17:42 ` [PATCH v3 09/18] perf dso: Move read_symbol from llvm/capstone to dso Ian Rogers
2025-01-22 17:43 ` Ian Rogers [this message]
2025-03-25 17:44 ` [PATCH v3 10/18] perf dso: Support BPF programs in dso__read_symbol Ian Rogers
2025-01-22 17:43 ` [PATCH v3 11/18] perf llvm: Disassemble cleanup Ian Rogers
2025-01-22 17:43 ` [PATCH v3 12/18] perf dso: Clean up read_symbol error handling Ian Rogers
2025-01-22 17:43 ` [PATCH v3 13/18] perf build: Remove libbfd support Ian Rogers
2025-01-29 0:31 ` Daniel Xu
2025-01-29 1:40 ` Ian Rogers
2025-01-29 16:46 ` Daniel Xu
2025-01-29 19:36 ` Ian Rogers
2025-01-22 17:43 ` [PATCH v3 14/18] perf build: Remove libiberty support Ian Rogers
2025-01-22 17:43 ` [PATCH v3 15/18] perf build: Remove unused defines Ian Rogers
2025-01-22 17:43 ` [PATCH v3 16/18] perf disasm: Remove disasm_bpf Ian Rogers
2025-01-22 17:43 ` [PATCH v3 17/18] perf disasm: Make ins__scnprintf and ins__is_nop static Ian Rogers
2025-01-22 17:43 ` [PATCH v3 18/18] perf srcline: Fallback between addr2line implementations Ian Rogers
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=20250122174308.350350-11-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adityag@linux.ibm.com \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=chaitanyas.prakash@arm.com \
--cc=changbin.du@huawei.com \
--cc=charlie@rivosinc.com \
--cc=dvyukov@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=kan.liang@linux.intel.com \
--cc=kjain@linux.ibm.com \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=sesse@google.com \
--cc=song@kernel.org \
/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