Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2503544pxj; Mon, 10 May 2021 04:42:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw24xTqUPT0FynLaZWAxhHWQcuYrhfOwtn9JuaT8r6hI2OPcybe9UfII6t7/5cWItPJegcE X-Received: by 2002:a05:6402:312a:: with SMTP id dd10mr28187430edb.384.1620646939131; Mon, 10 May 2021 04:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620646939; cv=none; d=google.com; s=arc-20160816; b=CvaImY5exEnsv3lJ41JJo2DYlPt+GVt29hAhHilQu/JK6eMxPr+ZJ3JjXc7FU3J+Dh 9rlmtCMBks6X8v5HH6kKIxkPPqYFIxiFMkHLWdHkpRKikE+51d949zjWDFNHlMGtJ4jK CEnWWJy4Z/gPnlyGMZBJ2bicAkODAlspN10caQkfK4T2GLBXUWwaF2+STesKnuuMAMl3 20EaH6eYljaDp9W3hCZhWnUOcinO74xImFk8h8Zh6wk3Z9rx3Ju3OtgZ6gAAhMcBUTzI WyTEpoJCRWsU6Fme7YSgFlkelAKZsnrd99PAX90ZHEfbcsSJqz3RD+JfK9iDKQQ7Ln9K QiIQ== 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=jNxfu6EmeHDB5Pkc+8H8nKitJNcQvxN9kGpLMtiKIY4=; b=Y5xz+fgoAySU/7EbCkH4/egwNoOxRkB/Vdosk7B7E+ti0XgZHf1Hez5wugFh46pkTm 0mglkxmKVixIsRNXv7AXidtOUyHTpx1Lz4ooNIU5NSbg4xsVrmDozcfZ9f0XAAEsYtfR kYPimkWx4MJZsThpIBjg0Qe/Bxkgw1mDwf0U91uUpN3eLywnuy0jY2EXtb3u7YoJMKb9 B2cumlhJ/8mAfrAY+U3AXFncfXoZAXsATm2JkKKhH8C6Cs4ofr3rvzAV59qhqH3nLcSb pyhv7QoUKKf5J4v7YXlfGjOzauI+8dirfQ48sVK3QaAqz/rIjAdbe3dO6Kl/pt5gpY82 UTiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dQw5da88; 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 o32si12736391eda.316.2021.05.10.04.41.55; Mon, 10 May 2021 04:42:19 -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=dQw5da88; 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 S241228AbhEJLht (ORCPT + 99 others); Mon, 10 May 2021 07:37:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233949AbhEJKzk (ORCPT ); Mon, 10 May 2021 06:55:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7993E61C1C; Mon, 10 May 2021 10:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643377; bh=WsGw9k/8ZnoBidialPyvo3PZGZ6IYAPkWtB1xC1T+gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQw5da8849keOyR+pA1xJ24rXxF3tBcEueWd5lDqAq0r3hy0vhrEPTZkjrovciO1k 0kjm4h58gbrtbKQ7TIZE1VyYs09wKqKEIlA8tWifNfuO4KHxVuuJCK2Y2LSKj0IBOH h4SYRCBJ+IZa3MEl4cQH9tUW4pei6jUsTu8YJboM= 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.10 290/299] tools/power turbostat: Fix offset overflow issue in index converting Date: Mon, 10 May 2021 12:21:27 +0200 Message-Id: <20210510102014.498108165@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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; @@ -3249,7 +3249,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; @@ -3258,7 +3258,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; }