Skip to content

schedule: zephyr_ll: add KAREA_WRITE_SCHEDULERS kernel mem region - #11469

Open
kv2019i wants to merge 9 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-boot-kareas
Open

kv2019i wants to merge 9 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-boot-kareas

Conversation

@kv2019i

@kv2019i kv2019i commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Add kernel managed LL objects to new kernel only area and add routines to publish a minimal set of read-only objects to the user LL thread.

This is part of effort to complete isolation of LL user and kernel thread resources, and to protect kernel functions from reliance on any user writable memory. Changes only affect SOF built with CONFIG_SOF_USERSPACE_LL.

With CONFIG_SOF_USERSPACE_LL, the list of user schedulers and the
struct schedule_data of each, including the scheduler ops that kernel
code calls, were allocated from the LL user heap, and the list heads
were in user-writable memory. An LL or IPC user thread could replace
the ops or the lists that the kernel uses.

Allocate the list heads and descriptors of user schedulers from the
kernel RO area of the LL memory region. They are only written by kernel
threads, at boot and at secondary core bring-up. Keep a kernel-only
copy of the per-core list heads for kernel code, and publish them to
the user-visible array after registration.

Tasks still point to their scheduler from user memory, so this protects
the descriptors themselves, not the choice of descriptor.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The IPC user thread state, the IPC data buffer and the LL allocation
context are created by kernel code at boot and used by user threads.
They were allocated from the LL user heap, whose metadata user threads
can write, with the kernel running the allocator.

Allocate struct ipc_user and the IPC data buffer from the kernel RW area
of the LL memory region, and the LL allocation context, which user
threads only read, from the kernel RO area.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Objects in the kernel-managed areas of the LL memory region are never
freed. sof_heap_free() falls back to rfree() for memory that is not in
the given heap, and the LL memory region is a block of the kernel heap,
so freeing such an object by mistake would corrupt the kernel heap.
Refuse and log instead.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, the per-core LL scheduler state and the
tasks that kernel threads create at boot, such as the IPC and secondary
core LL tasks, were allocated by the kernel from the LL user heap. The
scheduler state also stored the heap pointer, which the kernel then used
for freeing task data, in memory that user threads can write.

Allocate the scheduler state, the boot tasks and their task data from
the kernel RW area of the LL memory region. Tasks created by user
threads keep using the LL user heap. Free through a helper that uses
the heap directly and skips kernel area objects, instead of the stored
heap pointer.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, the LL timer domain and its Zephyr domain
data are created by kernel code at boot and used by LL user threads.
They were allocated from the LL user heap, with the kernel running its
allocator. Allocate them from the kernel RW area of the LL memory
region instead. They are never freed.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, the timer interrupt handler found the
per-core LL thread semaphores through the timer user data and the Zephyr
domain data. LL user threads can write that data and, having access to
the timer, set its user data, so they could make the interrupt handler
give a semaphore at any address. Thread teardown likewise aborted and
freed the thread and semaphore recorded in that data.

Keep kernel-only copies of the domain data pointer and of the per-core
semaphores. The interrupt handler only uses the timer user data and the
registered handler as flags, so forging them can only cause extra or
missed ticks. Thread setup and teardown use the kernel copies and the
existing kernel-only thread table.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, the per-core DP scheduler data, including
the LL tick task, is created by kernel code at boot and used by LL user
threads. Allocate it from the kernel RW area of the LL memory region
instead of the LL user heap. It is never freed.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Check that the user scheduler list of the current core and all its
scheduler descriptors are in the kernel RO area of the LL memory
region, and that an LL user thread writing the list, found through its
own copy of the list head, faults.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Document which kernel-created objects are now in the kernel RO and RW
areas of the LL memory region, the kernel-only copies used by the LL
timer interrupt and thread setup, and the user-writable pointers that
kernel code still follows.

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

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.

🔵 Needs a closer look

Changes to LL/IPC memory isolation and timer-IRQ ownership require human review and target MMU validation of access permissions, multicore initialization, and object teardown beyond what source inspection can establish.

No open issues 🎉

What changed in this PR

This PR strengthens low-latency (LL) userspace isolation by moving long-lived scheduler and IPC objects into kernel-managed memory areas and publishing read-only scheduler descriptors to user threads.

Changes:

  • Move boot-lifetime objects into LL read-only or read-write areas and prevent heap frees of those allocations.
  • Keep kernel-only copies of scheduler heads, domain pointers, and thread handles.
  • Document memory ownership and add scheduler write-protection tests.
File Description
zephyr/​test/​userspace/​test_ll_karea.c Test scheduler descriptors’ read-only placement and write protection.
zephyr/​schedule.c Separate kernel-owned scheduler heads from published user copies.
zephyr/​lib/​alloc.c Reject heap frees of kernel-managed LL memory.
src/​schedule/​zephyr_ll.c Allocate boot tasks in managed memory and adapt cleanup.
src/​kernel/​schedule/​zephyr_ll-kernel.c Move LL scheduler state into managed memory.
src/​kernel/​schedule/​zephyr_dp_schedule-kernel.c Move DP scheduler state into managed memory.
src/​kernel/​schedule/​zephyr_domain-kernel.c Use kernel-owned domain and thread references in privileged paths.
src/​kernel/​schedule/​schedule-kernel.c Allocate read-only user scheduler descriptors and publish list heads.
src/​kernel/​ipc/​ipc-common-kernel.c Move shared IPC objects into appropriate managed areas.
src/​include/​sof/​userspace/​README.md Document object placement and remaining isolation limitations.
src/​include/​sof/​schedule/​zephyr_ll.h Add area-aware cleanup helpers and remove the scheduler heap field.
src/​include/​sof/​schedule/​schedule.h Declare and document scheduler-head publication.
src/​include/​sof/​schedule/​ll_schedule_domain.h Allocate LL domains in managed memory.

Review effort: Balanced

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