summary refs log tree commit diff
path: root/devices/src/virtio/virtio_pci_device.rs
diff options
context:
space:
mode:
authorChuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>2019-12-03 09:34:39 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-03 11:12:01 +0000
commit572ca0cca2b53157ce857676b1f054464d4522bd (patch)
treea62c3822353642d8246d3215d99c6de69eff6a64 /devices/src/virtio/virtio_pci_device.rs
parent3dc90d0124ca4d797ff9119daf16016b225c1d96 (diff)
downloadcrosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar.gz
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar.bz2
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar.lz
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar.xz
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.tar.zst
crosvm-572ca0cca2b53157ce857676b1f054464d4522bd.zip
virtio: call virtio device reset method for reset
It refers to the implementation of the Cloud-hypervisor
commit:
- vm-virtio: Reset underlying device on driver request

If the driver triggers a reset by writing zero into the status register
then reset the underlying device if supported. A device reset also
requires resetting various aspects of the queue.

The reset method of a virtio device might return false if it is failed
to reset the device or it is not implemented. In this case, we don't
reset the queues. Otherwise the queues will also be reset together with
a successful device reset.

BUG=chromium:1030609
TEST=cargo test -p devices

Change-Id: Iad2be38149e423a79d8366dc72e570a1d6eb297c
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971096
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'devices/src/virtio/virtio_pci_device.rs')
-rw-r--r--devices/src/virtio/virtio_pci_device.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs
index dbfaa69..2be272c 100644
--- a/devices/src/virtio/virtio_pci_device.rs
+++ b/devices/src/virtio/virtio_pci_device.rs
@@ -297,6 +297,11 @@ impl VirtioPciDevice {
             && self.common_config.driver_status & DEVICE_FAILED as u8 == 0
     }
 
+    /// Determines if the driver has requested the device reset itself
+    fn is_reset_requested(&self) -> bool {
+        self.common_config.driver_status == DEVICE_RESET as u8
+    }
+
     fn are_queues_valid(&self) -> bool {
         if let Some(mem) = self.mem.as_ref() {
             self.queues.iter().all(|q| q.is_valid(mem))
@@ -688,5 +693,16 @@ impl PciDevice for VirtioPciDevice {
                 }
             }
         }
+
+        // Device has been reset by the driver
+        if self.device_activated && self.is_reset_requested() {
+            if self.device.reset() {
+                self.device_activated = false;
+                // reset queues
+                self.queues.iter_mut().for_each(Queue::reset);
+                // select queue 0 by default
+                self.common_config.queue_select = 0;
+            }
+        }
     }
 }