mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs
@ 2026-09-18 10:20 Hui Su
  2026-09-18 10:20 ` [PATCH bpf v2 1/2] bpftool: Fix CPU IDs in per-CPU map output Hui Su
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Hui Su @ 2026-09-18 10:20 UTC (permalink / raw)
  To: qmo
  Cc: bpf, linux-kernel, ast, daniel, andrii, eddyz87, memxor,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	davem, kuba, horms, Hui Su

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-18 11:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-18 10:20 [PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs Hui Su
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-18 11:26 ` [PATCH bpf v2 0/2] bpftool: Fix sparse CPU IDs Quentin Monnet

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®