Skip to content

[Userspace LL] module: generic: make resource locking compatible with user-space builds - #11086

Open
kv2019i wants to merge 3 commits into
thesofproject:mainfrom
kv2019i:202608-userll-modadapter-reslocking-fix
Open

[Userspace LL] module: generic: make resource locking compatible with user-space builds#11086
kv2019i wants to merge 3 commits into
thesofproject:mainfrom
kv2019i:202608-userll-modadapter-reslocking-fix

Conversation

@kv2019i

@kv2019i kv2019i commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

A small series to make the locking added in #10960 compatible with user-space LL builds.

For context, this is part of #10558

Copilot AI lite review requested due to automatic review settings August 12, 2026 13:52
@kv2019i
kv2019i requested review from jsarha and lyakh August 12, 2026 13:52
@kv2019i kv2019i changed the title [Userspace LL] module: generic: make resource lockign compatible with user-space builds [Userspace LL] module: generic: make resource locking compatible with user-space builds Aug 12, 2026

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.

Pull request overview

This PR updates the module resource tracking/locking layer to work with Zephyr user-space LL builds by moving the resource lock out of the per-module (user-writable) struct and by making mod_free_all() available as a syscall-compatible API.

Changes:

  • Remove the per-module k_mutex from struct module_resources and use a single shared lock for resource pool bookkeeping.
  • Convert mod_free_all() into a Zephyr syscall-style API (mod_free_all() / z_impl_mod_free_all() / z_vrfy_mod_free_all()), aligning it with the rest of the resource syscall wrappers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/include/sof/audio/module_adapter/module/generic.h Removes per-module lock from module_resources and adds syscall/macro plumbing for mod_free_all().
src/audio/module_adapter/module/generic.c Introduces a shared resource mutex and routes resource operations through it; adds syscall verification + implementation split for mod_free_all().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

* kernel object serialises all pools. Contention is negligible because resource
* bookkeeping only happens at module setup/teardown, not on the processing path.
*/
static K_MUTEX_DEFINE(mod_res_lock);

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.

Fixed in V2 by adding a posix wrapper for K_MUTEX_DEFINE.

module_adapter_free() runs in a user-mode thread in userspace-LL mode and
calls mod_free_all(). Unlike mod_free(), mod_free_all() was a plain function,
so its internal sof_heap_free() calls on the module heap went through the
user-mode syscall verifier, which only permits the LL user heap and K_OOPSes
on the module heap. Convert mod_free_all() to a syscall so the objpool/heap
cleanup runs in supervisor context, matching mod_free().

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Implement a wrapper for this Zephyr interface so it can be used
in generic SOF code.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Replace the per-pool k_mutex embedded in struct module_resources with a
single static K_MUTEX_DEFINE() shared by all module resource pools.

This approach to implement locking works both in kernel and userspace
SOF builds. When userspace is enabled, the resource API is only ever
entered from supervisor context (the z_impl_* syscall bodies), so is it
ok to have the lock only accessible from kernel.

Lock contention is negligible: resource bookkeeping happens at module
setup and teardown, not on the processing path, and the mutex carries
priority inheritance for the rare overlap.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
kv2019i force-pushed the 202608-userll-modadapter-reslocking-fix branch from 922b780 to 6b6af15 Compare August 12, 2026 16:11
@kv2019i

kv2019i commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

V2 pushed:

  • addressing code review comments so far

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jsarha jsarha 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.

Uncached static lock for all module resources on all cores should work always. It would be interesting to collect statistics if any module will ever need to block on this lock.

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.

3 participants