From: Quentin Monnet <qmo@kernel.org>
To: Eduard Zateev <hackerowskiy@gmail.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] bpftool: fix line info in multi-function CFG dumps
Date: Mon, 26 Oct 2026 10:58:24 +0000 [thread overview]
Message-ID: <88626067-69c0-4487-98b0-f68eb8c5e36c@kernel.org> (raw)
In-Reply-To: <20261024062329.264086-1-hackerowskiy@gmail.com>
2026-10-24 08:23 UTC+0200 ~ Eduard Zateev <hackerowskiy@gmail.com>
> The CFG dumper computes BTF line-info offsets relative to each function, but bpf_prog_linfo__lfind() expects offsets from the start of the whole program. As a result, line annotations in later functions can resolve to source lines from the first function.
>
> Pass the program instruction base to the graph dumper and use the global instruction offset for line-info lookup and display. Keep function-info matching relative to the function as before.
Please wrap your commit description. Also capitalise your title , and
target your patch to the bpf-next tree ("[PATCH bpf-next v2] bpftool:
Fix line info...")
> Add a selftest with a BPF-to-BPF call that checks the second function source line in visual output.
>
> Link: https://github.com/libbpf/bpftool/issues/178
Thanks for picking up this issue. Since you found that page, you must
also have seen the patch I posted there, and on which yours is based, so
some crediting would be appreciated.
> Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>
> ---
> tools/bpf/bpftool/cfg.c | 19 +++++----
> tools/bpf/bpftool/xlated_dumper.c | 10 +++--
> tools/bpf/bpftool/xlated_dumper.h | 3 +-
> .../selftests/bpf/prog_tests/bpftool_cfg.c | 41 +++++++++++++++++++
> .../testing/selftests/bpf/progs/bpftool_cfg.c | 16 ++++++++
> 5 files changed, 75 insertions(+), 14 deletions(-)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/bpftool_cfg.c
> create mode 100644 tools/testing/selftests/bpf/progs/bpftool_cfg.c
>
> diff --git a/tools/bpf/bpftool/cfg.c b/tools/bpf/bpftool/cfg.c
> diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c
> diff --git a/tools/bpf/bpftool/xlated_dumper.h b/tools/bpf/bpftool/xlated_dumper.h
The fix itself looks good to me.
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_cfg.c b/tools/testing/selftests/bpf/prog_tests/bpftool_cfg.c
> new file mode 100644
> index 000000000..7d5b80927
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/bpftool_cfg.c
> @@ -0,0 +1,41 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <bpftool_helpers.h>
> +#include <test_progs.h>
> +#include <linux/bpf.h>
> +#include "bpftool_cfg.skel.h"
> +
> +#define MAX_BPFTOOL_OUTPUT_LEN (64 * 1024)
> +
> +void test_bpftool_cfg(void)
> +{
> + struct bpftool_cfg *skel = NULL;
> + struct bpf_prog_info info = {};
> + __u32 info_len = sizeof(info);
> + char output[MAX_BPFTOOL_OUTPUT_LEN];
> + char cmd[MAX_BPFTOOL_CMD_LEN];
> + const char *expected = "return\\ bpf_ktime_get_ns()\\ ?\\ skb->len\\ :\\ 0;";
How did you test this? I would expect bpftool to print "skb-\>len" and
not "skb->len", so the expected string should never be found?
> + int err;
> +
> + skel = bpftool_cfg__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "bpftool_cfg__open_and_load"))
> + return;
> +
> + err = bpf_obj_get_info_by_fd(bpf_program__fd(skel->progs.bpftool_cfg),
> + &info, &info_len);
> + if (!ASSERT_OK(err, "bpf_obj_get_info_by_fd"))
> + goto cleanup;
> +
> + err = snprintf(cmd, sizeof(cmd), "prog dump xlated id %u visual linum",
> + info.id);
> + if (!ASSERT_GT(err, 0, "format bpftool command"))
> + goto cleanup;
> +
> + err = get_bpftool_command_output(cmd, output, sizeof(output));
> + if (ASSERT_OK(err, "dump program CFG")) {
> + ASSERT_HAS_SUBSTR(output, "cluster_1", "second function in CFG");
Escaping issue aside, I don't think this check would catch the issue in
the first place? The string is present in bpftool's output regardless of
your fix. Maybe check that "return\ helper(skb);" does not appear after
the main block, instead? And please make sure to test it.
pw-bot: cr
> + ASSERT_HAS_SUBSTR(output, expected, "second function line info");
> + }
> +
> +cleanup:
> + bpftool_cfg__destroy(skel);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/bpftool_cfg.c b/tools/testing/selftests/bpf/progs/bpftool_cfg.c
Nit: You're not doing a generic validation of the CFG from bpftool here,
so I think the names for the new test files should be more descriptive
to better indicate what the test it about ("bpftool_cfg_func_offset.c"?)
> new file mode 100644
> index 000000000..db01f20c8
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/bpftool_cfg.c
> @@ -0,0 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +static __noinline int helper(struct __sk_buff *skb)
> +{
> + return bpf_ktime_get_ns() ? skb->len : 0;
> +}
> +
> +SEC("socket")
> +int bpftool_cfg(struct __sk_buff *skb)
> +{
> + return helper(skb);
> +}
> +
> +char _license[] SEC("license") = "GPL";
prev parent reply other threads:[~2026-10-26 10:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 6:23 Eduard Zateev
2026-10-24 7:05 ` bot+bpf-ci
2026-10-26 10:58 ` Quentin Monnet [this message]
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=88626067-69c0-4487-98b0-f68eb8c5e36c@kernel.org \
--to=qmo@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hackerowskiy@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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
all inboxes | Powered by JetHome®