Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp537884ybd; Wed, 26 Jun 2019 02:27:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqw39OWTBTDacntBS/+W+B0QPtjfEwrNa4y+VUXWMZmtOhfKyjapoPoONfc+GdoRjNGBLQ0b X-Received: by 2002:a17:902:aa88:: with SMTP id d8mr320476plr.274.1561541261599; Wed, 26 Jun 2019 02:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561541261; cv=none; d=google.com; s=arc-20160816; b=fABAAttVAK9+wIoL7lUxwpNpldA2Ejtvsfmzc9VcnsfH0LXE9DAWdTKAxjYeLjALBK I6Ry3S1B6NW0m/Hv91DnQylK7yZws9cidz/39lnCFPTv3CJj5Rzk432vRl5nQCobRLvl 98dFP2fYO+94Qm3iUtoJaxYC5KcusA1x4yfE4IbaFxbEfd2i4w6L9aAFm3vxTWdBLGIp ISbqb6ZAMvJUt7qKQU/N0HYAHpaCZ86IljSAJ7cIUKh5X19lHrF1fvBVsgS5xbQistDo 8KuAXoi9DHHKf5gSe+ULyIhi7NonEbrpK7AykkWvj1+otCDiSZ+ajcMpWj8zDe+rI3Yj O9NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=MiqjDYPI8ChOGCH0xNujKVgnt1ZZI5QUZ5zwaPv8dTY=; b=zul6q5VE8F4XDDYLYflxpEigK5eKOx6ndUYe3FM6ULFs+rMzZu3GNUE3V7p5WqVshI oOO8UyO8t8HHIhfT7J8ucHQXZi1ss/hTdqwqAq820vq+CO9XpvjsoPxNDx7k5WBqk+y/ D3wKdbR2XdklnCHtOswua3SBN5rULbJpsktXLyVqtU72041lbi7kRFN718XXMkp6EQp0 27GvUHs/ay7JfOGgHZwkcABRvu3piavE2Hj82OOHE0RGteZht4rjA3eo5Fe7Oa42PbCt 2S5ZFS3ClQWukEfJadUV54nKvLM5+JCrjGG3fFbmACbXe05kD+dJKhqDFsdi5HvmX1pe wv8g== 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 33si2975678plv.153.2019.06.26.02.27.25; Wed, 26 Jun 2019 02:27:41 -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 S1726867AbfFZJZ0 (ORCPT + 99 others); Wed, 26 Jun 2019 05:25:26 -0400 Received: from foss.arm.com ([217.140.110.172]:57258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725379AbfFZJZ0 (ORCPT ); Wed, 26 Jun 2019 05:25:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 818432B; Wed, 26 Jun 2019 02:25:25 -0700 (PDT) Received: from [10.1.196.72] (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 55EE03F718; Wed, 26 Jun 2019 02:25:22 -0700 (PDT) Subject: Re: [PATCH 1/3] lib/vdso: Delay mask application in do_hres() To: Thomas Gleixner 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 References: <20190624133607.GI29497@fuggles.cambridge.arm.com> <20190625161804.38713-1-vincenzo.frascino@arm.com> From: Vincenzo Frascino Message-ID: <4ff43de4-fe51-eed4-a155-31a05edf2f11@arm.com> Date: Wed, 26 Jun 2019 10:25:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, On 26/06/2019 07:38, Thomas Gleixner wrote: > 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) > You are right. Thanks for spotting it. ... -- Regards, Vincenzo