Received: by 10.192.165.148 with SMTP id m20csp522274imm; Wed, 25 Apr 2018 03:36:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx48lxoA5wk79QB5r+t9LFtCtDSaFSYotnkUFbxVu0K1NlM2JiUxgPpJivZaRIHnN2hMYSYNk X-Received: by 10.98.33.28 with SMTP id h28mr26822438pfh.249.1524652579760; Wed, 25 Apr 2018 03:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524652579; cv=none; d=google.com; s=arc-20160816; b=ggGFcFa2Ui7nwb4T55M5yul3Lcl6aJ5+fp7VMyinE/nXx8Yhi0cVJOmxqh3FqQ464W xY4PSYo2ZsuddKmi6ZY0cHXQJiYNkuob4BLhqzZ97beqNZqRR3z4EZef4qBpNDnQcTuR nFgxQVAPwHuU/Q5dfBVvHFTkLMqndd8GSk6MgZ9GFFUgppMvWD10KVSHDlleOgbOAax6 xpZvBIo/SitclHDInrHb750zRcU3rQhNZFpg06dI06cqrlFSu3FcrELo5sVTBtCsK20q Zym6v/nyWlzyb3+cxZ58J68RRM23YLvW8pbcpPCgpVPGZ0PYgvX/xt3/zXrwgboV1lpb N6vg== 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=ASdFpj4hat6+E+FgaWFl7+k+zrIIBtKs0LrzDHlJ160=; b=DIasXwT5t3fcXM15Uz6B7buArQmErQ4SUFAPzysDW6PDSkiip5ALgWxNHEkfHO9se+ WJYgNHSE4dtmXtLLdnaU//f5e9v6I8iqAStPjiibLvjCiso0mV6Igm3h0x/TjD9R2f40 bmbW7wyrrBGHB2RUB2a4ElendC2tTiA1JKJ+tCIxWIhMwwHcra3MIFJTVKs/zkbjMAAX C7A58w40iP6zMK/R8vHhGSJuQDN10Plbw+NCVRXvxznP2dUnFGOLfU92DVLxz6UVyTTk FER63hxrMhNf4+ytT18rBDc0kCvhrpHytSPQp1MI2qvz7rsga3q7Ry8eLOtAyrnO7zp4 YokQ== 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 m65si15759049pfc.9.2018.04.25.03.36.05; Wed, 25 Apr 2018 03:36:19 -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 S1752963AbeDYKfD (ORCPT + 99 others); Wed, 25 Apr 2018 06:35:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50990 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbeDYKe5 (ORCPT ); Wed, 25 Apr 2018 06:34: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 BDFE44A5; Wed, 25 Apr 2018 10:34: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.16 08/26] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Date: Wed, 25 Apr 2018 12:33:17 +0200 Message-Id: <20180425103315.187911246@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103314.842517924@linuxfoundation.org> References: <20180425103314.842517924@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.16-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 @@ -317,7 +317,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; }