Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2920598pxb; Fri, 8 Oct 2021 19:20:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGlzlCREKyEbuM6g+ckWgEI4Omwgw0IDAVkd02UR+iVa+aE4Vxy2Yr3ifsEArhWKQHbfpy X-Received: by 2002:a05:6402:2793:: with SMTP id b19mr20034819ede.80.1633746048181; Fri, 08 Oct 2021 19:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633746048; cv=none; d=google.com; s=arc-20160816; b=yLQLSEmuYNDlT7GvqGxVI8R59Bb/br6j9rSyVVcMv2qtuoxfzXvkb2IfmoBqdjywxS ZAnL7cJNsMc1PxLNsSaaxMyb1+Io+NrBPAW3XwsTHIh+igK/A5rpmXV5qlTNtboispon vMrbtN5BYBZJSON2NqX6l0gmBY7G50zsY/qbutCQR+uYw3UbhHoCojh51hZbrNc22Xpu 6TOoQom+z6L+ZsYL/in3Jm6evbjLW+w/CX5M709+XHar3x76YziXEV7glTq2ACccp6gB soEmzmd3kwNHVYyjUHntwxpDJxsvw+TNA1QxgNq8NZyiOTJmspjaggSlUPzE/f0Oe14G VSiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=vARluonyUKpRy8G9DjKrfNHNdAc1HGSYAf2sHJRtsxE=; b=EH127DNGfN/Ufb5Oe0SAbXQLsL/axLoBoLovpqGtM8QPptmDdOHdjo+VyhWCCRklxP rGUTAP4RnTde7RmJKHdzV2chSd7NzpPlZ9MDM/AogvR75MsxLJVi2y+1IZTCtnDvHVSY B6Md6DTC8IcdlPgVwaGu6gAKKwHOYJenLf2OpvgwhmIWHA0RVj5nGv4RMQCzEBW7+Nug 33Oh795WNRwHkO1FNjpAVy8kYEjpL5WM9F52sDgylaxK5zvaw8i8tphFAi/JC/mPx/mI j+25ER6Ib9LMnM8IXpgeX3R4zuJX8tj2icIc6lhM+u0gJgJqGjaBeEAB/9Lh+9kjTkZR mH4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dDNQpdZf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs6si3217032ejc.12.2021.10.08.19.20.02; Fri, 08 Oct 2021 19:20:48 -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=@google.com header.s=20210112 header.b=dDNQpdZf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244416AbhJICS3 (ORCPT + 99 others); Fri, 8 Oct 2021 22:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244170AbhJICSB (ORCPT ); Fri, 8 Oct 2021 22:18:01 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD67BC061343 for ; Fri, 8 Oct 2021 19:14:08 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id q9-20020ad45749000000b00382b7c83aa1so10309299qvx.11 for ; Fri, 08 Oct 2021 19:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=vARluonyUKpRy8G9DjKrfNHNdAc1HGSYAf2sHJRtsxE=; b=dDNQpdZfL83I4Xoa9PZ3E5EsYnabe1TnFcUqC0GiE/0/lo3YBI4SgbGlytEWdsCvOf LL61F+TPG4wVAi+hBDwL0hYJr0Sf/hDhYBcY7jqTws2bL+a5fPjX5OLlspq9+auO8uLB LlWM6ttM2AIBOgSzLaGHfzimLEgh21na9pO5BUmiCsH43tkGQwDiPq/uFgoyBvKjufM1 qqm6SRzQMrUy4KCFfX/YOo+AIQIUXaJKY/DR/AD2RJh1k/DEWqufdKKiBjO5+vKlBr1h rts7eeL0kCC8yhrzj1lM+laL06N4oAUmGKJnSLoqoH7hEPeImUfW3S7INsYE4a0g/dn5 bbFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=vARluonyUKpRy8G9DjKrfNHNdAc1HGSYAf2sHJRtsxE=; b=mKrl3TQHiKPcnvIRsQoQfApCUo4p2QGL4i064URknB8bebj/sSCIlqtTT2MsVFIfe0 58US6r1P/FKMvJWdQMghWHhAbeIFPD9VsH3TyOHO/swHJei0QzTt4H0bDuWo9PY0WlNp TzTEYWbG/gRYqZxZodEBo6I0X4a45yKRCiVb5iS8ufotDYA0obePLASy7NaiiA2pJsZF dJAh3TKKpUxRMvO2/ztuP6bIcq7rVbU9ZzNq800UkVgzqXSXaLPFgUDprzRRuIf6iexV G7wutw99nbt7XgmKX2RDv0t8WX1gjjJWtnPUDLyJtu5iQ+kdmqhWmJyUatozH9hrmj1m KvxA== X-Gm-Message-State: AOAM532oM7TMXAL8sD9/DxqqRd+okEbIy73aqmVpHWP+qqAHb+QVigXi fxAByF/UkeHPernqc9YCA3AQtm/CCgM= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:ac8:7010:: with SMTP id x16mr1970027qtm.136.1633745647867; Fri, 08 Oct 2021 19:14:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:28 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-36-seanjc@google.com> Mime-Version: 1.0 References: <20211009021236.4122790-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v2 35/43] KVM: SVM: Signal AVIC doorbell iff vCPU is in guest mode From: Sean Christopherson To: 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 , Sean Christopherson , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.33.0.882.g93a45727a2-goog