From: Hui Su <sh_def@163.com>
To: qmo@kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
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,
davem@davemloft.net, kuba@kernel.org, horms@kernel.org,
Hui Su <sh_def@163.com>
Subject: [PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs
Date: Fri, 18 Sep 2026 19:20:50 +0900 [thread overview]
Message-ID: <20260918102052.1247819-1-sh_def@163.com> (raw)
bpftool currently assumes that possible CPU IDs are dense. This is not true
when the possible CPU mask itself is sparse, such as 0,2-3. In that case,
per-CPU map output labels and prog profile event-array keys can refer to the
wrong logical CPUs.
The first patch keeps dense per-CPU buffer slots separate from logical CPU
IDs when printing map values, and propagates errors from the shared output
path to its callers.
The second patch applies the same distinction to prog profile: userspace
keeps a compact CPU count for result buffers, while BPF event-array keys use
the logical CPU ID and the logical ID span.
Changes in v2:
- Add explicit bpftool errors for possible-CPU mask parsing and allocation
failures.
- Rename the helper result variable to reflect that successful returns are
CPU counts, and remove the duplicate CPU-count consistency check.
- Use a dedicated `cpu_cnt` in `map_dump()` instead of overloading `err`.
- Propagate BTF/output errors from `print_key_value()` through both callers.
- Remove the unused BPF-side `num_cpu` rodata and use the userspace
`profile_cpu_cnt` for compact per-CPU buffers.
- Reset all profile CPU state on cleanup paths.
Testing:
- Built the final bpftool tree successfully.
- Booted an ARM64 QEMU guest from a DTS-built virt DTB with possible CPUs
0,2-3.
- Verified plain/BTF and JSON per-CPU map output reports CPUs 0,2,3 and
omits CPU 1.
- Ran `prog profile` with cycles and instructions; the profiler skeleton
reached perf-event setup. QEMU did not provide a usable instructions PMU
event, so no hardware profile counts are claimed.
- Confirmed the final v2 tree is code-identical to the runtime-tested tree;
only commit metadata changed afterward.
Hui Su (2):
bpftool: Fix CPU IDs in per-CPU map output
bpftool: Fix sparse CPU IDs in prog profile
tools/bpf/bpftool/common.c | 40 ++++++++++++
tools/bpf/bpftool/main.h | 1 +
tools/bpf/bpftool/map.c | 76 ++++++++++++++++-------
tools/bpf/bpftool/prog.c | 51 ++++++++++-----
tools/bpf/bpftool/skeleton/profiler.bpf.c | 8 +--
5 files changed, 131 insertions(+), 45 deletions(-)
base-commit: 238650ef6c7c7cca08e032527329424c9fbd70e5
--
2.55.0
next reply other threads:[~2026-09-18 10:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 10:20 Hui Su [this message]
2026-09-18 10:20 ` [PATCH bpf v2 1/2] bpftool: Fix CPU IDs in per-CPU map output Hui Su
2026-09-18 11:38 ` bot+bpf-ci
2026-09-18 10:20 ` [PATCH bpf v2 2/2] bpftool: Fix sparse CPU IDs in prog profile Hui Su
2026-09-18 11:38 ` bot+bpf-ci
2026-09-21 21:59 ` Andrii Nakryiko
2026-09-22 3:15 ` Hui Su
2026-09-18 11:26 ` [PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs Quentin Monnet
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=20260918102052.1247819-1-sh_def@163.com \
--to=sh_def@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@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®