Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp627521rwe; Thu, 25 Aug 2022 06:37:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR4o/ODi7CAKD5+f7m0RAWMZ2umGT75ihZz9ZDU6R5pnOU2NRJKg4vHY1RsD9d6CGH4b2lZG X-Received: by 2002:a05:6402:1f8c:b0:43e:8fab:76c with SMTP id c12-20020a0564021f8c00b0043e8fab076cmr3280064edc.126.1661434663720; Thu, 25 Aug 2022 06:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661434663; cv=none; d=google.com; s=arc-20160816; b=GTeKD/Xc/Js+3b2ld8TOS//bEYSc+qVef0nfz9R7LKpoC37bse2sWNaoFEQWoPA7Iu 7U7K4JDJRBMz0vfn+oYh9f4VrpH5sTD81s2feQK+5GsOw1TIWcehoWSmU/AuWS6iasiZ RU+f0skXcm7Pvb3OafyntJVa8SVHsvTIxkXlWk162y5TXsG3j18l5sL8PncpzxpwtkNt YjhUPB2iZAIurctTk7vOFqbwG9mb0R4lPg/gALU7bqAO5vw5bvt6VqsFO5fVtjnrrnWw gqgdzPKny511fRk/P6XYcduk3MCsaJWew/dPkLQjUY/YU7CTlCAd/mnsD5SzIOpX989r hBPQ== 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=qiK5yVD55/0DU88B8CizACLoX9EwatHrsE3RC+J83z0=; b=VoJGJ07WVznaSXJgFDymILJJCiDE0ceG49dtCIvsORnDEgeM/CGBkKxz8CY9jZO9Rb Tg+kL9stQs4sHr6k4CZmUn2OPOTRewf94659635Ce0Hd9MWbkYhGkcyvUSFE1D+trdvY 31duQ/EwyoJGnmS6I7LLz7gdhT17fhkuaRrwsdEl9q86E++XQ+Xg7IxpklMe9wW0cLjW 3e7tDhOyDDxgZoDwHdxxChg0hMkxO8jwK4ZWISesDUoFjVY157hG6AK7y3zfN9OdPKow 6qrN8TDq6p/8644xJ7tdQPM5r6t6UJT9Ax0WEMyRJ2xbJJO4mz4/Um5dKTBhgGV73rFz jeSQ== 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 h11-20020a056402280b00b004472a202580si5803241ede.220.2022.08.25.06.37.18; Thu, 25 Aug 2022 06:37:43 -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 S241233AbiHYMqM (ORCPT + 99 others); Thu, 25 Aug 2022 08:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234338AbiHYMqL (ORCPT ); Thu, 25 Aug 2022 08:46:11 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 011E74D17E; Thu, 25 Aug 2022 05:46:06 -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 1oRCFC-0002Ci-QW; Thu, 25 Aug 2022 14:45:58 +0200 Message-ID: <3752b74b-74e1-00fd-d80d-41104e07fe95@maciej.szmigiero.name> Date: Thu, 25 Aug 2022 14:45:53 +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> <1062bf85-0d44-011b-2377-d6be1485ce65@amd.com> From: "Maciej S. Szmigiero" Subject: Re: [PATCHv3 5/8] KVM: SVM: Add VNMI support in inject_nmi In-Reply-To: <1062bf85-0d44-011b-2377-d6be1485ce65@amd.com> 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 25.08.2022 12:56, Shukla, Santosh wrote: > On 8/24/2022 6:26 PM, Maciej S. Szmigiero wrote: >> 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. >> > > For L1 with vnmi disabled case - is_vnmi_enabled()->get_vnmi_vmcb() will return false so the > execution path will opt EVTINJ model for re-injection. I guess by "get_vnmi_vmcb() will return false" you mean it will return NULL, since this function returns a pointer, not a bool. I can't see however, how this will happen: >static inline struct vmcb *get_vnmi_vmcb(struct vcpu_svm *svm) >{ > if (!vnmi) > return NULL; ^ "vnmi" variable controls whether L0 uses vNMI, so this variable is true in our case > > if (is_guest_mode(&svm->vcpu)) > return svm->nested.vmcb02.ptr; ^ this should be always non-NULL. So get_vnmi_vmcb() will return VMCB02 pointer in our case, not NULL... > > Thanks, > Santosh > >> 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 ... and due to the above is_vnmi_enabled() will return true, so re-injection will attempt to use vNMI instead of EVTINJ (wrong). >>> 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