Received: by 10.192.165.148 with SMTP id m20csp857486imm; Fri, 27 Apr 2018 08:36:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqkwgAd64re5MQJVqdKJkGZHIvyubY6m+h2qe3b8urtYwJK6psPzFeomnlZYEiZBHqbLRYR X-Received: by 2002:a63:751d:: with SMTP id q29-v6mr2543391pgc.269.1524843409250; Fri, 27 Apr 2018 08:36:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524843409; cv=none; d=google.com; s=arc-20160816; b=h884FX+ym45YmUEOOTzWNFtNcN9V9u9dNh+HxDv14G4Lw7pLn7/jqkR3CvAYE+N8o7 r65c93dYcoKX0192paIsWM9XOjkieFVDoaETrRDDAS+gHi6u33dkcS9fSH4zoBY2/dyo b0zzGpbyd5k54j1bnrCDAZpl1EdLpaj/RFtHt8glAPTxo5Vc4K0uYQK+YMi4Psm8GHhV x3Nox6E/EU6fkBBZ/vO0JmMilvof78d+oI5zTOWA8O3U9s3xPR6nsdvTse8n8NI553fA FX2zfAmj1h9SSF1TiZoMy9hUyAWKsxnGpK+VnONn/pKzA9pvwV7BSp2afUctehOmD07Z udtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=Y1H+Y/153Ihm0f4JRCLcfaPUywyhKAaVODFbsbW0ke0=; b=SKYWlHpu3OFL0hAI0M9CjuVMvgim47/NgjoyBbSfO03ohnL77QtbQ94PsWXYK49798 X1P6dsMArjzq3Sds1XQCKO6r2XKf84VU4qeeQYC5qWI+D/nWxz3wLweiMOXXhnAFhEzg +ryEfxUMh/jIqoxgSqOkMm12j3PNMmkpPTuQrfIFFiuU3cACUvWfYKO6/tjztGpNFiAw I0V/wHbQqdp3SjXWjzjXlzstm8oO9/JEcyznBO3TkTCPNzyZuQeqdGCmlRs17Oj8NdBH iI1KoEHYHQoESQQOadfl+/UH6ZhJJP2g/dQrpfRcQriTdD7psPPkNefWc24KjK3UJx6Z ny4A== 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 t24si191246pfj.231.2018.04.27.08.36.35; Fri, 27 Apr 2018 08:36:49 -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 S1758522AbeD0OAG (ORCPT + 99 others); Fri, 27 Apr 2018 10:00:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:47240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758480AbeD0OAC (ORCPT ); Fri, 27 Apr 2018 10:00:02 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 801BF21837; Fri, 27 Apr 2018 14:00:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 801BF21837 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoming Gao , Thomas Gleixner , peterz@infradead.org, hpa@zytor.com Subject: [PATCH 3.18 02/24] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Date: Fri, 27 Apr 2018 15:57:37 +0200 Message-Id: <20180427135631.684181554@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135631.584839868@linuxfoundation.org> References: <20180427135631.584839868@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xiaoming Gao commit d3878e164dcd3925a237a20e879432400e369172 upstream. The TSC calibration code uses HPET as reference. The conversion normalizes the delta of two HPET timestamps: hpetref = ((tshpet1 - tshpet2) * HPET_PERIOD) / 1e6 and then divides the normalized delta of the corresponding TSC timestamps by the result to calulate the TSC frequency. tscfreq = ((tstsc1 - tstsc2 ) * 1e6) / hpetref This uses do_div() which takes an u32 as the divisor, which worked so far because the HPET frequency was low enough that 'hpetref' never exceeded 32bit. On Skylake machines the HPET frequency increased so 'hpetref' can exceed 32bit. do_div() truncates the divisor, which causes the calibration to fail. Use div64_u64() to avoid the problem. [ tglx: Fixes whitespace mangled patch and rewrote changelog ] Signed-off-by: Xiaoming Gao Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Cc: peterz@infradead.org Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/38894564-4fc9-b8ec-353f-de702839e44e@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/tsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -399,7 +399,7 @@ static unsigned long calc_hpet_ref(u64 d hpet2 -= hpet1; tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD)); do_div(tmp, 1000000); - do_div(deltatsc, tmp); + deltatsc = div64_u64(deltatsc, tmp); return (unsigned long) deltatsc; }