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

Update for linux kernel module #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 hypervisor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ log = { default-features = false, version = "0.4" }
pcuart = { path= "../pcuart"}
hypervisor_abi = { path= "../hypervisor_abi"}
dmesg_logger = { path = "../dmesg_logger" }
#x86 = "0.39.0"
x86 = { git = "https://github.com/iankronquist/rust-x86" }
x86 = "0.46.0"
#x86 = { git = "https://github.com/iankronquist/rust-x86" }


[features]
Expand Down
2 changes: 2 additions & 0 deletions hypervisor/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! This module defines functions useful for debugging the hypervisor.

use core::arch::asm;

/// A breakpoint function for debuggers to hook.
///
/// This does NOT generate an int 3 breakpoint instruction.
Expand Down
14 changes: 8 additions & 6 deletions hypervisor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(asm)]
#![feature(lang_items)]
#![allow(unknown_lints)]
#![warn(missing_docs)]
Expand Down Expand Up @@ -45,7 +44,7 @@ mod vmexit_handlers;
mod vmexit_reasons;
mod vmx;

#[cfg(target_os = "uefi")]
//#[cfg(target_os = "uefi")]
use pcuart::logger;

#[cfg(target_os = "uefi")]
Expand All @@ -56,14 +55,17 @@ pub static LOGGER: logger::UartLogger = logger::UartLogger::new(pcuart::UartComP
pub static UNSYNCHRONIZED_LOGGER: logger::UnsynchronizedUartLogger =
logger::UnsynchronizedUartLogger::new(pcuart::UartComPort::Com1);

#[cfg(not(target_os = "uefi"))]
use dmesg_logger as logger;
//#[cfg(not(target_os = "uefi"))]
//use dmesg_logger as logger;
#[cfg(not(target_os = "uefi"))]
/// Logger used by the hypervisor when loading the guest and while running.
pub static LOGGER: logger::DMesgLogger = logger::DMesgLogger {};
//pub static LOGGER: logger::DMesgLogger = logger::DMesgLogger {};
pub static LOGGER: logger::UartLogger = logger::UartLogger::new(pcuart::UartComPort::Com1);
#[cfg(not(target_os = "uefi"))]
/// Logger used by the hypervisor when panicking.
pub static UNSYNCHRONIZED_LOGGER: logger::DMesgLogger = logger::DMesgLogger {};
pub static UNSYNCHRONIZED_LOGGER: logger::UnsynchronizedUartLogger =
logger::UnsynchronizedUartLogger::new(pcuart::UartComPort::Com1);
//pub static UNSYNCHRONIZED_LOGGER: logger::DMesgLogger = logger::DMesgLogger {};

/// This structure represents all of the data the hypervisor needs for a single CPU.
/// The environment loader, e.g. UEFI bindings or linux kernel bindings, needs
Expand Down
2 changes: 2 additions & 0 deletions hypervisor/src/msr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//! MSRs may be unique per core, unique per NUMA node, or global for the whole
//! machine.

use core::arch::asm;

/// The values of various Model Specific Registers.
#[allow(dead_code)]
#[derive(Debug, Copy, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions hypervisor/src/panic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This module handles hypervisor panics.
#![cfg(not(test))]

use core::arch::asm;

use core::sync::atomic;

use core::panic::PanicInfo;
Expand Down
8 changes: 4 additions & 4 deletions hypervisor/src/vmcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::msr::{rdmsr, rdmsrl, Msr};
use crate::segmentation::{get_current_gdt, unpack_gdt_entry};
use crate::vmcs_fields::*;
use crate::vmx::{read_dr7, vmread, vmwrite};
use crate::vmx::{vmread, vmwrite};
use crate::VCpu;
use core::convert::TryFrom;
use log::{trace, warn};
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn initialize_guest_state(_vcpu: &VCpu) -> Result<(), x86::vmx::VmFail> {
)?;
vmwrite(VmcsField::GuestSsBase, ss_unpacked.base)?;

let tr = x86::task::tr();
let tr = unsafe { x86::task::tr() };
let tr_unpacked = unpack_gdt_entry(gdt, tr.bits());
vmwrite(VmcsField::GuestTrSelector, u64::from(tr_unpacked.selector))?;
vmwrite(VmcsField::GuestTrLimit, tr_unpacked.limit)?;
Expand Down Expand Up @@ -179,8 +179,8 @@ pub fn initialize_guest_state(_vcpu: &VCpu) -> Result<(), x86::vmx::VmFail> {
vmwrite(VmcsField::GuestCr0, cr0.bits() as u64)?;
//vmwrite(VmcsField::GuestCr0ReadShadow, cr0)?;
vmwrite(VmcsField::GuestIA32Debugctl, rdmsrl(Msr::Ia32DebugControl))?;
let dr7 = read_dr7();
vmwrite(VmcsField::GuestDr7, dr7)?;
let dr7 = unsafe { x86::debugregs::dr7() };
vmwrite(VmcsField::GuestDr7, dr7.0 as u64)?;

Ok(())
}
Expand Down
9 changes: 0 additions & 9 deletions hypervisor/src/vmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ pub fn vmwrite(field: VmcsField, val: u64) -> Result<(), x86::vmx::VmFail> {
unsafe { x86::bits64::vmx::vmwrite(field as u32, val) }
}

/// Read the contents of the current machine's dr7 (debug register 7).
pub fn read_dr7() -> u64 {
let ret: u64;
unsafe {
asm!("mov {}, dr7", out(reg)(ret));
}
ret
}

/// Returns true if the Intel vmx extensions are available and a hypervisor is not present, false otherwise.
fn vmx_available() -> bool {
let result = unsafe { core::arch::x86_64::__cpuid(CPUIDLeaf::ProcessorInfoAndFeatures as u32) };
Expand Down
3 changes: 2 additions & 1 deletion pcuart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ edition = "2018"
spin = { version = "0.9" }
log = { default-features = false, version = "0.4" }
#x86 = "0.39.0"
x86 = { git = "https://github.com/iankronquist/rust-x86" }
#x86 = { git = "https://github.com/iankronquist/rust-x86" }
x86 = "0.46.0"

1 change: 0 additions & 1 deletion pcuart/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(asm)]
#![warn(missing_docs)]

//! A logging crate for writing logs to a PC's COM port.
Expand Down
5 changes: 3 additions & 2 deletions rustyvctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ edition = "2018"
[dependencies]
hypervisor_abi = { path = "../hypervisor_abi" }
uefi = "0.11.0"
x86 = { git = "https://github.com/iankronquist/rust-x86" }
log = { default-features = false, version = "0.4" }
#x86 = { git = "https://github.com/iankronquist/rust-x86" }
x86 = "0.46.0"
log = { default-features = false, version = "0.4" }
5 changes: 4 additions & 1 deletion uefi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
}
objs.push(obj);
println!("here {:x?}", objs);

println!("cargo:rerun-if-changed={}", filename);
//println!("cargo:rerun-if-changed={}", filename);
}

let mut args = vec![format!("-out:{}", full_lib)];
args.append(&mut objs);
println!("{:x?}", full_lib);
println!("{:x?}", args);
Command::new("llvm-lib")
.args(args)
.current_dir(&Path::new(&out_dir))
Expand Down