Skip to content

Commit 2c122e6

Browse files
author
Dorinda Bassey
committed
vhost-device-gpu: Add Initial Implementation
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 device uses the rutabaga_gfx crate to offer two rendering backends: 1. Virglrenderer: - Rutabaga translates OpenGL API and Vulkan calls to an intermediate representation and allows for OpenGL acceleration on the host. 2. Gfxstream: - GLES and Vulkan calls are forwarded to the host. These backends can be used by simply changing the `--gpu-mode` 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: #598 Co-authored-by: Dorinda Bassey <dbassey@redhat.com> Co-authored-by: Matej Hrica <mhrica@redhat.com> Signed-off-by: Dorinda Bassey <dbassey@redhat.com> Signed-off-by: Matej Hrica <mhrica@redhat.com>
1 parent fe02fcd commit 2c122e6

File tree

14 files changed

+4680
-16
lines changed

14 files changed

+4680
-16
lines changed

staging/Cargo.lock

Lines changed: 225 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
resolver = "2"
33
members = [
4+
"vhost-device-gpu",
45
"vhost-device-video",
56
"vhost-device-can",
67
"vhost-device-console",

staging/coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 80.31,
2+
"coverage_score": 80.64,
33
"exclude_path": "",
44
"crate_features": ""
55
}

staging/vhost-device-gpu/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
## Unreleased
3+
4+
### Added
5+
6+
### Changed
7+
8+
### Fixed
9+
10+
### Deprecated

staging/vhost-device-gpu/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "vhost-device-gpu"
3+
version = "0.1.0"
4+
authors = ["Dorinda Bassey <dbassey@redhat.com>", "Matej Hrica <mhrica@redhat.com>"]
5+
description = "A virtio-gpu device using the vhost-user protocol."
6+
repository = "https://github.com/rust-vmm/vhost-device"
7+
readme = "README.md"
8+
keywords = ["gpu", "vhost", "vhost-user", "virtio"]
9+
categories = ["multimedia::video", "virtualization"]
10+
license = "Apache-2.0 OR BSD-3-Clause"
11+
edition = "2021"
12+
publish = false
13+
14+
[features]
15+
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]
16+
17+
[dependencies]
18+
clap = { version = "4.4", features = ["derive"] }
19+
env_logger = "0.11.5"
20+
libc = "0.2"
21+
log = "0.4"
22+
23+
[target.'cfg(not(target_env = "musl"))'.dependencies]
24+
rutabaga_gfx = { version = "0.1.4", features = ["gfxstream", "virgl_renderer"] }
25+
thiserror = "1.0"
26+
vhost = { version = "0.12.1", features = ["vhost-user-backend"] }
27+
vhost-user-backend = "0.16.1"
28+
virtio-bindings = "0.2.2"
29+
virtio-queue = "0.13.0"
30+
vm-memory = "0.15.0"
31+
vmm-sys-util = "0.12.1"
32+
zerocopy = "0.6.3"
33+
34+
[dev-dependencies]
35+
assert_matches = "1.5"
36+
tempfile = "3.13"
37+
virtio-queue = { version = "0.13", features = ["test-utils"] }
38+
vm-memory = { version = "0.15.0", features = ["backend-mmap", "backend-atomic"] }
39+
mockall = "0.13.0"
40+
rusty-fork = "0.3.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-APACHE
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-BSD-3-Clause

staging/vhost-device-gpu/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# vhost-device-gpu - GPU emulation backend daemon
2+
3+
## Synopsis
4+
```shell
5+
vhost-device-gpu --socket-path <SOCKET>
6+
```
7+
8+
## Description
9+
A virtio-gpu device using the vhost-user protocol.
10+
11+
## Options
12+
13+
```text
14+
-s, --socket-path <SOCKET>
15+
vhost-user Unix domain socket path
16+
17+
-h, --help
18+
Print help
19+
20+
-V, --version
21+
Print version
22+
```
23+
24+
## Limitations
25+
26+
We are currently only supporting sharing the display output to QEMU through a
27+
socket using the transfer_read operation triggered by
28+
VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D to transfer data from and to virtio-gpu 3d
29+
resources. It'll be nice to have support for directly sharing display output
30+
resource using dmabuf.
31+
32+
This device does not yet support the VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB,
33+
VIRTIO_GPU_CMD_SET_SCANOUT_BLOB and VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID features.
34+
35+
Currently this crate requires some necessary bits in order to move the crate out of staging:
36+
37+
- Achieving a minimum of ~87% code coverage in the main vhost-device repository,
38+
which requires some additional unit tests to increase code coverage.
39+
- Addition of CLI arguments to specify the exact number of capsets and use
40+
a default capset configuration when no capset is specified rather than using
41+
hard-coded capset value.
42+
43+
## Features
44+
45+
The device leverages the [rutabaga_gfx](https://crates.io/crates/rutabaga_gfx) crate
46+
to provide virglrenderer and gfxstream rendering. With Virglrenderer, Rutabaga
47+
translates OpenGL API and Vulkan calls to an intermediate representation and allows
48+
for OpenGL acceleration on the host. With the gfxstream rendering mode, GLES and
49+
Vulkan calls are forwarded to the host with minimal modification.
50+
51+
## Examples
52+
53+
First start the daemon on the host machine using either of the 2 gpu modes:
54+
55+
1) virgl-renderer
56+
2) gfxstream
57+
58+
```shell
59+
host# vhost-device-gpu --socket-path /tmp/gpu.socket --gpu-mode virgl-renderer
60+
```
61+
62+
With QEMU, there are two device front-ends you can use with this device.
63+
You can either use `vhost-user-gpu-pci` or `vhost-user-vga`, which also
64+
implements VGA, that allows you to see boot messages before the guest
65+
initializes the GPU. You can also use different display outputs (for example
66+
`gtk` or `dbus`).
67+
By default, QEMU also adds another VGA output, use `-vga none` to make
68+
sure it is disabled.
69+
70+
1) Using `vhost-user-gpu-pci`
71+
72+
Start QEMU with the following flags:
73+
74+
```text
75+
-chardev socket,id=vgpu,path=/tmp/gpu.socket \
76+
-device vhost-user-gpu-pci,chardev=vgpu,id=vgpu \
77+
-object memory-backend-memfd,share=on,id=mem0,size=4G, \
78+
-machine q35,memory-backend=mem0,accel=kvm \
79+
-display gtk,gl=on,show-cursor=on \
80+
-vga none
81+
```
82+
83+
2) Using `vhost-user-vga`
84+
85+
Start QEMU with the following flags:
86+
87+
```text
88+
-chardev socket,id=vgpu,path=/tmp/gpu.socket \
89+
-device vhost-user-vga,chardev=vgpu,id=vgpu \
90+
-object memory-backend-memfd,share=on,id=mem0,size=4G, \
91+
-machine q35,memory-backend=mem0,accel=kvm \
92+
-display gtk,gl=on,show-cursor=on \
93+
-vga none
94+
```
95+
96+
## License
97+
98+
This project is licensed under either of
99+
100+
- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
101+
- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause)

staging/vhost-device-gpu/rustfmt.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
edition = "2018"
2+
format_generated_files = false
3+
format_code_in_doc_comments = true
4+
format_strings = true
5+
imports_granularity = "Crate"
6+
group_imports = "StdExternalCrate"
7+
wrap_comments = true

0 commit comments

Comments
 (0)