Skip to content

platform: posix: add virtual DAI devices for native_sim - #11493

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/posix/add_virtual_dai
Nov 20, 2026
Merged

lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/posix/add_virtual_dai

Conversation

@tmleman

@tmleman tmleman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

native_sim has no audio hardware and no registered Zephyr DAI device, so zephyr_dev[] is empty and dai_get_device() can never match. Every DAI gateway request therefore failed at

copier_dai_create -> dai_common_new -> dai_get -> dai_get_device

which hid the whole generic SOF DAI construction, configuration and property layer from the IPC fuzzer.

Add a devicetree-described virtual DAI backend for the POSIX platform and include it in the native DAI enumeration behind the new CONFIG_DAI_POSIX, enabled only by the fuzz feature configuration. The overlay declares SSP 0-3, DMIC 0-1, HDA 0-3, ALH 0-3 and UAOL 0-1, so a gateway node id carrying a realistic index resolves to a device.

The model is deliberately configuration-only: probe/remove, config set/get, trigger, the timestamping ops and the properties SOF queries (FIFO address and depth, handshake id, stream id) are implemented, the type-specific blob is read through but never parsed, and no data is moved. Reading every byte of the host supplied blob lets the sanitizers validate the (pointer, size) pair the IPC layer hands down, which memcpy_s() cannot do because it only guards the destination. Reporting a rate and channel count of zero keeps dai_verify_params() from rejecting otherwise valid streams, and prepare still stops cleanly in the POSIX DMA model, which does not implement the transfer contract yet.

The driver is placed under the kernel tier (src/kernel/platform/posix/) and hooked into zephyr_dev[] in src/kernel/lib/dai-kernel.c, following the user/kernel split introduced after the original change. Using the devicetree device model means the production dai_get_device() lookup is exercised unmodified, with no fuzz specific branching in shared firmware code.

Verified on IPC3 and IPC4 builds under both ASan and UBSan. Crafted copier INIT_INSTANCE seeds covering nine gateway classes hit copier_dai_create() 36 times, dai_get_device() 20 times, dai_common_new() 20 times, posix_dai_probe() 18 times, posix_dai_config_set() 18 times and dai_set_config() 18 times.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:54
@tmleman
tmleman force-pushed the topic/upstream/pr/posix/add_virtual_dai branch from af62a32 to d75abe4 Compare November 19, 2026 10:57

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.

🟡 Changes recommended

Comments in dai_virtual.c overstate truncated-message detection because reads into zero-filled allocation padding remain valid to sanitizers, so the claims need to be limited to allocation bounds.

1 open issue
What changed in this PR

Adds a configuration-only virtual DAI backend so the native_sim IPC fuzzer can reach SOF’s generic DAI setup paths without audio hardware.

Changes:

  • Defines virtual SSP, DMIC, HDA, ALH, and UAOL devices through devicetree.
  • Implements configuration, property, lifecycle, trigger, and timestamp callbacks without moving audio.
  • Integrates the backend with fuzz configuration, build rules, and standard DAI lookup.
File Description
zephyr/​CMakeLists.txt Builds the virtual driver when enabled.
src/​kernel/​platform/​posix/​dai_virtual.c Implements the configuration-only virtual DAI backend.
src/​kernel/​platform/​Kconfig Adds the fuzz-scoped DAI_POSIX option.
src/​kernel/​lib/​dai-kernel.c Includes virtual devices in standard DAI enumeration.
app/​dts/​bindings/​dai/​zephyr,posix-dai.yaml Defines device type, index, and FIFO-depth properties.
app/​configs/​fuzz_features.conf Enables virtual DAIs for fuzz builds.
app/​boards/​native_sim.overlay Declares 16 virtual DAI instances across five types.

Review effort: Balanced

Comment thread src/kernel/platform/posix/dai_virtual.c Resolved
@intel-sofci

intel-sofci commented Nov 19, 2026 •

Copy link
Copy Markdown

PR 11493: test results

Run date: 2026-11-20 13:17 UTC

Tested commit: dca35b691a4789b186dd2316cbb043610ad5b690

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@kv2019i kv2019i 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.

Excellent, very cool!

@lgirdwood

Copy link
Copy Markdown
Member

@tmleman can you resolve the copilot comment and check the CI thanks !

@tmleman
tmleman force-pushed the topic/upstream/pr/posix/add_virtual_dai branch from d75abe4 to dca35b6 Compare November 20, 2026 11:52
native_sim has no audio hardware and no registered Zephyr DAI device, so
zephyr_dev[] is empty and dai_get_device() can never match. Every DAI
gateway request therefore failed at

  copier_dai_create -> dai_common_new -> dai_get -> dai_get_device

which hid the whole generic SOF DAI construction, configuration and
property layer from the IPC fuzzer.

Add a devicetree-described virtual DAI backend for the POSIX platform and
include it in the native DAI enumeration behind the new CONFIG_DAI_POSIX,
enabled only by the fuzz feature configuration. The overlay declares SSP
0-3, DMIC 0-1, HDA 0-3, ALH 0-3 and UAOL 0-1, so a gateway node id
carrying a realistic index resolves to a device.

The model is deliberately configuration-only: probe/remove, config
set/get, trigger, the timestamping ops and the properties SOF queries
(FIFO address and depth, handshake id, stream id) are implemented, the
type-specific blob is read through but never parsed, and no data is
moved. Reading every byte of the host supplied blob lets the sanitizers
validate the (pointer, size) pair the IPC layer hands down, which
memcpy_s() cannot do because it only guards the destination. Reporting a
rate and channel count of zero keeps dai_verify_params() from rejecting
otherwise valid streams, and prepare still stops cleanly in the POSIX DMA
model, which does not implement the transfer contract yet.

The driver is placed under the kernel tier (src/kernel/platform/posix/)
and hooked into zephyr_dev[] in src/kernel/lib/dai-kernel.c, following
the user/kernel split introduced after the original change. Using the
devicetree device model means the production dai_get_device() lookup is
exercised unmodified, with no fuzz specific branching in shared firmware
code.

Verified on IPC3 and IPC4 builds under both ASan and UBSan. Crafted
copier INIT_INSTANCE seeds covering nine gateway classes hit
copier_dai_create() 36 times, dai_get_device() 20 times, dai_common_new()
20 times, posix_dai_probe() 18 times, posix_dai_config_set() 18 times and
dai_set_config() 18 times.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@lgirdwood
lgirdwood merged commit d1e9aca into thesofproject:main Nov 20, 2026
44 of 46 checks passed
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.

5 participants