Re: [PATCH v3 00/15] KVM: x86: Exit handling for Hyper-V hcalls, register intercept

From: Zack Rusin

Date: Mon Nov 30 2026 - 12:20:02 EST


On Fri, Nov 27, 2026 at 10:27 AM David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:
>
> From: David Woodhouse <dwmw@xxxxxxxxxxxx>
>
> Add KVM_CAP_HYPERV_FORWARD_HCALL. As with KVM_CAP_XEN_HVM and
> KVM_CAP_EXIT_HYPERCALL, KVM_CHECK_EXTENSION returns a bitmask of
> features and KVM_ENABLE_CAP takes the subset to enable. The first
> feature, KVM_HYPERV_HCALL_FORWARD_UNKNOWN, surfaces unknown hypercalls
> to userspace through the existing KVM_EXIT_HYPERV_HCALL exit.
>
> A second feature, KVM_HYPERV_HCALL_RET, allows userspace to choose
> whether/how the kernel should complete the hypercall, populating a
> 'ret' field with one of:
>
> KVM_INSN_COMPLETE finish the instruction, as now
> KVM_INSN_GP inject #GP(0) at it
> KVM_INSN_UD inject #UD at it
> KVM_INSN_RESUME do nothing; resume the guest as userspace left it
>
> Hyper-V needs to do this in some cases, for example HvCallVtlCall and
> HvCallVtlReturn are supposed to raise #UD when they are refused.
>
> Further features will follow for HvCallVtlCall and HvCallVtlReturn on
> VMs with planes, so that KVM can handle VTL transitions in the kernel.
>
> Also add KVM_CAP_X86_REG_WRITE_FILTER for trapping control register
> writes (CR0, CR4, XCR0, IDTR, LDTR, etc.).
>
> Add KVM_CAP_X86_MSR_EXIT_INSN to allow MSR exits to gain the same
> ability to COMPLETE/GP/UD/RESUME so that they can be handled by
> another plane too. The existing 'error' field was already a u8 there,
> so userspace can just opt in to using the new KVM_INSN_xxx values in
> place of the existing 'non-zero means #GP' behaviour.
>
> The VMware hypercall series¹ needs to fault its instruction too, and
> with more than #GP. As posted, it has its exit carry a vector, an
> error code and a fault address for KVM to inject. It can use the same
> model, and the complex faults can be injected with KVM_SET_VCPU_EVENTS
> followed by a ret of KVM_INSN_RESUME.

My unposted v4 drops the exception fields and any non-zero ret leaves
the instruction alone. I think with your numbering, that would give 1
and 2 a different meaning for VMware.

Could VMware take just 0 (complete if the linear RIP still matches)
and 3 (resume as userspace left it)? KVM_RUN could fail with -EINVAL
for anything else, leaving 1 and 2 available for #GP(0) and #UD.

z

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature