Skip to content

Commit ea6803f

Browse files
kepstingregkh
authored andcommitted
tools/power turbostat: Fix offset overflow issue in index converting
commit 13a779d 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: 9972d5d ("tools/power turbostat: Enable accumulate RAPL display") Signed-off-by: Calvin Walton <calvin.walton@kepstin.ca> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b84c577 commit ea6803f

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎tools/power/x86/turbostat/turbostat.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ struct msr_sum_array {
291291
/* The percpu MSR sum array.*/
292292
struct msr_sum_array *per_cpu_msr_sum;
293293

294-
int idx_to_offset(int idx)
294+
off_t idx_to_offset(int idx)
295295
{
296-
int offset;
296+
off_t offset;
297297

298298
switch (idx) {
299299
case IDX_PKG_ENERGY:
@@ -323,7 +323,7 @@ int idx_to_offset(int idx)
323323
return offset;
324324
}
325325

326-
int offset_to_idx(int offset)
326+
int offset_to_idx(off_t offset)
327327
{
328328
int idx;
329329

@@ -3249,7 +3249,7 @@ static int update_msr_sum(struct thread_data *t, struct core_data *c, struct pkg
32493249

32503250
for (i = IDX_PKG_ENERGY; i < IDX_COUNT; i++) {
32513251
unsigned long long msr_cur, msr_last;
3252-
int offset;
3252+
off_t offset;
32533253

32543254
if (!idx_valid(i))
32553255
continue;
@@ -3258,7 +3258,8 @@ static int update_msr_sum(struct thread_data *t, struct core_data *c, struct pkg
32583258
continue;
32593259
ret = get_msr(cpu, offset, &msr_cur);
32603260
if (ret) {
3261-
fprintf(outf, "Can not update msr(0x%x)\n", offset);
3261+
fprintf(outf, "Can not update msr(0x%llx)\n",
3262+
(unsigned long long)offset);
32623263
continue;
32633264
}
32643265

0 commit comments

Comments
 (0)