Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3480556ybz; Mon, 4 May 2020 03:57:23 -0700 (PDT) X-Google-Smtp-Source: APiQypKEzDtKns3fTWJwqCTrRaH/khiUemxidfjomLiGJaDr+tLO1QdENfsp8oM1/dBwH/foVDnG X-Received: by 2002:a50:eb0a:: with SMTP id y10mr1328524edp.312.1588589842911; Mon, 04 May 2020 03:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588589842; cv=none; d=google.com; s=arc-20160816; b=0u9hv3ngmorYlKNmOHFOOUv6nPP6V7g17n1vyd2ejaX9RaaB/kCfGaC4+02Jp7YQb+ wnTnMIgHFGkUm4Y+Yt0q+gMB3CZvKT0uuQqHH8IonGN2NZ0YDeUvFQzOMJI5UWTxI+uH HI+TtlSxOB/y/iIrpqjWU75mfZmWJoPr7b0ccck7HSy6Tad/0h+fLnTqKs2IsqFh+5Qr g1Hdyk2NNlQ8sAEOCGleRk0e84xVR/47OXyq/bVIMCzinXaHBZfyps4EXQlofL6THLQr rmqWVkWbfJSaCvBvR0HWS/XcAxqvpPvxpeMrSy3FWU484IDZLKJShA+QUYctblni8orZ bHDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=nN1gwhKlafwwpra/2V+AF/XlCAPHGrwuEYLMMDNzEYY=; b=ux2GEIv9ns5fqV7sJiC4HynSP1uQ4lwCrU/t4+vJmVIu2OPTb2OC+/KzQjiLzd8zeh KWfuQhYgKYbAZZK+TlFyyWWYjRxLKdAUW3lyfhK1ULTtplTSk2kAYrqP/tmsqC75gIIy LIXTcYbWXIGh97rno7wgv0xICkZrijds4wSxBYfkl/n9RSAYjLPpqbtXnOWKBtHyyFTB W8PBZoQMqdRN8/Q+q1KtbBkMBi4YbKnwHvQqtcrjeOFYb17MyVu8k6vgf5g7XUQ2LDem 77tTFbpQmfH1FVwgqfBISEN2pI8AKlNqARLy8Lksbqw2l1qEGSesVHhhF/jIKVSku/xV DFSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QBsHgtSP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si6363135eja.355.2020.05.04.03.57.00; Mon, 04 May 2020 03:57:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QBsHgtSP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728169AbgEDKte (ORCPT + 99 others); Mon, 4 May 2020 06:49:34 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:33960 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726445AbgEDKte (ORCPT ); Mon, 4 May 2020 06:49:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588589372; 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=nN1gwhKlafwwpra/2V+AF/XlCAPHGrwuEYLMMDNzEYY=; b=QBsHgtSPWIKcb2ZadgeAKThuNRl/QVxphPcq0uQuC6TCkD29Xb0gq7PUsAz0zAw3me1AUD N+51FSrTrmbcWZ29sahl8HDDy9zB44ak4UzpSE2viqjaMjhnJ6Mbf0Mq8Y5TTo5wpuEKhj floL2KYiuYRQ+/86S+GwH7etDC4a/m4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-255-UVnvHHm7Onq7BanzxqSb-g-1; Mon, 04 May 2020 06:49:28 -0400 X-MC-Unique: UVnvHHm7Onq7BanzxqSb-g-1 Received: by mail-wr1-f71.google.com with SMTP id v17so5723717wrq.8 for ; Mon, 04 May 2020 03:49:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nN1gwhKlafwwpra/2V+AF/XlCAPHGrwuEYLMMDNzEYY=; b=kWYZzgL0DPnUT5Olj8ypajDLc8sUn9YsR201EyARk31J2ROxr93C76guBBhyv6r2Vq 42wP+kj08n+xbpyu2mbP8aAvciQVput6+whLvzY7oU2feT43Ti1O2kV2zPYP04TmKNxM yw2U4L8rTDeMYr82e5IkiSSM1PkEjFv7fjJIKtXhhQ0p69hG6FIJ5ybaM/Oto8rt0IM9 xNk+PsfJgLwqru533y62E8I+fWWQ/E/juVw5poLRbcdl8VfJvvgCj4+9lQCpr5U6/JD3 jLR9zPwpiLLVgMSDmv4UX7Hb5i3e2AnfCllGANSmDiJDnuJHBJ0HmXGgkyXozG9ZP/eh j2gA== X-Gm-Message-State: AGi0PubL81rKh6wWkQbY9CTrTnCYMVnVwG2Z8X6w/7vK6BC8ocOCDpQd tMg42dUa9zx28YsQqS+oT5gMeWBCSRZhD9ascpP6l8l5VgrHOBp65L57GM8I9W7P9VUtjfmSzLP Wz2eajVxOZBt1s/t0A777gHTo X-Received: by 2002:a05:6000:85:: with SMTP id m5mr8682230wrx.281.1588589367644; Mon, 04 May 2020 03:49:27 -0700 (PDT) X-Received: by 2002:a05:6000:85:: with SMTP id m5mr8682203wrx.281.1588589367364; Mon, 04 May 2020 03:49:27 -0700 (PDT) Received: from [192.168.178.58] ([151.20.132.175]) by smtp.gmail.com with ESMTPSA id b66sm13671732wmh.12.2020.05.04.03.49.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2020 03:49:26 -0700 (PDT) Subject: Re: AVIC related warning in enable_irq_window To: Suravee Suthikulpanit , Maxim Levitsky , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org References: <9ce7bb5c4fb8bcc4ac21103f7534a6edfcbe195d.camel@redhat.com> <758b27a8-74c0-087d-d90b-d95faee2f561@redhat.com> <159382e7fdf0f9b50d79e29554842289e92e1ed7.camel@redhat.com> From: Paolo Bonzini Message-ID: <23b0dfe5-eba4-136b-0d4a-79f57f8a03ff@redhat.com> Date: Mon, 4 May 2020 12:49:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/05/20 12:37, Suravee Suthikulpanit wrote: > Paolo / Maxim, > > On 5/4/20 4:25 PM, Paolo Bonzini wrote: >> On 04/05/20 11:13, Maxim Levitsky wrote: >>> On Mon, 2020-05-04 at 15:46 +0700, Suravee Suthikulpanit wrote: >>>> Paolo / Maxim, >>>> >>>> On 5/2/20 11:42 PM, Paolo Bonzini wrote: >>>>> On 02/05/20 15:58, Maxim Levitsky wrote: >>>>>> The AVIC is disabled by svm_toggle_avic_for_irq_window, which calls >>>>>> kvm_request_apicv_update, which broadcasts the >>>>>> KVM_REQ_APICV_UPDATE vcpu request, >>>>>> however it doesn't broadcast it to CPU on which now we are >>>>>> running, which seems OK, >>>>>> because the code that handles that broadcast runs on each VCPU >>>>>> entry, thus >>>>>> when this CPU will enter guest mode it will notice and disable the >>>>>> AVIC. >>>>>> >>>>>> However later in svm_enable_vintr, there is test >>>>>> 'WARN_ON(kvm_vcpu_apicv_active(&svm->vcpu));' >>>>>> which is still true on current CPU because of the above. >>>>> >>>>> Good point!  We can just remove the WARN_ON I think.  Can you send >>>>> a patch? >>>> >>>> Instead, as an alternative to remove the WARN_ON(), would it be >>>> better to just explicitly >>>> calling kvm_vcpu_update_apicv(vcpu) to update the apicv_active flag >>>> right after >>>> kvm_request_apicv_update()? >>>> >>> This should work IMHO, other that the fact kvm_vcpu_update_apicv will >>> be called again, >>> when this vcpu is entered since the KVM_REQ_APICV_UPDATE will still >>> be pending on it. >>> It shoudn't be a problem, and we can even add a check to do nothing >>> when it is called >>> while avic is already in target enable state. >> >> I thought about that but I think it's a bit confusing.  If we want to >> keep the WARN_ON, Maxim can add an equivalent one to svm_vcpu_run, which >> is even better because the invariant is clearer. >> >> WARN_ON((vmcb->control.int_ctl & (AVIC_ENABLE_MASK | V_IRQ_MASK)) >>     == (AVIC_ENABLE_MASK | V_IRQ_MASK)); >> >> Paolo >> > > Quick update. I tried your suggestion as following, and it's showing the > warning still. > I'll look further into this. Ok, thanks. By the way, there is another possible cleanup: the clearing of V_IRQ_MASK can be removed from interrupt_window_interception since it has already called svm_clear_vintr. Paolo >  arch/x86/kvm/svm/svm.c | 20 +++++++++++++------- >  1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 2f379ba..142c4b9 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -1368,9 +1368,6 @@ static inline void svm_enable_vintr(struct > vcpu_svm *svm) >  { >         struct vmcb_control_area *control; > > -       /* The following fields are ignored when AVIC is enabled */ > -       WARN_ON(kvm_vcpu_apicv_active(&svm->vcpu)); > - >         /* >          * This is just a dummy VINTR to actually cause a vmexit to happen. >          * Actual injection of virtual interrupts happens through EVENTINJ. > @@ -3322,6 +3319,11 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) >                 vcpu->arch.apic->lapic_timer.timer_advance_ns) >                 kvm_wait_lapic_expire(vcpu); > > +//SURAVEE > +       WARN_ON((svm->vmcb->control.int_ctl & > +                (AVIC_ENABLE_MASK | V_IRQ_MASK)) > +                == (AVIC_ENABLE_MASK | V_IRQ_MASK)); > + > > Suravee >