Received: by 10.192.165.148 with SMTP id m20csp526066imm; Wed, 25 Apr 2018 03:40:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Ab8xGMqu+EqnU1y3DLtHaFZR9pFGLeyLHhjcpRrxaymFkWbqT1RalJK+M5tc0jl/hbziN X-Received: by 10.98.52.193 with SMTP id b184mr23416549pfa.178.1524652857706; Wed, 25 Apr 2018 03:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524652857; cv=none; d=google.com; s=arc-20160816; b=cSi7nIeQzjr+DAxapvrGdBG74hc0EEqfgBXpNToPO6UwKeFgS6wxgR4N3e55OY3CCS vp8rZTDePpo4JZjqCC1Vb0PgqK1jh6hIZKyTkLACuFagiNGbqS69fTCIHECo2q3992nb jypK+URbOZpdgNGYLXLGiMkEa7m1s8h4vqDD+ap2ha40IUdzEaqdWNFVWvSQToX0nxei uaABAuXe04hPfI767ajaAm7jftQ4oeJkPrv4LE4QJYw9mS7hg2FtLrNZ32Jk8cQMjSdV HtEu4JybloWJFDdagzT9CrMaPdXSNy750H3M82G7magH5YNjKB5hOT4kATIT44/L08wI 023g== 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 :arc-authentication-results; bh=NPnhIHT4yXgqCOr4H2/zUqleeYAINfJ6H9ryAnk0+L4=; b=umomLKt/IMpSjHjIqF2xt/gKqbW965bJtJJ3ffltvdmwGUeUIwtzn301766oqyWWMS kV1n2pF14GvbYY7KqbYAyVNgPkvLUJthE0kmk8hpRvpSU5pMQ+U61GioAWFaUuEVEj61 k4F5FWUDoxKv6BNEhZOGrbKFo4L5x8krm+EUpIiMaYqnTRpNP8D/tpvWHl9a2mFIv3Lx vhpNtbShDOitbTsEt+2qOuEMoJh05lmHmypjQN0lSHMxr+qZJc1aY4ofMDDP87yUotJI 4QlVJJ0YWbeKKNv/QP+cX2BMbfCU+o3SOnvV0IftX2oxsGIbnTMN5unv2ScOcow8FS9b 8Vjg== 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 bg11-v6si16197731plb.171.2018.04.25.03.40.43; Wed, 25 Apr 2018 03:40:57 -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 S1753371AbeDYKiA (ORCPT + 99 others); Wed, 25 Apr 2018 06:38:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51246 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbeDYKh5 (ORCPT ); Wed, 25 Apr 2018 06:37:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2C0EE480; Wed, 25 Apr 2018 10:37:56 +0000 (UTC) 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 4.14 005/183] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Date: Wed, 25 Apr 2018 12:33:45 +0200 Message-Id: <20180425103242.822858601@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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 4.14-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 @@ -316,7 +316,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; }