Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp590040rwe; Wed, 24 Aug 2022 06:12:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6wCxYqBqmz9Ec22whhyF9/sPgxiaX2XlNbLG/VaXYzmj6BkU5KjEx1VmrZqoZZR5ORa6vI X-Received: by 2002:a17:907:2cd1:b0:730:65c9:4c18 with SMTP id hg17-20020a1709072cd100b0073065c94c18mr2936343ejc.324.1661346723080; Wed, 24 Aug 2022 06:12:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661346723; cv=none; d=google.com; s=arc-20160816; b=JFKS0yb4qYWHVj+8kdFnqrkzPvQP6ZrKz26bYBrqLKudqKV94C2zcrbZ/dsAqXl0rh ruBP2h5u/AbF649F+jnAegzFk8vzexzOMOkIsHuQnjt1Wl0xeE2j4sf0aJPIvGL3n1EI ZGTyj4oyfaWtePL4mZfJHFCZe4vj8iAkWlXvZmIcXaNONgIFYiWw5kTFLG0juMs1Co7q uGD4v6sTaEUGIUqeF1YuUBDjHDSEGuoxd/jvoC180UfX6gKkXT/bbmKgr1AnvfFFLM8r hobBVxhjmNby2xNh2J5MxkMT1taI6mJeNQponhFIsypVaxKiFWzopFJdm2Gvm2CjWfeB 68ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id; bh=HRC/fpbDh6xd3uu7AscH6jkUeSoMewWFqhvMJdc8nDo=; b=TbXQhVIwkxVcuMq4ftL5+SS8jEN4ubmIXS8Zt+b9DAU1pNbUt/3N0uvuR6pDxPynLW GKZNe002f5aRaxKmG94wpSMizqKdJxnYIiK6H7zbF91J3auMCR6EFndSLODhiZndht/U sSxyREc+wd4BdJr/BZktWvDRDiAvA/jRk3DEKtgWP+MmMiCNIZCx7BVi4nldyoGzdBDP JlIKH/YZpBEjzEWww4uWmBwRuC+OgErednjSopR/2AKMJATRv3BlhBK1NPR+NM+3zMxB VbYvcpS/bBupjQn06h6h0GeNgSLR0cLBS6uGEpXqUpGMUlV2MmO1QIKJdFasRZIoPirj OY0g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a170906590700b00722e91c126bsi1899247ejq.55.2022.08.24.06.11.35; Wed, 24 Aug 2022 06:12: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237717AbiHXM5O (ORCPT + 99 others); Wed, 24 Aug 2022 08:57:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbiHXM5N (ORCPT ); Wed, 24 Aug 2022 08:57:13 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E5F85FFF; Wed, 24 Aug 2022 05:57:11 -0700 (PDT) Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1oQpwN-0005wX-Rc; Wed, 24 Aug 2022 14:57:03 +0200 Message-ID: Date: Wed, 24 Aug 2022 14:56:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Content-Language: en-US To: "Shukla, Santosh" Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, mlevitsk@redhat.com References: <20220810061226.1286-1-santosh.shukla@amd.com> <20220810061226.1286-6-santosh.shukla@amd.com> From: "Maciej S. Szmigiero" Subject: Re: [PATCHv3 5/8] KVM: SVM: Add VNMI support in inject_nmi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,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 24.08.2022 14:13, Shukla, Santosh wrote: > Hi Maciej, > > On 8/11/2022 2:54 AM, Maciej S. Szmigiero wrote: >> On 10.08.2022 08:12, 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 >>> --- >>> v3: >>> - Removed WARN_ON check. >>> >>> v2: >>> - Added WARN_ON check for vnmi pending. >>> - use `get_vnmi_vmcb` to get correct vmcb so to inject vnmi. >>> >>>   arch/x86/kvm/svm/svm.c | 7 +++++++ >>>   1 file changed, 7 insertions(+) >>> >>> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c >>> index e260e8cb0c81..8c4098b8a63e 100644 >>> --- a/arch/x86/kvm/svm/svm.c >>> +++ b/arch/x86/kvm/svm/svm.c >>> @@ -3479,7 +3479,14 @@ static void pre_svm_run(struct kvm_vcpu *vcpu) >>>   static void svm_inject_nmi(struct kvm_vcpu *vcpu) >>>   { >>>       struct vcpu_svm *svm = to_svm(vcpu); >>> +    struct vmcb *vmcb = NULL; >>>   +    if (is_vnmi_enabled(svm)) { >> >> I guess this should be "is_vnmi_enabled(svm) && !svm->nmi_l1_to_l2" >> since if nmi_l1_to_l2 is true then the NMI to be injected originally >> comes from L1's VMCB12 EVENTINJ field. >> > > Not sure if I understood the case fully.. so trying to sketch scenario here - > if nmi_l1_to_l2 is true then event is coming from EVTINJ. .which could > be one of following case - > 1) L0 (vnmi enabled) and L1 (vnmi disabled) As far as I can see in this case: is_vnmi_enabled() returns whether VMCB02's int_ctl has V_NMI_ENABLE bit set. This field in VMCB02 comes from nested_vmcb02_prepare_control() which in the !nested_vnmi_enabled() case (L1 is not using vNMI) copies these bits from VMCB01: > int_ctl_vmcb01_bits |= (V_NMI_PENDING | V_NMI_ENABLE | V_NMI_MASK); So in this case (L0 uses vNMI) V_NMI_ENABLE will be set in VMCB01, right? This bit will then be copied to VMCB02 so re-injection will attempt to use vNMI instead of EVTINJ. > 2) L0 & L1 both vnmi disabled. This case is ok. > > In both cases the vnmi check will fail for L1 and execution path > will fall back to default - right? > > Thanks, > Santosh Thanks, Maciej