summary refs log tree commit diff
path: root/src/linux.rs
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 /src/linux.rs
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 'src/linux.rs')
-rw-r--r--src/linux.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 19cdf09..6e2c2c9 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -34,6 +34,8 @@ use net_util::{Error as NetError, MacAddress, Tap};
 use qcow::{self, ImageType, QcowFile};
 use rand_ish::SimpleRng;
 use remain::sorted;
+#[cfg(feature = "gpu-forward")]
+use resources::Alloc;
 use sync::{Condvar, Mutex};
 use sys_util::net::{UnixSeqpacket, UnixSeqpacketListener, UnlinkUnixSeqpacketListener};
 use sys_util::{
@@ -1173,8 +1175,13 @@ pub fn run_config(cfg: Config) -> Result<()> {
         // guest address space.
         let gpu_addr = linux
             .resources
-            .allocate_device_addresses(RENDER_NODE_HOST_SIZE)
-            .ok_or(Error::AllocateGpuDeviceAddress)?;
+            .device_allocator()
+            .allocate(
+                RENDER_NODE_HOST_SIZE,
+                Alloc::GpuRenderNode,
+                "gpu_render_node".to_string(),
+            )
+            .map_err(|_| Error::AllocateGpuDeviceAddress)?;
 
         let host = RenderNodeHost::start(&gpu_mmap, gpu_addr, linux.vm.get_memory().clone());