Skip to content

LL userspace ipc_msg_send() and send_resource_notif() syscalls and related changes - #10725

Open
jsarha wants to merge 3 commits into
thesofproject:mainfrom
jsarha:ll_userspace_ipc_msg_send
Open

LL userspace ipc_msg_send() and send_resource_notif() syscalls and related changes#10725
jsarha wants to merge 3 commits into
thesofproject:mainfrom
jsarha:ll_userspace_ipc_msg_send

Conversation

@jsarha

Copy link
Copy Markdown
Contributor

FYI @kv2019i , @lyakh , @lrgirdwo

I still intent to make sure the position updates work.

@jsarha
jsarhaforce-pushed the ll_userspace_ipc_msg_send branch from 9511db2 to 0382995CompareApril 28, 2026 13:29
@jsarha

jsarha commented Apr 28, 2026

Copy link
Copy Markdown
ContributorAuthor

Hmmm, looks like something is crashintg this branch every now and then at GLB_CREATE_PIPELINE message. Not sure if its my changes or some other bug in the userspace support. I guess I need come up with new methods to debug issue. Can not proceed with getting CONFIG_HOST_DMA_IPC_POSITION_UPDATES=y to work while there is random crashes even without it.

@jsarha

Copy link
Copy Markdown
ContributorAuthor

I just rebased the the relevant commits on top of V32 of #10558 and tested that they still work, and also that they do not break the normal functions of non LL user-space build. So I think these are ready for wider review and merge.

CopilotAI 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 introduces Zephyr user-space (LL) syscall support for ipc_msg_send() and IPC4 send_resource_notif(), and refactors some IPC4 notification helpers while extending IPC message allocation to optionally use specific heaps/module allocators.

Changes:

  • Added Zephyr syscall wrappers + marshalling for ipc_msg_send() and IPC4 send_resource_notif().
  • Refactored IPC4 notification helpers into a separate compilation unit and added syscall-side argument validation.
  • Extended IPC message initialization APIs to optionally allocate from a specified k_heap and introduced module-allocator IPC msg init helpers.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
zephyr/CMakeLists.txtRegisters new syscall headers for ipc_msg_send and IPC4 notification syscalls.
src/trace/dma-trace.cUpdates ipc_msg_init() call to the new signature.
src/samples/audio/detect_test.cUpdates IPC msg init helpers to pass an explicit heap argument.
src/library_manager/lib_notification.cUpdates ipc_msg_init() call to the new signature.
src/ipc/ipc4/notification.cConverts send_resource_notif() into a syscall-capable implementation + verifier.
src/ipc/ipc4/notification-user.cAdds refactored, non-syscall IPC4 notification helper functions.
src/ipc/ipc4/CMakeLists.txtAdds the new notification-user.c to the IPC4 build.
src/ipc/ipc-common.cAdds heap-aware IPC msg allocation and syscall support for ipc_msg_send().
src/include/sof/ipc/msg.hChanges IPC msg init APIs to accept an optional heap; moves send decl to a new header.
src/include/sof/ipc/ipc_msg_send.hIntroduces a dedicated header for ipc_msg_send() (syscall-aware).
src/include/sof/audio/module_adapter/module/generic.hAdds module-allocator IPC msg init helpers.
src/include/ipc4/notification.hDeclares send_resource_notif() as a syscall under CONFIG_SOF_USERSPACE_LL.
src/audio/tdfb/tdfb_ipc4.cSwitches IPC4 notification template allocation to module allocator helper.
src/audio/tdfb/tdfb_ipc3.cSwitches IPC3 IPC msg allocation to module allocator helper.
src/audio/sound_dose/sound_dose-ipc4.cSwitches IPC4 notification template allocation to module allocator helper.
src/audio/pipeline/pipeline-graph.cAllocates pipeline IPC msg using the pipeline heap via the new API.
src/audio/module_adapter/module/cadence_ipc4.cSwitches IPC notification template allocation to module allocator helper.
src/audio/mfcc/mfcc_ipc4.cSwitches IPC4 notification template allocation to module allocator helper.
src/audio/host-zephyr.cAllocates host position IPC msg using the host heap via the new API.
src/audio/host-legacy.cUpdates ipc_msg_init() call to the new signature.
src/audio/google/google_hotword_detect.cUpdates ipc_msg_init() call to the new signature.

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

Comment on lines +22 to +26
#else
void z_impl_ipc_msg_send(struct ipc_msg *msg, void *data,
bool high_priority);
#define ipc_msg_send z_impl_ipc_msg_send
#endif

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header, with the macro is also included in the c-file where the implementation is. So the macro will replace ipc_msg_send with z_impl_ipc_msg_send .

Comment on lines +51 to 53
struct ipc_msg *ipc_msg_w_ext_init(struct k_heap *heap, uint32_t header,
uint32_t extension, uint32_t size);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a clear bug. Will fix.

Comment threadsrc/ipc/ipc-common.c
Comment on lines +345 to +352
void z_vrfy_ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
{
K_OOPS(K_SYSCALL_MEMORY_WRITE(msg, sizeof(*msg)));

z_vrfy_ipc_msg_send_check_data(msg, data);

z_impl_ipc_msg_send(msg, data, high_priority);
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More the checks the better.

Comment on lines +251 to +255
static inline struct ipc_msg *mod_ipc_msg_w_ext_init(struct processing_module *mod,
uint32_t header,
uint32_t extension,
uint32_t size)
{
Jyri Sarha added 3 commits August 12, 2026 22:09
Make ipc_msg_send() a Zephyr system call so audio processing modules
running in user-space LL threads can queue IPC messages (e.g. position
updates, notifications) back to the host. The change takes effect only
if CONFIG_SOF_USERSPACE_LL=y.
Follows the same pattern used for ipc_msg_reply(): a dedicated
header with __syscall declaration, z_impl/z_vrfy split, and
syscall header registration in CMakeLists.txt.
The verifier validates that the msg struct is writable (the
implementation touches the list linkage) and that the data
buffer, when provided, is readable up to msg->tx_size bytes.
Add ipc_msg_list_remove() as a system call that acquires the IPC lock
and removes a message from its list. This allows message freeing to
work from userspace threads that cannot access kernel spinlocks
directly.
Update ipc_msg_free() in msg.h to use ipc_msg_list_remove() instead
of directly accessing the IPC spinlock.
Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add an optional heap parameter to ipc_msg_w_ext_init() and
ipc_msg_init() so callers can direct allocations to a specific
heap. When the heap argument is NULL the existing rzalloc()
path is used; when non-NULL, sof_heap_alloc()/sof_heap_free()
are used instead. This allows IPC messages to be allocated from
userspace-accessible heaps.
For audio module contexts, introduce mod_ipc_msg_w_ext_init()
and mod_ipc_msg_init() in generic.h. These use mod_zalloc()/
mod_free() for allocations that are automatically tracked and
freed with the module lifecycle.
ipc_msg_w_ext_init() is moved from a static inline in msg.h to
a non-inline function in ipc-common.c due to the additional
sof_heap_alloc dependency.
Update all existing callers:
- Module context callers (cadence, sound_dose, tdfb, mfcc) use
the new mod_ipc_msg_*() variants and mod_ipc_msg_free().
- host-zephyr.c uses hd->heap, pipeline-graph.c uses the heap
parameter from pipeline_new().
- Remaining kernel-context callers pass NULL for the default
heap.
Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Move user-facing notification functions
(send_copier_gateway_xrun_notif_msg, send_gateway_xrun_notif_msg,
send_mixer_underrun_notif_msg, send_process_data_error_notif_msg) to a
new notification-user.c file so they can run in userspace.
The send_resource_notif() function, which depends on the kernel-side
notification pool and IPC message infrastructure, is converted to a
Zephyr syscall. The implementation is renamed to
z_impl_send_resource_notif() and remains in notification.c alongside
is_notif_filtered_out() and ipc4_update_notification_mask().
The send_resource_notif() is converted to a system call only if
CONFIG_SOF_USERSPACE_LL=y, without it the behaviour is same as befofe.
A z_vrfy_send_resource_notif() handler is added to validate the
user-provided data buffer and other parameters before forwarding to
the kernel implementation.
Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
@jsarha
jsarhaforce-pushed the ll_userspace_ipc_msg_send branch from 8812392 to fff3d44CompareAugust 12, 2026 19:44
@jsarha

Copy link
Copy Markdown
ContributorAuthor

Issues found by Copilot fixed.

@kv2019ikv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syscall verify checks are tricky, a few comments on those (plus some minor stuff).

#endif

#if defined(__ZEPHYR__) && defined(CONFIG_SOF_USERSPACE_LL)
#include <zephyr/syscalls/ipc_msg_list_remove.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this could be part of the first if branch as the condition is the same..

#define ipc_msg_send z_impl_ipc_msg_send
#endif

#if defined(__ZEPHYR__) && defined(CONFIG_SOF_USERSPACE_LL)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation. All rights reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the all rights reserved.

Comment threadsrc/ipc/ipc-common.c

z_vrfy_ipc_msg_send_check_data(msg, data);

z_impl_ipc_msg_send(msg, data, high_priority);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs addition checks on the embedded list. Kernel will call "(list_is_empty(&msg->list)" and we need to make sure this is safe any user has access to any non-NULL pointers.

Comment threadsrc/ipc/ipc-common.c
k_spinlock_key_t key;

key = k_spin_lock(&ipc->lock);
list_item_del(&msg->list);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think same here, we can't trust msg->list contents and needs to be checked in z_vrfy()

send_resource_notif(resource_id, SOF_IPC4_MIXER_UNDERRUN_DETECTED, SOF_IPC4_PIPELINE,
&mixer_underrun_data, sizeof(mixer_underrun_data));
}
EXPORT_SYMBOL(send_mixer_underrun_notif_msg);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported?

Sign up for freeto 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.

3 participants

@jsarha@kv2019i