devices: vhost-user: Avoid dropping handler on fs exit
In commit 4c7cab5c5aa4 ("devices: vhost-user: Return Ok(()) on client
exit in run_handler"), `start_device` in vhost-user-fs passed
`&mut fs_device` to `conn.run_backend(&mut fs_device, &ex)` so that
`FsBackend` (`PassthroughFs`) would not be dropped before
`std::process::exit(0)`.
However, `conn.run_backend` still owned `DeviceRequestHandler` and
dropped it when the client exited, before `std::process::exit(0)` was
reached. Dropping `DeviceRequestHandler` dropped `GuestMemory`,
invoking `munmap()` and `close(memfd)` across gigabytes of ARCVM guest
RAM while still in userspace (~350ms-1,150ms), causing `ui-post-stop`
`process_killer` to send `SIGKILL` (`signal 9`) to the child process
and triggering a panic in the parent process (b:563911411).
Fix this and address post-submit review feedback on CL 8371801 by:
1. Changing `run_req_handler` to borrow
`handler: &'e mut (dyn vmm_vhost::Backend + 'e)` instead of taking
ownership of `Box<dyn vmm_vhost::Backend + 'e>`.
2. Constructing `let mut handler = DeviceRequestHandler::new(fs_device)`
on `start_device`'s stack in `fs/sys/linux.rs` and passing
`&mut handler` to `conn.run_req_handler(&mut handler, &ex)`, so
neither `DeviceRequestHandler` (`GuestMemory`) nor `FsBackend`
(`PassthroughFs`) is dropped before `std::process::exit(0)` enters
`exit_group(0)` in the kernel.
3. Deleting the blanket `impl VhostUserDevice for &mut T` and
`for Box<T>` in `handler.rs`, while keeping `DeviceRequestHandler`
with a single owned `new(backend: T)` constructor.
BUG=b:563911411
BUG=b:558685652
BUG=b:440937769
TEST=cargo test -p devices --features test-util --lib -- virtio::vhost_user_backend
TEST=cargo test -p vmm_vhost -p device_virtio_block -p device_virtio_console -p device_virtio_net -p device_virtio_snd
TAG=agy
CONV=9979768c-71e6-49a9-8ad4-0baa8c3bb574
Change-Id: I76b12846c6606515d7b7f73b5f61d0b9a2b93cce
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/8461802
Commit-Queue: Yoshiki IGUCHI <yoshiki@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Yoshiki IGUCHI <yoshiki@chromium.org>
The ChromeOS Virtual Machine Monitor
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.
io_uring, vhost, and an internal async runtime (cros_async).crosvm implements a wide range of paravirtualized devices via the virtio standard:
virtio-net with optional vhost and slirp backends.virtio-block supporting raw, qcow2, zstd, and Android sparse formats.virtio-gpu with 2D and 3D acceleration (via virglrenderer, gfxstream, or vulkano).virtio-snd with backends for CRAS (ChromeOS), AAudio (Android), and more.virtio-fs and virtio-9p.crosvm is designed with a “process-per-device” model:
forked into its own process.The recommended way to build and develop crosvm is using the provided development container.
Use the dev container to build a release version of crosvm:
./tools/dev_container ./tools/build_release
Follow this example usage to run a simple Linux guest.
#crosvm channel on Matrix.crosvm is an open-source project licensed under the BSD-3-Clause License.