6

VMCALL is quite similar to the SYSENTER instruction, differing in the way that SYSENTER is meant for system call (fast transition to the OS), while VMCALL is for hypercalls (transition to hypervisor).

My question is that while SYSENTER does not save the CPU state, does the same apply for VMCALL. Issuing a VMCALL causes a VM exit, but I am not sure if it saves the guest CPU state to the associated VMCS structure or not?

If it does save the CPU state then how exactly can we pass arguments in a hypercall?

1 Answer 1

5

VMCS Region is divided into 6 regions, one of which is Guest-state area.

Guest State stores RIP, RFLAGS and RSP on every VMExit. The rest of guest GPRs are live in HW immediately after a VMExit.

VMCALL only causes a VMExit unconditionally. The usage of registers as arguments is left to the api of the VMM.

From Linux KVM API documentation:

Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively. The hypercall number should be placed in rax and the return value will be placed in rax. No other registers will be clobbered unless explicitly stated by the particular hypercall.

From Intel 64 and IA-32 Architectures Software Developer’s Manual:

this instruction does nothing more than cause a VM exit, registering the appropriate exit reason.

From the above I conclude that VMCALL does not preserve any CPU state.

4
  • That makes sense; leaving register save/restore to software is the obvious way to design things. Otherwise you'd need a control register to point to a register-save area and stuff like that. So using vmcall is a lot like using syscall; you have to know the ABI you're calling. Jun 16, 2016 at 3:37
  • Does a VM exit save the register state? I could not find any fields for the regular registers in VMCS guest area in the Intel Manual
    – qstack
    Jun 22, 2016 at 7:39
  • @qstack I guess this should be done by the VMM itself. Jun 22, 2016 at 15:09
  • Your last sentence is very misleading. Every VM exit saves a huge amount of CPU state. The guest state saved for a VMCALL is identical that for every other VM exit type. You are correct that VM exits do not save the general-purpose registers other than RSP.
    – prl
    Jan 17, 2022 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.