From 3eb7927bcd1aeb5578aab3109b9fb90c7a641af5 Mon Sep 17 00:00:00 2001 From: Chuanxiao Dong Date: Mon, 13 Jan 2020 10:27:10 +0800 Subject: vhost: put kill eventfd to Worker worker.run might encounter error when running but we still need it to give the ownerships of the kill eventfd back so that it can have a second round activate. And Worker structure also contains several other eventfds which will be needed for a second round activate so change to put this eventfd into Worker as well. BUG=None TEST=launch Crosvm guest with vhost-net and vsock. Both of them work fine. TEST=cargo test -p devices Change-Id: I34477cfa3de23d7ab849f741d0ffb098c720a629 Signed-off-by: Chuanxiao Dong Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009664 Reviewed-by: Daniel Verkamp Tested-by: kokoro Tested-by: Dylan Reid --- devices/src/virtio/vhost/net.rs | 10 +++------- devices/src/virtio/vhost/vsock.rs | 10 +++------- devices/src/virtio/vhost/worker.rs | 6 ++++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index 1107e9f..e9dcf14 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -197,6 +197,7 @@ where vhost_interrupt, interrupt, acked_features, + kill_evt, ); let activate_vqs = |handle: &U| -> Result<()> { for idx in 0..NUM_QUEUES { @@ -214,13 +215,8 @@ where } Ok(()) }; - let result = worker.run( - queue_evts, - QUEUE_SIZES, - kill_evt, - activate_vqs, - cleanup_vqs, - ); + let result = + worker.run(queue_evts, QUEUE_SIZES, activate_vqs, cleanup_vqs); if let Err(e) = result { error!("net worker thread exited with error: {}", e); } diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs index 99af8ce..03826ff 100644 --- a/devices/src/virtio/vhost/vsock.rs +++ b/devices/src/virtio/vhost/vsock.rs @@ -168,6 +168,7 @@ impl VirtioDevice for Vsock { interrupts, interrupt, acked_features, + kill_evt, ); let activate_vqs = |handle: &VhostVsockHandle| -> Result<()> { handle.set_cid(cid).map_err(Error::VhostVsockSetCid)?; @@ -175,13 +176,8 @@ impl VirtioDevice for Vsock { Ok(()) }; let cleanup_vqs = |_handle: &VhostVsockHandle| -> Result<()> { Ok(()) }; - let result = worker.run( - queue_evts, - QUEUE_SIZES, - kill_evt, - activate_vqs, - cleanup_vqs, - ); + let result = + worker.run(queue_evts, QUEUE_SIZES, activate_vqs, cleanup_vqs); if let Err(e) = result { error!("vsock worker thread exited with error: {:?}", e); } diff --git a/devices/src/virtio/vhost/worker.rs b/devices/src/virtio/vhost/worker.rs index 9450929..630edaa 100644 --- a/devices/src/virtio/vhost/worker.rs +++ b/devices/src/virtio/vhost/worker.rs @@ -20,6 +20,7 @@ pub struct Worker { vhost_handle: T, vhost_interrupt: Vec, acked_features: u64, + kill_evt: EventFd, } impl Worker { @@ -29,6 +30,7 @@ impl Worker { vhost_interrupt: Vec, interrupt: Interrupt, acked_features: u64, + kill_evt: EventFd, ) -> Worker { Worker { interrupt, @@ -36,6 +38,7 @@ impl Worker { vhost_handle, vhost_interrupt, acked_features, + kill_evt, } } @@ -43,7 +46,6 @@ impl Worker { &mut self, queue_evts: Vec, queue_sizes: &[u16], - kill_evt: EventFd, activate_vqs: F1, cleanup_vqs: F2, ) -> Result<()> @@ -104,7 +106,7 @@ impl Worker { let poll_ctx: PollContext = PollContext::build_with(&[ (self.interrupt.get_resample_evt(), Token::InterruptResample), - (&kill_evt, Token::Kill), + (&self.kill_evt, Token::Kill), ]) .map_err(Error::CreatePollContext)?; -- cgit 1.4.1