summary refs log tree commit diff
diff options
context:
space:
mode:
authorChuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>2020-01-13 10:27:10 +0800
committerCommit Bot <commit-bot@chromium.org>2020-02-06 03:25:33 +0000
commit3eb7927bcd1aeb5578aab3109b9fb90c7a641af5 (patch)
tree15e28704a6bf0478852e57988e15e46ee7b4606c
parentf054de59b3d6efbfa7daa6d4300bec9ca94b778a (diff)
downloadcrosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar.gz
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar.bz2
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar.lz
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar.xz
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.tar.zst
crosvm-3eb7927bcd1aeb5578aab3109b9fb90c7a641af5.zip
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 <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009664
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
-rw-r--r--devices/src/virtio/vhost/net.rs10
-rw-r--r--devices/src/virtio/vhost/vsock.rs10
-rw-r--r--devices/src/virtio/vhost/worker.rs6
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<T: Vhost> {
     vhost_handle: T,
     vhost_interrupt: Vec<EventFd>,
     acked_features: u64,
+    kill_evt: EventFd,
 }
 
 impl<T: Vhost> Worker<T> {
@@ -29,6 +30,7 @@ impl<T: Vhost> Worker<T> {
         vhost_interrupt: Vec<EventFd>,
         interrupt: Interrupt,
         acked_features: u64,
+        kill_evt: EventFd,
     ) -> Worker<T> {
         Worker {
             interrupt,
@@ -36,6 +38,7 @@ impl<T: Vhost> Worker<T> {
             vhost_handle,
             vhost_interrupt,
             acked_features,
+            kill_evt,
         }
     }
 
@@ -43,7 +46,6 @@ impl<T: Vhost> Worker<T> {
         &mut self,
         queue_evts: Vec<EventFd>,
         queue_sizes: &[u16],
-        kill_evt: EventFd,
         activate_vqs: F1,
         cleanup_vqs: F2,
     ) -> Result<()>
@@ -104,7 +106,7 @@ impl<T: Vhost> Worker<T> {
 
         let poll_ctx: PollContext<Token> = PollContext::build_with(&[
             (self.interrupt.get_resample_evt(), Token::InterruptResample),
-            (&kill_evt, Token::Kill),
+            (&self.kill_evt, Token::Kill),
         ])
         .map_err(Error::CreatePollContext)?;