summary refs log tree commit diff
path: root/devices/src
diff options
context:
space:
mode:
authorXiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>2019-10-29 17:32:44 +0800
committerCommit Bot <commit-bot@chromium.org>2019-11-10 06:39:31 +0000
commit87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1 (patch)
tree29bc942019a2cdb32d292c4650eccb5cf0deaddf /devices/src
parent279248255f9f65c6baf044f1fbff0011bcd9938a (diff)
downloadcrosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.gz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.bz2
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.lz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.xz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.zst
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.zip
Resource: Unify mmio allocator
Current mmio and device two allocators exist, the purpose to define
two allocator is:
Accessing to gpa from mmio allocator cause vm exit, while gpa from
device allocator doesn't cause vm exit.

Whether vm exits exist or not, dependency on whether
vm->add_device_memory() is called with gpa from allocator or not.Even
if gpa is from mmio alloator, and vm->add_device_memory() is called
with this gpa, accessing this gpa won't cause vm exit. So mmio allocator
and device allocator couldn't guarantee the original purpose.

This patch unify mmio allocator and device allocator into one mmio
allocator.

BUG=chromium:992270
TEST=this patch doesn't change function, so just run build_test

Change-Id: If87d5c2838eb122ef627fa45c394b1b3ccfafeb0
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895233
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices/src')
-rw-r--r--devices/src/pci/ac97.rs6
-rw-r--r--devices/src/pci/vfio_pci.rs4
-rw-r--r--devices/src/usb/xhci/xhci_controller.rs4
-rw-r--r--devices/src/virtio/virtio_pci_device.rs6
4 files changed, 10 insertions, 10 deletions
diff --git a/devices/src/pci/ac97.rs b/devices/src/pci/ac97.rs
index 2deef03..73a5093 100644
--- a/devices/src/pci/ac97.rs
+++ b/devices/src/pci/ac97.rs
@@ -5,7 +5,7 @@
 use std::os::unix::io::RawFd;
 
 use audio_streams::StreamSource;
-use resources::{Alloc, SystemAllocator};
+use resources::{Alloc, MmioType, SystemAllocator};
 use sys_util::{error, EventFd, GuestMemory};
 
 use crate::pci::ac97_bus_master::Ac97BusMaster;
@@ -149,7 +149,7 @@ impl PciDevice for Ac97Dev {
             .expect("assign_bus_dev must be called prior to allocate_io_bars");
         let mut ranges = Vec::new();
         let mixer_regs_addr = resources
-            .mmio_allocator()
+            .mmio_allocator(MmioType::Mmio)
             .allocate_with_align(
                 MIXER_REGS_SIZE,
                 Alloc::PciBar { bus, dev, bar: 0 },
@@ -167,7 +167,7 @@ impl PciDevice for Ac97Dev {
         ranges.push((mixer_regs_addr, MIXER_REGS_SIZE));
 
         let master_regs_addr = resources
-            .mmio_allocator()
+            .mmio_allocator(MmioType::Mmio)
             .allocate_with_align(
                 MASTER_REGS_SIZE,
                 Alloc::PciBar { bus, dev, bar: 1 },
diff --git a/devices/src/pci/vfio_pci.rs b/devices/src/pci/vfio_pci.rs
index a1e7a74..c10715d 100644
--- a/devices/src/pci/vfio_pci.rs
+++ b/devices/src/pci/vfio_pci.rs
@@ -8,7 +8,7 @@ use std::u32;
 
 use kvm::Datamatch;
 use msg_socket::{MsgReceiver, MsgSender};
-use resources::{Alloc, SystemAllocator};
+use resources::{Alloc, MmioType, SystemAllocator};
 use sys_util::{error, EventFd};
 
 use vfio_sys::*;
@@ -502,7 +502,7 @@ impl PciDevice for VfioPciDevice {
                 size |= u64::from(low);
                 size = !size + 1;
                 let bar_addr = resources
-                    .mmio_allocator()
+                    .mmio_allocator(MmioType::Mmio)
                     .allocate_with_align(
                         size,
                         Alloc::PciBar {
diff --git a/devices/src/usb/xhci/xhci_controller.rs b/devices/src/usb/xhci/xhci_controller.rs
index 5db31ef..dfba4a4 100644
--- a/devices/src/usb/xhci/xhci_controller.rs
+++ b/devices/src/usb/xhci/xhci_controller.rs
@@ -12,7 +12,7 @@ use crate::usb::xhci::xhci::Xhci;
 use crate::usb::xhci::xhci_backend_device_provider::XhciBackendDeviceProvider;
 use crate::usb::xhci::xhci_regs::{init_xhci_mmio_space_and_regs, XhciRegs};
 use crate::utils::FailHandle;
-use resources::{Alloc, SystemAllocator};
+use resources::{Alloc, MmioType, SystemAllocator};
 use std::mem;
 use std::os::unix::io::RawFd;
 use std::sync::atomic::{AtomicBool, Ordering};
@@ -213,7 +213,7 @@ impl PciDevice for XhciController {
             .expect("assign_bus_dev must be called prior to allocate_io_bars");
         // xHCI spec 5.2.1.
         let bar0_addr = resources
-            .mmio_allocator()
+            .mmio_allocator(MmioType::Mmio)
             .allocate_with_align(
                 XHCI_BAR0_SIZE,
                 Alloc::PciBar { bus, dev, bar: 0 },
diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs
index 033d4ee..bd94fe3 100644
--- a/devices/src/virtio/virtio_pci_device.rs
+++ b/devices/src/virtio/virtio_pci_device.rs
@@ -10,7 +10,7 @@ use sync::Mutex;
 
 use data_model::{DataInit, Le32};
 use kvm::Datamatch;
-use resources::{Alloc, SystemAllocator};
+use resources::{Alloc, MmioType, SystemAllocator};
 use sys_util::{EventFd, GuestMemory, Result};
 
 use super::*;
@@ -384,7 +384,7 @@ impl PciDevice for VirtioPciDevice {
         // Allocate one bar for the structures pointed to by the capability structures.
         let mut ranges = Vec::new();
         let settings_config_addr = resources
-            .mmio_allocator()
+            .mmio_allocator(MmioType::Mmio)
             .allocate_with_align(
                 CAPABILITY_BAR_SIZE,
                 Alloc::PciBar { bus, dev, bar: 0 },
@@ -422,7 +422,7 @@ impl PciDevice for VirtioPciDevice {
         let mut ranges = Vec::new();
         for config in self.device.get_device_bars(bus, dev) {
             let device_addr = resources
-                .device_allocator()
+                .mmio_allocator(MmioType::Device)
                 .allocate_with_align(
                     config.get_size(),
                     Alloc::PciBar {