Skip to content

Commit

Permalink
Cpuid vm exit support
Browse files Browse the repository at this point in the history
  • Loading branch information
pacbypass committed Aug 26, 2020
1 parent 54d971c commit 127a9ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions kernel/src/fuzz_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,24 @@ impl<'a> Worker<'a> {
self.stats.vm_cycles += vm_cycles;

match vmexit {
VmExit::CpuId { inst_len } => {
let rax = self.reg(Register::Rax) as u32;
let rcx = self.reg(Register::Rcx) as u32;

// Take the host cpuid and write it into the guest
unsafe{
let (eax, ebx, ecx, edx) = cpu::cpuid(rax,rcx);
self.set_reg(Register::Eax, eax as u64);
self.set_reg(Register::Ebx, ebx as u64);
self.set_reg(Register::Ecx, ecx as u64);
self.set_reg(Register::Edx, edx as u64);
}

// Advance RIP to next instruction
let rip = self.reg(Register::Rip);
self.set_reg(Register::Rip, rip.wrapping_add(inst_len));
continue 'vm_loop;
}
VmExit::Rdtsc { inst_len } => {
let tsc = self.backing.vm.guest_regs.tsc;
self.set_reg(Register::Rax, (tsc >> 0) & 0xffffffff);
Expand Down
7 changes: 7 additions & 0 deletions kernel/src/vtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,9 @@ pub enum CpuMode {
/// Virtual machine exit reason
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
pub enum VmExit {
CpuId {
inst_len: u64,
},
VmCall,
InterruptWindow,
Io,
Expand Down Expand Up @@ -1954,6 +1957,10 @@ impl Vm {
}
1 => VmExit::ExternalInterrupt,
7 => VmExit::InterruptWindow,
10 => {
let inst_len = self.reg(Register::ExitInstructionLength);
VmExit::CpuId { inst_len }
}
16 => {
let inst_len = self.reg(Register::ExitInstructionLength);
VmExit::Rdtsc { inst_len }
Expand Down

0 comments on commit 127a9ec

Please sign in to comment.