Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

fix: critical process died error. #1

Merged
merged 1 commit into from
Jan 12, 2024
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
3 changes: 2 additions & 1 deletion hypervisor/src/intel/vmcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! is vital for VMX operations on the CPU. It also offers utility functions for
//! adjusting VMCS entries and displaying VMCS state for debugging purposes.

use x86_64::registers::control::Cr4;
use {
// Internal crate usages
crate::{
Expand Down Expand Up @@ -109,7 +110,7 @@ impl Vmcs {
pub fn setup_guest_registers_state(context: &CONTEXT, guest_descriptor_table: &Box<DescriptorTables, KernelAlloc>, guest_registers: &mut GuestRegisters) {
unsafe { vmwrite(vmcs::guest::CR0, controlregs::cr0().bits() as u64) };
unsafe { vmwrite(vmcs::guest::CR3, controlregs::cr3()) };
unsafe { vmwrite(vmcs::guest::CR4, controlregs::cr4().bits() as u64) };
unsafe { vmwrite(vmcs::guest::CR4, Cr4::read_raw()) };

vmwrite(vmcs::guest::DR7, context.Dr7);

Expand Down
16 changes: 9 additions & 7 deletions hypervisor/src/intel/vmxon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! enable VMX operations. It also offers utility functions for adjusting control
//! registers to facilitate VMX operations.

use x86_64::registers::control::Cr4;
use {
crate::{
error::HypervisorError,
Expand Down Expand Up @@ -68,9 +69,10 @@ impl Vmxon {

/// Enables VMX operation by setting appropriate bits and executing the VMXON instruction.
fn enable_vmx_operation() -> Result<(), HypervisorError> {
let mut cr4 = unsafe { x86::controlregs::cr4() };
cr4.set(x86::controlregs::Cr4::CR4_ENABLE_VMX, true);
unsafe { x86::controlregs::cr4_write(cr4) };
const CR4_VMX_ENABLE_BIT: usize = 13;
let mut cr4 = Cr4::read_raw();
cr4.set_bit(CR4_VMX_ENABLE_BIT, true);
unsafe { Cr4::write_raw(cr4) };

/* Intel® 64 and IA-32 Architectures Software Developer's Manual: 24.7 ENABLING AND ENTERING VMX OPERATION */
log::info!("Setting Lock Bit set via IA32_FEATURE_CONTROL");
Expand Down Expand Up @@ -128,11 +130,11 @@ impl Vmxon {
let ia32_vmx_cr4_fixed0 = unsafe { x86::msr::rdmsr(x86::msr::IA32_VMX_CR4_FIXED0) };
let ia32_vmx_cr4_fixed1 = unsafe { x86::msr::rdmsr(x86::msr::IA32_VMX_CR4_FIXED1) };

let mut cr4 = unsafe { x86::controlregs::cr4() };
let mut cr4 = Cr4::read_raw();

cr4 |= x86::controlregs::Cr4::from_bits_truncate(ia32_vmx_cr4_fixed0 as usize);
cr4 &= x86::controlregs::Cr4::from_bits_truncate(ia32_vmx_cr4_fixed1 as usize);
cr4 |= ia32_vmx_cr4_fixed0;
cr4 &= ia32_vmx_cr4_fixed1;

unsafe { x86::controlregs::cr4_write(cr4) };
unsafe { Cr4::write_raw(cr4) };
}
}