[PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs

Hui Su <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.bpf
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.