Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1744325pxb; Thu, 28 Oct 2021 09:15:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycN4yOVozlFVXCmh8+WOjVizDhg4uZbK0k9cuRNJtQbu8Wr38RsAUdZTdb6OsOi8xvDF7g X-Received: by 2002:a05:6a00:b46:b0:47b:f401:d76a with SMTP id p6-20020a056a000b4600b0047bf401d76amr5174534pfo.47.1635437721613; Thu, 28 Oct 2021 09:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635437721; cv=none; d=google.com; s=arc-20160816; b=tSty8FsuQaKr3SDGXTAFH7be3csDXjMLmbX1pqMoRr8UWVtJGT0fKoI7y/LrQgsM65 WxgWzyHmBISTySvswIiwKD+Cr0iVcZ+ZprVggthiu30XTPUtoS8TCyDvYN+wkUmEElEN JEDUij4a55ns3ujftZnAZWp1orN8kUZLoe5NK8WpWf65EjGJRkuyLKjq1MwGvubALO7s l7Q0cRTv40pGf71Wz5dgyuoLaRXHaxzlicz6KDwzN+v063dIIMYVBJT7yIHZ4hw+aNpN v8QDOqqjBRiMqi0IBBaiS3OzGa9p51cxPVqIeic7Ic43f5TY2aQ1Ezc2g7Z3lJxXJ6C7 ez5g== 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=MqVw0Z8vi7JjvCVtjxAexVsSznKzCGLBzzaPnc6KX/k=; b=znUgcTKMir6vb9+PKLcu1cRC6S7lxM8ReFH2/DK1E1Vgz5RmHOYqLnQ9AdD+FyouHY x3Ap8aZ9iFLgo60n4h6/Lw39U+7sH0y53y+1NmoCzgK+7WYUTTUIQd2c9LRCCooy+qCi dmz6hW3wFrrGloY56lCyjeYOmCKmbWOT7DfeGybLbksEew7eLSY/4LjU0/uD81V6ymYY qxCNa2se8p78SBhpvD9lQDTA0GXV4OLvCzp070wyiKRQK6i2GoSKaTtmNbsI5pC3tXB2 fzkTrW3e8/93tBFCGfv3hOswkVRu85OU1bHDAfwbggcjH/DoJEIbENqw9W6HJYC1FG9W /AFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DcGeE5aj; 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 m4si5191725pfk.76.2021.10.28.09.15.02; Thu, 28 Oct 2021 09:15:21 -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=DcGeE5aj; 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 S230248AbhJ1QPf (ORCPT + 99 others); Thu, 28 Oct 2021 12:15:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46808 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbhJ1QPd (ORCPT ); Thu, 28 Oct 2021 12:15:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635437586; 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=MqVw0Z8vi7JjvCVtjxAexVsSznKzCGLBzzaPnc6KX/k=; b=DcGeE5ajlUqoCuTtu9dQxp5GHJ9Zj4uNGnYldZ6OSY8VBRVQfZW0SfDRcV6PMxLVtQR93J QhPs4rJVYEdHdtIa4/G8Fh69ucrkfyrrYS3aGEZmc3v6kB2TVM+7u0T12q/s1DVNFOyhZH gwi8ioJhreoia23cpxG+CuPek8CkqXQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-R1OcEdtCNRy5fjOQqmfJWg-1; Thu, 28 Oct 2021 12:13:00 -0400 X-MC-Unique: R1OcEdtCNRy5fjOQqmfJWg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 594BC112A0A3; Thu, 28 Oct 2021 16:12:14 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBDF84180; Thu, 28 Oct 2021 16:12:05 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 35/43] KVM: SVM: Signal AVIC doorbell iff vCPU is in guest mode From: Maxim Levitsky To: Sean Christopherson , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang Date: Thu, 28 Oct 2021 19:12:04 +0300 In-Reply-To: <20211009021236.4122790-36-seanjc@google.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-36-seanjc@google.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.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-10-08 at 19:12 -0700, Sean Christopherson wrote: > Signal the AVIC doorbell iff the vCPU is running in the guest. If the vCPU > is not IN_GUEST_MODE, it's guaranteed to pick up any pending IRQs on the > next VMRUN, which unconditionally processes the vIRR. > > Add comments to document the logic. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/svm/avic.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index 208c5c71e827..cbf02e7e20d0 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -674,7 +674,12 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) > kvm_lapic_set_irr(vec, vcpu->arch.apic); > smp_mb__after_atomic(); > > - if (avic_vcpu_is_running(vcpu)) { > + /* > + * Signal the doorbell to tell hardware to inject the IRQ if the vCPU > + * is in the guest. If the vCPU is not in the guest, hardware will > + * automatically process AVIC interrupts at VMRUN. > + */ > + if (vcpu->mode == IN_GUEST_MODE) { > int cpu = READ_ONCE(vcpu->cpu); > > /* > @@ -687,8 +692,13 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) > if (cpu != get_cpu()) > wrmsrl(SVM_AVIC_DOORBELL, kvm_cpu_get_apicid(cpu)); > put_cpu(); > - } else > + } else { > + /* > + * Wake the vCPU if it was blocking. KVM will then detect the > + * pending IRQ when checking if the vCPU has a wake event. > + */ > kvm_vcpu_wake_up(vcpu); > + } > > return 0; > } It makes sense indeed to avoid ringing the doorbell when the vCPU is not in the guest mode. I do wonder if we want to call kvm_vcpu_wake_up always otherwise, as the vCPU might be just outside of the guest mode and not scheduled out. I don't know how expensive is kvm_vcpu_wake_up in this case. Before this patch, the avic_vcpu_is_running would only be false when the vCPU is scheduled out (e.g when vcpu_put was done on it) Best regards, Maxim Levitsky