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

From: David Woodhouse

Date: Mon Nov 30 2026 - 09:56:02 EST


On Fri, 2026-11-27 at 15:27 +0000, David Woodhouse 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.
>
> The completion result code deliberately does not cover:
>
>  - PIO and MMIO. Those completions carry state which can't just be
>    dropped, and VSM has no use for it: what a higher VTL intercepts
>    there is the memory access, which faults before the instruction has
>    done anything.
>
>  - Guests with protected state. There is no instruction for KVM to
>    leave alone, so MSR exits keep today's meaning (any non-zero value
>    fails the access), a Hyper-V hypercall always completes, and a
>    register write filter cannot be armed. Nor can one be armed for a
>    plain SEV guest, whose instructions KVM cannot decode.
>
>  - KVM_EXIT_HYPERCALL, KVM_EXIT_XEN and KVM_EXIT_TDX, which are
>    untouched.
>
> On an Intel Xeon 6 (itself a KVM guest, so VMX there is nested), on the
> series as posted, the three new tests and hyperv_forward_hcall pass, as
> do userspace_msr_exit_test, msrs_test, hyperv_features,
> hyperv_extended_hypercalls, set_sregs_test, cr4_cpuid_sync_test,
> xcr0_cpuid_test, smm_test and state_test: 13 of 13. The three with
> emulator legs (msr_exit_insn_test, userspace_msr_exit_test and
> reg_write_filter_test) pass again with kvm.force_emulation_prefix=1, as
> do hyperv_forward_hcall and nested_reg_write_filter_test.
>
> On a bare-metal AMD EPYC 9R14 (Zen 4), also on the series as posted,
> the same 13 pass, and the same five again with
> kvm.force_emulation_prefix=1. The three new tests also pass with
> kvm_amd nrips=0, with and without forced emulation; there the
> instruction lengths come from the emulator.
>
> An earlier revision of these patches is at the base of the full VSM
> tree², on which Windows Server 2025 boots with VBS and Credential
> Guard, through the hypercall and register write exits.
>
> One open question, on patch 7. It reports
> HV_X64_HYPERCALL_XMM_OUTPUT_AVAILABLE unconditionally, as it did in
> v2, although only a VMM which handles forwarded hypercalls can honour
> it.  I wonder if it should only be reported once the VMM has opted in,
> perhaps just tied to KVM_HYPERV_HCALL_FORWARD_UNKNOWN. I've left it as
> it is for now.
>
> Based on v7.4-rc2. Also at:
>
>   https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/exit-insn

I've dealt with the Sashiko feedback (which as ever, was different to
what I'd already dealt with in local runs), and pushed it out to an
exit-insn-v4 branch along with the complete retested vsm+planes stack.

I'll wait for a human opinion on the approach before reposting it
though, for now.

Attachment: smime.p7s
Description: S/MIME cryptographic signature