summary refs log tree commit diff
path: root/devices/src/virtio/rng.rs
diff options
context:
space:
mode:
authorChuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>2019-12-03 09:48:28 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-03 11:12:04 +0000
commit313f64127f812b5ffa97fcfeb74a1e98e64f6fbf (patch)
treedd776e0bf4a9ec126ff88c30c0e013d4f8f58ca8 /devices/src/virtio/rng.rs
parent572ca0cca2b53157ce857676b1f054464d4522bd (diff)
downloadcrosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar.gz
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar.bz2
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar.lz
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar.xz
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.tar.zst
crosvm-313f64127f812b5ffa97fcfeb74a1e98e64f6fbf.zip
virtio: implement reset for balloon/rng/blk/net
The reset method will be called when guest virtio driver is
resetting the device. Currently the balloon/Rng/block/net
virtio drivers will re-configure the virt queue during the
reset so they required to be re-activated for using the new
virt queue configurations. To support this, need these device
models to return back the moved ownership of the important
variables so that they can do the re-activate.

BUG=chromium:1030609
TEST=Launch linux guest and follow the reproduce steps in BUG#1030609 to check
if balloon/Rng/block/net driver still complain failure.

Change-Id: I5b40fd303ea334484c590982e3e0874ea4e854ee
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971097
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'devices/src/virtio/rng.rs')
-rw-r--r--devices/src/virtio/rng.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/devices/src/virtio/rng.rs b/devices/src/virtio/rng.rs
index a7fc3d7..b8e4bb1 100644
--- a/devices/src/virtio/rng.rs
+++ b/devices/src/virtio/rng.rs
@@ -121,7 +121,7 @@ impl Worker {
 /// Virtio device for exposing entropy to the guest OS through virtio.
 pub struct Rng {
     kill_evt: Option<EventFd>,
-    worker_thread: Option<thread::JoinHandle<()>>,
+    worker_thread: Option<thread::JoinHandle<Worker>>,
     random_file: Option<File>,
 }
 
@@ -203,6 +203,7 @@ impl VirtioDevice for Rng {
                             random_file,
                         };
                         worker.run(queue_evts.remove(0), kill_evt);
+                        worker
                     });
 
             match worker_result {
@@ -216,4 +217,27 @@ impl VirtioDevice for Rng {
             }
         }
     }
+
+    fn reset(&mut self) -> bool {
+        if let Some(kill_evt) = self.kill_evt.take() {
+            if kill_evt.write(1).is_err() {
+                error!("{}: failed to notify the kill event", self.debug_label());
+                return false;
+            }
+        }
+
+        if let Some(worker_thread) = self.worker_thread.take() {
+            match worker_thread.join() {
+                Err(_) => {
+                    error!("{}: failed to get back resources", self.debug_label());
+                    return false;
+                }
+                Ok(worker) => {
+                    self.random_file = Some(worker.random_file);
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }