Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp395757ybd; Tue, 25 Jun 2019 23:41:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLe5J2FZ8i7rsDDs7+oBEV2QG3O/j7blYdBMkQxm8P3Jx2CPLxQ/Y2vVrvyZcJznvn8t7t X-Received: by 2002:a17:902:4c:: with SMTP id 70mr3462012pla.308.1561531272202; Tue, 25 Jun 2019 23:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561531272; cv=none; d=google.com; s=arc-20160816; b=iyeuYbdBSFzLok733xVcyZ4oIpPb1ee/7uJ1AtyjtVze/NeFo7gwFNrJa0S1L0gDYN 2e+dg5UrHtyqY7UmOESyFnjij0V8SUZplFjKdi9MClN/W0Sb3gYh/EwFCV32ZOrYqige QKzZbhSdQrbQEtSBRNEIlU8BKxOJ0B/txZG8xjqAh/QLSBNHTJ08S3Ydy8awx2WDauH2 MjDZE26cAIiUBUTws6hOcD4s17kWcfFgI0EbxYGApyqmkqJDjKTs+XHWLxJgmxjClRzr UYo2HMC5PFsKyKl/vEyhVQ0g5cTObOpAcMWLegy2D39ho3nGrEZMaYrFMrS6Y+6p+1bp Uu3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=iLbWMwe+WfURn81pfYDIl5qPK/EbCour5oQeXc5OQe0=; b=lrSx3tEwQKgxFPsYOoQ6ZjQwkArAjMySKbzbWgDuKYcbtSTS/c8gcyc5Pa3fF5Yvic CbQrqJUipqFuQnRlZG0ZxVcLrc/y6piX5+xT9JmWS/LF9/VykwjVVdgqcAcEub3UbI/b kbozWdd+BtVduDu0vDvoevipdOpwOHEeW/mCxNFMtB1uNW81kbgsXYm1zqGqCg5smZ4l UdeXfy1SJSIDNTQGIRCWnv//PZBUtncEml+6SFUnKAzM/0n08ISrsw6g87lhZeeglGAv +y6u7CRecYMm8wlh/ggqP5WXeEBtgiuevKButaqc29zE6jMac8hHZjqzIGtDC+/UlmGc P5rQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si16203225pfd.156.2019.06.25.23.40.54; Tue, 25 Jun 2019 23:41:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726849AbfFZGi5 (ORCPT + 99 others); Wed, 26 Jun 2019 02:38:57 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:45176 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbfFZGi5 (ORCPT ); Wed, 26 Jun 2019 02:38:57 -0400 Received: from p5b06daab.dip0.t-ipconnect.de ([91.6.218.171] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hg1Zx-0005Tw-AG; Wed, 26 Jun 2019 08:38:49 +0200 Date: Wed, 26 Jun 2019 08:38:48 +0200 (CEST) From: Thomas Gleixner To: Vincenzo Frascino cc: linux-arch@vger.kernel.org, LAK , LKML , linux-mips@vger.kernel.org, linux-kselftest@vger.kernel.org, catalin.marinas@arm.com, Will Deacon , Arnd Bergmann , linux@armlinux.org.uk, Ralf Baechle , paul.burton@mips.com, Daniel Lezcano , salyzyn@android.com, pcc@google.com, shuah@kernel.org, 0x7f454c46@gmail.com, linux@rasmusvillemoes.dk, huw@codeweavers.com, sthotton@marvell.com, andre.przywara@arm.com, Andy Lutomirski Subject: Re: [PATCH 1/3] lib/vdso: Delay mask application in do_hres() In-Reply-To: Message-ID: References: <20190624133607.GI29497@fuggles.cambridge.arm.com> <20190625161804.38713-1-vincenzo.frascino@arm.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Jun 2019, Thomas Gleixner wrote: > On Tue, 25 Jun 2019, Vincenzo Frascino wrote: > > do_hres() in the vDSO generic library masks the hw counter value > > immediately after reading it. > > > > Postpone the mask application after checking if the syscall fallback is > > enabled, in order to be able to detect a possible fallback for the > > architectures that have masks smaller than ULLONG_MAX. > > Right. This only worked on x86 because the mask is there ULLONG_MAX for all > VDSO capable clocksources, i.e. that ever worked just by chance. But it's actually worse than that: > > + cycles &= vd->mask; > > if (cycles > last) > > ns += (cycles - last) * vd->mult; > > ns >>= vd->shift; This is broken for any clocksource which can legitimately wrap around. The core timekeeping does the right thing: (cycles - last) & mask That makes sure that a wraparound is correctly handled. With the above the wrap around would be ignored due to if (cycles > last) Stupid me. I should have added big fat comments to the x86 vdso why this all works correctly and only correctly for the x86 crud. That was part of squeezing the last cycles out of the vdso. Sorry for not noticing earlier. Working on a fix. Thanks, tglx