Skip to content

Commit

Permalink
misc: Upgrade to use the vm-memory crate w/ dirty-page-tracking
Browse files Browse the repository at this point in the history
As the first step to complete live-migration with tracking dirty-pages
written by the VMM, this patch patches the dependent vm-memory crate to
the development branch with dirty-page-tracking capability [1]. For now,
we are using our own fork of the vm-memory crate [2] before the feature
is landed in the upstream.

Most changes are due to the updated `GuestMemoryMmap`, `GuestRegionMmap`,
and `MmapRegion` structs which are taking an additional generic type
parameter (to specify what 'bitmap backend' is used). For the same
reason, similar changes are required in the dependent 'vfio-ioctls'
crate (that uses the vm-memory crate). We are also using our own fork of
the vfio-ioctls crate before the upstream is updated [3].

The above changes should be transparent to the rest of the code base,
e.g. all unit/integration tests should pass without additional changes.

[1] rust-vmm/vm-memory#125
[2] https://github.com/cloud-hypervisor/vm-memory/tree/ch
[3] https://github.com/cloud-hypervisor/vfio-ioctls/tree/ch

Signed-off-by: Bo Chen <chen.bo@intel.com>
  • Loading branch information
likebreath committed May 27, 2021
1 parent a174ad0 commit b9de289
Show file tree
Hide file tree
Showing 54 changed files with 123 additions and 73 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ clap = { version = "2.33.3", features = ["wrap_help"] }
[patch.crates-io]
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.4.0", features = ["with-serde", "fam-wrappers"] }
versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch" }
vm-memory = { git = "https://github.com/cloud-hypervisor/vm-memory", branch = "ch"}

[dev-dependencies]
credibility = "0.1.3"
Expand Down
2 changes: 1 addition & 1 deletion arch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ serde_derive = ">=1.0.27"
serde_json = ">=1.0.9"
thiserror = "1.0"
vm-fdt = { git = "https://github.com/rust-vmm/vm-fdt", branch = "master" }
vm-memory = { version = "0.5.0", features = ["backend-mmap"] }
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-bitmap"] }
vm-migration = { path = "../vm-migration" }

3 changes: 2 additions & 1 deletion arch/src/aarch64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fmt::Debug;
use std::result;

use super::super::DeviceType;
use super::super::GuestMemoryMmap;
use super::super::InitramfsConfig;
use super::get_fdt_addr;
use super::gic::GicDevice;
Expand All @@ -20,7 +21,7 @@ use super::layout::{
PCI_MMCONFIG_START,
};
use vm_fdt::{FdtWriter, FdtWriterResult};
use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap};
use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestMemoryError};

// This is a value for uniquely identifying the FDT node declaring the interrupt controller.
const GIC_PHANDLE: u32 = 1;
Expand Down
4 changes: 2 additions & 2 deletions arch/src/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub mod regs;

pub use self::fdt::DeviceInfoForFdt;
use crate::DeviceType;
use crate::GuestMemoryMmap;
use crate::RegionType;
use gic::GicDevice;
use std::collections::HashMap;
use std::ffi::CStr;
use std::fmt::Debug;
use std::sync::Arc;
use vm_memory::{
Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestMemoryMmap,
GuestUsize,
Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestUsize,
};

/// Errors thrown while configuring aarch64 system.
Expand Down
2 changes: 1 addition & 1 deletion arch/src/aarch64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// found in the THIRD-PARTY file.

use super::get_fdt_addr;
use crate::GuestMemoryMmap;
use hypervisor::kvm::kvm_bindings::{
kvm_regs, user_pt_regs, KVM_REG_ARM64, KVM_REG_ARM_CORE, KVM_REG_SIZE_U64,
};
use hypervisor::{arm64_core_reg_id, offset__of};
use std::sync::Arc;
use std::{mem, result};
use vm_memory::GuestMemoryMmap;

/// Errors thrown while setting aarch64 registers.
#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extern crate serde_derive;

use std::fmt;
use std::result;
use vm_memory::bitmap::AtomicBitmap;

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

/// Type for returning error code.
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion arch/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod layout;
mod mpspec;
mod mptable;
pub mod regs;
use crate::GuestMemoryMmap;
use crate::InitramfsConfig;
use crate::RegionType;
use hypervisor::{CpuId, CpuIdEntry, CPUID_FLAG_VALID_INDEX};
Expand All @@ -22,7 +23,7 @@ use linux_loader::loader::elf::start_info::{
use std::mem;
use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
GuestMemoryMmap, GuestMemoryRegion, GuestUsize,
GuestMemoryRegion, GuestUsize,
};
mod smbios;
use std::arch::x86_64;
Expand Down
5 changes: 2 additions & 3 deletions arch/src/x86_64/mptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

use crate::layout::{APIC_START, HIGH_RAM_START, IOAPIC_START};
use crate::x86_64::mpspec;
use crate::GuestMemoryMmap;
use libc::c_char;
use std::io;
use std::mem;
use std::result;
use std::slice;
use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap,
};
use vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError};

// This is a workaround to the Rust enforcement specifying that any implementation of a foreign
// trait (in this case `ByteValued`) where:
Expand Down
6 changes: 4 additions & 2 deletions arch/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
use crate::layout::{BOOT_GDT_START, BOOT_IDT_START, PVH_INFO_START};
use crate::GuestMemoryMmap;
use hypervisor::arch::x86::gdt::{gdt_entry, segment_from_gdt};
use hypervisor::arch::x86::regs::*;
use hypervisor::x86_64::{FpuState, SpecialRegisters, StandardRegisters};
use std::sync::Arc;
use std::{mem, result};
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryMmap};
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError};

#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -163,7 +164,8 @@ pub fn configure_segments_and_sregs(
#[cfg(test)]
mod tests {
use super::*;
use vm_memory::{GuestAddress, GuestMemoryMmap};
use crate::GuestMemoryMmap;
use vm_memory::GuestAddress;

fn create_guest_mem() -> GuestMemoryMmap {
GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap()
Expand Down
3 changes: 2 additions & 1 deletion arch/src/x86_64/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use crate::layout::SMBIOS_START;
use crate::GuestMemoryMmap;
use std::fmt::{self, Display};
use std::mem;
use std::result;
use std::slice;
use vm_memory::ByteValued;
use vm_memory::{Address, Bytes, GuestAddress, GuestMemoryMmap};
use vm_memory::{Address, Bytes, GuestAddress};

#[allow(unused_variables)]
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion arch/src/x86_64/tdx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright © 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
use crate::GuestMemoryMmap;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use thiserror::Error;
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemoryError, GuestMemoryMmap};
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemoryError};

#[derive(Error, Debug)]
pub enum TdvfError {
Expand Down
2 changes: 1 addition & 1 deletion block_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thiserror = "1.0"
versionize = "0.1.6"
versionize_derive = "0.1.4"
virtio-bindings = { version = "0.1", features = ["virtio-v5_0_0"]}
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic"] }
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
vm-virtio = { path = "../vm-virtio" }
vmm-sys-util = ">=0.3.1"

6 changes: 5 additions & 1 deletion block_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ use std::sync::{Arc, Mutex};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::bindings::virtio_blk::*;
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap};
use vm_memory::{
bitmap::AtomicBitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError,
};
use vm_virtio::DescriptorChain;
use vmm_sys_util::eventfd::EventFd;

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

const SECTOR_SHIFT: u8 = 9;
pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT;

Expand Down
2 changes: 1 addition & 1 deletion net_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde = "1.0.126"
versionize = "0.1.6"
versionize_derive = "0.1.4"
virtio-bindings = "0.1.0"
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic"] }
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
vm-virtio = { path = "../vm-virtio" }
vmm-sys-util = ">=0.3.1"

Expand Down
3 changes: 2 additions & 1 deletion net_util/src/ctrl_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use crate::GuestMemoryMmap;
use crate::Tap;
use libc::c_uint;
use virtio_bindings::bindings::virtio_net::{
Expand All @@ -11,7 +12,7 @@ use virtio_bindings::bindings::virtio_net::{
VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_OK,
};
use vm_memory::{ByteValued, Bytes, GuestMemoryError, GuestMemoryMmap};
use vm_memory::{ByteValued, Bytes, GuestMemoryError};
use vm_virtio::Queue;

#[derive(Debug)]
Expand Down
4 changes: 3 additions & 1 deletion net_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use virtio_bindings::bindings::virtio_net::{
VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4,
VIRTIO_NET_F_GUEST_TSO6, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_MAC, VIRTIO_NET_F_MQ,
};
use vm_memory::ByteValued;
use vm_memory::{bitmap::AtomicBitmap, ByteValued};

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

pub use ctrl_queue::{CtrlQueue, Error as CtrlQueueError};
pub use mac::{MacAddr, MAC_ADDR_LEN};
Expand Down
3 changes: 2 additions & 1 deletion net_util/src/queue_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use super::{unregister_listener, vnet_hdr_len, Tap};
use crate::GuestMemoryMmap;
use rate_limiter::{RateLimiter, TokenType};
use std::io;
use std::num::Wrapping;
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use vm_memory::{Bytes, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestMemoryMmap};
use vm_memory::{Bytes, GuestAddressSpace, GuestMemory, GuestMemoryAtomic};
use vm_virtio::Queue;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion pci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
anyhow = "1.0"
byteorder = "1.4.3"
hypervisor = { path = "../hypervisor" }
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "master" }
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
vmm-sys-util = ">=0.3.1"
libc = "0.2.95"
log = "0.4.14"
Expand Down
2 changes: 1 addition & 1 deletion vhost_user_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ epoll = ">=4.0.1"
libc = "0.2.95"
log = "0.4.14"
virtio-bindings = "0.1.0"
vm-memory = "0.5.0"
vm-memory = { version = "0.5.0", features = ["backend-bitmap"] }
vm-virtio = { path = "../vm-virtio" }
vmm-sys-util = ">=0.3.1"
vhost = { git = "https://github.com/rust-vmm/vhost", branch = "master", package = "vhost", features = ["vhost-user-slave"] }
5 changes: 4 additions & 1 deletion vhost_user_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ use vhost::vhost_user::{
};
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use vm_memory::guest_memory::FileOffset;
use vm_memory::{GuestAddress, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
use vm_memory::{bitmap::AtomicBitmap, GuestAddress, MmapRegion};
use vm_virtio::Queue;
use vmm_sys_util::eventfd::EventFd;

pub type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
pub type GuestRegionMmap = vm_memory::GuestRegionMmap<AtomicBitmap>;

const MAX_MEM_SLOTS: u64 = 32;

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions vhost_user_block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use std::vec::Vec;
use std::{convert, error, fmt, io};
use vhost::vhost_user::message::*;
use vhost::vhost_user::Listener;
use vhost_user_backend::{VhostUserBackend, VhostUserDaemon, Vring};
use vhost_user_backend::{GuestMemoryMmap, VhostUserBackend, VhostUserDaemon, Vring};
use virtio_bindings::bindings::virtio_blk::*;
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use vm_memory::ByteValued;
use vm_memory::{Bytes, GuestMemoryMmap};
use vm_memory::Bytes;
use vmm_sys_util::eventfd::EventFd;

const SECTOR_SHIFT: u8 = 9;
Expand Down
4 changes: 2 additions & 2 deletions vhost_user_net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::sync::{Arc, Mutex, RwLock};
use std::vec::Vec;
use vhost::vhost_user::message::*;
use vhost::vhost_user::Listener;
use vhost_user_backend::{VhostUserBackend, VhostUserDaemon, Vring, VringWorker};
use vhost_user_backend::{GuestMemoryMmap, VhostUserBackend, VhostUserDaemon, Vring, VringWorker};
use virtio_bindings::bindings::virtio_net::*;
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
use vm_memory::GuestMemoryAtomic;
use vmm_sys_util::eventfd::EventFd;

pub type Result<T> = std::result::Result<T, Error>;
Expand Down
2 changes: 1 addition & 1 deletion virtio-devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ vhost = { git = "https://github.com/rust-vmm/vhost", branch = "master", package
virtio-bindings = { version = "0.1", features = ["virtio-v5_0_0"]}
vm-allocator = { path = "../vm-allocator" }
vm-device = { path = "../vm-device" }
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic"] }
vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
vm-migration = { path = "../vm-migration" }
vm-virtio = { path = "../vm-virtio" }
vmm-sys-util = ">=0.3.1"
3 changes: 2 additions & 1 deletion virtio-devices/src/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use super::{
VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1,
};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::GuestMemoryMmap;
use crate::{VirtioInterrupt, VirtioInterruptType};
use libc::EFD_NONBLOCK;
use seccomp::{SeccompAction, SeccompFilter};
Expand All @@ -31,7 +32,7 @@ use std::thread;
use vm_memory::GuestMemory;
use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryMmap,
GuestMemoryError,
};
use vm_migration::{Migratable, MigratableError, Pausable, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd;
Expand Down
3 changes: 2 additions & 1 deletion virtio-devices/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::{
EPOLL_HELPER_EVENT_LAST,
};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::GuestMemoryMmap;
use crate::VirtioInterrupt;
use block_util::{
async_io::AsyncIo, async_io::AsyncIoError, async_io::DiskFile, build_disk_image_id, Request,
Expand All @@ -34,7 +35,7 @@ use std::{collections::HashMap, convert::TryInto};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::bindings::virtio_blk::*;
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap};
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd;
Expand Down
3 changes: 2 additions & 1 deletion virtio-devices/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::GuestMemoryMmap;
use crate::VirtioInterrupt;
use libc::EFD_NONBLOCK;
use seccomp::{SeccompAction, SeccompFilter};
Expand All @@ -23,7 +24,7 @@ use std::sync::{Arc, Barrier, Mutex};
use std::thread;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap};
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd;
Expand Down
3 changes: 2 additions & 1 deletion virtio-devices/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use crate::{ActivateError, ActivateResult, Error, Queue};
use crate::{GuestMemoryMmap, GuestRegionMmap};
use libc::EFD_NONBLOCK;
use std::collections::HashMap;
use std::io::Write;
Expand All @@ -16,7 +17,7 @@ use std::sync::{
Arc, Barrier,
};
use std::thread;
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryMmap, GuestRegionMmap, GuestUsize};
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestUsize};
use vm_migration::{MigratableError, Pausable};
use vm_virtio::VirtioDeviceType;
use vmm_sys_util::eventfd::EventFd;
Expand Down
Loading

0 comments on commit b9de289

Please sign in to comment.