hypervisor: emulator: Pass CPU context to instruction stream emulator

This is a precursor change to overall ioctl and hypercall reduction
effort. The old (current) CPU state can be compared to the new to
determine what has changed and avoid unnecessary register updates.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
This commit is contained in:
Stanislav Kinsburskii
2026-01-13 08:03:25 -08:00
committed by Rob Bradford
parent 03252f5851
commit 5aba9b4308
2 changed files with 25 additions and 12 deletions

View File

@@ -715,14 +715,19 @@ impl cpu::Vcpu for MshvVcpu {
map: (gva, gpa),
};
let old_state = context
.cpu_state(self.vp_index as usize)
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;
// Create a new emulator.
let mut emul = Emulator::new(&mut context);
// Emulate the trapped instruction, and only the first one.
let new_state = emul
.emulate_first_insn(
self.vp_index as usize,
.emulate_insn_stream(
&old_state,
&info.instruction_bytes[..insn_len],
Some(1),
)
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;