Skip to content

userspace: share read-only fast_get copies of LL modules in a kernel-managed area - #11531

Open
kv2019i wants to merge 5 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-fg
Open

kv2019i wants to merge 5 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-fg

Conversation

@kv2019i

@kv2019i kv2019i commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

With CONFIG_SOF_USERSPACE_LL, the fast_get() state is kernel memory, so since the LL user heap allocator moved to user mode, LL modules have made a private copy of their fast_get data, such as SRC coefficients, in their own memory. Every instance makes its own copy, and LL threads can write it. This series gives LL modules shared read-only copies again, managed by the kernel.

  • fast_get area: a new part of the LL memory region, CONFIG_SOF_ZEPHYR_LL_FG_AR_SIZE, between the kernel RO and RW areas. It is 32 kB by default when fast_get is enabled and the memory has mirrored cached and uncached aliases, and is taken from the LL user heap. The allocator is a bitmap of 256-byte blocks in kernel memory. Only the cached alias is mapped into the LL memory domain, read-only. Kernel code writes the copies through the uncached alias, which also works in a system call from an LL thread.
  • fast_get_ll() / fast_put_ll(): new system calls for the LL and IPC user threads, which share one copy between all users of the same data. The data must be readable by the caller. The entries stay in kernel memory and are marked as LL copies. fast_get() and fast_put() never use those entries, and the new calls use no others, so a user thread cannot make the kernel free a copy with the wrong allocator. Every get invalidates the cached alias on the calling core, because the core may still hold lines of an earlier copy at the same address.
  • Module resources: in user mode, mod_fast_get() for an LL module gets its copy with fast_get_ll(), and the resource is released with fast_put_ll(). The user-mode resource bookkeeping stays as before. If the area is full, the module falls back to a private copy. Without CONFIG_COLD_STORE_EXECUTE_DRAM, fast_get_ll() returns the DRAM pointer, so no copy is made.
  • DP modules are unchanged: small copies stay in the module vregion, and large copies come from vpage_alloc() with a read-only grant to each DP domain.
  • Tests and docs: a new standalone suite userspace_ll_fast_get checks:
    • shared copies, which kernel fast_put() does not release;
    • reuse of a freed copy without stale cache lines;
    • a user write to a copy faults the thread;
    • caller and source-readability checks;
    • the module fallback when the area is full.

The userspace README and the syscall map are updated.

Known limitation: an LL thread can release a copy that other LL modules still use. This is acceptable limitation as LL modules are not protected from other LL modules in the same domain. This only affects LL modules, not kernel state.

Tested on PTL:

  • standalone userspace suites;
  • LL SRC rate sweeps and parallel streams on sof-ptl-nocodec-dp-test, with copies shared and the area returning to empty;
  • nocodec with DP SRC, multiple-pipeline, DP long run and create/free cycles;
  • HDA, chain DMA and D3 cycles.

Every commit builds, and the mtl/lnl/ptl/imx8m/testbench builds are OK.

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

The tests make unsupported configuration assumptions, causing failures when DRAM execution is disabled and leaked references when syscall caller checking is disabled.

2 open issues
What changed in this PR

This PR restores shared, read-only fast-get copies for low-latency (LL) userspace modules, reducing duplicate coefficient storage while keeping allocation state in the kernel.

Changes:

  • Adds a configurable LL fast-get area with bitmap allocation and read-only cached mappings.
  • Introduces fast_get_ll() / fast_put_ll() syscalls and module integration, with private-copy fallback when the area is full.
  • Adds standalone tests and updates userspace documentation; DP module behavior remains unchanged.
File Description
zephyr/​test/​userspace/​test_ll_user_heap.c Adds sharing, cache-reuse, access-control, and fallback tests.
zephyr/​test/​userspace/​README.md Documents the new fast-get test coverage.
zephyr/​lib/​fast-get.c Implements LL syscalls, separate entry ownership, and cache invalidation.
zephyr/​Kconfig Configures the LL fast-get area size.
src/​kernel/​schedule/​zephyr_ll_user.c Allocates and maps the kernel-managed fast-get area.
src/​include/​sof/​userspace/​README.md Updates the syscall map and shared-memory design documentation.
src/​include/​sof/​schedule/​ll_schedule_domain.h Declares fast-get area allocation and accounting APIs.
src/​include/​sof/​lib/​fast-get.h Declares LL syscalls and passthrough implementations.
src/​audio/​module_adapter/​module/​generic.c Integrates shared LL copies with resource cleanup and private fallback.

Review effort: Balanced

@intel-sofci

intel-sofci commented Nov 24, 2026 •

Copy link
Copy Markdown

PR 11531: test results

Run date: 2026-11-25 12:47 UTC

Tested commit: e8857edf272109017dfc39cbbe825afe7239145a

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

@kv2019i

kv2019i commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

V2 pushed:

  • fixed code review comments

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

The Kconfig default unnecessarily reserves 32 KiB in passthrough builds, reducing the LL user heap from 104 KiB to 72 KiB and potentially causing pipeline allocation failures.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread zephyr/Kconfig Resolved
LL modules get their fast_get() copies, such as SRC coefficients, as
private copies in their own memory, since the fast_get() state is in
kernel memory and the kernel must not allocate from the LL user heap.
Copies of the same data are no longer shared, and LL threads can write
them.

Reserve a fast_get area in the LL memory region for these copies, 32 kB
by default when fast_get() is enabled and the memory has mirrored cached
and uncached aliases. Its allocator is a bitmap of
256-byte blocks in kernel memory. Only the cached alias of the area is
mapped into the LL memory domain, read-only, so kernel code can write a
copy through the uncached alias also in a system call from an LL
thread, while LL threads only read it. The cache lines of the area are
written back and invalidated at boot, so no dirty line can later
overwrite a copy.

The area is taken from the LL user heap, which shrinks by the same
amount. The private copies that the area replaces came from that heap.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
LL modules make their fast_get() copies in user mode, as private copies
in their own memory, since the fast_get() state is in kernel memory.
Add the fast_get_ll() and fast_put_ll() system calls for LL user threads
instead, which share a copy between all users of the same data.

The copies come from the fast_get area of the LL memory region, which
LL threads can only read. Kernel code writes a copy through the
uncached alias, and invalidates the cached alias on the calling core on
every get, as the core may still hold lines of an earlier copy at the
same address. The entries stay in kernel memory, marked as LL copies:
fast_get() and fast_put() never use them, and the new calls use no
other entries, so a user thread cannot make the kernel free a copy with
the wrong allocator. Only the LL and IPC user threads may make the
calls, and the data must be readable by the caller.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
LL modules in user mode get a private copy of their fast_get data, such
as SRC coefficients, in the module memory. Every instance makes its own
copy, and LL threads can write it.

Get the copies with fast_get_ll() instead, and release them with
fast_put_ll(), so instances share a read-only copy in the fast_get area
of the LL memory region. The resource is tracked as before, in user
mode. When the area is full, fall back to a private copy.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add a standalone suite for the fast_get area of the LL memory region.
An IPC user thread gets a copy of the same data twice and both users
share it, the copy is in the area and is freed with its last user, and
kernel code does not release it with fast_put(). A freed copy is reused
for other data without stale cache lines, and a user thread that
writes a copy faults. A thread in the LL memory domain that is not the
LL or IPC user thread cannot get copies, nor can the IPC user thread
get a copy of memory it cannot read. An LL module gets its copy from
the area, and a private copy when the area is full.

The suite shares the user thread of the LL user heap suite, as the
standalone build has no thread ID left for another one.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Describe the fast_get area of the LL memory region, how kernel code
writes the shared copies of the LL modules and keeps their state, and
the private copy when the area is full. Add the fast_get_ll() and
fast_put_ll() system calls to the syscall map, and note where the
copies of DP modules are.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i

kv2019i commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

V3 pushed:

  • fixed code review comments to V2

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

The explicit copy-test invocation lacks a nonzero-area guard, so DRAM staging with CONFIG_SOF_ZEPHYR_LL_FG_AREA_SIZE=0 bypasses the skip predicate and fails assertions on NULL shared-copy acquisitions.

1 open issue
1 resolved since last review

Review effort: Balanced

static int run_tests(void)
{
ztest_run_test_suite(userspace_ll_user_heap, false, 1, 1, NULL);
#if HAVE_LL_FAST_GET_COPIES

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.

This is always defined for ll user builds, so not worth respinning the series.

@kv2019i

kv2019i commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Multiple fails in Intel sof-pr-test, but these are due to sof-logger check -> fix in thesofproject/sof-test#1371

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