Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3529202pxf; Mon, 15 Mar 2021 11:35:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaKNJvqNBGbmpQ1EDBUM7mJ6iP4NNW+wtI8dBUU+PJGnefpiaSvVIPqPCn/o2SnkRFjyIa X-Received: by 2002:a05:6402:1c98:: with SMTP id cy24mr31533217edb.296.1615833308022; Mon, 15 Mar 2021 11:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833308; cv=none; d=google.com; s=arc-20160816; b=ZEAXc1OC+D+qnQCu74PP8oyX5wWqWB7pgVK6J/HlCJVtORWdcmFtCBvaXA/BDME9wR 91HQgG90T5O4Hy6uKvBKeK4BnS+5bPNd9jyU98xQK+5ETEHs2jtfYV2mD0ylMthGRtuK q/raxVzZEfzEkTAVttyoCp7pGL/zoZulgQQ8lvp10brXU8kdaSsu77xCdT0cKp1HRD4p 5fJE+aJDystCZsnO6NF4eMgusqGHfHsRdw5WVV9LUGrYcwKXhDVBZLyC+xuRla8Io6U3 LTJTG5xHGwcEgq0m24O+CD3KkCz+aIjzQtYKMqHPcQombVUPBp49nBQSAdkK/Bo9K9Yz 8aPQ== 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=hFzBBej8Yh0Edgw/WqB91G+QjECQKrA/hW1i1rTwHQTsJadhvzH5mUh1KNJUn0mvsH QSgzpibCm2r2s1PN9zxKEbL3DIcmxMfdMSsu+vT4AnJba/mzes6fbzLH3U+loIRuV4kh 3lRrueurB0RkjMbEWoVGiHh5QC5Kd2KDwxTHEcTjM5IvROg9wtPNvCiT5sy6QpalgjaT cZCD7Eyx7d3oJAx9QjMD2Uz2cSXM08PTcNtlOC9QlgOqInGNQ2dQvEmCKHPhKiC7zRVr JONd+C51afVmCO1AX0AyFvbA/h33jGsPQHXKM4hnftGxp/kY4BFuOvXvuPTk/znaqZ3I WyzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zR61yK5Z; 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 m13si11466190edd.35.2021.03.15.11.34.45; Mon, 15 Mar 2021 11:35:08 -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=zR61yK5Z; 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 S239145AbhCOOqY (ORCPT + 99 others); Mon, 15 Mar 2021 10:46:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:52902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234632AbhCOOEf (ORCPT ); Mon, 15 Mar 2021 10:04:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C0D764DAD; Mon, 15 Mar 2021 14:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817074; bh=dLggE5UcIHdTZxiVTcRYvG1zoFKMcwZg9ZMurFrMvKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zR61yK5Z0zYeWtMQCZ/K0GDdCq58+s3AYSjBKiL/tUQ4HFYObIotCZYg10eWvWn5U nxIPrDcVWwxFQoFHSS4RLMtI8IW3jqfb9kOaVfUbeKb9jyjdu4Op613fKukMbPJoPX M0M8ufdCl/W7siHYNmNYur/n2SRVB6xdkRvhCKIw= 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.10 276/290] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ Date: Mon, 15 Mar 2021 14:56:09 +0100 Message-Id: <20210315135551.359947615@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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; }