Received: by 10.223.185.116 with SMTP id b49csp3900568wrg; Tue, 13 Feb 2018 09:25:45 -0800 (PST) X-Google-Smtp-Source: AH8x224xgPgDHoTkSwxEIYI1Sy9L9HcUZe3SCh63Fq4oNjTTK54NmS8ZYQ/11QHNk1+/vM2CVrCO X-Received: by 2002:a17:902:7297:: with SMTP id d23-v6mr1743639pll.417.1518542745777; Tue, 13 Feb 2018 09:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518542745; cv=none; d=google.com; s=arc-20160816; b=Shfa9aHA6dxfi6PowAKIWa9IVuHJfL63mxaINZXqsndWn1snI8V0+nuIjWsqRKgypb r9zV7RhzRkYJdAdbmmL6RtXcGLJXeaA/cwuoCPKNAXJzsHuze07C1VWEXU5kclvIHI0W nD9xj5li4A5s/64Ldcq6AQCBS73pUC1xIm3d4S/zAWOjNkbVNMMf+JKkMq48hXjc3CW8 wh19NU5C1C1q1QPCQntDK0lhGTso5bGjt4q+4wvbPW38Sixkzc/FLmjsdhYnHalJblQk /F+BBqhiISzfTT8AvIbkIPBQViW9iRfkSCiMZy/sQSwQnFra2M6HBTLAMilfVeZzC38D 6hTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :user-agent:in-reply-to:references:subject:cc:to:from:message-id :date:arc-authentication-results; bh=Bw+bZyeaZGbDD+HCVcRVY0V0V6EHFL+NuYeD3O9N26g=; b=D/7G6nz/SwS1nmszPrJzp1lHX4iWc1RdmRuV5hCHhp20pUqVL/MAgIY1M6uFb6BE4W uYgADY8DnZIryU+xgDc7J7VXal2mn9+beb37vfPwO02vWpt3y3ViXAwNNrW624arc+vo H8M5wHq69K2Cw6i8zABKRJTVQgUhaPI9G4ctxuPiVRcFUTfVW8SJJRYXUZEaZ1Qf9NlC kf6SUjOcmVWAUR7LqjbS5bzfXayyPgI+p+r24wQWvPNcdRp/eCmnHUl/dXJSd+jlxy1S xqzRj033PRlWkC6ONDvJtAKvHCAZVEYqRCZexw/Z1pUUGDzFBrb+JilR3nII8OqUsYd5 oD8A== 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 p11si1699143pfl.310.2018.02.13.09.25.30; Tue, 13 Feb 2018 09:25:45 -0800 (PST) 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 S965218AbeBMRYt (ORCPT + 99 others); Tue, 13 Feb 2018 12:24:49 -0500 Received: from gateway36.websitewelcome.com ([192.185.193.12]:30057 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934279AbeBMRYs (ORCPT ); Tue, 13 Feb 2018 12:24:48 -0500 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway36.websitewelcome.com (Postfix) with ESMTP id E614C40404982 for ; Tue, 13 Feb 2018 11:24:47 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id leJzeWVefzzFjleJze8x5U; Tue, 13 Feb 2018 11:24:47 -0600 Received: from gator4166.hostgator.com ([108.167.133.22]:12264) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1eleJz-001hr9-J3; Tue, 13 Feb 2018 11:24:47 -0600 Received: from 189.175.4.238 ([189.175.4.238]) by gator4166.hostgator.com (Horde Framework) with HTTPS; Tue, 13 Feb 2018 11:24:47 -0600 Date: Tue, 13 Feb 2018 11:24:47 -0600 Message-ID: <20180213112447.Horde.gzaHZ_lO1wrYVuxHFhkn6nu@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Thomas Gleixner Cc: Borislav Petkov , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/microcode/intel: Use 64-bit arithmetic instead of 32-bit References: <20180213164404.GA11664@embeddedor.com> In-Reply-To: User-Agent: Horde Application Framework 5 Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 108.167.133.22 X-Source-L: Yes X-Exim-ID: 1eleJz-001hr9-J3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:12264 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 1 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, Quoting Thomas Gleixner : > On Tue, 13 Feb 2018, Gustavo A. R. Silva wrote: > >> Add suffix ULL to constant 1024 in order to give the compiler complete >> information about the proper arithmetic to use. Notice that this >> constant is used in a context that expects an expression of type >> u64 (64 bits, unsigned). >> >> The expression c->x86_cache_size * 1024 is currently being evaluated >> using 32-bit arithmetic. >> >> Addresses-Coverity-ID: 1464429 >> Signed-off-by: Gustavo A. R. Silva >> --- >> arch/x86/kernel/cpu/microcode/intel.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/x86/kernel/cpu/microcode/intel.c >> b/arch/x86/kernel/cpu/microcode/intel.c >> index f7c55b0..e5edb92 100644 >> --- a/arch/x86/kernel/cpu/microcode/intel.c >> +++ b/arch/x86/kernel/cpu/microcode/intel.c >> @@ -982,7 +982,7 @@ static struct microcode_ops microcode_intel_ops = { >> >> static int __init calc_llc_size_per_core(struct cpuinfo_x86 *c) >> { >> - u64 llc_size = c->x86_cache_size * 1024; >> + u64 llc_size = c->x86_cache_size * 1024ULL; > > x86_cache_size is 'int', so you really want to cast c->x86_cache_size to > (u64) for correctness sake. > > Aside of that the patch is really purely cosmetic at the moment because the > largest LLC sizes are still below the 3 digit MB range which fits into > 32bit quite well. You'd need to have a CPU with >= 2G LLC to create a > problem. > > But looking at c->x86_cache_size again. It's int because it's set to -1 > initially which is then changed if CPUid or general CPU info gives real > information about the cache size. The only place where that matters is the > /proc/cpuinfo output: > > if (c->x86_cache_size >= 0) > seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size); > > which is silly, because that really can be done with: > > if (c->x86_cache_size) > > as there is no point in printing 'cache size 0KB', which means > x86_cache_size can be made unsigned int, which makes sense because cache > size < 0 does not at all. > > So instead of doing this purely mechanical cosmetic change to make a static > checker shut up, I'd like to see a proper cleanup of that thing. > Yeah, actually I was curious about why x86_cache_size is signed instead of unsigned. You've made it clear now. I will change it to be of type unsigned int and make the proper changes to the rest of code in which x86_cache_size is being used. Also, I'm curious about the types of the rest of the related variables: /* Cache QoS architectural values: */ int x86_cache_max_rmid; /* max index */ int x86_cache_occ_scale; /* scale to bytes */ int x86_power; Maybe they need some cleanup too. Thanks for the feedback. -- Gustavo