BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	bpf@vger.kernel.org,  ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net, kafai@meta.com,  kernel-team@meta.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v7] selftests/bpf: add BPF program dump in veristat
Date: Fri, 05 Sep 2025 12:00:48 -0700	[thread overview]
Message-ID: <ac6e70c96097c677d5689d86dd2bc0dea603a5d1.camel@gmail.com> (raw)
In-Reply-To: <20250905140835.1416179-1-mykyta.yatsenko5@gmail.com>

On Fri, 2025-09-05 at 15:08 +0100, Mykyta Yatsenko wrote:
> From: Mykyta Yatsenko <yatsenko@meta.com>
> 
> Add the ability to dump BPF program instructions directly from veristat.
> Previously, inspecting a program required separate bpftool invocations:
> one to load and another to dump it, which meant running multiple
> commands.
> During active development, it's common for developers to use veristat
> for testing verification. Integrating instruction dumping into veristat
> reduces the need to switch tools and simplifies the workflow.
> By making this information more readily accessible, this change aims
> to streamline the BPF development cycle and improve usability for
> developers.
> This implementation leverages bpftool, by running it directly via popen
> to avoid any code duplication and keep veristat simple.
> 
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
> ---

Lgtm with a small nit.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

> @@ -1554,6 +1573,35 @@ static int parse_rvalue(const char *val, struct rvalue *rvalue)
>  	return 0;
>  }
>  
> +static void dump(__u32 prog_id, enum dump_mode mode, const char *file_name, const char *prog_name)
> +{
> +	char command[64], buf[4096];
> +	FILE *fp;
> +	int status;
> +
> +	status = system("which bpftool > /dev/null 2>&1");

Fun fact: if you do a minimal Fedora install (dnf group install core)
          "which" is not installed by default o.O
          (not suggesting any changes).

> +	if (status != 0) {
> +		fprintf(stderr, "bpftool is not available, can't print program dump\n");
> +		return;
> +	}

[...]

> @@ -1630,8 +1678,13 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
>  
>  	memset(&info, 0, info_len);
>  	fd = bpf_program__fd(prog);
> -	if (fd > 0 && bpf_prog_get_info_by_fd(fd, &info, &info_len) == 0)
> +	if (fd > 0 && bpf_prog_get_info_by_fd(fd, &info, &info_len) == 0) {
>  		stats->stats[JITED_SIZE] = info.jited_prog_len;
> +		if (env.dump_mode & DUMP_JITED)
> +			dump(info.id, DUMP_JITED, base_filename, prog_name);
> +		if (env.dump_mode & DUMP_XLATED)
> +			dump(info.id, DUMP_XLATED, base_filename, prog_name);

Nit: if you do `./veristat --dump=jited iters.bpf.o` there would be an empty line
     after dump for each program, but not for --dump=xlated.

> +	}
>  
>  	parse_verif_log(buf, buf_sz, stats);
>  

  reply	other threads:[~2025-09-05 19:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 14:08 [PATCH bpf-next v7] selftests/bpf: add BPF program dump in veristat Mykyta Yatsenko
2025-09-05 19:00 ` Eduard Zingerman [this message]
2025-09-05 19:14   ` Andrii Nakryiko
2025-09-05 19:19     ` Eduard Zingerman
2025-09-05 21:38       ` Andrii Nakryiko
2025-09-05 21:43         ` Eduard Zingerman
2025-09-05 21:51           ` Andrii Nakryiko
2025-09-05 22:00             ` Eduard Zingerman

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=ac6e70c96097c677d5689d86dd2bc0dea603a5d1.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@meta.com \
    --cc=kernel-team@meta.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=yatsenko@meta.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