Skip to content
Closed
Changes from 1 commit
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
37 changes: 29 additions & 8 deletions src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ extern crate linux_loader;
extern crate vm_memory;
extern crate vm_superio;

use std::fs::File;
use std::io::stdout;
use std::os::unix::io::AsRawFd;
use std::os::unix::prelude::RawFd;
use std::sync::{Arc, Mutex};
use std::thread;
use std::{io, path::PathBuf};
use std::fs::File;

use kvm_bindings::{kvm_userspace_memory_region, KVM_MAX_CPUID_ENTRIES};
use kvm_ioctls::{Kvm, VmFd};
Expand All @@ -30,6 +30,13 @@ mod epoll_context;
use epoll_context::{EpollContext, EPOLL_EVENTS_LEN};
mod kernel;

/// End the mmio gap at the last 32-bit address
const MMIO_GAP_END: usize = 1 << 32;
/// Size of the MMIO gap
const MMIO_GAP_SIZE: usize = 32 << 20;
/// Start of the MMIO gap
const MMIO_GAP_START: usize = MMIO_GAP_END - MMIO_GAP_SIZE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, placing the MMIO gap under 32 bits is meant for supporting 32-bit architecture. The PCI memory hole (Which MMIO is taking advantage of) is a legacy burden that's carried over to support MMIO based devices on 32-bit CPUs.

It does not matter where you place it, and at the end of the 32-bit address space is fine. But you should know that this could be placed e.g. way further in the 64-bit address space, and leave RAM unfragmented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to support 32bit OSes ? Then we could instead use something like an allocator to place the MMIO devices after the guest's memory ?


#[derive(Debug)]

/// VMM errors.
Expand Down Expand Up @@ -112,8 +119,19 @@ impl VMM {
// Convert memory size from MBytes to bytes.
let mem_size = ((mem_size_mb as u64) << 20) as usize;

// Create one single memory region, from zero to mem_size.
let mem_regions = vec![(GuestAddress(0), mem_size)];
// Check if the memory is overlapping with the MMIO gap.
// If it is, split the memory into two regions.

let mem_regions = if mem_size < MMIO_GAP_START {
vec![(GuestAddress(0), mem_size)]
} else {
vec![
(GuestAddress(0), MMIO_GAP_START),
(GuestAddress(MMIO_GAP_END as u64), mem_size - MMIO_GAP_END),
]
};

let mem_regions = vec![(GuestAddress(0), MMIO_GAP_START)];

// Allocate the guest memory from the memory region.
let guest_memory = GuestMemoryMmap::from_ranges(&mem_regions).map_err(Error::Memory)?;
Expand Down Expand Up @@ -164,10 +182,7 @@ impl VMM {
Ok(())
}

pub fn configure_console(
&mut self,
console_path: Option<String>
) -> Result<()> {
pub fn configure_console(&mut self, console_path: Option<String>) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unneeded reformatting.

if let Some(console_path) = console_path {
// We create the file if it does not exist, else we open
let file = File::create(&console_path).map_err(Error::ConsoleError)?;
Expand Down Expand Up @@ -266,7 +281,13 @@ impl VMM {
}
}

pub fn configure(&mut self, num_vcpus: u8, mem_size_mb: u32, kernel_path: &str, console: Option<String>) -> Result<()> {
pub fn configure(
&mut self,
num_vcpus: u8,
mem_size_mb: u32,
kernel_path: &str,
console: Option<String>,
) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

self.configure_console(console)?;
self.configure_memory(mem_size_mb)?;
let kernel_load = kernel::kernel_setup(&self.guest_memory, PathBuf::from(kernel_path))?;
Expand Down