Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not panic if virtio device activation return Err(...) #4665

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex, MutexGuard};

use utils::byte_order;

use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::device::{IrqType, VirtioDevice};
use crate::devices::virtio::device_status;
use crate::devices::virtio::queue::Queue;
use crate::logger::warn;
Expand Down Expand Up @@ -186,10 +186,18 @@ impl MmioTransport {
DRIVER_OK if self.device_status == (ACKNOWLEDGE | DRIVER | FEATURES_OK) => {
self.device_status = status;
let device_activated = self.locked_device().is_activated();
if !device_activated && self.are_queues_valid() {
self.locked_device()
.activate(self.mem.clone())
.expect("Failed to activate device");
if !device_activated
&& self.are_queues_valid()
&& self.locked_device().activate(self.mem.clone()).is_err()
roypat marked this conversation as resolved.
Show resolved Hide resolved
{
self.device_status |= DEVICE_NEEDS_RESET;
roypat marked this conversation as resolved.
Show resolved Hide resolved

// Section 2.1.2 of the specification states that we need to send a device
// configuration change interrupt
let _ = self
.locked_device()
.interrupt_trigger()
.trigger_irq(IrqType::Config);
roypat marked this conversation as resolved.
Show resolved Hide resolved
}
}
_ if (status & FAILED) != 0 => {
Expand Down Expand Up @@ -306,7 +314,9 @@ impl MmioTransport {
0x20 => {
if self.check_device_status(
device_status::DRIVER,
device_status::FEATURES_OK | device_status::FAILED,
device_status::FEATURES_OK
| device_status::FAILED
| device_status::DEVICE_NEEDS_RESET,
) {
self.locked_device()
.ack_features_by_page(self.acked_features_select, v);
Expand Down Expand Up @@ -339,7 +349,10 @@ impl MmioTransport {
}
}
0x100..=0xfff => {
if self.check_device_status(device_status::DRIVER, device_status::FAILED) {
if self.check_device_status(
device_status::DRIVER,
device_status::FAILED | device_status::DEVICE_NEEDS_RESET,
) {
self.locked_device().write_config(offset - 0x100, data)
} else {
warn!("can not write to device config data area before driver is ready");
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/devices/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod device_status {
pub const FAILED: u32 = 128;
pub const FEATURES_OK: u32 = 8;
pub const DRIVER_OK: u32 = 4;
pub const DEVICE_NEEDS_RESET: u32 = 64;
}

/// Types taken from linux/virtio_ids.h.
Expand Down