diff options
author | Gautham R. Shenoy <ego@linux.vnet.ibm.com> | 2017-11-07 03:09:29 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-11-08 17:41:25 -0500 |
commit | f7bc9b209e27c0b617378400136cc663a6314d0c (patch) | |
tree | b54c5275965162f7df59cdf84c0c1ff82c7f87b4 | |
parent | 0011c6da99ddc428a35456d5819d6e476005f6f2 (diff) |
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>
-rw-r--r-- | Documentation/cpu-freq/cpufreq-stats.txt | 3 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt index 2bbe207354ed..a873855c811d 100644 --- a/Documentation/cpu-freq/cpufreq-stats.txt +++ b/Documentation/cpu-freq/cpufreq-stats.txt | |||
@@ -90,6 +90,9 @@ Freq_i to Freq_j. Freq_i is in descending order with increasing rows and | |||
90 | Freq_j is in descending order with increasing columns. The output here also | 90 | Freq_j is in descending order with increasing columns. The output here also |
91 | contains the actual freq values for each row and column for better readability. | 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 | <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table | 97 | <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table |
95 | From : To | 98 | From : To |
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index e75880eb037d..1e55b5790853 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
@@ -118,8 +118,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) | |||
118 | break; | 118 | break; |
119 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | 119 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
120 | } | 120 | } |
121 | if (len >= PAGE_SIZE) | 121 | |
122 | return PAGE_SIZE; | 122 | if (len >= PAGE_SIZE) { |
123 | pr_warn_once("cpufreq transition table exceeds PAGE_SIZE. Disabling\n"); | ||
124 | return -EFBIG; | ||
125 | } | ||
123 | return len; | 126 | return len; |
124 | } | 127 | } |
125 | cpufreq_freq_attr_ro(trans_table); | 128 | cpufreq_freq_attr_ro(trans_table); |