From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933259AbbLSPEY (ORCPT ); Sat, 19 Dec 2015 10:04:24 -0500 Received: from terminus.zytor.com ([198.137.202.10]:39127 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753880AbbLSPEW (ORCPT ); Sat, 19 Dec 2015 10:04:22 -0500 Date: Sat, 19 Dec 2015 07:03:33 -0800 From: tip-bot for Yang Yingliang Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, yangyingliang@huawei.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, hpa@zytor.com Reply-To: yangyingliang@huawei.com, linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com In-Reply-To: <56349607.6070708@huawei.com> References: <56349607.6070708@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] clocksource: Make clocksource validation work for all clocksources Git-Commit-ID: 1f45f1f33c8c8b96722dbc5e6b7acf74eaa721f7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 1f45f1f33c8c8b96722dbc5e6b7acf74eaa721f7 Gitweb: http://git.kernel.org/tip/1f45f1f33c8c8b96722dbc5e6b7acf74eaa721f7 Author: Yang Yingliang AuthorDate: Sat, 31 Oct 2015 18:20:55 +0800 Committer: Thomas Gleixner CommitDate: Sat, 19 Dec 2015 15:59:57 +0100 clocksource: Make clocksource validation work for all clocksources The clocksource validation which makes sure that the newly read value is not smaller than the last value only works if the clocksource mask is 64bit, i.e. the counter is 64bit wide. But we want to use that mechanism also for clocksources which are less than 64bit wide. So instead of checking whether bit 63 is set, we check whether the most significant bit of the clocksource mask is set in the delta result. If it is set, we return 0. [ tglx: Simplified the implementation, added a comment and massaged the commit message ] Suggested-by: Thomas Gleixner Signed-off-by: Yang Yingliang Cc: Link: http://lkml.kernel.org/r/56349607.6070708@huawei.com Signed-off-by: Thomas Gleixner --- kernel/time/timekeeping_internal.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index e20466f..5be7627 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -17,7 +17,11 @@ static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) { cycle_t ret = (now - last) & mask; - return (s64) ret > 0 ? ret : 0; + /* + * Prevent time going backwards by checking the MSB of mask in + * the result. If set, return 0. + */ + return ret & ~(mask >> 1) ? 0 : ret; } #else static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask)