Skip to content

Commit f899300

Browse files
authored
perf(mshv): skip RIP advance on VmAction::Halt fast path (#1476)
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 9026c70 commit f899300

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

  • src/hyperlight_host/src/hypervisor/virtual_machine/mshv

src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ impl VirtualMachine for MshvVm {
220220
let instruction_length = io_message.header.instruction_length() as u64;
221221
let is_write = io_message.header.intercept_access_type != 0;
222222

223+
// VmAction::Halt always means "I'm done", regardless of
224+
// whether a timer is active. The next guest dispatch
225+
// rewrites RIP via set_regs(), so skip the RIP advance on
226+
// this hot path.
227+
if is_write && port_number == VmAction::Halt as u16 {
228+
// Stop the timer thread before returning.
229+
#[cfg(feature = "hw-interrupts")]
230+
{
231+
if let Some(mut t) = self.timer.take() {
232+
t.stop();
233+
}
234+
}
235+
return Ok(VmExit::Halt());
236+
}
237+
223238
// mshv, unlike kvm, does not automatically increment RIP.
224239
if let Some(page) = self
225240
.vcpu_fd
@@ -245,19 +260,6 @@ impl VirtualMachine for MshvVm {
245260
.map_err(|e| RunVcpuError::IncrementRip(e.into()))?;
246261
}
247262

248-
// VmAction::Halt always means "I'm done", regardless
249-
// of whether a timer is active.
250-
if is_write && port_number == VmAction::Halt as u16 {
251-
// Stop the timer thread before returning.
252-
#[cfg(feature = "hw-interrupts")]
253-
{
254-
if let Some(mut t) = self.timer.take() {
255-
t.stop();
256-
}
257-
}
258-
return Ok(VmExit::Halt());
259-
}
260-
261263
#[cfg(feature = "hw-interrupts")]
262264
{
263265
if is_write {

0 commit comments

Comments
 (0)