Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: stats: Handle the case when trans_table goes beyond PAGE_SIZE

On platforms with large number of Pstates, the transition table, which
is a NxN matrix, can overflow beyond the PAGE_SIZE boundary.

This can be seen on POWER9 which has 100+ Pstates.

As a result, each time the trans_table is read for any of the CPUs, we
will get the following error.

---------------------------------------------------
fill_read_buffer: show+0x0/0xa0 returned bad count
---------------------------------------------------

This patch ensures that in case of an overflow, we print a warning
once in the dmesg and return FILE TOO LARGE error for this and all
subsequent accesses of trans_table.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Gautham R. Shenoy and committed by
Rafael J. Wysocki
f7bc9b20 0011c6da

+8 -2
+3
Documentation/cpu-freq/cpufreq-stats.txt
··· 90 90 Freq_j is in descending order with increasing columns. The output here also 91 91 contains the actual freq values for each row and column for better readability. 92 92 93 + If the transition table is bigger than PAGE_SIZE, reading this will 94 + return an -EFBIG error. 95 + 93 96 -------------------------------------------------------------------------------- 94 97 <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table 95 98 From : To
+5 -2
drivers/cpufreq/cpufreq_stats.c
··· 118 118 break; 119 119 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 120 120 } 121 - if (len >= PAGE_SIZE) 122 - return PAGE_SIZE; 121 + 122 + if (len >= PAGE_SIZE) { 123 + pr_warn_once("cpufreq transition table exceeds PAGE_SIZE. Disabling\n"); 124 + return -EFBIG; 125 + } 123 126 return len; 124 127 } 125 128 cpufreq_freq_attr_ro(trans_table);