Skip to content

Commit

Permalink
Fix bug with 64-bit guests (incorrect bit flag being set
Browse files Browse the repository at this point in the history
  • Loading branch information
gamozolabs committed Jun 24, 2020
1 parent fed5528 commit 54d971c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion kernel/src/test_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::fuzz_session::{Worker, FuzzSession};
use lockcell::LockCell;

pub fn fuzz() {
//if core!().id != 0 { cpu::halt(); }
if core!().id != 0 { cpu::halt(); }
//if core!().id >= 24 { cpu::halt(); }

static SESSION:
Expand Down
41 changes: 21 additions & 20 deletions kernel/src/vtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,25 +1628,6 @@ impl Vm {
}
}

// Set the 64-bit guest entry control flag based on the EFER
let lma = (self.reg(Register::Efer) & (1 << 10)) != 0;
self.mod_reg(Register::EntryControls, |x| {
if lma {
// Set that we have a 64-bit guest
x | (1 << 15)
} else {
// Clear that the guest is 64-bit
x & !(1 << 15)
}
});

// Set unrestricted guest mode if we have a guest without paging
// enabled
if (self.reg(Register::Cr0) & (1 << 31)) == 0 {
// Set unrestricted guest
self.mod_reg(Register::ProcBasedControls2, |x| x | (1 << 7));
}

// Do one-time initialization
if !self.init {
unsafe {
Expand Down Expand Up @@ -1713,7 +1694,27 @@ impl Vm {
// We have initialized the VM
self.init = true;
}


// Set the 64-bit guest entry control flag based on the EFER
let lma = (self.reg(Register::Efer) & (1 << 10)) != 0;
self.mod_reg(Register::EntryControls, |x| {
if lma {
// Set that we have a 64-bit guest
x | (1 << 9)
} else {
// Clear that the guest is 64-bit
x & !(1 << 9)
}
});

// Set unrestricted guest mode if we have a guest without paging
// enabled
if (self.reg(Register::Cr0) & (1 << 31)) == 0 {
// Set unrestricted guest
self.mod_reg(Register::ProcBasedControls2, |x| x | (1 << 7));
}

// Invalidate the EPT if it has been dirtied
if self.ept_dirty {
unsafe {
// Invalidate the EPT
Expand Down

0 comments on commit 54d971c

Please sign in to comment.