summary refs log tree commit diff
path: root/pkgs/cloud-hypervisor
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-12-17 01:15:41 +0100
committerAlyssa Ross <hi@alyssa.is>2023-12-17 15:46:37 +0100
commit33fe5c1194e3e9c8b69bfecce201758227e6dbbf (patch)
tree9da58d29e11f81a80784923391e2b6b7b0ab0672 /pkgs/cloud-hypervisor
parent63bb27990b91e3c0f6526a84371fd003585da1e6 (diff)
downloadspectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar.gz
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar.bz2
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar.lz
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar.xz
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.tar.zst
spectrum-33fe5c1194e3e9c8b69bfecce201758227e6dbbf.zip
pkgs: cloud-hypervisor: use SHARED_MEMORY_REGIONS
This avoids the need to configure the cache size by getting it from
the backend.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
Diffstat (limited to 'pkgs/cloud-hypervisor')
-rw-r--r--pkgs/cloud-hypervisor/0001-build-use-local-vhost.patch2
-rw-r--r--pkgs/cloud-hypervisor/0002-virtio-devices-add-a-GPU-device.patch372
-rw-r--r--pkgs/cloud-hypervisor/Cargo.lock1
3 files changed, 171 insertions, 204 deletions
diff --git a/pkgs/cloud-hypervisor/0001-build-use-local-vhost.patch b/pkgs/cloud-hypervisor/0001-build-use-local-vhost.patch
index 80cec0e..cf8077b 100644
--- a/pkgs/cloud-hypervisor/0001-build-use-local-vhost.patch
+++ b/pkgs/cloud-hypervisor/0001-build-use-local-vhost.patch
@@ -1,4 +1,4 @@
-From 84bc6ecfd69da2483fc440147d0213474432240e Mon Sep 17 00:00:00 2001
+From d70541c471be5d21bc840f0588759d88a7d6ec78 Mon Sep 17 00:00:00 2001
 From: Alyssa Ross <alyssa.ross@unikie.com>
 Date: Wed, 28 Sep 2022 12:18:19 +0000
 Subject: [PATCH 1/2] build: use local vhost
diff --git a/pkgs/cloud-hypervisor/0002-virtio-devices-add-a-GPU-device.patch b/pkgs/cloud-hypervisor/0002-virtio-devices-add-a-GPU-device.patch
index 235a960..e879fc2 100644
--- a/pkgs/cloud-hypervisor/0002-virtio-devices-add-a-GPU-device.patch
+++ b/pkgs/cloud-hypervisor/0002-virtio-devices-add-a-GPU-device.patch
@@ -1,4 +1,4 @@
-From 8dc027a4675b511ebf6c757eb0054d60d2a65f03 Mon Sep 17 00:00:00 2001
+From 81a571032de71665d97ca8579249d91225e77ec0 Mon Sep 17 00:00:00 2001
 From: Alyssa Ross <alyssa.ross@unikie.com>
 Date: Wed, 7 Sep 2022 14:16:29 +0000
 Subject: [PATCH 2/2] virtio-devices: add a GPU device
@@ -26,36 +26,23 @@ Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
 Co-authored-by: Alyssa Ross <hi@alyssa.is>
 Signed-off-by: Alyssa Ross <hi@alyssa.is>
 ---
- Cargo.lock                                 |   1 +
- src/main.rs                                |   8 +
- virtio-devices/src/device.rs               |   8 +-
- virtio-devices/src/lib.rs                  |   4 +-
- virtio-devices/src/seccomp_filters.rs      |  16 +
- virtio-devices/src/transport/pci_device.rs |   4 +-
- virtio-devices/src/vhost_user/gpu.rs       | 406 +++++++++++++++++++++
- virtio-devices/src/vhost_user/mod.rs       |   2 +
- vmm/Cargo.toml                             |   1 +
- vmm/src/api/mod.rs                         |  10 +-
- vmm/src/config.rs                          | 119 ++++++
- vmm/src/device_manager.rs                  | 140 ++++++-
- vmm/src/lib.rs                             |  88 ++++-
- vmm/src/vm.rs                              |  28 +-
- vmm/src/vm_config.rs                       |  27 ++
- 15 files changed, 845 insertions(+), 17 deletions(-)
+ src/main.rs                                   |   8 +
+ virtio-devices/src/device.rs                  |   4 +-
+ virtio-devices/src/lib.rs                     |   4 +-
+ virtio-devices/src/seccomp_filters.rs         |  16 +
+ virtio-devices/src/transport/pci_device.rs    |   4 +-
+ virtio-devices/src/vhost_user/gpu.rs          | 415 ++++++++++++++++++
+ virtio-devices/src/vhost_user/mod.rs          |   6 +
+ .../src/vhost_user/vu_common_ctrl.rs          |   9 +-
+ vmm/src/api/mod.rs                            |  10 +-
+ vmm/src/config.rs                             | 108 +++++
+ vmm/src/device_manager.rs                     | 135 +++++-
+ vmm/src/lib.rs                                |  86 +++-
+ vmm/src/vm.rs                                 |  28 +-
+ vmm/src/vm_config.rs                          |  10 +
+ 14 files changed, 829 insertions(+), 14 deletions(-)
  create mode 100644 virtio-devices/src/vhost_user/gpu.rs
 
-diff --git a/Cargo.lock b/Cargo.lock
-index fbab2e1d..c6675f28 100644
---- a/Cargo.lock
-+++ b/Cargo.lock
-@@ -2542,6 +2542,7 @@ dependencies = [
-  "versionize_derive",
-  "vfio-ioctls",
-  "vfio_user",
-+ "virtio-bindings",
-  "virtio-devices",
-  "virtio-queue",
-  "vm-allocator",
 diff --git a/src/main.rs b/src/main.rs
 index 426d154c..82ee6821 100644
 --- a/src/main.rs
@@ -83,7 +70,7 @@ index 426d154c..82ee6821 100644
              serial: ConsoleConfig {
                  file: None,
 diff --git a/virtio-devices/src/device.rs b/virtio-devices/src/device.rs
-index b70092f8..e091ddd6 100644
+index b70092f8..4b6e6a3b 100644
 --- a/virtio-devices/src/device.rs
 +++ b/virtio-devices/src/device.rs
 @@ -11,7 +11,7 @@ use crate::{
@@ -95,21 +82,7 @@ index b70092f8..e091ddd6 100644
  use std::io::Write;
  use std::num::Wrapping;
  use std::sync::{
-@@ -47,19 +47,19 @@ pub struct UserspaceMapping {
-     pub mergeable: bool,
- }
- 
--#[derive(Clone)]
-+#[derive(Clone, Debug)]
- pub struct VirtioSharedMemory {
-     pub offset: u64,
-     pub len: u64,
- }
- 
--#[derive(Clone)]
-+#[derive(Clone, Debug)]
- pub struct VirtioSharedMemoryList {
-     pub host_addr: u64,
+@@ -59,7 +59,7 @@ pub struct VirtioSharedMemoryList {
      pub mem_slot: u32,
      pub addr: GuestAddress,
      pub len: GuestUsize,
@@ -201,10 +174,10 @@ index 60979573..0348b53a 100644
                      );
 diff --git a/virtio-devices/src/vhost_user/gpu.rs b/virtio-devices/src/vhost_user/gpu.rs
 new file mode 100644
-index 00000000..416d9629
+index 00000000..ab8e6b48
 --- /dev/null
 +++ b/virtio-devices/src/vhost_user/gpu.rs
-@@ -0,0 +1,406 @@
+@@ -0,0 +1,415 @@
 +// Copyright 2019 Intel Corporation. All Rights Reserved.
 +// Copyright 2022 Unikie
 +// Copyright 2023 Alyssa Ross <hi@alyssa.is>
@@ -227,8 +200,8 @@ index 00000000..416d9629
 +use std::sync::{Arc, Barrier, Mutex};
 +use std::thread;
 +use vhost::vhost_user::message::{
-+    VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserShmemMapMsg, VhostUserShmemUnmapMsg,
-+    VhostUserVirtioFeatures,
++    VhostSharedMemoryRegion, VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserShmemMapMsg,
++    VhostUserShmemUnmapMsg, VhostUserVirtioFeatures,
 +};
 +use vhost::vhost_user::{
 +    HandlerResult, MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler,
@@ -345,11 +318,10 @@ index 00000000..416d9629
 +    pub fn new(
 +        id: String,
 +        path: &str,
-+        cache: Option<(VirtioSharedMemoryList, MmapRegion)>,
 +        seccomp_action: SeccompAction,
 +        exit_evt: EventFd,
 +        iommu: bool,
-+    ) -> Result<Gpu> {
++    ) -> Result<(Gpu, VhostSharedMemoryRegion)> {
 +        // Connect to the vhost-user socket.
 +        let mut vu = VhostUserHandle::connect_vhost_user(false, path, NUM_QUEUES as u64, false)?;
 +
@@ -360,47 +332,62 @@ index 00000000..416d9629
 +            | 1 << VIRTIO_GPU_F_CONTEXT_INIT
 +            | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits();
 +
-+        let avail_protocol_features =
-+            VhostUserProtocolFeatures::CONFIG | VhostUserProtocolFeatures::SLAVE_REQ;
-+        // The SHARED_MEMORY_REGIONS protocol feature is a way for the backend to indicate
-+        // that it supports the GET_SHARED_MEMORY_REGIONS request.  Since we don't use that
-+        // request, we don't ack SHARED_MEMORY_REGIONS.
++        let avail_protocol_features = VhostUserProtocolFeatures::CONFIG
++            | VhostUserProtocolFeatures::SLAVE_REQ
++            | VhostUserProtocolFeatures::SHARED_MEMORY_REGIONS;
 +
 +        let (acked_features, acked_protocol_features) =
 +            vu.negotiate_features_vhost_user(avail_features, avail_protocol_features)?;
 +
-+        Ok(Gpu {
-+            common: VirtioCommon {
-+                device_type: VirtioDeviceType::Gpu as u32,
-+                avail_features: acked_features,
-+                // If part of the available features that have been acked, the
-+                // PROTOCOL_FEATURES bit must be already set through the VIRTIO
-+                // acked features as we know the guest would never ack it, this
-+                // the feature would be lost.
-+                acked_features: acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
-+                paused_sync: Some(Arc::new(Barrier::new(NUM_QUEUES as usize))),
-+                queue_sizes: QUEUE_SIZES.to_vec(),
-+                min_queues: NUM_QUEUES,
-+                ..Default::default()
-+            },
-+            vu_common: VhostUserCommon {
-+                vu: Some(Arc::new(Mutex::new(vu))),
-+                acked_protocol_features,
-+                socket_path: path.to_string(),
-+                vu_num_queues: NUM_QUEUES as usize,
-+                ..Default::default()
++        let shm_regions = vu.get_shared_memory_regions()?;
++        if shm_regions.len() != 1 {
++            return Err(Error::VhostUserUnexpectedSharedMemoryRegionsCount(
++                1,
++                shm_regions.len(),
++            ));
++        }
++        let shm_region = shm_regions[0];
++
++        Ok((
++            Gpu {
++                common: VirtioCommon {
++                    device_type: VirtioDeviceType::Gpu as u32,
++                    avail_features: acked_features,
++                    // If part of the available features that have been acked, the
++                    // PROTOCOL_FEATURES bit must be already set through the VIRTIO
++                    // acked features as we know the guest would never ack it, this
++                    // the feature would be lost.
++                    acked_features: acked_features
++                        & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(),
++                    paused_sync: Some(Arc::new(Barrier::new(NUM_QUEUES as usize))),
++                    queue_sizes: QUEUE_SIZES.to_vec(),
++                    min_queues: NUM_QUEUES,
++                    ..Default::default()
++                },
++                vu_common: VhostUserCommon {
++                    vu: Some(Arc::new(Mutex::new(vu))),
++                    acked_protocol_features,
++                    socket_path: path.to_string(),
++                    vu_num_queues: NUM_QUEUES as usize,
++                    ..Default::default()
++                },
++                id,
++                cache: None,
++                slave_req_support: acked_protocol_features
++                    & VhostUserProtocolFeatures::SLAVE_REQ.bits()
++                    != 0,
++                seccomp_action,
++                guest_memory: None,
++                epoll_thread: None,
++                exit_evt,
++                iommu,
 +            },
-+            id,
-+            cache,
-+            slave_req_support: acked_protocol_features
-+                & VhostUserProtocolFeatures::SLAVE_REQ.bits()
-+                != 0,
-+            seccomp_action,
-+            guest_memory: None,
-+            epoll_thread: None,
-+            exit_evt,
-+            iommu,
-+        })
++            shm_region,
++        ))
++    }
++
++    pub fn set_cache(&mut self, cache: (VirtioSharedMemoryList, MmapRegion)) {
++        self.cache = Some(cache);
 +    }
 +}
 +
@@ -552,11 +539,6 @@ index 00000000..416d9629
 +    }
 +
 +    fn get_shm_regions(&self) -> Option<VirtioSharedMemoryList> {
-+        // It would be possible to get the size of the region from the
-+        // backend over vhost-user, but since we need to know the size
-+        // up front in cloud-hypervisor to construct Self, it wouldn't
-+        // help.  The user is thereforce responsible for configuring
-+        // the correct region size in VM configuration.
 +        self.cache.as_ref().map(|cache| cache.0.clone())
 +    }
 +
@@ -612,7 +594,7 @@ index 00000000..416d9629
 +    }
 +}
 diff --git a/virtio-devices/src/vhost_user/mod.rs b/virtio-devices/src/vhost_user/mod.rs
-index 2dee7324..d1b1c4e6 100644
+index 2dee7324..803db659 100644
 --- a/virtio-devices/src/vhost_user/mod.rs
 +++ b/virtio-devices/src/vhost_user/mod.rs
 @@ -31,11 +31,13 @@ use vu_common_ctrl::VhostUserHandle;
@@ -629,18 +611,51 @@ index 2dee7324..d1b1c4e6 100644
  pub use self::net::Net;
  pub use self::vu_common_ctrl::VhostUserConfig;
  
-diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml
-index 7b5b6fe9..2f883f8d 100644
---- a/vmm/Cargo.toml
-+++ b/vmm/Cargo.toml
-@@ -53,6 +53,7 @@ versionize = "0.1.10"
- versionize_derive = "0.1.4"
- vfio-ioctls = { git = "https://github.com/rust-vmm/vfio", branch = "main", default-features = false }
- vfio_user = { git = "https://github.com/rust-vmm/vfio-user", branch = "main" }
-+virtio-bindings = "0.2.0"
- virtio-devices = { path = "../virtio-devices" }
- virtio-queue = "0.9.0"
- vm-allocator = { path = "../vm-allocator" }
+@@ -73,6 +75,8 @@ pub enum Error {
+     VhostUserGetQueueMaxNum(VhostError),
+     #[error("Get protocol features failed: {0}")]
+     VhostUserGetProtocolFeatures(VhostError),
++    #[error("Get shared memory regions failed: {0}")]
++    VhostUserGetSharedMemoryRegions(VhostError),
+     #[error("Get vring base failed: {0}")]
+     VhostUserGetVringBase(VhostError),
+     #[error("Vhost-user Backend not support vhost-user protocol")]
+@@ -121,6 +125,8 @@ pub enum Error {
+     VhostUserSetInflight(VhostError),
+     #[error("Failed setting the log base: {0}")]
+     VhostUserSetLogBase(VhostError),
++    #[error("Expected {0} shared memory regions; got {1}")]
++    VhostUserUnexpectedSharedMemoryRegionsCount(usize, usize),
+     #[error("Invalid used address")]
+     UsedAddress,
+     #[error("Invalid features provided from vhost-user backend")]
+diff --git a/virtio-devices/src/vhost_user/vu_common_ctrl.rs b/virtio-devices/src/vhost_user/vu_common_ctrl.rs
+index 7bbf936c..b804084b 100644
+--- a/virtio-devices/src/vhost_user/vu_common_ctrl.rs
++++ b/virtio-devices/src/vhost_user/vu_common_ctrl.rs
+@@ -19,7 +19,8 @@ use std::time::{Duration, Instant};
+ use std::vec::Vec;
+ use vhost::vhost_kern::vhost_binding::{VHOST_F_LOG_ALL, VHOST_VRING_F_LOG};
+ use vhost::vhost_user::message::{
+-    VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
++    VhostSharedMemoryRegion, VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures,
++    VhostUserVirtioFeatures,
+ };
+ use vhost::vhost_user::{Master, MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler};
+ use vhost::{VhostBackend, VhostUserDirtyLogRegion, VhostUserMemoryRegionInfo, VringConfigData};
+@@ -103,6 +104,12 @@ impl VhostUserHandle {
+             .map_err(Error::VhostUserAddMemReg)
+     }
+ 
++    pub fn get_shared_memory_regions(&self) -> Result<Vec<VhostSharedMemoryRegion>> {
++        self.vu
++            .get_shared_memory_regions()
++            .map_err(Error::VhostUserGetSharedMemoryRegions)
++    }
++
+     pub fn negotiate_features_vhost_user(
+         &mut self,
+         avail_features: u64,
 diff --git a/vmm/src/api/mod.rs b/vmm/src/api/mod.rs
 index aaae8ee3..9433ee07 100644
 --- a/vmm/src/api/mod.rs
@@ -677,7 +692,7 @@ index aaae8ee3..9433ee07 100644
      VmAddPmem(Arc<PmemConfig>, Sender<ApiResponse>),
  
 diff --git a/vmm/src/config.rs b/vmm/src/config.rs
-index 3bac721a..299d461b 100644
+index 3bac721a..277e2408 100644
 --- a/vmm/src/config.rs
 +++ b/vmm/src/config.rs
 @@ -27,6 +27,8 @@ pub enum Error {
@@ -733,30 +748,20 @@ index 3bac721a..299d461b 100644
              pmem,
              serial,
              console,
-@@ -1404,6 +1415,60 @@ impl FsConfig {
+@@ -1404,6 +1415,49 @@ impl FsConfig {
      }
  }
  
 +impl GpuConfig {
 +    pub const SYNTAX: &'static str = "virtio-gpu parameters \
-+    \"socket=<socket_path>,cache_size=<default 8GiB>,id=<device_id>,\
-+    pci_segment=<segment_id>\"";
++    \"socket=<socket_path>,id=<device_id>,pci_segment=<segment_id>\"";
 +
 +    pub fn parse(gpu: &str) -> Result<Self> {
 +        let mut parser = OptionParser::new();
-+        parser
-+            .add("socket")
-+            .add("cache_size")
-+            .add("id")
-+            .add("pci_segment");
++        parser.add("socket").add("id").add("pci_segment");
 +        parser.parse(gpu).map_err(Error::ParseGpu)?;
 +
 +        let socket = PathBuf::from(parser.get("socket").ok_or(Error::ParseGpuSockMissing)?);
-+        let cache_size = parser
-+            .convert::<ByteSized>("cache_size")
-+            .map_err(Error::ParseGpu)?
-+            .unwrap_or_else(|| ByteSized(default_gpuconfig_cache_size()))
-+            .0;
 +        let id = parser.get("id");
 +
 +        let pci_segment = parser
@@ -766,7 +771,6 @@ index 3bac721a..299d461b 100644
 +
 +        Ok(GpuConfig {
 +            socket,
-+            cache_size,
 +            id,
 +            pci_segment,
 +        })
@@ -794,7 +798,7 @@ index 3bac721a..299d461b 100644
  impl PmemConfig {
      pub const SYNTAX: &'static str = "Persistent memory parameters \
      \"file=<backing_file_path>,size=<persistent_memory_size>,iommu=on|off,\
-@@ -1988,6 +2053,17 @@ impl VmConfig {
+@@ -1988,6 +2042,17 @@ impl VmConfig {
              }
          }
  
@@ -812,7 +816,7 @@ index 3bac721a..299d461b 100644
          if let Some(pmems) = &self.pmem {
              for pmem in pmems {
                  pmem.validate(self)?;
-@@ -2202,6 +2278,15 @@ impl VmConfig {
+@@ -2202,6 +2267,15 @@ impl VmConfig {
              fs = Some(fs_config_list);
          }
  
@@ -828,7 +832,7 @@ index 3bac721a..299d461b 100644
          let mut pmem: Option<Vec<PmemConfig>> = None;
          if let Some(pmem_list) = &vm_params.pmem {
              let mut pmem_config_list = Vec::new();
-@@ -2308,6 +2393,7 @@ impl VmConfig {
+@@ -2308,6 +2382,7 @@ impl VmConfig {
              rng,
              balloon,
              fs,
@@ -836,7 +840,7 @@ index 3bac721a..299d461b 100644
              pmem,
              serial,
              console,
-@@ -2362,6 +2448,13 @@ impl VmConfig {
+@@ -2362,6 +2437,13 @@ impl VmConfig {
              removed |= fs.len() != len;
          }
  
@@ -850,7 +854,7 @@ index 3bac721a..299d461b 100644
          // Remove if net device
          if let Some(net) = self.net.as_mut() {
              let len = net.len();
-@@ -2431,6 +2524,7 @@ impl Clone for VmConfig {
+@@ -2431,6 +2513,7 @@ impl Clone for VmConfig {
              rng: self.rng.clone(),
              balloon: self.balloon.clone(),
              fs: self.fs.clone(),
@@ -858,7 +862,7 @@ index 3bac721a..299d461b 100644
              pmem: self.pmem.clone(),
              serial: self.serial.clone(),
              console: self.console.clone(),
-@@ -2825,6 +2919,21 @@ mod tests {
+@@ -2825,6 +2908,21 @@ mod tests {
          Ok(())
      }
  
@@ -880,7 +884,7 @@ index 3bac721a..299d461b 100644
      #[test]
      fn test_pmem_parsing() -> Result<()> {
          // Must always give a file and size
-@@ -3075,6 +3184,7 @@ mod tests {
+@@ -3075,6 +3173,7 @@ mod tests {
              },
              balloon: None,
              fs: None,
@@ -888,7 +892,7 @@ index 3bac721a..299d461b 100644
              pmem: None,
              serial: ConsoleConfig {
                  file: None,
-@@ -3242,6 +3352,15 @@ mod tests {
+@@ -3242,6 +3341,15 @@ mod tests {
              Err(ValidationError::VhostUserRequiresSharedMemory)
          );
  
@@ -905,7 +909,7 @@ index 3bac721a..299d461b 100644
          still_valid_config.memory.shared = true;
          assert!(still_valid_config.validate().is_ok());
 diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs
-index 24900e78..29a83a6d 100644
+index 24900e78..4aa6a676 100644
 --- a/vmm/src/device_manager.rs
 +++ b/vmm/src/device_manager.rs
 @@ -10,8 +10,8 @@
@@ -927,13 +931,7 @@ index 24900e78..29a83a6d 100644
  use std::mem::zeroed;
  use std::num::Wrapping;
  use std::os::unix::fs::OpenOptionsExt;
-@@ -76,11 +77,13 @@ use std::sync::{Arc, Mutex};
- use std::time::Instant;
- use tracer::trace_scoped;
- use vfio_ioctls::{VfioContainer, VfioDevice, VfioDeviceFd};
-+use virtio_bindings::virtio_gpu::virtio_gpu_shm_id_VIRTIO_GPU_SHM_ID_HOST_VISIBLE as VIRTIO_GPU_SHM_ID_HOST_VISIBLE;
- use virtio_devices::transport::VirtioTransport;
- use virtio_devices::transport::{VirtioPciDevice, VirtioPciDeviceActivator};
+@@ -81,6 +82,7 @@ use virtio_devices::transport::{VirtioPciDevice, VirtioPciDeviceActivator};
  use virtio_devices::vhost_user::VhostUserConfig;
  use virtio_devices::{
      AccessPlatformMapping, ActivateError, VdpaDmaMapping, VirtioMemMappingSource,
@@ -941,7 +939,7 @@ index 24900e78..29a83a6d 100644
  };
  use virtio_devices::{Endpoint, IommuMapping};
  use vm_allocator::{AddressAllocator, SystemAllocator};
-@@ -122,6 +125,7 @@ const PVPANIC_DEVICE_NAME: &str = "__pvpanic";
+@@ -122,6 +124,7 @@ const PVPANIC_DEVICE_NAME: &str = "__pvpanic";
  // identifiers if the user doesn't give one
  const DISK_DEVICE_NAME_PREFIX: &str = "_disk";
  const FS_DEVICE_NAME_PREFIX: &str = "_fs";
@@ -949,7 +947,7 @@ index 24900e78..29a83a6d 100644
  const NET_DEVICE_NAME_PREFIX: &str = "_net";
  const PMEM_DEVICE_NAME_PREFIX: &str = "_pmem";
  const VDPA_DEVICE_NAME_PREFIX: &str = "_vdpa";
-@@ -158,9 +162,15 @@ pub enum DeviceManagerError {
+@@ -158,9 +161,15 @@ pub enum DeviceManagerError {
      /// Cannot create virtio-fs device
      CreateVirtioFs(virtio_devices::vhost_user::Error),
  
@@ -965,7 +963,7 @@ index 24900e78..29a83a6d 100644
      /// Cannot create vhost-user-blk device
      CreateVhostUserBlk(virtio_devices::vhost_user::Error),
  
-@@ -245,6 +255,9 @@ pub enum DeviceManagerError {
+@@ -245,6 +254,9 @@ pub enum DeviceManagerError {
      /// Cannot find a memory range for virtio-fs
      FsRangeAllocation,
  
@@ -975,7 +973,7 @@ index 24900e78..29a83a6d 100644
      /// Error creating serial output file
      SerialOutputFileOpen(io::Error),
  
-@@ -2155,6 +2168,9 @@ impl DeviceManager {
+@@ -2155,6 +2167,9 @@ impl DeviceManager {
          // Add virtio-fs if required
          devices.append(&mut self.make_virtio_fs_devices()?);
  
@@ -985,7 +983,7 @@ index 24900e78..29a83a6d 100644
          // Add virtio-pmem if required
          devices.append(&mut self.make_virtio_pmem_devices()?);
  
-@@ -2684,6 +2700,118 @@ impl DeviceManager {
+@@ -2684,6 +2699,114 @@ impl DeviceManager {
          Ok(devices)
      }
  
@@ -1006,25 +1004,35 @@ index 24900e78..29a83a6d 100644
 +        let mut node = device_node!(id);
 +
 +        if let Some(gpu_socket) = gpu_cfg.socket.to_str() {
-+            let cache_size = gpu_cfg.cache_size;
++            let (mut virtio_gpu_device, region) = virtio_devices::vhost_user::Gpu::new(
++                id.clone(),
++                gpu_socket,
++                self.seccomp_action.clone(),
++                self.exit_evt
++                    .try_clone()
++                    .map_err(DeviceManagerError::EventFd)?,
++                self.force_iommu,
++            )
++            .map_err(DeviceManagerError::CreateVirtioGpu)?;
++
 +            // In crosvm, the 8 GiB bar is 8 GiB-aligned.
 +            let cache_base = self.pci_segments[gpu_cfg.pci_segment as usize]
 +                .allocator
 +                .lock()
 +                .unwrap()
-+                .allocate(None, cache_size as GuestUsize, Some(cache_size))
++                .allocate(None, region.length as GuestUsize, Some(region.length))
 +                .ok_or(DeviceManagerError::GpuRangeAllocation)?
 +                .raw_value();
 +
 +            // Update the node with correct resource information.
 +            node.resources.push(Resource::MmioAddressRange {
 +                base: cache_base,
-+                size: cache_size,
++                size: region.length,
 +            });
 +
 +            let mmap_region = MmapRegion::build(
 +                None,
-+                cache_size as usize,
++                region.length as usize,
 +                libc::PROT_NONE,
 +                libc::MAP_ANONYMOUS | libc::MAP_PRIVATE,
 +            )
@@ -1035,47 +1043,33 @@ index 24900e78..29a83a6d 100644
 +                .memory_manager
 +                .lock()
 +                .unwrap()
-+                .create_userspace_mapping(cache_base, cache_size, host_addr, false, false, false)
++                .create_userspace_mapping(cache_base, region.length, host_addr, false, false, false)
 +                .map_err(DeviceManagerError::MemoryManager)?;
 +
 +            let region_list = once((
-+                VIRTIO_GPU_SHM_ID_HOST_VISIBLE as u8,
++                region.id,
 +                VirtioSharedMemory {
 +                    offset: 0,
-+                    len: cache_size,
++                    len: region.length,
 +                },
 +            ))
 +            .collect();
 +
-+            let cache = Some((
++            virtio_gpu_device.set_cache((
 +                VirtioSharedMemoryList {
 +                    host_addr,
 +                    mem_slot,
 +                    addr: GuestAddress(cache_base),
-+                    len: cache_size as GuestUsize,
++                    len: region.length as GuestUsize,
 +                    region_list,
 +                },
 +                mmap_region,
 +            ));
 +
-+            let virtio_gpu_device = Arc::new(Mutex::new(
-+                virtio_devices::vhost_user::Gpu::new(
-+                    id.clone(),
-+                    gpu_socket,
-+                    cache,
-+                    self.seccomp_action.clone(),
-+                    self.exit_evt
-+                        .try_clone()
-+                        .map_err(DeviceManagerError::EventFd)?,
-+                    self.force_iommu,
-+                )
-+                .map_err(DeviceManagerError::CreateVirtioGpu)?,
-+            ));
-+
 +            self.device_tree.lock().unwrap().insert(id.clone(), node);
 +
 +            Ok(MetaVirtioDevice {
-+                virtio_device: Arc::clone(&virtio_gpu_device)
++                virtio_device: Arc::new(Mutex::new(virtio_gpu_device))
 +                    as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
 +                iommu: false,
 +                id,
@@ -1104,7 +1098,7 @@ index 24900e78..29a83a6d 100644
      fn make_virtio_pmem_device(
          &mut self,
          pmem_cfg: &mut PmemConfig,
-@@ -3943,6 +4071,7 @@ impl DeviceManager {
+@@ -3943,6 +4066,7 @@ impl DeviceManager {
                  | VirtioDeviceType::Block
                  | VirtioDeviceType::Pmem
                  | VirtioDeviceType::Fs
@@ -1112,7 +1106,7 @@ index 24900e78..29a83a6d 100644
                  | VirtioDeviceType::Vsock => {}
                  _ => return Err(DeviceManagerError::RemovalNotAllowed(device_type)),
              }
-@@ -4211,6 +4340,13 @@ impl DeviceManager {
+@@ -4211,6 +4335,13 @@ impl DeviceManager {
          self.hotplug_virtio_pci_device(device)
      }
  
@@ -1127,7 +1121,7 @@ index 24900e78..29a83a6d 100644
          self.validate_identifier(&pmem_cfg.id)?;
  
 diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs
-index 96425b59..62c9aeff 100644
+index 96425b59..6490cdb8 100644
 --- a/vmm/src/lib.rs
 +++ b/vmm/src/lib.rs
 @@ -13,8 +13,8 @@ use crate::api::{
@@ -1141,16 +1135,7 @@ index 96425b59..62c9aeff 100644
  };
  #[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
  use crate::coredump::GuestDebuggable;
-@@ -25,8 +25,6 @@ use crate::migration::{recv_vm_config, recv_vm_state};
- use crate::seccomp_filters::{get_seccomp_filter, Thread};
- use crate::vm::{Error as VmError, Vm, VmState};
- use anyhow::anyhow;
--#[cfg(feature = "dbus_api")]
--use api::dbus::{DBusApiOptions, DBusApiShutdownChannels};
- use libc::{tcsetattr, termios, EFD_NONBLOCK, SIGINT, SIGTERM, TCSANOW};
- use memory_manager::MemoryManagerSnapshotData;
- use pci::PciBdf;
-@@ -1171,6 +1169,32 @@ impl Vmm {
+@@ -1171,6 +1171,32 @@ impl Vmm {
          }
      }
  
@@ -1183,7 +1168,7 @@ index 96425b59..62c9aeff 100644
      fn vm_add_pmem(&mut self, pmem_cfg: PmemConfig) -> result::Result<Option<Vec<u8>>, VmError> {
          self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;
  
-@@ -2111,6 +2135,13 @@ impl Vmm {
+@@ -2111,6 +2137,13 @@ impl Vmm {
                                          .map(ApiResponsePayload::VmAction);
                                      sender.send(response).map_err(Error::ApiResponseSend)?;
                                  }
@@ -1197,7 +1182,7 @@ index 96425b59..62c9aeff 100644
                                  ApiRequest::VmAddPmem(add_pmem_data, sender) => {
                                      let response = self
                                          .vm_add_pmem(add_pmem_data.as_ref().clone())
-@@ -2276,6 +2307,7 @@ mod unit_tests {
+@@ -2276,6 +2309,7 @@ mod unit_tests {
              },
              balloon: None,
              fs: None,
@@ -1205,7 +1190,7 @@ index 96425b59..62c9aeff 100644
              pmem: None,
              serial: ConsoleConfig {
                  file: None,
-@@ -2505,6 +2537,54 @@ mod unit_tests {
+@@ -2505,6 +2539,54 @@ mod unit_tests {
          );
      }
  
@@ -1307,43 +1292,26 @@ index c6a0bec9..e8617d46 100644
          let pci_device_info = self
              .device_manager
 diff --git a/vmm/src/vm_config.rs b/vmm/src/vm_config.rs
-index dc028d89..b30a6f8b 100644
+index dc028d89..3bc41dc7 100644
 --- a/vmm/src/vm_config.rs
 +++ b/vmm/src/vm_config.rs
-@@ -423,6 +423,32 @@ impl Default for FsConfig {
+@@ -423,6 +423,15 @@ impl Default for FsConfig {
      }
  }
  
-+#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
++#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
 +pub struct GpuConfig {
 +    pub socket: PathBuf,
-+    #[serde(default = "default_gpuconfig_cache_size")]
-+    pub cache_size: u64,
 +    #[serde(default)]
 +    pub id: Option<String>,
 +    #[serde(default)]
 +    pub pci_segment: u16,
 +}
 +
-+impl Default for GpuConfig {
-+    fn default() -> Self {
-+        Self {
-+            socket: PathBuf::new(),
-+            cache_size: default_gpuconfig_cache_size(),
-+            id: None,
-+            pci_segment: 0,
-+        }
-+    }
-+}
-+
-+pub fn default_gpuconfig_cache_size() -> u64 {
-+    1 << 33
-+}
-+
  #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
  pub struct PmemConfig {
      pub file: PathBuf,
-@@ -594,6 +620,7 @@ pub struct VmConfig {
+@@ -594,6 +603,7 @@ pub struct VmConfig {
      pub rng: RngConfig,
      pub balloon: Option<BalloonConfig>,
      pub fs: Option<Vec<FsConfig>>,
diff --git a/pkgs/cloud-hypervisor/Cargo.lock b/pkgs/cloud-hypervisor/Cargo.lock
index c6675f2..fbab2e1 100644
--- a/pkgs/cloud-hypervisor/Cargo.lock
+++ b/pkgs/cloud-hypervisor/Cargo.lock
@@ -2542,7 +2542,6 @@ dependencies = [
  "versionize_derive",
  "vfio-ioctls",
  "vfio_user",
- "virtio-bindings",
  "virtio-devices",
  "virtio-queue",
  "vm-allocator",