Skip to content

scripts: reset LLEXT VMA accumulators before each west build#10793

Open
lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/vma-fix
Open

scripts: reset LLEXT VMA accumulators before each west build#10793
lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/vma-fix

Conversation

@lgirdwood
Copy link
Copy Markdown
Member

llext_link_helper.py uses openmod_module_size and module_size as persistent counters to assign pre-linked VMAs to LLEXT ELFs. Running ninja more than once without a pristine build causes these files to accumulate across invocations. The second run doubles the counter values, placing all ELF VMAs outside the valid LLEXT virtual region [CONFIG_LIBRARY_BASE_ADDRESS, +CONFIG_LIBRARY_REGION_SIZE).

When pre_located=true the LLEXT loader uses the ELF sh_addr VMAs directly as physical load addresses. sys_mm_drv_map_region() silently fails for out-of-range addresses, so the module is never registered. The kernel then receives IPC4_MOD_NOT_INITIALIZED (error 104) for every module init IPC.

Reset both accumulator files to 0 before every west build invocation so VMA assignment always starts from CONFIG_LIBRARY_BASE_ADDRESS.

Copilot AI review requested due to automatic review settings May 20, 2026 15:56
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR prevents incorrect pre-linked LLEXT VMAs on incremental rebuilds by resetting the on-disk accumulator counters before each west build, ensuring VMA assignment restarts from CONFIG_LIBRARY_BASE_ADDRESS.

Changes:

  • Reset openmod_module_size and module_size accumulator files to 0 before invoking the build command.
  • Add inline documentation explaining the runtime failure mode prevented by the reset.

Comment thread scripts/xtensa-build-zephyr.py Outdated
Comment on lines +990 to +992
for acc_file in ("openmod_module_size", "module_size"):
acc_path = zephyr_build_dir / acc_file
if acc_path.is_file():
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread scripts/xtensa-build-zephyr.py Outdated
for acc_file in ("openmod_module_size", "module_size"):
acc_path = zephyr_build_dir / acc_file
if acc_path.is_file():
acc_path.write_text("0\n")
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.

why not just delete it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread scripts/xtensa-build-zephyr.py Outdated
# valid LLEXT virtual region and causing sys_mm_drv_map_region() to
# fail silently at runtime (IPC4_MOD_NOT_INITIALIZED error 104).
zephyr_build_dir = pathlib.Path(abs_build_dir) / "zephyr"
for acc_file in ("openmod_module_size", "module_size"):
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.

I don't see "openmod_module_size" anywhere, where does it come from?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

need to check where openmod_module_size comes from

llext_offset_calc.py uses module_size as a persistent counter across
cmake custom-command invocations.  Running ninja more than once without
a pristine build causes the counter to accumulate, placing all pre-linked
LLEXT ELF VMAs outside the valid region [CONFIG_LIBRARY_BASE_ADDRESS,
+CONFIG_LIBRARY_REGION_SIZE).

When pre_located=true the LLEXT loader uses the ELF sh_addr VMAs
directly as physical load addresses.  sys_mm_drv_map_region() silently
fails for out-of-range addresses, so the module is never registered.
The kernel then receives IPC4_MOD_NOT_INITIALIZED (error 104) for every
module init IPC.

Delete module_size before every west build invocation so VMA assignment
always starts from CONFIG_LIBRARY_BASE_ADDRESS.  llext_offset_calc.py
already handles a missing file as size=0 (OSError except clause), so
deletion is the simplest reset.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
Copy link
Copy Markdown
Member Author

need to check where openmod_module_size comes from

looks like an intermediate step during solution search - lets see what copilot thinks of copilot again.

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