audio_streams, snd: Add stream start and stop

Add start() and stop() lifecycle methods to AsyncCaptureBufferStream
and CaptureBufferReader traits, and invoke them in the virtio-snd PCM
capture worker loop upon WorkerStatus transitions.

Currently, AsyncCaptureBufferStream only exposes next_capture_buffer(),
with no explicit mechanism to start or stop the underlying audio stream
upon guest PCM state changes (such as VIRTIO_SND_R_PCM_START and
VIRTIO_SND_R_PCM_STOP).

This change:
1. Adds start() and stop() methods with default Ok(()) implementations
   to AsyncCaptureBufferStream in audio_streams, including blanket
   implementations for &mut S. start() and stop() are synchronous and
   must return promptly; they must not wait for external events such as
   a permission prompt.
2. Extends CaptureBufferReader in device_virtio_snd with start() and
   stop(), forwarding calls in UnixBufferReader and WinBufferReader.
3. Adds CaptureStreamState and update_capture_stream_state() to
   pcm_worker_loop, invoking buffer_reader.start() and
   buffer_reader.stop() on WorkerStatus transitions without holding
   status_mutex across an await.
4. Implements start() and stop() on android_audio's AudioStream,
   invoking AAudioStream_requestStart() and AAudioStream_requestStop().
5. Adds AAudioStream_requestStop() to AAudio FFI and libaaudio_stub.
6. Gates android_audio with cfg(any(target_os = "android", feature =
   "libaaudio_stub")) to preserve cross-platform builds.

BUG=b:553670496
TEST=tools/dev_container cargo test -p device_virtio_snd
TEST=tools/dev_container cargo test -p android_audio --features libaaudio_stub
TEST=tools/dev_container ./tools/presubmit all

Change-Id: I3976f3c8a92a71c3b112da5dc914d933aa3c54ad
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/8400152
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Mu-Le Lee <mulelee@google.com>
Reviewed-by: Norman Bintang <normanbt@chromium.org>
Commit-Queue: Cassie Wang <cassiewang@google.com>
6 files changed
tree: 1c47f4817eeb7f37c5aa87c1b3278d16063e367b
  1. .agents/
  2. .cargo/
  3. .config/
  4. .devcontainer/
  5. .github/
  6. .vscode/
  7. aarch64/
  8. aarch64_sys_reg/
  9. acpi_tables/
  10. android_audio/
  11. arch/
  12. argh_helpers/
  13. audio_streams_conformance_test/
  14. audio_util/
  15. base/
  16. base_tokio/
  17. bit_field/
  18. common/
  19. cros_async/
  20. cros_fdt/
  21. cros_tracing/
  22. cros_tracing_types/
  23. crosvm_cli/
  24. crosvm_control/
  25. devices/
  26. disk/
  27. docs/
  28. e2e_tests/
  29. ext2/
  30. fuse/
  31. fuzz/
  32. gpu_display/
  33. hypervisor/
  34. infra/
  35. io_uring/
  36. jail/
  37. kernel_cmdline/
  38. kernel_loader/
  39. kvm_sys/
  40. libcras_stub/
  41. linux_input_sys/
  42. logo/
  43. media/
  44. metrics/
  45. metrics_events/
  46. net_sys/
  47. net_util/
  48. perfetto/
  49. power_monitor/
  50. prebuilts/
  51. proc_init/
  52. proto_build_tools/
  53. protos/
  54. resources/
  55. riscv64/
  56. sandbox/
  57. serde_keyvalue/
  58. snapshot/
  59. src/
  60. swap/
  61. system_api/
  62. tests/
  63. third_party/
  64. tools/
  65. tube_transporter/
  66. usb_sys/
  67. usb_util/
  68. vendor/
  69. vfio_sys/
  70. vhost/
  71. virtio_sys/
  72. vm_control/
  73. vm_memory/
  74. win_audio/
  75. win_util/
  76. x86_64/
  77. .dockerignore
  78. .envrc
  79. .gitattributes
  80. .gitignore
  81. .gitmodules
  82. .rustfmt.toml
  83. ARCHITECTURE.md
  84. Cargo.lock
  85. Cargo.toml
  86. CONTRIBUTING.md
  87. DIR_METADATA
  88. LICENSE
  89. mypy.ini
  90. OWNERS
  91. OWNERS_COUNCIL
  92. PRESUBMIT.cfg
  93. pyproject.toml
  94. README.chromeos.md
  95. README.md
  96. rust-toolchain
README.md

crosvm

crosvm logo

The ChromeOS Virtual Machine Monitor

License Documentation Matrix


crosvm is a secure, lightweight, and performant Virtual Machine Monitor (VMM) written in Rust. Originally developed for ChromeOS to run Linux (Crostini) and Android guests (ARCVM). It is now used across multiple products and platforms such as TerminalApp on Android, Cuttlefish and Windows.

crosvm focuses on security through strong isolation and a modern, memory-safe implementation. It leverages hardware-assisted virtualization to provide a robust execution environment for untrusted code.

🌟 Core Philosophy

  • Security First: Built with Rust's memory safety guarantees. Each virtual device can be run in its own sandboxed process with restricted system access.
  • Isolation: Uses Linux namespaces, seccomp filters, and Minijail to create a multi-layered security boundary.
  • Performance: Optimized for modern workloads with features like io_uring, vhost, and an internal async runtime (cros_async).
  • Portability: Supports multiple CPU architectures and hypervisor backends.

🛠️ Technical Specifications

Supported Architectures

  • x86_64
  • aarch64
  • riscv64

Supported Hypervisors

  • Linux/Android: KVM, Gunyah (Qualcomm), GenieZone (MediaTek), Halla (Exynos).
  • Windows: WHPX (Windows Hypervisor Platform), HAXM (Intel).

Virtio Device Support

crosvm implements a wide range of paravirtualized devices via the virtio standard:

  • Network: virtio-net with optional vhost and slirp backends.
  • Storage: virtio-block supporting raw, qcow2, zstd, and Android sparse formats.
  • Graphics: virtio-gpu with 2D and 3D acceleration (via virglrenderer, gfxstream, or vulkano).
  • Display/Input: Integrated virtio gpu cross domain support for wayland passthrough
  • Audio: virtio-snd with backends for CRAS (ChromeOS), AAudio (Android), and more.
  • File System: virtio-fs and virtio-9p.
  • Other: Console, RNG, Balloon, Vsock, TPM, Pmem, Video Decoder/Encoder, etc.

🔒 Security Architecture

crosvm is designed with a “process-per-device” model:

  1. Main Process: Handles VM initialization and core orchestration.
  2. Device Processes: Each virtio device can be forked into its own process.
  3. Sandboxing: Each device process is jailed using Minijail:
    • Namespaces: VFS (pivot_root), PID, User, and Network isolation.
    • Seccomp: Strict BPF filters restrict syscalls to only those required by the specific device.
    • Capabilities: All unnecessary Linux capabilities are dropped.

📖 Documentation

🚀 Getting Started

The recommended way to build and develop crosvm is using the provided development container.

Prerequisites

  • Linux: A modern kernel (5.x+) with KVM access.
  • Podman or Docker: Installed and configured.

Building

Use the dev container to build a release version of crosvm:

./tools/dev_container ./tools/build_release

Basic Usage

Follow this example usage to run a simple Linux guest.

🤝 Community & Support


crosvm is an open-source project licensed under the BSD-3-Clause License.