[Userspace LL] schedule: zephyr_ll: grant LL thread access to per-task semaphores - #11080
[Userspace LL] schedule: zephyr_ll: grant LL thread access to per-task semaphores#11080kv2019i wants to merge 1 commit into
Conversation
|
For context, this is part of #10558 |
There was a problem hiding this comment.
Pull request overview
This PR addresses a userspace permission fault in CONFIG_SOF_USERSPACE_LL builds by ensuring the unprivileged LL scheduler thread is explicitly granted access to per-task semaphores that are dynamically allocated for tasks created after the bootstrap context.
Changes:
- Grant the LL scheduler thread access to each task’s dynamically allocated semaphore at allocation time (in the privileged syscall implementation path).
- Add
zephyr_domain_thread_tid_for_core()to retrieve the LL thread for a specified core without relying oncpu_get_id()in syscall contexts. - Expose the new helper in the LL schedule domain public header.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/schedule/zephyr_ll.c | Grants the LL thread access to per-task semaphores during allocation for userspace LL builds. |
| src/schedule/zephyr_domain.c | Adds a core-explicit helper to retrieve the LL scheduler thread TID safely in syscall contexts. |
| src/include/sof/schedule/ll_schedule_domain.h | Declares the new zephyr_domain_thread_tid_for_core() API for userspace LL builds. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| struct zephyr_ll *sch = task->sch ? task->sch->data : NULL; | ||
|
|
||
| if (sch && sch->ll_domain) { | ||
| struct k_thread *ll_tid = | ||
| zephyr_domain_thread_tid_for_core(sch->ll_domain, task->core); | ||
|
|
||
| if (ll_tid) | ||
| k_thread_access_grant(ll_tid, ts->sem); | ||
| } |
72be414 to
5f2d96a
Compare
|
V2:
|
|
@jsarha @lgirdwood good to go? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
src/schedule/zephyr_domain.c:507
- This new exported C function is documented with a plain block comment, so Doxygen will not associate the documentation with the API. Convert it to a Doxygen comment and document both parameters and the nullable return value, as required for new C APIs in this repository.
/*
* Return the LL scheduling thread for an explicitly given core.
*
* Unlike zephyr_domain_thread_tid(), this does not rely on cpu_get_id() and
* is therefore safe to call from a syscall context that may run on a core
| list_for_item(slist, &schedulers->list) { | ||
| sch = container_of(slist, struct schedule_data, list); | ||
| if (sch->type == SOF_SCHEDULE_LL_TIMER) | ||
| return sch->data; |
In CONFIG_SOF_USERSPACE_LL builds the LL scheduler thread runs unprivileged, so every Zephyr kernel object it accesses must be explicitly granted to it. In commit ffa52df ("schedule: ll: dynamically allocate the semaphore"), task semaphores were converted to dynamically allocated objects. Only the bootstrap task's semaphore was granted to the LL thread (in zephyr_ll_init_context()); tasks created later (e.g. chain_dma) were not, so pausing/stopping such a task while it was running crashed the DSP. Fix the issue by grant the LL scheduling thread access to the task's semaphore at allocation time, from the syscall implementation which runs in privileged context. Add zephyr_domain_thread_tid_for_core() to look up the LL thread for an explicit core without relying on cpu_get_id(), and without dereferencing user-accessible task struct. Fixes: ffa52df ("schedule: ll: dynamically allocate the semaphore") Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
5f2d96a to
076e5e1
Compare
|
V3 update:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/include/sof/schedule/ll_schedule_domain.h:331
- The new public helper lacks the required Doxygen API documentation; the regular source comment is not attached to this declaration and will not document its parameter or nullable return value. Add a Doxygen block here so documentation builds expose the contract.
struct k_thread *zephyr_domain_thread_tid_for_core(int core);
In CONFIG_SOF_USERSPACE_LL builds the LL scheduler thread runs unprivileged, so every Zephyr kernel object it accesses must be explicitly granted to it.
In commit ffa52df ("schedule: ll: dynamically allocate the semaphore"), task semaphores were converted to dynamically allocated objects. Only the bootstrap task's semaphore was granted to the LL thread (in zephyr_ll_init_context()); tasks created later (e.g. chain_dma) were not, so pausing/stopping such a task while it was running crashed the DSP.
Fix the issue by grant the LL scheduling thread access to the task's semaphore at allocation time, from the syscall implementation which runs in privileged context. The task's LL scheduler is resolved via task->sch (bound in schedule_task_init() using the core-explicit user scheduler list), because zephyr_ll_domain()/cpu_get_id()-based helpers are unreliable in a syscall context: zephyr_ll_domain() reads the kernel scheduler list and returns NULL for the user-space LL scheduler.
Add zephyr_domain_thread_tid_for_core() to look up the LL thread for an explicit core without relying on cpu_get_id().
Fixes: ffa52df ("schedule: ll: dynamically allocate the semaphore")