Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp185965pxy; Wed, 28 Apr 2021 02:07:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+WOsXFJLDBAiyLIt1Nyw4b4RByWphpJC95ZUI45sLkgxqaNgEaNRucElKXbAS94SZYMRX X-Received: by 2002:a17:906:3952:: with SMTP id g18mr27961727eje.104.1619600837417; Wed, 28 Apr 2021 02:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619600837; cv=none; d=google.com; s=arc-20160816; b=l7bO5yzU3DsBWhMaJ9eoflWITeHO9rn1ey1YnhQgd+XQayZPBsQIaTm2vdA6bruUd5 zOH0KJrOtFoZYFoUWh7Ya+V9BD4u8yaGqW/EgdiJfu9Uku+O5t5qUr4i4DwFyWlm3+4f YHchLo5b9kiSdguWO7bArhqLhVB5ulodMTpESo7BfzjSQJcwPRvMXPdeSFuLOHWC/nLw fUK0XClAVvoJ4MoGx0FUX89f/x5ih9laaCYEfsloqrSRp2TVRhQao+L/+NTJbEm+jD8v sJuA3lo3NLyjJjegNVsUHVZPSS9HbIRTs/vQblwwKevBZICnJH+uzmMaPFS+aqC3k3Ll e2iA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=ZgjFKGpVryRtOrTR+2f2UxGxyQKJi1GZZuKy6taxAtA=; b=OhkJxk4xaUIUs4QL9minQ0/c+nd9gcrBU0KjpzT7pTvXh/MV11DI553df9OZvFRU9z CteX26EFjwEjD1BMml22KL0MizJmi5dpR0+uiafhJxRMTmu8hC3PRitVarfVja0VbQQ+ WlIwR3HnYZeV/wBXx0hNm2tEMsP9nLDTF6IRDmTHCST6QEb9eh6gDTHVhRkHaXWUfyXq mvyZU0H0Z3BKA547Q6aWJmQ7UmxqgwxdoGSkO0ZHRMaKrBnRpTEJAfnkMyw+TAsjW2PG 6USVvZRBeWH03xLg51GxZ6nwD6mPTuLHbOgnIcS4LbkwCcNuQCI+dV4lEbrvlBI5WgSP YfJA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si4838665edc.569.2021.04.28.02.06.53; Wed, 28 Apr 2021 02:07:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238087AbhD1JGg (ORCPT + 99 others); Wed, 28 Apr 2021 05:06:36 -0400 Received: from mga12.intel.com ([192.55.52.136]:37426 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237995AbhD1JGR (ORCPT ); Wed, 28 Apr 2021 05:06:17 -0400 IronPort-SDR: YvRvMJjQP9sSqg3CASik2pSG8ZHHPyBVLJ/uag0x21Ktb5vqQ2Cnwxxc4gUgBbl6ogMZMhhxl6 OzDuaC8BowwQ== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="176176420" X-IronPort-AV: E=Sophos;i="5.82,257,1613462400"; d="scan'208";a="176176420" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2021 02:05:32 -0700 IronPort-SDR: PwIgUXmzgjn8bi3GeVIzjJ1gcB0DhsL8DJ8zLPSXYIL5SNVovySYeXVz/ejif7dW8aCXdtuP2E xbjoQr41t/bQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,257,1613462400"; d="scan'208";a="458084311" Received: from chenyu-desktop.sh.intel.com ([10.239.158.173]) by fmsmga002.fm.intel.com with ESMTP; 28 Apr 2021 02:05:30 -0700 From: Chen Yu To: youling257 , Kurt Garloff , Bingsong Si , "Artem S . Tashkinov" Cc: Terry Bowman , Bas Nieuwenhuizen , Calvin Walton , Borislav Petkov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] tools/power turbostat: Fix offset overflow issue in index converting Date: Wed, 28 Apr 2021 17:09:16 +0800 Message-Id: <8167875a1d688b92b0ec707b95855a604afacf01.1619600637.git.yu.c.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Calvin Walton 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 --- tools/power/x86/turbostat/turbostat.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 37759d6c463d..085057daef86 100644 --- 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_data *t, struct core_data *c, struct pkg 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_data *t, struct core_data *c, struct pkg 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; } -- 2.25.1