Skip to content

Commit

Permalink
hypervisor: mshv: relax the requirement for instruction emulation
Browse files Browse the repository at this point in the history
Previously we required the hypervisor to give us a valid instruction
stream. That worked well enough because we never hit any edge conditions
(such as when the instruction stream crosses page boundary).

Now that MSHV can deal with partial or empty instruction stream, we can
remove that requirement.

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
liuw committed Jul 4, 2024
1 parent 5fec858 commit 519476e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hypervisor/src/mshv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ impl cpu::Vcpu for MshvVcpu {
hv_message_type_HVMSG_UNMAPPED_GPA => {
let info = x.to_memory_info().unwrap();
let insn_len = info.instruction_byte_count as usize;
assert!(insn_len > 0 && insn_len <= 16);

let mut context = MshvEmulatorContext {
vcpu: self,
Expand All @@ -653,7 +652,10 @@ impl cpu::Vcpu for MshvVcpu {

// Emulate the trapped instruction, and only the first one.
let new_state = emul
.emulate_first_insn(self.vp_index as usize, &info.instruction_bytes)
.emulate_first_insn(
self.vp_index as usize,
&info.instruction_bytes[..insn_len],
)
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;

// Set CPU state back.
Expand Down

0 comments on commit 519476e

Please sign in to comment.