summary refs log tree commit diff
path: root/vm_control
diff options
context:
space:
mode:
authorDaniel Prilik <prilik@google.com>2019-03-26 14:28:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-20 03:58:40 -0700
commitd92f81a249cdeacdd1b37574b479d35c09dc5e55 (patch)
tree87795f27b432f2c9b8d8d65bdb8db57e2c09a658 /vm_control
parentcfb6f70d1c3038ab3db3d92dce8016351b2d257c (diff)
downloadcrosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar.gz
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar.bz2
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar.lz
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar.xz
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.tar.zst
crosvm-d92f81a249cdeacdd1b37574b479d35c09dc5e55.zip
resources+pci: allocator rework (allocation tags)
AddressAllocator now maintains a HashMap<Alloc, (u64, u64, u64)>,
which uniquely maps a Allocation enum (e.g: PciBar(bus, dev, bar),
GpuRenderNode, etc...) to it's address, size, and human-readable tag
/ description.

The interface has also been modified to use Error instead of Option.

Aside from improving debugging, tracking allocations will have
numerous uses in the future. For example, when allocating guest memory
over VmControl sockets, it will be possible to restrict allocations to
pre-allocated slices of memory owned by the requesting device.

To plumb through PCI information to PCI devices, this CL necessitated
the addition of a PciDevice method called `assign_bus_dev`, which
notifies PCI devices of their uniquely assigned Bus and Device numbers.

BUG=chromium:936567
TEST=cargo test -p resources && cargo build --features="gpu gpu-forward"

Change-Id: I8b4b0e32c6f3168138739249ede53d03143ee5c3
Reviewed-on: https://chromium-review.googlesource.com/1536207
Commit-Ready: Daniel Prilik <prilik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'vm_control')
-rw-r--r--vm_control/src/lib.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index b197e9b..474380c 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -209,9 +209,14 @@ fn register_memory(
         Err(MmapError::SystemCallFailed(e)) => return Err(e),
         _ => return Err(SysError::new(EINVAL)),
     };
-    let addr = match allocator.allocate_device_addresses(size as u64) {
-        Some(a) => a,
-        None => return Err(SysError::new(EINVAL)),
+    let alloc = allocator.get_anon_alloc();
+    let addr = match allocator.device_allocator().allocate(
+        size as u64,
+        alloc,
+        "vmcontrol_register_memory".to_string(),
+    ) {
+        Ok(a) => a,
+        Err(_) => return Err(SysError::new(EINVAL)),
     };
     let slot = match vm.add_device_memory(GuestAddress(addr), mmap, false, false) {
         Ok(v) => v,