Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp18314pxj; Mon, 17 May 2021 19:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlJts1x9olE3QmoOQZ6yhhHaAahmBBm4KdDSwcw6uSisNcntEo2rRQhPgp7Lc5b3ax38T3 X-Received: by 2002:a02:3304:: with SMTP id c4mr3101112jae.68.1621305706603; Mon, 17 May 2021 19:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621305706; cv=none; d=google.com; s=arc-20160816; b=0pC6OEeLQwLXYFgnp+UoMBrETiyFL25AtRnGs++4XQREkKHVgtvcJLHv1ph9eEmuGZ /6P4rdBKiSfMcecTVD8DCxOpBnLRetI5jox5PhFheHqzZLQlhPurBC7ou6mIfFs6wJgn 2neh5TFXEJHvnWIhZGlK1UFeq2goHzcnhSoz7vGtOYa5+Xu/mDwz1CNzjEX7mO8ymB3o ZWSVrI6d/OfevzRVFo+0GBjZyXO7ovsEZwmSU0wFA/z+arQ7SX06+stYnmDrK8nVFD3I WyiO4oOk/Z2cTeRq/zwzZRHnftaUeflc0NjCHjC7SyxaiYgpVX9TrDdJA+qB3kaSA8Cc XvdA== 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=SWu0rdeUP8wAt2ZsrTV3fK12lzhTyiTp79hpnFhXyss=; b=hV0owgFqhkHcT0rEcQRqrZruBeucyid/TvS/OsL2jCigB6L0fgCZHrSWb5LlD21+HE eq59NJfY39lTlqURB5zFTZztbfUD+fg79UUXrqyLT81fM5LRSnjQyFhCMPcJ9JeqSBK6 c0Xzi9RZtQ9m9iM/P+4hpRFx0UZPZRBO70fSuTFQYivXHXL5mi3tsC1AOTZ3LVcIlkOF EGklKdAUjM7QouS/Lm/R0JDYYUz7/IwqlPMPT8wZZMcFC41aldYigWRO+DPO6DbSvrs3 G4xO5zd8zC7wijXibBhBNn3UuNrlYUd5rqHYp59Rq6sUsT0t+XlgxlF7UFzhgTWPzUZ6 PBDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eylsnsjw; 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 b12si6663502iob.37.2021.05.17.19.41.33; Mon, 17 May 2021 19:41:46 -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=eylsnsjw; 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 S240397AbhEQOiW (ORCPT + 99 others); Mon, 17 May 2021 10:38:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:44958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236839AbhEQOcN (ORCPT ); Mon, 17 May 2021 10:32:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 059FB6190A; Mon, 17 May 2021 14:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260959; bh=0i23hUk+mLVJQ5yE6IVfIrU+/y8lkTiab14ntsBSRcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eylsnsjwsIsx5JrI4Ox9f3dCkhysKEOX71DZmptCKoM1XAi0zgX7MXfw9sSuqQAVm nlmw3A+1q7pWBogJYCqidoJr7Y25dAFgOeOA5IxgKCKiC7p1r1d16XT4oEgKbslxK7 qcqgq7RyRO83rEfQMy83YjoUkXoht/o8VJF1SIIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Wanpeng Li , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.12 275/363] KVM: LAPIC: Accurately guarantee busy wait for timer to expire when using hv_timer Date: Mon, 17 May 2021 16:02:21 +0200 Message-Id: <20210517140311.915606478@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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: Wanpeng Li [ Upstream commit d981dd15498b188636ec5a7d8ad485e650f63d8d ] Commit ee66e453db13d (KVM: lapic: Busy wait for timer to expire when using hv_timer) tries to set ktime->expired_tscdeadline by checking ktime->hv_timer_in_use since lapic timer oneshot/periodic modes which are emulated by vmx preemption timer also get advanced, they leverage the same vmx preemption timer logic with tsc-deadline mode. However, ktime->hv_timer_in_use is cleared before apic_timer_expired() handling, let's delay this clearing in preemption-disabled region. Fixes: ee66e453db13d ("KVM: lapic: Busy wait for timer to expire when using hv_timer") Reviewed-by: Sean Christopherson Signed-off-by: Wanpeng Li Message-Id: <1619608082-4187-1-git-send-email-wanpengli@tencent.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 49a839d0567a..fa023f3feb25 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1913,8 +1913,8 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) if (!apic->lapic_timer.hv_timer_in_use) goto out; WARN_ON(rcuwait_active(&vcpu->wait)); - cancel_hv_timer(apic); apic_timer_expired(apic, false); + cancel_hv_timer(apic); if (apic_lvtt_period(apic) && apic->lapic_timer.period) { advance_periodic_target_expiration(apic); -- 2.30.2