From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D604B391836 for ; Wed, 4 Mar 2026 08:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772613385; cv=none; b=dimnnzpH4UT/hc+3da5hlqF71SGw3Ckervm6CD7AGPdWGsgbyhbbhL+ZkgZLvssGwrR7T8TCNGN60bQNyB32cJOC52qgVlZ3N6g2PgCIbUITyCFieKPl/Do1aw1WnqZ10yEbY/lFUtSxRTpT0X9YJbdSB7ibX92gwRD9O+jptl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772613385; c=relaxed/simple; bh=Jd1aaV467fk1kqAGA4F9wKW75W9/mq7tq7aMFmhVX0Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=mequ3RXM1NzF1UQxGDxcpiGXMcLcO8niGNvweKqc2b9AO9Qy9TJ7oHq9J/YAq5Wp05qReEs8JSgrgZF0xjxcMGt/gbswn08BxFh329R92155JZO4ddXyi4pnPj8PCKZSHYszOCtrHApKFPFkaCn+D2yUq38IM3Cb75xXcigwvu0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XS7wzm7C; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IQd0P/uh; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XS7wzm7C"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IQd0P/uh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772613382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZgQ4/WuIi2IMDLFjnCM3cSYg+YpvYB+CaxzfN9HB8CY=; b=XS7wzm7CiNbcJZhHJbbZ/8PYOELDpm3w4ulZD1YZyniFOViwCmBDA3EiybgsIdHLU1ng1M BFfW5kBuYmgSonY/4TaDGljWgIAgwB8oIGmQl95dieu8kDE1akn5OCzPCzVM4xGA5ENc9U 5sKl9YP7G4WnTy/G5GwJmYD7BV7ee2g= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-Vgq78cAyPaeeh_JfNRgONA-1; Wed, 04 Mar 2026 03:36:21 -0500 X-MC-Unique: Vgq78cAyPaeeh_JfNRgONA-1 X-Mimecast-MFC-AGG-ID: Vgq78cAyPaeeh_JfNRgONA_1772613381 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4837b7903f3so79225835e9.2 for ; Wed, 04 Mar 2026 00:36:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1772613380; x=1773218180; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZgQ4/WuIi2IMDLFjnCM3cSYg+YpvYB+CaxzfN9HB8CY=; b=IQd0P/uhRacXNWGo/V6ihGhCpym1wHxejTcRAL1Gm6ychQ5GqGIVgIOVpuVMByQg/y 2HgMIFP9MeC4T2a0XsO7bBt/grSihZz6bt7otAFj2B35KzjQIh86XATBQFn1gpXFV2BW tilC3eAR1VisL4Aw0o+AS8xs3SG0rPpK7HT1qpDTdM4k5nZb5P2WEXpKFsamv23P+0nY 0rvy5D0KAQ1sTeExCUJT5/i/wKyHCIgoU/r9KYSUdz+1TuFTWiWZNMBJjgq57b2PX+gr hIsHvtYcdDsg2w9YvR0fb3tHmcfCk75llhVEftwAtZ8uHySd9vU8/vGexJ2RHeUDZd7m dsuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772613380; x=1773218180; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZgQ4/WuIi2IMDLFjnCM3cSYg+YpvYB+CaxzfN9HB8CY=; b=I4tHRpz0HhrZVRjBntWIapsVj2Jis+V0nuZDXSIBp2v9O0/V7bPxeYjuqIaAH62wAy ardj2gJiEFKFZKuTleCEvhAnwZZq9kDdmsclyO5edXoZ7okIv7+pyz9W0Pm6dG7NejkZ F72V9cQVVf4nxed4NYkOmvkHrr19zo2WCErEiQ+ZLZDxebXJuAVRi4pYQLBMFLFGL+3X 3mq1xU8joT2Iw/os3LOcfXQZ1FpProZd7P1IoKGIMs5j8I0cg4qx0TZOUR+qLaVabgUJ khD9/VEdXWJ+agae0gfIOLxaPAaKKrbWwlMfoxcnYZ/E5y9/1vtGdOAfkJuphK1D5GSd AjRA== X-Forwarded-Encrypted: i=1; AJvYcCUSCynHVeNseuTryHECGZlrI43rjMID/Kri8KqQLF63kZZLSe399DXG5L7obnzBJxpN9uZtZWAWvdqWCb4=@vger.kernel.org X-Gm-Message-State: AOJu0YxcXx24Kk+vVOBppEg99G4/lHxXTIuO+azPcw9hjpnnMUracaox 05xmK/dwl2kk4h/KtEbzUzju9DvCMKTI2m3N5jOBPh3ITVJiADx6/+rw3/gej1SLUTbzdus366/ MEqgN2nuDZErAOZNSjzdnKGSfn1UmSfeeBTuyV/vIHR8EuCprwS+FzAcQnd9Z2R+b2A== X-Gm-Gg: ATEYQzycEMsa6/ivy+1WCigyoJniK5ebX1dR0QRzin7PwEicjssvdVDksrnhZPc0fPw lyG7nLYTl8CnwEeFVsweUoiXREDJtehL+H9W8M23JPMgXuwPogPaC7u3IeJxlgi2CgFdik/6hM6 ZrARywsYRg6pUZyU8o0A14/9QEDU+cfCRTK15EMaX61R8KKQ7BZfUCF2FHXvduHHDkg573rJMen lXB4zz1JDiQjz6sHuXkhGUpBDK//4oFyKlGc2/VTsW5G0UhvYNaQIJaCOz/SFoioTWrh8K4ooQN thVU+aTBCjb1Pu2parNbm++gqbtycMyN/N1P2nIEpNnHZcSZwktYdUcPqb9sqrfc/SlCuCAk32Z SbZTPFZcucfRkiC+YVw== X-Received: by 2002:a05:600c:45c6:b0:483:c12b:fe4b with SMTP id 5b1f17b1804b1-4851984953emr17559345e9.9.1772613380425; Wed, 04 Mar 2026 00:36:20 -0800 (PST) X-Received: by 2002:a05:600c:45c6:b0:483:c12b:fe4b with SMTP id 5b1f17b1804b1-4851984953emr17558675e9.9.1772613379272; Wed, 04 Mar 2026 00:36:19 -0800 (PST) Received: from fedora (g3.ign.cz. [91.219.240.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485187c2ef2sm36649635e9.5.2026.03.04.00.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 00:36:18 -0800 (PST) From: Vitaly Kuznetsov To: Sean Christopherson , Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kevin Cheng Subject: Re: [PATCH v5 1/2] KVM: nSVM: Raise #UD if unhandled VMMCALL isn't intercepted by L1 In-Reply-To: <20260304002223.1105129-2-seanjc@google.com> References: <20260304002223.1105129-1-seanjc@google.com> <20260304002223.1105129-2-seanjc@google.com> Date: Wed, 04 Mar 2026 09:36:17 +0100 Message-ID: <87bjh4f0u6.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Sean Christopherson writes: > From: Kevin Cheng > > Explicitly synthesize a #UD for VMMCALL if L2 is active, L1 does NOT want > to intercept VMMCALL, nested_svm_l2_tlb_flush_enabled() is true, and the > hypercall is something other than one of the supported Hyper-V hypercalls. > When all of the above conditions are met, KVM will intercept VMMCALL but > never forward it to L1, i.e. will let L2 make hypercalls as if it were L1. > > The TLFS says a whole lot of nothing about this scenario, so go with the > architectural behavior, which says that VMMCALL #UDs if it's not > intercepted. > > Opportunistically do a 2-for-1 stub trade by stub-ifying the new API > instead of the helpers it uses. The last remaining "single" stub will > soon be dropped as well. > > Suggested-by: Sean Christopherson > Fixes: 3f4a812edf5c ("KVM: nSVM: hyper-v: Enable L2 TLB flush") > Cc: Vitaly Kuznetsov > Cc: stable@vger.kernel.org > Signed-off-by: Kevin Cheng > Link: https://patch.msgid.link/20260228033328.2285047-5-chengkev@google.com > [sean: rewrite changelog and comment, tag for stable, remove defunct stubs] > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/hyperv.h | 8 -------- > arch/x86/kvm/svm/hyperv.h | 11 +++++++++++ > arch/x86/kvm/svm/nested.c | 4 +--- > arch/x86/kvm/svm/svm.c | 19 ++++++++++++++++++- > 4 files changed, 30 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h > index 6ce160ffa678..6301f79fcbae 100644 > --- a/arch/x86/kvm/hyperv.h > +++ b/arch/x86/kvm/hyperv.h > @@ -305,14 +305,6 @@ static inline bool kvm_hv_has_stimer_pending(struct kvm_vcpu *vcpu) > { > return false; > } > -static inline bool kvm_hv_is_tlb_flush_hcall(struct kvm_vcpu *vcpu) > -{ > - return false; > -} > -static inline bool guest_hv_cpuid_has_l2_tlb_flush(struct kvm_vcpu *vcpu) > -{ > - return false; > -} > static inline int kvm_hv_verify_vp_assist(struct kvm_vcpu *vcpu) > { > return 0; > diff --git a/arch/x86/kvm/svm/hyperv.h b/arch/x86/kvm/svm/hyperv.h > index d3f8bfc05832..9af03970d40c 100644 > --- a/arch/x86/kvm/svm/hyperv.h > +++ b/arch/x86/kvm/svm/hyperv.h > @@ -41,6 +41,13 @@ static inline bool nested_svm_l2_tlb_flush_enabled(struct kvm_vcpu *vcpu) > return hv_vcpu->vp_assist_page.nested_control.features.directhypercall; > } > > +static inline bool nested_svm_is_l2_tlb_flush_hcall(struct kvm_vcpu *vcpu) > +{ > + return guest_hv_cpuid_has_l2_tlb_flush(vcpu) && > + nested_svm_l2_tlb_flush_enabled(vcpu) && > + kvm_hv_is_tlb_flush_hcall(vcpu); > +} > + > void svm_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu); > #else /* CONFIG_KVM_HYPERV */ > static inline void nested_svm_hv_update_vm_vp_ids(struct kvm_vcpu *vcpu) {} > @@ -48,6 +55,10 @@ static inline bool nested_svm_l2_tlb_flush_enabled(struct kvm_vcpu *vcpu) > { > return false; > } > +static inline bool nested_svm_is_l2_tlb_flush_hcall(struct kvm_vcpu *vcpu) > +{ > + return false; > +} > static inline void svm_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu) {} > #endif /* CONFIG_KVM_HYPERV */ > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > index 53ab6ce3cc26..750bf93c5341 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -1674,9 +1674,7 @@ int nested_svm_exit_special(struct vcpu_svm *svm) > } > case SVM_EXIT_VMMCALL: > /* Hyper-V L2 TLB flush hypercall is handled by L0 */ > - if (guest_hv_cpuid_has_l2_tlb_flush(vcpu) && > - nested_svm_l2_tlb_flush_enabled(vcpu) && > - kvm_hv_is_tlb_flush_hcall(vcpu)) > + if (nested_svm_is_l2_tlb_flush_hcall(vcpu)) > return NESTED_EXIT_HOST; > break; > default: > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 8f8bc863e214..38a2fad81ad8 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -52,6 +52,7 @@ > #include "svm.h" > #include "svm_ops.h" > > +#include "hyperv.h" > #include "kvm_onhyperv.h" > #include "svm_onhyperv.h" > > @@ -3228,6 +3229,22 @@ static int bus_lock_exit(struct kvm_vcpu *vcpu) > return 0; > } > > +static int vmmcall_interception(struct kvm_vcpu *vcpu) > +{ > + /* > + * Inject a #UD if L2 is active and the VMMCALL isn't a Hyper-V TLB > + * hypercall, as VMMCALL #UDs if it's not intercepted, and this path is > + * reachable if and only if L1 doesn't want to intercept VMMCALL or has > + * enabled L0 (KVM) handling of Hyper-V L2 TLB flush hypercalls. > + */ > + if (is_guest_mode(vcpu) && !nested_svm_is_l2_tlb_flush_hcall(vcpu)) { > + kvm_queue_exception(vcpu, UD_VECTOR); > + return 1; > + } > + > + return kvm_emulate_hypercall(vcpu); > +} > + > static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { > [SVM_EXIT_READ_CR0] = cr_interception, > [SVM_EXIT_READ_CR3] = cr_interception, > @@ -3278,7 +3295,7 @@ static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { > [SVM_EXIT_TASK_SWITCH] = task_switch_interception, > [SVM_EXIT_SHUTDOWN] = shutdown_interception, > [SVM_EXIT_VMRUN] = vmrun_interception, > - [SVM_EXIT_VMMCALL] = kvm_emulate_hypercall, > + [SVM_EXIT_VMMCALL] = vmmcall_interception, > [SVM_EXIT_VMLOAD] = vmload_interception, > [SVM_EXIT_VMSAVE] = vmsave_interception, > [SVM_EXIT_STGI] = stgi_interception, Reviewed-by: Vitaly Kuznetsov -- Vitaly