From patchwork Wed Apr 28 11:08:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 12228539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAE07C433B4 for ; Wed, 28 Apr 2021 11:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 869B561429 for ; Wed, 28 Apr 2021 11:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238305AbhD1LI7 (ORCPT ); Wed, 28 Apr 2021 07:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239648AbhD1LIz (ORCPT ); Wed, 28 Apr 2021 07:08:55 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED36C061574; Wed, 28 Apr 2021 04:08:10 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id c3so24720259pfo.3; Wed, 28 Apr 2021 04:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sLpoIH+yhyALQFTgQocCci8bsTG3D7jmg/76ZkWjRcY=; b=dpwXpyq3mY3XQ/cbopkDD6jheZvyXHH6oeT2KuE8ukVbHVlj940j0PSiy+9xFf9xsh +NNRap1mP+dfKzOY1wZpB+MXHl14qTGu29zkTdUjG/9YHWH28q50wsevtiSHsRjZorkp TBidwdOjaxRWuGrrBR2WMAHr/hYZRMm4OVYcfrWZfYnhK6qdSLLniHMS7UoT6f1IU1WC EzEFS8iidL21YpS0nUD+WLjHvuXCCQFbUuYtw0PctqOWcZndxuKU604QfncYs5H+ik17 F0z3l2U+DwwnQKsqNKCYHe1ZCgd2WqzmA04SkOUAYz7xZR5HkaDsfztOhENb2tbqAoGm 9b8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sLpoIH+yhyALQFTgQocCci8bsTG3D7jmg/76ZkWjRcY=; b=J9V1vGPHVbYRmUi+52GFCxgGznh7ZnI/kPaHDwgaL3ARZvrO+aDhDbXUaKMwkFFKN9 t5L+0gnrhVBwmk1hrWAfJlFuysKQ9tsnE+Pnx6c3rR75oDSTY82TN6251ZfQnBMfUXw6 0Qbuv64S/kkc8Bn75M5vwWqeRJifFZgrPat7UKjVI8+r0IaX3yMKMUouVwwitlvcBAIJ /C95Id1DZ6CbQNF2lrln3xC1NyQgz68KJS8DiDWNcFM3X6L8t4PSy0s722quJT0tnphz mY+jsNRc4Rgz8D2CznqU7zN0i1aBbGBv7WmShvt82V9jQ9JDJIfRG0gAg7fkenCN3dnJ BweQ== X-Gm-Message-State: AOAM530TzsiLtGc0L+wXj80u5QErXaoQVj6H4CLel1rVVi0kFAY8mUFs aMpLBLnQ0HJHYLjB+oUcQRVZCIuP300= X-Google-Smtp-Source: ABdhPJzgUYS5opVQrXuZN/v6IrlJrCS4wl7W8ENluYVVshJoupHTYPqxcKawOAAerM7DT8BRVj3gKg== X-Received: by 2002:a63:d942:: with SMTP id e2mr26479270pgj.117.1619608089738; Wed, 28 Apr 2021 04:08:09 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id z17sm4738423pfe.181.2021.04.28.04.08.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Apr 2021 04:08:09 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: [PATCH] KVM: LAPIC: Accurately guarantee busy wait for timer to expire when using hv_timer Date: Wed, 28 Apr 2021 19:08:02 +0800 Message-Id: <1619608082-4187-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li 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) Cc: Sean Christopherson Signed-off-by: Wanpeng Li Reviewed-by: Sean Christopherson --- 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 152591f..c0ebef5 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);