Received: by 10.192.165.148 with SMTP id m20csp839716imm; Fri, 27 Apr 2018 08:19:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpj5nlsUJ/uNCOwmXvH34KyB3Mi7I4qdi6HIi5xoWrYWAMlkW2D7ZgZ3NCCKIRPp0llSYEK X-Received: by 2002:a63:41c5:: with SMTP id o188-v6mr2503427pga.280.1524842367482; Fri, 27 Apr 2018 08:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524842367; cv=none; d=google.com; s=arc-20160816; b=kBqsSuNDjt6GHq8zJF4Spq3pMtg+6ldKq7lRD8yUZLbjMJbDzIqZjb09C47ARrWxns 6ecXYen3LqKCkXd1LAo5Q/WtLinzzLqNl5LqAQLWbGQH3OQ2Z537LaV0SBwFNWIkVflv 5dEOSPtpWnsaxdJ7ppqfV1e488XuPNvUm+FDK9Gq4TNJqGvPwieTsBbDTsVPJuG6Qjhk ElGG41KBEeQuESCJ0PdWwYLyWs1wBKFKHfWP0qW9Gmu+FpIPFiyl01Exzdkpvdz+B87S GfIR76RJb4xIkv6lAzUBIOFEt4jrloDrGUPBvbOjWFtwkWycdBlwCQnap++l+hC0STpp OtEA== 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=ad8nTsbqwGkO3Ch7zisS4x0sAeXBnY8UuHfhXGhPCmM=; b=L/kAMsELbThJbgpXRP1OilPjCFvpa4pt/d/T4jji+bCR6doobVrIDKNqAnESZlcAI2 IH/4wCjZfDmZowJR4GvpDOktEcUIkBA4q113jMYtSlu/Igj9htcLEBIqd84bhMz836+y G4pvUmZzTCuenysKwSEuP1Mm9IEPK4qUEnkHF0xdoqK4JFQRrWIfEvs7nXiAXuR7b4a+ Uy6D/SFn6845OgRhDkjZ3A/OKRVrBvhxiVCMqPXH/15BNBXltJcxgAznUibQ6OO5i53w PEfWMrf+kEfrguGowwQoEX1DBTvHSJrH3rhhIa0sA07NHUFt7krjs5cAtb0bCQHAlRtK gxaQ== 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 v5si1482450pfd.341.2018.04.27.08.19.13; Fri, 27 Apr 2018 08:19:27 -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 S933132AbeD0OC6 (ORCPT + 99 others); Fri, 27 Apr 2018 10:02:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:49542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933411AbeD0OCz (ORCPT ); Fri, 27 Apr 2018 10:02:55 -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 85B86218A0; Fri, 27 Apr 2018 14:02:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85B86218A0 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.9 02/74] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Date: Fri, 27 Apr 2018 15:57:52 +0200 Message-Id: <20180427135709.998099721@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135709.899303463@linuxfoundation.org> References: <20180427135709.899303463@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.9-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 @@ -409,7 +409,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; }