Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to hermit-entry #335

Merged
merged 1 commit into from
Jun 20, 2022
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
7 changes: 7 additions & 0 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 @@ -51,6 +51,7 @@ envmnt = "0.10"
gdbstub = "0.6"
gdbstub_arch = "0.2"
goblin = { version = "0.5", default-features = false, features = ["elf64", "elf32", "endian_fd", "std"] }
hermit-entry = { version = "0.1", features = ["loader"] }
lazy_static = "1.4"
libc = "0.2"
log = "0.4"
Expand Down
101 changes: 0 additions & 101 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::consts::UHYVE_UART_PORT;
use bitflags::bitflags;
use core::fmt;
use goblin::elf64::header::EM_AARCH64;

pub const RAM_START: u64 = 0x00;
Expand Down Expand Up @@ -49,105 +47,6 @@ pub const fn tcr_size(x: u64) -> u64 {
((64 - x) << 16) | (64 - x)
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct BootInfo {
pub magic_number: u32,
pub version: u32,
pub base: u64,
pub ram_start: u64,
pub limit: u64,
pub image_size: u64,
pub tls_start: u64,
pub tls_filesz: u64,
pub tls_memsz: u64,
pub tls_align: u64,
pub current_stack_address: u64,
pub current_percore_address: u64,
pub host_logical_addr: u64,
pub boot_gtod: u64,
pub cmdline: u64,
pub cmdsize: u64,
pub cpu_freq: u32,
pub boot_processor: u32,
pub cpu_online: u32,
pub possible_cpus: u32,
pub current_boot_id: u32,
pub uartport: u32,
pub single_kernel: u8,
pub uhyve: u8,
pub hcip: [u8; 4],
pub hcgateway: [u8; 4],
pub hcmask: [u8; 4],
}

impl BootInfo {
pub const fn new() -> Self {
BootInfo {
magic_number: 0xC0DE_CAFEu32,
version: 1,
base: 0,
ram_start: RAM_START,
limit: 0,
tls_start: 0,
tls_filesz: 0,
tls_memsz: 0,
tls_align: 0,
image_size: 0,
current_stack_address: 0,
current_percore_address: 0,
host_logical_addr: 0,
boot_gtod: 0,
cmdline: 0,
cmdsize: 0,
cpu_freq: 0,
boot_processor: !0,
cpu_online: 0,
possible_cpus: 0,
current_boot_id: 0,
uartport: UHYVE_UART_PORT as u32,
single_kernel: 1,
uhyve: 0,
hcip: [255, 255, 255, 255],
hcgateway: [255, 255, 255, 255],
hcmask: [255, 255, 255, 0],
}
}
}

impl fmt::Debug for BootInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "magic_number {:#x}", self.magic_number)?;
writeln!(f, "version {:#x}", self.version)?;
writeln!(f, "base {:#x}", self.base)?;
writeln!(f, "ram address {:#x}", self.ram_start)?;
writeln!(f, "limit {:#x}", self.limit)?;
writeln!(f, "tls_start {:#x}", self.tls_start)?;
writeln!(f, "tls_filesz {:#x}", self.tls_filesz)?;
writeln!(f, "tls_memsz {:#x}", self.tls_memsz)?;
writeln!(f, "tls_align {:#x}", self.tls_align)?;
writeln!(f, "image_size {:#x}", self.image_size)?;
writeln!(f, "current_stack_address {:#x}", self.current_stack_address)?;
writeln!(
f,
"current_percore_address {:#x}",
self.current_percore_address
)?;
writeln!(f, "host_logical_addr {:#x}", self.host_logical_addr)?;
writeln!(f, "boot_gtod {:#x}", self.boot_gtod)?;
writeln!(f, "cmdline {:#x}", self.cmdline)?;
writeln!(f, "cmdsize {:#x}", self.cmdsize)?;
writeln!(f, "cpu_freq {}", self.cpu_freq)?;
writeln!(f, "boot_processor {}", self.boot_processor)?;
writeln!(f, "cpu_online {}", self.cpu_online)?;
writeln!(f, "possible_cpus {}", self.possible_cpus)?;
writeln!(f, "current_boot_id {}", self.current_boot_id)?;
writeln!(f, "uartport {:#x}", self.uartport)?;
writeln!(f, "single_kernel {}", self.single_kernel)?;
writeln!(f, "uhyve {}", self.uhyve)
}
}

bitflags! {
pub struct PSR: u64 {
const MODE_EL1H = 0x00000005;
Expand Down
72 changes: 0 additions & 72 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,6 @@ pub const ELF_HOST_ARCH: u16 = EM_X86_64;
const MHZ_TO_HZ: u64 = 1000000;
const KHZ_TO_HZ: u64 = 1000;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct BootInfo {
pub magic_number: u32,
pub version: u32,
pub base: u64,
pub limit: u64,
pub image_size: u64,
pub tls_start: u64,
pub tls_filesz: u64,
pub tls_memsz: u64,
pub current_stack_address: u64,
pub current_percore_address: u64,
pub host_logical_addr: u64,
pub boot_gtod: u64,
pub mb_info: u64,
pub cmdline: u64,
pub cmdsize: u64,
pub cpu_freq: u32,
pub boot_processor: u32,
pub cpu_online: u32,
pub possible_cpus: u32,
pub current_boot_id: u32,
pub uartport: u16,
pub single_kernel: u8,
pub uhyve: u8,
pub hcip: [u8; 4],
pub hcgateway: [u8; 4],
pub hcmask: [u8; 4],
pub tls_align: u64,
}

impl BootInfo {
pub fn new() -> Self {
BootInfo {
magic_number: 0xC0DE_CAFEu32,
version: 1,
base: 0,
limit: 0,
tls_start: 0,
tls_filesz: 0,
tls_memsz: 0,
image_size: 0,
current_stack_address: 0,
current_percore_address: 0,
host_logical_addr: 0,
boot_gtod: 0,
mb_info: 0,
cmdline: 0,
cmdsize: 0,
cpu_freq: 0,
boot_processor: !0,
cpu_online: 0,
possible_cpus: 0,
current_boot_id: 0,
uartport: 0,
single_kernel: 1,
uhyve: 0,
hcip: [255, 255, 255, 255],
hcgateway: [255, 255, 255, 255],
hcmask: [255, 255, 255, 0],
tls_align: 0,
}
}
}

impl Default for BootInfo {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug)]
pub struct FrequencyDetectionFailed;

Expand Down
15 changes: 7 additions & 8 deletions src/linux/uhyve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This file contains the entry point to the Hypervisor. The Uhyve utilizes KVM to
//! create a Virtual Machine and load the kernel.

use crate::arch::x86_64::BootInfo;
use crate::consts::*;
use crate::linux::vcpu::*;
use crate::linux::virtio::*;
Expand All @@ -11,6 +10,7 @@ use crate::shared_queue::*;
use crate::vm::HypervisorResult;
use crate::vm::Vm;
use crate::x86_64::create_gdt_entry;
use hermit_entry::RawBootInfo;
use kvm_bindings::*;
use kvm_ioctls::VmFd;
use log::debug;
Expand Down Expand Up @@ -135,7 +135,7 @@ pub struct Uhyve {
num_cpus: u32,
path: PathBuf,
args: Vec<OsString>,
boot_info: *const BootInfo,
boot_info: *const RawBootInfo,
verbose: bool,
ip: Option<Ipv4Addr>,
gateway: Option<Ipv4Addr>,
Expand Down Expand Up @@ -354,16 +354,15 @@ impl Vm for Uhyve {
))
}

fn set_boot_info(&mut self, header: *const BootInfo) {
fn set_boot_info(&mut self, header: *const RawBootInfo) {
self.boot_info = header;
}

fn cpu_online(&self) -> u32 {
if self.boot_info.is_null() {
0
} else {
unsafe { read_volatile(&(*self.boot_info).cpu_online) }
}
let boot_info = unsafe { self.boot_info.as_ref() };
boot_info
.map(RawBootInfo::load_cpu_online)
.unwrap_or_default()
}

/// Initialize the page tables for the guest
Expand Down
17 changes: 8 additions & 9 deletions src/macos/aarch64/uhyve.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::aarch64::{BootInfo, PT_MEM, PT_MEM_CD, PT_PT, PT_SELF};
use crate::aarch64::{PT_MEM, PT_MEM_CD, PT_PT, PT_SELF};
use crate::consts::{BOOT_INFO_ADDR, BOOT_PGT, PAGE_SIZE};
use crate::macos::aarch64::vcpu::*;
use crate::macos::aarch64::HYPERVISOR_PAGE_SIZE;
use crate::params::Params;
use crate::vm::HypervisorResult;
use crate::vm::Vm;
use hermit_entry::RawBootInfo;
use libc;
use libc::c_void;
use log::debug;
Expand All @@ -13,7 +14,6 @@ use std::net::Ipv4Addr;
use std::path::Path;
use std::path::PathBuf;
use std::ptr;
use std::ptr::read_volatile;
use xhypervisor::{create_vm, map_mem, unmap_mem, MemPerm};

pub struct Uhyve {
Expand All @@ -24,7 +24,7 @@ pub struct Uhyve {
num_cpus: u32,
path: PathBuf,
args: Vec<OsString>,
boot_info: *const BootInfo,
boot_info: *const RawBootInfo,
verbose: bool,
}

Expand Down Expand Up @@ -156,16 +156,15 @@ impl Vm for Uhyve {
None
}

fn set_boot_info(&mut self, header: *const BootInfo) {
fn set_boot_info(&mut self, header: *const RawBootInfo) {
self.boot_info = header;
}

fn cpu_online(&self) -> u32 {
if self.boot_info.is_null() {
0
} else {
unsafe { read_volatile(&(*self.boot_info).cpu_online) }
}
let boot_info = unsafe { self.boot_info.as_ref() };
boot_info
.map(RawBootInfo::load_cpu_online)
.unwrap_or_default()
}

fn init_guest_mem(&self) {
Expand Down
16 changes: 7 additions & 9 deletions src/macos/x86_64/uhyve.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::arch::x86_64::BootInfo;
use crate::consts::*;
use crate::macos::x86_64::ioapic::IoApic;
use crate::macos::x86_64::vcpu::*;
use crate::params::Params;
use crate::vm::HypervisorResult;
use crate::vm::Vm;
use crate::x86_64::create_gdt_entry;
use hermit_entry::RawBootInfo;
use libc;
use libc::c_void;
use log::debug;
Expand All @@ -15,7 +15,6 @@ use std::net::Ipv4Addr;
use std::path::Path;
use std::path::PathBuf;
use std::ptr;
use std::ptr::read_volatile;
use std::sync::{Arc, Mutex};
use x86_64::structures::paging::{Page, PageTable, PageTableFlags, Size2MiB};
use x86_64::PhysAddr;
Expand All @@ -29,7 +28,7 @@ pub struct Uhyve {
num_cpus: u32,
path: PathBuf,
args: Vec<OsString>,
boot_info: *const BootInfo,
boot_info: *const RawBootInfo,
ioapic: Arc<Mutex<IoApic>>,
verbose: bool,
}
Expand Down Expand Up @@ -154,16 +153,15 @@ impl Vm for Uhyve {
None
}

fn set_boot_info(&mut self, header: *const BootInfo) {
fn set_boot_info(&mut self, header: *const RawBootInfo) {
self.boot_info = header;
}

fn cpu_online(&self) -> u32 {
if self.boot_info.is_null() {
0
} else {
unsafe { read_volatile(&(*self.boot_info).cpu_online) }
}
let boot_info = unsafe { self.boot_info.as_ref() };
boot_info
.map(RawBootInfo::load_cpu_online)
.unwrap_or_default()
}

/// Initialize the page tables for the guest
Expand Down
Loading