From a6ec1a7ad683be3733b71a3f93484f87ff920ce2 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Wed, 18 Nov 2026 12:32:18 +0200 Subject: [PATCH] schedule: dp: look up the DP scheduler by core in the LL user thread With CONFIG_SOF_USERSPACE_APPLICATION and CONFIG_SOF_USERSPACE_LL, scheduler_dp_ll_post_tick() runs in the LL user thread on every LL tick and finds the DP scheduler with scheduler_get_user_data(). This now reads the kernel-only copy of the user scheduler list, so the LL thread takes a load/store privilege exception (EXCCAUSE 26) as soon as audio starts. Pass the core of the calling LL scheduler to scheduler_dp_ll_post_tick() and look up the DP scheduler with arch_user_schedulers_get_for_core(), which is safe to call from user threads. Use the same core for the DP lock instead of cpu_get_id(), which reads a privileged register. Fixes: 91c214856ad1 ("schedule: keep user scheduler descriptors read-only to user threads") Signed-off-by: Kai Vehmanen --- src/include/sof/schedule/dp_schedule.h | 4 +++- src/schedule/zephyr_dp_schedule.c | 11 +++++++---- src/schedule/zephyr_ll.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/include/sof/schedule/dp_schedule.h b/src/include/sof/schedule/dp_schedule.h index 63f1a02f71e8..ab511e125f65 100644 --- a/src/include/sof/schedule/dp_schedule.h +++ b/src/include/sof/schedule/dp_schedule.h @@ -147,8 +147,10 @@ static inline void scheduler_dp_check_deadline(uint16_t core, uint32_t deadline_ * memory is writable by the DP threads, so the calculation runs in the calling * LL user thread, and only its results are passed to the kernel with * scheduler_dp_kick(). Otherwise this calls scheduler_dp_ll_tick(). + * + * @param[in] core Core ID of the calling LL scheduler. */ -void scheduler_dp_ll_post_tick(void); +void scheduler_dp_ll_post_tick(unsigned int core); #if CONFIG_SOF_BOOT_TEST_STANDALONE && CONFIG_SOF_USERSPACE_APPLICATION /* Test hooks: add and remove kernel-only DP task records without a DP task */ diff --git a/src/schedule/zephyr_dp_schedule.c b/src/schedule/zephyr_dp_schedule.c index 918d3661bb95..38d228d4b609 100644 --- a/src/schedule/zephyr_dp_schedule.c +++ b/src/schedule/zephyr_dp_schedule.c @@ -52,9 +52,12 @@ void scheduler_dp_unlock(unsigned int key) #if CONFIG_SOF_USERSPACE_APPLICATION && CONFIG_SOF_USERSPACE_LL /* Runs in the LL user thread, see scheduler_dp_ll_post_tick() documentation */ -void scheduler_dp_ll_post_tick(void) +void scheduler_dp_ll_post_tick(unsigned int core) { - struct scheduler_dp_data *dp_sch = scheduler_get_user_data(SOF_SCHEDULE_DP); + /* user context: the kernel-only lookup and cpu_get_id() are not usable */ + struct scheduler_dp_data *dp_sch = + scheduler_list_get_data(*arch_user_schedulers_get_for_core(core), + SOF_SCHEDULE_DP); unsigned int lock_key; /* @@ -64,12 +67,12 @@ void scheduler_dp_ll_post_tick(void) if (!dp_sch || list_is_empty(&dp_sch->tasks)) return; - lock_key = scheduler_dp_lock(cpu_get_id()); + lock_key = scheduler_dp_lock(core); scheduler_dp_recalculate(dp_sch); scheduler_dp_unlock(lock_key); } #else -void scheduler_dp_ll_post_tick(void) +void scheduler_dp_ll_post_tick(unsigned int core) { scheduler_dp_ll_tick(); } diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index 951f421e00a8..95f4cd17620d 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -302,7 +302,7 @@ static void zephyr_ll_run(void *data) zephyr_ll_unlock(sch, &flags); #ifdef CONFIG_ZEPHYR_DP_SCHEDULER - scheduler_dp_ll_post_tick(); + scheduler_dp_ll_post_tick(sch->core); #endif }