Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528909pxf; Mon, 15 Mar 2021 11:34:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIzvbHT1OCceSTApOQZTDZxSwswFLAl3/QBAaXMFd62kIUtGl74LDwwK+nJpy/0PedYDMC X-Received: by 2002:a17:907:76b6:: with SMTP id jw22mr25095213ejc.11.1615833283902; Mon, 15 Mar 2021 11:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833283; cv=none; d=google.com; s=arc-20160816; b=DU3XO6fjarvzGp0NTA72cBHtNQLzi2kuUw9cWNpvI6woaE4TFTHgEeGzTllmj+K74M j/p6tZZ7OIiLjU2Iujvx0hdTVoiNGGOe3/zT/KNNIm4b0lPGxnkgkQk/XlUe3tIdBqtX KnKQh8EfbowxptOFwoQfPrzpob9d6Jv6zjV0wcnHwXLsDPS2c2rpLIWL5cG/kU2rDbtG KsWbMNkxgq/0fRJqZ37+GfKTh8aa6EQKAgLZMdCTxzIkI+A1RWSrIkdWsy0n1+C0/M3P 9Ww0P4PxkD78IQ1y55MIyiPFnpYnXpRFjxB6UNS7tCzL4vJvm/5HeKctqOuiknXIydgM 23Yw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=vYx/GKZJtZ2kY6bzxDgdP8vlzYC87dw+Znbn5wNmDmw=; b=U8zqfUmM/DYeq24DorqJygMOjAPBVmVKVP+y9dwGGvL+yR8xWI3ldsxs1JtPMOqhdj peH2kAbn02fy6pbctXgM+t62p97j2sYYiV6RKJGJwmolRJLKpWnu+FZhFiqCo9w2yhh+ aGuae5eWJUZyMkCQKvGPL7hmgyYVQFjGzP3UbP6Or8rdp2p+ph1cItAzHOHKW7aVFV8U 9tF21TVja5VTmmrp5lHAO7RfajKrpBqZIK2hvvf8G9JdjEp20+bCMM/xohhtJN456YGD ZVuV2kcpQxQXLSgXYSNUBe4voaVSYAl/Zolu9PZ9zfRX+PflpCjD2P+YyxCv5TaR0j2T JFJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1ORzIRsA; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si11261734edr.381.2021.03.15.11.34.21; Mon, 15 Mar 2021 11:34:43 -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=@linuxfoundation.org header.s=korg header.b=1ORzIRsA; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239469AbhCOOrA (ORCPT + 99 others); Mon, 15 Mar 2021 10:47:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbhCOOEp (ORCPT ); Mon, 15 Mar 2021 10:04:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 88AE864EFD; Mon, 15 Mar 2021 14:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817084; bh=dLggE5UcIHdTZxiVTcRYvG1zoFKMcwZg9ZMurFrMvKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ORzIRsAQjtwyEIy+HbiRzbowW9d2nGht4MqlvvTaTyrKBMbyQBAbUQNIfy6c0Pqp hHEQbhkeYxm/Df6wLK7LYpd+ZGgeyIyHmRpUdUu6HAOJjl0ZtquBKk1diqBWN8JxCX 4RxgaQXX4fXgDLhby/aDvei1hiGXlmdqKzrcgt+E= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.11 292/306] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ Date: Mon, 15 Mar 2021 14:55:55 +0100 Message-Id: <20210315135517.556638562@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Sean Christopherson commit beda430177f56656e7980dcce93456ffaa35676b upstream. When posting a deadline timer interrupt, open code the checks guarding __kvm_wait_lapic_expire() in order to skip the lapic_timer_int_injected() check in kvm_wait_lapic_expire(). The injection check will always fail since the interrupt has not yet be injected. Moving the call after injection would also be wrong as that wouldn't actually delay delivery of the IRQ if it is indeed sent via posted interrupt. Fixes: 010fd37fddf6 ("KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20210305021808.3769732-1-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1641,7 +1641,16 @@ static void apic_timer_expired(struct kv } if (kvm_use_posted_timer_interrupt(apic->vcpu)) { - kvm_wait_lapic_expire(vcpu); + /* + * Ensure the guest's timer has truly expired before posting an + * interrupt. Open code the relevant checks to avoid querying + * lapic_timer_int_injected(), which will be false since the + * interrupt isn't yet injected. Waiting until after injecting + * is not an option since that won't help a posted interrupt. + */ + if (vcpu->arch.apic->lapic_timer.expired_tscdeadline && + vcpu->arch.apic->lapic_timer.timer_advance_ns) + __kvm_wait_lapic_expire(vcpu); kvm_apic_inject_pending_timer_irqs(apic); return; }