Skip to content

schedule: zephyr_ll: protect against a race in task free - #11104

Open
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202608-fix-chaindma-task-free-race
Open

schedule: zephyr_ll: protect against a race in task free#11104
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202608-fix-chaindma-task-free-race

Conversation

@kv2019i

@kv2019i kv2019i commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Add a check to ensure task state is what is expected after k_sem_take() returns in zephyr_ll_task_free().

This is needed to avoid a rare error hit when running stress tests with chain DMA in user-space LL builds. Issue is hard to reproduce, but similar error signature can be created by passing K_NO_WAIT to k_sem_take() and running a test with chain-dma pipeline.

Add defensive code that handles this scenario and prints out a warning when unexpected return occurs. Tested with a custom build with K_NO_WAIT passed to k_sem_take().

Copilot AI lite review requested due to automatic review settings August 18, 2026 12:56
@kv2019i
kv2019i requested review from jsarha, lgirdwood and lyakh August 18, 2026 12:56

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.

Pull request overview

This PR updates the Zephyr LL scheduler task teardown path to add a defensive validation after waiting in zephyr_ll_task_free(), aiming to avoid a rare race observed during stress tests (user-space LL + chain DMA) where a task can be freed while still active.

Changes:

  • Captures the return value of k_sem_take() in zephyr_ll_task_free() and adds a warning path when the wait result/state is unexpected.
  • Attempts to force-complete a task during free when the wait result indicates an abnormal condition.

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

Comment thread src/schedule/zephyr_ll.c Outdated
Comment on lines +603 to +607
if (wait_ret && task->state != SOF_TASK_STATE_FREE) {
tr_warn(&ll_tr, "task %p still active on free (state %d, semret %d)",
task, task->state, wait_ret);
zephyr_ll_task_done(sch, task);
}

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.

Fixed in V2.

Add a check to ensure task state is what is expected after k_sem_take()
returns in zephyr_ll_task_free().

This is needed to avoid a rare error hit when running stress tests with
chain DMA in user-space LL builds. Issue is hard to reproduce,
but similar error signature can be created by passing K_NO_WAIT to
k_sem_take() and running a test with chain-dma pipeline.

Add defensive code that handles this scenario and prints out a warning
when unexpected return occurs. Tested with a custom build with K_NO_WAIT
passed to k_sem_take().

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
kv2019i force-pushed the 202608-fix-chaindma-task-free-race branch from 9c640a2 to 7f69e94 Compare August 18, 2026 14:07
@kv2019i

kv2019i commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

V2:

  • move handling sem_wait timeout later in the function so it is called with ll lock held

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