From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755895AbcK1WvK (ORCPT ); Mon, 28 Nov 2016 17:51:10 -0500 Received: from mail-oi0-f47.google.com ([209.85.218.47]:35614 "EHLO mail-oi0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755318AbcK1WvA (ORCPT ); Mon, 28 Nov 2016 17:51:00 -0500 MIME-Version: 1.0 In-Reply-To: <1479531216-25361-1-git-send-email-john.stultz@linaro.org> References: <1479531216-25361-1-git-send-email-john.stultz@linaro.org> From: John Stultz Date: Mon, 28 Nov 2016 14:50:59 -0800 Message-ID: Subject: Re: [PATCH] timekeeping: Change type of nsec variable to unsigned in its calculation. To: lkml Cc: Liav Rehana , Chris Metcalf , Thomas Gleixner , Richard Cochran , Ingo Molnar , Prarit Bhargava , Laurent Vivier , David Gibson , "Christopher S . Hall" , "4.6+" , John Stultz Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 18, 2016 at 8:53 PM, John Stultz wrote: > From: Liav Rehana > > During the calculation of the nsec variable in the inline function > timekeeping_delta_to_ns, it may undergo a sign extension if its msb > is set just before the shift. The sign extension may, in some cases, > gain it a value near the maximum value of the 64-bit range. This is > bad when it is later used in a division function, such as > __iter_div_u64_rem, where the amount of loops it will go through to > calculate the division will be too large. One can encounter such a > problem, for example, when trying to connect through ftp from an > outside host to the operation system. When the OS is too overloaded, > delta will get a high enough value for the msb of the sum > delta * tkr->mult + tkr->xtime_nsec to be set, and so after the > shift the nsec variable will gain a value similar to > 0xffffffffff000000. Using a variable with such a value in the > inline function __iter_div_u64_rem will take too long, making the > ftp connection attempt seem to get stuck. > The following commit fixes that chance of sign extension, while > maintaining the type of the nsec variable as signed for other > functions that use this variable, for possible legit negative > time intervals. > > Cc: Chris Metcalf > Cc: Thomas Gleixner > Cc: Richard Cochran > Cc: Ingo Molnar > Cc: Prarit Bhargava > Cc: Laurent Vivier > Cc: David Gibson > Cc: "Christopher S . Hall" > Cc: stable@vger.kernel.org (4.6+) > Fixes: 6bd58f09e1d8 ("time: Add cycles to nanoseconds translation") > Also-Reported-by: Chris Metcalf > Signed-off-by: Liav Rehana > Signed-off-by: John Stultz > --- > Thomas/Ingo: This is for tip:timers/urgent. Hey Thomas, Ingo, I just wanted to follow up to make sure this wasn't missed last time. Should be applied against tip/timers/urgent. thanks -john