Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3317874imu; Sun, 11 Nov 2018 12:14:41 -0800 (PST) X-Google-Smtp-Source: AJdET5dG0ZbLFLcic0H3wBn/q/7r/YZMe76Gu4ivuuvsHglqpYlBFE1DlNFdK34K218iJAs6CBhV X-Received: by 2002:a17:902:6909:: with SMTP id j9-v6mr16629037plk.221.1541967281860; Sun, 11 Nov 2018 12:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967281; cv=none; d=google.com; s=arc-20160816; b=qvM7RtXNjFqwclzS2cWVEVwhuK7kXZb2+oWOHBL1+lUCU7uIHm0xlxsiR9Hs8/UhZe vrBnR0vvvG41H6yMe1bHsgauBzBFWsEV/aKslHsWKJhGy/y0BS6G/Suarkp5DiS8wByF SEotVnkpKZMXPDwynQwjuHeFa2jrLTMDw8Y+2sXQM0tbvOAAlvCAEDJCWxv+EETtDbZi CyQksWpd6Z+JeMYtrDKMvLkSFifwQRdZlIlvtOEnN0lT4qJwKkbH6SATkfeMeAcE+zal VL4sh/+zxCVdcXuY070S9XxHZrUFpswNjqVON0jRsxwP8sZeYzVP+1MAUDKPM5MCFmWe nYtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=+Ti3iFnKR12YOESREKZJ74mrcAd5jQKwUdrEkCDy63M=; b=c1sXQxmjt7FZ1zpiq8aJGNfyJZQwu/w/ch4WJEZtmwD1kdXrHh4gan+6fhHFGL01ee US+6HWveKkM11JCKJ0PsrVTEqQn6hHioJUqzTmfE9FmPRv8/alILcBP/b/pm6ypAU2kv 56vffhG3kBArjRvBzBWrUsqbpK8ikLx9obEDBnOEnldml3ZRp0WdANvaO0KVl8vhrAll ZPOR5d8qqf0ly2t3gkRji7cF5ogL2vr/dNFadqpdWiC18l62sSjfl+498RBJb0njcFSJ Pw1Jfzj5Jm0mkFZFynnDrPY5t/pqQrqeFh+Gt5kjpd/xv9y8BlefuecG/G4LYAzYY8SJ YF9w== 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 r36-v6si13555895pgl.257.2018.11.11.12.14.26; Sun, 11 Nov 2018 12:14:41 -0800 (PST) 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 S1731237AbeKLGDO (ORCPT + 99 others); Mon, 12 Nov 2018 01:03:14 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52754 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726809AbeKLGDN (ORCPT ); Mon, 12 Nov 2018 01:03:13 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsz-0000l5-0O; Sun, 11 Nov 2018 19:59:09 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsT-0001cL-MU; Sun, 11 Nov 2018 19:58:37 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Arnd Bergmann" , "Geert Uytterhoeven" , linux-mips@linux-mips.org, "Thomas Gleixner" , "Stephen Boyd" , "John Stultz" , linux-alpha@vger.kernel.org Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 183/366] time: Make sure jiffies_to_msecs() preserves non-zero time periods In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven commit abcbcb80cd09cd40f2089d912764e315459b71f7 upstream. For the common cases where 1000 is a multiple of HZ, or HZ is a multiple of 1000, jiffies_to_msecs() never returns zero when passed a non-zero time period. However, if HZ > 1000 and not an integer multiple of 1000 (e.g. 1024 or 1200, as used on alpha and DECstation), jiffies_to_msecs() may return zero for small non-zero time periods. This may break code that relies on receiving back a non-zero value. jiffies_to_usecs() does not need such a fix: one jiffy can only be less than one µs if HZ > 1000000, and such large values of HZ are already rejected at build time, twice: - include/linux/jiffies.h does #error if HZ >= 12288, - kernel/time/time.c has BUILD_BUG_ON(HZ > USEC_PER_SEC). Broken since forever. Signed-off-by: Geert Uytterhoeven Signed-off-by: Thomas Gleixner Reviewed-by: Arnd Bergmann Cc: John Stultz Cc: Stephen Boyd Cc: linux-alpha@vger.kernel.org Cc: linux-mips@linux-mips.org Link: https://lkml.kernel.org/r/20180622143357.7495-1-geert@linux-m68k.org [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- kernel/time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/kernel/time.c +++ b/kernel/time.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -253,9 +254,10 @@ unsigned int jiffies_to_msecs(const unsi return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); #else # if BITS_PER_LONG == 32 - return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32; + return (HZ_TO_MSEC_MUL32 * j + (1ULL << HZ_TO_MSEC_SHR32) - 1) >> + HZ_TO_MSEC_SHR32; # else - return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN; + return DIV_ROUND_UP(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN); # endif #endif }