From patchwork Thu Dec 3 17:11:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11949163 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=-12.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 D9508C0018C for ; Thu, 3 Dec 2020 17:13:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53F9E207AE for ; Thu, 3 Dec 2020 17:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728633AbgLCRN0 (ORCPT ); Thu, 3 Dec 2020 12:13:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53421 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501942AbgLCRNY (ORCPT ); Thu, 3 Dec 2020 12:13:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607015518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zaqAemO/Fsujg9r8lt/SFqF1ctdGuOQUqsO5lgI9LxY=; b=eapRq1a/cEDgA0rlGekknwtGedJqPGEcwuF08WAje/e7/Q0c3mCr2p3nHuSAtCYk7tch61 vhOX38J70DdI2K/Wv6dDcdeCyaAqbTKitwotK8HCJQAhKsnLYRIYwpARxIw9e4JZ7ETzDm LvrKY4WFdLnX03Mxtp+LYPVjFFyfvtg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-6I46_4btNSS0GSJXwwek_Q-1; Thu, 03 Dec 2020 12:11:55 -0500 X-MC-Unique: 6I46_4btNSS0GSJXwwek_Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51CEC180A089; Thu, 3 Dec 2020 17:11:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2475A6F963; Thu, 3 Dec 2020 17:11:19 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: "H. Peter Anvin" , Paolo Bonzini , Jonathan Corbet , Jim Mattson , Wanpeng Li , linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), Vitaly Kuznetsov , Marcelo Tosatti , Thomas Gleixner , Sean Christopherson , linux-kernel@vger.kernel.org (open list), Ingo Molnar , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Joerg Roedel , Borislav Petkov , Shuah Khan , Maxim Levitsky , Andrew Jones , Oliver Upton , linux-doc@vger.kernel.org (open list:DOCUMENTATION) Subject: [PATCH v2 0/3] RFC: Precise TSC migration Date: Thu, 3 Dec 2020 19:11:15 +0200 Message-Id: <20201203171118.372391-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi! This is the second version of the work to make TSC migration more accurate, as was defined by Paulo at: https://www.spinics.net/lists/kvm/msg225525.html I omitted most of the semi-offtopic points I raised related to TSC in the previous RFC where we can continue the discussion. I do want to raise another thing that I almost forgot. On AMD systems, the Linux kernel will mark the guest tsc as unstable unless invtsc is set which is set on recent AMD hardware. Take a look at 'unsynchronized_tsc()' to verify this. This is another thing that IMHO should be fixed at least when running under KVM. Note that I forgot to mention that X86_FEATURE_TSC_RELIABLE also short-circuits this code, thus giving another reason to enable it under KVM. Changes from V1: - added KVM_TSC_STATE_TIMESTAMP_VALID instead of testing ns == 0 - allow diff < 0, because it is still better that capping it to 0 - updated tsc_msr_test unit test to cover this feature - refactoring Patches to enable this feature in qemu are in the process of being sent to qemu-devel mailing list. Best regards, Maxim Levitsky Maxim Levitsky (3): KVM: x86: implement KVM_{GET|SET}_TSC_STATE KVM: x86: introduce KVM_X86_QUIRK_TSC_HOST_ACCESS kvm/selftests: update tsc_msrs_test to cover KVM_X86_QUIRK_TSC_HOST_ACCESS Documentation/virt/kvm/api.rst | 65 +++++++++++++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 92 ++++++++++++++++++- include/uapi/linux/kvm.h | 15 +++ .../selftests/kvm/x86_64/tsc_msrs_test.c | 79 ++++++++++++++-- 5 files changed, 237 insertions(+), 15 deletions(-)