Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp74571imm; Wed, 3 Oct 2018 12:08:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV60kUIRprbY/tpqb7T11CYd5RXsMx9tZH9YkLboeW0tDyKF3iRhquVVs/meoOnLoeGNGsq/5 X-Received: by 2002:a17:902:b03:: with SMTP id 3-v6mr3050828plq.156.1538593688087; Wed, 03 Oct 2018 12:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538593688; cv=none; d=google.com; s=arc-20160816; b=URV+LxV1CukbJFb00X7nGzWsgcCAL7yXeSYpmsNj61tWqWY/OCw+AcfRtcsBwKBQUx TWI7nURkBwHsIW6uH/0jTTmGgZ3Bf82TmBM7e1DUmdhcxZ9cL4UiSQlUN7nmQ+wMDkMo jzZcsv+SEGDMoxARvAukYR0xUlu1hhX12HTZNR+btsdljLGhjMOfBCd6xRQ5jFa4496D hjvLUUSSpMzzByWT5sisElB8LcUBwmJUnjY/gy0Nqc9OHEOtYe6bvoWZNeC+kuhFc7Wx vaqG6ZTkvVf4Wj4szj82hCRrUT3og+y/4bheCiqPoZLZD730iP9YJq0KEcwNWLc800hj jKeQ== 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=EaPzbwfh2pkJA10yDRemZJQDQuu5JAaSu6hcx0EzK5w=; b=dzMuCDOJmUBTb6A5Vl3ebaq/ytYypf0xcikEwRUZRnVxUoD2bQmjGXObcpdBLyPLfq SCbKxEBEesm9zqnDQO3L/7JK9XTFnIxvhyYV7xBaY4B78J4R97493iJlHJ/Tp8ckuyh5 cQOxJ5ZE6mLCaWroM7Ll3TmKAYwSR7oPrg8GaDD/YLdZ2FMdI4VcRO8RuwDaLCBHggj/ FlKkkJusN5YT5jzLzLw9RX5hMD+vhhoSmZ6zhvIrrC3gGrEufvENkDI7mVIt3hIMgxds 0QlXFpZrqf/G86MWJ2ZNo9pWxf7Jp4H5EQgKTegnTANlsKV/pEpxl9ZdsuCqols9SJZ3 6u9g== 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 b6-v6si2282678pgh.542.2018.10.03.12.07.52; Wed, 03 Oct 2018 12:08:08 -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 S1727318AbeJDB5W (ORCPT + 99 others); Wed, 3 Oct 2018 21:57:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55250 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbeJDB5W (ORCPT ); Wed, 3 Oct 2018 21:57:22 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BE9E87624; Wed, 3 Oct 2018 19:07:41 +0000 (UTC) Received: from amt.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B2A7ABA06; Wed, 3 Oct 2018 19:07:40 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7555910514A; Wed, 3 Oct 2018 16:06:24 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id w93J6KYF023802; Wed, 3 Oct 2018 16:06:20 -0300 Date: Wed, 3 Oct 2018 16:06:20 -0300 From: Marcelo Tosatti To: Vitaly Kuznetsov Cc: Andy Lutomirski , Thomas Gleixner , Paolo Bonzini , Radim Krcmar , Wanpeng Li , LKML , X86 ML , Peter Zijlstra , 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: <20181003190617.GC21381@amt.cnet> References: <20180914125006.349747096@linutronix.de> <87sh1ne64t.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sh1ne64t.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 03 Oct 2018 19:07:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 03, 2018 at 11:22:58AM +0200, Vitaly Kuznetsov wrote: > Andy Lutomirski writes: > > > Hi Vitaly, Paolo, Radim, etc., > > > > On Fri, Sep 14, 2018 at 5:52 AM Thomas Gleixner wrote: > >> > >> Matt attempted to add CLOCK_TAI support to the VDSO clock_gettime() > >> implementation, which extended the clockid switch case and added yet > >> another slightly different copy of the same code. > >> > >> Especially the extended switch case is problematic as the compiler tends to > >> generate a jump table which then requires to use retpolines. If jump tables > >> are disabled it adds yet another conditional to the existing maze. > >> > >> This series takes a different approach by consolidating the almost > >> identical functions into one implementation for high resolution clocks and > >> one for the coarse grained clock ids by storing the base data for each > >> clock id in an array which is indexed by the clock id. > >> > > > > I was trying to understand more of the implications of this patch > > series, and I was again reminded that there is an entire extra copy of > > the vclock reading code in arch/x86/kvm/x86.c. And the purpose of > > that code is very, very opaque. > > > > Can one of you explain what the code is even doing? From a couple of > > attempts to read through it, it's a whole bunch of > > probably-extremely-buggy code that, drumroll please, tries to > > atomically read the TSC value and the time. And decide whether the > > result is "based on the TSC". And then synthesizes a TSC-to-ns > > multiplier and shift, based on *something other than the actual > > multiply and shift used*. > > > > IOW, unless I'm totally misunderstanding it, the code digs into the > > private arch clocksource data intended for the vDSO, uses a poorly > > maintained copy of the vDSO code to read the time (instead of doing > > the sane thing and using the kernel interfaces for this), and > > propagates a totally made up copy to the guest. And gets it entirely > > wrong when doing nested virt, since, unless there's some secret in > > this maze, it doesn't acutlaly use the scaling factor from the host > > when it tells the guest what to do. > > > > I am really, seriously tempted to send a patch to simply delete all > > this code. The correct way to do it is to hook > > "I have discovered a truly marvelous proof of this, which this margin is > too narrow to contain" :-) > > There is a very long history of different (hardware) issues Marcelo was > fighting with and the current code is the survived Frankenstein. Right, the code has to handle different TSC modes. > E.g. it > is very, very unclear what "catchup", "always catchup" and > masterclock-less mode in general are and if we still need them. Catchup means handling exposed (to guest) TSC frequency smaller than HW TSC frequency. That is "frankenstein" code, could be removed. > That said I'm all for simplification. I'm not sure if we still need to > care about buggy hardware though. What simplification is that again? > > > > And I don't see how it's even possible to pass kvmclock correctly to > > the L2 guest when L0 is hyperv. KVM could pass *hyperv's* clock, but > > L1 isn't notified when the data structure changes, so how the heck is > > it supposed to update the kvmclock structure? > > Well, this kind of works in the the followin way: > L1's clocksource is 'tsc_page' which is, basically, a compliment to TSC: > two numbers provided by L0: offset and scale and KVM was tought to treat > this clocksource as a good one (see b0c39dc68e3b "x86/kvm: Pass stable > clocksource to guests when running nested on Hyper-V"). > > The notification you're talking about exists, it is called > Reenligntenment, see 0092e4346f49 "x86/kvm: Support Hyper-V > reenlightenment"). When TSC page changes (and this only happens when L1 > is migrated to a different host with a different TSC frequency and TSC > scaling is not supported by the CPU) we receive an interrupt in L1 (at > this moment all TSC accesses are emulated which guarantees the > correctness of the readings), pause all L2 guests, update their kvmclock > structures with new data (we already know the new TSC frequency) and > then tell L0 that we're done and it can stop emulating TSC accesses. > > (Nothing like this exists for KVM-on-KVM, by the way, when L1's > clocksource is 'kvmclock' L2s won't get a stable kvmclock clocksource.) > > -- > Vitaly