Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp743993imm; Thu, 13 Sep 2018 07:08:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbyWDJ+t67ZjL9sRgwG+bPUmcbB5dQGvcgfjW4o//xJzCern0opfUuqb2+baH8X9kJxTy/j X-Received: by 2002:a17:902:7246:: with SMTP id c6-v6mr7571636pll.28.1536847692368; Thu, 13 Sep 2018 07:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847692; cv=none; d=google.com; s=arc-20160816; b=OYjQZIQ6XngDCuoIaiJKGMRzWFk01xmOmKLYwBPObpF/EqYhxkFhwq5ubSgJ6fa0KA u/++ntMqABFWbMOefMK+qTCXV2wJO21GO53oNLJv9hp+PIJdAdt+jFjJ65mS2nnebiyA iOJk11aM0wULpW9QpfGrCj8gN6IYEP4BKGmuo8O6U86RZIOsqepjG+ezPBGoz31otp8U 7fZxyAadVUgV5JptotK7Q4xQL2eOHu3iL3MgQQ2/BwpJDTKCbLXoz2UcZ43TkdRapIiW o1cnShwkj4P75aDJuQZ4msVqu4J82UiZgV7a7JajAhEHocVH/XgoNFar8pjCqHQhMwOa +WAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=EOLrsFh3/AMTtrLeSiZOYhFyJk24KWmSuFn8FjVENu4=; b=hFY9tZc2p0X4oEMJG5EjNkAT1MpLL9LxMLBGkD9GwwmfBdHiIVeuOE7+k8cVsxuN8Z kQQ8qY66cecBx2HAmiWq0KuEVZc1iDQylhMcCGA7bSGFRkrDAx3ZWq2HK3HtnCTb0LD3 u6W3LsGD79jQuIEPNAlvXj4h9dnJAK9VfqrANvj7sHXxNOV9b57fk86o3cUMcdJcYWUq sYGbGS2RiRA6hZZ280acf9ImY80DKY7Seeo8IHlld+ratdrA00ziNkPw8ucG1toHoZgc GBHtmc/RExFxD12cWQai0qL90BtWoGHzKnDcLMj0JhAD56gWbOyDDaQB726qKUt0SRNW fS3w== 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 p19-v6si4022980plo.432.2018.09.13.07.07.56; Thu, 13 Sep 2018 07:08:12 -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 S1731986AbeIMTQA (ORCPT + 99 others); Thu, 13 Sep 2018 15:16:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35590 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731651AbeIMTP7 (ORCPT ); Thu, 13 Sep 2018 15:15:59 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 52839D39; Thu, 13 Sep 2018 14:06:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuanhua Lei , Thomas Gleixner , yixin.zhu@linux.intel.com, "H. Peter Anvin" , Peter Zijlstra , Len Brown , Pavel Tatashin , Rajvi Jingar , Dou Liyang Subject: [PATCH 4.18 185/197] x86/tsc: Prevent result truncation on 32bit Date: Thu, 13 Sep 2018 15:32:14 +0200 Message-Id: <20180913131848.961235382@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuanhua Lei commit 17f6bac2249356c795339e03a0742cd79be3cab8 upstream. Loops per jiffy is calculated by multiplying tsc_khz with 1e3 and then dividing it by HZ. Both tsc_khz and the temporary variable holding the multiplication result are of type unsigned long, so on 32bit the result is truncated to the lower 32bit. Use u64 as type for the temporary variable and cast tsc_khz to it before multiplying. [ tglx: Massaged changelog and removed pointless braces ] [ tglx: Backport to stable. Due to massive code changes is the upstream commit not applicable anymore. The issue has gone unnoticed in kernels pre 4.19 because the bogus LPJ value gets fixed up in a later stage of early boot, but it still might cause subtle and hard to debug issues between these two points. ] Fixes: cf7a63ef4e02 ("x86/tsc: Calibrate tsc only once") Signed-off-by: Chuanhua Lei Signed-off-by: Thomas Gleixner Cc: yixin.zhu@linux.intel.com Cc: "H. Peter Anvin" Cc: Peter Zijlstra Cc: Len Brown Cc: Pavel Tatashin Cc: Rajvi Jingar Cc: Dou Liyang Link: https://lkml.kernel.org/r/1536228203-18701-1-git-send-email-chuanhua.lei@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/tsc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1343,7 +1343,7 @@ device_initcall(init_tsc_clocksource); void __init tsc_early_delay_calibrate(void) { - unsigned long lpj; + u64 lpj; if (!boot_cpu_has(X86_FEATURE_TSC)) return; @@ -1355,7 +1355,7 @@ void __init tsc_early_delay_calibrate(vo if (!tsc_khz) return; - lpj = tsc_khz * 1000; + lpj = (u64)tsc_khz * 1000; do_div(lpj, HZ); loops_per_jiffy = lpj; }