From 5eca9379410b0d2422d540dded995523edf6fdc9 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 1 Nov 2019 10:34:02 -0700 Subject: [PATCH] devices: virtio: use signal helper for config changes Add handling of the virtio device MSI-X configuration change vector by using the signal function that was previously factored out. BUG=chromium:854765 TEST=./build_test TEST=trigger disk config change with `crosvm disk resize ...` Change-Id: I462c23e10d152f896586bb70b95634a53088d480 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898269 Tested-by: kokoro Reviewed-by: Zide Chen Reviewed-by: Zach Reizner --- devices/src/virtio/interrupt.rs | 10 +++++----- devices/src/virtio/vhost/net.rs | 2 ++ devices/src/virtio/virtio_pci_device.rs | 1 + fuzz/block_fuzzer.rs | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/devices/src/virtio/interrupt.rs b/devices/src/virtio/interrupt.rs index 0665b3fc99..f808d84738 100644 --- a/devices/src/virtio/interrupt.rs +++ b/devices/src/virtio/interrupt.rs @@ -14,6 +14,7 @@ pub struct Interrupt { interrupt_evt: EventFd, interrupt_resample_evt: EventFd, msix_config: Option>>, + config_msix_vector: u16, } impl Interrupt { @@ -22,12 +23,14 @@ impl Interrupt { interrupt_evt: EventFd, interrupt_resample_evt: EventFd, msix_config: Option>>, + config_msix_vector: u16, ) -> Interrupt { Interrupt { interrupt_status, interrupt_evt, interrupt_resample_evt, msix_config, + config_msix_vector, } } @@ -64,12 +67,9 @@ impl Interrupt { self.signal(vector, INTERRUPT_STATUS_USED_RING) } - /// Notification of Device Configuration Changes - /// Set BIT1 in ISR and write to irqfd + /// Notify the driver that the device configuration has changed. pub fn signal_config_changed(&self) { - self.interrupt_status - .fetch_or(INTERRUPT_STATUS_CONFIG_CHANGED as usize, Ordering::SeqCst); - self.interrupt_evt.write(1).unwrap(); + self.signal(self.config_msix_vector, INTERRUPT_STATUS_CONFIG_CHANGED) } /// Handle interrupt resampling event diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index 1196200a23..8462da58ce 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -233,6 +233,7 @@ where #[cfg(test)] pub mod tests { use super::*; + use crate::virtio::VIRTIO_MSI_NO_VECTOR; use net_util::fakes::FakeTap; use std::result; use std::sync::atomic::AtomicUsize; @@ -295,6 +296,7 @@ pub mod tests { EventFd::new().unwrap(), EventFd::new().unwrap(), None, + VIRTIO_MSI_NO_VECTOR, ), vec![Queue::new(1)], vec![EventFd::new().unwrap()], diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs index c535ab5f30..b79a98a3a9 100644 --- a/devices/src/virtio/virtio_pci_device.rs +++ b/devices/src/virtio/virtio_pci_device.rs @@ -618,6 +618,7 @@ impl PciDevice for VirtioPciDevice { interrupt_evt, interrupt_resample_evt, msix_config, + self.common_config.msix_config, ); self.device.activate( diff --git a/fuzz/block_fuzzer.rs b/fuzz/block_fuzzer.rs index 1730d49d6f..ec103bb937 100644 --- a/fuzz/block_fuzzer.rs +++ b/fuzz/block_fuzzer.rs @@ -88,7 +88,8 @@ fuzz_target!(|bytes| { Arc::new(AtomicUsize::new(0)), EventFd::new().unwrap(), EventFd::new().unwrap(), - None, // msix_config + None, // msix_config + 0xFFFF, // VIRTIO_MSI_NO_VECTOR ), vec![q], queue_evts,