From ec058d6c46c8602d49e347afa15c918f05cf6821 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Mon, 20 Jul 2020 20:21:11 -0700 Subject: [PATCH] vm_memory: A crate to hold vm-specific memory objects Move GuestAddress and GuestMemory to a new crate for VM memory. This will make separating sys_util and crosvm independent making it easier to use sys_util functions outside of crosvm. Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251 Auto-Submit: Dylan Reid Commit-Queue: Dylan Reid Tested-by: Dylan Reid Reviewed-by: Zach Reizner --- Cargo.lock | 22 ++++++++ Cargo.toml | 2 + aarch64/Cargo.toml | 1 + aarch64/src/fdt.rs | 2 +- aarch64/src/lib.rs | 3 +- arch/Cargo.toml | 1 + arch/src/lib.rs | 3 +- arch/src/pstore.rs | 3 +- cros_async/Cargo.toml | 1 + cros_async/src/uring_futures/uring_source.rs | 2 +- devices/Cargo.toml | 1 + devices/src/ioapic.rs | 2 +- devices/src/irqchip/kvm/mod.rs | 2 +- devices/src/irqchip/kvm/x86_64.rs | 3 +- devices/src/pci/ac97.rs | 5 +- devices/src/pci/ac97_bus_master.rs | 7 ++- .../src/usb/xhci/command_ring_controller.rs | 3 +- devices/src/usb/xhci/device_slot.rs | 3 +- devices/src/usb/xhci/event_ring.rs | 2 +- devices/src/usb/xhci/interrupter.rs | 3 +- devices/src/usb/xhci/ring_buffer.rs | 2 +- .../src/usb/xhci/ring_buffer_controller.rs | 3 +- devices/src/usb/xhci/scatter_gather_buffer.rs | 2 +- .../src/usb/xhci/transfer_ring_controller.rs | 3 +- devices/src/usb/xhci/xhci.rs | 3 +- devices/src/usb/xhci/xhci_abi.rs | 2 +- devices/src/usb/xhci/xhci_controller.rs | 3 +- devices/src/usb/xhci/xhci_transfer.rs | 3 +- devices/src/vfio.rs | 4 +- devices/src/virtio/balloon.rs | 5 +- devices/src/virtio/block.rs | 5 +- devices/src/virtio/console.rs | 3 +- devices/src/virtio/descriptor_utils.rs | 5 +- devices/src/virtio/fs/mod.rs | 3 +- devices/src/virtio/fs/worker.rs | 3 +- devices/src/virtio/gpu/mod.rs | 3 +- devices/src/virtio/gpu/virtio_2d_backend.rs | 3 +- devices/src/virtio/gpu/virtio_3d_backend.rs | 3 +- devices/src/virtio/gpu/virtio_backend.rs | 3 +- .../virtio/gpu/virtio_gfxstream_backend.rs | 3 +- devices/src/virtio/input/mod.rs | 3 +- devices/src/virtio/net.rs | 3 +- devices/src/virtio/p9.rs | 3 +- devices/src/virtio/pmem.rs | 3 +- devices/src/virtio/queue.rs | 3 +- devices/src/virtio/rng.rs | 3 +- devices/src/virtio/tpm.rs | 3 +- devices/src/virtio/vhost/net.rs | 5 +- devices/src/virtio/vhost/vsock.rs | 3 +- devices/src/virtio/video/mod.rs | 3 +- devices/src/virtio/video/worker.rs | 3 +- devices/src/virtio/virtio_device.rs | 3 +- .../src/virtio/virtio_pci_common_config.rs | 6 ++- devices/src/virtio/virtio_pci_device.rs | 3 +- devices/src/virtio/wl.rs | 5 +- fuzz/block_fuzzer.rs | 3 +- fuzz/fs_server_fuzzer.rs | 2 +- fuzz/virtqueue_fuzzer.rs | 2 +- fuzz/zimage_fuzzer.rs | 3 +- gpu_renderer/Cargo.toml | 1 + gpu_renderer/src/lib.rs | 2 +- hypervisor/Cargo.toml | 1 + hypervisor/src/kvm/aarch64.rs | 2 +- hypervisor/src/kvm/mod.rs | 7 +-- hypervisor/src/kvm/x86_64.rs | 5 +- hypervisor/src/lib.rs | 3 +- hypervisor/src/x86_64.rs | 3 +- kernel_loader/Cargo.toml | 1 + kernel_loader/src/lib.rs | 5 +- kvm/Cargo.toml | 1 + kvm/src/lib.rs | 5 +- kvm/tests/dirty_log.rs | 3 +- kvm/tests/read_only_memory.rs | 3 +- kvm/tests/real_run_adder.rs | 2 +- src/linux.rs | 7 +-- src/plugin/mod.rs | 6 +-- src/plugin/process.rs | 5 +- sys_util/src/lib.rs | 5 -- vhost/Cargo.toml | 1 + vhost/src/lib.rs | 5 +- vhost/src/net.rs | 3 +- vhost/src/vsock.rs | 3 +- vm_control/Cargo.toml | 1 + vm_control/src/lib.rs | 5 +- vm_memory/Cargo.toml | 14 +++++ {sys_util => vm_memory}/src/guest_address.rs | 2 +- {sys_util => vm_memory}/src/guest_memory.rs | 53 +++++++++++-------- vm_memory/src/lib.rs | 11 ++++ x86_64/Cargo.toml | 1 + x86_64/src/acpi.rs | 2 +- x86_64/src/bzimage.rs | 2 +- x86_64/src/fdt.rs | 2 +- x86_64/src/lib.rs | 3 +- x86_64/src/mptable.rs | 2 +- x86_64/src/regs.rs | 5 +- x86_64/src/smbios.rs | 2 +- 96 files changed, 250 insertions(+), 131 deletions(-) create mode 100644 vm_memory/Cargo.toml rename {sys_util => vm_memory}/src/guest_address.rs (98%) rename {sys_util => vm_memory}/src/guest_memory.rs (95%) create mode 100644 vm_memory/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index dd035a5037..8f161dc71a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,7 @@ dependencies = [ "sync 0.1.0", "sys_util 0.1.0", "vm_control 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -40,6 +41,7 @@ dependencies = [ "sync 0.1.0", "sys_util 0.1.0", "vm_control 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -104,6 +106,7 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "sys_util 0.1.0", "syscall_defines 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -142,6 +145,7 @@ dependencies = [ "sys_util 0.1.0", "vhost 0.1.0", "vm_control 0.1.0", + "vm_memory 0.1.0", "x86_64 0.1.0", ] @@ -207,6 +211,7 @@ dependencies = [ "vhost 0.1.0", "virtio_sys 0.1.0", "vm_control 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -346,6 +351,7 @@ dependencies = [ "data_model 0.1.0", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "sys_util 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -361,6 +367,7 @@ dependencies = [ "msg_socket 0.1.0", "sync 0.1.0", "sys_util 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -385,6 +392,7 @@ version = "0.1.0" dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "sys_util 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -397,6 +405,7 @@ dependencies = [ "msg_socket 0.1.0", "sync 0.1.0", "sys_util 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -772,6 +781,7 @@ dependencies = [ "net_util 0.1.0", "sys_util 0.1.0", "virtio_sys 0.1.0", + "vm_memory 0.1.0", ] [[package]] @@ -792,6 +802,17 @@ dependencies = [ "resources 0.1.0", "sync 0.1.0", "sys_util 0.1.0", + "vm_memory 0.1.0", +] + +[[package]] +name = "vm_memory" +version = "0.1.0" +dependencies = [ + "data_model 0.1.0", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "sys_util 0.1.0", + "syscall_defines 0.1.0", ] [[package]] @@ -823,6 +844,7 @@ dependencies = [ "sync 0.1.0", "sys_util 0.1.0", "vm_control 0.1.0", + "vm_memory 0.1.0", ] [metadata] diff --git a/Cargo.toml b/Cargo.toml index e3d6f53f95..da6964ef16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ exclude = [ "sys_util", "syscall_defines", "tempfile", + "vm_memory", "hypervisor" ] @@ -77,6 +78,7 @@ sys_util = "*" vhost = { path = "vhost" } vm_control = { path = "vm_control" } acpi_tables = { path = "acpi_tables" } +vm_memory = { path = "vm_memory" } [target.'cfg(target_arch = "x86_64")'.dependencies] x86_64 = { path = "x86_64" } diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml index 45f89cde1c..d14a6820d6 100644 --- a/aarch64/Cargo.toml +++ b/aarch64/Cargo.toml @@ -18,3 +18,4 @@ resources = { path = "../resources" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } vm_control = { path = "../vm_control" } +vm_memory = { path = "../vm_memory" } diff --git a/aarch64/src/fdt.rs b/aarch64/src/fdt.rs index 19662c6b8f..6cc80d1a92 100644 --- a/aarch64/src/fdt.rs +++ b/aarch64/src/fdt.rs @@ -12,7 +12,7 @@ use arch::fdt::{ }; use arch::SERIAL_ADDR; use devices::{PciAddress, PciInterruptPin}; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; // This is the start of DRAM in the physical address space. use crate::AARCH64_PHYS_MEM_START; diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs index 17b2344aa9..19d0a3c490 100644 --- a/aarch64/src/lib.rs +++ b/aarch64/src/lib.rs @@ -20,8 +20,9 @@ use minijail::Minijail; use remain::sorted; use resources::SystemAllocator; use sync::Mutex; -use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError}; +use sys_util::EventFd; use vm_control::VmIrqRequestSocket; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; use kvm::*; use kvm_sys::kvm_device_attr; diff --git a/arch/Cargo.toml b/arch/Cargo.toml index d322a07c13..eca06e5b70 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -15,3 +15,4 @@ resources = { path = "../resources" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } vm_control = { path = "../vm_control" } +vm_memory = { path = "../vm_memory" } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 2d7ce67085..48f0a76193 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -27,8 +27,9 @@ use kvm::{IoeventAddress, Kvm, Vcpu, Vm}; use minijail::Minijail; use resources::SystemAllocator; use sync::Mutex; -use sys_util::{syslog, EventFd, GuestAddress, GuestMemory, GuestMemoryError}; +use sys_util::{syslog, EventFd}; use vm_control::VmIrqRequestSocket; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; pub use serial::{ add_serial_devices, get_serial_cmdline, set_default_serial_parameters, GetSerialCmdlineError, diff --git a/arch/src/pstore.rs b/arch/src/pstore.rs index a6c5e612c6..19c67b9385 100644 --- a/arch/src/pstore.rs +++ b/arch/src/pstore.rs @@ -10,7 +10,8 @@ use crate::Pstore; use kvm::Vm; use resources::SystemAllocator; use resources::{Alloc, MmioType}; -use sys_util::{GuestAddress, MemoryMapping}; +use sys_util::MemoryMapping; +use vm_memory::GuestAddress; /// Error for pstore. #[derive(Debug)] diff --git a/cros_async/Cargo.toml b/cros_async/Cargo.toml index d2dce813cb..c8760ee7d3 100644 --- a/cros_async/Cargo.toml +++ b/cros_async/Cargo.toml @@ -11,6 +11,7 @@ paste = "*" pin-utils = "0.1.0-alpha.4" sys_util = { path = "../sys_util" } syscall_defines = { path = "../syscall_defines" } +vm_memory = { path = "../vm_memory" } [dependencies.futures] version = "*" diff --git a/cros_async/src/uring_futures/uring_source.rs b/cros_async/src/uring_futures/uring_source.rs index d8dbbf147c..fca914f55a 100644 --- a/cros_async/src/uring_futures/uring_source.rs +++ b/cros_async/src/uring_futures/uring_source.rs @@ -192,7 +192,7 @@ mod tests { #[test] fn read_to_mem() { - use sys_util::{GuestAddress, GuestMemory}; + use vm_memory::{GuestAddress, GuestMemory}; use crate::uring_mem::VecIoWrapper; diff --git a/devices/Cargo.toml b/devices/Cargo.toml index d042662015..2c75e5e3a3 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -52,6 +52,7 @@ vfio_sys = { path = "../vfio_sys" } vhost = { path = "../vhost" } virtio_sys = { path = "../virtio_sys" } vm_control = { path = "../vm_control" } +vm_memory = { path = "../vm_memory" } [dev-dependencies] tempfile = { path = "../tempfile" } diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index 09ccb896c7..20ecffdb37 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -360,7 +360,7 @@ mod tests { fn new() -> Ioapic { let kvm = kvm::Kvm::new().unwrap(); - let gm = sys_util::GuestMemory::new(&vec![(sys_util::GuestAddress(0), 0x1000)]).unwrap(); + let gm = vm_memory::GuestMemory::new(&vec![(vm_memory::GuestAddress(0), 0x1000)]).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap(); vm.enable_split_irqchip().unwrap(); let (_, device_socket) = msg_socket::pair::().unwrap(); diff --git a/devices/src/irqchip/kvm/mod.rs b/devices/src/irqchip/kvm/mod.rs index 766c4cc3ca..d1ff076485 100644 --- a/devices/src/irqchip/kvm/mod.rs +++ b/devices/src/irqchip/kvm/mod.rs @@ -156,7 +156,7 @@ mod tests { use hypervisor::kvm::{Kvm, KvmVm}; use hypervisor::{MPState, Vm}; - use sys_util::GuestMemory; + use vm_memory::GuestMemory; use crate::irqchip::{IrqChip, KvmKernelIrqChip}; diff --git a/devices/src/irqchip/kvm/x86_64.rs b/devices/src/irqchip/kvm/x86_64.rs index 135aca7734..5477e82483 100644 --- a/devices/src/irqchip/kvm/x86_64.rs +++ b/devices/src/irqchip/kvm/x86_64.rs @@ -641,7 +641,8 @@ mod tests { use super::*; use hypervisor::kvm::Kvm; - use sys_util::{EventReadResult, GuestMemory}; + use sys_util::EventReadResult; + use vm_memory::GuestMemory; use hypervisor::{IoapicRedirectionTableEntry, PitRWMode, TriggerMode, Vm, VmX86_64}; use vm_control::{VmIrqRequest, VmIrqResponse}; diff --git a/devices/src/pci/ac97.rs b/devices/src/pci/ac97.rs index 8182a4c79d..6f8cc0daba 100644 --- a/devices/src/pci/ac97.rs +++ b/devices/src/pci/ac97.rs @@ -14,7 +14,8 @@ use audio_streams::{ }; use libcras::{CrasClient, CrasClientType, CrasSocketType}; use resources::{Alloc, MmioType, SystemAllocator}; -use sys_util::{error, EventFd, GuestMemory}; +use sys_util::{error, EventFd}; +use vm_memory::GuestMemory; use crate::pci::ac97_bus_master::Ac97BusMaster; use crate::pci::ac97_mixer::Ac97Mixer; @@ -336,7 +337,7 @@ impl PciDevice for Ac97Dev { mod tests { use super::*; use audio_streams::shm_streams::MockShmStreamSource; - use sys_util::GuestAddress; + use vm_memory::GuestAddress; #[test] fn create() { diff --git a/devices/src/pci/ac97_bus_master.rs b/devices/src/pci/ac97_bus_master.rs index 68c7912837..e3351cf754 100644 --- a/devices/src/pci/ac97_bus_master.rs +++ b/devices/src/pci/ac97_bus_master.rs @@ -17,9 +17,8 @@ use audio_streams::{ BoxError, DummyStreamControl, SampleFormat, StreamControl, StreamDirection, StreamEffect, }; use sync::{Condvar, Mutex}; -use sys_util::{ - self, error, set_rt_prio_limit, set_rt_round_robin, warn, EventFd, GuestAddress, GuestMemory, -}; +use sys_util::{self, error, set_rt_prio_limit, set_rt_round_robin, warn, EventFd}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::pci::ac97_mixer::Ac97Mixer; use crate::pci::ac97_regs::*; @@ -95,7 +94,7 @@ impl Ac97BusMasterRegs { #[derive(Debug)] enum GuestMemoryError { // Failure getting the address of the audio buffer. - ReadingGuestBufferAddress(sys_util::GuestMemoryError), + ReadingGuestBufferAddress(vm_memory::GuestMemoryError), } impl std::error::Error for GuestMemoryError {} diff --git a/devices/src/usb/xhci/command_ring_controller.rs b/devices/src/usb/xhci/command_ring_controller.rs index e893194f7a..8ade7923de 100644 --- a/devices/src/usb/xhci/command_ring_controller.rs +++ b/devices/src/usb/xhci/command_ring_controller.rs @@ -18,7 +18,8 @@ use crate::utils::EventLoop; use std::fmt::{self, Display}; use std::sync::Arc; use sync::Mutex; -use sys_util::{error, warn, Error as SysError, EventFd, GuestAddress, GuestMemory}; +use sys_util::{error, warn, Error as SysError, EventFd}; +use vm_memory::{GuestAddress, GuestMemory}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/device_slot.rs b/devices/src/usb/xhci/device_slot.rs index 22cfb1d149..818377fc60 100644 --- a/devices/src/usb/xhci/device_slot.rs +++ b/devices/src/usb/xhci/device_slot.rs @@ -20,7 +20,8 @@ use std::mem::size_of; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use sync::Mutex; -use sys_util::{error, GuestAddress, GuestMemory, GuestMemoryError}; +use sys_util::error; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/event_ring.rs b/devices/src/usb/xhci/event_ring.rs index 4711c46bc7..46dad4a2c7 100644 --- a/devices/src/usb/xhci/event_ring.rs +++ b/devices/src/usb/xhci/event_ring.rs @@ -6,7 +6,7 @@ use data_model::DataInit; use std::fmt::{self, Display}; use std::mem::size_of; use std::sync::atomic::{fence, Ordering}; -use sys_util::{GuestAddress, GuestMemory, GuestMemoryError}; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; use super::xhci_abi::*; diff --git a/devices/src/usb/xhci/interrupter.rs b/devices/src/usb/xhci/interrupter.rs index cf79fd8567..41c8e7c710 100644 --- a/devices/src/usb/xhci/interrupter.rs +++ b/devices/src/usb/xhci/interrupter.rs @@ -10,7 +10,8 @@ use super::xhci_abi::{ use super::xhci_regs::*; use crate::register_space::Register; use std::fmt::{self, Display}; -use sys_util::{Error as SysError, EventFd, GuestAddress, GuestMemory}; +use sys_util::{Error as SysError, EventFd}; +use vm_memory::{GuestAddress, GuestMemory}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/ring_buffer.rs b/devices/src/usb/xhci/ring_buffer.rs index 91806c6ea3..64ca6f7f5f 100644 --- a/devices/src/usb/xhci/ring_buffer.rs +++ b/devices/src/usb/xhci/ring_buffer.rs @@ -7,7 +7,7 @@ use super::xhci_abi::{ }; use std::fmt::{self, Display}; use std::mem::size_of; -use sys_util::{GuestAddress, GuestMemory, GuestMemoryError}; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/ring_buffer_controller.rs b/devices/src/usb/xhci/ring_buffer_controller.rs index 8dd5426082..d1a0dbf1a2 100644 --- a/devices/src/usb/xhci/ring_buffer_controller.rs +++ b/devices/src/usb/xhci/ring_buffer_controller.rs @@ -9,7 +9,8 @@ use std::fmt::{self, Display}; use std::sync::{Arc, MutexGuard}; use sync::Mutex; -use sys_util::{error, Error as SysError, EventFd, GuestAddress, GuestMemory, WatchingEvents}; +use sys_util::{error, Error as SysError, EventFd, WatchingEvents}; +use vm_memory::{GuestAddress, GuestMemory}; use super::ring_buffer::RingBuffer; diff --git a/devices/src/usb/xhci/scatter_gather_buffer.rs b/devices/src/usb/xhci/scatter_gather_buffer.rs index f64f778b15..d67e92bd1d 100644 --- a/devices/src/usb/xhci/scatter_gather_buffer.rs +++ b/devices/src/usb/xhci/scatter_gather_buffer.rs @@ -7,7 +7,7 @@ use super::xhci_abi::{ }; use bit_field::Error as BitFieldError; use std::fmt::{self, Display}; -use sys_util::{GuestAddress, GuestMemory, GuestMemoryError}; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/transfer_ring_controller.rs b/devices/src/usb/xhci/transfer_ring_controller.rs index 0b5d3b64b2..9ba8a7a7a8 100644 --- a/devices/src/usb/xhci/transfer_ring_controller.rs +++ b/devices/src/usb/xhci/transfer_ring_controller.rs @@ -8,7 +8,8 @@ use crate::usb::xhci::ring_buffer_controller::{ use crate::utils::EventLoop; use std::sync::Arc; use sync::Mutex; -use sys_util::{error, EventFd, GuestMemory}; +use sys_util::{error, EventFd}; +use vm_memory::GuestMemory; use super::interrupter::Interrupter; use super::usb_hub::UsbPort; diff --git a/devices/src/usb/xhci/xhci.rs b/devices/src/usb/xhci/xhci.rs index bd8e21775e..956017689a 100644 --- a/devices/src/usb/xhci/xhci.rs +++ b/devices/src/usb/xhci/xhci.rs @@ -16,7 +16,8 @@ use std::fmt::{self, Display}; use std::sync::Arc; use std::thread; use sync::Mutex; -use sys_util::{error, EventFd, GuestAddress, GuestMemory}; +use sys_util::{error, EventFd}; +use vm_memory::{GuestAddress, GuestMemory}; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/xhci_abi.rs b/devices/src/usb/xhci/xhci_abi.rs index e9be3c330f..ba5f78afd1 100644 --- a/devices/src/usb/xhci/xhci_abi.rs +++ b/devices/src/usb/xhci/xhci_abi.rs @@ -6,7 +6,7 @@ use bit_field::Error as BitFieldError; use bit_field::*; use data_model::DataInit; use std::fmt::{self, Display}; -use sys_util::GuestAddress; +use vm_memory::GuestAddress; #[derive(Debug)] pub enum Error { diff --git a/devices/src/usb/xhci/xhci_controller.rs b/devices/src/usb/xhci/xhci_controller.rs index 4c7d744677..dee779286e 100644 --- a/devices/src/usb/xhci/xhci_controller.rs +++ b/devices/src/usb/xhci/xhci_controller.rs @@ -17,7 +17,8 @@ use std::mem; use std::os::unix::io::RawFd; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use sys_util::{error, EventFd, GuestMemory}; +use sys_util::{error, EventFd}; +use vm_memory::GuestMemory; const XHCI_BAR0_SIZE: u64 = 0x10000; diff --git a/devices/src/usb/xhci/xhci_transfer.rs b/devices/src/usb/xhci/xhci_transfer.rs index 625f97ec7c..7e3ce4cb93 100644 --- a/devices/src/usb/xhci/xhci_transfer.rs +++ b/devices/src/usb/xhci/xhci_transfer.rs @@ -16,8 +16,9 @@ use std::fmt::{self, Display}; use std::mem; use std::sync::{Arc, Weak}; use sync::Mutex; -use sys_util::{error, Error as SysError, EventFd, GuestMemory}; +use sys_util::{error, Error as SysError, EventFd}; use usb_util::{TransferStatus, UsbRequestSetup}; +use vm_memory::GuestMemory; #[derive(Debug)] pub enum Error { diff --git a/devices/src/vfio.rs b/devices/src/vfio.rs index a5744303da..93550137b7 100644 --- a/devices/src/vfio.rs +++ b/devices/src/vfio.rs @@ -18,9 +18,9 @@ use sync::Mutex; use kvm::Vm; use sys_util::{ - ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val, warn, Error, - EventFd, GuestMemory, + ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val, warn, Error, EventFd, }; +use vm_memory::GuestMemory; use vfio_sys::*; diff --git a/devices/src/virtio/balloon.rs b/devices/src/virtio/balloon.rs index 30417fae88..5792a83bce 100644 --- a/devices/src/virtio/balloon.rs +++ b/devices/src/virtio/balloon.rs @@ -10,12 +10,11 @@ use std::thread; use data_model::{DataInit, Le16, Le32, Le64}; use msg_socket::{MsgReceiver, MsgSender}; -use sys_util::{ - self, error, info, warn, EventFd, GuestAddress, GuestMemory, PollContext, PollToken, -}; +use sys_util::{self, error, info, warn, EventFd, PollContext, PollToken}; use vm_control::{ BalloonControlCommand, BalloonControlResponseSocket, BalloonControlResult, BalloonStats, }; +use vm_memory::{GuestAddress, GuestMemory}; use super::{ copy_config, Interrupt, Queue, Reader, VirtioDevice, TYPE_BALLOON, VIRTIO_F_VERSION_1, diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index 80d51030b3..b224470ebc 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -19,9 +19,10 @@ use msg_socket::{MsgReceiver, MsgSender}; use sync::Mutex; use sys_util::Error as SysError; use sys_util::Result as SysResult; -use sys_util::{error, info, iov_max, warn, EventFd, GuestMemory, PollContext, PollToken, TimerFd}; +use sys_util::{error, info, iov_max, warn, EventFd, PollContext, PollToken, TimerFd}; use virtio_sys::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use vm_control::{DiskControlCommand, DiskControlResponseSocket, DiskControlResult}; +use vm_memory::GuestMemory; use super::{ copy_config, DescriptorChain, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, @@ -818,8 +819,8 @@ impl VirtioDevice for Block { mod tests { use std::fs::{File, OpenOptions}; use std::mem::size_of_val; - use sys_util::GuestAddress; use tempfile::TempDir; + use vm_memory::GuestAddress; use crate::virtio::descriptor_utils::{create_descriptor_chain, DescriptorType}; diff --git a/devices/src/virtio/console.rs b/devices/src/virtio/console.rs index 50a5a76380..8e41986dfe 100644 --- a/devices/src/virtio/console.rs +++ b/devices/src/virtio/console.rs @@ -8,7 +8,8 @@ use std::sync::mpsc::{channel, Receiver, TryRecvError}; use std::thread; use data_model::{DataInit, Le16, Le32}; -use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, EventFd, PollContext, PollToken}; +use vm_memory::GuestMemory; use super::{ copy_config, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_CONSOLE, VIRTIO_F_VERSION_1, diff --git a/devices/src/virtio/descriptor_utils.rs b/devices/src/virtio/descriptor_utils.rs index c878a45a27..e0286ac0dc 100644 --- a/devices/src/virtio/descriptor_utils.rs +++ b/devices/src/virtio/descriptor_utils.rs @@ -14,14 +14,15 @@ use std::ptr::copy_nonoverlapping; use std::result; use data_model::{DataInit, Le16, Le32, Le64, VolatileMemoryError, VolatileSlice}; -use sys_util::{FileReadWriteAtVolatile, FileReadWriteVolatile, GuestAddress, GuestMemory}; +use sys_util::{FileReadWriteAtVolatile, FileReadWriteVolatile}; +use vm_memory::{GuestAddress, GuestMemory}; use super::DescriptorChain; #[derive(Debug)] pub enum Error { DescriptorChainOverflow, - GuestMemoryError(sys_util::GuestMemoryError), + GuestMemoryError(vm_memory::GuestMemoryError), InvalidChain, IoError(io::Error), SplitOutOfBounds(usize), diff --git a/devices/src/virtio/fs/mod.rs b/devices/src/virtio/fs/mod.rs index 9cac98b389..578bb3ed9c 100644 --- a/devices/src/virtio/fs/mod.rs +++ b/devices/src/virtio/fs/mod.rs @@ -11,7 +11,8 @@ use std::sync::Arc; use std::thread; use data_model::{DataInit, Le32}; -use sys_util::{error, warn, Error as SysError, EventFd, GuestMemory}; +use sys_util::{error, warn, Error as SysError, EventFd}; +use vm_memory::GuestMemory; use crate::virtio::{ copy_config, DescriptorError, Interrupt, Queue, VirtioDevice, TYPE_FS, VIRTIO_F_VERSION_1, diff --git a/devices/src/virtio/fs/worker.rs b/devices/src/virtio/fs/worker.rs index 36b8b69746..7e165e4c56 100644 --- a/devices/src/virtio/fs/worker.rs +++ b/devices/src/virtio/fs/worker.rs @@ -4,7 +4,8 @@ use std::sync::Arc; -use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, EventFd, PollContext, PollToken}; +use vm_memory::GuestMemory; use crate::virtio::fs::filesystem::FileSystem; use crate::virtio::fs::server::Server; diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index a6724d4ee1..3bcaa7f053 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -22,7 +22,8 @@ use std::time::Duration; use data_model::*; -use sys_util::{debug, error, warn, EventFd, GuestAddress, GuestMemory, PollContext, PollToken}; +use sys_util::{debug, error, warn, EventFd, PollContext, PollToken}; +use vm_memory::{GuestAddress, GuestMemory}; use gpu_buffer::Format; pub use gpu_display::EventDevice; diff --git a/devices/src/virtio/gpu/virtio_2d_backend.rs b/devices/src/virtio/gpu/virtio_2d_backend.rs index a9637030c3..61bb26c5ff 100644 --- a/devices/src/virtio/gpu/virtio_2d_backend.rs +++ b/devices/src/virtio/gpu/virtio_2d_backend.rs @@ -17,8 +17,9 @@ use data_model::*; use gpu_display::*; use gpu_renderer::RendererFlags; use resources::Alloc; -use sys_util::{error, GuestAddress, GuestMemory}; +use sys_util::error; use vm_control::VmMemoryControlRequestSocket; +use vm_memory::{GuestAddress, GuestMemory}; use super::protocol::GpuResponse; pub use super::virtio_backend::{VirtioBackend, VirtioResource}; diff --git a/devices/src/virtio/gpu/virtio_3d_backend.rs b/devices/src/virtio/gpu/virtio_3d_backend.rs index 4a8174bc1c..dca5bed134 100644 --- a/devices/src/virtio/gpu/virtio_3d_backend.rs +++ b/devices/src/virtio/gpu/virtio_3d_backend.rs @@ -17,7 +17,8 @@ use libc::EINVAL; use data_model::*; use msg_socket::{MsgReceiver, MsgSender}; use resources::Alloc; -use sys_util::{error, warn, Error, GuestAddress, GuestMemory}; +use sys_util::{error, warn, Error}; +use vm_memory::{GuestAddress, GuestMemory}; use gpu_display::*; use gpu_renderer::{ diff --git a/devices/src/virtio/gpu/virtio_backend.rs b/devices/src/virtio/gpu/virtio_backend.rs index 3200fa2c96..3e4fab2907 100644 --- a/devices/src/virtio/gpu/virtio_backend.rs +++ b/devices/src/virtio/gpu/virtio_backend.rs @@ -10,7 +10,8 @@ use std::rc::Rc; use super::protocol::GpuResponse; use data_model::*; use gpu_display::*; -use sys_util::{error, GuestMemory}; +use sys_util::error; +use vm_memory::GuestMemory; pub trait VirtioResource { fn width(&self) -> u32; diff --git a/devices/src/virtio/gpu/virtio_gfxstream_backend.rs b/devices/src/virtio/gpu/virtio_gfxstream_backend.rs index 977f561264..911d2734f7 100644 --- a/devices/src/virtio/gpu/virtio_gfxstream_backend.rs +++ b/devices/src/virtio/gpu/virtio_gfxstream_backend.rs @@ -20,8 +20,9 @@ use std::usize; use gpu_display::*; use gpu_renderer::RendererFlags; use resources::Alloc; -use sys_util::{error, GuestAddress, GuestMemory}; +use sys_util::error; use vm_control::VmMemoryControlRequestSocket; +use vm_memory::{GuestAddress, GuestMemory}; use super::protocol::GpuResponse; pub use super::virtio_backend::{VirtioBackend, VirtioResource}; diff --git a/devices/src/virtio/input/mod.rs b/devices/src/virtio/input/mod.rs index c789dd87fe..235dafc467 100644 --- a/devices/src/virtio/input/mod.rs +++ b/devices/src/virtio/input/mod.rs @@ -13,7 +13,8 @@ use self::constants::*; use std::os::unix::io::{AsRawFd, RawFd}; use data_model::{DataInit, Le16, Le32}; -use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, warn, EventFd, PollContext, PollToken}; +use vm_memory::GuestMemory; use self::event_source::{EvdevEventSource, EventSource, SocketEventSource}; use super::{ diff --git a/devices/src/virtio/net.rs b/devices/src/virtio/net.rs index 8e9aa9e3cc..9109ed08f7 100644 --- a/devices/src/virtio/net.rs +++ b/devices/src/virtio/net.rs @@ -15,12 +15,13 @@ use std::thread; use data_model::{DataInit, Le16, Le64}; use net_util::{Error as TapError, MacAddress, TapT}; use sys_util::Error as SysError; -use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken, WatchingEvents}; +use sys_util::{error, warn, EventFd, PollContext, PollToken, WatchingEvents}; use virtio_sys::virtio_net::{ virtio_net_hdr_v1, VIRTIO_NET_CTRL_GUEST_OFFLOADS, VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET, VIRTIO_NET_CTRL_MQ, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, VIRTIO_NET_ERR, VIRTIO_NET_OK, }; use virtio_sys::{vhost, virtio_net}; +use vm_memory::GuestMemory; use super::{ copy_config, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_NET, diff --git a/devices/src/virtio/p9.rs b/devices/src/virtio/p9.rs index 7854c39bb1..91cb8c4f22 100644 --- a/devices/src/virtio/p9.rs +++ b/devices/src/virtio/p9.rs @@ -10,8 +10,9 @@ use std::path::{Path, PathBuf}; use std::result; use std::thread; -use sys_util::{error, warn, Error as SysError, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, warn, Error as SysError, EventFd, PollContext, PollToken}; use virtio_sys::vhost::VIRTIO_F_VERSION_1; +use vm_memory::GuestMemory; use super::{ copy_config, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_9P, diff --git a/devices/src/virtio/pmem.rs b/devices/src/virtio/pmem.rs index cbeecc3dc1..b9db342854 100644 --- a/devices/src/virtio/pmem.rs +++ b/devices/src/virtio/pmem.rs @@ -8,8 +8,9 @@ use std::io; use std::os::unix::io::{AsRawFd, RawFd}; use std::thread; -use sys_util::{error, EventFd, GuestAddress, GuestMemory, PollContext, PollToken}; +use sys_util::{error, EventFd, PollContext, PollToken}; use sys_util::{Error as SysError, Result as SysResult}; +use vm_memory::{GuestAddress, GuestMemory}; use data_model::{DataInit, Le32, Le64}; diff --git a/devices/src/virtio/queue.rs b/devices/src/virtio/queue.rs index 56bc70fcb8..85852335a8 100644 --- a/devices/src/virtio/queue.rs +++ b/devices/src/virtio/queue.rs @@ -8,8 +8,9 @@ use std::os::unix::io::AsRawFd; use std::sync::atomic::{fence, Ordering}; use cros_async::{AsyncError, U64Source}; -use sys_util::{error, GuestAddress, GuestMemory}; +use sys_util::error; use virtio_sys::virtio_ring::VIRTIO_RING_F_EVENT_IDX; +use vm_memory::{GuestAddress, GuestMemory}; use super::{Interrupt, VIRTIO_MSI_NO_VECTOR}; diff --git a/devices/src/virtio/rng.rs b/devices/src/virtio/rng.rs index 3d7801fa96..84a1d062b7 100644 --- a/devices/src/virtio/rng.rs +++ b/devices/src/virtio/rng.rs @@ -8,7 +8,8 @@ use std::io; use std::os::unix::io::{AsRawFd, RawFd}; use std::thread; -use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, warn, EventFd, PollContext, PollToken}; +use vm_memory::GuestMemory; use super::{Interrupt, Queue, VirtioDevice, Writer, TYPE_RNG}; diff --git a/devices/src/virtio/tpm.rs b/devices/src/virtio/tpm.rs index 727c634586..53011d24f5 100644 --- a/devices/src/virtio/tpm.rs +++ b/devices/src/virtio/tpm.rs @@ -11,7 +11,8 @@ use std::os::unix::io::RawFd; use std::path::PathBuf; use std::thread; -use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken}; +use sys_util::{error, EventFd, PollContext, PollToken}; +use vm_memory::GuestMemory; use super::{ DescriptorChain, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_TPM, diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index ce132267cf..ecae68b4c0 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -9,9 +9,10 @@ use std::thread; use net_util::{MacAddress, TapT}; -use sys_util::{error, warn, EventFd, GuestMemory}; +use sys_util::{error, warn, EventFd}; use vhost::NetT as VhostNetT; use virtio_sys::virtio_net; +use vm_memory::GuestMemory; use super::control_socket::*; use super::worker::Worker; @@ -350,8 +351,8 @@ pub mod tests { use std::result; use std::sync::atomic::AtomicUsize; use std::sync::Arc; - use sys_util::{GuestAddress, GuestMemory, GuestMemoryError}; use vhost::net::fakes::FakeNet; + use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; fn create_guest_memory() -> result::Result { let start_addr1 = GuestAddress(0x0); diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs index 390c857ee7..73f9acd96e 100644 --- a/devices/src/virtio/vhost/vsock.rs +++ b/devices/src/virtio/vhost/vsock.rs @@ -7,9 +7,10 @@ use std::thread; use data_model::{DataInit, Le64}; -use sys_util::{error, warn, EventFd, GuestMemory}; +use sys_util::{error, warn, EventFd}; use vhost::Vhost; use vhost::Vsock as VhostVsockHandle; +use vm_memory::GuestMemory; use super::worker::Worker; use super::{Error, Result}; diff --git a/devices/src/virtio/video/mod.rs b/devices/src/virtio/video/mod.rs index 7082d7cdab..0d871ed9b9 100644 --- a/devices/src/virtio/video/mod.rs +++ b/devices/src/virtio/video/mod.rs @@ -12,7 +12,8 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::thread; use data_model::{DataInit, Le32}; -use sys_util::{error, Error as SysError, EventFd, GuestMemory}; +use sys_util::{error, Error as SysError, EventFd}; +use vm_memory::GuestMemory; use crate::virtio::resource_bridge::ResourceRequestSocket; use crate::virtio::virtio_device::VirtioDevice; diff --git a/devices/src/virtio/video/worker.rs b/devices/src/virtio/video/worker.rs index 195854f0aa..06717895f8 100644 --- a/devices/src/virtio/video/worker.rs +++ b/devices/src/virtio/video/worker.rs @@ -6,7 +6,8 @@ use std::collections::{BTreeMap, VecDeque}; -use sys_util::{error, EventFd, GuestMemory, PollContext}; +use sys_util::{error, EventFd, PollContext}; +use vm_memory::GuestMemory; use crate::virtio::queue::{DescriptorChain, Queue}; use crate::virtio::resource_bridge::ResourceRequestSocket; diff --git a/devices/src/virtio/virtio_device.rs b/devices/src/virtio/virtio_device.rs index 7c076517f4..16bddf0e2e 100644 --- a/devices/src/virtio/virtio_device.rs +++ b/devices/src/virtio/virtio_device.rs @@ -4,7 +4,8 @@ use std::os::unix::io::RawFd; -use sys_util::{EventFd, GuestMemory}; +use sys_util::EventFd; +use vm_memory::GuestMemory; use super::*; use crate::pci::{MsixStatus, PciAddress, PciBarConfiguration, PciCapability}; diff --git a/devices/src/virtio/virtio_pci_common_config.rs b/devices/src/virtio/virtio_pci_common_config.rs index 97d7001e65..bbb9c7a8b9 100644 --- a/devices/src/virtio/virtio_pci_common_config.rs +++ b/devices/src/virtio/virtio_pci_common_config.rs @@ -4,7 +4,8 @@ use std::convert::TryInto; -use sys_util::{warn, GuestAddress}; +use sys_util::warn; +use vm_memory::GuestAddress; use super::*; @@ -243,7 +244,8 @@ mod tests { use super::*; use std::os::unix::io::RawFd; - use sys_util::{EventFd, GuestMemory}; + use sys_util::EventFd; + use vm_memory::GuestMemory; struct DummyDevice(u32); const QUEUE_SIZE: u16 = 256; diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs index c264ac0b6f..440f004e4b 100644 --- a/devices/src/virtio/virtio_pci_device.rs +++ b/devices/src/virtio/virtio_pci_device.rs @@ -11,7 +11,8 @@ use data_model::{DataInit, Le32}; use kvm::Datamatch; use libc::ERANGE; use resources::{Alloc, MmioType, SystemAllocator}; -use sys_util::{warn, EventFd, GuestMemory, Result}; +use sys_util::{warn, EventFd, Result}; +use vm_memory::GuestMemory; use super::*; use crate::pci::{ diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs index 3a5eceee22..d834160701 100644 --- a/devices/src/virtio/wl.rs +++ b/devices/src/virtio/wl.rs @@ -59,9 +59,10 @@ use resources::GpuMemoryDesc; #[cfg(feature = "wl-dmabuf")] use sys_util::ioctl_iow_nr; use sys_util::{ - error, pipe, round_up_to_page_size, warn, Error, EventFd, FileFlags, GuestMemory, - GuestMemoryError, PollContext, PollToken, Result, ScmSocket, SharedMemory, + error, pipe, round_up_to_page_size, warn, Error, EventFd, FileFlags, PollContext, PollToken, + Result, ScmSocket, SharedMemory, }; +use vm_memory::{GuestMemory, GuestMemoryError}; #[cfg(feature = "wl-dmabuf")] use sys_util::ioctl_with_ref; diff --git a/fuzz/block_fuzzer.rs b/fuzz/block_fuzzer.rs index ccd7c8510e..c4edbc88b3 100644 --- a/fuzz/block_fuzzer.rs +++ b/fuzz/block_fuzzer.rs @@ -13,7 +13,8 @@ use std::sync::Arc; use cros_fuzz::fuzz_target; use devices::virtio::{Block, Interrupt, Queue, VirtioDevice}; -use sys_util::{EventFd, GuestAddress, GuestMemory, SharedMemory}; +use sys_util::{EventFd, SharedMemory}; +use vm_memory::{GuestAddress, GuestMemory}; const MEM_SIZE: u64 = 256 * 1024 * 1024; const DESC_SIZE: u64 = 16; // Bytes in one virtio descriptor. diff --git a/fuzz/fs_server_fuzzer.rs b/fuzz/fs_server_fuzzer.rs index c824a0ae02..462282cdb0 100644 --- a/fuzz/fs_server_fuzzer.rs +++ b/fuzz/fs_server_fuzzer.rs @@ -9,7 +9,7 @@ use std::convert::TryInto; use cros_fuzz::fuzz_target; use devices::virtio::fs::fuzzing::fuzz_server; use devices::virtio::{create_descriptor_chain, DescriptorType, Reader, Writer}; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; const MEM_SIZE: u64 = 256 * 1024 * 1024; const BUFFER_ADDR: GuestAddress = GuestAddress(0x100); diff --git a/fuzz/virtqueue_fuzzer.rs b/fuzz/virtqueue_fuzzer.rs index 70ad330f9d..4f2c7acf93 100644 --- a/fuzz/virtqueue_fuzzer.rs +++ b/fuzz/virtqueue_fuzzer.rs @@ -10,7 +10,7 @@ use cros_fuzz::fuzz_target; use cros_fuzz::rand::FuzzRng; use devices::virtio::{DescriptorChain, Queue}; use rand::{Rng, RngCore}; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; const MAX_QUEUE_SIZE: u16 = 256; const MEM_SIZE: u64 = 1024 * 1024; diff --git a/fuzz/zimage_fuzzer.rs b/fuzz/zimage_fuzzer.rs index 971e75016e..5fffa23895 100644 --- a/fuzz/zimage_fuzzer.rs +++ b/fuzz/zimage_fuzzer.rs @@ -5,7 +5,8 @@ #![no_main] use cros_fuzz::fuzz_target; -use sys_util::{GuestAddress, GuestMemory, SharedMemory}; +use sys_util::SharedMemory; +use vm_memory::{GuestAddress, GuestMemory}; use std::fs::File; use std::io::Write; diff --git a/gpu_renderer/Cargo.toml b/gpu_renderer/Cargo.toml index b331f491d9..1240044791 100644 --- a/gpu_renderer/Cargo.toml +++ b/gpu_renderer/Cargo.toml @@ -12,3 +12,4 @@ gfxstream = [] data_model = { path = "../data_model" } libc = "*" sys_util = { path = "../sys_util" } +vm_memory = { path = "../vm_memory" } diff --git a/gpu_renderer/src/lib.rs b/gpu_renderer/src/lib.rs index 33f5357430..692e2ac2cc 100644 --- a/gpu_renderer/src/lib.rs +++ b/gpu_renderer/src/lib.rs @@ -24,7 +24,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use libc::close; use data_model::VolatileSlice; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::generated::p_defines::{ PIPE_BIND_RENDER_TARGET, PIPE_BIND_SAMPLER_VIEW, PIPE_TEXTURE_1D, PIPE_TEXTURE_2D, diff --git a/hypervisor/Cargo.toml b/hypervisor/Cargo.toml index aa38095442..46db508074 100644 --- a/hypervisor/Cargo.toml +++ b/hypervisor/Cargo.toml @@ -14,3 +14,4 @@ libc = "*" msg_socket = { path = "../msg_socket" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } +vm_memory = { path = "../vm_memory" } diff --git a/hypervisor/src/kvm/aarch64.rs b/hypervisor/src/kvm/aarch64.rs index 0edc4632c9..a5559bbbbe 100644 --- a/hypervisor/src/kvm/aarch64.rs +++ b/hypervisor/src/kvm/aarch64.rs @@ -177,7 +177,7 @@ mod tests { IoapicRedirectionTableEntry, IoapicState, IrqRoute, IrqSource, IrqSourceChip, LapicState, PicInitState, PicState, PitChannelState, PitRWMode, PitRWState, PitState, TriggerMode, Vm, }; - use sys_util::{GuestAddress, GuestMemory}; + use vm_memory::{GuestAddress, GuestMemory}; #[test] fn set_gsi_routing() { diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 80273830de..b34b7484ff 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -33,9 +33,9 @@ use sync::Mutex; use sys_util::{ block_signal, errno_result, error, ioctl, ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val, pagesize, signal, unblock_signal, AsRawDescriptor, Error, EventFd, FromRawDescriptor, - GuestAddress, GuestMemory, MappedRegion, MemoryMapping, MmapError, RawDescriptor, Result, - SafeDescriptor, + MappedRegion, MemoryMapping, MmapError, RawDescriptor, Result, SafeDescriptor, }; +use vm_memory::{GuestAddress, GuestMemory}; use crate::{ ClockState, Datamatch, DeviceKind, Hypervisor, HypervisorCap, IoEventAddress, IrqRoute, @@ -1097,7 +1097,8 @@ mod tests { use super::*; use std::os::unix::io::FromRawFd; use std::thread; - use sys_util::{pagesize, GuestAddress, MemoryMapping, MemoryMappingArena}; + use sys_util::{pagesize, MemoryMapping, MemoryMappingArena}; + use vm_memory::GuestAddress; #[test] fn dirty_log_size() { diff --git a/hypervisor/src/kvm/x86_64.rs b/hypervisor/src/kvm/x86_64.rs index eb98ca737f..e3a403f355 100644 --- a/hypervisor/src/kvm/x86_64.rs +++ b/hypervisor/src/kvm/x86_64.rs @@ -12,8 +12,9 @@ use data_model::vec_with_array_field; use kvm_sys::*; use sys_util::{ errno_result, error, ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, - ioctl_with_ref, ioctl_with_val, Error, GuestAddress, MappedRegion, Result, + ioctl_with_ref, ioctl_with_val, Error, MappedRegion, Result, }; +use vm_memory::GuestAddress; use super::{Kvm, KvmVcpu, KvmVm}; use crate::{ @@ -1136,7 +1137,7 @@ mod tests { PicInitState, PicState, PitChannelState, PitRWMode, PitRWState, PitState, TriggerMode, Vm, }; use libc::EINVAL; - use sys_util::{GuestAddress, GuestMemory}; + use vm_memory::{GuestAddress, GuestMemory}; #[test] fn get_supported_cpuid() { diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 5bd849ec25..fdf0c4af5f 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -14,7 +14,8 @@ use std::ops::{Deref, DerefMut}; use std::os::raw::c_int; use msg_socket::MsgOnSocket; -use sys_util::{EventFd, GuestAddress, GuestMemory, MappedRegion, Result, SafeDescriptor}; +use sys_util::{EventFd, MappedRegion, Result, SafeDescriptor}; +use vm_memory::{GuestAddress, GuestMemory}; #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub use crate::aarch64::*; diff --git a/hypervisor/src/x86_64.rs b/hypervisor/src/x86_64.rs index d86011e6d8..29e1b26161 100644 --- a/hypervisor/src/x86_64.rs +++ b/hypervisor/src/x86_64.rs @@ -3,7 +3,8 @@ // found in the LICENSE file. use bit_field::*; -use sys_util::{error, GuestAddress, Result}; +use sys_util::{error, Result}; +use vm_memory::GuestAddress; use crate::{Hypervisor, IrqRoute, IrqSource, IrqSourceChip, Vcpu, Vm}; diff --git a/kernel_loader/Cargo.toml b/kernel_loader/Cargo.toml index b49dbad856..64bee87dd9 100644 --- a/kernel_loader/Cargo.toml +++ b/kernel_loader/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] libc = "*" sys_util = { path = "../sys_util" } +vm_memory = { path = "../vm_memory" } diff --git a/kernel_loader/src/lib.rs b/kernel_loader/src/lib.rs index 31804da8ef..4a6fce4242 100644 --- a/kernel_loader/src/lib.rs +++ b/kernel_loader/src/lib.rs @@ -8,7 +8,7 @@ use std::io::{Read, Seek, SeekFrom}; use std::mem; use std::os::unix::io::AsRawFd; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; #[allow(dead_code)] #[allow(non_camel_case_types)] @@ -179,7 +179,8 @@ mod test { use super::*; use std::fs::File; use std::io::Write; - use sys_util::{GuestAddress, GuestMemory, SharedMemory}; + use sys_util::SharedMemory; + use vm_memory::{GuestAddress, GuestMemory}; const MEM_SIZE: u64 = 0x8000; diff --git a/kvm/Cargo.toml b/kvm/Cargo.toml index 9a6feee997..115cdaab77 100644 --- a/kvm/Cargo.toml +++ b/kvm/Cargo.toml @@ -11,3 +11,4 @@ libc = "*" msg_socket = { path = "../msg_socket" } sys_util = { path = "../sys_util" } sync = { path = "../sync" } +vm_memory = { path = "../vm_memory" } diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index 531c105c32..14fa68de96 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -29,9 +29,10 @@ use msg_socket::MsgOnSocket; #[allow(unused_imports)] use sys_util::{ block_signal, ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, - ioctl_with_val, pagesize, signal, unblock_signal, warn, Error, EventFd, GuestAddress, - GuestMemory, IoctlNr, MappedRegion, MemoryMapping, MmapError, Result, SIGRTMIN, + ioctl_with_val, pagesize, signal, unblock_signal, warn, Error, EventFd, IoctlNr, MappedRegion, + MemoryMapping, MmapError, Result, SIGRTMIN, }; +use vm_memory::{GuestAddress, GuestMemory}; pub use crate::cap::*; diff --git a/kvm/tests/dirty_log.rs b/kvm/tests/dirty_log.rs index 57d98667fd..e6cb6b6306 100644 --- a/kvm/tests/dirty_log.rs +++ b/kvm/tests/dirty_log.rs @@ -6,7 +6,8 @@ use kvm::*; use kvm_sys::kvm_regs; -use sys_util::{GuestAddress, GuestMemory, MemoryMapping, SharedMemory}; +use sys_util::{MemoryMapping, SharedMemory}; +use vm_memory::{GuestAddress, GuestMemory}; #[test] fn test_run() { diff --git a/kvm/tests/read_only_memory.rs b/kvm/tests/read_only_memory.rs index 36ba1b25b4..668a1dade3 100644 --- a/kvm/tests/read_only_memory.rs +++ b/kvm/tests/read_only_memory.rs @@ -6,7 +6,8 @@ use kvm::*; use kvm_sys::kvm_regs; -use sys_util::{GuestAddress, GuestMemory, MemoryMapping, SharedMemory}; +use sys_util::{MemoryMapping, SharedMemory}; +use vm_memory::{GuestAddress, GuestMemory}; #[test] fn test_run() { diff --git a/kvm/tests/real_run_adder.rs b/kvm/tests/real_run_adder.rs index 60869ed2c1..efd39d437e 100644 --- a/kvm/tests/real_run_adder.rs +++ b/kvm/tests/real_run_adder.rs @@ -6,7 +6,7 @@ use kvm::*; use kvm_sys::kvm_regs; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; #[test] fn test_run() { diff --git a/src/linux.rs b/src/linux.rs index 5d133ae42c..202097e004 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -49,9 +49,9 @@ use sys_util::net::{UnixSeqpacket, UnixSeqpacketListener, UnlinkUnixSeqpacketLis use sys_util::{ self, block_signal, clear_signal, drop_capabilities, error, flock, get_blocked_signals, get_group_id, get_user_id, getegid, geteuid, info, register_rt_signal_handler, - set_cpu_affinity, validate_raw_fd, warn, EventFd, ExternalMapping, FlockOperation, - GuestAddress, GuestMemory, Killable, MemoryMappingArena, PollContext, PollToken, Protection, - ScopedEvent, SignalFd, Terminal, TimerFd, WatchingEvents, SIGRTMIN, + set_cpu_affinity, validate_raw_fd, warn, EventFd, ExternalMapping, FlockOperation, Killable, + MemoryMappingArena, PollContext, PollToken, Protection, ScopedEvent, SignalFd, Terminal, + TimerFd, WatchingEvents, SIGRTMIN, }; use vm_control::{ BalloonControlCommand, BalloonControlRequestSocket, BalloonControlResponseSocket, @@ -61,6 +61,7 @@ use vm_control::{ VmMemoryRequest, VmMemoryResponse, VmMsyncRequest, VmMsyncRequestSocket, VmMsyncResponse, VmMsyncResponseSocket, VmRunMode, }; +use vm_memory::{GuestAddress, GuestMemory}; use crate::{Config, DiskOption, Executable, SharedDir, SharedDirKind, TouchDeviceOption}; use arch::{ diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index ad88dfdd2c..c71088344d 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -31,10 +31,10 @@ use minijail::{self, Minijail}; use net_util::{Error as TapError, Tap, TapT}; use sys_util::{ block_signal, clear_signal, drop_capabilities, error, getegid, geteuid, info, pipe, - register_rt_signal_handler, validate_raw_fd, warn, Error as SysError, EventFd, GuestMemory, - Killable, MmapError, PollContext, PollToken, Result as SysResult, SignalFd, SignalFdError, - SIGRTMIN, + register_rt_signal_handler, validate_raw_fd, warn, Error as SysError, EventFd, Killable, + MmapError, PollContext, PollToken, Result as SysResult, SignalFd, SignalFdError, SIGRTMIN, }; +use vm_memory::GuestMemory; use self::process::*; use self::vcpu::*; diff --git a/src/plugin/process.rs b/src/plugin/process.rs index 7bf9ceac7d..65b7f6f172 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -26,9 +26,10 @@ use minijail::Minijail; use protos::plugin::*; use sync::Mutex; use sys_util::{ - error, Error as SysError, EventFd, GuestAddress, Killable, MemoryMapping, Result as SysResult, - ScmSocket, SharedMemory, SIGRTMIN, + error, Error as SysError, EventFd, Killable, MemoryMapping, Result as SysResult, ScmSocket, + SharedMemory, SIGRTMIN, }; +use vm_memory::GuestAddress; use super::*; diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index 5c9ac38f65..e0673a0e6c 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -20,8 +20,6 @@ mod external_mapping; mod file_flags; pub mod file_traits; mod fork; -mod guest_address; -pub mod guest_memory; mod mmap; pub mod net; mod passwd; @@ -48,8 +46,6 @@ pub use crate::eventfd::*; pub use crate::external_mapping::*; pub use crate::file_flags::*; pub use crate::fork::*; -pub use crate::guest_address::*; -pub use crate::guest_memory::*; pub use crate::ioctl::*; pub use crate::mmap::*; pub use crate::passwd::*; @@ -72,7 +68,6 @@ pub use crate::file_traits::{ AsRawFds, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen, FileSync, }; -pub use crate::guest_memory::Error as GuestMemoryError; pub use crate::mmap::Error as MmapError; pub use crate::seek_hole::SeekHole; pub use crate::signalfd::Error as SignalFdError; diff --git a/vhost/Cargo.toml b/vhost/Cargo.toml index 567e880a4f..bedb346813 100644 --- a/vhost/Cargo.toml +++ b/vhost/Cargo.toml @@ -10,3 +10,4 @@ libc = "*" net_util = { path = "../net_util" } sys_util = { path = "../sys_util" } virtio_sys = { path = "../virtio_sys" } +vm_memory = { path = "../vm_memory" } diff --git a/vhost/src/lib.rs b/vhost/src/lib.rs index 04ba65565b..dcbf39e683 100644 --- a/vhost/src/lib.rs +++ b/vhost/src/lib.rs @@ -18,7 +18,8 @@ use std::ptr::null; use assertions::const_assert; use sys_util::{ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref}; -use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError, LayoutAllocation}; +use sys_util::{EventFd, LayoutAllocation}; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; #[derive(Debug)] pub enum Error { @@ -342,7 +343,7 @@ mod tests { use crate::net::fakes::FakeNet; use net_util::fakes::FakeTap; use std::result; - use sys_util::{GuestAddress, GuestMemory, GuestMemoryError}; + use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; fn create_guest_memory() -> result::Result { let start_addr1 = GuestAddress(0x0); diff --git a/vhost/src/net.rs b/vhost/src/net.rs index 9b59cf2704..e750162384 100644 --- a/vhost/src/net.rs +++ b/vhost/src/net.rs @@ -8,7 +8,8 @@ use std::marker::PhantomData; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; -use sys_util::{ioctl_with_ref, GuestMemory}; +use sys_util::ioctl_with_ref; +use vm_memory::GuestMemory; use super::{ioctl_result, Error, Result, Vhost}; diff --git a/vhost/src/vsock.rs b/vhost/src/vsock.rs index 8bd27e723b..af7e518256 100644 --- a/vhost/src/vsock.rs +++ b/vhost/src/vsock.rs @@ -6,8 +6,9 @@ use std::fs::{File, OpenOptions}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; -use sys_util::{ioctl_with_ref, GuestMemory}; +use sys_util::ioctl_with_ref; use virtio_sys::{VHOST_VSOCK_SET_GUEST_CID, VHOST_VSOCK_SET_RUNNING}; +use vm_memory::GuestMemory; use super::{ioctl_result, Error, Result, Vhost}; diff --git a/vm_control/Cargo.toml b/vm_control/Cargo.toml index c5dbfee0a5..39f0da8f92 100644 --- a/vm_control/Cargo.toml +++ b/vm_control/Cargo.toml @@ -12,3 +12,4 @@ msg_socket = { path = "../msg_socket" } resources = { path = "../resources" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } +vm_memory = { path = "../vm_memory" } diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index 72e7b97576..027c557121 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -24,9 +24,10 @@ use msg_socket::{MsgError, MsgOnSocket, MsgReceiver, MsgResult, MsgSender, MsgSo use resources::{Alloc, GpuMemoryDesc, MmioType, SystemAllocator}; use sync::Mutex; use sys_util::{ - error, Error as SysError, EventFd, ExternalMapping, GuestAddress, MappedRegion, MemoryMapping, - MmapError, Result, + error, Error as SysError, EventFd, ExternalMapping, MappedRegion, MemoryMapping, MmapError, + Result, }; +use vm_memory::GuestAddress; /// A file descriptor either borrowed or owned by this. #[derive(Debug)] diff --git a/vm_memory/Cargo.toml b/vm_memory/Cargo.toml new file mode 100644 index 0000000000..077eab7c47 --- /dev/null +++ b/vm_memory/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "vm_memory" +version = "0.1.0" +authors = ["The Chromium OS Authors"] +edition = "2018" +include = ["src/**/*", "Cargo.toml"] + +[dependencies] +data_model = { path = "../data_model" } # provided by ebuild +libc = "*" +sys_util = { path = "../sys_util" } # provided by ebuild +syscall_defines = { path = "../syscall_defines" } # provided by ebuild + +[workspace] diff --git a/sys_util/src/guest_address.rs b/vm_memory/src/guest_address.rs similarity index 98% rename from sys_util/src/guest_address.rs rename to vm_memory/src/guest_address.rs index 1b78e71122..075cf9f8c9 100644 --- a/sys_util/src/guest_address.rs +++ b/vm_memory/src/guest_address.rs @@ -18,7 +18,7 @@ impl GuestAddress { /// # Examples /// /// ``` - /// # use sys_util::GuestAddress; + /// # use vm_memory::GuestAddress; /// let base = GuestAddress(0x100); /// let addr = GuestAddress(0x150); /// assert_eq!(addr.offset_from(base), 0x50u64); diff --git a/sys_util/src/guest_memory.rs b/vm_memory/src/guest_memory.rs similarity index 95% rename from sys_util/src/guest_memory.rs rename to vm_memory/src/guest_memory.rs index b13b8cc12a..63275c8c03 100644 --- a/sys_util/src/guest_memory.rs +++ b/vm_memory/src/guest_memory.rs @@ -13,24 +13,24 @@ use std::result; use std::sync::Arc; use crate::guest_address::GuestAddress; -use crate::mmap::{self, MappedRegion, MemoryMapping}; -use crate::shm::{MemfdSeals, SharedMemory}; -use crate::{errno, pagesize}; use data_model::volatile_memory::*; use data_model::DataInit; +use sys_util::{pagesize, Error as SysError}; +use sys_util::{MappedRegion, MemoryMapping, MmapError}; +use sys_util::{MemfdSeals, SharedMemory}; #[derive(Debug)] pub enum Error { DescriptorChainOverflow, InvalidGuestAddress(GuestAddress), - MemoryAccess(GuestAddress, mmap::Error), - MemoryMappingFailed(mmap::Error), + MemoryAccess(GuestAddress, MmapError), + MemoryMappingFailed(MmapError), MemoryRegionOverlap, MemoryRegionTooLarge(u64), MemoryNotAligned, - MemoryCreationFailed(errno::Error), - MemorySetSizeFailed(errno::Error), - MemoryAddSealsFailed(errno::Error), + MemoryCreationFailed(SysError), + MemorySetSizeFailed(SysError), + MemoryAddSealsFailed(SysError), ShortWrite { expected: usize, completed: usize }, ShortRead { expected: usize, completed: usize }, SplitOutOfBounds(usize), @@ -198,7 +198,8 @@ impl GuestMemory { /// # Examples /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_end_addr() -> Result<(), ()> { /// let start_addr = GuestAddress(0x1000); /// let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?; @@ -292,7 +293,8 @@ impl GuestMemory { /// * Write a slice at guestaddress 0x200. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_write_u64() -> Result<(), ()> { /// # let start_addr = GuestAddress(0x1000); /// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?; @@ -319,7 +321,7 @@ impl GuestMemory { /// # Examples /// /// ``` - /// use sys_util::{guest_memory, GuestAddress, GuestMemory}; + /// use vm_memory::{guest_memory, GuestAddress, GuestMemory}; /// /// fn test_write_all() -> guest_memory::Result<()> { /// let ranges = &[(GuestAddress(0x1000), 0x400)]; @@ -349,7 +351,8 @@ impl GuestMemory { /// * Read a slice of length 16 at guestaddress 0x200. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_write_u64() -> Result<(), ()> { /// # let start_addr = GuestAddress(0x1000); /// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?; @@ -376,7 +379,7 @@ impl GuestMemory { /// # Examples /// /// ``` - /// use sys_util::{guest_memory, GuestAddress, GuestMemory, MemoryMapping}; + /// use vm_memory::{guest_memory, GuestAddress, GuestMemory}; /// /// fn test_read_exact() -> guest_memory::Result<()> { /// let ranges = &[(GuestAddress(0x1000), 0x400)]; @@ -407,7 +410,8 @@ impl GuestMemory { /// * Read a u64 from two areas of guest memory backed by separate mappings. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_read_u64() -> Result { /// # let start_addr1 = GuestAddress(0x0); /// # let start_addr2 = GuestAddress(0x400); @@ -433,7 +437,8 @@ impl GuestMemory { /// * Write a u64 at guest address 0x1100. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_write_u64() -> Result<(), ()> { /// # let start_addr = GuestAddress(0x1000); /// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?; @@ -456,7 +461,8 @@ impl GuestMemory { /// * Write `99` to 30 bytes starting at guest address 0x1010. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, GuestMemoryError, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; /// # fn test_volatile_slice() -> Result<(), GuestMemoryError> { /// # let start_addr = GuestAddress(0x1000); /// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)])?; @@ -487,7 +493,8 @@ impl GuestMemory { /// * Get a &u64 at offset 0x1010. /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, GuestMemoryError, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; /// # fn test_ref_u64() -> Result<(), GuestMemoryError> { /// # let start_addr = GuestAddress(0x1000); /// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)])?; @@ -516,7 +523,8 @@ impl GuestMemory { /// * Read bytes from /dev/urandom /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # use std::fs::File; /// # use std::path::Path; /// # fn test_read_random() -> Result { @@ -555,7 +563,8 @@ impl GuestMemory { /// * Write 128 bytes to /dev/null /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + /// # use sys_util::MemoryMapping; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # use std::fs::File; /// # use std::path::Path; /// # fn test_write_null() -> Result<(), ()> { @@ -591,7 +600,7 @@ impl GuestMemory { /// # Examples /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory}; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// # fn test_host_addr() -> Result<(), ()> { /// let start_addr = GuestAddress(0x1000); /// let mut gm = GuestMemory::new(&vec![(start_addr, 0x500)]).map_err(|_| ())?; @@ -637,7 +646,7 @@ impl GuestMemory { /// # Examples /// /// ``` - /// # use sys_util::{GuestAddress, GuestMemory}; + /// # use vm_memory::{GuestAddress, GuestMemory}; /// let addr_a = GuestAddress(0x1000); /// let addr_b = GuestAddress(0x8000); /// let mut gm = GuestMemory::new(&vec![ @@ -659,7 +668,7 @@ impl GuestMemory { #[cfg(test)] mod tests { use super::*; - use crate::kernel_has_memfd; + use sys_util::kernel_has_memfd; #[test] fn test_alignment() { diff --git a/vm_memory/src/lib.rs b/vm_memory/src/lib.rs new file mode 100644 index 0000000000..4067cd39b9 --- /dev/null +++ b/vm_memory/src/lib.rs @@ -0,0 +1,11 @@ +// Copyright 2020 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// + +mod guest_address; +pub mod guest_memory; + +pub use guest_address::*; +pub use guest_memory::Error as GuestMemoryError; +pub use guest_memory::*; diff --git a/x86_64/Cargo.toml b/x86_64/Cargo.toml index 0056ff8ae3..63d4d68176 100644 --- a/x86_64/Cargo.toml +++ b/x86_64/Cargo.toml @@ -21,3 +21,4 @@ sync = { path = "../sync" } sys_util = { path = "../sys_util" } acpi_tables = {path = "../acpi_tables" } vm_control = { path = "../vm_control" } +vm_memory = { path = "../vm_memory" } diff --git a/x86_64/src/acpi.rs b/x86_64/src/acpi.rs index e6fc15af99..95d3396e17 100644 --- a/x86_64/src/acpi.rs +++ b/x86_64/src/acpi.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. use acpi_tables::{rsdp::RSDP, sdt::SDT}; use data_model::DataInit; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; pub struct ACPIDevResource { pub amls: Vec, diff --git a/x86_64/src/bzimage.rs b/x86_64/src/bzimage.rs index d43d405dd6..8f5c539f7a 100644 --- a/x86_64/src/bzimage.rs +++ b/x86_64/src/bzimage.rs @@ -9,7 +9,7 @@ use std::fmt::{self, Display}; use std::io::{Read, Seek, SeekFrom}; use std::os::unix::io::AsRawFd; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::bootparam::boot_params; diff --git a/x86_64/src/fdt.rs b/x86_64/src/fdt.rs index 655a812d9f..b2c2611d96 100644 --- a/x86_64/src/fdt.rs +++ b/x86_64/src/fdt.rs @@ -7,7 +7,7 @@ use arch::fdt::{begin_node, end_node, finish_fdt, start_fdt, Error}; use data_model::DataInit; use std::fs::File; use std::mem; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::bootparam::setup_data; use crate::{SETUP_DTB, X86_64_FDT_MAX_SIZE}; diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index 7c75d76344..bfd8eefb67 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -70,8 +70,9 @@ use minijail::Minijail; use remain::sorted; use resources::SystemAllocator; use sync::Mutex; -use sys_util::{Clock, EventFd, GuestAddress, GuestMemory, GuestMemoryError}; +use sys_util::{Clock, EventFd}; use vm_control::VmIrqRequestSocket; +use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError}; #[sorted] #[derive(Debug)] diff --git a/x86_64/src/mptable.rs b/x86_64/src/mptable.rs index de489f2faf..3fa5aef080 100644 --- a/x86_64/src/mptable.rs +++ b/x86_64/src/mptable.rs @@ -11,7 +11,7 @@ use std::slice; use libc::c_char; use devices::{PciAddress, PciInterruptPin}; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::mpspec::*; diff --git a/x86_64/src/regs.rs b/x86_64/src/regs.rs index 1f5c816552..d9429ce36d 100644 --- a/x86_64/src/regs.rs +++ b/x86_64/src/regs.rs @@ -12,7 +12,8 @@ use kvm_sys::kvm_msr_entry; use kvm_sys::kvm_msrs; use kvm_sys::kvm_regs; use kvm_sys::kvm_sregs; -use sys_util::{self, warn, GuestAddress, GuestMemory, LayoutAllocation}; +use sys_util::{self, warn, LayoutAllocation}; +use vm_memory::{GuestAddress, GuestMemory}; use crate::gdt; @@ -413,7 +414,7 @@ pub fn setup_sregs(mem: &GuestMemory, vcpu: &kvm::Vcpu) -> Result<()> { #[cfg(test)] mod tests { use super::*; - use sys_util::{GuestAddress, GuestMemory}; + use vm_memory::{GuestAddress, GuestMemory}; fn create_guest_mem() -> GuestMemory { GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap() diff --git a/x86_64/src/smbios.rs b/x86_64/src/smbios.rs index 0ae3851164..31ce559f2c 100644 --- a/x86_64/src/smbios.rs +++ b/x86_64/src/smbios.rs @@ -8,7 +8,7 @@ use std::result; use std::slice; use data_model::DataInit; -use sys_util::{GuestAddress, GuestMemory}; +use vm_memory::{GuestAddress, GuestMemory}; #[derive(Debug)] pub enum Error {