MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / update_memory

Method update_memory

vmm/src/device_manager.rs:4545–4601  ·  view source on GitHub ↗
(&self, new_region: &Arc<GuestRegionMmap>)

Source from the content-addressed store, hash-verified

4543 }
4544
4545 pub fn update_memory(&self, new_region: &Arc<GuestRegionMmap>) -> DeviceManagerResult<()> {
4546 for handle in self.virtio_devices.iter() {
4547 handle
4548 .virtio_device
4549 .lock()
4550 .unwrap()
4551 .add_memory_region(new_region)
4552 .map_err(DeviceManagerError::UpdateMemoryForVirtioDevice)?;
4553
4554 if let Some(dma_handler) = &handle.dma_handler
4555 && !handle.pci_common.iommu
4556 {
4557 let gpa = new_region.start_addr().0;
4558 let size = new_region.len();
4559 dma_handler
4560 .map(gpa, gpa, size)
4561 .map_err(DeviceManagerError::VirtioDmaMap)?;
4562 }
4563 }
4564
4565 // Take care of updating the memory for VFIO PCI devices.
4566 if let Some(vfio_ops) = &self.vfio_ops {
4567 // vfio_dma_map is unsound and ought to be marked as unsafe
4568 #[allow(unused_unsafe)]
4569 // SAFETY: GuestMemoryMmap guarantees that region points
4570 // to len bytes of valid memory starting at as_ptr()
4571 // that will only be freed with munmap().
4572 unsafe {
4573 vfio_ops.vfio_dma_map(
4574 new_region.start_addr().raw_value(),
4575 new_region.len() as usize,
4576 new_region.as_ptr(),
4577 )
4578 }
4579 .map_err(DeviceManagerError::UpdateMemoryForVfioPciDevice)?;
4580 }
4581
4582 // Take care of updating the memory for vfio-user devices.
4583 {
4584 let device_tree = self.device_tree.lock().unwrap();
4585 for pci_device_node in device_tree.pci_devices() {
4586 if let PciDeviceHandle::VfioUser(vfio_user_pci_device) = pci_device_node
4587 .pci_device_handle
4588 .as_ref()
4589 .ok_or(DeviceManagerError::MissingPciDevice)?
4590 {
4591 vfio_user_pci_device
4592 .lock()
4593 .unwrap()
4594 .dma_map(new_region)
4595 .map_err(DeviceManagerError::UpdateMemoryForVfioUserPciDevice)?;
4596 }
4597 }
4598 }
4599
4600 Ok(())
4601 }
4602

Callers 1

resizeMethod · 0.45

Calls 7

iterMethod · 0.80
start_addrMethod · 0.80
pci_devicesMethod · 0.80
add_memory_regionMethod · 0.45
lenMethod · 0.45
mapMethod · 0.45
dma_mapMethod · 0.45

Tested by

no test coverage detected