* [PATCH] cpufreq:stats: Handle the case when trans_table goes beyond PAGE_SIZE
@ 2017-11-07 5:22 Gautham R. Shenoy
2017-11-07 5:32 ` Viresh Kumar
0 siblings, 1 reply; 3+ messages in thread
From: Gautham R. Shenoy @ 2017-11-07 5:22 UTC (permalink / raw)
To: Viresh Kumar, Rafael J . Wysocki, Akshay Adiga, shilpa.bhat,
Vaidyanathan Srinivasan
Cc: linux-pm, Gautham R. Shenoy
From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
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 detect the overflow the first time the trans_table is read
and print a warning in the dmesg and return return the FILE TOO LARGE
error. The subsequent reads also return FILE TOO LARGE error.
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
Documentation/cpu-freq/cpufreq-stats.txt | 3 +++
drivers/cpufreq/cpufreq_stats.c | 11 +++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
index 2bbe207..a873855 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
Freq_j is in descending order with increasing columns. The output here also
contains the actual freq values for each row and column for better readability.
+If the transition table is bigger than PAGE_SIZE, reading this will
+return an -EFBIG error.
+
--------------------------------------------------------------------------------
<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
From : To
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index e75880e..3cb717c 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -79,6 +79,7 @@ static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
return count;
}
+bool trans_table_overflow;
static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
{
struct cpufreq_stats *stats = policy->stats;
@@ -88,6 +89,9 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
if (policy->fast_switch_enabled)
return 0;
+ if (unlikely(trans_table_overflow))
+ return -EFBIG;
+
len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n");
len += snprintf(buf + len, PAGE_SIZE - len, " : ");
for (i = 0; i < stats->state_num; i++) {
@@ -118,8 +122,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
break;
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
}
- if (len >= PAGE_SIZE)
- return PAGE_SIZE;
+ if (len >= PAGE_SIZE) {
+ trans_table_overflow = true;
+ pr_warn("cpufreq transition table exceeds PAGE_SIZE. Disabling\n");
+ return -EFBIG;
+ }
return len;
}
cpufreq_freq_attr_ro(trans_table);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq:stats: Handle the case when trans_table goes beyond PAGE_SIZE
2017-11-07 5:22 [PATCH] cpufreq:stats: Handle the case when trans_table goes beyond PAGE_SIZE Gautham R. Shenoy
@ 2017-11-07 5:32 ` Viresh Kumar
2017-11-07 7:52 ` Gautham R Shenoy
0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2017-11-07 5:32 UTC (permalink / raw)
To: Gautham R. Shenoy
Cc: Rafael J . Wysocki, Akshay Adiga, shilpa.bhat,
Vaidyanathan Srinivasan, linux-pm
On 07-11-17, 10:52, Gautham R. Shenoy wrote:
> From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
>
> 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 detect the overflow the first time the trans_table is read
> and print a warning in the dmesg and return return the FILE TOO LARGE
s/return return/return/
> error. The subsequent reads also return FILE TOO LARGE error.
>
> Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
> ---
> Documentation/cpu-freq/cpufreq-stats.txt | 3 +++
> drivers/cpufreq/cpufreq_stats.c | 11 +++++++++--
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
> index 2bbe207..a873855 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
> Freq_j is in descending order with increasing columns. The output here also
> contains the actual freq values for each row and column for better readability.
>
> +If the transition table is bigger than PAGE_SIZE, reading this will
> +return an -EFBIG error.
> +
> --------------------------------------------------------------------------------
> <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
> From : To
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index e75880e..3cb717c 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -79,6 +79,7 @@ static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
> return count;
> }
>
> +bool trans_table_overflow;
This should be marked static and would be better to move it as local to below
function, but ...
> static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> {
> struct cpufreq_stats *stats = policy->stats;
> @@ -88,6 +89,9 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> if (policy->fast_switch_enabled)
> return 0;
>
> + if (unlikely(trans_table_overflow))
> + return -EFBIG;
> +
Do we really need to optimize this path at all? This is debug stuff really. Over
that a person can theoretically rmmod the driver, insmod another driver and the
problem may go away then. And so above would be problematic then.
> len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n");
> len += snprintf(buf + len, PAGE_SIZE - len, " : ");
> for (i = 0; i < stats->state_num; i++) {
> @@ -118,8 +122,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> break;
> len += snprintf(buf + len, PAGE_SIZE - len, "\n");
> }
> - if (len >= PAGE_SIZE)
> - return PAGE_SIZE;
> + if (len >= PAGE_SIZE) {
> + trans_table_overflow = true;
> + pr_warn("cpufreq transition table exceeds PAGE_SIZE. Disabling\n");
> + return -EFBIG;
> + }
I would suggest making only this change and removing other optimizations
completely.
--
viresh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq:stats: Handle the case when trans_table goes beyond PAGE_SIZE
2017-11-07 5:32 ` Viresh Kumar
@ 2017-11-07 7:52 ` Gautham R Shenoy
0 siblings, 0 replies; 3+ messages in thread
From: Gautham R Shenoy @ 2017-11-07 7:52 UTC (permalink / raw)
To: Viresh Kumar
Cc: Gautham R. Shenoy, Rafael J . Wysocki, Akshay Adiga, shilpa.bhat,
Vaidyanathan Srinivasan, linux-pm
Hi Viresh,
On Tue, Nov 07, 2017 at 11:02:36AM +0530, Viresh Kumar wrote:
> On 07-11-17, 10:52, Gautham R. Shenoy wrote:
> > From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
> >
> > 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 detect the overflow the first time the trans_table is read
> > and print a warning in the dmesg and return return the FILE TOO LARGE
>
> s/return return/return/
Will fix this.
>
> > error. The subsequent reads also return FILE TOO LARGE error.
> >
> > Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
> > ---
> > Documentation/cpu-freq/cpufreq-stats.txt | 3 +++
> > drivers/cpufreq/cpufreq_stats.c | 11 +++++++++--
> > 2 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
> > index 2bbe207..a873855 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
> > Freq_j is in descending order with increasing columns. The output here also
> > contains the actual freq values for each row and column for better readability.
> >
> > +If the transition table is bigger than PAGE_SIZE, reading this will
> > +return an -EFBIG error.
> > +
> > --------------------------------------------------------------------------------
> > <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
> > From : To
> > diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> > index e75880e..3cb717c 100644
> > --- a/drivers/cpufreq/cpufreq_stats.c
> > +++ b/drivers/cpufreq/cpufreq_stats.c
> > @@ -79,6 +79,7 @@ static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
> > return count;
> > }
> >
> > +bool trans_table_overflow;
>
> This should be marked static and would be better to move it as local to below
> function, but ...
> > static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> > {
> > struct cpufreq_stats *stats = policy->stats;
> > @@ -88,6 +89,9 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> > if (policy->fast_switch_enabled)
> > return 0;
> >
> > + if (unlikely(trans_table_overflow))
> > + return -EFBIG;
> > +
>
> Do we really need to optimize this path at all? This is debug stuff really. Over
> that a person can theoretically rmmod the driver, insmod another driver and the
> problem may go away then. And so above would be problematic then.
Sure, I see what you mean. I can change the warning below to a
pr_warn_once, so that the dmesg isn't cluttered everytime someone
reads the trans_table.
>
> > len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n");
> > len += snprintf(buf + len, PAGE_SIZE - len, " : ");
> > for (i = 0; i < stats->state_num; i++) {
> > @@ -118,8 +122,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
> > break;
> > len += snprintf(buf + len, PAGE_SIZE - len, "\n");
> > }
> > - if (len >= PAGE_SIZE)
> > - return PAGE_SIZE;
> > + if (len >= PAGE_SIZE) {
> > + trans_table_overflow = true;
> > + pr_warn("cpufreq transition table exceeds PAGE_SIZE. Disabling\n");
> > + return -EFBIG;
> > + }
>
> I would suggest making only this change and removing other optimizations
> completely.
Ok. Will resend the patch incorporating your suggestions. Thanks for
the review.
>
> --
> viresh
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-07 7:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-07 5:22 [PATCH] cpufreq:stats: Handle the case when trans_table goes beyond PAGE_SIZE Gautham R. Shenoy
2017-11-07 5:32 ` Viresh Kumar
2017-11-07 7:52 ` Gautham R Shenoy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).