From f29c2f18f4004a063212769455fd077c4c2dee8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 7 Jul 2023 17:52:56 +0100 Subject: [PATCH] vhost-device-rng: add support for standalone daemons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is fairly simple for the backend we just need to implement the specs message. The handling of GET/SET_STATUS is done by vhost internals. Signed-off-by: Alex Bennée --- Cargo.lock | 47 ++++++++++++++++++++++++++++++--------- crates/rng/Cargo.toml | 9 ++++++-- crates/rng/src/vhu_rng.rs | 12 +++++++++- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fafaafe7..a0919add 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1304,6 +1304,17 @@ dependencies = [ "vmm-sys-util", ] +[[package]] +name = "vhost" +version = "0.8.0" +source = "git+https://github.com/stsquad/vhost?branch=standalone/get-specs#b4313a1fcfe5aaba69efedbc7142b54891db2215" +dependencies = [ + "bitflags 1.3.2", + "libc", + "vm-memory", + "vmm-sys-util", +] + [[package]] name = "vhost-device-gpio" version = "0.1.0" @@ -1314,8 +1325,8 @@ dependencies = [ "libgpiod", "log", "thiserror", - "vhost", - "vhost-user-backend", + "vhost 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vhost-user-backend 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1331,8 +1342,8 @@ dependencies = [ "libc", "log", "thiserror", - "vhost", - "vhost-user-backend", + "vhost 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vhost-user-backend 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1351,8 +1362,8 @@ dependencies = [ "rand", "tempfile", "thiserror", - "vhost", - "vhost-user-backend", + "vhost 0.8.0 (git+https://github.com/stsquad/vhost?branch=standalone/get-specs)", + "vhost-user-backend 0.10.0 (git+https://github.com/stsquad/vhost?branch=standalone/get-specs)", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1370,8 +1381,8 @@ dependencies = [ "num_enum", "tempfile", "thiserror", - "vhost", - "vhost-user-backend", + "vhost 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vhost-user-backend 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1386,7 +1397,21 @@ checksum = "e3ea9d5e8ec847cde4df1c04e586698a479706fd6beca37323f9d425b24b4c2f" dependencies = [ "libc", "log", - "vhost", + "vhost 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "virtio-bindings", + "virtio-queue", + "vm-memory", + "vmm-sys-util", +] + +[[package]] +name = "vhost-user-backend" +version = "0.10.0" +source = "git+https://github.com/stsquad/vhost?branch=standalone/get-specs#b4313a1fcfe5aaba69efedbc7142b54891db2215" +dependencies = [ + "libc", + "log", + "vhost 0.8.0 (git+https://github.com/stsquad/vhost?branch=standalone/get-specs)", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1408,8 +1433,8 @@ dependencies = [ "serde_yaml", "serial_test", "thiserror", - "vhost", - "vhost-user-backend", + "vhost 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vhost-user-backend 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "virtio-bindings", "virtio-queue", "virtio-vsock", diff --git a/crates/rng/Cargo.toml b/crates/rng/Cargo.toml index dd71b189..d7617cf9 100644 --- a/crates/rng/Cargo.toml +++ b/crates/rng/Cargo.toml @@ -21,8 +21,13 @@ log = "0.4" rand = "0.8.5" tempfile = "3.5" thiserror = "1.0" -vhost = { version = "0.8", features = ["vhost-user-slave"] } -vhost-user-backend = "0.10" +# vhost = { version = "0.8", features = ["vhost-user-slave"] } +# vhost-user-backend = "0.10" +# vhost = { path = "../../../vhost.git/crates/vhost/" } +# vhost-user-backend = { path = "../../../vhost.git/crates/vhost-user-backend/" } +vhost = { git = "https://github.com/stsquad/vhost", branch = "standalone/get-specs" } +vhost-user-backend = { git = "https://github.com/stsquad/vhost", branch = "standalone/get-specs" } + virtio-bindings = "0.2.1" virtio-queue = "0.9" vm-memory = "0.12" diff --git a/crates/rng/src/vhu_rng.rs b/crates/rng/src/vhu_rng.rs index d51755ef..caf267ed 100644 --- a/crates/rng/src/vhu_rng.rs +++ b/crates/rng/src/vhu_rng.rs @@ -13,7 +13,7 @@ use std::time::{Duration, Instant}; use std::{convert, io, result}; use thiserror::Error as ThisError; -use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; +use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures, VhostUserBackendSpecs}; use vhost_user_backend::{VhostUserBackendMut, VringRwLock, VringT}; use virtio_bindings::bindings::virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1}; use virtio_bindings::bindings::virtio_ring::{ @@ -28,6 +28,7 @@ use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; const QUEUE_SIZE: usize = 1024; const NUM_QUEUES: usize = 1; +const VIRTIO_ID_RNG: u32 = 4; type Result = std::result::Result; type RngDescriptorChain = DescriptorChain>>; @@ -222,6 +223,15 @@ impl VhostUserBackendMut for V fn protocol_features(&self) -> VhostUserProtocolFeatures { VhostUserProtocolFeatures::MQ + | VhostUserProtocolFeatures::STATUS + | VhostUserProtocolFeatures::STANDALONE + } + + fn specs(&self) -> VhostUserBackendSpecs { + VhostUserBackendSpecs::new(VIRTIO_ID_RNG, + 0, + NUM_QUEUES as u32, + NUM_QUEUES as u32) } fn set_event_idx(&mut self, enabled: bool) {