mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Sean Christopherson" <seanjc@google.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"James Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Thara Gopinath" <tgopinath@linux.microsoft.com>,
	"Wei Liu" <wei.liu@kernel.org>,
	"Michael Kelley" <mhklinux@outlook.com>,
	"Nicolas Saenz Julienne" <nsaenz@amazon.com>,
	"Nikolas Wipper" <nik.wipper@gmx.de>,
	"Mushahid Hussain" <hmushi@amazon.co.uk>,
	"Sriram Nambakam" <snambakam@linux.microsoft.com>,
	"Zack Rusin" <zack.rusin@broadcom.com>,
	"Doug Covelli" <doug.covelli@broadcom.com>,
	"Jim Mattson" <jmattson@google.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Paul Durrant" <paul@xen.org>, "Xin Li" <xin@zytor.com>,
	"Francesco Lavra" <flavra@baylibre.com>,
	"Radim Krčmář" <rkrcmar@ventanamicro.com>,
	"Liran Alon" <liran.alon@oracle.com>,
	"Arbel Moshe" <arbel.moshe@oracle.com>
Subject: Re: [PATCH v3 00/15] KVM: x86: Exit handling for Hyper-V hcalls, register intercept
Date: Mon, 30 Nov 2026 14:55:38 +0000	[thread overview]
Message-ID: <ef6664e1a253c40cecda0f14320fc811840da2fc.camel@infradead.org> (raw)
In-Reply-To: <20261127152730.99319-1-dwmw2@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 4567 bytes --]

On Fri, 2026-11-27 at 15:27 +0000, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
> 
> 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 #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

  parent reply	other threads:[~2026-11-30 14:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:27 David Woodhouse
2026-11-27 15:27 ` [PATCH v3 01/15] KVM: selftests: Make the x86 SSE register helpers volatile David Woodhouse
2026-11-27 15:27 ` [PATCH v3 02/15] KVM: Define what completing an exit does with its instruction David Woodhouse
2026-11-30 17:23   ` Zack Rusin
2026-11-30 18:42     ` David Woodhouse
2026-11-30 19:51       ` Zack Rusin
2026-11-27 15:27 ` [PATCH v3 03/15] KVM: x86: Let userspace leave an MSR access alone David Woodhouse
2026-11-27 15:27 ` [PATCH v3 04/15] KVM: selftests: Test MSR accesses which userspace leaves alone David Woodhouse
2026-11-27 15:27 ` [PATCH v3 05/15] KVM: x86: hyper-v: Add KVM_CAP_HYPERV_FORWARD_HCALL David Woodhouse
2026-11-27 15:27 ` [PATCH v3 06/15] KVM: x86: hyper-v: Let userspace leave a hypercall uncompleted David Woodhouse
2026-11-27 15:27 ` [PATCH v3 07/15] KVM: x86: hyper-v: Advertise XMM fast hypercall output David Woodhouse
2026-11-27 15:27 ` [PATCH v3 08/15] KVM: selftests: Add Hyper-V hypercall forwarding test David Woodhouse
2026-11-27 15:27 ` [PATCH v3 09/15] KVM: x86: Add a per-vCPU register write filter David Woodhouse
2026-11-27 15:27 ` [PATCH v3 10/15] KVM: x86: Filter emulated CR0 and CR4 writes David Woodhouse
2026-11-27 15:27 ` [PATCH v3 11/15] KVM: VMX: Support CR0 and CR4 write filters David Woodhouse
2026-11-27 15:27 ` [PATCH v3 12/15] KVM: SVM: " David Woodhouse
2026-11-27 15:27 ` [PATCH v3 13/15] KVM: x86: Add descriptor-table registers to the write filter David Woodhouse
2026-11-27 15:27 ` [PATCH v3 14/15] KVM: selftests: Add x86 register write filter test David Woodhouse
2026-11-27 15:27 ` [PATCH v3 15/15] KVM: selftests: Test the register write filter with a nested guest David Woodhouse
2026-11-30 14:55 ` David Woodhouse [this message]
2026-11-30 17:19 ` [PATCH v3 00/15] KVM: x86: Exit handling for Hyper-V hcalls, register intercept Zack Rusin
2026-11-30 18:07   ` David Woodhouse
2026-11-30 20:00     ` Zack Rusin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef6664e1a253c40cecda0f14320fc811840da2fc.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=arbel.moshe@oracle.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=doug.covelli@broadcom.com \
    --cc=flavra@baylibre.com \
    --cc=hmushi@amazon.co.uk \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liran.alon@oracle.com \
    --cc=mhklinux@outlook.com \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=nik.wipper@gmx.de \
    --cc=nsaenz@amazon.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rkrcmar@ventanamicro.com \
    --cc=seanjc@google.com \
    --cc=skhan@linuxfoundation.org \
    --cc=snambakam@linux.microsoft.com \
    --cc=tglx@kernel.org \
    --cc=tgopinath@linux.microsoft.com \
    --cc=thomas.lendacky@amd.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    --cc=zack.rusin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®