mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: "Zack Rusin" <zack.rusin@broadcom.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	kvm@vger.kernel.org, "Doug Covelli" <doug.covelli@broadcom.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" <shuah@kernel.org>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Paul Durrant" <paul@xen.org>, "Xin Li" <xin@zytor.com>,
	"Francesco Lavra" <flavra@baylibre.com>,
	"Radim Krčmář" <rkrcmar@ventanamicro.com>,
	linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 06/12] KVM: x86: Forward VMware hypercalls to userspace
Date: Mon, 16 Nov 2026 14:27:28 -0800	[thread overview]
Message-ID: <avuDUNAU_a933zvp@seanjc-mac.roam.internal> (raw)
In-Reply-To: <ca9dffb64656a392965f95d35b9d13d829f34076.camel@infradead.org>

On Fri, Nov 13, 2026, David Woodhouse wrote:
> On Fri, 2026-11-13 at 01:33 -0500, Zack Rusin wrote:
> > > Userspace *already* needed to
> > > know about those¹ because it can't migrate while those are pending;
> > > it has to do at least one more run, even if it's with the immediate_exit
> > > flag set.
> > 
> > True, but, again afaict, that rule exists because those completions
> > have to run, so I don't think it tells us they can be dropped.
> > 
> > > If it's deemed clearer, I'd also be OK with an explicit
> > > KVM_VCPUEVENT_CANCEL_HCALL which cancels *only* hypercalls. But I don't
> > > really see the point; userspace shouldn't be getting confused when it
> > > was actually some other kind of completion that was active anyway.
> > > 
> > > ¹ https://lore.kernel.org/all/20250111012450.1262638-1-seanjc@google.com/
> > > 
> > > Looks something like this in my Hyper-V hcall series (except I already
> > > shouted at the agent for stupid struct layout and made it go run pahole
> > > on everything it's working on).
> > 
> > FWIW, restricting cancellation to explicitly marked completions looks
> > good to me.  If Sean/Paolo prefer that, I'm happy to mark our
> > completion cancellable and drop our exception fields.
> 
> I posted that as
> https://lore.kernel.org/kvm/20261113170535.79246-3-dwmw2@infradead.org/T/#u
> and caught both Paolo and Sean here at KVM Forum and both seem OK with it
> (although acquiescence when badgered at a conference doesn't necessarily
> translate to applying the patch... :)

Heh, you jinxed yourself.

Adding something to KVM_SET_VCPU_EVENTS is complete overkill, and will create a
confusing ABI for hypercalls versus MSR exits.  For the latter, KVM lets userspace
signal success/failure, and injects a #GP on failure.

The VMware case in particular is a bit different since that case needs to inject
a variety of faults, with a payload, but the concept is the same: give userspace
a way to cancel/reject the hypercall/action.  And that's dead simple, e.g.

  static int complete_vmware_hypercall_exit(struct kvm_vcpu *vcpu)
  {
	if (vcpu->run->vmware.ret)
		return 1;

	return kvm_skip_emulated_instruction(vcpu);
  }

For Hyper-V exits, from what I can tell, the plumbing already exists, i.e. I
suspect that this:

  A VMM implementing Hyper-V hypercalls behind KVM_EXIT_HYPERV_HCALL can only
  complete them: write a status, advance RIP.  The TLFS specifies some hypercalls
  to raise an exception at the hypercall instruction instead, and the exit has no
  way to say that.

is partly wrong.  Presumably the TLFS provides a HV_STATUS_xxx flag or three to
indicate "exception", KVM just needs to honor those, e.g. if the behavior only
applies to userspace exits *and* userspace is responsible for injecting the fault:

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 5d2e3617c952..7933389731e6 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2430,7 +2430,12 @@ static int kvm_hv_hypercall_complete(struct kvm_vcpu *vcpu, u64 result)

 static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu)
 {
-	return kvm_hv_hypercall_complete(vcpu, vcpu->run->hyperv.u.hcall.result);
+	u64 result = READ_ONCE(vcpu->run->hyperv.u.hcall.result);
+
+	if (hv_result_exception(result))
+		return 1;
+
+	return kvm_hv_hypercall_complete(vcpu, result);
 }

or if the type of fault is hardcoded and we want to apply the behavior to both
userspace exits and KVM-internal exits:

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 5d2e3617c952..c726a707a7ca 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2420,6 +2420,9 @@ static int kvm_hv_hypercall_complete(struct kvm_vcpu *vcpu, u64 result)
 	kvm_hv_hypercall_set_result(vcpu, result);
 	++vcpu->stat.hypercalls;

+	if (hv_result_exception(result))
+		return 1;
+
 	ret = kvm_skip_emulated_instruction(vcpu);

 	if (tlb_lock_count)

If it's a mix of those two, we can obviously sort that out.

If the exception is communicated through some other means, then (a) that needs
to be explained in detail, and (b) we should be able to use the same appraoch,
just with new "ret" field or whatever in kvm_hyperv_exit.u.hcall.

  reply	other threads:[~2026-11-16 22:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  5:59 [PATCH v3 00/12] KVM: Improve VMware guest support Zack Rusin
2026-11-11  5:59 ` [PATCH v3 01/12] KVM: x86/pmu: Honor enable_vmware_backdoor for VMware pseudo-PMCs Zack Rusin
2026-11-12  0:13   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 02/12] KVM: x86: Move VMware backdoor support to separate files Zack Rusin
2026-11-12  0:14   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 03/12] KVM: x86: Encapsulate VMware backdoor checks Zack Rusin
2026-11-12  0:14   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 04/12] KVM: x86: Add CONFIG_KVM_VMWARE Zack Rusin
2026-11-12  0:15   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 05/12] KVM: x86: Add a unified VMware capability Zack Rusin
2026-11-12  0:17   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 06/12] KVM: x86: Forward VMware hypercalls to userspace Zack Rusin
2026-11-12  0:28   ` Jim Mattson
2026-11-12  5:48     ` Zack Rusin
2026-11-12 18:52   ` Jim Mattson
2026-11-12 20:25   ` David Woodhouse
2026-11-13  1:05     ` Zack Rusin
2026-11-13  4:56       ` David Woodhouse
2026-11-13  6:33         ` Zack Rusin
2026-11-13 18:16           ` David Woodhouse
2026-11-16 22:27             ` Sean Christopherson [this message]
2026-11-11  5:59 ` [PATCH v3 07/12] KVM: x86: Route nested VMware backdoors to KVM Zack Rusin
2026-11-11  5:59 ` [PATCH v3 08/12] KVM: selftests: Add helpers to run x86 guest code in user mode Zack Rusin
2026-11-11  5:59 ` [PATCH v3 09/12] KVM: selftests: Port VMware backdoor coverage Zack Rusin
2026-11-12 18:36   ` Jim Mattson
2026-11-11  5:59 ` [PATCH v3 10/12] KVM: selftests: Test VMware hypercall exits Zack Rusin
2026-11-11  6:00 ` [PATCH v3 11/12] KVM: selftests: Test VMware hypercall exits with nested Hyper-V flushes Zack Rusin
2026-11-11  6:00 ` [PATCH v3 12/12] KVM: selftests: Test nested VMware backdoor routing 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=avuDUNAU_a933zvp@seanjc-mac.roam.internal \
    --to=seanjc@google.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=doug.covelli@broadcom.com \
    --cc=dwmw2@infradead.org \
    --cc=flavra@baylibre.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rkrcmar@ventanamicro.com \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vkuznets@redhat.com \
    --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®