Skip to content

Commit

Permalink
vhost-device-gpu: Add Initial Implementation
Browse files Browse the repository at this point in the history
This program is a vhost-user backend daemon that provides
VIRTIO GPU device emulation as specified in the VIRTIO Spec v.1.2
https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html
This crate utilizes the rutabaga crate from crosvm with some
minor modification to rutabaga crate to fix compilation.
This crate depends on this PR[rust-vmm/vhost#239]
that implements support for QEMU's vhost-user-gpu protocol.

This crate supports both gfxstream and virglrenderer library
either of these libraries can be used by simply changing the
`renderer` command line option.
This crate also includes some modifications from libkrun virtio-gpu device
https://github.com/containers/libkrun/tree/main/src/devices/src/virtio/gpu

Fixes: rust-vmm#598

Co-authored-by: Dorinda Bassey <[email protected]>
Co-authored-by: Matej Hrica <[email protected]>

Signed-off-by: Dorinda Bassey <[email protected]>
Signed-off-by: Matej Hrica <[email protected]>
  • Loading branch information
Dorinda Bassey committed Oct 16, 2024
1 parent e9819c0 commit 3e89404
Show file tree
Hide file tree
Showing 13 changed files with 4,538 additions and 23 deletions.
294 changes: 272 additions & 22 deletions staging/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions staging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"vhost-device-gpu",
"vhost-device-video",
"vhost-device-can",
"vhost-device-console",
Expand Down
2 changes: 1 addition & 1 deletion staging/coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 71.04,
"coverage_score": 62.72,
"exclude_path": "",
"crate_features": ""
}
14 changes: 14 additions & 0 deletions staging/vhost-device-gpu/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
## [Unreleased]

### Added

### Changed

### Fixed

### Deprecated

## [0.1.0]

First release
37 changes: 37 additions & 0 deletions staging/vhost-device-gpu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "vhost-device-gpu"
version = "0.1.0"
authors = ["Dorinda Bassey <[email protected]>", "Matej Hrica <[email protected]>"]
description = "A virtio-gpu device using the vhost-user protocol."
repository = "https://github.com/rust-vmm/vhost-device"
readme = "README.md"
keywords = ["gpu", "vhost", "virt", "backend"]
license = "Apache-2.0 OR BSD-3-Clause"
edition = "2021"
publish = false

[features]
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]

[dependencies]
clap = { version = "4.4", features = ["derive"] }
env_logger = "0.11.5"
libc = "0.2"
log = "0.4"
[target.'cfg(not(target_env = "musl"))'.dependencies]
rutabaga_gfx = { version = "0.1.4", features = ["gfxstream", "virgl_renderer"] }
thiserror = "1.0"
vhost = { git = "https://github.com/rust-vmm/vhost.git", package = "vhost", branch = "main", features = ["vhost-user-backend"] }
vhost-user-backend = { git = "https://github.com/rust-vmm/vhost.git", package = "vhost-user-backend", branch = "main", features = ["gpu-socket"] }
virtio-bindings = "0.2.2"
virtio-queue = "0.13.0"
vm-memory = "0.15.0"
vmm-sys-util = "0.12.1"
zerocopy = "0.6.3"

[dev-dependencies]
assert_matches = "1.5"
virtio-queue = { version = "0.13", features = ["test-utils"] }
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-atomic"] }
mockall = "0.13.0"
rusty-fork = "0.3.0"
1 change: 1 addition & 0 deletions staging/vhost-device-gpu/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../LICENSE-APACHE
1 change: 1 addition & 0 deletions staging/vhost-device-gpu/LICENSE-BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../LICENSE-BSD-3-Clause
67 changes: 67 additions & 0 deletions staging/vhost-device-gpu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# vhost-device-gpu - GPU emulation backend daemon

## Synopsis
```shell
vhost-device-gpu --socket-path <SOCKET>
```

## Description
A virtio-gpu device using the vhost-user protocol.

## Options

```text
-s, --socket-path <SOCKET>
vhost-user Unix domain socket path
-h, --help
Print help
-V, --version
Print version
```

## Examples

First start the daemon on the host machine:

```shell
host# vhost-device-gpu --socket-path /tmp/gpu.socket
```

With QEMU, there are two device frontends you can use with this device.
You can either use `vhost-user-gpu-pci` or `vhost-user-vga`, which also
implements VGA, that allows you to see boot messages before the guest
initializes the GPU. You can also use different display outputs (for example
`gtk` or `dbus`).
By default, QEMU also adds another VGA output, use `-vga none` to make
sure it is disabled.

1) Using `vhost-user-gpu-pci` Start QEMU with the following flags:

```text
-chardev socket,id=vgpu,path=/tmp/gpu.socket \
-device vhost-user-gpu-pci,chardev=vgpu,id=vgpu \
-object memory-backend-memfd,share=on,id=mem0,size=4G, \
-machine q35,memory-backend=mem0,accel=kvm \
-display gtk,gl=on,show-cursor=on \
-vga none
```

2) Using `vhost-user-vga` Start QEMU with the following flags:

```text
-chardev socket,id=vgpu,path=/tmp/gpu.socket \
-device vhost-user-vga,chardev=vgpu,id=vgpu \
-object memory-backend-memfd,share=on,id=mem0,size=4G, \
-machine q35,memory-backend=mem0,accel=kvm \
-display gtk,gl=on,show-cursor=on \
-vga none
```

## License

This project is licensed under either of

- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
Loading

0 comments on commit 3e89404

Please sign in to comment.