hypervisor: mshv: relax the requirement for instruction emulation

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 <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-06-28 03:27:13 +00:00 committed by Liu Wei
parent 5fec858130
commit 519476e842

View File

@ -641,7 +641,6 @@ impl cpu::Vcpu for MshvVcpu {
hv_message_type_HVMSG_UNMAPPED_GPA => { hv_message_type_HVMSG_UNMAPPED_GPA => {
let info = x.to_memory_info().unwrap(); let info = x.to_memory_info().unwrap();
let insn_len = info.instruction_byte_count as usize; let insn_len = info.instruction_byte_count as usize;
assert!(insn_len > 0 && insn_len <= 16);
let mut context = MshvEmulatorContext { let mut context = MshvEmulatorContext {
vcpu: self, vcpu: self,
@ -653,7 +652,10 @@ impl cpu::Vcpu for MshvVcpu {
// Emulate the trapped instruction, and only the first one. // Emulate the trapped instruction, and only the first one.
let new_state = emul 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()))?; .map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;
// Set CPU state back. // Set CPU state back.