generated from rust-vmm/crate-template
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[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
Nov 20, 2024
1 parent
b7321b7
commit 21335fe
Showing
14 changed files
with
4,730 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"vhost-device-gpu", | ||
"vhost-device-video", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"coverage_score": 74.82, | ||
"coverage_score": 79.82, | ||
"exclude_path": "", | ||
"crate_features": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
## Unreleased | ||
|
||
### Added | ||
|
||
### Changed | ||
|
||
### Fixed | ||
|
||
### Deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[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", "vhost-user", "virtio"] | ||
categories = ["multimedia::video", "virtualization"] | ||
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 = { version = "0.12.1", features = ["vhost-user-backend"] } | ||
vhost-user-backend = "0.16.1" | ||
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" | ||
tempfile = "3.13" | ||
virtio-queue = { version = "0.13", features = ["test-utils"] } | ||
vm-memory = { version = "0.15.0", features = ["backend-mmap", "backend-atomic"] } | ||
mockall = "0.13.0" | ||
rusty-fork = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE-BSD-3-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# 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 | ||
``` | ||
|
||
## Limitations | ||
|
||
We are currently only supporting sharing the display output to QEMU through a | ||
socket using the transfer_read operation triggered by | ||
VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D to transfer data from and to virtio-gpu 3d | ||
resources. It'll be nice to have support for directly sharing display output | ||
resource using dmabuf. | ||
|
||
This device does not yet support the VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB, | ||
VIRTIO_GPU_CMD_SET_SCANOUT_BLOB and VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID features. | ||
|
||
Currently this crate requires some necessary bits in order to move the crate out of staging: | ||
|
||
- Achieving a minimum of ~87% code coverage in the main vhost-device repository, | ||
which requires some additional unit tests to increase code coverage. | ||
- Addition of CLI arguments to specify the exact number of capsets and use | ||
a default capset configuration when no capset is specified rather than using | ||
hard-coded capset value. | ||
|
||
## Features | ||
|
||
The device leverages the [rutabaga_gfx](https://crates.io/crates/rutabaga_gfx) crate | ||
to provide virglrenderer and gfxstream rendering. With Virglrenderer, Rutabaga | ||
translates OpenGL API and Vulkan calls to an intermediate representation and allows | ||
for OpenGL acceleration on the host. With the gfxstream rendering mode, GLES and | ||
Vulkan calls are forwarded to the host with minimal modification. | ||
|
||
## Examples | ||
|
||
First start the daemon on the host machine using either of the 2 gpu modes: | ||
|
||
1) virgl-renderer | ||
2) gfxstream | ||
|
||
```shell | ||
host# vhost-device-gpu --socket-path /tmp/gpu.socket --gpu-mode virgl-renderer | ||
``` | ||
|
||
With QEMU, there are two device front-ends 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
edition = "2018" | ||
format_generated_files = false | ||
format_code_in_doc_comments = true | ||
format_strings = true | ||
imports_granularity = "Crate" | ||
group_imports = "StdExternalCrate" | ||
wrap_comments = true |
Oops, something went wrong.