Skip to content

audio: copier_host: free the FPI sync group with its last member - #11585

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:copier-fpi-sync-group-lifetime
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:copier-fpi-sync-group-lifetime

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

add_to_fpi_sync_group() allocates the struct fpi_sync_group shared by every host copier in a group from the resource pool of whichever copier creates it, so mod_free_all() frees it with that copier while the group is still linked in group_list_head:

  • delete_from_fpi_sync_group() only unlinks the group when ref_count reaches 0. Init host copier A and host copier B with the same HDA_SYNC_FPI_UPDATE_GROUP TLV, then delete A: the node is freed but stays in the list. The next host copier init reads it in find_group_by_id() and appends to it, and deleting B writes ref_count and list_item_del() through the freed block before mod_free() fails because the block was never B's.
  • a single playback copier whose init fails after joining (for example node_id.v_index >= IPC4_MAX_PIPELINE_REG_SLOTS, or no converter for the format pair) leaves the same dangling node, since the e_conv path does not leave the group before mod_free_all() runs.
  • hd->group_id is a uint8_t copy 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_SYNCHRONIZATION is on by default on every ACE platform. ca85076 moved the group from rzalloc()/rfree() to the module API; the group is cold-path state only, the runtime FPI sync in host-zephyr.c reads nothing from it.

The group now comes from the system user heap through sof_heap_alloc(sof_sys_user_heap_get(), ...), the same way data_blob.c allocates memory that is not owned by one module, and the last member frees it there. The create error path leaves the group, and group_id keeps 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.

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>
@sofci

sofci commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@intel-sofci

intel-sofci commented Dec 2, 2026 •

Copy link
Copy Markdown

PR 11585: test results

Run date: 2026-12-02 10:12 UTC

Tested commit: 79775e921bcfe9fd2a7e56ada0bd08c07671b224

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood
lgirdwood requested a balanced review from Copilot December 2, 2026 16:23
@lgirdwood

Copy link
Copy Markdown
Member

test this please

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.

🟡 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

Comment on lines +70 to +72
group = sof_heap_alloc(sof_sys_user_heap_get(),
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
sizeof(*group), 0);
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.

5 participants