Repository navigation
audio: copier_host: free the FPI sync group with its last member - #11585
Shrusti-pk wants to merge 4 commits into
Conversation
add_to_fpi_sync_group() allocates the struct fpi_sync_group that every host gateway copier joining the same group_id shares with mod_alloc_ext(), so the group belongs to the resource pool of the copier that happens to create it. mod_free_all() releases that pool when the module is freed or when its init fails, while delete_from_fpi_sync_group() keeps the group linked in group_list_head as long as another member still references it. Deleting the creating copier while a second member is alive therefore leaves a freed node in the global list. The next host copier init reads it in find_group_by_id() and list_item_append() writes to it, and when the remaining member is deleted it decrements ref_count and runs list_item_del() on the freed block before mod_free() fails to find it. A single playback copier whose init fails after joining the group, for example with a node_id v_index of IPC4_MAX_PIPELINE_REG_SLOTS or more, leaves the same dangling node because the e_conv path does not leave the group before mod_free_all() frees it. Allocate the group from the system user heap with sof_heap_alloc(), as data_blob.c does for memory that is not owned by one module, and free it there when the last member leaves. Leave the group on the copier_host_create() error path. hd->group_id was a uint8_t copy of the 32-bit IPC group id, so delete_from_fpi_sync_group() could release a different group than the one joined; store the full id. Fixes: ca85076 ("audio: copier: Use module API also for allocating non cached memory") Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
|
Can one of the admins verify this patch?
|
PR 11585: test resultsRun date: 2026-12-02 10:12 UTC Tested commit: 79775e921bcfe9fd2a7e56ada0bd08c07671b224 |
|
test this please |
There was a problem hiding this comment.
🟡 Changes recommended
Error paths after successful host creation leave group references unreleased, leaking resources and potentially blocking ID reuse with a different period.
1 open issue
What changed in this PR
Fixes shared FPI synchronization-group lifetime in host copiers so groups survive individual member deletion and are freed by their last member.
Changes:
- Moves group allocation outside individual module resource pools.
- Releases membership on host-creation failure.
- Preserves full 32-bit group IDs.
| File | Description |
|---|---|
src/audio/copier/host_copier.h |
Widens the stored group ID to 32 bits. |
src/audio/copier/copier_host.c |
Uses shared heap ownership and adds host-creation failure cleanup. |
Review effort: Balanced
| group = sof_heap_alloc(sof_sys_user_heap_get(), | ||
| SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, | ||
| sizeof(*group), 0); |
There was a problem hiding this comment.
Right, both of those paths skip host teardown and now that the group is outside the module pool the membership just stays. Fixed in two commits:
copier_init() now calls copier_host_free() before taking the shared error label when mic_privacy_configure() fails, so the gateway and the group reference go away.
module_adapter_new_ext() tracks whether module_init() succeeded and runs module_free() on the err path when it did, before schedule_task_free() and the allocation context release, same order as module_adapter_free(). That covers module_adapter_params() and anything else added after module_init() there, not just the copier.
Re-ran the init/delete model with both failure points added, including re-joining the same group id with a different fpi_update_period_usec afterwards: no stale member and the list ends empty.
kv2019i
left a comment
There was a problem hiding this comment.
Good find! The one copilot finding still needs attention, but looks good otherwise.
module_adapter_new_ext() keeps going after module_init() has succeeded: it calls module_adapter_reset_data() and, on IPC4, module_adapter_params(). If anything there fails the err path only frees the task, scrubs the pipeline back-pointers and releases the module allocation context, so the module's own .free() never runs. That is fine for state that lives in the module allocation context, which is released wholesale, but not for anything the .init() method took ownership of outside it. A host copier joins an FPI sync group in copier_host_create(); the group lives on the system user heap and is released by its last member, so a failed create leaves a member that never leaves, and the id cannot be reused later with a different period. Track whether module_init() succeeded and run module_free() on the err path when it did, before the task is freed and the allocation context goes away, matching the order in module_adapter_free(). Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
copier_init() calls mic_privacy_configure() after copier_host_create() has already set the host gateway up, and its error path jumps to the shared error label, which only frees cd. The host data is reclaimed with the module allocation context, but the FPI sync group the gateway may have joined is not: it lives on the system user heap and is released by its last member, so the failed copier stays a member for good and the group id cannot be reused with a different fpi_update_period_usec. Call copier_host_free() before taking the error path so the gateway, and with it the group membership, is released. Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
The creation and teardown flow only describes module_init() returning OK, so note that the steps after it can fail and that the error path runs the same teardown as comp_free(), and why module_free() has to be part of it. Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
|
@kv2019i the copilot finding is handled now, pushed three commits on top. Two error paths after copier_host_create() succeeds never reached host teardown, so with the group living outside the module pool the failed copier stayed a member and the id could no longer be reused with a different fpi_update_period_usec. copier_init() now releases the gateway when mic_privacy_configure() fails, and module_adapter_new_ext() runs module_free() on its err path when module_init() had succeeded, before the task is freed and the allocation context goes away, which is the same order as module_adapter_free(). The third commit just notes that error path in the module_adapter README, since the flow there only described module_init() returning OK. The ptl critical_failure in the 2026-12-02 run was before your retrigger and I don't see a newer summary yet, so I'm watching for that one. |
|
test this please |
|
ive restarted the CI |
|
The sof-ci FW build that went red on cb69b18 is red on every open PR right now, including ones that only touch topology files and build overlays updated this morning, so it isn't coming from this branch. The github actions builds and ztest are green on that commit, and no new test summary has landed since the retrigger, so the ptl result is still outstanding. |

add_to_fpi_sync_group()allocates thestruct fpi_sync_groupshared by every host copier in a group from the resource pool of whichever copier creates it, somod_free_all()frees it with that copier while the group is still linked ingroup_list_head:delete_from_fpi_sync_group()only unlinks the group whenref_countreaches 0. Init host copier A and host copier B with the sameHDA_SYNC_FPI_UPDATE_GROUPTLV, then delete A: the node is freed but stays in the list. The next host copier init reads it infind_group_by_id()and appends to it, and deleting B writesref_countandlist_item_del()through the freed block beforemod_free()fails because the block was never B's.node_id.v_index >= IPC4_MAX_PIPELINE_REG_SLOTS, or no converter for the format pair) leaves the same dangling node, since thee_convpath does not leave the group beforemod_free_all()runs.hd->group_idis auint8_tcopy of the 32-bit IPC group id, so for ids above 255 delete releases a different group than the one joined, or none.CONFIG_HOST_DMA_STREAM_SYNCHRONIZATIONis on by default on every ACE platform. ca85076 moved the group fromrzalloc()/rfree()to the module API; the group is cold-path state only, the runtime FPI sync inhost-zephyr.creads nothing from it.The group now comes from the system user heap through
sof_heap_alloc(sof_sys_user_heap_get(), ...), the same waydata_blob.callocates memory that is not owned by one module, and the last member frees it there. The create error path leaves the group, andgroup_idkeeps the full id. Checked the init/delete sequence above against a model of the module resource pool semantics: before the fix the next lookup reads the freed node, after it the list ends empty with nothing leaked. I could not run the Zephyr build here, so a CI pass on an ACE board with two synchronized streams is the real check.