Received: by 10.192.165.148 with SMTP id m20csp855536imm; Fri, 27 Apr 2018 08:34:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOcXKa9ncF55UG1FONvebgH8LQsXATKusG+FejSrldXVhHg7O/hztxSBsAqi00C6P2RJkC X-Received: by 2002:a65:6301:: with SMTP id g1-v6mr2543330pgv.307.1524843292720; Fri, 27 Apr 2018 08:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524843292; cv=none; d=google.com; s=arc-20160816; b=Cnb1BViKzcSxtr854N0ED3/U+GGQh/YwUlx1Nr7oKuqmMVdwf9HFR+fNtUZOBEqnhF MaFIGsk0Be2u6hNmsQ44ZhGDqadq14EbbvNw3IIPH4sikTa3as1qgpAOLpb7mjtWoNwY HfUND+ZMCmaQ3Uu9J8AEoTnxN1yzZi670Aqs95io62wnr4utanzKxqS5pwxu2CuHtJjd /XbVvYku+XkEQ+4+3KdIpTVgz5xyZtcJi1L448R/UoNotpGXHXOfBqEhzTH10revvFV0 +OfJ0x7RFK3ZWdCuSM+vrAAp8agb3XWPqVQzKgrgLxLFzHFTye8JJd+brhW1CmPrVVsO +BCQ== 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=EzWiRHQcKIwT/XuSTbb38cE1y0A6UpeRuZye1yG1tjI=; b=eXqzjFT6QBRCTjxTuK6+pTSxSIzXUGzTiBxC4B1HMs5TeusdZvqNvGzmyyd5/ZVpTB qj46sk1cHrNdZGo5KZdd5ooitBzAylNyYTBiNruluoa+dy7iZeR/d8P3AP/60RVMb3Zp dBUwGWFyHwi11g0UkY+hqJ5uJjK31oVMFkkzVxHE+SsMwxX+tW3p363ERh2STTGMKuJV Gloz3kunbB1u8PqLGw4syxKUtAcExVpdr/nPI+pgABWzsDXpS5anQKzq5OfMs2eGdf7J Lcn8uVBJFywPV6htCM1Qbao0SuMmf32OXHWIYJnKDa1H8bhmaSl/A7gibBwef223VZlm FcJw== 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 f123si1424488pfa.364.2018.04.27.08.34.38; Fri, 27 Apr 2018 08:34:52 -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 S933125AbeD0PdW (ORCPT + 99 others); Fri, 27 Apr 2018 11:33:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:47772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932387AbeD0OAi (ORCPT ); Fri, 27 Apr 2018 10:00:38 -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 8CD4321897; Fri, 27 Apr 2018 14:00:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CD4321897 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 4.4 02/50] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Date: Fri, 27 Apr 2018 15:58:04 +0200 Message-Id: <20180427135655.769458519@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135655.623669681@linuxfoundation.org> References: <20180427135655.623669681@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.4-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 @@ -408,7 +408,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; }