summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-10-05 14:51:22 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-11 13:25:38 -0700
commitcf2e00e9827798de956ff564aa422e9f31983d69 (patch)
tree7281bf9f0d8336894cfea3004c8d8cd5a8526711 /devices
parentdb6edff22f8bddabd6985c11a8f9456d2bc21c1f (diff)
downloadcrosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar.gz
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar.bz2
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar.lz
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar.xz
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.tar.zst
crosvm-cf2e00e9827798de956ff564aa422e9f31983d69.zip
arch: add virtio-pci eventfds with exact match
The virtio PCI spec (4.1.5.2 Notifying The Device) says:

  "The driver notifies the device by writing the 16-bit virtqueue index
  of this virtqueue to the Queue Notify address."

We were previously registering the notify address specifying
NoDatamatch; switch this to a 16-bit match of the queue index to follow
the specification.

BUG=chromium:854766
TEST=Boot crosvm with virtio devices converted to PCI

Change-Id: Ic950a8c7751268f7fcc21d5c37b0afc859f1e6d0
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1265861
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/Cargo.toml1
-rw-r--r--devices/src/lib.rs1
-rw-r--r--devices/src/pci/pci_device.rs9
-rw-r--r--devices/src/virtio/virtio_pci_device.rs12
4 files changed, 16 insertions, 7 deletions
diff --git a/devices/Cargo.toml b/devices/Cargo.toml
index 404efb0..ce0c0e5 100644
--- a/devices/Cargo.toml
+++ b/devices/Cargo.toml
@@ -13,6 +13,7 @@ data_model = { path = "../data_model" }
 gpu_buffer = { path = "../gpu_buffer", optional = true }
 gpu_display = { path = "../gpu_display", optional = true }
 gpu_renderer = { path = "../gpu_renderer", optional = true }
+kvm = { path = "../kvm" }
 libc = "*"
 io_jail = { path = "../io_jail" }
 net_sys = { path = "../net_sys" }
diff --git a/devices/src/lib.rs b/devices/src/lib.rs
index c6bf785..d76e743 100644
--- a/devices/src/lib.rs
+++ b/devices/src/lib.rs
@@ -7,6 +7,7 @@
 extern crate byteorder;
 extern crate data_model;
 extern crate io_jail;
+extern crate kvm;
 extern crate libc;
 extern crate net_sys;
 extern crate net_util;
diff --git a/devices/src/pci/pci_device.rs b/devices/src/pci/pci_device.rs
index edc1b5c..395caf1 100644
--- a/devices/src/pci/pci_device.rs
+++ b/devices/src/pci/pci_device.rs
@@ -7,6 +7,7 @@ use byteorder::{ByteOrder, LittleEndian};
 use std;
 use std::os::unix::io::RawFd;
 
+use kvm::Datamatch;
 use pci::pci_configuration::PciConfiguration;
 use pci::PciInterruptPin;
 use resources::SystemAllocator;
@@ -35,8 +36,8 @@ pub trait PciDevice: Send {
         Ok(Vec::new())
     }
     /// Gets a list of ioeventfds that should be registered with the running VM. The list is
-    /// returned as a Vec of (eventfd, addr) tuples.
-    fn ioeventfds(&self) -> Vec<(&EventFd, u64)> {
+    /// returned as a Vec of (eventfd, addr, datamatch) tuples.
+    fn ioeventfds(&self) -> Vec<(&EventFd, u64, Datamatch)> {
         Vec::new()
     }
     /// Gets the configuration registers of the Pci Device.
@@ -98,8 +99,8 @@ impl<T: PciDevice + ?Sized> PciDevice for Box<T> {
         (**self).allocate_io_bars(resources)
     }
     /// Gets a list of ioeventfds that should be registered with the running VM. The list is
-    /// returned as a Vec of (eventfd, addr) tuples.
-    fn ioeventfds(&self) -> Vec<(&EventFd, u64)> {
+    /// returned as a Vec of (eventfd, addr, datamatch) tuples.
+    fn ioeventfds(&self) -> Vec<(&EventFd, u64, Datamatch)> {
         (**self).ioeventfds()
     }
     /// Gets the configuration registers of the Pci Device.
diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs
index 10cbd32..613418c 100644
--- a/devices/src/virtio/virtio_pci_device.rs
+++ b/devices/src/virtio/virtio_pci_device.rs
@@ -9,6 +9,7 @@ use std::sync::Arc;
 
 use super::*;
 use data_model::{DataInit, Le32};
+use kvm::Datamatch;
 use pci::{
     PciCapability, PciCapabilityID, PciClassCode, PciConfiguration, PciDevice, PciDeviceError,
     PciHeaderType, PciInterruptPin, PciSubclass,
@@ -308,14 +309,19 @@ impl PciDevice for VirtioPciDevice {
         Ok(ranges)
     }
 
-    fn ioeventfds(&self) -> Vec<(&EventFd, u64)> {
+    fn ioeventfds(&self) -> Vec<(&EventFd, u64, Datamatch)> {
         let bar0 = self.config_regs.get_bar_addr(self.settings_bar as usize) as u64;
         let notify_base = bar0 + NOTIFICATION_BAR_OFFSET;
         self.queue_evts()
             .iter()
             .enumerate()
-            .map(|(i, event)| (event, notify_base + i as u64 * NOTIFY_OFF_MULTIPLIER as u64))
-            .collect()
+            .map(|(i, event)| {
+                (
+                    event,
+                    notify_base + i as u64 * NOTIFY_OFF_MULTIPLIER as u64,
+                    Datamatch::U16(Some(i as u16)),
+                )
+            }).collect()
     }
 
     fn config_registers(&self) -> &PciConfiguration {