* [PATCH] perf/core: fix perf_proc_update_handler() bug
@ 2019-01-11 1:17 Stephane Eranian
2019-01-17 21:03 ` Stephane Eranian
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Stephane Eranian @ 2019-01-11 1:17 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz, mingo, ak, kan.liang, jolsa, acme
The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
then no modification to sysctl_perf_event_sample_rate is allowed to prevent
possible hang from wrong values.
The problem is that the test to prevent modification is made after the
sysctl variable is modified in perf_proc_update_handler().
You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
echo: write error: invalid argument
But the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate
10001
This patch fixes the problem by moving the parsing of the value after
the test.
Signed-off-by: Stephane Eranian <eranian@google.com>
---
kernel/events/core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 3cd13a30f732..e5ede6918050 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
- int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
-
- if (ret || !write)
- return ret;
-
+ int ret;
+ int perf_cpu = sysctl_perf_cpu_time_max_percent;
/*
* If throttling is disabled don't allow the write:
*/
- if (sysctl_perf_cpu_time_max_percent == 100 ||
- sysctl_perf_cpu_time_max_percent == 0)
+ if (write && (perf_cpu == 100 || perf_cpu == 0))
return -EINVAL;
+ ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+ if (ret || !write)
+ return ret;
+
max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
update_perf_cpu_limits();
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] perf/core: fix perf_proc_update_handler() bug
2019-01-11 1:17 [PATCH] perf/core: fix perf_proc_update_handler() bug Stephane Eranian
@ 2019-01-17 21:03 ` Stephane Eranian
2019-01-17 22:09 ` Andi Kleen
2019-01-18 14:14 ` Arnaldo Carvalho de Melo
2019-01-18 9:52 ` Jiri Olsa
2019-01-22 11:35 ` [tip:perf/urgent] perf core: Fix " tip-bot for Stephane Eranian
2 siblings, 2 replies; 6+ messages in thread
From: Stephane Eranian @ 2019-01-17 21:03 UTC (permalink / raw)
To: LKML
Cc: Peter Zijlstra, mingo, Andi Kleen, Liang, Kan, Jiri Olsa,
Arnaldo Carvalho de Melo
On Thu, Jan 10, 2019 at 5:17 PM Stephane Eranian <eranian@google.com> wrote:
>
> The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
> syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
> when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
> then no modification to sysctl_perf_event_sample_rate is allowed to prevent
> possible hang from wrong values.
>
> The problem is that the test to prevent modification is made after the
> sysctl variable is modified in perf_proc_update_handler().
>
> You get an error:
>
> $ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
> echo: write error: invalid argument
>
> But the value is still modified causing all sorts of inconsistencies:
>
> $ cat /proc/sys/kernel/perf_event_max_sample_rate
> 10001
>
> This patch fixes the problem by moving the parsing of the value after
> the test.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
Ping.
> ---
> kernel/events/core.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 3cd13a30f732..e5ede6918050 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp,
> loff_t *ppos)
> {
> - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
> -
> - if (ret || !write)
> - return ret;
> -
> + int ret;
> + int perf_cpu = sysctl_perf_cpu_time_max_percent;
> /*
> * If throttling is disabled don't allow the write:
> */
> - if (sysctl_perf_cpu_time_max_percent == 100 ||
> - sysctl_perf_cpu_time_max_percent == 0)
> + if (write && (perf_cpu == 100 || perf_cpu == 0))
> return -EINVAL;
>
> + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
> + if (ret || !write)
> + return ret;
> +
> max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
> perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
> update_perf_cpu_limits();
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] perf/core: fix perf_proc_update_handler() bug
2019-01-17 21:03 ` Stephane Eranian
@ 2019-01-17 22:09 ` Andi Kleen
2019-01-18 14:14 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 6+ messages in thread
From: Andi Kleen @ 2019-01-17 22:09 UTC (permalink / raw)
To: Stephane Eranian
Cc: LKML, Peter Zijlstra, mingo, Liang, Kan, Jiri Olsa,
Arnaldo Carvalho de Melo
On Thu, Jan 17, 2019 at 01:03:20PM -0800, Stephane Eranian wrote:
> On Thu, Jan 10, 2019 at 5:17 PM Stephane Eranian <eranian@google.com> wrote:
> >
> > The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
> > syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
> > when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
> > then no modification to sysctl_perf_event_sample_rate is allowed to prevent
> > possible hang from wrong values.
> >
> > The problem is that the test to prevent modification is made after the
> > sysctl variable is modified in perf_proc_update_handler().
> >
> > You get an error:
> >
> > $ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
> > echo: write error: invalid argument
> >
> > But the value is still modified causing all sorts of inconsistencies:
> >
> > $ cat /proc/sys/kernel/perf_event_max_sample_rate
> > 10001
> >
> > This patch fixes the problem by moving the parsing of the value after
> > the test.
> >
> > Signed-off-by: Stephane Eranian <eranian@google.com>
>
> Ping.
Reviewed-by: Andi Kleen <ak@linux.intel.com>
-Andi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] perf/core: fix perf_proc_update_handler() bug
2019-01-11 1:17 [PATCH] perf/core: fix perf_proc_update_handler() bug Stephane Eranian
2019-01-17 21:03 ` Stephane Eranian
@ 2019-01-18 9:52 ` Jiri Olsa
2019-01-22 11:35 ` [tip:perf/urgent] perf core: Fix " tip-bot for Stephane Eranian
2 siblings, 0 replies; 6+ messages in thread
From: Jiri Olsa @ 2019-01-18 9:52 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, peterz, mingo, ak, kan.liang, acme
On Thu, Jan 10, 2019 at 05:17:16PM -0800, Stephane Eranian wrote:
> The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
> syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
> when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
> then no modification to sysctl_perf_event_sample_rate is allowed to prevent
> possible hang from wrong values.
>
> The problem is that the test to prevent modification is made after the
> sysctl variable is modified in perf_proc_update_handler().
>
> You get an error:
>
> $ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
> echo: write error: invalid argument
>
> But the value is still modified causing all sorts of inconsistencies:
>
> $ cat /proc/sys/kernel/perf_event_max_sample_rate
> 10001
>
> This patch fixes the problem by moving the parsing of the value after
> the test.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> kernel/events/core.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 3cd13a30f732..e5ede6918050 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp,
> loff_t *ppos)
> {
> - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
> -
> - if (ret || !write)
> - return ret;
> -
> + int ret;
> + int perf_cpu = sysctl_perf_cpu_time_max_percent;
> /*
> * If throttling is disabled don't allow the write:
> */
> - if (sysctl_perf_cpu_time_max_percent == 100 ||
> - sysctl_perf_cpu_time_max_percent == 0)
> + if (write && (perf_cpu == 100 || perf_cpu == 0))
> return -EINVAL;
>
> + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
> + if (ret || !write)
> + return ret;
> +
> max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
> perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
> update_perf_cpu_limits();
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] perf/core: fix perf_proc_update_handler() bug
2019-01-17 21:03 ` Stephane Eranian
2019-01-17 22:09 ` Andi Kleen
@ 2019-01-18 14:14 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-01-18 14:14 UTC (permalink / raw)
To: Stephane Eranian
Cc: LKML, Peter Zijlstra, mingo, Andi Kleen, Liang, Kan, Jiri Olsa
Em Thu, Jan 17, 2019 at 01:03:20PM -0800, Stephane Eranian escreveu:
> On Thu, Jan 10, 2019 at 5:17 PM Stephane Eranian <eranian@google.com> wrote:
> >
> > The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
> > syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
> > when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
> > then no modification to sysctl_perf_event_sample_rate is allowed to prevent
> > possible hang from wrong values.
> >
> > The problem is that the test to prevent modification is made after the
> > sysctl variable is modified in perf_proc_update_handler().
> >
> > You get an error:
> >
> > $ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
> > echo: write error: invalid argument
> >
> > But the value is still modified causing all sorts of inconsistencies:
> >
> > $ cat /proc/sys/kernel/perf_event_max_sample_rate
> > 10001
> >
> > This patch fixes the problem by moving the parsing of the value after
> > the test.
> >
> > Signed-off-by: Stephane Eranian <eranian@google.com>
>
> Ping.
Collected the Reviewed-by from Jiri and Andi, reproduced the problem
before the patch and I'm testing it to push to Ingo via perf/urgent,
thanks for the patch.
- Arnaldo
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip:perf/urgent] perf core: Fix perf_proc_update_handler() bug
2019-01-11 1:17 [PATCH] perf/core: fix perf_proc_update_handler() bug Stephane Eranian
2019-01-17 21:03 ` Stephane Eranian
2019-01-18 9:52 ` Jiri Olsa
@ 2019-01-22 11:35 ` tip-bot for Stephane Eranian
2 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Stephane Eranian @ 2019-01-22 11:35 UTC (permalink / raw)
To: linux-tip-commits
Cc: eranian, linux-kernel, kan.liang, hpa, jolsa, mingo, peterz, ak,
tglx, acme
Commit-ID: 1a51c5da5acc6c188c917ba572eebac5f8793432
Gitweb: https://git.kernel.org/tip/1a51c5da5acc6c188c917ba572eebac5f8793432
Author: Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 10 Jan 2019 17:17:16 -0800
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 18 Jan 2019 11:10:38 -0300
perf core: Fix perf_proc_update_handler() bug
The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate
syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e,
when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100,
then no modification to sysctl_perf_event_sample_rate is allowed to prevent
possible hang from wrong values.
The problem is that the test to prevent modification is made after the
sysctl variable is modified in perf_proc_update_handler().
You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate
echo: write error: invalid argument
But the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate
10001
This patch fixes the problem by moving the parsing of the value after
the test.
Committer testing:
# echo 100 > /proc/sys/kernel/perf_cpu_time_max_percent
# echo 10001 > /proc/sys/kernel/perf_event_max_sample_rate
-bash: echo: write error: Invalid argument
# cat /proc/sys/kernel/perf_event_max_sample_rate
10001
#
Signed-off-by: Stephane Eranian <eranian@google.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1547169436-6266-1-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
kernel/events/core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 3cd13a30f732..e5ede6918050 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
- int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
-
- if (ret || !write)
- return ret;
-
+ int ret;
+ int perf_cpu = sysctl_perf_cpu_time_max_percent;
/*
* If throttling is disabled don't allow the write:
*/
- if (sysctl_perf_cpu_time_max_percent == 100 ||
- sysctl_perf_cpu_time_max_percent == 0)
+ if (write && (perf_cpu == 100 || perf_cpu == 0))
return -EINVAL;
+ ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+ if (ret || !write)
+ return ret;
+
max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
update_perf_cpu_limits();
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-22 11:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-11 1:17 [PATCH] perf/core: fix perf_proc_update_handler() bug Stephane Eranian
2019-01-17 21:03 ` Stephane Eranian
2019-01-17 22:09 ` Andi Kleen
2019-01-18 14:14 ` Arnaldo Carvalho de Melo
2019-01-18 9:52 ` Jiri Olsa
2019-01-22 11:35 ` [tip:perf/urgent] perf core: Fix " tip-bot for Stephane Eranian
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.