Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2576167imw; Sun, 10 Jul 2022 09:43:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLB43I3cwn5o1YHQTgELmiYvznhrgyV/n5XEgcb3ANv67c0jxYe3GiWAEOWpygfDm6bdlb X-Received: by 2002:a17:903:2310:b0:16c:1546:19ba with SMTP id d16-20020a170903231000b0016c154619bamr14228870plh.57.1657471383573; Sun, 10 Jul 2022 09:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657471383; cv=none; d=google.com; s=arc-20160816; b=djVzXev4RY0UEMe8Pk21gIVJpyTgzhDiS41umaXI7jU+2YRldqILrqrR07at8Tcp96 jDh7DNw5mwCZSnKyaXcpE0v0HDqx9ftBp/d6vSCCAJjMObNt7Qoat+MjmHMlu1yB9mX8 k6GU6nUN9tknBhKO5WMBaP3FsnETOan9x6UAx/aBNmT1a70zgncwY8dhuNX3o9QWqFwW czWiSRROiLgvhIB9Yo/RG7vXXlgctGkOMdaSi6+tk79cTgC688G0j1UGAQjWJI1eRpxz UEbDQ9RqXHCaIBmIXiv10Nqzo5F3uewuLt0JifU5SXrLNrjusEufnQaFyq5PoKZOZflx Bxdg== 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=7cDiMFRwcLb3xRy42jRsEfwAfDPcPQNVS/oizbo1jZ0=; b=ES5AYBQmg4WY/+X1XK5T+UO/9d1/BjJKzg/ypgHzvjq892/yiuP6CaZjQbJQZhfU5W C+oV8ij0p4weD90C6j/D+JAuX+E2fFz3PfKbLUDu+aq/GVgM6vOZO0DZPC2TCX6jX30u 7POEzBP7xzl8JMDpg8hf+bVsjKTFC3IMLUEwHtzQXMLCCW9sqQPunkIghxQr2Pz3wmva AnkvzLUWuXmeYcR/cTb27bOnFuCjm0TdlIcxBgsOEB0uR/JvkPWf9Ayv2VWQ4a3yOjl/ J4GnZ6QmpAfh4zqcVfZ9f5RoZw3L194dlBABaPmu6gOwRbP6PmdDBYwKRqZAhPjhqU8b rhsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UkAG1COO; 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 y65-20020a638a44000000b00411b662ae26si5519340pgd.671.2022.07.10.09.42.51; Sun, 10 Jul 2022 09:43:03 -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=UkAG1COO; 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 S229564AbiGJQHg (ORCPT + 99 others); Sun, 10 Jul 2022 12:07:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiGJQHf (ORCPT ); Sun, 10 Jul 2022 12:07:35 -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 E7A5812AA7 for ; Sun, 10 Jul 2022 09:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657469254; 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=7cDiMFRwcLb3xRy42jRsEfwAfDPcPQNVS/oizbo1jZ0=; b=UkAG1COOnEdbrxzvztnDo3rrvoR8m9ZhMp108YpEjHitlD+GLWP3fBkXBtVlf5+Nyj+L7p EqYTo0DkW0V5XArsiIyvm3x45FTgvQ7FX6XZxRyCrskW7bBYvptszmBhSd6yMA9lkKSiy5 Jc7U7ZqeNGfniQtKeUDN6KHv0lHIxTM= 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-135-WYrWyNiINXiQSzsq-MwwhQ-1; Sun, 10 Jul 2022 12:07:27 -0400 X-MC-Unique: WYrWyNiINXiQSzsq-MwwhQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35322101AA47; Sun, 10 Jul 2022 16:07:27 +0000 (UTC) Received: from starship (unknown [10.40.192.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7474492CA2; Sun, 10 Jul 2022 16:07:24 +0000 (UTC) Message-ID: <670ce789f6139143f781bdd5ebfead79d5a4fadb.camel@redhat.com> Subject: Re: [PATCH 5/7] KVM: SVM: Add VNMI support in inject_nmi 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:07:23 +0300 In-Reply-To: <0981fd1c-b4b4-84ad-27e9-babcfa2524db@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> <20220602142620.3196-6-santosh.shukla@amd.com> <0981fd1c-b4b4-84ad-27e9-babcfa2524db@amd.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.85 on 10.11.54.9 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=unavailable 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:35 +0530, Shukla, Santosh wrote: > > On 6/7/2022 6:44 PM, Maxim Levitsky wrote: > > On Thu, 2022-06-02 at 19:56 +0530, Santosh Shukla wrote: > > > Inject the NMI by setting V_NMI in the VMCB interrupt control. processor > > > will clear V_NMI to acknowledge processing has started and will keep the > > > V_NMI_MASK set until the processor is done with processing the NMI event. > > > > > > Signed-off-by: Santosh Shukla > > > --- > > > arch/x86/kvm/svm/svm.c | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > > index a405e414cae4..200f979169e0 100644 > > > --- a/arch/x86/kvm/svm/svm.c > > > +++ b/arch/x86/kvm/svm/svm.c > > > @@ -3385,11 +3385,16 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) > > > { > > > struct vcpu_svm *svm = to_svm(vcpu); > > > > > > + ++vcpu->stat.nmi_injections; > > > + if (is_vnmi_enabled(svm->vmcb)) { > > > + svm->vmcb->control.int_ctl |= V_NMI_PENDING; > > > + return; > > > + } > > Here I would advice to have a warning to check if vNMI is already pending. > > > Yes, in v2. > > > Also we need to check what happens if we make vNMI pending and get #SMI, > > while in #NMI handler, or if #NMI is blocked due to interrupt window. > > > > V_NMI_MASK should be saved as 1 in the save area and > hypervisor will resume the NMI handler after handling the SMI. Answering my own question, because I did some homework in this area while working on that SMI int shadow bug: Actually what will happen (now I checked) is that we have a special KVM host state flag (called X86EMUL_SMM_MASK, and HF_SMM_INSIDE_NMI_MASK), and what we do is that if we receive SMI while in NMI handler, we don't mask the NMI again, on RSM we don't unmask NMI. Also, as I found out the hard way recently, the NMI is not blocked by the interrupt shadow. I don't think that anything is saved to the SMRAM in this case. Best regards, Maxim Levitsky > > Thanks, > Santosh > > > Best regards, > > Maxim Levitsky > > > > > > > + > > > svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; > > > vcpu->arch.hflags |= HF_NMI_MASK; > > > if (!sev_es_guest(vcpu->kvm)) > > > svm_set_intercept(svm, INTERCEPT_IRET); > > > - ++vcpu->stat.nmi_injections; > > > } > > > > > > static void svm_inject_irq(struct kvm_vcpu *vcpu)