Skip to content

audio: fast-get: improve userspace compatibility#10524

Open
lyakh wants to merge 3 commits intothesofproject:mainfrom
lyakh:fastget
Open

audio: fast-get: improve userspace compatibility#10524
lyakh wants to merge 3 commits intothesofproject:mainfrom
lyakh:fastget

Conversation

@lyakh
Copy link
Collaborator

@lyakh lyakh commented Feb 5, 2026

remove unneeded syscalls and fix compilation warnings (part of #10469 )

lyakh added 2 commits February 5, 2026 14:50
Userspace modules should only call mod_fast_get() and mod_fast_put(),
which already can cross into the kernel space on their own, so
fast_get() and fast_put() themselves don't need to be syscalls.
Remove their syscall implementations.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
fast_get.c doesn't have a "trace context" - it doesn't have a
DECLARE_TR_CTX() call. Hencs all calls to tr_err() and friends are
wrong. Replace them with respective LOG_*() analogs.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Copy link

Copilot AI left a comment

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 removes the syscall infrastructure for fast-get/fast-put functions and enhances userspace compatibility by enabling direct buffer sharing between user and kernel spaces. The changes eliminate unnecessary syscall overhead and prepare for more efficient memory management in userspace contexts.

Changes:

  • Converted fast-get functions from syscalls to regular functions, removing z_impl_* and z_vrfy_* wrappers
  • Added userspace-specific logic to handle memory partition grants for large buffers (> PAGE_SZ/2)
  • Updated logging from SOF trace macros (tr_) to standard LOG_ macros with conditional compilation for non-Zephyr builds

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
zephyr/lib/fast-get.c Removed syscall infrastructure, added userspace memory partition management, updated logging macros
src/include/sof/lib/fast-get.h Simplified API by removing syscall declarations and conditional compilation
src/audio/module_adapter/module_adapter.c Updated include path from platform/platform.h to sof/platform.h for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 266 to 267
.size = ALIGN_UP(entry->size, CONFIG_MM_DRV_PAGE_SIZE),
.attr = K_MEM_PARTITION_P_RO_U_RO | XTENSA_MMU_CACHED_WB,
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The constant XTENSA_MMU_CACHED_WB is Xtensa-specific but is used without architecture-specific guards. If CONFIG_USERSPACE is enabled on a non-Xtensa platform, this will cause a compilation error. Consider using architecture-specific conditionals or defining a platform-agnostic cache attribute constant. For example, you could use preprocessor conditionals to select the appropriate cache attribute based on the target architecture.

Suggested change
.size = ALIGN_UP(entry->size, CONFIG_MM_DRV_PAGE_SIZE),
.attr = K_MEM_PARTITION_P_RO_U_RO | XTENSA_MMU_CACHED_WB,
.size = ALIGN_UP(entry->size, CONFIG_MM_DRV_PAGE_SIZE),
#ifdef XTENSA_MMU_CACHED_WB
.attr = K_MEM_PARTITION_P_RO_U_RO | XTENSA_MMU_CACHED_WB,
#else
.attr = K_MEM_PARTITION_P_RO_U_RO,
#endif

Copilot uses AI. Check for mistakes.
int err = fast_get_access_grant(entry->thread, ret, size);

if (err < 0) {
sof_heap_free(NULL, ret);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

When fast_get_access_grant fails, the allocated memory is freed and ret is set to NULL, but the entry fields (entry->size, entry->sram_ptr, entry->dram_ptr set at line 224) remain set. This leaves the entry in an inconsistent state. Consider resetting the entry with memset(entry, 0, sizeof(*entry)) after freeing the memory to ensure clean error handling, similar to what's done in fast_put at line 278.

Suggested change
sof_heap_free(NULL, ret);
sof_heap_free(NULL, ret);
memset(entry, 0, sizeof(*entry));

Copilot uses AI. Check for mistakes.

ret = sof_heap_alloc(heap, SOF_MEM_FLAG_USER, size, PLATFORM_DCACHE_ALIGN);
/*
* If a userspace threads is the first user to fast-get the buffer, an
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The word "threads" should be "thread" (singular) to match the grammatical context of the sentence.

Suggested change
* If a userspace threads is the first user to fast-get the buffer, an
* If a userspace thread is the first user to fast-get the buffer, an

Copilot uses AI. Check for mistakes.
Fix "unused function" Zephyr compilation warnings.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Comment on lines +22 to +25
#define LOG_DBG(...) do {} while (0)
#define LOG_INF(...) do {} while (0)
#define LOG_WRN(...) do {} while (0)
#define LOG_ERR(...) do {} while (0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understand, these are Zephyr macros. I suspect they might be used in other places soon. Do we want to move this else into a separate file that is included when Zephyr is not present?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@lyakh Also wondering why do we need to ifdef Zephyr, this is zephyr/lib/fast-get.c after all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Check the comment in second patch.

Comment on lines +22 to +25
#define LOG_DBG(...) do {} while (0)
#define LOG_INF(...) do {} while (0)
#define LOG_WRN(...) do {} while (0)
#define LOG_ERR(...) do {} while (0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lyakh Also wondering why do we need to ifdef Zephyr, this is zephyr/lib/fast-get.c after all?

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.

3 participants