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=-3.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 1EC56C282DA for ; Wed, 17 Apr 2019 17:15:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5602206BA for ; Wed, 17 Apr 2019 17:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732832AbfDQRPf (ORCPT ); Wed, 17 Apr 2019 13:15:35 -0400 Received: from mga12.intel.com ([192.55.52.136]:3647 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729395AbfDQRPf (ORCPT ); Wed, 17 Apr 2019 13:15:35 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2019 10:15:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,362,1549958400"; d="scan'208";a="150220069" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.181]) by FMSMGA003.fm.intel.com with ESMTP; 17 Apr 2019 10:15:35 -0700 From: Sean Christopherson To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: kvm@vger.kernel.org, Liran Alon , Wanpeng Li Subject: [PATCH v4 0/4] KVM: lapic: Fix a variety of timer adv issues Date: Wed, 17 Apr 2019 10:15:30 -0700 Message-Id: <20190417171534.10385-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KVM's recently introduced adaptive tuning of lapic_timer_advance_ns has several critical flaws: - The advancement is completely unbounded, e.g. there's nothing in the logic that prevents the advancement from creeping up to hundreds of milliseconds in case something goes awry with the guest's TSC. - TSC scaling is done on a per-vCPU basis, while the advancement value is global. This issue is also present without adaptive tuning, but is now more pronounced. - Tuning the value concurrently on multiple CPUs can corrupt the advancement variable. - Userspace can't disable adaptive tuning. Fix the above issues along with a theoretical bug found by inspenction, where the wait_lapic_timer() delay could be inaccurate when the guest TSC is running at a different ratio than the host's TSC. v4: - Rebase to latest kvm/queue. - Kill the timer advancement if adaptive tuning goes above the abrbitrary threshold of 5000ns. [Paolo]. - Revert back to disabling adaptive tuning via the existing param, except use '-1' as the "use adaptive tuning" indicator. [Paolo]. - Do the conversion to nanoseconds when delaying iff the guest TSC is running at a different ratio, and move the patch to the end so that the other patches are not dependent on it since it's not 100% clear (to me) that the conversion is correct/necessary. v3: - https://patchwork.kernel.org/cover/10904163/ - Split the refactoring of start_hv_timer() and ->set_hv_timer into three separate patches instead of attempting to do a big refactor in a single patch to fix three separate issues. - Explicitly cancel the hv timer to avoid - Use a param for "expired" instead of overloading the return value of ->set_hv_timer(). - Check for a pending non-periodic in restart_apic_timer(). [Liran] - Add more Reviewed-by tags. v2: - https://patchwork.kernel.org/cover/10903613/ - Add explicit param to control automatic tuning. [Liran] - Document the effect of per-vCPU tracking on the module params. - Use fancy math to convert guest clockcycles to host nanoseconds instead of brute forcing the delay with a for loop. [Liran] - Refactor start_hv_timer()'s return semantics to move the "expired timer" handling up a level. [Liran and Paolo] - Add Liran's Reviewed-by tags. v1: https://patchwork.kernel.org/cover/10899101/ Sean Christopherson (4): KVM: lapic: Disable timer advancement if adaptive tuning goes haywire KVM: lapic: Track lapic timer advance per vCPU KVM: lapic: Allow user to disable adaptive tuning of timer advancement KVM: lapic: Convert guest TSC to host time domain if necessary arch/x86/kvm/lapic.c | 61 +++++++++++++++++++++++++++++++----------- arch/x86/kvm/lapic.h | 4 ++- arch/x86/kvm/vmx/vmx.c | 4 ++- arch/x86/kvm/x86.c | 14 ++++++---- arch/x86/kvm/x86.h | 2 -- 5 files changed, 61 insertions(+), 24 deletions(-) -- 2.21.0