Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp477510imi; Thu, 21 Jul 2022 05:07:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1set18Tc8ZvMctHe6h9qDkWWbpoHuoYRLH/azfkpv2vZtLvOuIco/tglPhmNDTKYZBd+4/L X-Received: by 2002:a05:6808:f90:b0:339:ec43:c9ef with SMTP id o16-20020a0568080f9000b00339ec43c9efmr4388130oiw.248.1658405269704; Thu, 21 Jul 2022 05:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658405269; cv=none; d=google.com; s=arc-20160816; b=GPtieL1kz+8Hd7gnhdIbYS1CKNnnqJfsldVH/DekwZUSoJfF5PoejK+Eo6oQX+GhJg UxExXrlJCxEOM7jLvVviEG0T5beiI8X1ioUGdr6dk82OpUY1lfJiin53niAVXC/puTK5 nydEvjzs8XdFjDlS0VLiDWhfDoBDoEwjpFFNxdjKHryWHIy1yAdtr3aAMQuWVbxHCinU 7CY/wb6UoFtbbG0h62bJSOMVsIcmZ9kMHBJAHVC2ZpntKehIyPP4Vwz5KXGMq8XdgnYj Av/tvlyUO+eXT2fTh7QaMkt+QcL2eV50slpxTAhzVY7W8n2jZo45wgL0CCgiazDLpJYZ l1Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=E0E6tU6gY5NO+RqEHYg9V7mVYbdn26+2ozaiEoyYI8s=; b=eoW/FK08O/OX5De7XZIIuJLdi9jNOcPbzDrC05L1aiP1lNQAVqP0xGGvUEz22CGPw4 6JhUAYUmJrypROz2nmXSSZfAqHEyIcRBbwDNRw8j01QyY1wFVegt/0ZGx7MZUT00WKKI EzM8pfK+Bo7iXS+FfxltbobRRePFbek6IhdYWj79ZBXoWFz1JhJ7Q0qGxc3m8ecDNbnk Sdv9qf/MVPAA+hvJ87K4tIQfJzBmqsojsx5HsJDrYq88cu4Axl8vfGl8TWe/rIxgmMKO 8LfmgY4cO3aIMBV/b7JKZ2agaty/a/4k6UwJ3QSGg8ofdYHvUqy/v8AK2ZJP8bhsTpVv 92bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bHRnHOGP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a0568080b0800b003352927135esi1057168oij.37.2022.07.21.05.07.35; Thu, 21 Jul 2022 05:07:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bHRnHOGP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbiGUL5L (ORCPT + 99 others); Thu, 21 Jul 2022 07:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbiGUL5I (ORCPT ); Thu, 21 Jul 2022 07:57:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C0CE2D1FF for ; Thu, 21 Jul 2022 04:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658404627; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E0E6tU6gY5NO+RqEHYg9V7mVYbdn26+2ozaiEoyYI8s=; b=bHRnHOGPoylZ15ZTVNOOC7pMJ6TiSvO8g/2Zd9PY/n/s1oe7u1Je+PgEZli+EOzHjNLr7h TqAfaY7emyKDD48wyy0jH3GVgkahv7DMYxOzmCNcaYnhpQUAyVb1yrLMzknjWY/05LL2Nw 7Z8VjTyM+rg09JFzaPOnXoMwlhECLsc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-neNqakEbPvqBw9t7gQb52g-1; Thu, 21 Jul 2022 07:56:58 -0400 X-MC-Unique: neNqakEbPvqBw9t7gQb52g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84A34802D2C; Thu, 21 Jul 2022 11:56:57 +0000 (UTC) Received: from starship (unknown [10.40.192.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37D6A2026985; Thu, 21 Jul 2022 11:56:55 +0000 (UTC) Message-ID: <44938d77b4ee62b69ad3ff88be30c942282a05d7.camel@redhat.com> Subject: Re: [PATCH 4/7] KVM: SVM: Report NMI not allowed when Guest busy handling VNMI From: Maxim Levitsky To: "Shukla, Santosh" , Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 21 Jul 2022 14:56:54 +0300 In-Reply-To: References: <20220602142620.3196-1-santosh.shukla@amd.com> <20220602142620.3196-5-santosh.shukla@amd.com> <45e9ccafcdb48c7521b697b41e849dab98a7a76c.camel@redhat.com> <76e007d7fc7af0629279f2563f8d0c48274bc774.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-07-21 at 15:01 +0530, Shukla, Santosh wrote: > > On 7/10/2022 9:38 PM, Maxim Levitsky wrote: > > On Fri, 2022-06-17 at 20:29 +0530, Shukla, Santosh wrote: > > > On 6/7/2022 6:42 PM, Maxim Levitsky wrote: > > > > On Tue, 2022-06-07 at 16:10 +0300, Maxim Levitsky wrote: > > > > > On Thu, 2022-06-02 at 19:56 +0530, Santosh Shukla wrote: > > > > > > In the VNMI case, Report NMI is not allowed when the processor set the > > > > > > V_NMI_MASK to 1 which means the Guest is busy handling VNMI. > > > > > > > > > > > > Signed-off-by: Santosh Shukla > > > > > > --- > > > > > > arch/x86/kvm/svm/svm.c | 6 ++++++ > > > > > > 1 file changed, 6 insertions(+) > > > > > > > > > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > > > > > index d67a54517d95..a405e414cae4 100644 > > > > > > --- a/arch/x86/kvm/svm/svm.c > > > > > > +++ b/arch/x86/kvm/svm/svm.c > > > > > > @@ -3483,6 +3483,9 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu) > > > > > > struct vmcb *vmcb = svm->vmcb; > > > > > > bool ret; > > > > > > > > > > > > + if (is_vnmi_enabled(vmcb) && is_vnmi_mask_set(vmcb)) > > > > > > + return true; > > > > > > > > > > How does this interact with GIF? if the guest does clgi, will the > > > > > CPU update the V_NMI_MASK on its own If vGIF is enabled? > > > > > > > > Yes. > > > > > > > > What happens if vGIF is disabled and vNMI is enabled? KVM then intercepts > > > > > the stgi/clgi, and it should then update the V_NMI_MASK? > > > > > > > > No. > > > > > > For both case - HW takes the V_NMI event at the boundary of VMRUN instruction. > > > > How that is possible? if vGIF is disabled in L1, then L1 can't execute STGI/CLGI - > > that means that the CPU can't update the V_NMI, as it never sees the STGI/CLGI > > beeing executed. > > > > If vGIF is disabled then HW will take the vnmi event at the boundary of vmrun instruction. I think I understand now, if vGIF is enabled, and V_NMI_MASK is set, and the guest does STGI, then nothing new should be injected. If V_NMI_MASK is not set, then svm_nmi_blocked will respect the HF_GIF_MASK, and on STGI interception, the new NMI will be injected on VM entry by setting the V_NMI_PENDING. So looks like it should work. Thanks, Best regards, Maxim Levitsky > > Thanks, > Santosh > > > Best regards, > > Maxim Levitsky > > > > > > > > > > > > > + > > > > > > if (!gif_set(svm)) > > > > > > return true; > > > > > > > > > > > > @@ -3618,6 +3621,9 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vcpu) > > > > > > { > > > > > > struct vcpu_svm *svm = to_svm(vcpu); > > > > > > > > > > > > + if (is_vnmi_enabled(svm->vmcb) && is_vnmi_mask_set(svm->vmcb)) > > > > > > + return; > > > > > > > > > > This might have hidden assumption that we will only enable NMI window when vNMI is masked. > > > > > > > > Also what if vNMI is already pending? > > > > > > > If V_NMI_MASK set, that means V_NMI is pending, if so then inject another V_NMI in next VMRUN. > > > > > > Thanks, > > > Santosh > > > > > > > Best regards, > > > > Maxim Levitsky > > > > > > > > > > > + > > > > > > if ((vcpu->arch.hflags & (HF_NMI_MASK | HF_IRET_MASK)) == HF_NMI_MASK) > > > > > > return; /* IRET will cause a vm exit */ > > > > > > > > > > > > > > > > Best regards, > > > > > Maxim Levitsky