From 28066469ccd6b6dd89e44b116c214eb498875b27 Mon Sep 17 00:00:00 2001 From: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> Date: Wed, 27 May 2026 12:47:21 -0700 Subject: [PATCH] perf(mshv): skip RIP advance on VmAction::Halt fast path Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> --- .../hypervisor/virtual_machine/mshv/x86_64.rs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs b/src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs index badd4f90d..9a277fe9d 100644 --- a/src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs +++ b/src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs @@ -220,6 +220,21 @@ impl VirtualMachine for MshvVm { let instruction_length = io_message.header.instruction_length() as u64; let is_write = io_message.header.intercept_access_type != 0; + // VmAction::Halt always means "I'm done", regardless of + // whether a timer is active. The next guest dispatch + // rewrites RIP via set_regs(), so skip the RIP advance on + // this hot path. + if is_write && port_number == VmAction::Halt as u16 { + // Stop the timer thread before returning. + #[cfg(feature = "hw-interrupts")] + { + if let Some(mut t) = self.timer.take() { + t.stop(); + } + } + return Ok(VmExit::Halt()); + } + // mshv, unlike kvm, does not automatically increment RIP. if let Some(page) = self .vcpu_fd @@ -245,19 +260,6 @@ impl VirtualMachine for MshvVm { .map_err(|e| RunVcpuError::IncrementRip(e.into()))?; } - // VmAction::Halt always means "I'm done", regardless - // of whether a timer is active. - if is_write && port_number == VmAction::Halt as u16 { - // Stop the timer thread before returning. - #[cfg(feature = "hw-interrupts")] - { - if let Some(mut t) = self.timer.take() { - t.stop(); - } - } - return Ok(VmExit::Halt()); - } - #[cfg(feature = "hw-interrupts")] { if is_write {