Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2575925imw; Sun, 10 Jul 2022 09:42:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbcNM8Rm8d5CAPnNtpAlSw6r96ukRPOANSLEFeEGGkyKRJFrsqXWW5X4TRSVLqhT1XKAS/ X-Received: by 2002:a63:1921:0:b0:412:407f:f012 with SMTP id z33-20020a631921000000b00412407ff012mr11909870pgl.125.1657471360276; Sun, 10 Jul 2022 09:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657471360; cv=none; d=google.com; s=arc-20160816; b=chJ56rGslWFio2MGCsM471xt70jnfosBiov73jVdiQRUwsGFJHw8kVftuTm5QyO/ix bokhkS74lVyN2wakifBiZ/1BmwWnsg8JqW8/r1VvzNWi6JU9HMa7PWA7kPgs+Fj4tDdq XiqDuQmoBmyoBmQoEpMQ8C1B7U6nDEpDhZXWPXJrxvjrnwnohxM10j8riCioaoVa1h9o jyF02mh5QUe4v4JEaEyA2ZUd6lyW6p0P7bS9qBvWskhAFSzdM1bq6yEXB8RSaifq+2MF eadX1h6jBMJPQ20XEdtQZKLSZJWuMMcyH9HeHHj5IEF2m0BLRaKPxEEosxOXrAcWCK97 We2A== 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=QDaP+Um08WiLx8iD9VSv1hZdsAPWgMvxBOznx9yoqlk=; b=JcATHL479fwo0OUCNxviS+rUcx+3saZAVzjYXnUiUdi2g0lq4QIhHCcQv8wtQGmYt2 AH1Jjg42no6BTan77xEPQkK5P44xP7a1OcMrHIqb07jk1LR8L9xgW7celhQlM0t4N7Fj 7CIIk+NhO9/rV0yCUl/uTJyO01XPqdYjLOpUk+hh+kSjO1RBqX8Z5qO9ExfxpCvIriZd ZBAf2w4M+/sVeKHnjExyHTrhlVYxnai6eQuOT8hfNTHnH0WzjX5WNbzdxlPy5VJuBoUK i1v0fvNWJwMati5POfAGMaKve08uqgZNqnlPr2Aj9kuPHGeBpg+4UNgR+QZZWAoc1yuB raVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZOJF3hgH; 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 q19-20020a056a00089300b00528d5546dcesi7827860pfj.267.2022.07.10.09.42.28; Sun, 10 Jul 2022 09:42:40 -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=ZOJF3hgH; 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 S229647AbiGJQI2 (ORCPT + 99 others); Sun, 10 Jul 2022 12:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiGJQIY (ORCPT ); Sun, 10 Jul 2022 12:08:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E09BC5F7D for ; Sun, 10 Jul 2022 09:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657469302; 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=QDaP+Um08WiLx8iD9VSv1hZdsAPWgMvxBOznx9yoqlk=; b=ZOJF3hgHZEG7XsvZJ5IwEEVa1UX//KLSCiC/6A/84Y+7s0w+TwzU0sCnXBFlqerokz0U4u yROxAGor4uhh2Ywgl/A1HBFFwMl6SElIvmMLcJi56/vLKasIzcIu5dC2qGpvBV/IKR3q7u OBN/aGhhCoCa4CzyJGmuSfK1C7Oy8Ks= 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-369-oHyl3jA-MZ29rftAmg328w-1; Sun, 10 Jul 2022 12:08:21 -0400 X-MC-Unique: oHyl3jA-MZ29rftAmg328w-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 EF52C185A79C; Sun, 10 Jul 2022 16:08:20 +0000 (UTC) Received: from starship (unknown [10.40.192.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACF802026D64; Sun, 10 Jul 2022 16:08:18 +0000 (UTC) Message-ID: <76e007d7fc7af0629279f2563f8d0c48274bc774.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: Sun, 10 Jul 2022 19:08:17 +0300 In-Reply-To: References: <20220602142620.3196-1-santosh.shukla@amd.com> <20220602142620.3196-5-santosh.shukla@amd.com> <45e9ccafcdb48c7521b697b41e849dab98a7a76c.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=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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. 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