Skip to content

telemetry: performance_monitor: fix manifest module entry offset - #11482

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:perf-monitor-manifest-offset
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:perf-monitor-manifest-offset

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

enable_performance_counters() reads the wrong memory for every manifest module entry:

  • desc is a const struct sof_man_fw_desc *, so desc + SOF_MAN_MODULE_OFFSET(mod_id) scales the byte offset by sizeof(*desc) (52). Entry 0 is read at desc + 2704 instead of desc + 52, and entry i at desc + 52 * (52 + 116 * i)
  • instance_max_count comes from that memory, so each module either faults or runs up to 65535 ipc4_get_comp_dev() lookups on unrelated IDs, and the real instances never get their perf data reinitialized
  • reached on every IPC4_PERF_MEASUREMENTS_STATE set to STOPPED, STARTED or PAUSED (set_perf_meas_state()), for the base FW manifest and every loaded library
  • the other SOF_MAN_MODULE_OFFSET() users (lib_manager.c, llext_manager.c, helper-kernel.c, base_fw_intel.c) already cast to a byte pointer first

Checked by building the function verbatim against a 3-module manifest laid out as rimage writes it: under ASan the old code is a heap-buffer-overflow READ 2380 bytes past the 400-byte manifest, and the fixed code reads entries at +52/+168/+284 and does the expected 15 lookups. I could not run it on hardware here.

enable_performance_counters() adds SOF_MAN_MODULE_OFFSET(mod_id), a
byte offset, to a const struct sof_man_fw_desc pointer. The pointer
arithmetic scales it by sizeof(struct sof_man_fw_desc), so module entry
0 is read 2704 bytes into the manifest instead of 52, and entry i at
52 * (52 + 116 * i). instance_max_count is then taken from unrelated
memory past the manifest, which can fault or drive up to 65535 bogus
ipc4_get_comp_dev() lookups per module, and the real instances are not
reinitialized.

It runs on every IPC4_PERF_MEASUREMENTS_STATE change to STOPPED,
STARTED or PAUSED, for the base firmware manifest and every loaded
library.

Cast the descriptor to a byte pointer before adding the offset, as the
other SOF_MAN_MODULE_OFFSET() users in lib_manager.c, llext_manager.c
and helper-kernel.c already do.
@sofci

sofci commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@lgirdwood

Copy link
Copy Markdown
Member

test this please

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shrusti-pk pls make sure you add your SOB. You have several patches that are good enough to merge currently but are missing a SOB (and we cant merge without it).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the manifest-addressing and const-qualification changes.

No open issues 🎉

What changed in this PR

Fixes manifest traversal in SOF’s performance monitor so re-enabling measurements reads the intended module entries when reinitializing component performance data.

Changes:

  • Applies module offsets to a byte pointer, avoiding incorrect scaling by the descriptor size.
  • Preserves const qualification when accessing module records.
File Description
src/​kernel/​debug/​telemetry/​performance_monitor.c Corrects manifest module addressing and makes the module pointer const.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants