Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/vm-bootloader/src/boot_loader/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use vm_core::arch::layout::MemoryLayout;
use vm_core::device::mmio::mmio_device::MmioDevice;
use vm_core::virt::Virt;
use vm_fdt::FdtWriter;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;

use crate::boot_loader::BootLoader;
use crate::boot_loader::BootLoaderBuilder;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl AArch64BootLoader {
}

memory
.copy_from_slice(dtb_start, &dtb, dtb.len())
.copy_from_slice(dtb_start, &dtb)
.map_err(|_| Error::LoadDtbFailed("failed to copy".to_string()))?;

layout.set_dtb_len(dtb.len())?;
Expand Down
4 changes: 2 additions & 2 deletions crates/vm-bootloader/src/initrd_loader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fs;
use std::path::Path;

use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -35,7 +35,7 @@ impl InitrdLoader {
C: MemoryContainer,
{
memory
.copy_from_slice(addr, &self.initrd, self.initrd.len())
.copy_from_slice(addr, &self.initrd)
.map_err(|_| Error::CopyFailed)?;

Ok(LoadResult {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-bootloader/src/kernel_loader/linux/bzimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fs;
use std::path::Path;

use header::*;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;

use crate::kernel_loader::Error;
use crate::kernel_loader::KernelLoader;
Expand Down
4 changes: 2 additions & 2 deletions crates/vm-bootloader/src/kernel_loader/linux/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::fs;
use std::path::Path;

use tracing::debug;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;
use zerocopy::FromBytes;

use crate::kernel_loader::Error;
Expand Down Expand Up @@ -128,7 +128,7 @@ where
}

memory
.copy_from_slice(kernel_start, &self.kernel, self.kernel.len())
.copy_from_slice(kernel_start, &self.kernel)
.map_err(|err| Error::CopyKernelFailed(err.to_string()))?;

Ok(LoadResult {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-core/src/virt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;

use crate::arch::Arch;
use crate::arch::irq::InterruptController;
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-core/src/virt/hvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl Virt for Hvp {
let mut memory = allocator.alloc(memory_size, None)?;
memory.0.map(ram_base, MemPerms::ReadWriteExec)?;
memory_address_space
.try_insert(MemoryRegion::new(ram_base, memory_size, memory))
.try_insert(MemoryRegion::new(ram_base, memory))
.map_err(|_| Error::FailedInitialize("Failed to initialize memory".to_string()))?;

self.get_layout_mut().set_ram_size(memory_size as u64)?;
Expand Down
8 changes: 6 additions & 2 deletions crates/vm-core/src/virt/hvp/mm.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use applevisor::memory::Memory;
use applevisor::vm::VirtualMachineInstance;
use vm_mm::allocator::Allocator;
use vm_mm::allocator::MemoryContainer;
use vm_mm::error::Error;
use vm_mm::memory_container::MemoryContainer;

pub struct MemoryWrapper(pub Memory);

unsafe impl Send for MemoryWrapper {}
unsafe impl Sync for MemoryWrapper {}

impl MemoryContainer for MemoryWrapper {
fn to_hva(&self) -> *mut u8 {
fn hva(&self) -> *mut u8 {
self.0.host_addr()
}

fn length(&self) -> usize {
self.0.size()
}
}

pub struct HvpAllocator<'a, Gic> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::sync::Mutex;

use tokio::sync::Notify;
use vm_core::arch::irq::InterruptController;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;
use vm_virtio::device::VirtioDevice;
use vm_virtio::device::transport::TransportContext;
use vm_virtio::device::virtqueue::VirtqueueHandler;
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-device/src/device/virtio/virtio_blk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Mutex;

use tokio::sync::Notify;
use vm_core::arch::irq::InterruptController;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;
use vm_pci::device::interrupt::legacy::InterruptPin;
use vm_virtio::device::VirtioDevice;
use vm_virtio::device::transport::TransportContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-device/src/device/virtio/virtio_mmio_kbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use vm_core::device::Device;
use vm_core::device::mmio::MmioDevice;
use vm_core::device::mmio::MmioRange;
use vm_core::arch::irq::InterruptController;
use vm_mm::allocator::MemoryContainer;
use vm_mm::memory_container::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_virtio::transport::Virtio;
use vm_virtio::transport::mmio::VirtioMmio;
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-machine/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use vm_device::device::virtio::virtio_balloon_traditional::VirtioBalloonTranditi
use vm_device::device::virtio::virtio_balloon_traditional::VirtioMmioBalloonDevice;
use vm_device::device::virtio::virtio_blk::VirtioBlkDevice;
use vm_device::device::virtio::virtio_blk::VirtioMmioBlkDevice;
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;
use vm_pci::root_complex::mmio::PciRootComplexMmio;
use vm_virtio::transport::VirtioDev;
use vm_virtio::transport::pci::VirtioPciDevice;
Expand Down
2 changes: 1 addition & 1 deletion crates/vm-machine/src/firmware/bios.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vm_mm::allocator::MemoryContainer;
use vm_mm::manager::MemoryAddressSpace;
use vm_mm::memory_container::MemoryContainer;

use crate::firmware::bios::e820::*;
use crate::firmware::bios::ivt::InterruptVectorTable;
Expand Down
5 changes: 1 addition & 4 deletions crates/vm-mm/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::error::Error;
use crate::memory_container::MemoryContainer;

pub mod mmap_allocator;

pub trait MemoryContainer: Send + Sync + 'static {
fn to_hva(&self) -> *mut u8;
}

pub trait Allocator {
type Container: MemoryContainer;

Expand Down
19 changes: 8 additions & 11 deletions crates/vm-mm/src/allocator/mmap_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use memmap2::MmapMut;

use crate::allocator::Allocator;
use crate::error::Error;
use crate::memory_container::MemoryContainer;

mod container {
use memmap2::MmapMut;

use crate::allocator::MemoryContainer;
impl MemoryContainer for MmapMut {
fn hva(&self) -> *mut u8 {
self.as_ptr() as *mut u8
}

impl MemoryContainer for MmapMut {
fn to_hva(&self) -> *mut u8 {
self.as_ptr() as *mut u8
}
fn length(&self) -> usize {
self.len()
}
}

Expand All @@ -25,8 +24,6 @@ impl Allocator for MmapAllocator {
unimplemented!()
}

let mmap = MmapMut::map_anon(len).map_err(|_| Error::AllocAnonymousMemoryFailed { len })?;

Ok(mmap)
MmapMut::map_anon(len).map_err(|_| Error::AllocAnonymousMemoryFailed { len })
}
}
6 changes: 0 additions & 6 deletions crates/vm-mm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ pub enum Error {
#[error("failed to allocate anonymous memory, len: {len}")]
AllocAnonymousMemoryFailed { len: usize },

#[error("try to access an uninitialized memory")]
MemoryIsNotAllocated,

#[error("memory already allocated, cannot allocate again")]
MemoryAlreadyAllocated,

#[error("try to access invalid gpa: {0}")]
AccessInvalidGpa(u64),

Expand Down
3 changes: 3 additions & 0 deletions crates/vm-mm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![deny(warnings)]

pub mod allocator;
pub mod error;
pub mod manager;
pub mod memory_container;
pub mod region;
Loading
Loading