Skip to content

ipc: ipc-helper: use list_mutex to guard buffer list in userspace LL#10762

Draft
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202605-ipchelper-use-mutex
Draft

ipc: ipc-helper: use list_mutex to guard buffer list in userspace LL#10762
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202605-ipchelper-use-mutex

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented May 11, 2026

In user-space LL builds (CONFIG_SOF_USERSPACE_LL), irq_local_disable() is a privileged operation. In ipc_comp_free(), use sys_mutex_lock/unlock on the per-component list_mutex to protect buffer list iteration instead.

This follows the same locking pattern as PPL_LOCK/PPL_UNLOCK used in pipeline_disconnect().

In user-space LL builds (CONFIG_SOF_USERSPACE_LL), irq_local_disable()
is a privileged operation. In ipc_comp_free(), use sys_mutex_lock/unlock
on the per-component list_mutex to protect buffer list iteration instead.

This follows the same locking pattern as PPL_LOCK/PPL_UNLOCK used in
pipeline_disconnect().

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI review requested due to automatic review settings May 11, 2026 11:34
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 11, 2026

For context, part of #10558

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ipc_comp_free() to avoid using irq_local_disable() in user-space LL builds (CONFIG_SOF_USERSPACE_LL), where disabling IRQs is a privileged operation, by guarding component buffer-list iteration with the per-component list_mutex instead.

Changes:

  • Add a CONFIG_SOF_USERSPACE_LL conditional path that locks/unlocks icd->cd->list_mutex around producer/consumer buffer list iteration in ipc_comp_free().
  • Keep the existing irq_local_disable()/irq_local_enable() path for non-user-space builds.

Comment thread src/ipc/ipc-helper.c
Comment on lines +341 to +345
#ifdef CONFIG_SOF_USERSPACE_LL
sys_mutex_lock(&icd->cd->list_mutex, K_FOREVER);
#else
irq_local_disable(flags);
#endif
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.

I wonder if we can just replace irq_local_disable() regardless of user or not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kv2019i how will buffer walking during actual pipeline processing in

err = pipeline_for_each_comp(current, ctx, dir);
be protected after this change? Since we currently don't run cross-core in our tests (AFAIK), locking interrupts protected us against racing with the scheduler, so what will protect the scheduler after this change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, this is an oversight. The LL thread priority will protect once LL walk has started, but indeed this does not protect against the case where LL tick happens in middle of ipc_comp_free(). Let me work on improving this.

In principle @lgirdwood we could apply this for all builds, but this does increase regression risk and above case is a good example.

Comment thread src/ipc/ipc-helper.c
Comment on lines +341 to +343
#ifdef CONFIG_SOF_USERSPACE_LL
sys_mutex_lock(&icd->cd->list_mutex, K_FOREVER);
#else
Copy link
Copy Markdown
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

I'm good, but just wondered if we should just go full change here and have every config do the same. Not sure if you have already tried.

@softwarecki softwarecki self-requested a review May 12, 2026 14:50
@kv2019i kv2019i marked this pull request as draft May 12, 2026 15:31
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 12, 2026

Back to draft. This requires more work. I have one version working, but locking at component level is too expensive, so need to figure out a different approach to this.

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