Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2555085pxj; Mon, 10 May 2021 05:50:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI0tLZhGkqO3RYBpljsuyzNDopK2cqHAGxu6jd8lvI1v1hKrKFOzedV7xI0XiO3fVmhkrC X-Received: by 2002:a05:6e02:19ce:: with SMTP id r14mr22130748ill.4.1620651028712; Mon, 10 May 2021 05:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620651028; cv=none; d=google.com; s=arc-20160816; b=MAtKobbj11NHW0Umsy35P1bIA4OmUHu5pX24sIRYVmVf7Use8dRB9EYDcMjBrWEjH8 XTpUIDJyQXRHzMbeyZ+N8STpJAN4OabbXF7vOg4TNRsdflfvSPOlj1+KkUIIE49rakPU HWmOyM01sjIJpq1lFbe1h7yH/V5IjR4kWY8YRkYQ8Kp3JPKCz5XdLmRvvrrIjHZRi0mP hQzQ/5BelnvxgW5MoCHlnXyWti+AH7n+MvDOutbBRC9hT6hSeoI76frrXs8AGCX6Hc1Y f3Lz9PqLqJVm2hCp6je7YRVVzyiSVYDhVonAgRPxnfpq4Cz0nfUUmzqlHRnPnykaTOeY pk8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NxbBYwN1JmklgC0+ln++6X5y+IMyjT46Oa/KVMz8/xc=; b=Bt5xqdKub8uJCcTGjYUf6D/ADIqN0zudJ6qfXLbnnf2O/TgHXlohihoYBgxmb9Ajjt eqpCqOeAmZLgUfH9TXAbReiKp+NYuEWyVLUwLDLHF7RFZewLr09zU3r09ZcbxWUvMBXP xWtpdD3GtsEtg3d5ZzagYiFhYlqkbieroHzKmoBgrNdfNOBVuMhuCiTjPVFbUvK1yyTq CEtdJZYSQ286zJ04vsiszp3TnwmDC2AtcWiR78mUDFWD8fz3Ba+3PS7+WxFq1e9KA3eD wgPAoJTWmH1jiimypCPYP+AFLyuCYzYPFA820Qn5+2XvZ0Ya8anyDx33nVODOulLFBWM HJKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TDw3eZDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si1398798ilu.88.2021.05.10.05.50.15; Mon, 10 May 2021 05:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TDw3eZDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241408AbhEJMoc (ORCPT + 99 others); Mon, 10 May 2021 08:44:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:58324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238141AbhEJLRJ (ORCPT ); Mon, 10 May 2021 07:17:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF546616E9; Mon, 10 May 2021 11:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620645153; bh=DIItjvddofOd61EZziGfIY/0ApXe1STJV2zOgTiU0ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDw3eZDXKkmhzUSET5WwAOtukbKGwwneySYvzVCSK0lafCI+K7kLmKlbbVFRpYjYo kaX6fTxcC0S6xilBkJrMA1aEA/TXsl5qSOWUm0Zue6X8Iethk0GTzWmn7fKe6d/cad fAxqd3Fl9vCeriSoXvYB1M9BxF6LSHs8NucpettQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Calvin Walton , Len Brown Subject: [PATCH 5.12 373/384] tools/power turbostat: Fix offset overflow issue in index converting Date: Mon, 10 May 2021 12:22:42 +0200 Message-Id: <20210510102027.067158312@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Calvin Walton commit 13a779de4175df602366d129e41782ad7168cef0 upstream. The idx_to_offset() function returns type int (32-bit signed), but MSR_PKG_ENERGY_STAT is u32 and would be interpreted as a negative number. The end result is that it hits the if (offset < 0) check in update_msr_sum() which prevents the timer callback from updating the stat in the background when long durations are used. The similar issue exists in offset_to_idx() and update_msr_sum(). Fix this issue by converting the 'int' to 'off_t' accordingly. Fixes: 9972d5d84d76 ("tools/power turbostat: Enable accumulate RAPL display") Signed-off-by: Calvin Walton Signed-off-by: Len Brown Signed-off-by: Greg Kroah-Hartman --- tools/power/x86/turbostat/turbostat.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -291,9 +291,9 @@ struct msr_sum_array { /* The percpu MSR sum array.*/ struct msr_sum_array *per_cpu_msr_sum; -int idx_to_offset(int idx) +off_t idx_to_offset(int idx) { - int offset; + off_t offset; switch (idx) { case IDX_PKG_ENERGY: @@ -323,7 +323,7 @@ int idx_to_offset(int idx) return offset; } -int offset_to_idx(int offset) +int offset_to_idx(off_t offset) { int idx; @@ -3276,7 +3276,7 @@ static int update_msr_sum(struct thread_ for (i = IDX_PKG_ENERGY; i < IDX_COUNT; i++) { unsigned long long msr_cur, msr_last; - int offset; + off_t offset; if (!idx_valid(i)) continue; @@ -3285,7 +3285,8 @@ static int update_msr_sum(struct thread_ continue; ret = get_msr(cpu, offset, &msr_cur); if (ret) { - fprintf(outf, "Can not update msr(0x%x)\n", offset); + fprintf(outf, "Can not update msr(0x%llx)\n", + (unsigned long long)offset); continue; }