Skip to content

llext: userspace: clear cold segment descriptors when sections are ab… - #11159

Open
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202609-fix-rm-mod-domain-error
Open

llext: userspace: clear cold segment descriptors when sections are ab…#11159
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202609-fix-rm-mod-domain-error

Conversation

@kv2019i

@kv2019i kv2019i commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

…sent

llext_manager_rm_mod_domain() removes the .cold and .coldrodata memory partitions of a module from its domain if the corresponding mctx->segment[] descriptor has a non-zero address. Those descriptors are only ever populated by llext_manager_add_mod_domain() when the module actually contains a .cold / .coldrodata section.

The module context array is allocated with rmalloc() (non-zeroing) and llext_manager_mod_init() initialises every field except the segment[] array. The LIB_MANAGER_TEXT/RODATA/DATA/BSS descriptors are filled in during linking, but LIB_MANAGER_COLD / LIB_MANAGER_COLDRODATA are left holding uninitialised heap data for any module that has no such section.

As a result, when such a module is freed, rm_mod_domain() sees a garbage non-zero address and tries to remove a partition that was never added:

os.k_mem_domain_remove_partition: no matching partition found
lib_manager.llext_manager_rm_mod_domain: failed to remove
.coldrodata memory partition: -2

Reproduced at end-of-stream of a DMIC capture (arecord -Dhw:0,4), whose EQIIR / TDFB / DRC modules carry no .coldrodata section.

Make add_mod_domain() the sole owner of these descriptors: explicitly zero them when the section is absent, so rm_mod_domain() only ever removes partitions that were really added.

…sent

llext_manager_rm_mod_domain() removes the .cold and .coldrodata memory
partitions of a module from its domain if the corresponding
mctx->segment[] descriptor has a non-zero address. Those descriptors are
only ever populated by llext_manager_add_mod_domain() when the module
actually contains a .cold / .coldrodata section.

The module context array is allocated with rmalloc() (non-zeroing) and
llext_manager_mod_init() initialises every field except the segment[]
array. The LIB_MANAGER_TEXT/RODATA/DATA/BSS descriptors are filled in
during linking, but LIB_MANAGER_COLD / LIB_MANAGER_COLDRODATA are left
holding uninitialised heap data for any module that has no such section.

As a result, when such a module is freed, rm_mod_domain() sees a garbage
non-zero address and tries to remove a partition that was never added:

  <err> os.k_mem_domain_remove_partition: no matching partition found
  <err> lib_manager.llext_manager_rm_mod_domain: failed to remove
        .coldrodata memory partition: -2

Reproduced at end-of-stream of a DMIC capture (arecord -Dhw:0,4), whose
EQIIR / TDFB / DRC modules carry no .coldrodata section.

Make add_mod_domain() the sole owner of these descriptors: explicitly
zero them when the section is absent, so rm_mod_domain() only ever
removes partitions that were really added.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 13:02
@kv2019i
kv2019i requested review from jsarha and lyakh September 2, 2026 13:02

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.

🟢 Approval recommended

The change is narrowly scoped to correctly initializing two segment descriptors and aligns with the teardown logic’s “remove only if addr is non-zero” contract.

Pull request overview

This PR fixes a userspace memory-domain teardown bug in the LLEXT library manager by ensuring .cold / .coldrodata segment descriptors are deterministically cleared when those sections are absent, preventing llext_manager_rm_mod_domain() from attempting to remove partitions that were never added.

Changes:

  • Explicitly zero mctx->segment[LIB_MANAGER_COLD] when the module has no .cold section.
  • Explicitly zero mctx->segment[LIB_MANAGER_COLDRODATA] when the module has no .coldrodata section.
File summaries
File Description
src/library_manager/llext_manager.c Clears .cold/.coldrodata segment descriptors when sections are absent to avoid erroneous partition removals during domain teardown.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

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.

2 participants