Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhost-device-rng: add support for standalone daemons #394

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions crates/rng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion crates/rng/src/vhu_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably virtio-bindings should get extended with virtio_ids.h bindings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this for scsi recently, so I can propose a PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


type Result<T> = std::result::Result<T, VuRngError>;
type RngDescriptorChain = DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap<()>>>;
Expand Down Expand Up @@ -222,6 +223,15 @@ impl<T: 'static + Read + Sync + Send> VhostUserBackendMut<VringRwLock, ()> 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) {
Expand Down