Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5187994imm; Tue, 18 Sep 2018 05:50:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZgp7A4OgO+jo49kvLOSb/FFjYZCQB1jPb87VFmH7q3rrb6dNdo+/bygetz3oVUPwjsdaYw X-Received: by 2002:a17:902:2ac3:: with SMTP id j61-v6mr29229038plb.172.1537275022508; Tue, 18 Sep 2018 05:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537275022; cv=none; d=google.com; s=arc-20160816; b=wx1UEUjAzH3LOwJAgddqLyU6s0myzsKfR6U9YTe1Ig/Mxm3l9BfRPrHNPZQUU0/LlP 2Q/QK37wVYkekHxraoNukoq1WtoXPtcR5DbkUa/JgYw86tmv2wcq353LKD6V1OohekXp pAEbuZO+ugM/PwYSL+lvdBk14lIsNsQbA0DDt1a4UUnVIOciAUzpD4tjzfxYAr3H7Uk9 K+b1r1zE8zTx79UtB5G+1KU8Ffi7mhVut43gJha41qvm7TURbZK7ye0udBaU9yihwftU 3sLaS+y2tfCGv3CcCRwAokPWi2pRTLRQyf0Y4wS3n6neeR4jfzgEAKLkZg+dvUP8JYo0 Slvg== 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:dkim-signature; bh=meVvnGJ/ZpoQL/RyVdnVPz0EGiXzy8+NhM7Xubw+vZc=; b=mXvZY1lJfMDacFHjtMMobT9Jz1jVCCrLaKfy4VYYItu7qLkpB6kCVvj2lQSjt9v5gc kXoH3tlSzifgAxgyQ5G9cwB1gPU6kcbJW26z6+rEv74smLeTeGL6zXu07YTm8VOftovc mQPC6tkxAXWbJ+/jWmtLAfUkjy330UDfC6jWSUNR+KLEq5V2AVRaZ8UNa2DvqPNQeqRF 13729RZofm6b6szoPnTq43/x1tcVBc1W2afF30YLvwKFqS1SJS7erjSSg+IKMbrEy+oa 4wp4a/wlHrDY5z1U7EMLEGrGHTIxERKRoQAN+QLZhI4hf5CtnshwW1LgvMX40vX0d7bK RJeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="CwB/O0Rk"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6-v6si17430344pge.100.2018.09.18.05.50.06; Tue, 18 Sep 2018 05:50:22 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="CwB/O0Rk"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729618AbeIRSUi (ORCPT + 99 others); Tue, 18 Sep 2018 14:20:38 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:54022 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728065AbeIRSUh (ORCPT ); Tue, 18 Sep 2018 14:20:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=meVvnGJ/ZpoQL/RyVdnVPz0EGiXzy8+NhM7Xubw+vZc=; b=CwB/O0Rk0/mhMsG4Ss9xSykid rezVVrmZsi+d2nDNVjTjsGoX+Pik//UmWKbQuGXEbaGIg7hAc+3bqaVm7ckW7fE5dZJqGYV2gH5hx BeQnxjgZJgMcVFlinA5yYWv379Sbq/oKczdwwUuparM0grPp0fwGECh8wzseRg0Ps00sjXr/zhoaZ BeqsVUHvELFaDua75mcP+L54CAEAIDWzBTI+P9A+sfyrrkubrLFLj4Q19sac/Yq9dsuuREkRl/XhU 7jzN5a8EpeTkuFApCD+7aEmrwjReh55nF5LMjQ6wsyeHW60k2F3e2BdFmW/sJW/SNlNdbvgmnq0wz 41owmMCtA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2FQ9-0004Zu-Vg; Tue, 18 Sep 2018 12:48:02 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3B42C202C1A35; Tue, 18 Sep 2018 14:48:00 +0200 (CEST) Date: Tue, 18 Sep 2018 14:48:00 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: John Stultz , Andy Lutomirski , LKML , X86 ML , Matt Rickard , Stephen Boyd , Florian Weimer , "K. Y. Srinivasan" , Vitaly Kuznetsov , devel@linuxdriverproject.org, Linux Virtualization , Paolo Bonzini , Arnd Bergmann , Juergen Gross Subject: Re: [patch 09/11] x86/vdso: Simplify the invalid vclock case Message-ID: <20180918124800.GL24106@hirez.programming.kicks-ass.net> References: <20180914125006.349747096@linutronix.de> <20180914125118.909646643@linutronix.de> <20180918083055.GJ24106@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 18, 2018 at 12:41:57PM +0200, Thomas Gleixner wrote: > On Tue, 18 Sep 2018, Thomas Gleixner wrote: > > On Tue, 18 Sep 2018, Thomas Gleixner wrote: > > > On Tue, 18 Sep 2018, Peter Zijlstra wrote: > > > > > Your memory serves you right. That's indeed observable on CPUs which > > > > > lack TSC_ADJUST. > > > > > > > > But, if the gtod code can observe this, then why doesn't the code that > > > > checks the sync? > > > > > > Because it depends where the involved CPUs are in the topology. The sync > > > code might just run on the same package an simply not see it. Yes, w/o > > > TSC_ADJUST the TSC sync code can just fail to see the havoc. > > > > Even with TSC adjust the TSC can be slightly off by design on multi-socket > > systems. > > Here are the gory details: > > https://lore.kernel.org/lkml/3c1737210708230408i7a8049a9m5db49e6c4d89ab62@mail.gmail.com/ > > The changelog has an explanation as well. > > d8bb6f4c1670 ("x86: tsc prevent time going backwards") > > I still have one of the machines which is affected by this. Are we sure this isn't a load vs rdtsc reorder? Because if I look at the current code: notrace static u64 vread_tsc(void) { u64 ret = (u64)rdtsc_ordered(); u64 last = gtod->cycle_last; if (likely(ret >= last)) return ret; /* * GCC likes to generate cmov here, but this branch is extremely * predictable (it's just a function of time and the likely is * very likely) and there's a data dependence, so force GCC * to generate a branch instead. I don't barrier() because * we don't actually need a barrier, and if this function * ever gets inlined it will generate worse code. */ asm volatile (""); return last; } That does: lfence rdtsc load gtod->cycle_last Which obviously allows us to observe a cycles_last that is later than the rdtsc itself, and thus time can trivially go backwards. The new code: last = gtod->cycle_last; cycles = vgetcyc(gtod->vclock_mode); if (unlikely((s64)cycles < 0)) return vdso_fallback_gettime(clk, ts); if (cycles > last) ns += (cycles - last) * gtod->mult; looks like: load gtod->cycle_last lfence rdtsc which avoids that possibility, the cycle_last load must have completed before the rdtsc.