Based on cloud-hypervisor 97699a521fbdffd0166bc55be37c13bb6bc1949f.
vm-virtio: vhost-user: Vring should be enabled after initialization
As mentioned in the vhost-user specification, each ring is initialized in a stopped state. This means each ring should be enabled only after it has been correctly initialized.
devices/src/virtio/vhost_user/mod.rs | 2 -- devices/src/virtio/vhost_user/vu_common_ctrl.rs | 13 ++++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/devices/src/virtio/vhost_user/mod.rs b/devices/src/virtio/vhost_user/mod.rs index 99d8e651..43fc6350 100644 --- a/devices/src/virtio/vhost_user/mod.rs +++ b/devices/src/virtio/vhost_user/mod.rs @@ -70,8 +70,6 @@ pub enum Error { VhostUserSetVringKick(VhostError), /// Set vring enable failed. VhostUserSetVringEnable(VhostError), - /// Vhost-user setup vring failed. - VhostUserSetupVringFailed, /// Failed to create vhost eventfd. VhostIrqCreate(std::io::Error), /// Failed to read vhost eventfd. diff --git a/devices/src/virtio/vhost_user/vu_common_ctrl.rs b/devices/src/virtio/vhost_user/vu_common_ctrl.rs index 38b7b4f2..b594b177 100644 --- a/devices/src/virtio/vhost_user/vu_common_ctrl.rs +++ b/devices/src/virtio/vhost_user/vu_common_ctrl.rs @@ -87,6 +87,9 @@ pub fn setup_vhost_user_vring( vu.set_vring_kick(queue_index, &queue_evts[queue_index]) .map_err(Error::VhostUserSetVringKick)?; + + vu.set_vring_enable(queue_index, true) + .map_err(Error::VhostUserSetVringEnable)?; } Ok(vu_interrupt_list) @@ -99,17 +102,9 @@ pub fn setup_vhost_user( queue_evts: Vec<EventFd>, acked_features: u64, ) -> Result<Vec<(vmm_sys_util::eventfd::EventFd, Queue)>> { - for i in 0..queues.len() { - vu.set_vring_enable(i, true) - .map_err(Error::VhostUserSetVringEnable)?; - } - let backend_features = vu.get_features().unwrap(); vu.set_features(acked_features & backend_features) .map_err(Error::VhostUserSetFeatures)?; - match setup_vhost_user_vring(vu, mem, queues, queue_evts) { - Ok(vu_interrupt_list) => Ok(vu_interrupt_list), - Err(_) => Err(Error::VhostUserSetupVringFailed), - } + setup_vhost_user_vring(vu, mem, queues, queue_evts) } -- 2.31.0