From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794868054; b=AuTwN0EcTr4Gx4ybbUDVv9Op4Ui3Dyv98gqA4wbKWtRqrZI2XVwOE/QHHK70T3+Q8cPa kywPGmNUAAoHkxd+Cwzepk2/AQrVWy0m6Z/N6Yoe9aaIFPo6rMQq2U+zRYqYWT6zoU1sm 8dzxwdNFNnj5QP7I8c8GVlnXRSNphnZ0sdy/hC3C1v5bNJsyUmhNER7pkm83nihR9PlLd Zc2dUtkPYC4sGX/SdRItL8+9DrGDz7YRabRFPfEj3S+yEeTvWfV7WRUejpZCHTrNVtVW9 EtF8VsK6YKWhRjfLEPN96XxaGlihS6xzomfwfpApk23H/KmDLV97E8hc8HWQcJ7hXWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794868054; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type: Content-Transfer-Encoding; bh=RUvXiIcVm9hOpppwwCqg1ARGN5d5bhbmrIqkvTODPmQ=; b=EAorzBm3/28VSpsnRY9XMf3WXi/njP9H+ZvUFs7hnfaIR97L5S+UofIRFK57xTf+i623 f31X/j1mod5ifkmxV8xBiiu9DTeGahM0L4vDkfq76SAZXMTXV9Nadj7UMyr3GePpVsOuh cx6IIM0Szw3Lc4a7NEU5YIPTQmUN0ceZRnTKOVsIS+K9DP/e3obhmO2u3oiNznvRo4BbJ AZMyVxUfGFMvht8yBkSkCO0llXAWKqNtmz6F9AYNo2h4hqDGbZSuks4grHH9K4Vi/bR8Z 194/Q9yEZKlvsGP51x/75AxP/DkoqpSdI2pXqv6uq+w+U3j5gB8oYlzceqvwzXTXNdw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ni9kZ9z3; arc=none smtp.remote-ip=209.85.216.72 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85AD3606A8A1 for ; Mon, 16 Nov 2026 22:27:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85AD3606A8A1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ni9kZ9z3 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-3b18a173e48so3306977a91.0 for ; Mon, 16 Nov 2026 14:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794868050; x=1795472850; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=RUvXiIcVm9hOpppwwCqg1ARGN5d5bhbmrIqkvTODPmQ=; b=ni9kZ9z3ndG3fR2W1CR/nXPGUaB4ZhicnRKeINuTayT2Oky75VTmjsp/DzFK86Cd9v cPuoexhvixBJyC7j96hyx+yJVVOr7VBMAk8TLQNJT8bkATeR0B7k0ge7nhaUGONn/UOb gEXkCJLiugSWUvSaIeV7WGRgINROsyHnlu/Fn50HVBM+HAJlzY/ll3zTYjoV/rYfHxxj Ltpok75OWasipSzWml+SR4Th8dijeW+FKWIGF6HtVq3JO2m2NZbMKiQRrwLFEpcL++E7 RWLup/N/BkKUgkCU/Fe2e7Q57Ua0Yn4kx63U3lSePzsGhjAmmmW8lWZKaBAuuUSETbLk H8Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794868050; x=1795472850; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RUvXiIcVm9hOpppwwCqg1ARGN5d5bhbmrIqkvTODPmQ=; b=N3UD1JicOnI00uDEaom3mLixwDToBSXe2iSI02W0b/vlbLrmbKl/pSfUhtjNign6AS IqKDY45ghceIq7WCXA7rMyjk8zOIjuHO91j1Y9RYlTtRdzb15W52VAkegY9v6H4f/1hZ M+MDR2fXkkpqbW5XUYrj57rbVgvNvaUJpff+tKBKwsM02Jlslclwk9PYbO0XFAZFccjB mw2YZvIFSIBzEc35d0JG9+pCqSSVXlSx6AbvM6Lvx51ftSVecwv5LgKedJK0fAnnuFhU JsdOJYM5cKMswW0Z23nMYelFVnponj6M/oaDJ3E0ciqahWkE6wcgcDOOTx4cXJbtz17H rQmQ== X-Forwarded-Encrypted: i=1; AL+hErGJ08Ue5jIyuc58/YZWahwfdmYu2XLy9/avj3HTX0WMnoYWi+SUkmmGa8l2nYdg3BLFoAAWSudICQKbMCU=@vger.kernel.org X-Gm-Message-State: APuU4Z9Bhtqwdk8THw/cWegfNBYUUm0z21ldMPYaTN+enVL4V//2yTDg UginUNOfDsQLV1UfGgIoFg5Jyadkq9bTTEB3ElH5qsMAIRrOTv4ZvxQF1RxdooVJqdI6V0PfXfh UI6ebyQ== X-Received: from ploh2.prod.google.com ([2002:a17:902:f702:b0:2e3:1b6e:33bb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:574b:b0:3ae:2969:903f with SMTP id 98e67ed59e1d1-3b1b0b8bcb7mr10699281a91.45.1794868049419; Mon, 16 Nov 2026 14:27:29 -0800 (PST) Date: Mon, 16 Nov 2026 14:27:28 -0800 In-Reply-To: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <90467782be23b83fd3e9a6afe2f1d2149eaf9db9.1794374897.git.zack.rusin@broadcom.com> <876c4f4fc442116c9bff8abd8c34f99fcfa65531.camel@infradead.org> <1bae109338ab6ff1ff14eac811f7e86ced785b22.camel@infradead.org> Message-ID: Subject: Re: [PATCH v3 06/12] KVM: x86: Forward VMware hypercalls to userspace From: Sean Christopherson To: David Woodhouse Cc: Zack Rusin , Paolo Bonzini , kvm@vger.kernel.org, Doug Covelli , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jonathan Corbet , Randy Dunlap , Shuah Khan , Vitaly Kuznetsov , Paul Durrant , Xin Li , Francesco Lavra , "Radim =?utf-8?B?S3LEjW3DocWZ?=" , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C2=B9 because it can't migrate while those are pendi= ng; > > > it has to do at least one more run, even if it's with the immediate_e= xit > > > flag set. > >=20 > > 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. > >=20 > > > 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. > > >=20 > > > =C2=B9 https://lore.kernel.org/all/20250111012450.1262638-1-seanjc@go= ogle.com/ > > >=20 > > > Looks something like this in my Hyper-V hcall series (except I alread= y > > > shouted at the agent for stupid struct layout and made it go run paho= le > > > on everything it's working on). > >=20 > > FWIW, restricting cancellation to explicitly marked completions looks > > good to me.=C2=A0 If Sean/Paolo prefer that, I'm happy to mark our > > completion cancellable and drop our exception fields. >=20 > 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 crea= te a confusing ABI for hypercalls versus MSR exits. For the latter, KVM lets us= erspace signal success/failure, and injects a #GP on failure. The VMware case in particular is a bit different since that case needs to i= nject a variety of faults, with a payload, but the concept is the same: give user= space 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 on= ly complete them: write a status, advance RIP. The TLFS specifies some hype= rcalls 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 thre= e to indicate "exception", KVM just needs to honor those, e.g. if the behavior o= nly 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 =3D 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 b= oth 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 =3D 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 ne= eds to be explained in detail, and (b) we should be able to use the same apprao= ch, just with new "ret" field or whatever in kvm_hyperv_exit.u.hcall.