Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2920792pxb; Fri, 8 Oct 2021 19:21:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUaUEcDWS5GpflzIpabp5pQK80IHkNRe5md0jzBAjbdrOxq7+flZZRiy1/iI3OchaJFJWo X-Received: by 2002:a50:dacf:: with SMTP id s15mr19732825edj.385.1633746069825; Fri, 08 Oct 2021 19:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633746069; cv=none; d=google.com; s=arc-20160816; b=CnYPH4WBoGNlwP+mDtSPpeVm/SaiCb4/PJcAdxoIby5hgG7kKZfvsrlqBJ/C8czkuU IhLu+B4NKx7CM7M7FxkQ4ZhI8bs9YgreGVrBBx6A/Li8Knv94/ifJpO9utqzukQu+1Zv PE0HSip7LKUbaOsAWQl0x1M47EZ3tN7oiI6CUM+J2BeTK3/IGENUfkphD2pSiPPYDQPt 1QxvOuWi5z1DWVYLF+SibK1JbBRq40SAdJXLzeWkeiymqI4HvYajx4UfGRyAM7YZiBvg h6LbqErwRLqp4XEyCUmmeznguqcQeLlp0ojUkYVZdgw5grehwC5ofra33TOpQcWvs8Zy C7Gg== 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=aUX8Y2YLswKDqX/BLpfoyrV2JucXQRAbXeQDlXSPSss=; b=yJ2TSNICC/vJYc5X16+ZJOuzVWgEu99yCRbM4IWC0E9vzS5ql8gC0gWuTy+l7Ag+lG GR9R3P55TJGgdzbeNe6nl7WAFh91Z25wCeCnDzX/TvhZbIuTKMrFYQ4cNh84z4jCrQve Uy+IVP3kc1GuM0S4H+5hQqmKdv51Uara5427VfhWcKrCUyLiC1GSlmV/OdH1X2EO6zdi 60UMDF6b2DBsH3Yv1DBc7zipQLGb2c3sBzyHMhfWcF+TYhgPe+28fan/fcNdyi01XafG EK7hpZbcEBuyUzEvewiNwF7BHORfUsR8bbg2NtHLnuAHvZoz4rz2dx+lyljPEMSXUKwP 8jyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G5MbwU8B; 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 i1si1957593edc.20.2021.10.08.19.20.46; Fri, 08 Oct 2021 19:21:09 -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=G5MbwU8B; 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 S244672AbhJICTM (ORCPT + 99 others); Fri, 8 Oct 2021 22:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244406AbhJICSk (ORCPT ); Fri, 8 Oct 2021 22:18:40 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D97C061770 for ; Fri, 8 Oct 2021 19:14:20 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id f8-20020a2585480000b02905937897e3daso15200611ybn.2 for ; Fri, 08 Oct 2021 19:14:20 -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=aUX8Y2YLswKDqX/BLpfoyrV2JucXQRAbXeQDlXSPSss=; b=G5MbwU8BdaMQMjcxHC7wzAGcbCLg0J9TahLf26928bNhrSUGxee3WK+qIWNauLjJc2 4Xwq4k9z0Bcozkgdo9UuN8pYL/McLuokdYERF6AjYJpP9DVrzz7LcHr5xQ7YSRGHDf83 C4d2MTdybZ7qs6+Hvzz4omoXgx38bBowhcmbmBEmcHJcWdglD0Yhc1MiEuFt9Fw1KjYf IU8Si/NujuJeGl73mPfUyvTbrfWHQuWcYsMeCz7hSroDRTTwybjhxVWqi9JvGgqv6GdE c2z6JfVm7zV7RLMtNOh0ttQMOfVO1eAL7gbGkhhf3GzhLAQDASqkrGGTf6PyZKaDC4wn ItTQ== 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=aUX8Y2YLswKDqX/BLpfoyrV2JucXQRAbXeQDlXSPSss=; b=D8XxxjDva0MszEDTQAxclQ/1WAeaao8+l0hGvubnwmu2lolwm4j+WsNU2zgm+6s/b7 zOWGWt6en4QKPro3z5WXUX2g/X0drXAhGcXdHKH9Rb+uOfpS0yghSP4WRF755wGqJtm+ wrhI9YjPicvguOIrhltUFw8NmrCLjouwxZuSVeCviR3tqq72M0qmgd5iralsDlFVPOIH tSTCtdQSGZ58fe4YlMRYYhONlusEV1HSaPTDRKvUw5In9NqFKUqKvA8t3x/twqi/4Yli 6CqVb9ET+ByxH9HnCVoBhJu0Z2QETUCs38a9Lf/G5FhUMSuYHdb++wm8BXf+glC0fsZv PvrA== X-Gm-Message-State: AOAM532pmNoXsxH8iiL7cmPwxC0iA3k41I/6svQru+uhewmUICirtGuK Tdi0npJ30bUbcgDAi2bzK6fC1rfutvU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:2209:: with SMTP id i9mr7632692ybi.52.1633745659766; Fri, 08 Oct 2021 19:14:19 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:33 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-41-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 40/43] KVM: VMX: Wake vCPU when delivering posted IRQ even if vCPU == this vCPU 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 Drop a check that guards triggering a posted interrupt on the currently running vCPU, and more importantly guards waking the target vCPU if triggering a posted interrupt fails because the vCPU isn't IN_GUEST_MODE. The "do nothing" logic when "vcpu == running_vcpu" works only because KVM doesn't have a path to ->deliver_posted_interrupt() from asynchronous context, e.g. if apic_timer_expired() were changed to always go down the posted interrupt path for APICv, or if the IN_GUEST_MODE check in kvm_use_posted_timer_interrupt() were dropped, and the hrtimer fired in kvm_vcpu_block() after the final kvm_vcpu_check_block() check, the vCPU would be scheduled() out without being awakened, i.e. would "miss" the timer interrupt. One could argue that invoking kvm_apic_local_deliver() from (soft) IRQ context for the current running vCPU should be illegal, but nothing in KVM actually enforces that rules. There's also no strong obvious benefit to making such behavior illegal, e.g. checking IN_GUEST_MODE and calling kvm_vcpu_wake_up() is at worst marginally more costly than querying the current running vCPU. Lastly, this aligns the non-nested and nested usage of triggering posted interrupts, and will allow for additional cleanups. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 44d760dde0f9..78c8bc7f1b3b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4024,8 +4024,7 @@ static int vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector) * guaranteed to see PID.ON=1 and sync the PIR to IRR if triggering a * posted interrupt "fails" because vcpu->mode != IN_GUEST_MODE. */ - if (vcpu != kvm_get_running_vcpu() && - !kvm_vcpu_trigger_posted_interrupt(vcpu, false)) + if (!kvm_vcpu_trigger_posted_interrupt(vcpu, false)) kvm_vcpu_wake_up(vcpu); return 0; -- 2.33.0.882.g93a45727a2-goog