mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
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>
This commit is contained in:
parent
3dc90d0124
commit
572ca0cca2
3 changed files with 29 additions and 0 deletions
|
@ -49,6 +49,7 @@ pub use self::wl::*;
|
|||
use std::cmp;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
const DEVICE_RESET: u32 = 0x0;
|
||||
const DEVICE_ACKNOWLEDGE: u32 = 0x01;
|
||||
const DEVICE_DRIVER: u32 = 0x02;
|
||||
const DEVICE_DRIVER_OK: u32 = 0x04;
|
||||
|
|
|
@ -245,6 +245,18 @@ impl Queue {
|
|||
min(self.size, self.max_size)
|
||||
}
|
||||
|
||||
/// Reset queue to a clean state
|
||||
pub fn reset(&mut self) {
|
||||
self.ready = false;
|
||||
self.size = self.max_size;
|
||||
self.vector = VIRTIO_MSI_NO_VECTOR;
|
||||
self.desc_table = GuestAddress(0);
|
||||
self.avail_ring = GuestAddress(0);
|
||||
self.used_ring = GuestAddress(0);
|
||||
self.next_avail = Wrapping(0);
|
||||
self.next_used = Wrapping(0);
|
||||
}
|
||||
|
||||
pub fn is_valid(&self, mem: &GuestMemory) -> bool {
|
||||
let queue_size = self.actual_size() as usize;
|
||||
let desc_table = self.desc_table;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue