Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5016543imm; Tue, 9 Oct 2018 08:30:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV60KvfCBqRsMTS9jsEZYjT2ydOAsz8kW9gNNOfOGhQd3h/fk3sIVcRC06GJGXKlI48sn13KA X-Received: by 2002:a63:4281:: with SMTP id p123-v6mr25611573pga.91.1539099048704; Tue, 09 Oct 2018 08:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539099048; cv=none; d=google.com; s=arc-20160816; b=s8ce/Vt5lTfMKjONty4DhWwjQZF37h+sirXskIu5ONGQxvML5LC7ZAFer5QdcjuW4y isnq9fvmmFXF2ZcbXlRVEwQ2YslTXPnxFgCjd8zzFLFOhcDOsD1ynZqeFFPsYQMCZnua YudRIIMuZenzUN26qC7WOpb+CSjp/PtYW/nYxVe17dBKypQPz+6wY4DRhr+WpttZnviB waaTP7hBIhsMS9UyS8gpN4ytPfHqhlLjihBmOyZEb2DAPBxKbLI3MJNzG7OvbtjBJEyb mU9vDI0TsXnaEqGlqbApF6OSPGU7MzBpKeZiVARVVxS3QMjTUPLlwqMR7tIu6tR9vFkl TXdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/qCr9jtk8v56/ow0ebbb8hbEBPiUqbP6n8y5NKwwd/s=; b=Q/8pikVEy2oy1roIXULPEOzn45Lzf/+Wc7/rS1K2zfswXEEyn/Ik8c8Xdq3hMbYwoH YXG+Kge+hEqPhNXLBrrkhbMghmJsGgFsUM8rowEDXDLxaRN5+NoqINnTQomZUMfY8Zys nW7NdiNYGu/ds3zFW3S/ky6JmRbdVV/Uf6dV5Zxep0MAQeDrCl8oey4gj89asxHWiaKX EciT2bpQljUMTajlsaaJJ+34ogqHtvBM+GCNWoKgHJfxwJ/MPsd6PJL+nWDLIpypTnyU FtpEb/mpK+2LuqYm7ne+e2FlXnxrwcN128hHb/dwyA3IoGC6XEuH2vwsVZc2hSrBlCFX Radg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d40-v6si22474057pla.217.2018.10.09.08.30.33; Tue, 09 Oct 2018 08:30:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbeJIWqW (ORCPT + 99 others); Tue, 9 Oct 2018 18:46:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37700 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbeJIWqV (ORCPT ); Tue, 9 Oct 2018 18:46:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 143CB3086249; Tue, 9 Oct 2018 15:28:54 +0000 (UTC) Received: from amt.cnet (ovpn-112-5.gru2.redhat.com [10.97.112.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ADE07A418; Tue, 9 Oct 2018 15:28:50 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id EA4711050CB; Mon, 8 Oct 2018 16:36:47 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id w98Jaadc031930; Mon, 8 Oct 2018 16:36:36 -0300 Date: Mon, 8 Oct 2018 16:36:36 -0300 From: Marcelo Tosatti To: Andy Lutomirski Cc: Peter Zijlstra , Vitaly Kuznetsov , Thomas Gleixner , Paolo Bonzini , Radim Krcmar , Wanpeng Li , LKML , X86 ML , Matt Rickard , Stephen Boyd , John Stultz , Florian Weimer , KY Srinivasan , devel@linuxdriverproject.org, Linux Virtualization , Arnd Bergmann , Juergen Gross Subject: Re: [patch 00/11] x86/vdso: Cleanups, simmplifications and CLOCK_TAI support Message-ID: <20181008193632.GA31729@amt.cnet> References: <87k1mycfju.fsf@vitty.brq.redhat.com> <20181004081100.GI19272@hirez.programming.kicks-ass.net> <20181004193150.GQ19272@hirez.programming.kicks-ass.net> <499807AB-E779-40C3-AA3F-E8C77A7770EC@amacapital.net> <20181006202731.GC7129@amt.cnet> <20181008152650.GB27822@amt.cnet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 09 Oct 2018 15:28:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 08, 2018 at 10:38:22AM -0700, Andy Lutomirski wrote: > On Mon, Oct 8, 2018 at 8:27 AM Marcelo Tosatti wrote: > > > > On Sat, Oct 06, 2018 at 03:28:05PM -0700, Andy Lutomirski wrote: > > > On Sat, Oct 6, 2018 at 1:29 PM Marcelo Tosatti wrote: > > > > > > > > On Thu, Oct 04, 2018 at 03:15:32PM -0700, Andy Lutomirski wrote: > > > > > For better or for worse, I'm trying to understand this code. So far, > > > > > I've come up with this patch: > > > > > > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/commit/?h=x86/vdso-tglx&id=14fd71e12b1c4492a06f368f75041f263e6862bf > > > > > > > > > > Is it correct, or am I missing some subtlety? > > > > > > > > The master clock, when initialized, has a pair > > > > > > > > masterclockvalues=(TSC value, time-of-day data). > > > > > > > > When updating the guest clock, we only update relative to (TSC value) > > > > that was read on masterclock initialization. > > > > > > I don't see the problem. The masterclock data is updated here: > > > > > > host_tsc_clocksource = kvm_get_time_and_clockread( > > > &ka->master_kernel_ns, > > > &ka->master_cycle_now); > > > > > > kvm_get_time_and_clockread() gets those values from > > > do_monotonic_boot(), which, barring bugs, should cause > > > get_kvmclock_ns() to return exactly the same thing as > > > ktime_get_boot_ns() + ka->kvmclock_offset, albeit in a rather > > > roundabout manner. > > > > > > So what am I missing? Is there actually something wrong with my patch? > > > > For the bug mentioned in the comment not to happen, you must only read > > TSC and add it as offset to (TSC value, time-of-day data). > > > > Its more than "a roundabout manner". > > > > Read the comment again. > > > > I read the comment three more times and even dug through the git > history. It seems like what you're saying is that, under certain > conditions (which arguably would be bugs in the core Linux timing > code), I don't see that as a bug. Its just a side effect of reading two different clocks (one is CLOCK_MONOTONIC and the other is TSC), and using those two clocks to as a "base + offset". As the comment explains, if you do that, can't guarantee monotonicity. > actually calling ktime_get_boot_ns() could be non-monotonic > with respect to the kvmclock timing. But get_kvmclock_ns() isn't used > for VM timing as such -- it's used for the IOCTL interfaces for > updating the time offset. So can you explain how my patch is > incorrect? ktime_get_boot_ns() has frequency correction applied, while reading masterclock + TSC offset does not. So the clock reads differ.