Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755250AbcKOCtP (ORCPT ); Mon, 14 Nov 2016 21:49:15 -0500 Received: from ozlabs.org ([103.22.144.67]:37795 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754034AbcKOCtM (ORCPT ); Mon, 14 Nov 2016 21:49:12 -0500 Date: Tue, 15 Nov 2016 11:56:36 +1100 From: David Gibson To: Chris Metcalf Cc: John Stultz , Thomas Gleixner , Laurent Vivier , "Christopher S . Hall" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] time: Avoid signed overflow in timekeeping_delta_to_ns() Message-ID: <20161115005636.GF24747@umbus.fritz.box> References: <1479152569-16890-1-git-send-email-cmetcalf@mellanox.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KJY2Ze80yH5MUxol" Content-Disposition: inline In-Reply-To: <1479152569-16890-1-git-send-email-cmetcalf@mellanox.com> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2515 Lines: 68 --KJY2Ze80yH5MUxol Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 14, 2016 at 02:42:49PM -0500, Chris Metcalf wrote: > This bugfix was originally made in commit 35a4933a8959 ("time: > Avoid signed overflow in timekeeping_get_ns()"). When the code was > refactored in commit 6bd58f09e1d8 ("time: Add cycles to nanoseconds > translation") the signed overflow fix was lost. Re-introduce it. >=20 > Signed-off-by: Chris Metcalf Reviewed-by: David Gibson > --- > I happened to be looking for an unrelated fix, found this code, > realized the tip code didn't match the fixed code, and > backtracked to where it had gone away. >=20 > kernel/time/timekeeping.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) >=20 > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 37dec7e3db43..57926bc7b7f3 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -304,8 +304,7 @@ static inline s64 timekeeping_delta_to_ns(struct tk_r= ead_base *tkr, > { > s64 nsec; > =20 > - nsec =3D delta * tkr->mult + tkr->xtime_nsec; > - nsec >>=3D tkr->shift; > + nsec =3D (delta * tkr->mult + tkr->xtime_nsec) >> tkr->shift; > =20 > /* If arch requires, add in get_arch_timeoffset() */ > return nsec + arch_gettimeoffset(); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --KJY2Ze80yH5MUxol Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYKl1BAAoJEGw4ysog2bOSol8P/i/c8IqCAxLZYKz04bxQBWmp /mIZy5nd4tC5I0G56i/+fCfpRclMgC0nWM/olSIuvoVGkZPhXsUe3MXp45YIMkSR 64Q0NOaM7S5KdvUxS7AdIOBqxm6H4Y9NO4umZlzLEYtKKOiBx/vAlX4oIvB+ss9F 00KAbACKpqFKqIxveztptmKWhgdBJq30lUVooKsSTVym1wgPilhqtaO0y4FdGiIv ANueCBRkZC4OXDSr0SiGr+jrJ02ZZbcIcbKFJykKD1Pldkf67TbGNN3o6jI6aIR/ kQTCAiO5kIomWG4POLEN7zbw0FVFxg6BzhQRfJ+KfB42RBjyqjgxejlsVwHhkV/J zNm9n33/6AAX6GnuKkjS4FP2QokMSLhxYX+6dM3NcWXAxOS+8JTIlWUNwZOJANoM 1GM8v8UT7UqxLaU26/747m8ZG9UEvF1kPiDc1bgcYC2HpyZdtVRS9zu/d4NTQqNs k8tx/pnUwYqlJh1epb522yIxOfGFsODWsrQUGqdnWf8Gg0dqvAwjd2wFbUEFOAqx hKUQxOtE56hdlbhYBgJxlSIf1FxYADhb+5wtpEqssjtrCitaXsQLeDU3gMo0GZ58 KIb3QBme5RZ+ytTIabTG/xccjVDGHx2/yeZlz9tFRCyz9SIeCfOncGsTnPWwbPAc ciiy7qJsOwbTck+RMRit =SzAG -----END PGP SIGNATURE----- --KJY2Ze80yH5MUxol--