Repository navigation
telemetry: performance_monitor: bound extended perf data reply - #11477
Shrusti-pk wants to merge 2 commits into
Conversation
|
Can one of the admins verify this patch?
|
|
test this please |
There was a problem hiding this comment.
🟡 Changes recommended
Vendor-config GETs can still overrun the buffer, and capped reports silently omit records without a way to retrieve them.
2 open issues
What changed in this PR
Adds size-aware generation of IPC4 extended performance telemetry replies to prevent oversized reports from overflowing the reply buffer.
Changes:
- Validate destination capacity and cap the number of core and component records written.
- Pass the IPC message-size limit from BaseFW and update the API declaration, disabled stub, and documentation.
| File | Description |
|---|---|
src/kernel/debug/telemetry/performance_monitor.c |
Adds capacity validation and limits emitted performance records. |
src/kernel/audio/base_fw.c |
Supplies the IPC message-size limit to the telemetry function. |
src/include/sof/debug/telemetry/performance_monitor.h |
Updates the function signature, stub, and buffer-size documentation. |
Review effort: Balanced
| struct extended_global_perf_data *perf_data = (struct extended_global_perf_data *)data; | ||
|
|
||
| ret = get_extended_performance_data(perf_data); | ||
| ret = get_extended_performance_data(perf_data, SOF_IPC_MSG_MAX_SIZE); |
There was a problem hiding this comment.
Right, through a vendor config get the data pointer sits after the earlier TLV replies, so the full comp_data size was the wrong bound there. The getter now takes its size from the in/out data_off_size, which is the host max length on a direct GET (what Linux sends) and max_length on the vendor path, capped at SOF_IPC_MSG_MAX_SIZE. The vendor path itself was also 8 bytes short: it bounded produced_data + max_length against the DSPBOX but writes the sof_tlv header in front of the value, so a getter honouring max_length could still run past the box. The first commit counts the header there and clamps the first-block max_length the same way.
| if (slots_count > max_slots) { | ||
| tr_warn(&ipc_tr, "%zu perf items do not fit, reporting %zu", slots_count, | ||
| max_slots); | ||
| slots_count = max_slots; |
There was a problem hiding this comment.
Agreed, a short report with a success code is worse than no report. Dropped the cap: the getter now counts the items up front and returns -ENOBUFS without writing anything when they don't all fit, which base_fw reports as IPC4_OUT_OF_MEMORY ("not enough space in the IPC reply buffer"). Reports that fit are unchanged. Multi-block continuation for this param would be the way to fetch the full set, but that's a protocol addition rather than a bounds fix, so I've left it out here.
|
@Shrusti-pk can you respond/respin to teh review comments. Thanks ! |
ipc4_get_vendor_config_module_instance() checks that produced_data plus the host max_length fits in MAILBOX_DSPBOX_SIZE, but the sof_tlv header is written at produced_data and the getter's output starts after it. A getter that honours max_length can therefore end 8 bytes past the DSPBOX, and the header write itself goes past it when produced_data is within 8 bytes of the end. For the first block of a multi-block get max_length is passed on unbounded while the output also starts after the header. Count the header in the multi-TLV bound and clamp the first block max_length to what is left after the header, so the in/out size a getter sees is the room it really has. Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
get_extended_performance_data() writes one 48-byte ext_perf_data_item for every enabled core and every occupied performance slot, and never looks at the size of the buffer it writes to. The IPC4 BaseFW LARGE_CONFIG_GET for IPC4_EXTENDED_GLOBAL_PERF_DATA hands it ipc->comp_data, a SOF_IPC_MSG_MAX_SIZE (4096 byte) heap block, which holds 85 items after the count word. A slot is taken for every component the host creates, and while measurements are started it stays taken after the component is freed. CONFIG_SOF_TELEMETRY_MAX_COMP_ENTRIES defaults to 88 (170 without SOF_TELEMETRY_MODULE_RESOURCES), so 85 components on one core are enough for the report to run past the end of comp_data: up to 372 bytes with 5 cores and 88 slots, about 4 KiB with 170 slots. The reply size check in ipc4_get_large_config_module_instance() runs only after the getter has written. Through a VENDOR_CONFIG_PARAM get the same getter is reached with data pointing after earlier TLV replies inside comp_data, so the whole buffer size is not a safe bound there. Pass the buffer size to get_extended_performance_data() and refuse the request with -ENOBUFS, reported as IPC4_OUT_OF_MEMORY, when the items do not all fit, instead of returning a report the host cannot tell apart from a complete one. The size is the in/out data_off_size, the host max reply length that the vendor config path narrows to the room left after its TLV header, capped at SOF_IPC_MSG_MAX_SIZE. Reports that fit are unchanged. The 16-byte global and I/O perf reports cannot exceed the buffer with the configured slot counts. Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
e033e3b to
91e7dff
Compare
|
Respun. The getter now refuses a report that doesn't fit (IPC4_OUT_OF_MEMORY) instead of truncating it, takes its bound from the in/out data_off_size so the vendor config get path is covered too, and a first commit makes that path leave room for its own TLV header. Both review threads are answered inline. |
kv2019i
left a comment
There was a problem hiding this comment.
Needs a rebase, otherwise looks good.


get_extended_performance_data() fills the IPC4_EXTENDED_GLOBAL_PERF_DATA reply without knowing the size of the buffer it writes to:
The fix passes the buffer size down and refuses the request with -ENOBUFS (IPC4_OUT_OF_MEMORY, "not enough space in the IPC reply buffer") when the items do not all fit, rather than returning a report the host cannot tell apart from a complete one. The size comes from the in/out data_off_size, the host max reply length (what Linux sends on a GET and what the vendor config path passes as max_length), capped at SOF_IPC_MSG_MAX_SIZE. Reports that fit are byte-identical.
The first commit makes the vendor config get path account for its own TLV header: the DSPBOX bound checked produced_data + max_length but the header is written in front of the value, so a getter honouring max_length could still end 8 bytes past the box, and the first block of a multi-block get passed max_length on unbounded.
The global and I/O reports use 16-byte items and fit. I could not build the Zephyr image locally, so the change is compile- and run-tested through the standalone ASan harness.