BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <aspsk@isovalent.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jiri Olsa <jolsa@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Stanislav Fomichev <sdf@google.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Quentin Monnet <quentin@isovalent.com>,
	bpf@vger.kernel.org
Cc: Anton Protopopov <aspsk@isovalent.com>
Subject: [PATCH v1 bpf-next 5/9] bpftool: dump new fields of bpf prog info
Date: Fri,  2 Feb 2024 16:28:09 +0000	[thread overview]
Message-ID: <20240202162813.4184616-6-aspsk@isovalent.com> (raw)
In-Reply-To: <20240202162813.4184616-1-aspsk@isovalent.com>

When dumping prog info in JSON format add two new fields: "orig_insn"
and "jit". The former field maps the xlated instruction to the original
instruction (which was loaded via the bpf(2) syscall). The latter maps
the xlated instruction to the jitted instruction; as jited instructions
lengths may vary both the offset and length are specified.

Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
---
 tools/bpf/bpftool/prog.c          | 14 ++++++++++++++
 tools/bpf/bpftool/xlated_dumper.c | 18 ++++++++++++++++++
 tools/bpf/bpftool/xlated_dumper.h |  2 ++
 3 files changed, 34 insertions(+)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 9cb42a3366c0..d3fd7d699574 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -119,6 +119,12 @@ static int prep_prog_info(struct bpf_prog_info *const info, enum dump_mode mode,
 	holder.jited_line_info_rec_size = info->jited_line_info_rec_size;
 	needed += info->nr_jited_line_info * info->jited_line_info_rec_size;
 
+	holder.orig_idx_len = info->orig_idx_len;
+	needed += info->orig_idx_len;
+
+	holder.xlated_to_jit_len = info->xlated_to_jit_len;
+	needed += info->xlated_to_jit_len;
+
 	if (needed > *info_data_sz) {
 		ptr = realloc(*info_data, needed);
 		if (!ptr)
@@ -152,6 +158,12 @@ static int prep_prog_info(struct bpf_prog_info *const info, enum dump_mode mode,
 	holder.jited_line_info = ptr_to_u64(ptr);
 	ptr += holder.nr_jited_line_info * holder.jited_line_info_rec_size;
 
+	holder.orig_idx = ptr_to_u64(ptr);
+	ptr += holder.orig_idx_len;
+
+	holder.xlated_to_jit = ptr_to_u64(ptr);
+	ptr += holder.xlated_to_jit_len;
+
 	*info = holder;
 	return 0;
 }
@@ -852,6 +864,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
 		dd.func_info = func_info;
 		dd.finfo_rec_size = info->func_info_rec_size;
 		dd.prog_linfo = prog_linfo;
+		dd.orig_idx = u64_to_ptr(info->orig_idx);
+		dd.xlated_to_jit = u64_to_ptr(info->xlated_to_jit);
 
 		if (json_output)
 			dump_xlated_json(&dd, buf, member_len, opcodes, linum);
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c
index 567f56dfd9f1..fcc1c4a96178 100644
--- a/tools/bpf/bpftool/xlated_dumper.c
+++ b/tools/bpf/bpftool/xlated_dumper.c
@@ -270,6 +270,24 @@ void dump_xlated_json(struct dump_data *dd, void *buf, unsigned int len,
 		jsonw_name(json_wtr, "disasm");
 		print_bpf_insn(&cbs, insn + i, true);
 
+		if (dd->orig_idx) {
+			jsonw_name(json_wtr, "orig_insn");
+			jsonw_printf(json_wtr, "\"0x%x\"", dd->orig_idx[i]);
+		}
+
+		if (dd->xlated_to_jit) {
+			jsonw_name(json_wtr, "jit");
+			jsonw_start_object(json_wtr);
+
+			jsonw_name(json_wtr, "off");
+			jsonw_printf(json_wtr, "\"0x%x\"", dd->xlated_to_jit[i].off);
+
+			jsonw_name(json_wtr, "len");
+			jsonw_printf(json_wtr, "\"%d\"", dd->xlated_to_jit[i].len);
+
+			jsonw_end_object(json_wtr);
+		}
+
 		if (opcodes) {
 			jsonw_name(json_wtr, "opcodes");
 			jsonw_start_object(json_wtr);
diff --git a/tools/bpf/bpftool/xlated_dumper.h b/tools/bpf/bpftool/xlated_dumper.h
index db3ba0671501..078430fada17 100644
--- a/tools/bpf/bpftool/xlated_dumper.h
+++ b/tools/bpf/bpftool/xlated_dumper.h
@@ -26,6 +26,8 @@ struct dump_data {
 	__u32 finfo_rec_size;
 	const struct bpf_prog_linfo *prog_linfo;
 	char scratch_buff[SYM_MAX_NAME + 8];
+	unsigned int *orig_idx;
+	struct bpf_xlated_to_jit *xlated_to_jit;
 };
 
 void kernel_syms_load(struct dump_data *dd);
-- 
2.34.1


  parent reply	other threads:[~2024-02-02 16:34 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 16:28 [PATCH v1 bpf-next 0/9] BPF static branches Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 1/9] bpf: fix potential error return Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 2/9] bpf: keep track of and expose xlated insn offsets Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 3/9] bpf: expose how xlated insns map to jitted insns Anton Protopopov
2024-02-06  1:09   ` Alexei Starovoitov
2024-02-06 10:02     ` Anton Protopopov
2024-02-07  2:26       ` Alexei Starovoitov
2024-02-08 11:05         ` Anton Protopopov
2024-02-15  6:48           ` Alexei Starovoitov
2024-02-16 13:57             ` Anton Protopopov
2024-02-21  1:09               ` Alexei Starovoitov
2024-03-06 10:44                 ` Anton Protopopov
2024-03-14  1:56                   ` Alexei Starovoitov
2024-03-14  9:03                     ` Anton Protopopov
2024-03-14 17:07                       ` Alexei Starovoitov
2024-03-14 20:06                         ` Andrii Nakryiko
2024-03-14 21:41                           ` Alexei Starovoitov
2024-03-15 13:11                             ` Anton Protopopov
2024-03-15 16:32                             ` Andrii Nakryiko
2024-03-15 17:22                               ` Alexei Starovoitov
2024-03-15 17:29                                 ` Andrii Nakryiko
2024-03-28 16:37                                   ` Anton Protopopov
2024-03-29 22:44                                     ` Andrii Nakryiko
2024-04-01  9:47                                       ` Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 4/9] selftests/bpf: Add tests for instructions mappings Anton Protopopov
2024-02-02 16:28 ` Anton Protopopov [this message]
2024-02-02 16:28 ` [PATCH v1 bpf-next 6/9] bpf: add support for an extended JA instruction Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 7/9] bpf: Add kernel/bpftool asm support for new instructions Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 8/9] bpf: add BPF_STATIC_BRANCH_UPDATE syscall Anton Protopopov
2024-02-02 16:28 ` [PATCH v1 bpf-next 9/9] selftests/bpf: Add tests for new ja* instructions Anton Protopopov
2024-02-02 22:39 ` [PATCH v1 bpf-next 0/9] BPF static branches Andrii Nakryiko
2024-02-04 16:05   ` Anton Protopopov

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=20240202162813.4184616-6-aspsk@isovalent.com \
    --to=aspsk@isovalent.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=yonghong.song@linux.dev \
    /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