Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp649066pxu; Thu, 3 Dec 2020 09:15:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGzMf4OjL7n5ueMcDtf1gmdARrhJMqDNu0IXT+9DK+8rKU0CZ9QbhBBszXTDdxkDcnqQbu X-Received: by 2002:a05:6402:1c96:: with SMTP id cy22mr3721289edb.339.1607015715367; Thu, 03 Dec 2020 09:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607015715; cv=none; d=google.com; s=arc-20160816; b=HvXSjqJzx7hAgV8I9LbvSt+Hv2ijGZlZmfvWOpg3z2y4PGZUowTN0YwKdvK4SRVHOX nBX0b1PtZrwisTvYgNzZpgx2eKDscABnwtHrb5IJHfCcor+5sSUFSVFBki+iwifnXSv7 Xxw7uImwyKUjX/VX++JocevDMGbpIaYew8RFT82ZtA4KSaMqsdTer13AQrmcYVmhRImE cNNFZ2nBAsx5fOVWlH5hf4pNXjHvTtNv/C9g68fBNM9DyzcuY445OqByHMVPLLfABqel 0gm3aad1Jb1UREm9Fxr9kPgyf6JvVgKyHrv56nNqlRcIrAi/OABd4dYgLpDQZwLc+XEy 6/Lg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zaqAemO/Fsujg9r8lt/SFqF1ctdGuOQUqsO5lgI9LxY=; b=Br2+NgUJTxuSP1UtwmZlALn+hRbR9C9TyN9K5gahEh6hIGvhGROJBbLrBpgjOdSpj5 k6X8HsFbI8nqZ7b/LFhaOsVRCJI32aVs9Lnn5BG3ZgIOaVbF7Zh7un4dhA8oIqtUbV0I cDq+vZW6VKjfhogqElMJpHfauA6A7z526PO7lDR9NZhf0Q5dReYJgP+03rkZiPVJGYw9 6d+aLfiy/o45s6zfXYqjoug66ANiJfQCYZKN2sPcYC1NG5KHmFf+ayBQ1OZvajL/K1Or s/EwWys35djJZA7TnSOZ6H2iUL6mJmXUGxbEUiBEPQXanL7pd5wgSXhNdRlYGNYO5wGl e/7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ADArdz4S; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si1299503edt.481.2020.12.03.09.14.52; Thu, 03 Dec 2020 09:15:15 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=ADArdz4S; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2501943AbgLCRNY (ORCPT + 99 others); Thu, 3 Dec 2020 12:13:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28497 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728633AbgLCRNX (ORCPT ); Thu, 3 Dec 2020 12:13:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607015517; 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=ADArdz4STVkVdvCwpuY2nBKbYTOFKUGwVYg3ryoZEKvXpFZELwOERnQRC+vfhg1HxYGk7x EM8uDEgWcVA53IFNHOg1SM8NoYK5wYoU/ZThhRmQ5al1uQNtgZUgeOWusjpj3pIyoVZ8Ok 2fncSz9PH4EuhwyKSOzWRllHjNNk5Qs= 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 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi!=0D =0D This is the second version of the work to make TSC migration more accurate,= =0D as was defined by Paulo at:=0D https://www.spinics.net/lists/kvm/msg225525.html=0D =0D I omitted most of the semi-offtopic points I raised related to TSC=0D in the previous RFC where we can continue the discussion.=0D =0D I do want to raise another thing that I almost forgot.=0D =0D On AMD systems, the Linux kernel will mark the guest tsc as=0D unstable unless invtsc is set which is set on recent AMD=0D hardware.=0D =0D Take a look at 'unsynchronized_tsc()' to verify this.=0D =0D This is another thing that IMHO should be fixed at least when=0D running under KVM.=0D =0D Note that I forgot to mention that=0D X86_FEATURE_TSC_RELIABLE also short-circuits this code,=0D thus giving another reason to enable it under KVM.=0D =0D Changes from V1:=0D =0D - added KVM_TSC_STATE_TIMESTAMP_VALID instead of testing ns =3D=3D 0=0D - allow diff < 0, because it is still better that capping it to 0=0D - updated tsc_msr_test unit test to cover this feature=0D - refactoring=0D =0D Patches to enable this feature in qemu are in the process of=0D being sent to qemu-devel mailing list.=0D =0D Best regards,=0D Maxim Levitsky=0D =0D Maxim Levitsky (3):=0D KVM: x86: implement KVM_{GET|SET}_TSC_STATE=0D KVM: x86: introduce KVM_X86_QUIRK_TSC_HOST_ACCESS=0D kvm/selftests: update tsc_msrs_test to cover=0D KVM_X86_QUIRK_TSC_HOST_ACCESS=0D =0D Documentation/virt/kvm/api.rst | 65 +++++++++++++=0D arch/x86/include/uapi/asm/kvm.h | 1 +=0D arch/x86/kvm/x86.c | 92 ++++++++++++++++++-=0D include/uapi/linux/kvm.h | 15 +++=0D .../selftests/kvm/x86_64/tsc_msrs_test.c | 79 ++++++++++++++--=0D 5 files changed, 237 insertions(+), 15 deletions(-)=0D =0D -- =0D 2.26.2=0D =0D