Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3356307pxu; Tue, 8 Dec 2020 09:51:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaWvx71rsGJwb29rMiN9Or8xFu6gG3jIZl/MRqR61W/Y6+QSiZ6TDZ5ewlJQoYXqtmrd0a X-Received: by 2002:a17:906:b56:: with SMTP id v22mr20331811ejg.145.1607449889057; Tue, 08 Dec 2020 09:51:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607449889; cv=none; d=google.com; s=arc-20160816; b=zyryJXT3A6deCeB4rCM+iE+qn8FH/59mwlJJtMjIP9i3n0y9Akrgd0j7BC8331J7ba TUzD+6g7K6waTHu7vDAOainxc4YoSdUt6I/fyRiYW7Q60HeLWcOqstZciMdyvhd902uB mmcEkHd6h9jDB7ckq3DsAixWuEHsBFOxe0qO7mApa5YJjtxKQmaMJ6xYwnPmCmUap9mC Pv/9tbIU60uxUGhiqgYJKPOk7ev8qN/5RnKT4vouvJsKo99Bxd9fE3KiVipv8+LXsTUv MaRJsw+SAdoWQ+dufXviQjYm8QIJ9RY6TVUM0DKIKUfCPbBQkLncmZve8OFGImNd2Xs3 XoRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=hgLwc0RUbljt4Sar2tm11A6S02UXu07vDDIecgkS2W4=; b=g3/wcRMzNC96P7tmMIIEr8wI5gmtCN94TMWcAFWhMqTMx8scJcqUhvw9pyKJmGkawd rzmve7FC0l6wZ9jk+I6F0vT+7Gie/5jp1oHVSGIRrWjph8NQCTg8M947gNtvn6nvvNjY i+bc7I3WVrMPhSDfSQVaA/UoyahA4W705ZuACdDYqU3MaU02NgRYtGEnwy9Q/Yxdt0Nj KCOp06VBXI2amVpARXG1hzfQ5q0zKdFxUAAOaWH2Jx5GEwUnVjEmjpBNJK0sF3Z8GM8f oU+rl39mj+K+gLosIzWB6BIciqS46mUYZ+4nS7zJIO4V90IelvSFpqMaL8NRCdBL97DB X74Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dAb3IRJq; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si8607622ejk.231.2020.12.08.09.51.05; Tue, 08 Dec 2020 09:51:29 -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=@kernel.org header.s=k20201202 header.b=dAb3IRJq; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730832AbgLHRoo (ORCPT + 99 others); Tue, 8 Dec 2020 12:44:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:37628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730827AbgLHRoo (ORCPT ); Tue, 8 Dec 2020 12:44:44 -0500 X-Gm-Message-State: AOAM532D4vzm8xrkYvssZ1CmGPEar46YZIDtlyQP6Kmi7DNNbtjwalr3 5TVG443J7s7aGvPxV4sgs37ueKoMhAnfclaxs34vZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607449443; bh=qOJEF76l9wC8yLqJEJDwkrt5AGUmhLvlKmfUMREz+ko=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dAb3IRJqoR06BqD0je5AQGVNbWRVArv9rH+FjDpIwFKjqgIMLfwl4f+JxmubOQ1ec r2sacEDyxFlxt1DswVi3PMaLtJIViE4p/ms42Wkx/s8lEWFq7ygu+3ZqKscDuw3dj2 5HU8rwwVDrqA+9IoVaSyg1rD9F5rudJ2gxnwWmba2JOJGnGnTyoVUWLobdHUegrRKg jlS4FXaRPC336p6hlLiHZ3yFgrVpRsIUR1u46UPrks0cVH6y9S+HornA802V/dk19l aWkrR6Sjz/hrvgcNmOFefXAevz82mMJMcA1u0DinCF6ntbu6BisQn4c6CKHqohU2qj 3gllIJr1YdRuQ== X-Received: by 2002:a1c:1d85:: with SMTP id d127mr4943071wmd.49.1607449442016; Tue, 08 Dec 2020 09:44:02 -0800 (PST) MIME-Version: 1.0 References: <636fecc20b0143128b484f159ff795ff65d05b82.camel@redhat.com> <885C1725-B479-47F6-B08D-A7181637A80A@amacapital.net> <20201207231127.GB27492@fuller.cnet> In-Reply-To: <20201207231127.GB27492@fuller.cnet> From: Andy Lutomirski Date: Tue, 8 Dec 2020 09:43:50 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE To: Marcelo Tosatti Cc: Maxim Levitsky , Thomas Gleixner , kvm list , "H. Peter Anvin" , Paolo Bonzini , Jonathan Corbet , Jim Mattson , Wanpeng Li , "open list:KERNEL SELFTEST FRAMEWORK" , Vitaly Kuznetsov , Sean Christopherson , open list , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , Borislav Petkov , Shuah Khan , Andrew Jones , Oliver Upton , "open list:DOCUMENTATION" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 8, 2020 at 6:23 AM Marcelo Tosatti wrote: > > On Mon, Dec 07, 2020 at 10:04:45AM -0800, Andy Lutomirski wrote: > > > > > > I do have a feature request, though: IMO it would be quite nifty if the= new kvmclock structure could also expose NTP corrections. In other words, = if you could expose enough info to calculate CLOCK_MONOTONIC_RAW, CLOCK_MON= OTONIC, and CLOCK_REALTIME, then we could have paravirt NTP. > > Hi Andy, > > Any reason why drivers/ptp/ptp_kvm.c does not work for you? > It looks like it tries to accomplish the right goal, but in a rather roundabout way. The host knows how to convert from TSC to CLOCK_REALTIME, and ptp_kvm.c exposes this data to the guest. But, rather than just making the guest use the same CLOCK_REALTIME data as the host, ptp_kvm.c seems to expose information to usermode that a user daemon could use to attempt (with some degree of error?) to use to make the guest kernel track CLOCK_REALTIME. This seems inefficient and dubiously accurate. My feature request is for this to be fully automatic and completely coherent. I would like for a host user program and a guest user program to be able to share memory, run concurrently, and use the shared memory to exchange CLOCK_REALTIME values without ever observing the clock going backwards. This ought to be doable. Ideally the result should even be usable for Spanner-style synchronization assuming the host clock is good enough. Also, this whole thing should work without needing to periodically wake the guest to remain synchronized. If the guest sleeps for two minutes (full nohz-idle, no guest activity at all), the host makes a small REALTIME frequency adjustment, and then the guest runs user code that reads CLOCK_REALTIME, the guest clock should still be fully synchronized with the host. I don't think that ptp_kvm.c-style synchronization can do this. tglx etc, I think that doing this really really nicely might involve promoting something like the current vDSO data structures to ABI -- a straightforward-ish implementation would be for the KVM host to export its vvar clock data to the guest and for the guest to use it, possibly with an offset applied. The offset could work a lot like timens works today. --Andy