x86中的VMCALL指令是否保存来宾CPU状态

Does VMCALL instruction in x86 save the guest CPU state

VMCALL 与 SYSENTER 指令非常相似,不同之处在于 SYSENTER 用于系统调用(快速过渡到操作系统),而 VMCALL 用于超级调用(过渡到管理程序)。

我的问题是,虽然 SYSENTER 不保存 CPU 状态,但同样适用于 VMCALL。发出 VMCALL 会导致 VM 退出,但我不确定它是否将来宾 CPU 状态保存到关联的 VMCS 结构中?

如果它确实保存了 CPU 状态,那么我们如何在 hypercall 中传递参数?

VMCS Region分为6个区域,其中一个是Guest-state区域。

来宾状态在每个 VMExit 上存储 RIP、RFLAGS 和 RSP。 VMExit 后,其余的来宾 GPR 立即在 HW 中运行。

VMCALL 只会无条件地导致 VMExit。寄存器作为参数的使用留给 VMM api。

来自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.

来自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.

从上面我得出结论,VMCALL 不保留任何 CPU 状态。