mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 23:11:16 +00:00
arch, vmm: Enable initramfs on AArch64
Ported Firecracker commit 144b6c. Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
parent
f449aec78e
commit
3e051e7b2c
@ -35,8 +35,8 @@ pub enum Error {
|
|||||||
/// Failed to create a GIC.
|
/// Failed to create a GIC.
|
||||||
SetupGIC(gic::Error),
|
SetupGIC(gic::Error),
|
||||||
|
|
||||||
/// Failed to compute the initrd address.
|
/// Failed to compute the initramfs address.
|
||||||
InitrdAddress,
|
InitramfsAddress,
|
||||||
|
|
||||||
/// Error configuring the general purpose registers
|
/// Error configuring the general purpose registers
|
||||||
REGSConfiguration(regs::Error),
|
REGSConfiguration(regs::Error),
|
||||||
@ -165,6 +165,26 @@ pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the memory address where the initramfs could be loaded.
|
||||||
|
pub fn initramfs_load_addr(
|
||||||
|
guest_mem: &GuestMemoryMmap,
|
||||||
|
initramfs_size: usize,
|
||||||
|
) -> super::Result<u64> {
|
||||||
|
let round_to_pagesize = |size| (size + (super::PAGE_SIZE - 1)) & !(super::PAGE_SIZE - 1);
|
||||||
|
match GuestAddress(get_fdt_addr(&guest_mem))
|
||||||
|
.checked_sub(round_to_pagesize(initramfs_size) as u64)
|
||||||
|
{
|
||||||
|
Some(offset) => {
|
||||||
|
if guest_mem.address_in_range(offset) {
|
||||||
|
Ok(offset.raw_value())
|
||||||
|
} else {
|
||||||
|
Err(super::Error::AArch64Setup(Error::InitramfsAddress))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => Err(super::Error::AArch64Setup(Error::InitramfsAddress)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the memory address where the kernel could be loaded.
|
/// Returns the memory address where the kernel could be loaded.
|
||||||
pub fn get_kernel_start() -> u64 {
|
pub fn get_kernel_start() -> u64 {
|
||||||
layout::RAM_64BIT_START
|
layout::RAM_64BIT_START
|
||||||
|
@ -88,8 +88,8 @@ pub mod aarch64;
|
|||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub use aarch64::{
|
pub use aarch64::{
|
||||||
arch_memory_regions, configure_system, configure_vcpu, fdt::DeviceInfoForFDT,
|
arch_memory_regions, configure_system, configure_vcpu, fdt::DeviceInfoForFDT,
|
||||||
get_host_cpu_phys_bits, get_kernel_start, layout, layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE,
|
get_host_cpu_phys_bits, get_kernel_start, initramfs_load_addr, layout,
|
||||||
layout::IRQ_MAX, EntryPoint,
|
layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX, EntryPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
@ -47,12 +47,10 @@ use linux_loader::loader::elf::PvhBootCapability::PvhEntryPresent;
|
|||||||
use linux_loader::loader::KernelLoader;
|
use linux_loader::loader::KernelLoader;
|
||||||
use signal_hook::{iterator::Signals, SIGINT, SIGTERM, SIGWINCH};
|
use signal_hook::{iterator::Signals, SIGINT, SIGTERM, SIGWINCH};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use std::io::{Seek, SeekFrom};
|
use std::io::{Seek, SeekFrom};
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@ -60,9 +58,7 @@ use std::path::PathBuf;
|
|||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
use std::{result, str, thread};
|
use std::{result, str, thread};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use vm_memory::{Address, GuestAddress, GuestAddressSpace};
|
use vm_memory::{Address, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryMmap};
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use vm_memory::{Bytes, GuestMemoryMmap};
|
|
||||||
use vm_migration::{
|
use vm_migration::{
|
||||||
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
||||||
Transportable,
|
Transportable,
|
||||||
@ -245,7 +241,6 @@ impl VmState {
|
|||||||
|
|
||||||
pub struct Vm {
|
pub struct Vm {
|
||||||
kernel: File,
|
kernel: File,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
|
||||||
initramfs: Option<File>,
|
initramfs: Option<File>,
|
||||||
threads: Vec<thread::JoinHandle<()>>,
|
threads: Vec<thread::JoinHandle<()>>,
|
||||||
device_manager: Arc<Mutex<DeviceManager>>,
|
device_manager: Arc<Mutex<DeviceManager>>,
|
||||||
@ -434,7 +429,6 @@ impl Vm {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fn load_initramfs(&mut self, guest_mem: &GuestMemoryMmap) -> Result<arch::InitramfsConfig> {
|
fn load_initramfs(&mut self, guest_mem: &GuestMemoryMmap) -> Result<arch::InitramfsConfig> {
|
||||||
let mut initramfs = self.initramfs.as_ref().unwrap();
|
let mut initramfs = self.initramfs.as_ref().unwrap();
|
||||||
let size: usize = initramfs
|
let size: usize = initramfs
|
||||||
@ -631,6 +625,10 @@ impl Vm {
|
|||||||
let vcpu_mpidrs = self.cpu_manager.lock().unwrap().get_mpidrs();
|
let vcpu_mpidrs = self.cpu_manager.lock().unwrap().get_mpidrs();
|
||||||
let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory();
|
let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory();
|
||||||
let mem = guest_memory.memory();
|
let mem = guest_memory.memory();
|
||||||
|
let initramfs_config = match self.initramfs {
|
||||||
|
Some(_) => Some(self.load_initramfs(mem.deref())?),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let device_info = &self
|
let device_info = &self
|
||||||
.device_manager
|
.device_manager
|
||||||
@ -671,7 +669,7 @@ impl Vm {
|
|||||||
self.cpu_manager.lock().unwrap().boot_vcpus() as u64,
|
self.cpu_manager.lock().unwrap().boot_vcpus() as u64,
|
||||||
vcpu_mpidrs,
|
vcpu_mpidrs,
|
||||||
device_info,
|
device_info,
|
||||||
&None,
|
&initramfs_config,
|
||||||
&pci_space,
|
&pci_space,
|
||||||
)
|
)
|
||||||
.map_err(Error::ConfigureSystem)?;
|
.map_err(Error::ConfigureSystem)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user